|
|
@ -206,8 +206,17 @@ NSString *FLT_BLE_RCSP_R = @"AE02"; //命令“读”通道 |
|
|
if (ble_name.length == 0) return; |
|
|
if (ble_name.length == 0) return; |
|
|
|
|
|
|
|
|
kJLLog(JLLOG_DEBUG, @"发现 ----> NAME:%@ RSSI:%@ AD:%@", ble_name,RSSI,ble_AD); |
|
|
kJLLog(JLLOG_DEBUG, @"发现 ----> NAME:%@ RSSI:%@ AD:%@", ble_name,RSSI,ble_AD); |
|
|
|
|
|
|
|
|
[self addPeripheral:peripheral RSSI:RSSI Name:ble_name Info:ble_AD]; |
|
|
if (ble_AD.length >= 29) { |
|
|
|
|
|
const uint8_t *bytes = ble_AD.bytes; |
|
|
|
|
|
NSMutableString *macStr = [NSMutableString string]; |
|
|
|
|
|
for (int i = 7; i <= 12; i++) { |
|
|
|
|
|
uint8_t macByte = bytes[i] ^ 0x5A; |
|
|
|
|
|
[macStr appendFormat:@"%02X", macByte]; |
|
|
|
|
|
if (i < 12) [macStr appendString:@":"]; |
|
|
|
|
|
} |
|
|
|
|
|
[self addPeripheral:peripheral Info:macStr]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:kFLT_BLE_FOUND object:_blePeripheralArr userInfo:nil]; |
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:kFLT_BLE_FOUND object:_blePeripheralArr userInfo:nil]; |
|
|
|
|
|
|
|
|
@ -217,11 +226,11 @@ NSString *FLT_BLE_RCSP_R = @"AE02"; //命令“读”通道 |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
- (void)addPeripheral:(CBPeripheral*)peripheral RSSI:(NSNumber *)rssi Name:(NSString*)name Info:(NSData*)blead{ |
|
|
- (void)addPeripheral:(CBPeripheral*)peripheral Info:(NSString*)macStr { |
|
|
// if ([name isEqualToString:@"DeapSound"]) { |
|
|
if (self.lastAddress && [macStr isEqualToString:self.lastAddress]) { |
|
|
// [self stopScanBLE]; |
|
|
[self stopScanBLE]; |
|
|
// [self connectBLE:peripheral]; |
|
|
[self connectBLE:peripheral]; |
|
|
// } |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#pragma mark 设备连接回调 |
|
|
#pragma mark 设备连接回调 |
|
|
@ -349,13 +358,7 @@ NSString *FLT_BLE_RCSP_R = @"AE02"; //命令“读”通道 |
|
|
if (needForcedUpgrade) { |
|
|
if (needForcedUpgrade) { |
|
|
kJLLog(JLLOG_DEBUG, @"设备需要强制升级,请到升级界面选择ota升级文件进行升级!"); |
|
|
kJLLog(JLLOG_DEBUG, @"设备需要强制升级,请到升级界面选择ota升级文件进行升级!"); |
|
|
} |
|
|
} |
|
|
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; |
|
|
[self otaFuncWithFilePath:self.lastFilePath]; |
|
|
NSString *otaFilePath = [documentsPath stringByAppendingPathComponent:@"update030.ufw"]; |
|
|
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath:otaFilePath]) { |
|
|
|
|
|
[self otaFuncWithFilePath:otaFilePath]; |
|
|
|
|
|
} else { |
|
|
|
|
|
kJLLog(JLLOG_DEBUG, @"OTA文件不存在: %@", otaFilePath); |
|
|
|
|
|
} |
|
|
|
|
|
}]; |
|
|
}]; |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
@ -396,6 +399,15 @@ NSString *FLT_BLE_RCSP_R = @"AE02"; //命令“读”通道 |
|
|
*/ |
|
|
*/ |
|
|
- (void)otaFuncWithFilePath:(NSString *)otaFilePath { |
|
|
- (void)otaFuncWithFilePath:(NSString *)otaFilePath { |
|
|
kJLLog(JLLOG_DEBUG, @"current otaFilePath ---> %@", otaFilePath); |
|
|
kJLLog(JLLOG_DEBUG, @"current otaFilePath ---> %@", otaFilePath); |
|
|
|
|
|
if (self.flutterEventSink) { |
|
|
|
|
|
self.flutterEventSink(@{ |
|
|
|
|
|
@"event": @"onStartOTA", |
|
|
|
|
|
@"type": @0, |
|
|
|
|
|
@"progress": @0.0, |
|
|
|
|
|
@"code": @8, |
|
|
|
|
|
@"message": @"开始升级" |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
self.selectedOtaFilePath = otaFilePath; |
|
|
self.selectedOtaFilePath = otaFilePath; |
|
|
NSData *otaData = [[NSData alloc] initWithContentsOfFile:otaFilePath]; |
|
|
NSData *otaData = [[NSData alloc] initWithContentsOfFile:otaFilePath]; |
|
|
|
|
|
|
|
|
@ -425,6 +437,55 @@ NSString *FLT_BLE_RCSP_R = @"AE02"; //命令“读”通道 |
|
|
-(void)otaUpgradeResult:(JL_OTAResult)result Progress:(float)progress{ |
|
|
-(void)otaUpgradeResult:(JL_OTAResult)result Progress:(float)progress{ |
|
|
//TODO: 设备升级过程回调,包括进度状态 |
|
|
//TODO: 设备升级过程回调,包括进度状态 |
|
|
kJLLog(JLLOG_DEBUG, @"otaUpgradeResult ---> %u", result); |
|
|
kJLLog(JLLOG_DEBUG, @"otaUpgradeResult ---> %u", result); |
|
|
|
|
|
if (result == JL_OTAResultPreparing) { |
|
|
|
|
|
if (self.flutterEventSink) { |
|
|
|
|
|
self.flutterEventSink(@{ |
|
|
|
|
|
@"event": @"onProgress", |
|
|
|
|
|
@"type": @0, |
|
|
|
|
|
@"progress": @(progress * 100), |
|
|
|
|
|
@"code": @(result), |
|
|
|
|
|
@"message": @"开始升级" |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} else if (result == JL_OTAResultUpgrading) { |
|
|
|
|
|
if (self.flutterEventSink) { |
|
|
|
|
|
self.flutterEventSink(@{ |
|
|
|
|
|
@"event": @"onProgress", |
|
|
|
|
|
@"type": @1, |
|
|
|
|
|
@"progress": @(progress * 100), |
|
|
|
|
|
@"code": @(result), |
|
|
|
|
|
@"message": @"开始升级" |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} else if (result == JL_OTAResultPrepared) { |
|
|
|
|
|
|
|
|
|
|
|
} else if (result == JL_OTAResultReconnect) { |
|
|
|
|
|
|
|
|
|
|
|
} else if (result == JL_OTAResultReconnectWithMacAddr) { |
|
|
|
|
|
|
|
|
|
|
|
} else if (result == JL_OTAResultSuccess) { |
|
|
|
|
|
if (self.flutterEventSink) { |
|
|
|
|
|
self.flutterEventSink(@{ |
|
|
|
|
|
@"event": @"onStopOTA", |
|
|
|
|
|
@"type": @0, |
|
|
|
|
|
@"progress": @0.0, |
|
|
|
|
|
@"code": @(result), |
|
|
|
|
|
@"message": @"升级成功" |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} else if (result == JL_OTAResultReboot) { |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
if (self.flutterEventSink) { |
|
|
|
|
|
self.flutterEventSink(@{ |
|
|
|
|
|
@"event": @"onError", |
|
|
|
|
|
@"type": @0, |
|
|
|
|
|
@"progress": @0.0, |
|
|
|
|
|
@"code": @(result), |
|
|
|
|
|
@"message": @"升级失败" |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
-(void)otaDataSend:(NSData *)data{ |
|
|
-(void)otaDataSend:(NSData *)data{ |
|
|
|