泰凌微2代完成鉴权 M8 tlw2
authorliangzhenying <867174124@qq.com>
Mon, 28 Apr 2025 09:40:00 +0000 (17:40 +0800)
committerliangzhenying <867174124@qq.com>
Mon, 28 Apr 2025 09:40:00 +0000 (17:40 +0800)
21 files changed:
MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/project.pbxproj
MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist
MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.m
MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m
MouseSdk/AiMouseSdk/AiMouseSdk/AiSender.m
MouseSdk/AiMouseSdk/AiMouseSdk/SbcConverter.m
MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.h
MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.m
MouseSdk/AiMouseSdk/Keyboard/KeyboardHidManager.m
MouseSdk/AiMouseSdk/M8/M8MouseSdk.m
MouseSdk/AiMouseSdk/Manager/BleManager.h
MouseSdk/AiMouseSdk/Manager/BleManager.m
MouseSdk/AiMouseSdk/Manager/DeviceManger.m
MouseSdk/AiMouseSdk/Manager/HidManager.m
MouseSdk/AiMouseSdk/Manager/TimerManager.m
MouseSdk/AiMouseSdk/TlwMouseSdk/Tlw2ReceiveManager.h [new file with mode: 0644]
MouseSdk/AiMouseSdk/TlwMouseSdk/Tlw2ReceiveManager.m [new file with mode: 0644]
MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m
MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate
MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
MouseSdk/Pods/Pods.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist

index aec594a..cd430a2 100644 (file)
                3F434F9B2DBE0B3200D78C36 /* ima_decode_api.h in Headers */ = {isa = PBXBuildFile; fileRef = 3F434F992DBE0B3200D78C36 /* ima_decode_api.h */; };
                3F434F9C2DBE0B3200D78C36 /* ima_decode_api.h in Headers */ = {isa = PBXBuildFile; fileRef = 3F434F992DBE0B3200D78C36 /* ima_decode_api.h */; };
                3F434F9D2DBE0B3200D78C36 /* ima_adpcm_dec.c in Sources */ = {isa = PBXBuildFile; fileRef = 3F434F982DBE0B3200D78C36 /* ima_adpcm_dec.c */; };
+               3F434FA32DBF263D00D78C36 /* Tlw2ReceiveManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F434FA22DBF263D00D78C36 /* Tlw2ReceiveManager.m */; };
+               3F434FA42DBF263D00D78C36 /* Tlw2ReceiveManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 3F434FA12DBF263D00D78C36 /* Tlw2ReceiveManager.h */; };
+               3F434FA52DBF263D00D78C36 /* Tlw2ReceiveManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 3F434FA12DBF263D00D78C36 /* Tlw2ReceiveManager.h */; };
+               3F434FA62DBF263D00D78C36 /* Tlw2ReceiveManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F434FA22DBF263D00D78C36 /* Tlw2ReceiveManager.m */; };
                3F985CFA2DB34D0F008D6D73 /* DeviceTool.h in Headers */ = {isa = PBXBuildFile; fileRef = 3F985CF82DB34D0F008D6D73 /* DeviceTool.h */; };
                3F985CFB2DB34D0F008D6D73 /* DeviceTool.m in Sources */ = {isa = PBXBuildFile; fileRef = 3F985CF92DB34D0F008D6D73 /* DeviceTool.m */; };
                3F985CFC2DB34D0F008D6D73 /* DeviceTool.h in Headers */ = {isa = PBXBuildFile; fileRef = 3F985CF82DB34D0F008D6D73 /* DeviceTool.h */; };
                18EF7AF62C7603E800AC5223 /* AiConnectManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AiConnectManager.h; sourceTree = "<group>"; };
                3F434F982DBE0B3200D78C36 /* ima_adpcm_dec.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = ima_adpcm_dec.c; sourceTree = "<group>"; };
                3F434F992DBE0B3200D78C36 /* ima_decode_api.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ima_decode_api.h; sourceTree = "<group>"; };
+               3F434FA12DBF263D00D78C36 /* Tlw2ReceiveManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Tlw2ReceiveManager.h; sourceTree = "<group>"; };
+               3F434FA22DBF263D00D78C36 /* Tlw2ReceiveManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Tlw2ReceiveManager.m; sourceTree = "<group>"; };
                3F5CE3E62D1E7BCA00A5628A /* libAiMouseSdk copy.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libAiMouseSdk copy.a"; sourceTree = BUILT_PRODUCTS_DIR; };
                3F985CF82DB34D0F008D6D73 /* DeviceTool.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DeviceTool.h; sourceTree = "<group>"; };
                3F985CF92DB34D0F008D6D73 /* DeviceTool.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DeviceTool.m; sourceTree = "<group>"; };
                                18EF7AF52C7603E800AC5223 /* AdpcmConverter.m */,
                                18EF7AEA2C7603E800AC5223 /* adpcm.h */,
                                18EF7AF22C7603E800AC5223 /* adpcm.c */,
+                               3F434FA12DBF263D00D78C36 /* Tlw2ReceiveManager.h */,
+                               3F434FA22DBF263D00D78C36 /* Tlw2ReceiveManager.m */,
                        );
                        path = TlwMouseSdk;
                        sourceTree = "<group>";
                                180E7CD82BD8FC4E008558E8 /* timestamp.h in Headers */,
                                180E7CEB2BD8FC4E008558E8 /* vdpau.h in Headers */,
                                180E7CB72BD8FC4E008558E8 /* camellia.h in Headers */,
