[toc]
本项⽬所参考、使⽤技术必须全部来源于公知技术信息,或⾃主创新设计。
本项⽬不得使⽤任何未经授权的第三⽅知识产权的技术信息。
如个⼈使⽤未经授权的第三⽅知识产权的技术信息,造成的经济损失和法律后果由个⼈承担。
版本 | 日期 | 编辑 | 修改内容 |
---|---|---|---|
V3.3.0 | 2023年03月23日 | 陈冠杰 | 适配新SDK2.1.0 |
V3.2.0 | 2023年1月11日 | 陈冠杰 | 重构UI页面,整理项目架构,新增自动化测试/广播音箱模块 |
v2.0.0 | 2021年10月14日 | 凌 煊峰 | 蓝牙库新增根据ble地址对升级设备的回连;重写ota demo |
v1.5.0 | 2021年09月08日 | 冯 洪鹏 | 优化自定义蓝牙SDK的接入方式 |
v1.2 | 2020年12月09日 | 冯 洪鹏 | 更新文档 |
v1.1 | 2020年04月20日 | 冯 洪鹏 | 增加升级的错误回调 |
v1.0 | 2019年09月09日 | 冯 洪鹏 | OTA升级功能 |
本文档描述了如何使用已有SDK:JL_BLEKit.framework、JL_OTALib.framework、JL_AdvParse.framework、JL_HashPair.framework等一系列库实现iOS端协助设备端实现OTA升级的过程。本文会随着版本迭代而更新信息以及相关接入时的变化,开发者在使用上述开发库时可优先查看本文。
实现OTA升级必须导入的库:
JL_OTALib.framework——OTA升级业务库
JL_AdvParse.framework——杰理蓝牙设备广播包解析业务库
JL_HashPair.framework——设备认证业务库
可选择导入的库:
JL_BLEKit.framework
备注:当开发者想要使用杰理集成的蓝牙库(连接、其他通讯业务)时,需要导入当前SDK使用
添加以下权限:
Privacy - Bluetooth Peripheral Usage Description
Privacy - Bluetooth Always Usage Description
自定义蓝牙连接方式(对应BleManager文件夹);
备注:自定义蓝牙连接中所有BLE的操作都自行实现,SDK只负责对OTA数据包解析。
使用JL_BLEKit.framework蓝牙连接方式(对应SDKBleManager文件夹)。
工程中已通过BleHandle文件夹内的JLBleHandler类进行了区分,具体可以参考实际源码。开发普通OTA升级流程只需要参考Views文件夹中的NormalUpdate文件内容即可。
参考Demo:「JL_OTA项目的BleManager文件夹」
支持的功能:
用到的库和相关类:
用到的库:
JL_OTALib.framework——OTA升级业务库
JL_AdvParse.framework——杰理蓝牙设备广播包解析业务库
JL_HashPair.framework——设备认证业务库
相关类说明:
**JL_OTAManager:**OTA升级业务管理类
平台 | 接口 | 功能 |
---|---|---|
iOS | cmdTargetFeature | 获取设备信息(是否需要升级/强制升级) |
iOS | cmdOtaDataReceive: | 设备端发过来的数据解析接口 |
iOS | cmdOTAData:Result: | 请求进入loader状态,需要携带升数据bfu |
iOS | cmdOTAData:Result: | 进行数据传输(进入loader,重连后需要再次调用) |
iOS | cmdRebootDevice | 重启设备命令 |
**JLHashHandler:**设备认证业务类
**JL_AdvParse:**广播包内容解析类
BLE特征参数
【服务号】:AE00
【写】特征值:AE01
【读 】特征值:AE02
@interface JLBleManager() <JL_OTAManagerDelegate,JLHashHandlerDelegate>
@property (strong, nonatomic) JLHashHandler *pairHash;
@end
- (instancetype)init {
self = [super init];
if (self) {
_otaManager = [[JL_OTAManager alloc] init];
_otaManager.delegate = self;
self.pairHash = [[JLHashHandler alloc] init];
self.pairHash.delegate = self;
[JL_OTAManager logSDKVersion];
[JLHashHandler sdkVersion];
}
return self;
}
#pragma mark 设备特征回调
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(nullable NSError *)error {
if (error) { NSLog(@"Err: Discovered Characteristics fail."); return; }
if ([service.UUID.UUIDString isEqual:FLT_BLE_SERVICE]) {
for (CBCharacteristic *character in service.characteristics) {
/*--- RCSP ---*/
if ([character.UUID.UUIDString isEqual:FLT_BLE_RCSP_W]) {
NSLog(@"BLE Get Rcsp(Write) Channel ---> %@",character.UUID.UUIDString);
self.mRcspWrite = character;
}
if ([character.UUID.UUIDString isEqual:FLT_BLE_RCSP_R]) {
NSLog(@"BLE Get Rcsp(Read) Channel ---> %@",character.UUID.UUIDString);
self.mRcspRead = character;
[peripheral setNotifyValue:YES forCharacteristic:character];
if(self.mRcspRead.properties == CBCharacteristicPropertyRead){
[peripheral readValueForCharacteristic:character];
NSLog(@"BLE Rcsp(Read) Read Value For Characteristic.");
}
}
}
}
}
#pragma mark 更新通知特征的状态
- (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(nonnull CBCharacteristic *)characteristic error:(nullable NSError *)error {
if (error) { NSLog(@"Err: Update NotificationState For Characteristic fail."); return; }
if ([characteristic.service.UUID.UUIDString isEqual:FLT_BLE_SERVICE] &&
[characteristic.UUID.UUIDString isEqual:FLT_BLE_RCSP_R] &&
characteristic.isNotifying == YES)
{
__weak typeof(self) weakSelf = self;
self.bleMtu = [peripheral maximumWriteValueLengthForType:CBCharacteristicWriteWithoutResponse];
NSLog(@"BLE ---> MTU:%lu",(unsigned long)self.bleMtu);
if (self.isPaired == YES) {
[_pairHash hashResetPair];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//设备认证
[self->_pairHash bluetoothPairingKey:self.pairKey Result:^(BOOL ret) {
if(ret){
weakSelf.lastUUID = peripheral.identifier.UUIDString;
weakSelf.lastBleMacAddress = nil;
[[NSNotificationCenter defaultCenter] postNotificationName:kFLT_BLE_PAIRED object:peripheral];
[weakSelf.otaManager noteEntityConnected];
weakSelf.pairStatus = YES;
}else{
NSLog(@"JL_Assist Err: bluetooth pairing fail.");
[weakSelf.bleManager cancelPeripheralConnection:peripheral];
}
}];
});
}else{
self.lastUUID = peripheral.identifier.UUIDString;
self.lastBleMacAddress = nil;
[[NSNotificationCenter defaultCenter] postNotificationName:kFLT_BLE_PAIRED object:peripheral];
[self.otaManager noteEntityConnected];
}
}
self.isConnected = YES;
}
设备端返回的数据需要放入到SDK中解析,其中设备认证部分和通讯部分的处理是分开的
#pragma mark 设备返回的数据 GET
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
if (error) { NSLog(@"Err: receive data fail."); return; }
if(_isPaired == YES && _pairStatus == NO){
//收到设备的认证交互数据
[_pairHash inputPairData:characteristic.value];
}else{
//收到的设备数据,正常通讯数据
[_otaManager cmdOtaDataReceive:characteristic.value];
}
}
#pragma mark 设备断开连接
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(nullable NSError *)error {
NSLog(@"BLE Disconnect ---> Device %@ error:%d", peripheral.name, (int)error.code);
[_otaManager noteEntityDisconnected];
self.isConnected = NO;
self.pairStatus = NO;
/*--- UI刷新,设备断开 ---*/
[[NSNotificationCenter defaultCenter] postNotificationName:kFLT_BLE_DISCONNECTED object:peripheral];
}
//外部蓝牙,手机蓝牙状态回调处,实现以下:
#pragma mark - 蓝牙初始化 Callback
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
_mBleManagerState = central.state;
if (_mBleManagerState != CBManagerStatePoweredOn) {
self.mBlePeripheral = nil;
self.blePeripheralArr = [NSMutableArray array];
}
}
BLE连接且配对后必须执行一次
[_otaManager cmdTargetFeature];
/**
* ota升级
* @param otaFilePath ota升级文件路径
*/
- (void)otaFuncWithFilePath:(NSString *)otaFilePath {
NSLog(@"current otaFilePath ---> %@", otaFilePath);
self.selectedOtaFilePath = otaFilePath;
NSData *otaData = [[NSData alloc] initWithContentsOfFile:otaFilePath];
[_otaManager cmdOTAData:otaData Result:^(JL_OTAResult result, float progress) {
for (id<JLBleManagerOtaDelegate> objc in self.delegates) {
if([objc respondsToSelector:@selector(otaProgressWithOtaResult:withProgress:)]){
[objc otaProgressWithOtaResult:result withProgress:progress];
}
}
}];
}
- (void)otaFuncCancel:(CANCEL_CALLBACK _Nonnull)result{
[_otaManager cmdOTACancelResult:^(uint8_t status, uint8_t sn, NSData * _Nullable data) {
result(status);
}];
}
//MARK: - ota manager delegate callback
///取消升级回调
-(void)otaCancel{
//TODO: 取消OTA升级回调
}
///升级状态进度回调
-(void)otaUpgradeResult:(JL_OTAResult)result Progress:(float)progress{
//TODO: 设备升级过程回调,包括进度状态
}
///即将发送给设备的数据
-(void)otaDataSend:(NSData *)data{
//TODO: 开发者需要在这里要把数据发送到设备
[self writeDataByCbp:data];
}
///设备信息回调
-(void)otaFeatureResult:(JL_OTAManager *)manager{
NSLog(@"getDeviceInfo:%d",__LINE__);
if (manager.otaStatus == JL_OtaStatusForce) {
NSLog(@"---> 进入强制升级.");
if (self.selectedOtaFilePath) {
[self otaFuncWithFilePath:self.selectedOtaFilePath];
} else {
_getCallback(true);
}
return;
} else {
if (manager.otaHeadset == JL_OtaHeadsetYES) {
NSLog(@"---> 进入强制升级: OTA另一只耳机.");
if (self.selectedOtaFilePath) {
[self otaFuncWithFilePath:self.selectedOtaFilePath];
} else {
_getCallback(true);
}
return;
}
}
NSLog(@"---> 设备正常使用...");
dispatch_async(dispatch_get_main_queue(), ^{
/*--- 获取公共信息 ---*/
[self->_otaManager cmdSystemFunction];
self->_getCallback(false);
});
}
//MARK: - Hash pair delegate callback
///即将发送到设备的认证数据
-(void)hashOnPairOutputData:(NSData *)data{
//TODO: 开发者需要在这里要把数据发送到设备
[self writeDataByCbp:data];
}
self.bleMtu = [peripheral maximumWriteValueLengthForType:CBCharacteristicWriteWithoutResponse];
代码参考如下:
//MARK: - data send manager
/// 需要分包发送
/// - Parameter data: 数据
-(void)writeDataByCbp:(NSData *)data{
// NSLog(@"%s:data:%@",__func__,data);
if (_mBlePeripheral && self.mRcspWrite) {
if (data.length > 0 ) {
NSInteger len = data.length;
while (len>0) {
if (len <= _bleMtu) {
NSData *mtuData = [data subdataWithRange:NSMakeRange(0, data.length)];
[_mBlePeripheral writeValue:mtuData
forCharacteristic:self.mRcspWrite
type:CBCharacteristicWriteWithoutResponse];
len -= data.length;
}else{
NSData *mtuData = [data subdataWithRange:NSMakeRange(0, _bleMtu)];
[_mBlePeripheral writeValue:mtuData
forCharacteristic:self.mRcspWrite
type:CBCharacteristicWriteWithoutResponse];
len -= _bleMtu;
data = [data subdataWithRange:NSMakeRange(_bleMtu, len)];
}
}
}
}else{
//需要先赋值写特征的内容
NSLog(@"need to init");
}
}
以下实现方法兼容于JL_BLEKit.framework的老版本:V1.7.0/1.6.3/1.6.4
区别于旧版SDK,新版JL_BLEKit.framework依赖于其他的SDK,所以在导入时应包含以下:
JL_OTALib.framework——OTA升级业务库
JL_AdvParse.framework——杰理蓝牙设备广播包解析业务库
JL_HashPair.framework——设备认证业务库
外部蓝牙管理,在使用JL_BLEKit.framework的同时,在蓝牙管理部分交由外边(开发者自定义蓝牙)统筹管理,可保障使用时的多样化。
参考Demo:「 JL_OTA项目的 BleByAssist文件夹」
支持的功能:
会用到的类:
BLE参数:
/*--- JLSDK ADD ---*/
_mAssist = [[JL_Assist alloc] init];
_mAssist.mNeedPaired = _isPaired; //是否需要握手配对
/*--- 自定义配对码(16个字节配对码) ---*/
//char pairkey[16] = {0x01,0x02,0x03,0x04,
// 0x01,0x02,0x03,0x04,
// 0x01,0x02,0x03,0x04,
// 0x01,0x02,0x03,0x04};
//NSData *pairData = [NSData dataWithBytes:pairkey length:16];
_mAssist.mPairKey = nil; //配对秘钥(或者自定义配对码pairData)
_mAssist.mService = FLT_BLE_SERVICE; //服务号
_mAssist.mRcsp_W = FLT_BLE_RCSP_W; //特征「写」
_mAssist.mRcsp_R = FLT_BLE_RCSP_R; //特征「读」
#pragma mark - 设备特征回调
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service
error:(nullable NSError *)error
{
if (error) { NSLog(@"Err: Discovered Characteristics fail."); return; }
/*--- JLSDK ADD ---*/
[self.mAssist assistDiscoverCharacteristicsForService:service Peripheral:peripheral];
}
#pragma mark - 更新通知特征的状态
- (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(nonnull CBCharacteristic *)characteristic
error:(nullable NSError *)error
{
if (error) { NSLog(@"Err: Update NotificationState For Characteristic fail."); return; }
/*--- JLSDK ADD ---*/
__weak typeof(self) weakSelf = self;
[self.mAssist assistUpdateCharacteristic:characteristic Peripheral:peripheral Result:^(BOOL isPaired) {
if (isPaired == YES) {
weakSelf.lastUUID = peripheral.identifier.UUIDString;
weakSelf.lastBleMacAddress = nil;
weakSelf.mBlePeripheral = peripheral;
/*--- UI配对成功 ---*/
[JL_Tools post:kFLT_BLE_PAIRED Object:peripheral];
} else {
[weakSelf.bleManager cancelPeripheralConnection:peripheral];
}
}];
}
#pragma mark - 设备返回的数据 GET
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic
error:(NSError *)error
{
if (error) { NSLog(@"Err: receive data fail."); return; }
/*--- JLSDK ADD ---*/
[self.mAssist assistUpdateValueForCharacteristic:characteristic];
}
#pragma mark - 设备断开连接
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral
error:(nullable NSError *)error
{
NSLog(@"BLE Disconnect ---> Device %@ error:%d", peripheral.name, (int)error.code);
self.mBlePeripheral = nil;
/*--- JLSDK ADD ---*/
[self.mAssist assistDisconnectPeripheral:peripheral];
/*--- UI刷新,设备断开 ---*/
[JL_Tools post:kFLT_BLE_DISCONNECTED Object:peripheral];
}
//外部蓝牙,手机蓝牙状态回调处,实现以下:
#pragma mark - 蓝牙初始化 Callback
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
_mBleManagerState = central.state;
/*--- JLSDK ADD ---*/
[self.mAssist assistUpdateState:central.state];
if (_mBleManagerState != CBManagerStatePoweredOn) {
self.mBlePeripheral = nil;
self.blePeripheralArr = [NSMutableArray array];
}
}
BLE连接且配对后必须执行一次
[self.mAssist.mCmdManager cmdTargetFeatureResult:^(NSArray * _Nullable array) {
JL_CMDStatus st = [array[0] intValue];
if (st == JL_CMDStatusSuccess) {
JLModel_Device *model = [weakSelf.mAssist.mCmdManager outputDeviceModel];
JL_OtaStatus upSt = model.otaStatus;
if (upSt == JL_OtaStatusForce) {
NSLog(@"---> 进入强制升级.");
if (weakSelf.selectedOtaFilePath) {
[weakSelf otaFuncWithFilePath:weakSelf.selectedOtaFilePath];
} else {
callback(true);
}
return;
} else {
if (model.otaHeadset == JL_OtaHeadsetYES) {
NSLog(@"---> 进入强制升级: OTA另一只耳机.");
if (weakSelf.selectedOtaFilePath) {
[weakSelf otaFuncWithFilePath:weakSelf.selectedOtaFilePath];
} else {
callback(true);
}
return;
}
}
NSLog(@"---> 设备正常使用...");
[JL_Tools mainTask:^{
/*--- 获取公共信息 ---*/
[weakSelf.mAssist.mCmdManager cmdGetSystemInfo:JL_FunctionCodeCOMMON Result:nil];
}];
} else {
NSLog(@"---> ERROR:设备信息获取错误!");
}
}];
//升级流程:连接设备-->获取设备信息-->是否强制升级-->(是)则必须调用该API去OTA升级;
// |_______>(否)则可以正常使用APP;
// 设置代理
@interface JLUpdateViewController () <JLBleManagerOtaDelegate>
- (void)viewDidLoad {
[super viewDidLoad];
// 设置ota升级过程状态回调代理
[JLBleManager sharedInstance].otaDelegate = self;
}
/**
* 选择文件后,点击启动OTA升级
*/
- (IBAction)updateBtnFunc:(id)sender {
if (![JLBleManager sharedInstance].mBlePeripheral) {
self.updateSeekLabel.text = @"";
[DFUITools showText:@"请先连接设备" onView:self.view delay:1.0];
return;
}
/*--- 获取设备信息 ---*/
[[JLBleManager sharedInstance] otaFuncWithFilePath:_selectFilePath];
}
#pragma mark - JLBleManagerOtaDelegate
/**
* ota升级过程状态回调
*/
- (void)otaProgressWithOtaResult:(JL_OTAResult)result withProgress:(float)progress {
if (result == JL_OTAResultUpgrading || result == JL_OTAResultPreparing) {
if (result == JL_OTAResultPreparing) self.updateLabel.text = @"校验文件中";
if (result == JL_OTAResultUpgrading) self.updateLabel.text = @"正在升级";
} else if (result == JL_OTAResultPrepared) {
NSLog(@"---> 检验文件【完成】");
} else if (result == JL_OTAResultReconnect) {
NSLog(@"---> OTA正在回连设备... %@", [JLBleManager sharedInstance].mBlePeripheral.name);
[[JLBleManager sharedInstance] connectPeripheralWithUUID:[JLBleManager sharedInstance].lastUUID];
[self otaTimeClose];//关闭超时检测
} else if (result == JL_OTAResultReconnectWithMacAddr) {
NSLog(@"---> OTA正在通过Mac Addr方式回连设备... %@", [JLBleManager sharedInstance].mBlePeripheral.name);
JLModel_Device *model = [[JLBleManager sharedInstance].mAssist.mCmdManager outputDeviceModel];
[JLBleManager sharedInstance].lastBleMacAddress = model.bleAddr;
[[JLBleManager sharedInstance] startScanBLE];
[self otaTimeClose];//关闭超时检测
} else if (result == JL_OTAResultSuccess) {
NSLog(@"--->升级成功.");
} else if (result == JL_OTAResultReboot) {
NSLog(@"--->设备重启.");
} else {
// 其余错误码详细 Command+点击JL_OTAResult 查看说明
NSLog(@"ota update result: %d", result);
}
}
以下实现方法基于JL_BLEKit.framework的内部集成蓝牙连接方法,开发者无需管理蓝牙对象,只专注升级业务即可。
参考Demo:「 JL_OTA项目的 SDKBleManager文件夹」
1. 支持的功能:
BLE设备的扫描、连接、断开、收发数据、回连功能;
BLE设备过滤;
BLE设备握手连接;
BLE连接服务和特征值设置;
获取设备信息;
OTA升级能实现;
2. 会用到的类:
JL_BLEUsage :可设置BLE过滤、握手、参数;
查看蓝牙状态;
JL_Entity:BLE设备的模型类,记录设备的相关信息(如名字、UUID、UID、PID等);
JL_BLEMultiple:BLE扫描、连接、断开、回连;
JL_ManagerM:获取设备信息、OTA操作;
self.mBleMultiple = [[JL_BLEMultiple alloc] init];
self.mBleMultiple.BLE_FILTER_ENABLE = YES; // 过滤非杰理蓝牙设备
// self.mBleMultiple.filterKey = nil; // 一般情况赋值nil即可
self.mBleMultiple.BLE_PAIR_ENABLE = YES;
/*--- 自定义配对码(16个字节配对码) ---*/
//char pairkey[16] = {0x01,0x02,0x03,0x04,
// 0x01,0x02,0x03,0x04,
// 0x01,0x02,0x03,0x04,
// 0x01,0x02,0x03,0x04};
//NSData *pairData = [NSData dataWithBytes:pairkey length:16];
// self.mBleMultiple.pairKey = nil; // 配对秘钥(或者自定义配对码pairData)
self.mBleMultiple.BLE_TIMEOUT = 7;
/*--- 搜索蓝牙设备 ---*/
[[JL_RunSDK sharedInstance].mBleMultiple scanStart];
// 监听通知【kJL_BLE_M_FOUND】【kJL_BLE_M_FOUND_SINGLE】回调设备数组
[JL_Tools add:kJL_BLE_M_FOUND Action:@selector(reloadTableView) Own:self];
[JL_Tools add:kJL_BLE_M_FOUND_SINGLE Action:@selector(reloadTableView) Own:self];
// 获取设备数组
- (void)reloadTableView {
self.btEnityList = [JL_RunSDK sharedInstance].mBleMultiple.blePeripheralArr;
if ([JL_RunSDK sharedInstance].mBleEntityM && ![self.btEnityList containsObject:[JL_RunSDK sharedInstance].mBleEntityM]) {
[self.btEnityList insertObject:[JL_RunSDK sharedInstance].mBleEntityM atIndex:0];
}
[self.subTableView reloadData];
}
//API通过【JL_BLEMultiple】使用
/**
连接设备
@param entity 蓝牙设备类
*/
-(void)connectEntity:(JL_EntityM*)entity Result:(JL_EntityM_STATUS_BK)result;
/**
断开连接
*/
-(void)disconnectEntity:(JL_EntityM*)entity Result:(JL_EntityM_STATUS_BK)result;
/**
* BLE状态通知
*/
extern NSString *kJL_BLE_M_FOUND; //发现设备
extern NSString *kJL_BLE_M_FOUND_SINGLE; //发现单个设备
extern NSString *kJL_BLE_M_ENTITY_CONNECTED; //连接有更新
extern NSString *kJL_BLE_M_ENTITY_DISCONNECTED; //断开连接
extern NSString *kJL_BLE_M_ON; //BLE开启
extern NSString *kJL_BLE_M_OFF; //BLE关闭
extern NSString *kJL_BLE_M_EDR_CHANGE; //经典蓝牙输出通道变化
[[JL_RunSDK sharedInstance] getDeviceInfo:^(BOOL needForcedUpgrade) {
if (needForcedUpgrade) {
NSLog(@"设备需要强制升级,请到升级界面选择ota升级文件进行升级!");
[self startLoadingView:@"设备需要强制升级,请到升级界面选择ota升级文件进行升级!" Delay:1.0];
}
}];
//升级流程:连接设备-->获取设备信息-->是否强制升级-->(是)则必须调用该API去OTA升级;
// |_______>(否)则可以正常使用APP;
// 设置代理
@interface JLUpdateViewController () <JL_RunSDKOtaDelegate>
// 设置ota升级过程状态回调代理
[JL_RunSDK sharedInstance].otaDelegate = self;
/**
* 选择文件后,点击启动OTA升级
*/
- (IBAction)updateBtnFunc:(id)sender {
if (![JL_RunSDK sharedInstance].mBleEntityM) {
self.updateSeekLabel.text = @"";
[DFUITools showText:@"请先连接设备" onView:self.view delay:1.0];
return;
}
/*--- 获取设备信息 ---*/
[[JL_RunSDK sharedInstance] otaFuncWithFilePath:_selectFilePath];
}
#pragma mark - JL_RunSDKOtaDelegate
/**
* ota升级过程状态回调
*/
- (void)otaProgressWithOtaResult:(JL_OTAResult)result withProgress:(float)progress {
if (result == JL_OTAResultUpgrading || result == JL_OTAResultPreparing) {
if (result == JL_OTAResultPreparing) self.updateLabel.text = @"校验文件中";
if (result == JL_OTAResultUpgrading) self.updateLabel.text = @"正在升级";
} else if (result == JL_OTAResultPrepared) {
NSLog(@"---> 检验文件【完成】");
} else if (result == JL_OTAResultReconnect) {
NSLog(@"---> OTA正在回连设备... %@", [JL_RunSDK sharedInstance].mBleEntityM.mPeripheral.name);
} else if (result == JL_OTAResultReconnectWithMacAddr) {
NSLog(@"---> OTA正在通过Mac Addr方式回连设备... %@", [JL_RunSDK sharedInstance].mBleEntityM.mPeripheral.name);
} else if (result == JL_OTAResultSuccess) {
NSLog(@"--->升级成功.");
} else if (result == JL_OTAResultReboot) {
NSLog(@"--->设备重启.");
} else {
// 其余错误码详细 Command+点击JL_OTAResult 查看说明
NSLog(@"ota update result: %d", result);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型