From: liangzhenying <867174124@qq.com> Date: Mon, 28 Apr 2025 09:40:00 +0000 (+0800) Subject: 泰凌微2代完成鉴权 X-Git-Url: http://git.snicker.com.cn/sitemap.xml?a=commitdiff_plain;h=448199aff75854f9995cf188bdd3059ae464530d;p=mirrors%2FMouseSdk-MacOS.git 泰凌微2代完成鉴权 --- diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/project.pbxproj b/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/project.pbxproj index aec594a..cd430a2 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/project.pbxproj +++ b/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/project.pbxproj @@ -429,6 +429,10 @@ 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 */; }; @@ -673,6 +677,8 @@ 18EF7AF62C7603E800AC5223 /* AiConnectManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AiConnectManager.h; sourceTree = ""; }; 3F434F982DBE0B3200D78C36 /* ima_adpcm_dec.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = ima_adpcm_dec.c; sourceTree = ""; }; 3F434F992DBE0B3200D78C36 /* ima_decode_api.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ima_decode_api.h; sourceTree = ""; }; + 3F434FA12DBF263D00D78C36 /* Tlw2ReceiveManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Tlw2ReceiveManager.h; sourceTree = ""; }; + 3F434FA22DBF263D00D78C36 /* Tlw2ReceiveManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Tlw2ReceiveManager.m; sourceTree = ""; }; 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 = ""; }; 3F985CF92DB34D0F008D6D73 /* DeviceTool.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DeviceTool.m; sourceTree = ""; }; @@ -1147,6 +1153,8 @@ 18EF7AF52C7603E800AC5223 /* AdpcmConverter.m */, 18EF7AEA2C7603E800AC5223 /* adpcm.h */, 18EF7AF22C7603E800AC5223 /* adpcm.c */, + 3F434FA12DBF263D00D78C36 /* Tlw2ReceiveManager.h */, + 3F434FA22DBF263D00D78C36 /* Tlw2ReceiveManager.m */, ); path = TlwMouseSdk; sourceTree = ""; @@ -1177,6 +1185,7 @@ 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 */, @@ -1403,6 +1412,7 @@ 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 */, @@ -1620,6 +1630,7 @@ 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 */, @@ -1650,6 +1661,7 @@ 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 */, diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist b/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist index 27157b9..64bd978 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,7 +7,7 @@ AiMouseSdk copy.xcscheme_^#shared#^_ orderHint - 4 + 2 AiMouseSdk.xcscheme_^#shared#^_ diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.m b/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.m index 2a2a60f..3b7f186 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.m +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.m @@ -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" @@ -500,30 +501,43 @@ } - (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]; @@ -536,7 +550,7 @@ - (NSArray *)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]; diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m index dc147c6..aada5f2 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m @@ -128,6 +128,7 @@ } #pragma mark - pub Api - (void)didDisconnect{ + [[ByteDanceSdk shared] disconnected]; [self stopRecord:true]; // [self.connectManager disConnected]; } @@ -173,10 +174,10 @@ [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; @@ -221,12 +222,12 @@ [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]){ @@ -376,23 +377,35 @@ - (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]; }; } } diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiSender.m b/MouseSdk/AiMouseSdk/AiMouseSdk/AiSender.m index 8d72da0..adeedc3 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk/AiSender.m +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiSender.m @@ -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]; diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/SbcConverter.m b/MouseSdk/AiMouseSdk/AiMouseSdk/SbcConverter.m index aebec0c..0aed0b6 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk/SbcConverter.m +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/SbcConverter.m @@ -38,7 +38,7 @@ - (void)showLog:(NSString *)log{ if (self.outputLog) { - self.outputLog([NSString stringWithFormat:@"[audio] %@",log]); +// self.outputLog([NSString stringWithFormat:@"[audio] %@",log]); } } diff --git a/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.h b/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.h index 1122cfe..b254f99 100644 --- a/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.h +++ b/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.h @@ -23,5 +23,6 @@ - (void)sendToSdk:(NSData *)data; +- (void)disconnected; @end diff --git a/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.m b/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.m index 7d0101b..403d98b 100644 --- a/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.m +++ b/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.m @@ -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); } @@ -68,57 +70,9 @@ [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 *)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 *)split:(NSData *)data { + NSMutableArray *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 diff --git a/MouseSdk/AiMouseSdk/Keyboard/KeyboardHidManager.m b/MouseSdk/AiMouseSdk/Keyboard/KeyboardHidManager.m index cdac9e6..ae11b41 100644 --- a/MouseSdk/AiMouseSdk/Keyboard/KeyboardHidManager.m +++ b/MouseSdk/AiMouseSdk/Keyboard/KeyboardHidManager.m @@ -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; } diff --git a/MouseSdk/AiMouseSdk/M8/M8MouseSdk.m b/MouseSdk/AiMouseSdk/M8/M8MouseSdk.m index 34fccd2..183256d 100644 --- a/MouseSdk/AiMouseSdk/M8/M8MouseSdk.m +++ b/MouseSdk/AiMouseSdk/M8/M8MouseSdk.m @@ -35,10 +35,6 @@ return self; } --(NSString *)version{ - return @"1.0.2"; -} - - (AiRecordManager *)recordManager{ if (!_recordManager) { _recordManager = [[AiRecordManager alloc] init]; @@ -115,18 +111,23 @@ } - (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 @@ -274,7 +275,7 @@ } #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]; } @@ -291,13 +292,13 @@ - (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]; } diff --git a/MouseSdk/AiMouseSdk/Manager/BleManager.h b/MouseSdk/AiMouseSdk/Manager/BleManager.h index a704bfa..f5e9c9b 100644 --- a/MouseSdk/AiMouseSdk/Manager/BleManager.h +++ b/MouseSdk/AiMouseSdk/Manager/BleManager.h @@ -21,5 +21,7 @@ - (void)open; -(void)writeToDevice:(NSData *)data; + +- (void)disconnected; @end diff --git a/MouseSdk/AiMouseSdk/Manager/BleManager.m b/MouseSdk/AiMouseSdk/Manager/BleManager.m index fd44b4a..5688b05 100644 --- a/MouseSdk/AiMouseSdk/Manager/BleManager.m +++ b/MouseSdk/AiMouseSdk/Manager/BleManager.m @@ -197,7 +197,7 @@ } //收到蓝牙数据 - (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]){ @@ -319,4 +319,7 @@ } } +- (void)disconnected{ + self.curentPeripheral = nil; +} @end diff --git a/MouseSdk/AiMouseSdk/Manager/DeviceManger.m b/MouseSdk/AiMouseSdk/Manager/DeviceManger.m index 78202c0..1c2c895 100644 --- a/MouseSdk/AiMouseSdk/Manager/DeviceManger.m +++ b/MouseSdk/AiMouseSdk/Manager/DeviceManger.m @@ -50,7 +50,7 @@ - (instancetype)init{ self = [super init]; if (self) { - self.version = @"MouseSdk_v2025041501"; + self.version = @"MouseSdk_v2025042801"; } return self; } @@ -671,6 +671,10 @@ 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: 数据 @@ -893,6 +897,9 @@ if (self.aiMouseConnectStateDidChangeCallBack) { self.aiMouseConnectStateDidChangeCallBack(self.frkSdk.connectType == AiMouseConnectType_bluetooth ? 0:1,connected); } + if (self.frkSdk.connectType == AiMouseConnectType_bluetooth && connected == false) { + [self.ble disconnected]; + } } /// 鉴权结果返回 @@ -978,6 +985,10 @@ 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]; + } } diff --git a/MouseSdk/AiMouseSdk/Manager/HidManager.m b/MouseSdk/AiMouseSdk/Manager/HidManager.m index 0a09a9a..0a25599 100644 --- a/MouseSdk/AiMouseSdk/Manager/HidManager.m +++ b/MouseSdk/AiMouseSdk/Manager/HidManager.m @@ -13,10 +13,12 @@ #import #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{ diff --git a/MouseSdk/AiMouseSdk/Manager/TimerManager.m b/MouseSdk/AiMouseSdk/Manager/TimerManager.m index bfe9912..31e7535 100644 --- a/MouseSdk/AiMouseSdk/Manager/TimerManager.m +++ b/MouseSdk/AiMouseSdk/Manager/TimerManager.m @@ -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 index 0000000..3c81beb --- /dev/null +++ b/MouseSdk/AiMouseSdk/TlwMouseSdk/Tlw2ReceiveManager.h @@ -0,0 +1,17 @@ +// +// DataReceiveManager.h +// AiMouseSdk +// +// Created by liangshi on 2025/4/28. +// + +#import + +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 index 0000000..e740e89 --- /dev/null +++ b/MouseSdk/AiMouseSdk/TlwMouseSdk/Tlw2ReceiveManager.m @@ -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 diff --git a/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m b/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m index 0ab53c5..a940f0c 100644 --- a/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m +++ b/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m @@ -56,9 +56,6 @@ return self; } --(NSString *)version{ - return @"1.0.2"; -} - (AiRecordManager *)recordManager{ if (!_recordManager) { @@ -732,7 +729,7 @@ } #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]; } diff --git a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate index 194ce2d..c3f94d2 100644 Binary files a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate and b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 910b871..45774dd 100644 --- a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -3,22 +3,4 @@ uuid = "D56CBD13-B1CD-4964-946C-9C0A140796C8" type = "0" version = "2.0"> - - - - - - diff --git a/MouseSdk/Pods/Pods.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist b/MouseSdk/Pods/Pods.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist index a1cc8f6..8988d3e 100644 --- a/MouseSdk/Pods/Pods.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/MouseSdk/Pods/Pods.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,12 +7,12 @@ Masonry.xcscheme_^#shared#^_ orderHint - 3 + 4 Pods-MouseSdk.xcscheme_^#shared#^_ orderHint - 2 + 3