+                               3F434FA52DBF263D00D78C36 /* Tlw2ReceiveManager.h in Headers */,
                                180E7C872BD8FC4E008558E8 /* avfilter.h in Headers */,
                                180E7C862BD8FC4E008558E8 /* buffersink.h in Headers */,
                                180E7CC32BD8FC4E008558E8 /* macros.h in Headers */,
                                18862B3C2C806BD900D3564D /* BleManager.h in Headers */,
                                18862B3D2C806BD900D3564D /* lzo.h in Headers */,
                                18862B3E2C806BD900D3564D /* xtea.h in Headers */,
+                               3F434FA42DBF263D00D78C36 /* Tlw2ReceiveManager.h in Headers */,
                                18862B3F2C806BD900D3564D /* lfg.h in Headers */,
                                18862B402C806BD900D3564D /* audio_fifo.h in Headers */,
                                18862B412C806BD900D3564D /* swresample.h in Headers */,
                                188814C42C85C2BB009299A9 /* AESCBCHelper.m in Sources */,
                                3FF3D75F2DAFA0BC008EBA5D /* M8MouseInfo.m in Sources */,
                                180E7BDF2BD7BD84008558E8 /* AiMouseConfig.m in Sources */,
+                               3F434FA62DBF263D00D78C36 /* Tlw2ReceiveManager.m in Sources */,
                                18EF7AFC2C7603E800AC5223 /* AiConnectManager.m in Sources */,
                                181CE5C22C6EED9900EF8D07 /* AiAliAuthManager.m in Sources */,
                                18D57A032C917385003D5714 /* NMouseSdk.m in Sources */,
                                18862BB52C806BD900D3564D /* AiTrippleModel.m in Sources */,
                                3F434F9D2DBE0B3200D78C36 /* ima_adpcm_dec.c in Sources */,
                                18862BB62C806BD900D3564D /* AiMouseSdk.m in Sources */,
+                               3F434FA32DBF263D00D78C36 /* Tlw2ReceiveManager.m in Sources */,
                                188814912C85766B009299A9 /* AiDeviceAuthManager.m in Sources */,
                                18862BB82C806BD900D3564D /* AFHTTPSessionManager.m in Sources */,
                                18862BB92C806BD900D3564D /* AiMouseTools.m in Sources */,
index 27157b9..64bd978 100644 (file)
@@ -7,7 +7,7 @@
                <key>AiMouseSdk copy.xcscheme_^#shared#^_</key>
                <dict>
                        <key>orderHint</key>
-                       <integer>4</integer>
+                       <integer>2</integer>
                </dict>
                <key>AiMouseSdk.xcscheme_^#shared#^_</key>
                <dict>
index 2a2a60f..3b7f186 100644 (file)
@@ -11,6 +11,7 @@
 #import "AiMouseConfig.h"
 #import "AiSender.h"
 #import "TlwTools.h"
