|
@@ -37,6 +37,8 @@ WHPingDelegate
|
|
|
@property (nonatomic, assign) NSInteger tcpPort;
|
|
|
|
|
|
@property (nonatomic, copy) NSString *Pre_sdnId;//上一个sdn好
|
|
|
+
|
|
|
+@property (nonatomic, assign) BOOL isGetThridMsgType;
|
|
|
@end
|
|
|
|
|
|
@implementation connectDeviceManager
|
|
@@ -57,23 +59,32 @@ static connectDeviceManager *connectDeviceManagerInstance = nil;
|
|
|
#pragma mark 根据扫码的sn获取第三方信息
|
|
|
-(void)getThridMsgBySN:(NSString*)snStr needReconnect:(BOOL)needReconnect didNetEnd:(netWork_DidEndByOK)didNetEndIsOK
|
|
|
{
|
|
|
+
|
|
|
+ if(_isGetThridMsgType){
|
|
|
+ didNetEndIsOK(NO);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
if(needReconnect){
|
|
|
_curConnectDeviceState = DeviceConnectGetThridMsging;
|
|
|
|
|
|
//更换设备
|
|
|
- NSString *curSdnId = self.DeviceThirdIdMod.data.sdnId;
|
|
|
- if(curSdnId){
|
|
|
- _Pre_sdnId = curSdnId;
|
|
|
- }
|
|
|
+// NSString *curSdnId = self.DeviceThirdIdMod.data.sdnId;
|
|
|
+// if(curSdnId){
|
|
|
+// _Pre_sdnId = curSdnId;
|
|
|
+// }
|
|
|
|
|
|
}
|
|
|
|
|
|
NSMutableDictionary *paraDict = [NSMutableDictionary new];
|
|
|
[paraDict setValue:snStr forKey:@"sn"];
|
|
|
|
|
|
+ _isGetThridMsgType = YES;
|
|
|
KWeakSelf
|
|
|
[[netWorkManager shareInstance] CommonGetWithCallBackCode:getThirdIdBySn Parameters:paraDict success:^(id _Nonnull responseObject) {
|
|
|
|
|
|
+ self->_isGetThridMsgType = NO;
|
|
|
+
|
|
|
DeviceThirdIdModel *model = [[DeviceThirdIdModel alloc] initWithDictionary:responseObject error:nil];
|
|
|
|
|
|
if(model && model.data){
|
|
@@ -83,6 +94,7 @@ static connectDeviceManager *connectDeviceManagerInstance = nil;
|
|
|
if(weakSelf.DeviceThirdIdMod.status == 0
|
|
|
&& weakSelf.DeviceThirdIdMod.data)
|
|
|
{
|
|
|
+ //[[iToast makeText:[[NSString alloc] initWithFormat:@"sdnID:%@",model.data.sdnId]] show];
|
|
|
|
|
|
NSString*desPwdstr = [RSATool AES128Decrypt:weakSelf.DeviceThirdIdMod.data.password key:AESCODEKEEYY];
|
|
|
|
|
@@ -111,12 +123,21 @@ static connectDeviceManager *connectDeviceManagerInstance = nil;
|
|
|
|
|
|
} failure:^(NSError * _Nonnull error) {
|
|
|
HLog("网络报错");
|
|
|
+ self->_isGetThridMsgType = NO;
|
|
|
didNetEndIsOK(NO);
|
|
|
}];
|
|
|
}
|
|
|
|
|
|
#pragma mark 初始化瑞云的SDK等
|
|
|
- (void)initRuiyunSDKFun{
|
|
|
+
|
|
|
+ bool connected = [RaylinkProxy.sharedManager isSdnConnected];
|
|
|
+ if(connected){
|
|
|
+ [self onConnectFun];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
HLog(@"initRuiyunSDKFun");
|
|
|
|
|
|
// bool connected = [RaylinkProxy.sharedManager isSdnConnected];
|
|
@@ -159,6 +180,7 @@ static connectDeviceManager *connectDeviceManagerInstance = nil;
|
|
|
}
|
|
|
|
|
|
|
|
|
+ KWeakSelf
|
|
|
/// 启动定时器监听 SND 连接状态
|
|
|
self.connectCheckTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 repeats:YES block:^(NSTimer * _Nonnull timer) {
|
|
|
|
|
@@ -171,7 +193,9 @@ static connectDeviceManager *connectDeviceManagerInstance = nil;
|
|
|
self.sdnConnected = connected;
|
|
|
|
|
|
if (self.sdnConnected) {
|
|
|
-
|
|
|
+ [weakSelf onConnectFun];
|
|
|
+ [self->_connectCheckTimer invalidate];
|
|
|
+
|
|
|
//self.sdnConnectStateLab.text = @"SDN state: Connected";
|
|
|
//self.sdnIDLab.text = [@"My SDN ID: " stringByAppendingString:[RaylinkProxy.sharedManager getSdnId]];
|
|
|
|
|
@@ -184,34 +208,34 @@ static connectDeviceManager *connectDeviceManagerInstance = nil;
|
|
|
}];
|
|
|
|
|
|
|
|
|
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
- mainBlock(^{
|
|
|
- [self onConnectFun];
|
|
|
- });
|
|
|
- });
|
|
|
+// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+// mainBlock(^{
|
|
|
+// [self onConnectFun];
|
|
|
+// });
|
|
|
+// });
|
|
|
}
|
|
|
|
|
|
|
|
|
- (void)onConnectFun{
|
|
|
|
|
|
// 2. 监听SDN 连接状态
|
|
|
- bool connected = [RaylinkProxy.sharedManager isSdnConnected];
|
|
|
-
|
|
|
- HLog(@"协助瑞云看日志onConnectFun isSdnConnected:%d",connected);
|
|
|
-
|
|
|
- if(!connected){
|
|
|
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
- mainBlock(^{
|
|
|
- [self onConnectFun];
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- return;
|
|
|
- }
|
|
|
+// bool connected = [RaylinkProxy.sharedManager isSdnConnected];
|
|
|
+//
|
|
|
+// HLog(@"协助瑞云看日志onConnectFun isSdnConnected:%d",connected);
|
|
|
+//
|
|
|
+// if(!connected){
|
|
|
+// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
+// mainBlock(^{
|
|
|
+// [self onConnectFun];
|
|
|
+// });
|
|
|
+// });
|
|
|
+//
|
|
|
+// return;
|
|
|
+// }
|
|
|
|
|
|
if (self.peerConnected == YES) {
|
|
|
[self disconnect];
|
|
|
- return;
|
|
|
+ //return;
|
|
|
}
|
|
|
|
|
|
_curConnectDeviceState = DeviceConnectDeciceing;
|
|
@@ -290,6 +314,8 @@ static connectDeviceManager *connectDeviceManagerInstance = nil;
|
|
|
[self.socket connectToHost:@"127.0.0.1" onPort:self.tcpPort error:NULL];
|
|
|
|
|
|
_curConnectDeviceState = DeviceConnectDeciceOk;
|
|
|
+ _Pre_sdnId = self.DeviceThirdIdMod.data.sdnId;
|
|
|
+
|
|
|
// [self.connectBtn setTitle:@"连接成功" forState:UIControlStateDisabled];
|
|
|
// [self.sendBtn setEnabled:YES];
|
|
|
} else {
|