同步最新的demo文档
authorliangzhenying <867174124@qq.com>
Wed, 20 Mar 2024 04:03:08 +0000 (12:03 +0800)
committerliangzhenying <867174124@qq.com>
Wed, 20 Mar 2024 04:03:08 +0000 (12:03 +0800)
24 files changed:
Document/AiMouseSdk接口文档.md
Document/数据交互流程.eddx
MouseSdk/AiMouseSdk/AiMouse.h
MouseSdk/AiMouseSdk/AiMouse.m
MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate
MouseSdk/MouseSdk/BleManager.m
MouseSdk/MouseSdk/ViewController.m
MouseSdk_Mac_V1.0.1/AiMouseSDK数据交互流程.pdf [new file with mode: 0644]
MouseSdk_Mac_V1.0.1/AiMouseSdk接口文档.pdf
MouseSdk_Mac_V1.0.1/MouseSdkDemo/MouseSdkDemo.xcodeproj/project.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate
MouseSdk_Mac_V1.0.1/MouseSdkDemo/MouseSdkDemo/BleManager.h
MouseSdk_Mac_V1.0.1/MouseSdkDemo/MouseSdkDemo/BleManager.m
MouseSdk_Mac_V1.0.1/MouseSdkDemo/MouseSdkDemo/ViewController.m
MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AiMouseSdk.framework/Versions/A/AiMouseSdk
MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AiMouseSdk.framework/Versions/A/Headers/AiMouse.h
MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AiMouseSdk.framework/Versions/A/Headers/AiMouseDeviceInfo.h [new file with mode: 0644]
MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AiMouseSdk.framework/Versions/A/Headers/AiMouseSdk.h
MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AiMouseSdk.framework/Versions/A/Headers/AiMouseTools.h [moved from MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AiMouseSdk.framework/Versions/A/Headers/AiTools.h with 92% similarity]
MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AiMouseSdk.framework/Versions/A/_CodeSignature/CodeResources
MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AliIotConnectKit.framework/Versions/A/AliIotConnectKit
MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AliIotConnectKit.framework/Versions/A/Modules/AliIotConnectKit.swiftmodule/Project/arm64-apple-macos.swiftsourceinfo
MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AliIotConnectKit.framework/Versions/A/Modules/AliIotConnectKit.swiftmodule/Project/x86_64-apple-macos.swiftsourceinfo
MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AliIotConnectKit.framework/Versions/A/_CodeSignature/CodeResources
MouseSdk_Mac_V1.0.1/MouseSdk数据交互流程.pdf [deleted file]

index 1313ca9..016b1eb 100644 (file)
 ## SDK相关接口\r
 \r
 ```objective-c\r
-/// 单利\r
-+(AiMouse *)shared;\r
-\r
 /// 开始鉴权\r
-- (void)startAuthentication;\r
+/// - Parameter finished: 鉴权结果回调\r
+- (void)startAuthentication:(void (^)(AiMouseAuthState state))finished;\r
 \r
 ///  传输鉴权数据给sdk\r
 /// - Parameter data: 鉴权特征传过来的数据\r
 /// 传输业务数据给sdk\r
 /// - Parameter data:ai特征传过来的数据\r
 - (void)sendAiDataToSdk:(NSData *)data;\r
+\r
+///  传输设备信息数据给sdk\r
+/// - Parameter data:设备信息特征传过来的数据\r
+- (void)sendDeviceDataToSdk:(NSData *)data;\r
+\r
+/// 获取设备信息\r
+/// - Parameter completation: 如果获取成功,则deviceInfo有值,否则为空\r
+- (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))completation;\r
+\r
+/// 设置CPI\r
+/// - Parameters:\r
+///   - value: AiMouseDeviceInfo 中可以设置的值CPI_list\r
+///   - finished: 设置结果回调\r
+- (void)setCPI:(NSInteger)value completation:(void (^)(BOOL isSuccess,NSError *error))finished;\r
 ```\r
 \r
 ## SDK相关代理\r
 \r
 \r
 ```objective-c\r
-/// 鉴权状态回调\r
-/// - Parameter state:鉴权状态\r
-- (void)aiMouseAuthStateDidChange:(AiMouseAuthState)state;\r
-\r
 /// 鉴权数据回调,需要将此数据通过鉴权特征转发给蓝牙设备\r
 /// - Parameter data: 数据\r
 - (void)aiMouseSendAuthData:(NSData *)data;\r
 \r
+/// 设备信息数据回调,需要将此数据通过设备信息特征转发给蓝牙设备\r
+/// - Parameter data: 数据\r
+- (void)aiMouseSendDeviceInfoData:(NSData *)data;\r
+\r
 /// 鼠标按键指令回调\r
-/// - Parameter data: 数据。AI键0x42 单击   0x25 按下(开始录音)  0x26抬起(结束录音);   语音键0x31开始录音,0x32结束录音;OCR 按键  单击  0x41;其他未定义\r
+/// - Parameter data: 数据。\r
+/// M 键    短按0x42;长按按下(开始录音)0x25,  长按抬起(结束录音) 0x26;\r
+/// AI键  短按0x43  ,长按按下(开始录音)0x27,  长按抬起(结束录音) 0x28;\r
+/// 语音键 按下(开始录音) 0x31,弹起(结束录音)0x32;\r
+/// 其他未定义\r
 - (void)aiMouseSendCmdData:(NSData *)data;\r
 \r
 /// 录音回调\r
   #define kAiUUID @"0783B03E-8535-B5A0-7140-A304D2194CB8"\r
   //鉴权特征\r
   #define kAuthUUID @"0783B73E-8535-B5A0-7140-A304D2194CB7"\r
+  //设备信息特征\r
+  #define kDeviceInfoUUID @"0783B63E-8535-B5A0-7140-A304D2495CB6"\r
   ```\r
-\r
+  \r
   \r
 \r
 \r
 \r
