From: liangzhenying <867174124@qq.com> Date: Tue, 3 Dec 2024 05:52:41 +0000 (+0800) Subject: usb模式录音每次输出不超过800byte X-Git-Tag: 威鼠泰凌微电池电量版本优化~2 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=39c74efff0bb81afec96a46a920b47b64071070f;p=mirrors%2FMouseSdk-MacOS.git usb模式录音每次输出不超过800byte --- diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiRecordManager.m b/MouseSdk/AiMouseSdk/AiMouseSdk/AiRecordManager.m index 60a2179..9a25b3f 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk/AiRecordManager.m +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiRecordManager.m @@ -92,19 +92,27 @@ // self.recordData = [[NSMutableData alloc] init]; __weak typeof(self) ws = self; [input installTapOnBus:bus bufferSize:32 format:inputFormat block:^(AVAudioPCMBuffer * _Nonnull buffer, AVAudioTime * _Nonnull when) { + +// NSData *data = [ws pcm_downsample:buffer]; +// if (ws.didRecordData) { +// ws.didRecordData(data); +// } NSData *data = [ws pcm_downsample:buffer]; - if (ws.didRecordData) { - ws.didRecordData(data); + NSInteger index = 0; + NSInteger len = 800; + while (index < data.length) { + if (index + 800 > data.length) { + len = data.length - index; + } + else{ + len = 800; + } + NSData *subData = [data subdataWithRange:NSMakeRange(index, len)]; + if (ws.didRecordData) { + ws.didRecordData(subData); + } + index += len; } -// NSLog(@"%@",data); -// NSError *err0; - // [ws.outputFile writeFromBuffer:buffer error:&err0]; - // if (err0) { - // [self showLog:[NSString stringWithFormat:@"写入失败 %@", err0.description]]; - // } - // else{ - // [self showLog:@"写入成功"]; - // } }]; NSError *err1; diff --git a/MouseSdk/AiMouseSdk/Keyboard/KeyboardHidManager.m b/MouseSdk/AiMouseSdk/Keyboard/KeyboardHidManager.m index fcf8578..cdac9e6 100644 --- a/MouseSdk/AiMouseSdk/Keyboard/KeyboardHidManager.m +++ b/MouseSdk/AiMouseSdk/Keyboard/KeyboardHidManager.m @@ -87,7 +87,7 @@ 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]; - [[KeyboardHidManager shared] showLog:[NSString stringWithFormat:@"receive = %@",data]]; +// [[KeyboardHidManager shared] showLog:[NSString stringWithFormat:@"receive = %@",data]]; if([KeyboardHidManager shared].productType == AiMouseProductType_n){ uint32_t primaryUsagePage = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsagePageKey)); uint32_t primaryUsage = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsageKey)); diff --git a/MouseSdk/AiMouseSdk/Manager/DeviceManger.m b/MouseSdk/AiMouseSdk/Manager/DeviceManger.m index c68ab58..d6322d5 100644 --- a/MouseSdk/AiMouseSdk/Manager/DeviceManger.m +++ b/MouseSdk/AiMouseSdk/Manager/DeviceManger.m @@ -45,7 +45,7 @@ - (instancetype)init{ self = [super init]; if (self) { - NSString *version = @"MouseSdk_v2024112004"; + NSString *version = @"MouseSdk_v2024120301"; NSLog(@"[AiMouseSdk] %@",version); [self showLog:version];; [self setupSDK]; diff --git a/MouseSdk/AiMouseSdk/Manager/HidManager.m b/MouseSdk/AiMouseSdk/Manager/HidManager.m index 0a12880..3f1668b 100644 --- a/MouseSdk/AiMouseSdk/Manager/HidManager.m +++ b/MouseSdk/AiMouseSdk/Manager/HidManager.m @@ -180,7 +180,7 @@ 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]; - [[HidManager shared] showLog:[NSString stringWithFormat:@"receive = %@",data]]; +// [[HidManager shared] showLog:[NSString stringWithFormat:@"receive = %@",data]]; if([HidManager shared].productType == AiMouseProductType_keyboard){ uint32_t primaryUsagePage = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsagePageKey)); uint32_t primaryUsage = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsageKey)); diff --git a/MouseSdk/AiMouseSdk/NMouseSdk/NMouseSdk.m b/MouseSdk/AiMouseSdk/NMouseSdk/NMouseSdk.m index 256b66e..a3a4144 100644 --- a/MouseSdk/AiMouseSdk/NMouseSdk/NMouseSdk.m +++ b/MouseSdk/AiMouseSdk/NMouseSdk/NMouseSdk.m @@ -56,69 +56,33 @@ } //北科专属 -//- (void)sendDeviceDataToSdk:(NSData *)data{ -// -// NSString *text = [TlwTools dataToHexString:data]; -// -//// 鼠标 0x020001f0ff0000 -//// sn1 0xb52c00bba30d5540 -//// sn2 0xb52c01bba30d5540 -//// 62DF3D553297 -// -// if ([text hasPrefix:@"B52C00"]) { -// [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; -// [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; -// if (self.getSn1CallBack) { -// //北科加42专属 -// self.getSn1CallBack([NSString stringWithFormat:@"42%@",[text substringWithRange:NSMakeRange(6, 8)]], nil); -// } -// } -// else if ([text hasPrefix:@"B52C01"]) { -// [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; -// [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; -// if (self.getSn2CallBack) { -// //北科加42专属 -// self.getSn2CallBack([text substringWithRange:NSMakeRange(6, 2)], nil); -// } -// } -// else if([text hasPrefix:@"B5200443"]){ -// [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; -// uint8_t cmd = 0x42; -// NSMutableData *mData = [NSMutableData data]; -// [mData appendBytes:&cmd length:1]; -// [self.delegate nMouseSendCmdData:mData]; -// } -// else if([text hasPrefix:@"B5200057"]){ -// [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; -// uint8_t cmd = 0x42; -// NSMutableData *mData = [NSMutableData data]; -// [mData appendBytes:&cmd length:1]; -// [self.delegate nMouseSendCmdData:mData]; -// } -//} - -//千寻 - (void)sendDeviceDataToSdk:(NSData *)data{ + NSString *text = [TlwTools dataToHexString:data]; // 鼠标 0x020001f0ff0000 // sn1 0xb52c00bba30d5540 // sn2 0xb52c01bba30d5540 // 62DF3D553297 - [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; + if ([text hasPrefix:@"B52C00"]) { + [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; if (self.getSn1CallBack) { - self.getSn1CallBack([text substringWithRange:NSMakeRange(6, 8)], nil); + //北科加42专属 + self.getSn1CallBack([NSString stringWithFormat:@"42%@",[text substringWithRange:NSMakeRange(6, 8)]], nil); } } else if ([text hasPrefix:@"B52C01"]) { + [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; if (self.getSn2CallBack) { - self.getSn2CallBack([text substringWithRange:NSMakeRange(6, 4)], nil); + //北科加42专属 + self.getSn2CallBack([text substringWithRange:NSMakeRange(6, 2)], nil); } } else if([text hasPrefix:@"B5200443"]){ + [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; uint8_t cmd = 0x42; NSMutableData *mData = [NSMutableData data]; [mData appendBytes:&cmd length:1]; @@ -132,6 +96,42 @@ [self.delegate nMouseSendCmdData:mData]; } } + +//千寻 +//- (void)sendDeviceDataToSdk:(NSData *)data{ +// NSString *text = [TlwTools dataToHexString:data]; +// +//// 鼠标 0x020001f0ff0000 +//// sn1 0xb52c00bba30d5540 +//// sn2 0xb52c01bba30d5540 +//// 62DF3D553297 +// [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; +// if ([text hasPrefix:@"B52C00"]) { +// [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; +// if (self.getSn1CallBack) { +// self.getSn1CallBack([text substringWithRange:NSMakeRange(6, 8)], nil); +// } +// } +// else if ([text hasPrefix:@"B52C01"]) { +// [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; +// if (self.getSn2CallBack) { +// self.getSn2CallBack([text substringWithRange:NSMakeRange(6, 4)], nil); +// } +// } +// else if([text hasPrefix:@"B5200443"]){ +// uint8_t cmd = 0x42; +// NSMutableData *mData = [NSMutableData data]; +// [mData appendBytes:&cmd length:1]; +// [self.delegate nMouseSendCmdData:mData]; +// } +// else if([text hasPrefix:@"B5200057"]){ +// [self showLog:[NSString stringWithFormat:@"[receive][usb][info] %@",text]]; +// uint8_t cmd = 0x42; +// NSMutableData *mData = [NSMutableData data]; +// [mData appendBytes:&cmd length:1]; +// [self.delegate nMouseSendCmdData:mData]; +// } +//} - (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))finished{ [NSObject cancelPreviousPerformRequestsWithTarget:self]; self.getDeviceInfoCallBack = finished; diff --git a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate index 83cf893..ba56219 100644 Binary files a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate and b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate differ