From: liangzhenying <867174124@qq.com> Date: Fri, 17 May 2024 12:22:13 +0000 (+0800) Subject: 写入deviceSecrect直到成功 X-Git-Tag: 千寻适配d9~66 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=4748c235aaba8f76337d2ee739b5250364bbcf70;p=mirrors%2FMouseSdk-MacOS.git 写入deviceSecrect直到成功 --- diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiAuthManager.m b/MouseSdk/AiMouseSdk/AiMouseSdk/AiAuthManager.m index db6b87f..e516295 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk/AiAuthManager.m +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiAuthManager.m @@ -33,12 +33,12 @@ #pragma mark - pub api - (void)loginWith:(AiMouseDeviceInfo *)info{ + self.deviceInfo = info; if (![info valueForKey:@"productKey"] || ![info valueForKey:@"secretKey"] || !info.sn || !info.sn) { [self showLog:@"获取设备信息错误,鉴权失败!"]; return; } - if([info valueForKey:@"deviceSecret"]){ //已注册过,直接登录 [self loginRequest]; diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.h b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.h index 5e1d5e8..f0e96b6 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.h +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.h @@ -101,4 +101,6 @@ typedef NS_ENUM(NSInteger,AiMouseAuthState) { /// - value: AiMouseDeviceInfo 中可以设置的值CPI_list /// - finished: 设置结果回调 - (void)setCPI:(NSInteger)value completation:(void (^)(BOOL isSuccess,NSError *error))finished; + +- (void)setDS; @end diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m index 6f9d9e9..7daa2be 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m @@ -39,6 +39,8 @@ @property (nonatomic, strong) void (^getRSSIBlock)(NSString *value); @property (nonatomic, strong) SetDeviceSecretBlock deviceSecretBlock; @property (nonatomic, strong) void (^authBlock)(AiMouseAuthState state); +@property (nonatomic, strong) NSString *updateDS;//更新deviceSecret +@property (nonatomic, strong) NSTimer *dsTimer; @end @implementation AiMouse @@ -188,8 +190,8 @@ NSString *str2 = [AiMouseTools2 fixDeviceData:str]; NSDictionary *dict = [AiMouseTools stringToDictionary:str2]; // [self showLog:[NSString stringWithFormat:@"总data = %@",[AiMouseTools dataToHexString:data]]]; -// [self showLog:[NSString stringWithFormat:@"fix前 = %@",str]]; -// [self showLog:[NSString stringWithFormat:@"fix后 = %@",str2]]; + [self showLog:[NSString stringWithFormat:@"fix前 = %@",str]]; + [self showLog:[NSString stringWithFormat:@"fix后 = %@",str2]]; if (dict == nil) { if(data.length > 7 && [[AiMouseTools dataToHexString:[data subdataWithRange:NSMakeRange(0, 7)]] .lowercaseString isEqualToString:@"7b22534e223a22"] ){ //SN异常 @@ -223,6 +225,7 @@ if(self.deviceSecretBlock){ self.deviceSecretBlock(true); self.deviceSecretBlock = nil; + [self removeSendTimer]; } } else{ @@ -319,22 +322,113 @@ } - (void)setDeviceSecret:(NSString *)value completation:(SetDeviceSecretBlock)complete{ + self.updateDS = value; self.deviceSecretBlock = complete; NSData *data = [AiMouseTools dictionaryToData:@{@"cmd":@"set_config",@"set_deviceSecret":value}]; [self sendDeviceInfoData:data]; + [self addSendTimer]; +} + +- (void)setDS{ +// NSString *value = @"JXa2HAaXhaw5mnbjqadtMQQoDQOmGGQw"; + NSString *value = @"JXa2HAaXhaw5mnbjqadtMQQoDQOmGGQw"; + [self setDeviceSecret:value completation:^(BOOL isSuccess) { +// NSLog(@"写入ds成功========"); + }]; +} +- (void)addSendTimer{ + [self removeSendTimer]; + dispatch_async(dispatch_queue_create("DeviceQueue", DISPATCH_QUEUE_SERIAL), ^{ + self.dsTimer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(dsTimerAction) userInfo:nil repeats:true]; + [[NSRunLoop currentRunLoop] addTimer:self.dsTimer forMode:NSRunLoopCommonModes]; + [[NSRunLoop currentRunLoop] run]; + }); +} +- (void)removeSendTimer{ + if (self.dsTimer && [self.dsTimer isValid]) { + [self.dsTimer invalidate]; + } +} + +- (void)dsTimerAction{ + if(self.updateDS && self.deviceSecretBlock){ + [self setDeviceSecret:self.updateDS completation:self.deviceSecretBlock]; + } + else{ + [self removeSendTimer]; + } } #pragma mark - other - (void)sendDeviceInfoData:(NSData *)data{ - NSString *str = [AiMouseTools dataToUtf8String:data]; - NSMutableString *str1 = [NSMutableString stringWithString:str]; - NSString *sendStr = [NSString stringWithFormat:@"-$$%@$$-\n",str1]; - NSData *sendData = [sendStr dataUsingEncoding:NSUTF8StringEncoding]; +// NSString *str = [AiMouseTools dataToUtf8String:data]; +// NSMutableString *str1 = [NSMutableString stringWithString:str]; +// +// NSString *sendStr = [NSString stringWithFormat:@"-$$%@$$-\n",str1]; +// NSData *sendData = [sendStr dataUsingEncoding:NSUTF8StringEncoding]; // [self showLog:[NSString stringWithFormat:@"发送的设备信息数据 = %@",sendStr]]; - if (self.delegate) { - [self.delegate aiMouseSendDeviceInfoData:sendData]; +// if (self.delegate) { +// [self.delegate aiMouseSendDeviceInfoData:sendData]; +// } + +// NSString *str = [AiMouseTools dataToUtf8String:data]; + NSString *str = [AiMouseTools dataToUtf8String:data]; + NSArray *list = [self splitCMD:str]; + + + if(list.count > 1){ + { + NSString *sendStr = @"-$$\0"; + NSData *sendData = [sendStr dataUsingEncoding:NSUTF8StringEncoding]; +// [self showLog:[NSString stringWithFormat:@"发送的设备信息数据 = %@",sendStr]]; + if (self.delegate) { + [self.delegate aiMouseSendDeviceInfoData:sendData]; + } + } + for (NSInteger i = 0; i < list.count; i++) { + NSString *sendStr = [NSString stringWithFormat:@"%@\0",list[i]]; + NSData *sendData = [sendStr dataUsingEncoding:NSUTF8StringEncoding]; +// [self showLog:[NSString stringWithFormat:@"发送的设备信息数据 = %@",sendStr]]; + if (self.delegate) { + [self.delegate aiMouseSendDeviceInfoData:sendData]; + } + } + { + NSString *sendStr = @"$$-\0"; + NSData *sendData = [sendStr dataUsingEncoding:NSUTF8StringEncoding]; +// [self showLog:[NSString stringWithFormat:@"发送的设备信息数据 = %@",sendStr]]; + if (self.delegate) { + [self.delegate aiMouseSendDeviceInfoData:sendData]; + } + } + } + else{ + NSString *sendStr = [NSString stringWithFormat:@"-$$%@$$-\n",str]; + NSData *sendData = [sendStr dataUsingEncoding:NSUTF8StringEncoding]; +// [self showLog:[NSString stringWithFormat:@"发送的设备信息数据 = %@",sendStr]]; + if (self.delegate) { + [self.delegate aiMouseSendDeviceInfoData:sendData]; + } } } +- (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)sendRecordData:(NSData *)data{ if (self.authState != AiMouseAuthState_Success){ [self showLog:@"设备还未鉴权!!!"]; @@ -381,5 +475,6 @@ // [self showLog:@"结束录音"]; } + @end diff --git a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate index d3bdc84..6c6a72b 100644 Binary files a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate and b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/MouseSdk/MouseSdk/ViewController.m b/MouseSdk/MouseSdk/ViewController.m index fb74f81..1928a81 100644 --- a/MouseSdk/MouseSdk/ViewController.m +++ b/MouseSdk/MouseSdk/ViewController.m @@ -34,6 +34,24 @@ - (void)setupUI{ self.title = @"AI SDK"; + { + NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(50, self.view.bounds.size.height + 80, 100, 45)]; + btn.bordered = true; + btn.title = @"设置CPI"; + [btn setTarget:self]; + [btn setAction:@selector(cpiAction)]; + btn.state = 1; + [self.view addSubview:btn]; + } + { + NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(50, self.view.bounds.size.height, 100, 45)]; + btn.bordered = true; + btn.title = @"写入deviceScrect"; + [btn setTarget:self]; + [btn setAction:@selector(deviceScrectAction)]; + btn.state = 1; + [self.view addSubview:btn]; + } { NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(50, self.view.bounds.size.height - 80, 100, 45)]; btn.bordered = true; @@ -105,6 +123,16 @@ [self presentViewControllerAsModalWindow:vc]; } +- (void)cpiAction{ + [[AiMouse shared] setCPI:1000 completation:^(BOOL isSuccess, NSError *error) { + NSLog(@"1"); + }]; +} + +- (void)deviceScrectAction{ + [[AiMouse shared] setDS]; +} + /// 获取设备信息 - (void)geviceInfoAction{ [[DeviceManger shared] getDeviceInfo:^(AiMouseDeviceInfo *deviceInfo, NSError *error) {