-- 设置代理\r
+1. 设置代理\r
 \r
   ```objective-c\r
   [AiMouse shared].delegate = self;\r
   ```\r
 \r
-- 查找对应特征,订阅\r
+2. 查找对应特征,订阅\r
 \r
   ```\r
+  // 发现特征\r
   - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {\r
       for (CBCharacteristic *characteristic in service.characteristics){\r
           if ([characteristic.UUID.UUIDString isEqualToString:kAuthUUID]) {\r
+              //鉴权特征\r
               self.authCha = characteristic;\r
               [peripheral setNotifyValue:YES forCharacteristic:characteristic];\r
-              //开始鉴权\r
-              [[AiMouse shared] startAuthentication];\r
+              //找到鉴权特征后,一定要调用鉴权接口开始鉴权。只有鉴权通过了,sdk相关功能才可以使用\r
+              [[AiMouse shared] startAuthentication:^(AiMouseAuthState state) {\r
+                  [self showLog:[NSString stringWithFormat:@"鉴权结果 = %@",@(state)]];\r
+                  if(self.authCallBack){\r
+                      self.authCallBack(state == AiMouseAuthState_Success);\r
+                  }\r
+              }];\r
           }\r
           else if ([characteristic.UUID.UUIDString isEqualToString:kAiUUID]) {\r
+              //AI特征\r
               self.aiCha = characteristic;\r
               [peripheral setNotifyValue:YES forCharacteristic:characteristic];\r
           }\r
+          else if ([characteristic.UUID.UUIDString isEqualToString:kDeviceInfoUUID]) {\r
+              //设备信息特征\r
+              self.deviceInfoCha = characteristic;\r
+              [peripheral setNotifyValue:YES forCharacteristic:characteristic];\r
+          }\r
       }\r
   }\r
   ```\r
 \r
   \r
 \r
-- 收到设备传输过来的数据,传给sdk处理\r
+3. 收到设备传输过来的数据,传给sdk处理\r
 \r
   ```objective-c\r
+  //收到蓝牙数据\r
   - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {\r
       NSData *data = characteristic.value;\r
-      [self showLog:[NSString stringWithFormat:@"[receive] %@",[AiTools dataToHexString:data]]];\r
+      [self showLog:[NSString stringWithFormat:@"[receive] %@",[AiMouseTools dataToHexString:data]]];\r
       if([characteristic.UUID.UUIDString isEqualToString:kAuthUUID]){\r
           //鉴权数据\r
           [[AiMouse shared] sendAuthDataToSdk:data];\r
           //AI数据\r
           [[AiMouse shared] sendAiDataToSdk:data];\r
       }\r
+      else if([characteristic.UUID.UUIDString isEqualToString:kDeviceInfoUUID]){\r
+          //设备信息数据\r
+          [[AiMouse shared] sendDeviceDataToSdk:data];\r
+      }\r
   }\r
   \r
   ```\r
   sdk代理回调\r
 \r
   ```objective-c\r
-  /// 鉴权状态回调\r
-  /// - Parameter state:鉴权状态\r
-  -(void)aiMouseAuthStateDidChange:(AiMouseAuthState)state{\r
-      [self showLog:[NSString stringWithFormat:@"鉴权结果 = %@",@(state)]];\r
-  }\r
   /// 鉴权数据回调,需要将此数据转发给蓝牙设备\r
   /// - Parameter data: 数据\r
   - (void)aiMouseSendAuthData:(NSData *)data{\r
+      [self showLog:[NSString stringWithFormat:@"[send] %@",[AiMouseTools dataToHexString:data]]];\r
       [self.connectPeripheral writeValue:data forCharacteristic:self.authCha type:CBCharacteristicWriteWithoutResponse];\r
   }\r
+  \r
+  \r
+  /// 设备信息数据回调,需要将此数据通过设备信息特征转发给蓝牙设备\r
+  /// - Parameter data: 数据\r
+  -(void)aiMouseSendDeviceInfoData:(NSData *)data{\r
+      [self showLog:[NSString stringWithFormat:@"[send] %@",[AiMouseTools dataToHexString:data]]];\r
+      [self.connectPeripheral writeValue:data forCharacteristic:self.deviceInfoCha type:CBCharacteristicWriteWithoutResponse];\r
+  }\r
+  \r
   /// 鼠标按键指令回调\r
-  /// - Parameter data: 数据。AI键0x42 单击   0x25 按下(开始录音)  0x26抬起(结束录音);   语音键0x31开始录音,0x32结束录音;OCR 按键  单击  0x41;其他未定义\r
+  /// - Parameter data: 数据。\r
+  /// M 键    短按0x42;长按按下(开始录音)0x25,  长按抬起(结束录音) 0x26;\r
+  /// AI键  短按0x43  ,长按按下(开始录音)0x27,  长按抬起(结束录音) 0x28;\r
+  /// 语音键 按下(开始录音) 0x31,弹起(结束录音)0x32;\r
+  /// 其他未定义\r
   - (void)aiMouseSendCmdData:(NSData *)data{\r
-      NSString *cmd = [[AiTools dataToHexString:data] lowercaseString];\r
-      if([cmd hasSuffix:@"31"]){\r
-          [self showLog:@"录音键开始录音"];\r
+      uint8 cmd;\r
+      [data getBytes:&cmd length:1];\r
+      if(cmd == 0x25){\r
+          [self showLog:@"M键开始录音"];\r
           self.recordData = [[NSMutableData alloc] init];\r
       }\r
-      else if([cmd hasSuffix:@"32"]){\r
-          [self showLog:@"录音键结束录音"];\r
+      else if(cmd == 0x26){\r
+          [self showLog:@"M键结束录音"];\r
           [self finishRecored:self.recordData];\r
       }\r
-      if([cmd hasSuffix:@"25"]){\r
+      else if(cmd == 0x27){\r
           [self showLog:@"AI键开始录音"];\r
           self.recordData = [[NSMutableData alloc] init];\r
       }\r
-      else if([cmd hasSuffix:@"26"]){\r
+      else if(cmd == 0x28){\r
           [self showLog:@"AI键结束录音"];\r
           [self finishRecored:self.recordData];\r
       }\r
+      else if(cmd == 0x31){\r
+          [self showLog:@"语音键开始录音"];\r
+          self.recordData = [[NSMutableData alloc] init];\r
+      }\r
+      else if(cmd == 0x32){\r
+          [self showLog:@"语音键结束录音"];\r
+          [self finishRecored:self.recordData];\r
+      }\r
       else{\r
           [self showLog:@"未定义指令!!!!!!!!"];\r
       }\r
       [self.recordData appendData:data];\r
   }\r
   ```\r