+#import "AiMouseSdk.h"
 #define kCmd_Key @"cmd"
 #define kSetCmd_Value @"set_config"
 
 }
 - (void)sendCmdToBle:(NSDictionary *)dict{
     NSData *data = [AiMouseTools dictionaryToData:dict];
-    NSString *str = [AiMouseTools dataToUtf8String:data];
+    NSString *str = [NSString stringWithFormat:@"-$$%@$$-", [AiMouseTools dataToUtf8String:data]];
     NSArray *list = [self splitCMD:str];
-//    [self showLog:[NSString stringWithFormat:@"send %@",str]];
-    if(list.count > 1){
-        {
-            //开始标志
-            NSString *cmd = @"-$$\0";
-            [self sendToBle:cmd];
-        }
-        //指令
-        for (NSInteger i = 0; i < list.count; i++) {
-            NSString *cmd = [NSString stringWithFormat:@"%@\0",list[i]];
-            [self sendToBle:cmd];
-        }
-        {
-            //结束标志
-            NSString *cmd = @"$$-\0";
-            [self sendToBle:cmd];
-        }
-    }
-    else{
-        NSString *cmd = [NSString stringWithFormat:@"-$$%@$$-\n",str];
+    //指令
+    for (NSInteger i = 0; i < list.count; i++) {
+        NSString *cmd = [NSString stringWithFormat:@"%@",list[i]];
         [self sendToBle:cmd];
     }
+    
+//    [self showLog:[NSString stringWithFormat:@"send %@",str]];
+//    if(list.count > 1){
+//        {
+//            //开始标志
+//            NSString *cmd = @"-$$";
+//            [self sendToBle:cmd];
+//        }
+//        //指令
+//        for (NSInteger i = 0; i < list.count; i++) {
+//            NSString *cmd = [NSString stringWithFormat:@"%@",list[i]];
+//            [self sendToBle:cmd];
+//        }
+//        {
+//            //结束标志
+//            NSString *cmd = @"$$-\0";
+//            [self sendToBle:cmd];
+//        }
+//    }
+//    else{
+//        NSString *cmd = [NSString stringWithFormat:@"-$$%@$$-",str];
+//        [self sendToBle:cmd];
+//    }
+    
+//    self.sendToBleBlock([TlwTools hexStringToData:@"2D24247B22636D64223A226765745F4D4143"]);
+//    self.sendToBleBlock([TlwTools hexStringToData:@"227D24242D00000000000000000000000000"]);
+//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
+//        self.sendToBleBlock([TlwTools hexStringToData:@"2D24247B22636D64223A226765745F626174"]);
+//        self.sendToBleBlock([TlwTools hexStringToData:@"746572795F706F776572227D24242D"]);
+//    });
 }
 - (void)sendToBle:(NSString *)cmd{
     NSData *data = [cmd dataUsingEncoding:NSUTF8StringEncoding];
 - (NSArray<NSString *> *)splitCMD:(NSString *)cmd{
     NSMutableArray *list = [[NSMutableArray alloc] init];
     NSString *str = cmd;
-    NSInteger len = 30;
+    NSInteger len = [AiMouse shared].tlw2 ? 18: 48;
     while (str.length > 0) {
         if (str.length > len) {
             NSString *sub = [str substringToIndex:len];
index dc147c6..aada5f2 100644 (file)
 }
 #pragma mark - pub Api
 - (void)didDisconnect{
+    [[ByteDanceSdk shared] disconnected];
     [self stopRecord:true];
     //    [self.connectManager disConnected];
 }
         [self.connectdManager didConnected];
     }
     
-    [self showLog:[NSString stringWithFormat:@"[receive][Voice] %@",data]];
+//    [self showLog:[NSString stringWithFormat:@"[receive][Voice] %@",data]];
     if(self.connectType == AiMouseConnectType_hid){
         //        0AFFFF12BC32
-        if(data.length == 6){
+        if(data.length >= 6){
             NSData *subData = [data subdataWithRange:NSMakeRange(5, 1)];
             [self sendCmdData:subData];
             uint8 cmd;
         [self.connectdManager didConnected];
     }
     if (data.length == 0 || (data.length == 6 && [[AiMouseTools dataToHexString:data] hasSuffix:@"f77f"])) {
-        [self showLog:[NSString stringWithFormat:@"[receive][info] %@",data]];
+        [self showLog:[NSString stringWithFormat:@"[receive] %@",data]];
         [self showLog:@"收到异常数据!!!"];
         return;
     }
-    [self showLog:[NSString stringWithFormat:@"[receive][info] %@",[AiMouseTools dataToHexString:data]]];
-    [self showLog:[NSString stringWithFormat:@"[receive][info] %@",[AiMouseTools dataToUtf8String:data]]];
+    [self showLog:[NSString stringWithFormat:@"[receive]%@",[AiMouseTools dataToHexString:data]]];
+    [self showLog:[NSString stringWithFormat:@"[receive][utf8] %@",[AiMouseTools dataToUtf8String:data]]];
     
     if ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4) {
         if([self.deviceInfoManager receiveData:data]){
 
 - (void)sendToBle:(NSData *)data{
     if(self.connectType == AiMouseConnectType_hid && self.tlw2){
-        data = [TlwTools hexStringToData:@"11"];
-//        data = [TlwTools hexStringToData:@"2D24247B22636D64223A226765745F4D4143"];
-//        data = [TlwTools hexStringToData:@"227D24242D00000000000000000000000000"];
         NSMutableData *fullData = [[NSMutableData alloc] init];
         uint8_t head[] = { 0x05};
-        uint8_t tail[] = {0x00};
         [fullData appendBytes:&head length:1];
         [fullData appendData:data];
-        [fullData appendBytes:&tail length:1];
-        [self showLog:[NSString stringWithFormat:@"[send][info]%@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]]];
-        [self showLog:[NSString stringWithFormat:@"[send] %@",fullData]];
+        
+        if (fullData.length < 64) {
+            NSInteger len = 64 - fullData.length;
+            for (NSInteger i = 0; i < len; i++) {
+                uint8_t d = 0x00;
+                [fullData  appendBytes:&d length:1];
+            }
+        }
+//        [self showLog:[NSString stringWithFormat:@"[send][info]%@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]]];
+//        [self showLog:[NSString stringWithFormat:@"[send] %@",[AiMouseTools dataToHexString:fullData]]];
         if (self.delegate) [self.delegate aiMouseSendDeviceInfoData:fullData];
+
     }
     else{
-        [self showLog:[NSString stringWithFormat:@"[send] %@",[AiMouseTools dataToHexString:data]]];
+        NSMutableData *fullData = [NSMutableData dataWithData:data];
+        if (fullData.length < 64) {
+            NSInteger len = 64 - fullData.length;
+            for (NSInteger i = 0; i < len; i++) {
+                uint8_t d = 0x00;
+                [fullData  appendBytes:&d length:1];
+            }
+        }
+//        [self showLog:[NSString stringWithFormat:@"[send] %@",[AiMouseTools dataToHexString:fullData]]];
         if (self.delegate) {
-            [self.delegate aiMouseSendDeviceInfoData:data];
+            [self.delegate aiMouseSendDeviceInfoData:fullData];
         };
     }
 }
index 8d72da0..adeedc3 100644 (file)
@@ -73,7 +73,7 @@
 
 - (void)timerAction{
     self.number++;
-    if (self.number == 1) {
+    if (self.number == 6) {
         [self removeSendTimer];
         if (self.delegate && [self.delegate respondsToSelector:@selector(aiSenderRecieveTimeOut:)]) {
             [self.delegate aiSenderRecieveTimeOut:self];
index aebec0c..0aed0b6 100644 (file)
@@ -38,7 +38,7 @@
 
 - (void)showLog:(NSString *)log{
     if (self.outputLog) {
-        self.outputLog([NSString stringWithFormat:@"[audio] %@",log]);
+//        self.outputLog([NSString stringWithFormat:@"[audio] %@",log]);
     }
 }
 
index 1122cfe..b254f99 100644 (file)
@@ -23,5 +23,6 @@
 
 - (void)sendToSdk:(NSData *)data;
 
+- (void)disconnected;
 @end
 
index 7d0101b..403d98b 100644 (file)
@@ -36,7 +36,8 @@
     [LogManager log:@"开始初始化"];
     stb_app_printf_str_register(cus_printf_str);
     //    NSString *appId = @"tis_test";
-    NSString *appId = @"app_10dyx2ai21r2qkar";
+//    NSString *appId = @"app_10dyx2ai21r2qkar";
+    NSString *appId = @"app_gyaehpyinrog7dc5";
     int code = stb_app_init([appId UTF8String]);
     stb_app_event_callback_register(cust_event_callback_func);
     stb_app_send_data_to_device_register(cus_hal_send_data2device);
@@ -57,6 +58,7 @@
 }
 
 - (void)sendToSdk:(NSData *)data{
+    [LogManager log:[NSString stringWithFormat:@"[byte][reciv] %@",[AiMouseTools dataToHexString:data]]];
     stb_app_recv_data_from_device(data.bytes, data.length);
 }
 
         [NSObject cancelPreviousPerformRequestsWithTarget:self];
     }
 }
-- (void)stopAuth{
-    stb_app_stop_identify();
-}
-- (void)sendCmdToBle:(NSDictionary *)dict{
-    NSData *data = [AiMouseTools dictionaryToData:dict];
-    NSString *str = [AiMouseTools dataToUtf8String:data];
-    NSArray *list = [self splitCMD:str];
-    //    [self showLog:[NSString stringWithFormat:@"send %@",str]];
-    if(list.count > 1){
-        {
-            //开始标志
-            NSString *cmd = @"-$$\0";
-            [self sendToBle:cmd];
-        }
-        //指令
-        for (NSInteger i = 0; i < list.count; i++) {
-            NSString *cmd = [NSString stringWithFormat:@"%@\0",list[i]];
-            [self sendToBle:cmd];
-        }
-        {
-            //结束标志
-            NSString *cmd = @"$$-\0";
-            [self sendToBle:cmd];
-        }
-    }
-    else{
-        NSString *cmd = [NSString stringWithFormat:@"-$$%@$$-\n",str];
-        [self sendToBle:cmd];
-    }
-}
-- (void)sendToBle:(NSString *)cmd{
-    NSData *data = [cmd dataUsingEncoding:NSUTF8StringEncoding];
-    [[AiMouse shared] sendToBle:data];
-}
-//切割
-- (NSArray<NSString *> *)splitCMD:(NSString *)cmd{
-    NSMutableArray *list = [[NSMutableArray alloc] init];
-    NSString *str = cmd;
-    NSInteger len = 30;
-    while (str.length > 0) {
-        if (str.length > len) {
-            NSString *sub = [str substringToIndex:len];
-            [list addObject:sub];
-            str = [str substringFromIndex:len];
-        }
-        else{
-            [list addObject:str];
-            break;
-        }
-    }
-    return list;
+- (void)disconnected{
+//    stb_app_deinit();
+    
 }
 
 #pragma mark - ByteDance
@@ -204,20 +158,15 @@ static void cust_event_callback_func(uint32_t type,uint8_t *report, uint32_t dat
 
 int32_t STB_STDCALL cus_hal_send_data2device(uint8_t* data, uint32_t len)
 {
-    //    if ([[AiMouseTools dataToHexString_placeholder:[[NSData alloc] initWithBytes:data length:len]] hasPrefix:@"07"]) {
-    //        NSData *data = [AiMouseTools hexStringToData:@"2D2424073137333532303432363434313624242D0A"];
-    //        [[AiMouse shared] sendToBle:data];
-    //        return 0;
-    //    }
     NSData *cmdData = [[NSData alloc] initWithBytes:data length:len];
-    [LogManager log:[NSString stringWithFormat:@"send_data2device = %@",[AiMouseTools dataToHexString_placeholder:cmdData]]];
+    [LogManager log:[NSString stringWithFormat:@"send2device = %@",[AiMouseTools dataToHexString_placeholder:cmdData]]];
     NSMutableData *fullData = [[NSMutableData alloc] init];
     
     uint8_t head[] = { 0x2d, 0x24, 0x24};
-    uint8_t tail[] = {0x24, 0x24,0x2d,0x00};
+    uint8_t tail[] = {0x24, 0x24,0x2d};
     [fullData appendBytes:&head length:3];
     [fullData appendData:cmdData];
-    [fullData appendBytes:&tail length:4];
+    [fullData appendBytes:&tail length:3];
     
     //    uint8_t head[] = { 0x2d, 0x24, 0x24};
     //    uint8_t tail[] = {0x24, 0x24,0x2d};
@@ -225,46 +174,30 @@ int32_t STB_STDCALL cus_hal_send_data2device(uint8_t* data, uint32_t len)
     //    [fullData appendData:cmdData];
     //    [fullData appendBytes:&tail length:3];
     
-    if([AiMouse shared].connectType == AiMouseConnectType_hid){
-        if (fullData.length < 64) {
-            NSInteger len = 64 - fullData.length;
-            for (NSInteger i = 0; i < len; i++) {
-                uint8_t d = 0x00;
-                [fullData  appendBytes:&d length:1];
-            }
-        }
+    NSArray *list = [[ByteDanceSdk shared] split:fullData];
+    for (NSData *data in list) {
+//        [LogManager log:[NSString stringWithFormat:@"[byte][send] %@",[AiMouseTools dataToHexString:data]]];
+        [[AiMouse shared] sendToBle:data];
     }
-    
-    
-    [[AiMouse shared] sendToBle:fullData];
+//    [[AiMouse shared] sendToBle:data];
     return 0;
 }
 
-//int32_t STB_STDCALL cus_hal_send_data2device(uint8_t* data, uint32_t len)
-//{
-//    NSData *cmdData = [[NSData alloc] initWithBytes:data length:len];
-//    [LogManager log:[NSString stringWithFormat:@"send_data2device = %@",[AiMouseTools dataToHexString_placeholder:cmdData]]];
-//    NSMutableData *fullData = [[NSMutableData alloc] init];
-//    
-//    uint8_t head[] = { 0x05,0x2d, 0x24, 0x24};
-//    uint8_t tail[] = {0x24, 0x24,0x2d,0x00};
-//    [fullData appendBytes:&head length:4];
-//    [fullData appendData:cmdData];
-//    [fullData appendBytes:&tail length:4];
-//
-//    
-//    if([AiMouse shared].connectType == AiMouseConnectType_hid){
-//        if (fullData.length < 64) {
-//            NSInteger len = 64 - fullData.length;
-//            for (NSInteger i = 0; i < len; i++) {
-//                uint8_t d = 0x00;
-//                [fullData  appendBytes:&d length:1];
-//            }
-//        }
-//    }
-//    
-//    [[AiMouse shared] sendToBle:fullData];
-//    return 0;
-//}
-
+- (NSArray<NSData *> *)split:(NSData *)data {
+    NSMutableArray<NSData *> *resultArray = [NSMutableArray array];
+    NSUInteger length = data.length;
+    
+    if (length > 14) {
+        for (NSUInteger i = 0; i < length; i += 14) {
+            NSUInteger bytesToCopy = MIN(14, length - i);
+            NSRange range = NSMakeRange(i, bytesToCopy);
+            NSData *subData = [data subdataWithRange:range];
+            [resultArray addObject:subData];
+        }
+    }
+    else{
+        return [NSArray arrayWithObject:data];
+    }
+    return [resultArray copy];
+}
 @end
index cdac9e6..ae11b41 100644 (file)
@@ -108,7 +108,7 @@ static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDRe
     if (ret != kIOReturnSuccess) {
         [self showLog:(@"打开hid失败!")];
     }else{
-        [self showLog:(@"打开hid成功!")];
+//        [self showLog:(@"打开hid成功!")];
     }
     //设置匹配设备
     //    ////供应商id
@@ -133,7 +133,7 @@ static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDRe
     if (self.hidManager == nil) {
         return;
     }
-    [self showLog:@"关闭hid"];
+//    [self showLog:@"关闭hid"];
 
     IOReturn ret = IOHIDManagerClose(self.hidManager, 0);
     self.hidManager = nil;
@@ -141,7 +141,7 @@ static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDRe
     if (ret != kIOReturnSuccess) {
         [self showLog:(@"关闭hid失败!")];
     }else{
-        [self showLog:(@"关闭hid成功!")];
+//        [self showLog:(@"关闭hid成功!")];
         self.deviceInfoCha = nil;
         self.hidManager = nil;
     }
index 34fccd2..183256d 100644 (file)
     return self;
 }
 
--(NSString *)version{
-    return @"1.0.2";
-}
-
 - (AiRecordManager *)recordManager{
     if (!_recordManager) {
         _recordManager = [[AiRecordManager alloc] init];
 }
 
 - (void)getFullDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))finished{
-    AiMouseDeviceInfo *info = [[AiMouseDeviceInfo alloc] init];
-    info.type = 0;
-    info.battery_power = M8MouseInfo.shared.battery_power;
-    info.version = M8MouseInfo.shared.version;
-    info.brand = M8MouseInfo.shared.brand;
-    info.sn = M8MouseInfo.shared.sn;
-    info.mac = info.sn;
-    info.CPI_list = @"2400";
-    info.CPI = @"2400";
-    self.fullInfo = info;
-    finished(info,nil);
-    
+    if (self.connectType == AiMouseConnectType_hid) {
+        NSMutableData *data = [NSMutableData dataWithData:[TlwTools hexStringToData:@"09"]];
+        [self sendToDevice:data];
+    }
+    else{
+        AiMouseDeviceInfo *info = [[AiMouseDeviceInfo alloc] init];
+        info.type = 0;
+        info.battery_power = M8MouseInfo.shared.battery_power;
+        info.version = M8MouseInfo.shared.version;
+        info.brand = M8MouseInfo.shared.brand;
+        info.sn = M8MouseInfo.shared.sn;
+        info.mac = info.sn;
+        info.CPI_list = @"2400";
+        info.CPI = @"2400";
+        self.fullInfo = info;
+        finished(info,nil);
+    }
 }
 
 #pragma mark - check dongle
 }
 #pragma mark - other
 - (void)sendRecordData:(NSData *)data{
-    [self showLog:[NSString stringWithFormat:@"[send][audio] %@",data]];
+//    [self showLog:[NSString stringWithFormat:@"[send][audio] %@",data]];
     if (self.delegate)  [self.delegate m8MouseSendRecordData:data];
 }
 
 
 
 - (void)sendToDevice:(NSMutableData *)data{
-    if (data.length < 64) {
-        NSInteger len = 64 - data.length;
-        for (NSInteger i = 0; i < len; i++) {
-            uint8_t d = 0x00;
-            [data  appendBytes:&d length:1];
-        }
-    }
+//    if (data.length < 64) {
+//        NSInteger len = 64 - data.length;
+//        for (NSInteger i = 0; i < len; i++) {
+//            uint8_t d = 0x00;
+//            [data  appendBytes:&d length:1];
+//        }
+//    }
     [self showLog:[NSString stringWithFormat:@"[send][info] %@",[TlwTools dataToHexString:data]]];
     [self.delegate m8MouseSendDeviceInfoData:data];
 }
index a704bfa..f5e9c9b 100644 (file)
@@ -21,5 +21,7 @@
 - (void)open;
 
 -(void)writeToDevice:(NSData *)data;
+
+- (void)disconnected;
 @end
 
index fd44b4a..5688b05 100644 (file)
 }
 //收到蓝牙数据
 - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
-    [self showLog:[NSString stringWithFormat:@"[reciv]%@ %@",characteristic,characteristic.value]];
+//    [self showLog:[NSString stringWithFormat:@"[reciv]%@ %@",characteristic,characteristic.value]];
     if (self.productType == AiMouseProductType_m8) {
         NSData *data = characteristic.value;
         if( [characteristic.UUID.UUIDString isEqualToString:kM8ClickUUID]){
     }
 }
 
+- (void)disconnected{
+    self.curentPeripheral = nil;
+}
 @end
index 78202c0..1c2c895 100644 (file)
@@ -50,7 +50,7 @@
 - (instancetype)init{
     self = [super init];
     if (self) {
-        self.version = @"MouseSdk_v2025041501";
+        self.version = @"MouseSdk_v2025042801";
     }
     return self;
 }
         self.aiMouseConnectStateDidChangeCallBack(self.tlwSdk.connectType == AiMouseConnectType_bluetooth ? 0:1,connected);
     }
     if(self.authCallBack && connected)self.authCallBack(connected);
+    
+    if (self.tlwSdk.connectType == AiMouseConnectType_bluetooth && connected == false) {
+        [self.ble disconnected];
+    }
 }
 /// 设备信息数据回调,需要将此数据通过设备信息特征转发给蓝牙设备
 /// - Parameter data: 数据
     if (self.aiMouseConnectStateDidChangeCallBack) {
         self.aiMouseConnectStateDidChangeCallBack(self.frkSdk.connectType == AiMouseConnectType_bluetooth ? 0:1,connected);
     }
+    if (self.frkSdk.connectType == AiMouseConnectType_bluetooth && connected == false) {
+        [self.ble disconnected];
+    }
 }
 
 /// 鉴权结果返回
         self.aiMouseConnectStateDidChangeCallBack(self.m8Sdk.connectType == AiMouseConnectType_bluetooth ? 0:1,connected);
     }
     if(self.authCallBack && connected)self.authCallBack(connected);
+    
+    if (self.m8Sdk.connectType == AiMouseConnectType_bluetooth && connected == false) {
+        [self.ble disconnected];
+    }
 }
 
 
index 0a09a9a..0a25599 100644 (file)
 #import <Cocoa/Cocoa.h>
 #import "AiDeviceAuthManager.h"
 #import "TlwTools.h"
+#import "Tlw2ReceiveManager.h"
 @interface HidManager ()
 @property(nonatomic, assign) IOHIDManagerRef hidManager;///hid管理
 @property(nonatomic, assign) IOHIDDeviceRef deviceInfoCha;//设备信息通道
 @property(nonatomic, assign) IOHIDDeviceRef voiceCha;//语音通道
+@property(nonatomic, strong) Tlw2ReceiveManager *tlw2Receiver;
 @end
 
 @implementation HidManager
@@ -48,7 +50,42 @@ static void hidAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOH
     uint32_t vid = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDVendorIDKey));
     uint32_t page = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsagePageKey));
     uint32_t usage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsageKey));
-    [[HidManager shared] showLog: [NSString stringWithFormat:@"发现设备 %@",inIOHIDDeviceRef]];
+//    [[HidManager shared] showLog: [NSString stringWithFormat:@"发现设备 %@",inIOHIDDeviceRef]];
+   if(vid == 3468 && pid == 786){
+       if (page == 65282 && usage == 2) {
+           [HidManager shared].productType = AiMouseProductType_m8;
+           [HidManager shared].deviceInfoCha = inIOHIDDeviceRef;
+           unsigned char InputBuffer[64];
+           IOHIDDeviceRegisterInputReportCallback(inIOHIDDeviceRef, InputBuffer, sizeof(InputBuffer), &hidReceiveData, NULL);
+           
+           IOReturn result = IOHIDDeviceOpen(inIOHIDDeviceRef, kIOHIDOptionsTypeNone);
+           if (result != kIOReturnSuccess) {
+               [[HidManager shared] showLog:[NSString stringWithFormat:@"打开设备失败! %d",result]];
+               [[AiDeviceAuthManager shared] showHidAlert];
+               return;
+           }else{
+               [[HidManager shared] showLog:@"打开设备成功!"];
+               [HidManager shared].connectStateCallBack(true) ;
+           }
+       }
+//       else if (page == 1 && usage == 2){
+//           [HidManager shared].productType = AiMouseProductType_m8;
+//           [HidManager shared].deviceInfoCha = inIOHIDDeviceRef;
+//           unsigned char InputBuffer[64];
+//           IOHIDDeviceRegisterInputReportCallback(inIOHIDDeviceRef, InputBuffer, sizeof(InputBuffer), &hidReceiveData, NULL);
+//           
+//           IOReturn result = IOHIDDeviceOpen(inIOHIDDeviceRef, kIOHIDOptionsTypeNone);
+//           if (result != kIOReturnSuccess) {
+//               [[HidManager shared] showLog:[NSString stringWithFormat:@"打开设备失败! %d",result]];
+//               [[AiDeviceAuthManager shared] showHidAlert];
+//               return;
+//           }else{
+//               [[HidManager shared] showLog:@"打开设备成功!"];
+//               //            [HidManager shared].connectStateCallBack(true) ;
+//           }
+//       }
+       return;
+    }
     if((vid == 0x248a && pid == 0x6092)){
         [HidManager shared].productType = AiMouseProductType_keyboard;
         [HidManager shared].deviceInfoCha = inIOHIDDeviceRef;
@@ -143,25 +180,7 @@ static void hidAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOH
     else  if(vid == 0x6675 && pid == 0x8602){
         [HidManager shared].productType = AiMouseProductType_frk;
         AiMouse.shared.tlw2 = true;
-//        if(page == 1 && usage == 2){
-//            unsigned char InputBuffer[128];
-//            IOHIDDeviceRegisterInputReportCallback(inIOHIDDeviceRef, InputBuffer, sizeof(InputBuffer), hidReceiveData, NULL);
-//            
-//            IOReturn result = IOHIDDeviceOpen(inIOHIDDeviceRef, kIOHIDOptionsTypeNone);
-//            if (result != kIOReturnSuccess) {
-//                [[HidManager shared] showLog:[NSString stringWithFormat:@"打开设备信息失败! %d",result]];
-//                [[AiDeviceAuthManager shared] showHidAlert];
-//                return;
-//            }else{
-//                [HidManager shared].deviceInfoCha = inIOHIDDeviceRef;
-//                
-//                [[HidManager shared] showLog:@"打开设备信息成功!"];
-//                if([HidManager shared].voiceCha != nil){
-//                    [HidManager shared].connectStateCallBack(true);
-//                }
-//            }
-//        }
-//        else
+        [HidManager shared].tlw2Receiver = [[Tlw2ReceiveManager alloc] init];
             if(page == 65519 && usage == 0){
             unsigned char InputBuffer[128];
             IOHIDDeviceRegisterInputReportCallback(inIOHIDDeviceRef, InputBuffer, sizeof(InputBuffer), hidReceiveData, NULL);
@@ -196,10 +215,10 @@ static void hidDisAppearDevice(void *inContext,IOReturn inResult,void *inSender,
 
 static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDReportType type, uint32_t reportID, uint8_t *report,CFIndex reportLength){
     NSData *data = [[NSData alloc] initWithBytes:report length:reportLength];
-    //    if (data.length == 7) {
-    //        return;
-    //    }
-    [[HidManager shared] showLog:[NSString stringWithFormat:@"[reciv] %@",data]];
+        if (data.length <= 4) {
+            return;
+        }
+//    [[HidManager shared] showLog:[NSString stringWithFormat:@"[reciv] %@",data]];
     //    return;
     if([HidManager shared].productType == AiMouseProductType_keyboard){
         NSData *data = [[NSData alloc] initWithBytes:report length:reportLength];
@@ -223,20 +242,21 @@ static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDRe
         }
     }
     else if([HidManager shared].productType == AiMouseProductType_frk){
+        
         NSInteger len = get_data_len(report, (int)reportLength);
         NSData *data = [[NSData alloc] initWithBytes:report length:len];
         uint32_t page = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsagePageKey));
         uint32_t usage = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsageKey));