+\r
+  获取设备信息\r
+\r
+- 获取设备信息\r
+\r
+  ```\r
+      [[AiMouse shared] getDeviceInfo:^(AiMouseDeviceInfo *deviceInfo, NSError *error) {\r
   \r
+      }];\r
+  ```\r
+\r
   \r
 \r
+- 设置PCI\r
+\r
+  ```\r
+      [[AiMouse shared] setCPI:1000 completation:^(BOOL isSuccess, NSError *error) {\r
+          \r
+      }];\r
+  ```\r
+\r
   \r
 \r
+\r
+\r
 ## 注意事项\r
 \r
 - 鉴权数据使用的是鉴权特征,走鉴权接口;AI数据使用的是AI特征,走AI接口。\r
index 19f0f9e..4f8566e 100644 (file)
Binary files "a/Document/\346\225\260\346\215\256\344\272\244\344\272\222\346\265\201\347\250\213.eddx" and "b/Document/\346\225\260\346\215\256\344\272\244\344\272\222\346\265\201\347\250\213.eddx" differ
index 49a6812..fd49e55 100644 (file)
@@ -16,10 +16,6 @@ typedef NS_ENUM(NSInteger,AiMouseAuthState) {
 
 @protocol AiMouseDelegate <NSObject>
 
-/// 鉴权状态回调
-/// - Parameter state:鉴权状态
-- (void)aiMouseAuthStateDidChange:(AiMouseAuthState)state;
-
 /// 鉴权数据回调,需要将此数据通过鉴权特征转发给蓝牙设备
 /// - Parameter data: 数据
 - (void)aiMouseSendAuthData:(NSData *)data;
@@ -29,7 +25,11 @@ typedef NS_ENUM(NSInteger,AiMouseAuthState) {
 - (void)aiMouseSendDeviceInfoData:(NSData *)data;
 
 /// 鼠标按键指令回调
-/// - Parameter data: 数据。AI键0x42 单击   0x25 按下(开始录音)  0x26抬起(结束录音);   语音键0x31开始录音,0x32结束录音;OCR 按键  单击  0x41;其他未定义
+/// - Parameter data: 数据。
+/// M 键    短按0x42;长按按下(开始录音)0x25,  长按抬起(结束录音) 0x26;
+/// AI键  短按0x43  ,长按按下(开始录音)0x27,  长按抬起(结束录音) 0x28;
+/// 语音键 按下(开始录音) 0x31,弹起(结束录音)0x32;
+/// 其他未定义
 - (void)aiMouseSendCmdData:(NSData *)data;
 
 /// 录音回调
@@ -46,8 +46,10 @@ typedef NS_ENUM(NSInteger,AiMouseAuthState) {
 /// 单利
 +(AiMouse *)shared;
 
+
 /// 开始鉴权
-- (void)startAuthentication;
+/// - Parameter finished: 鉴权结果回调
+- (void)startAuthentication:(void (^)(AiMouseAuthState state))finished;
 
 ///  传输鉴权数据给sdk
 /// - Parameter data: 鉴权特征传过来的数据
index f0c35e1..8a8266d 100644 (file)
@@ -19,6 +19,7 @@
 @property (nonatomic, strong) AiMouseDeviceInfo *deviceInfo;
 @property (nonatomic, strong) void (^deviceInfoBlock)(AiMouseDeviceInfo *deviceInfo,NSError *error);
 @property (nonatomic, strong) void (^setCPIBlock)(BOOL isSuccess,NSError *error);
+@property (nonatomic, strong) void (^authBlock)(AiMouseAuthState state);
 @end
 
 @implementation AiMouse
@@ -39,7 +40,7 @@
 }
 
 -(NSString *)version{
-    return @"1.0.1";
+    return @"1.0.2";
 }
 -(AiFrameManager *)frameManager{
     if (!_frameManager) {
@@ -86,8 +87,9 @@
     
 }
 //开始鉴权
-- (void)startAuthentication{
+- (void)startAuthentication:(void (^)(AiMouseAuthState))finished{
     _authState = AiMouseAuthState_Unknow;
+    self.authBlock = finished;
     [self.authManager login];
 }
 
     //    0A65004E003200010101C0C10000A5A5
     if(data.length == 16){
         NSData *cmd = [data subdataWithRange:NSMakeRange(5, 1)];
+//        NSString *cmdStr = [[AiMouseTools dataToHexString:cmd] lowercaseString];
+//        NSLog(@"cmd = %@",cmdStr);
         [self sendCmdData:cmd];
     }
     else if([cmd hasPrefix:@"9c31"]){
 }
 
 -(void)sendDeviceDataToSdk:(NSData *)data{
-    NSLog(@"======%@",[AiMouseTools dataToUtf8String:data]);
     NSDictionary *dict = [AiMouseTools dataToDictionary:data];
+    NSString *str = [AiMouseTools dictionaryToString:dict];
+    [self showLog:str];
     if(dict[@"set_config"]){
         if([dict[@"set_config"] intValue] == 1){
             if(self.setCPIBlock)self.setCPIBlock(true, nil);
     }
 }
 - (void)sendCmdData:(NSData *)data{
-    if (self.authState != AiMouseAuthState_Success) return;
-    if (self.delegate) {
-        [self.delegate aiMouseSendCmdData:data];
+    if (self.authState == AiMouseAuthState_Success){
+        if (self.delegate) {
+            [self.delegate aiMouseSendCmdData:data];
+        }
+    }
+    else{
+//        [self showLog:@"设备鉴权失败"];
     }
+
 }
 
 - (void)authResult:(BOOL)isSuccess{
     _authState = isSuccess ? AiMouseAuthState_Success:AiMouseAuthState_Failure;
-    if (self.delegate) {
-        [self.delegate aiMouseAuthStateDidChange:self.authState];
-    }
+    self.authBlock(_authState);
     [self setAuthStateToDevice:isSuccess];
 }
 - (void)showLog:(NSString *)log{
-    //    NSLog(@"[sdk]%@",log);
+//        NSLog(@"[sdk]%@",log);
 }
 
 - (void)sendTestLP{
index 68aa75f..c9badbb 100644 (file)
Binary files a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate and b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate differ
index 4e8679f..215ac45 100644 (file)
@@ -15,8 +15,7 @@
 #define kAiUUID @"0783B03E-8535-B5A0-7140-A304D2194CB8"
 //鉴权特征
 #define kAuthUUID @"0783B73E-8535-B5A0-7140-A304D2194CB7"
-//#define kAuthUUID @"0783B03E-8535-B5A0-7140-A304D2194CB7"
-//获取设备信息特征
+//设备信息特征
 #define kDeviceInfoUUID @"0783B63E-8535-B5A0-7140-A304D2495CB6"
 
 @interface BleManager ()<CBCentralManagerDelegate,CBPeripheralDelegate,AiMouseDelegate>
 - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
     for (CBCharacteristic *characteristic in service.characteristics){
         if ([characteristic.UUID.UUIDString isEqualToString:kAuthUUID]) {
+            //鉴权特征
             self.authCha = characteristic;
             [peripheral setNotifyValue:YES forCharacteristic:characteristic];
-            //开始鉴权
-            [[AiMouse shared] startAuthentication];
+            //找到鉴权特征后,一定要调用鉴权接口开始鉴权。只有鉴权通过了,sdk相关功能才可以使用
+            [[AiMouse shared] startAuthentication:^(AiMouseAuthState state) {
+                [self showLog:[NSString stringWithFormat:@"鉴权结果 = %@",@(state)]];
+                if(self.authCallBack){
+                    self.authCallBack(state == AiMouseAuthState_Success);
+                }
+            }];
         }
         else if ([characteristic.UUID.UUIDString isEqualToString:kAiUUID]) {
+            //AI特征
             self.aiCha = characteristic;
             [peripheral setNotifyValue:YES forCharacteristic:characteristic];
         }
         else if ([characteristic.UUID.UUIDString isEqualToString:kDeviceInfoUUID]) {
+            //设备信息特征
             self.deviceInfoCha = characteristic;
             [peripheral setNotifyValue:YES forCharacteristic:characteristic];
         }
 }
 
 #pragma mark - AiDelegate
-/// 鉴权状态回调
-/// - Parameter state:鉴权状态
--(void)aiMouseAuthStateDidChange:(AiMouseAuthState)state{
-    [self showLog:[NSString stringWithFormat:@"鉴权结果 = %@",@(state)]];
-    if(self.authCallBack){
-        self.authCallBack(state == AiMouseAuthState_Success);
-    }
-}
 /// 鉴权数据回调,需要将此数据转发给蓝牙设备
 /// - Parameter data: 数据
 - (void)aiMouseSendAuthData:(NSData *)data{
 }
 
 /// 鼠标按键指令回调
-/// - Parameter data: 数据。AI键0x42 单击   0x25 按下(开始录音)  0x26抬起(结束录音);   语音键0x31开始录音,0x32结束录音;OCR 按键  单击  0x41;其他未定义
+/// - Parameter data: 数据。
+/// M 键    短按0x42;长按按下(开始录音)0x25,  长按抬起(结束录音) 0x26;
+/// AI键  短按0x43  ,长按按下(开始录音)0x27,  长按抬起(结束录音) 0x28;
+/// 语音键 按下(开始录音) 0x31,弹起(结束录音)0x32;
+/// 其他未定义
 - (void)aiMouseSendCmdData:(NSData *)data{
-    NSString *cmd = [[AiMouseTools dataToHexString:data] lowercaseString];
-    if([cmd hasSuffix:@"31"]){
-        [self showLog:@"录音键开始录音"];
+    uint8 cmd;
+    [data getBytes:&cmd length:1];
+    if(cmd == 0x25){
+        [self showLog:@"M键开始录音"];
         self.recordData = [[NSMutableData alloc] init];
     }
-    else if([cmd hasSuffix:@"32"]){
-        [self showLog:@"录音键结束录音"];
+    else if(cmd == 0x26){
+        [self showLog:@"M键结束录音"];
         [self finishRecored:self.recordData];
     }
-    if([cmd hasSuffix:@"25"]){
+    else if(cmd == 0x27){
         [self showLog:@"AI键开始录音"];
         self.recordData = [[NSMutableData alloc] init];
     }
-    else if([cmd hasSuffix:@"26"]){
+    else if(cmd == 0x28){
         [self showLog:@"AI键结束录音"];
         [self finishRecored:self.recordData];
     }
+    else if(cmd == 0x31){
+        [self showLog:@"语音键开始录音"];
+        self.recordData = [[NSMutableData alloc] init];
+    }
+    else if(cmd == 0x32){
+        [self showLog:@"语音键结束录音"];
+        [self finishRecored:self.recordData];
+    }
     else{
         [self showLog:@"未定义指令!!!!!!!!"];
     }
index a821b72..63bd155 100644 (file)
@@ -7,7 +7,6 @@
 
 #import "ViewController.h"
 #import "ScanVC.h"
-#import "AiMouseTools.h"
 #import "BleManager.h"
 
 
diff --git a/MouseSdk_Mac_V1.0.1/AiMouseSDK数据交互流程.pdf b/MouseSdk_Mac_V1.0.1/AiMouseSDK数据交互流程.pdf
new file mode 100644 (file)
index 0000000..fa7982d
Binary files /dev/null and "b/MouseSdk_Mac_V1.0.1/AiMouseSDK\346\225\260\346\215\256\344\272\244\344\272\222\346\265\201\347\250\213.pdf" differ
index 1617375..0602c55 100644 (file)
Binary files "a/MouseSdk_Mac_V1.0.1/AiMouseSdk\346\216\245\345\217\243\346\226\207\346\241\243.pdf" and "b/MouseSdk_Mac_V1.0.1/AiMouseSdk\346\216\245\345\217\243\346\226\207\346\241\243.pdf" differ
index 2a45334..b0b63fd 100644 (file)
Binary files a/MouseSdk_Mac_V1.0.1/MouseSdkDemo/MouseSdkDemo.xcodeproj/project.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate and b/MouseSdk_Mac_V1.0.1/MouseSdkDemo/MouseSdkDemo.xcodeproj/project.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate differ
index 6e3749e..d98b352 100644 (file)
@@ -7,11 +7,12 @@
 
 #import <Foundation/Foundation.h>
 #import <CoreBluetooth/CoreBluetooth.h>
+#import <AiMouseSdk/AiMouseDeviceInfo.h>
 
 #define kDidConnectBleNotification @"kDidConnectBleNotification"
 #define kDidDisconnectBleNotification @"kDidDisconnectBleNotification"
 
-NS_ASSUME_NONNULL_BEGIN
+
 
 @interface BleManager : NSObject
 @property (nonatomic,strong)void (^discoverDevice)(CBPeripheral *peripheral) ;/// 扫描到设备
@@ -30,8 +31,8 @@ NS_ASSUME_NONNULL_BEGIN
 /// - Parameter peripheral: 蓝牙设备
 - (void)connectPeripheral:(CBPeripheral *)peripheral;
 
-/// 开始鉴权
-- (void)startAuthentication;
+/// 获取设备信息
+- (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))completation;
+
 @end
 
-NS_ASSUME_NONNULL_END
index e33a4f4..215ac45 100644 (file)
 //ai特征
 #define kAiUUID @"0783B03E-8535-B5A0-7140-A304D2194CB8"
 //鉴权特征
-//#define kAuthUUID @"0783B73E-8535-B5A0-7140-A304D2194CB7"
-#define kAuthUUID @"0783B03E-8535-B5A0-7140-A304D2194CB7"
+#define kAuthUUID @"0783B73E-8535-B5A0-7140-A304D2194CB7"
+//设备信息特征
+#define kDeviceInfoUUID @"0783B63E-8535-B5A0-7140-A304D2495CB6"
 
 @interface BleManager ()<CBCentralManagerDelegate,CBPeripheralDelegate,AiMouseDelegate>
 @property(nonatomic, strong) CBCentralManager *centralManager;///蓝牙管理
 @property(nonatomic, strong) CBPeripheral *connectPeripheral;//连接的设备
 @property(nonatomic, strong) CBCharacteristic *authCha;//鉴权特征
 @property(nonatomic, strong) CBCharacteristic *aiCha;//ai特征
+@property(nonatomic, strong) CBCharacteristic *deviceInfoCha;//设备信息特征
 @property (nonatomic,strong) NSMutableData *recordData;//录音的数据
 @end
 
 - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
     for (CBCharacteristic *characteristic in service.characteristics){
         if ([characteristic.UUID.UUIDString isEqualToString:kAuthUUID]) {
+            //鉴权特征
             self.authCha = characteristic;
             [peripheral setNotifyValue:YES forCharacteristic:characteristic];
+            //找到鉴权特征后,一定要调用鉴权接口开始鉴权。只有鉴权通过了,sdk相关功能才可以使用
+            [[AiMouse shared] startAuthentication:^(AiMouseAuthState state) {
+                [self showLog:[NSString stringWithFormat:@"鉴权结果 = %@",@(state)]];
+                if(self.authCallBack){
+                    self.authCallBack(state == AiMouseAuthState_Success);
+                }
+            }];
         }
         else if ([characteristic.UUID.UUIDString isEqualToString:kAiUUID]) {
+            //AI特征
             self.aiCha = characteristic;
             [peripheral setNotifyValue:YES forCharacteristic:characteristic];
         }
+        else if ([characteristic.UUID.UUIDString isEqualToString:kDeviceInfoUUID]) {
+            //设备信息特征
+            self.deviceInfoCha = characteristic;
+            [peripheral setNotifyValue:YES forCharacteristic:characteristic];
+        }
     }
 }
 //收到蓝牙数据
 - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
     NSData *data = characteristic.value;
-    [self showLog:[NSString stringWithFormat:@"[receive] %@",[AiTools dataToHexString:data]]];
+    [self showLog:[NSString stringWithFormat:@"[receive] %@",[AiMouseTools dataToHexString:data]]];
     if([characteristic.UUID.UUIDString isEqualToString:kAuthUUID]){
         //鉴权数据
         [[AiMouse shared] sendAuthDataToSdk:data];
         //AI数据
         [[AiMouse shared] sendAiDataToSdk:data];
     }
+    else if([characteristic.UUID.UUIDString isEqualToString:kDeviceInfoUUID]){
+        //设备信息数据
+        [[AiMouse shared] sendDeviceDataToSdk:data];
+    }
 }
 
 #pragma mark - AiDelegate
-/// 鉴权状态回调
-/// - Parameter isSuccess:是否鉴权成功
--(void)aiMouseAuthCallBack:(BOOL)isSuccess{
-    [self showLog:[NSString stringWithFormat:@"鉴权结果 = %@",@(isSuccess)]];
-    if(self.authCallBack){
-        self.authCallBack(isSuccess);
-    }
-}
 /// 鉴权数据回调,需要将此数据转发给蓝牙设备
 /// - Parameter data: 数据
 - (void)aiMouseSendAuthData:(NSData *)data{
-    [self showLog:[NSString stringWithFormat:@"[send] %@",[AiTools dataToHexString:data]]];
+    [self showLog:[NSString stringWithFormat:@"[send] %@",[AiMouseTools dataToHexString:data]]];
     [self.connectPeripheral writeValue:data forCharacteristic:self.authCha type:CBCharacteristicWriteWithoutResponse];
 }
+
+
+/// 设备信息数据回调,需要将此数据通过设备信息特征转发给蓝牙设备
+/// - Parameter data: 数据
+-(void)aiMouseSendDeviceInfoData:(NSData *)data{
+    [self showLog:[NSString stringWithFormat:@"[send] %@",[AiMouseTools dataToHexString:data]]];
+    [self.connectPeripheral writeValue:data forCharacteristic:self.deviceInfoCha type:CBCharacteristicWriteWithoutResponse];
+}
+
 /// 鼠标按键指令回调
-/// - Parameter data: 数据。AI键0x42 单击   0x25 按下(开始录音)  0x26抬起(结束录音);   语音键0x31开始录音,0x32结束录音;OCR 按键  单击  0x41;其他未定义
+/// - Parameter data: 数据。
+/// M 键    短按0x42;长按按下(开始录音)0x25,  长按抬起(结束录音) 0x26;
+/// AI键  短按0x43  ,长按按下(开始录音)0x27,  长按抬起(结束录音) 0x28;
+/// 语音键 按下(开始录音) 0x31,弹起(结束录音)0x32;
+/// 其他未定义
 - (void)aiMouseSendCmdData:(NSData *)data{
-    NSString *cmd = [[AiTools dataToHexString:data] lowercaseString];
-    if([cmd hasSuffix:@"31"]){
-        [self showLog:@"录音键开始录音"];
+    uint8 cmd;
+    [data getBytes:&cmd length:1];
+    if(cmd == 0x25){
+        [self showLog:@"M键开始录音"];
         self.recordData = [[NSMutableData alloc] init];
     }
-    else if([cmd hasSuffix:@"32"]){
-        [self showLog:@"录音键结束录音"];
+    else if(cmd == 0x26){
+        [self showLog:@"M键结束录音"];
         [self finishRecored:self.recordData];
     }
-    if([cmd hasSuffix:@"25"]){
+    else if(cmd == 0x27){
         [self showLog:@"AI键开始录音"];
         self.recordData = [[NSMutableData alloc] init];
     }
-    else if([cmd hasSuffix:@"26"]){
+    else if(cmd == 0x28){
         [self showLog:@"AI键结束录音"];
         [self finishRecored:self.recordData];
     }
+    else if(cmd == 0x31){
+        [self showLog:@"语音键开始录音"];
+        self.recordData = [[NSMutableData alloc] init];
+    }
+    else if(cmd == 0x32){
+        [self showLog:@"语音键结束录音"];
+        [self finishRecored:self.recordData];
+    }
     else{
         [self showLog:@"未定义指令!!!!!!!!"];
     }
     [self.centralManager connectPeripheral:peripheral options:@{CBConnectPeripheralOptionNotifyOnConnectionKey : [NSNumber numberWithBool:YES]}];
 }
 
-/// 开始鉴权
-- (void)startAuthentication{
-    [[AiMouse shared] startAuthentication];
+/// 获取设备信息
+- (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo * _Nonnull, NSError * _Nonnull))completation{
+    [[AiMouse shared] getDeviceInfo:completation];
 }
-
 #pragma mark - other
 //自动连接,获取已配对的蓝牙,取第一个连接
 - (void)autoConnectDevice{
         return;
     }
     NSArray<CBPeripheral *> *devices = [self.centralManager retrieveConnectedPeripheralsWithServices:@[[CBUUID UUIDWithString:kServiceUUID]]];
-    for (CBPeripheral *peripheral in devices) {
+    if (devices.count > 0) {
+        CBPeripheral *peripheral = devices[0];
         [self showLog:[NSString stringWithFormat:@"匹配过的设备%@",peripheral.name]];
         [self connectPeripheral:peripheral];
-        break;
     }
     // 10s自动重连
     [self performSelector:@selector(autoConnectDevice) withObject:nil afterDelay:10];
index 8dd850e..63bd155 100644 (file)
@@ -9,6 +9,7 @@
 #import "ScanVC.h"
 #import "BleManager.h"
 
+
 @interface ViewController ()
 
 @property(nonatomic,strong)NSTextField *connectLabel;
@@ -36,7 +37,7 @@
     self.title = @"AI SDK";
 
     {
-        NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(100, self.view.bounds.size.height - 120, 100, 45)];
+        NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(100, self.view.bounds.size.height - 100, 100, 45)];
         btn.bordered = true;
         btn.title = @"扫描";
         [btn setTarget:self];
         btn.state = 1;
         [self.view addSubview:btn];
     }
-    {
-        NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(100, self.view.bounds.size.height - 200, 100, 45)];
-        btn.bordered = true;
-        btn.title = @"鉴权";
-        [btn setTarget:self];
-        [btn setAction:@selector(checkAuth)];
-        btn.state = 1;
-        [self.view addSubview:btn];
-    }
     {
         NSTextField *label = [[NSTextField alloc] initWithFrame:CGRectMake(230, self.view.bounds.size.height - 120, 200, 35)];
         label.editable = NO;
         NSTextField *label = [[NSTextField alloc] initWithFrame:CGRectMake(230, self.view.bounds.size.height - 200, 200, 35)];
         label.editable = NO;
         label.bordered = NO;
-        label.stringValue = @"鉴权状态:--";
+        label.stringValue = @"鉴权状态:unknow";
         label.backgroundColor = NSColor.clearColor;
         self.autoLabel = label;
         [self.view addSubview:label];
     }
+    {
+        NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(100, self.view.bounds.size.height - 200, 100, 45)];
+        btn.bordered = true;
+        btn.title = @"获取设备信息";
+        [btn setTarget:self];
+        [btn setAction:@selector(getDeviceInfoAction)];
+        btn.state = 1;
+        [self.view addSubview:btn];
+    }
 }
 - (void)setupBleManger{
     BleManager *manager = [BleManager shared];
     [self presentViewControllerAsModalWindow:vc];
 }
 
-- (void)checkAuth{
-    [[BleManager shared] startAuthentication];
+- (void)getDeviceInfoAction{
+    [[BleManager shared] getDeviceInfo:^(AiMouseDeviceInfo *deviceInfo, NSError *error) {
+        if (deviceInfo) {
+            NSLog(@"battery_power = %@,CPI = %@,CPI_list = %@,version = %@,brand = %@,sn = %@,mac = %@,",deviceInfo.battery_power,deviceInfo.CPI,deviceInfo.CPI_list,deviceInfo.version,deviceInfo.brand,deviceInfo.sn,deviceInfo.mac);
+        }
+        else{
+            NSLog(@"get deivce info error == %@",error.description);
+        }
+    }];
 }
 
 - (void)showAuthResult:(BOOL)isSuccess{
     dispatch_async(dispatch_get_main_queue(), ^{
-        self.autoLabel.stringValue = isSuccess?@"é\89´æ\9d\83ç»\93æ\9e\9cï¼\9aé\89´æ\9d\83æ\88\90å\8a\9f":@"é\89´æ\9d\83ç»\93æ\9e\9c:鉴权失败";
+        self.autoLabel.stringValue = isSuccess?@"é\89´æ\9d\83ç\8a¶æ\80\81ï¼\9aé\89´æ\9d\83æ\88\90å\8a\9f":@"é\89´æ\9d\83ç\8a¶æ\80\81:鉴权失败";
     });
 }
 
index 6359958..22e2791 100755 (executable)
Binary files a/MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AiMouseSdk.framework/Versions/A/AiMouseSdk and b/MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AiMouseSdk.framework/Versions/A/AiMouseSdk differ
index 1871b65..fd49e55 100644 (file)
@@ -6,21 +6,30 @@
 //
 
 #import <Foundation/Foundation.h>
+#import <AiMouseSdk/AiMouseDeviceInfo.h>
 
-NS_ASSUME_NONNULL_BEGIN
+typedef NS_ENUM(NSInteger,AiMouseAuthState) {
+    AiMouseAuthState_Unknow = 0,///未知
+    AiMouseAuthState_Success,///鉴权成功
+    AiMouseAuthState_Failure///鉴权失败
+};
 
 @protocol AiMouseDelegate <NSObject>
 
-/// 鉴权状态回调
-/// - Parameter isSuccess:是否鉴权成功
-- (void)aiMouseAuthCallBack:(BOOL)isSuccess;
-
-/// 鉴权数据回调,需要将此数据转发给蓝牙设备
+/// 鉴权数据回调,需要将此数据通过鉴权特征转发给蓝牙设备
 /// - Parameter data: 数据
 - (void)aiMouseSendAuthData:(NSData *)data;
 
+/// 设备信息数据回调,需要将此数据通过设备信息特征转发给蓝牙设备
+/// - Parameter data: 数据
+- (void)aiMouseSendDeviceInfoData:(NSData *)data;
+
 /// 鼠标按键指令回调
-/// - Parameter data: 数据。AI键0x42 单击   0x25 按下(开始录音)  0x26抬起(结束录音);   语音键0x31开始录音,0x32结束录音;OCR 按键  单击  0x41;其他未定义
+/// - Parameter data: 数据。
+/// M 键    短按0x42;长按按下(开始录音)0x25,  长按抬起(结束录音) 0x26;
+/// AI键  短按0x43  ,长按按下(开始录音)0x27,  长按抬起(结束录音) 0x28;
+/// 语音键 按下(开始录音) 0x31,弹起(结束录音)0x32;
+/// 其他未定义
 - (void)aiMouseSendCmdData:(NSData *)data;
 
 /// 录音回调
@@ -32,12 +41,15 @@ NS_ASSUME_NONNULL_BEGIN
 @interface AiMouse : NSObject
 @property (nonatomic, readonly) NSString *version;/// 版本号
 @property (nonatomic, weak) id<AiMouseDelegate> delegate;/// 代理
+@property (nonatomic, readonly) AiMouseAuthState authState;/// 鉴权状态,默认是Unknow。所以必须在连上蓝牙设备找到鉴权特征后,需要主动调用startAuthentication方法去鉴权。(只有鉴权成功,AI键,语音键、M键才可用)
 
 /// 单利
 +(AiMouse *)shared;
 
+
 /// 开始鉴权
-- (void)startAuthentication;
+/// - Parameter finished: 鉴权结果回调
+- (void)startAuthentication:(void (^)(AiMouseAuthState state))finished;
 
 ///  传输鉴权数据给sdk
 /// - Parameter data: 鉴权特征传过来的数据
@@ -46,6 +58,19 @@ NS_ASSUME_NONNULL_BEGIN
 /// 传输业务数据给sdk
 /// - Parameter data:ai特征传过来的数据
 - (void)sendAiDataToSdk:(NSData *)data;
+
+///  传输设备信息数据给sdk
+/// - Parameter data:设备信息特征传过来的数据
+- (void)sendDeviceDataToSdk:(NSData *)data;
+
+/// 获取设备信息
+/// - Parameter completation: 如果获取成功,则deviceInfo有值,否则为空
+- (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))completation;
+
+/// 设置CPI
+/// - Parameters:
+///   - value: AiMouseDeviceInfo 中可以设置的值CPI_list
+///   - finished: 设置结果回调
+- (void)setCPI:(NSInteger)value completation:(void (^)(BOOL isSuccess,NSError *error))finished;
 @end
 
-NS_ASSUME_NONNULL_END
diff --git a/MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AiMouseSdk.framework/Versions/A/Headers/AiMouseDeviceInfo.h b/MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AiMouseSdk.framework/Versions/A/Headers/AiMouseDeviceInfo.h
new file mode 100644 (file)
index 0000000..55e48da
--- /dev/null
@@ -0,0 +1,22 @@
+//
+//  AiMouseDeviceInfo.h
+//  AiMouseSdk
+//
+//  Created by incar on 2024/3/19.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface AiMouseDeviceInfo : NSObject
+@property (nonatomic, strong) NSString *battery_power;/// 电池百分百电量,0-100
+@property (nonatomic, strong) NSString *CPI;/// CPI值
+@property (nonatomic, strong) NSString *CPI_list;/// 可设置的CPI参数列表
+@property (nonatomic, strong) NSString *version;///软件版本
+@property (nonatomic, strong) NSString *brand;/// 品牌名称
+@property (nonatomic, strong) NSString *sn;/// 设备序列号
+@property (nonatomic, strong) NSString *mac;///设备MAC地址
+@end
+
+NS_ASSUME_NONNULL_END
index 68bada9..cf5694d 100644 (file)
@@ -16,4 +16,4 @@
 // In this header, you should import all the public headers of your framework using statements like #import <AiMouse/PublicHeader.h>
 
 #import <AiMouseSdk/AiMouse.h>
-#import <AiMouseSdk/AiTools.h>
+#import <AiMouseSdk/AiMouseTools.h>
@@ -1,5 +1,5 @@
 //
-//  AiTools.h
+//  AiMouseTools.h
 //  AiMouse
 //
 //  Created by incar on 2024/2/28.
@@ -9,7 +9,7 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
-@interface AiTools : NSObject
+@interface AiMouseTools : NSObject
 + (NSArray *)stringToArray:(NSString *)jsonString;
 + (NSString *)arrayToString:(NSArray *)arr;
 
index 2f9b9d7..2e3010c 100644 (file)
                <dict>
                        <key>hash2</key>
                        <data>
-                       har0X31Bg3x/RfWyhwbYkvdiNtDuAW93gKXIukmzbnI=
+                       7pIlETACg6jIAd8J1lBfoYKnQDcqmUBJga9MBIHdYQI=
+                       </data>
+               </dict>
+               <key>Headers/AiMouseDeviceInfo.h</key>
+               <dict>
+                       <key>hash2</key>
+                       <data>
+                       HhcoSLyB8eJaTzjLsGUFNtXXbys2JgQ4ehvTrgNDT6g=
                        </data>
                </dict>
                <key>Headers/AiMouseSdk.h</key>
                <dict>
                        <key>hash2</key>
                        <data>
-                       j3S7YhhAJBjrITuEo8XsYFmRefNYfkH8pYoLt6l/dGw=
+                       vKnPzInbrOTjtIQqZKZvozSl9iFo3gPJOWEkCrYBwY0=
                        </data>
                </dict>
-               <key>Headers/AiTools.h</key>
+               <key>Headers/AiMouseTools.h</key>
                <dict>
                        <key>hash2</key>
                        <data>
-                       8DpdJ1sLCY5dB4myv+oBOy3h1eFuzr6umt52e4gVDro=
+                       nNnZHOXG/JWO8UXAkwiP7mC1x/p4M4vchU5UR+jX/z8=
                        </data>
                </dict>
                <key>Modules/module.modulemap</key>
index 86382c0..1d27be7 100755 (executable)
Binary files a/MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AliIotConnectKit.framework/Versions/A/AliIotConnectKit and b/MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AliIotConnectKit.framework/Versions/A/AliIotConnectKit differ
index 4b0fa92..cab3143 100644 (file)
Binary files a/MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AliIotConnectKit.framework/Versions/A/Modules/AliIotConnectKit.swiftmodule/Project/arm64-apple-macos.swiftsourceinfo and b/MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AliIotConnectKit.framework/Versions/A/Modules/AliIotConnectKit.swiftmodule/Project/arm64-apple-macos.swiftsourceinfo differ
index efecf06..9b6bb95 100644 (file)
Binary files a/MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AliIotConnectKit.framework/Versions/A/Modules/AliIotConnectKit.swiftmodule/Project/x86_64-apple-macos.swiftsourceinfo and b/MouseSdk_Mac_V1.0.1/MouseSdkDemo/framework/AliIotConnectKit.framework/Versions/A/Modules/AliIotConnectKit.swiftmodule/Project/x86_64-apple-macos.swiftsourceinfo differ
index a15de84..2b2b83f 100644 (file)
                <dict>
                        <key>hash2</key>
                        <data>
-                       6ifxDxFkXyt1ny27eGGdB3fY7NAeisYepFOGrop5gow=
+                       FfGjeGCxTCx7ayLfCPgaan92ZPyOTsf6WkcMV/qOCw0=
                        </data>
                </dict>
                <key>Modules/AliIotConnectKit.swiftmodule/Project/x86_64-apple-macos.swiftsourceinfo</key>
                <dict>
                        <key>hash2</key>
                        <data>
-                       loR5HquD534eJ4A9BtA1sjTb9/SToenOxsbj1U6A06o=
+                       hTADtwRw04Q8S4kKt2x0FSF+IHoyQMr5BEQki1s2Lwk=
                        </data>
                </dict>
                <key>Modules/AliIotConnectKit.swiftmodule/arm64-apple-macos.abi.json</key>
diff --git a/MouseSdk_Mac_V1.0.1/MouseSdk数据交互流程.pdf b/MouseSdk_Mac_V1.0.1/MouseSdk数据交互流程.pdf
deleted file mode 100644 (file)
index 9251b02..0000000
Binary files "a/MouseSdk_Mac_V1.0.1/MouseSdk\346\225\260\346\215\256\344\272\244\344\272\222\346\265\201\347\250\213.pdf" and /dev/null differ