-        
+        [[HidManager shared] showLog:[NSString stringWithFormat:@"[reciv]%@",[TlwTools dataToHexString:data]]];
         if(page == 1 && usage == 0){
             [[AiMouse shared] sendDeviceDataToSdk:data];
         }
         else if(page == 65283 && usage == 0){
             [[AiMouse shared] sendAiDataToSdk:data];
         }
-        
-        if(page == 1 && usage == 2){
-            [[HidManager shared] showLog:[NSString stringWithFormat:@"[reciv] %@",data]];
+        else if(page == 65519 && usage == 0){
+            //泰凌微2代
+            [[HidManager shared].tlw2Receiver receive:data];
         }
     }
 }
@@ -300,7 +320,7 @@ static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDRe
     }
 //    data = [self addFullData:data];
     [self showLog:[NSString stringWithFormat:@"[send] %@ %@",self.deviceInfoCha,data]];
-    IOReturn ret = IOHIDDeviceSetReport(self.deviceInfoCha, kIOHIDReportTypeOutput, 0, data.bytes, data.length);
+    IOReturn ret = IOHIDDeviceSetReport(self.deviceInfoCha, kIOHIDReportTypeOutput, 0x05, data.bytes, data.length);
     if (ret != kIOReturnSuccess) {
         [self showLog:[NSString stringWithFormat:@"发送失败! code = %d",ret]];
     }else{
index bfe9912..31e7535 100644 (file)
@@ -32,7 +32,7 @@
 //        [[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
 //        [[NSRunLoop currentRunLoop] run];
 //    });
-    self.timer = [NSTimer scheduledTimerWithTimeInterval:5000 target:self selector:@selector(timerAction) userInfo:nil repeats:true];
+    self.timer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(timerAction) userInfo:nil repeats:true];
 }
 
 - (void)timerAction{
diff --git a/MouseSdk/AiMouseSdk/TlwMouseSdk/Tlw2ReceiveManager.h b/MouseSdk/AiMouseSdk/TlwMouseSdk/Tlw2ReceiveManager.h
new file mode 100644 (file)
index 0000000..3c81beb
--- /dev/null
@@ -0,0 +1,17 @@
+//
+//  DataReceiveManager.h
+//  AiMouseSdk
+//
+//  Created by liangshi on 2025/4/28.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface Tlw2ReceiveManager : NSObject
+
+- (void)receive:(NSData *)data;
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/MouseSdk/AiMouseSdk/TlwMouseSdk/Tlw2ReceiveManager.m b/MouseSdk/AiMouseSdk/TlwMouseSdk/Tlw2ReceiveManager.m
new file mode 100644 (file)
index 0000000..e740e89
--- /dev/null
@@ -0,0 +1,72 @@
+//
+//  DataReceiveManager.m
+//  AiMouseSdk
+//
+//  Created by liangshi on 2025/4/28.
+//
+
+#import "Tlw2ReceiveManager.h"
+#import "TlwTools.h"
+#import "AiMouseSdk.h"
+#import "LogManager.h"
+@interface Tlw2ReceiveManager()
+
+@property (nonatomic,strong)NSMutableString *totalData;
+
+@end
+
+@implementation Tlw2ReceiveManager
+
+
+- (void)receive:(NSData *)data{
+    if (self.totalData == nil) {
+        self.totalData = [[NSMutableString alloc] init];
+    }
+    NSString *currText = [[TlwTools dataToHexString:data] uppercaseString];
+    
+    if ([currText containsString:@"05120A2700"]) {
+        self.totalData = [[NSMutableString alloc] init];
+        [[AiMouse shared] sendAiDataToSdk:[data subdataWithRange:NSMakeRange(2, 6)]];
+        return;
+    }
+    if ([currText containsString:@"05127B"]) {
+        self.totalData = [[NSMutableString alloc] init];
+        [self.totalData appendString:currText];
+        [self checkFinish];
+    }
+    else{
+        if ([self.totalData containsString:@"05127B"]) {
+            if( [currText containsString:@"7D"]){
+                [self.totalData appendString:[currText substringFromIndex:4]];
+                [self checkFinish];
+                self.totalData = [[NSMutableString alloc] init];
+            }
+            else{
+                [self.totalData appendString:[currText substringFromIndex:4]];
+            }
+        }
+        else {
+            if ([currText hasPrefix:@"0512"]) {
+                [self.totalData appendString:[currText substringFromIndex:4]];
+                if (data.length < 21) {
+                    NSData *fullData = [TlwTools dataWithHexString:self.totalData];
+                    [[AiMouse shared] sendDeviceDataToSdk:fullData];
+                    self.totalData = [[NSMutableString alloc] init];
+                }
+                else{
+                    
+                }
+            }
+        }
+    }
+}
+
+- (void)checkFinish{
+    if ([self.totalData containsString:@"05127B"] && [self.totalData containsString:@"7D"]) {
+        [LogManager log: [NSString stringWithFormat:@"[reciv][total]  %@",self.totalData]];
+        NSData *fullData = [TlwTools dataWithHexString:[self.totalData substringFromIndex:4]];
+        [[AiMouse shared] sendDeviceDataToSdk:fullData];
+        self.totalData = [[NSMutableString alloc] init];
+    }
+}
+@end
index 0ab53c5..a940f0c 100644 (file)
@@ -56,9 +56,6 @@
     return self;
 }
 
--(NSString *)version{
-    return @"1.0.2";
-}
 
 - (AiRecordManager *)recordManager{
     if (!_recordManager) {
 }
 #pragma mark - other
 - (void)sendRecordData:(NSData *)data{
-    [self showLog:[NSString stringWithFormat:@"[send][audio] %@",data]];
+//    [self showLog:[NSString stringWithFormat:@"[send][audio] %@",data]];
     if (self.delegate)  [self.delegate tlwMouseSendRecordData:data];
 }
 
index 194ce2d..c3f94d2 100644 (file)
Binary files a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate and b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate differ
index 910b871..45774dd 100644 (file)
@@ -3,22 +3,4 @@
    uuid = "D56CBD13-B1CD-4964-946C-9C0A140796C8"
    type = "0"
    version = "2.0">
-   <Breakpoints>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "A592D25F-B5C1-4A3A-A315-96D146FF8489"
-            shouldBeEnabled = "No"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "AiMouseSdk/Manager/BleManager.m"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "247"
-            endingLineNumber = "247"
-            landmarkName = "-startScan"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
-   </Breakpoints>
 </Bucket>
index a1cc8f6..8988d3e 100644 (file)
@@ -7,12 +7,12 @@
                <key>Masonry.xcscheme_^#shared#^_</key>
                <dict>
                        <key>orderHint</key>
-                       <integer>3</integer>
+                       <integer>4</integer>
                </dict>
                <key>Pods-MouseSdk.xcscheme_^#shared#^_</key>
                <dict>
                        <key>orderHint</key>
-                       <integer>2</integer>
+                       <integer>3</integer>
                </dict>
        </dict>
 </dict>