6 Star 18 Fork 4

珠海杰理科技 / iOS-JL_Bluetooth

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
Apache-2.0

iOS杰理之家SDK接入

声明

  1. 本项⽬所参考、使⽤技术必须全部来源于公知技术信息,或⾃主创新设计。

  2. 本项⽬不得使⽤任何未经授权的第三⽅知识产权的技术信息。

  3. 如个⼈使⽤未经授权的第三⽅知识产权的技术信息,造成的经济损失和法律后果由个⼈承担。

版本

版本 日期 编辑 修改内容
v1.4 2020年12月17日 冯 洪鹏 1、手表表盘操作(表盘OTA);
v1.3 2020年12月11日 冯 洪鹏 1、重新整理代码框架;
2、增加多设备管理;
v1.2 2020年12月09日 冯 洪鹏 更新文档
v1.1 2020年04月20日 冯 洪鹏 增加升级的错误回调
v1.0 2019年09月09日 冯 洪鹏 OTA升级功能

概述

本文档是为了后续开发者更加便捷移植杰理蓝牙控制功能而创建。

1、导入JL_BLEKit.framework

1、将「 JL_BLEKit.framework 」导入Xcode工程,添加两个权限:

  • Privacy - Bluetooth Peripheral Usage Description
  • Privacy - Bluetooth Always Usage Description

2、SDK具体使用的两种方式:

​ 第一种,使用自定义的蓝牙连接API进行OTA:所有BLE的操作都自行实现,SDK只负责对OTA数据包解析

从而实现OTA功能。

​ 第二种,使用SDK内的蓝牙连接API进行OTA:完全使用SDK。 ​
​ 3、针对【杰理之家APP】的开发文档,请看《杰理蓝牙控制库_IOS_SDK开发说明》描述杰理之家内部所有功 ​ ​ 能的实现。 ​

4、本工程可Build出的ipa需要iPhone手机系统版本在iOS10.0以上。

2、使用自定义的蓝牙API接入SDK

参考Demo:「OTA_Update_M(外部BLE)

1、支持的功能

  • BLE设备握手连接;
  • 获取设备信息;
  • OTA升级能实现;
  • 注意:所有BLE扫描、连接、断开、重连等操作都需自行实现。

2、接触到的类

  • JL_BLEAction:实现BLE设备握手连接;(可选,需设备支持)
  • JL_Handle:RCSP数据格式分包器;(必须)
  • JL_ManagerM:命令处理中心,所有的命令操作都集中于此;(必须)
  • JLModel_Device:设备信息存储的数据模型;(必须)

3、BLE参数

  • 【服务号】:AE00
  • 【写】特征值:AE01
  • 【读 】特征值:AE02

2.1、初始化SDK

//主要是3个类,分别是配对器、数据分包器、命令中心类
/*--- 配对器 ---*/
bleAction = [[JL_BLEAction alloc] init];
bleAction.delegate = self;
        
/*--- 数据结构分包 ---*/
bleHandle = [[JL_Handle alloc] init];
bleHandle.delegate = self;
        
/*--- 命令处理中心 ---*/
self.mCmdManager = [[JL_ManagerM alloc] init];
self.mCmdManager.delegate = self;

2.2、BLE握手连接(可选)

/**
 蓝牙设备配对
 @param pKey 配对码(默认传nil)
 @param bk   配对回调YES:成功 NO:失败
 */
-(void)bluetoothPairingKey:(NSData*)pKey Result:(ATC_Block)bk
  
//外部蓝牙更新通知特征的状态的回调处实现,以下:
#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.isNotifying) {
        if ([characteristic.UUID.UUIDString containsString:@"AE02"])
        {
            QCY_BLE_LEN_45 = [peripheral maximumWriteValueLengthForType:CBCharacteristicWriteWithoutResponse];
            NSLog(@"BLE ---> MTU:%lu",(unsigned long)QCY_BLE_LEN_45);
                    
            NSData *pairKey = nil;//使用内置默认
            [bleAction bluetoothPairingKey:pairKey Result:^(BOOL ret) {
                if (ret) {
                    self.mBlePeripheral = peripheral;
                    self.lastUUID = peripheral.identifier.UUIDString;
                    self.mBleName = peripheral.name;
                    
                    [JL_Tools setUser:self.lastUUID forKey:kUUID_BLE_LAST];
                    
                    /*--- 存储名字和UUID ---*/
                    [self.mCmdManager setBleUuid:self.lastUUID];
                    [self.mCmdManager setBleName:self.mBleName];
                    
                    /*--- 告之SDK,设备连接成功 ---*/
                    [JL_Tools post:kJL_BLE_M_ENTITY_CONNECTED Object:peripheral];
                    
                }else{
                    NSLog(@"Err: bluetooth pairing fail.");
                    [self->bleManager cancelPeripheralConnection:peripheral];
                }
            }];
            
            /*            //不需要握手可以这样处理。
                    self.lastUUID = peripheral.identifier.UUIDString;
                    self.mBleName = peripheral.name;
                    
                    [JL_Tools setUser:self.lastUUID forKey:kUUID_BLE_LAST];
                    
                    //存储名字和UUID
                    [self.mCmdManager setBleUuid:self.lastUUID];
                    [self.mCmdManager setBleName:self.mBleName];
                    
                    //告之SDK,设备连接成功
                    [JL_Tools post:kJL_BLE_M_ENTITY_CONNECTED Object:peripheral];
            */
        }
    }
}

2.3、BLE设备返回的数据传入SDK

//外部蓝牙数据接收处,实现以下:
#pragma mark - 设备返回的数据 GET
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic
             error:(NSError *)error
{
    if (error) { NSLog(@"Err: receive data fail."); return; }
    
    NSData *data = characteristic.value;
    if (data.length <= 0) { return; }
    
    /*--- 【命令】通道返回的数据 ---*/
    if ([characteristic.UUID.UUIDString containsString:QCY_BLE_RCSP_R])
    {
        /*--- 配对输入 ---*/
        [bleAction inputPairData:data];
        
        /*--- RCSP数据结构分包 ---*/
        [bleHandle inputHandleData:data];
    }
}

2.4、实现SDK的Delete方法

#pragma mark -【JL_BLEActionDelegate】配对数据输出
-(void)onPairOutputData:(NSData *)data{
    [self writeRcspData:data];//使用外部蓝牙发数API
}

#pragma mark -【JL_HandleDelegate】RCSP数据包
-(void)onHandleOutputPKG:(JL_PKG *)pkg{
    [self.mCmdManager inputPKG:pkg];
}

#pragma mark -【JL_ManagerMDelegate】RCSP数据包
-(void)onManagerSendPackage:(JL_PKG *)pkg{
    NSData *data = [bleHandle sendPackage:pkg WithName:self.mBleName];
    [self writeRcspData:data];//使用外部蓝牙发数API
}

2.5、设备断开的处理

//外部蓝牙设备断开连接处,实现以下:
#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.mCmdManager cmdFlashActionDisconnect];
    
    /*--- 告之SDK,设备已断开 ---*/
    [JL_Tools post:kJL_BLE_M_ENTITY_DISCONNECTED Object:peripheral];
}

2.6、手机蓝牙状态传入SDK

//外部蓝牙,手机蓝牙状态回调处,实现以下:
#pragma mark - 蓝牙初始化 Callback
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
    NSInteger st = central.state;
    if (st != CBManagerStatePoweredOn) {
        /*--- 表盘清除回调 ---*/
        [self.mCmdManager cmdFlashActionDisconnect];
        
        /*--- 告之SDK,手机已关闭蓝牙 ---*/
        [JL_Tools post:kJL_BLE_M_OFF Object:@(0)];
    }
}

2.7、功能实现

2.7.1、获取设备信息

    [bt_ble.mCmdManager cmdTargetFeatureResult:^(NSArray * _Nullable array) {
        JL_CMDStatus st = [array[0] intValue];
        if (st == JL_CMDStatusSuccess) {
            JLModel_Device *model = [self->bt_ble.mCmdManager outputDeviceModel];
            JL_OtaStatus upSt = model.otaStatus;
            if (upSt == JL_OtaStatusForce) {
                NSLog(@"---> 进入强制升级.");
                [self noteOtaUpdate:nil];
                return;
            }else{
                if (model.otaHeadset == JL_OtaHeadsetYES) {
                    NSLog(@"---> 进入强制升级: OTA另一只耳机.");
                    [self noteOtaUpdate:nil];
                    return;
                }
            }
            NSLog(@"---> 设备正常使用...");
        }else{
            NSLog(@"---> ERROR:设备信息获取错误!");
        }
    }];

2.7.2、固件OTA升级

   //升级流程:连接设备-->获取设备信息-->是否强制升级-->(是)则必须调用该API去OTA升级;
     //                                                                        |_______>(否)则可以正常使用APP;
                                                                            
        NSData *otaData = [[NSData alloc] initWithContentsOfFile:@"OTA升级文件路径"];
    [bt_ble.mCmdManager cmdOTAData:otaData Result:^(JL_OTAResult result, float progress) {
        if (result == JL_OTAResultSuccess) {
            NSLog(@"--->升级成功.");
        }
        if (result == JL_OTAResultFail) {
            NSLog(@"--->OTA升级失败");
        }
        if (result == JL_OTAResultDataIsNull) {
            NSLog(@"--->OTA升级数据为空!");
        }
        if (result == JL_OTAResultCommandFail) {
            NSLog(@"--->OTA指令失败!");
        }
        if (result == JL_OTAResultSeekFail) {
            NSLog(@"--->OTA标示偏移查找失败!");
        }
        if (result == JL_OTAResultInfoFail) {
            NSLog(@"--->OTA升级固件信息错误!");
        }
        if (result == JL_OTAResultLowPower) {
            NSLog(@"--->OTA升级设备电压低!");
        }
        if (result == JL_OTAResultEnterFail) {
            NSLog(@"--->未能进入OTA升级模式!");
        }
        if (result == JL_OTAResultUnknown) {
            NSLog(@"--->OTA未知错误!");
        }
        if (result == JL_OTAResultFailSameVersion) {
            NSLog(@"--->相同版本!");
        }
        if (result == JL_OTAResultFailTWSDisconnect) {
            NSLog(@"--->TWS耳机未连接");
        }
        if (result == JL_OTAResultFailNotInBin) {
            NSLog(@"--->耳机未在充电仓");
        }
        
        if (result == JL_OTAResultPreparing ||
            result == JL_OTAResultUpgrading)
        {
            if (result == JL_OTAResultUpgrading) NSLog(@"---> 正在升级:%.1f",progress*100.0f);
            if (result == JL_OTAResultPreparing) NSLog(@"---> 检验文件:%.1f",progress*100.0f);
        }
        
        if (result == JL_OTAResultPrepared) {
            NSLog(@"---> 检验文件【完成】");
        }
        if (result == JL_OTAResultReconnect) {
            NSLog(@"---> OTA正在回连设备... %@",self->bt_ble.mBleName);
            [self->bt_ble connectPeripheralWithUUID:self->bt_ble.lastUUID];//自行实现回连
        }
    }];

2.7.3、⼿表切换表盘(OTA功能)

  • 详情看【FAT_Demo】
  • 导⼊【FATApi】【FATTool】⽂件内代码;
STEP.1、设置命令中⼼类
        JL_RunSDK *bleSDK = [JL_RunSDK sharedMe];
        bt_ble = bleSDK.bt_ble;
        
        /*--- 设置命令处理中心 ---*/
        [FatsObject makeCmdManager:bt_ble.mCmdManager];
STEP.2、获取外挂Flash的信息
//调⽤该API需要⽤异步,[JL_Tools subTask:^{}]为异步代码块
 [JL_Tools subTask:^{
        JL_ManagerM *mCmdManager = self->bleSDK.mBleEntityM.mCmdManager;
         [mCmdManager cmdGetFlashInfoResult:^(JLModel_Flash * _Nullable model) {
                 [JL_Tools mainTask:^{
                        //mFlashSize;     //flash大小
                        //mFatfsSize;     //FAT系统大小
                        //mFlashType;     //系统类型 0:FAT
                        //mFlashStatus;   //系统当前状态,0x00正常,0x01异常
                        //mFlashVersion;  //Flash版本
                        //mFlashMtu;      //发包窗口大小
                        //mFlashCluster;  //扇区大小
                         [DFUITools showText:@"FATFS信息已更新" onView:self delay:1.0];
                 }];
         }];
 }];
STEP.3、初始化本地FATFS系统
//调⽤该API需要⽤异步
 [JL_Tools subTask:^{
        JLModel_Device *model = [self->bleSDK.mBleEntityM.mCmdManager outputDeviceModel];
        uint32_t flashSize = model.flashInfo.mFlashSize;//外挂Flash剩余空间
        uint32_t fatsSize = model.flashInfo.mFatfsSize; //统⼤⼩
        BOOL isOk = [FatsObject makeFlashSize:flashSize FatsSize:fatsSize];
         [JL_Tools mainTask:^{
                NSString *txt = @"FATFS Mount OK !";
                if (isOk == NO) txt = @"FATFS Mount Fail~";
                 [DFUITools showText:txt onView:self delay:1.0];
         }];
 }];
读取表盘(⽂件)名字
//调⽤该API需要⽤异步
 [JL_Tools subTask:^{
            self->dataArray = [FatsObject makeListPath:@"/"];
            NSLog(@"Fats List ---> %@",self->dataArray);
             [JL_Tools mainTask:^{
                     [self->subTableView reloadData];
             }];
 }];
新增表盘(⽂件)
    NSString *pathMatch = [DFFile find:@"watch6.zip"];
    NSData *data = [NSData dataWithContentsOfFile:pathMatch];
    NSLog(@"-->创建的文件大小:%lld",(long long)data.length);
    
    NSString *path = @"/watch6";
    
    [JL_Tools subTask:^{
#if IS_FROM_BLE
        /*--- 开始写文件 ---*/
        __block uint8_t mFlag_0 = 0;
        NSLog(@"--->Fats Insert stat.");
        [mCmdManager cmdInsertFlashPath:path Size:(uint32_t)data.length
                                   Flag:0x01 Result:^(uint8_t flag) {
            mFlag_0 = flag;
        }];
        if (mFlag_0 != 0) {
            NSLog(@"--->Fats Insert Fail.");
            [JL_Tools mainTask:^{
                [self setLoadingText:@"创建文件失败!" Delay:0.5];
            }];
            return;
        }
#endif
        
        BOOL isOk = [FatsObject makeCreateFile:path Content:data Result:^(float progress) {
            [JL_Tools mainTask:^{
                //NSLog(@"---> Progress: %.1f",progress*100.0f);
                NSString *txt = [NSString stringWithFormat:@"正在升级:%.1f%%",progress*100.0f];
                self->progressLabel.text = txt;
                self->progressView.progress = progress;
            }];
        }];
        NSLog(@"Fats Add ---> %d",isOk);
        
        [JL_Tools mainTask:^{
            if (isOk) {
                [self setLoadingText:@"创建文件成功!" Delay:0.5];
#if IS_FROM_BLE
                [JL_Tools subTask:^{
                    /*--- 结束写文件 ---*/
                    NSLog(@"--->Fats Insert end.");
                    [mCmdManager cmdInsertFlashPath:nil Size:0 Flag:0x00 Result:nil];
                }];
#endif
                [JL_Tools delay:1.0 Task:^{
                    self->progressView.hidden = YES;
                    self->progressLabel.hidden = YES;
                    self->progressView.progress = 0.0f;
                    /*--- 读取列表 ---*/
                    [wSelf btn_List:nil];
                }];
            }else{
                [self setLoadingText:@"创建文件失败!" Delay:0.5];
            }
        }];
    }];
删除表盘(⽂件)
    [self startLoadingView:@"删除文件..." Delay:20.0];
    NSString *path = [NSString stringWithFormat:@"/%@",selectText];
    JL_ManagerM *mCmdManager = bt_ble.mCmdManager;
    
    [JL_Tools subTask:^{
#if IS_FROM_BLE
        /*--- 开始删除文件 ---*/
        __block uint8_t m_flag = 0;
        NSLog(@"--->Fats Delete stat.");
        [mCmdManager cmdDeleteFlashPath:path Flag:0x01 Result:^(uint8_t flag) {
            m_flag = flag;
        }];
        if (m_flag != 0) {
            NSLog(@"--->Fats Delete Fail.");
            [JL_Tools mainTask:^{
                [self setLoadingText:@"删除文件失败!" Delay:0.5];
            }];
            return;
        }
#endif
        
        BOOL isOk = [FatsObject makeRemoveFile:path];
        NSLog(@"Fats Remove ---> %d",isOk);
        
        [JL_Tools mainTask:^{
            if (isOk) {
                [self setLoadingText:@"删除文件成功!" Delay:0.5];
#if IS_FROM_BLE
                [JL_Tools subTask:^{
                    /*--- 结束删除文件 ---*/
                    NSLog(@"--->Fats Delete end.");
                    [mCmdManager cmdDeleteFlashPath:nil Flag:0x00 Result:nil];
                }];
#endif
                /*--- 读取列表 ---*/
                [wSelf btn_List:nil];
            }else{
                [self setLoadingText:@"删除文件失败!" Delay:0.5];
            }

        }];
    }];
⽤户设置当前表盘
    NSString *path = [NSString stringWithFormat:@"/%@",selectText];
    
    JL_ManagerM *mCmdManager = bt_ble.mCmdManager;
    [mCmdManager cmdWatchFlashPath:path Flag:0x01
                            Result:^(uint8_t flag, uint32_t size,
                                     NSString * _Nullable path,
                                     NSString * _Nullable describe) {
        [JL_Tools mainTask:^{
            NSString *txt = @"设置表盘成功!";
            if (flag != 0) txt = @"设置表盘失败~";
            [DFUITools showText:txt onView:self delay:1.0];
        }];
    }];
设备主动切换的表盘
        //监听通知
        [JL_Tools add:kJL_MANAGER_WATCH_FACE Action:@selector(noteWatchFace:) Own:self];

    JL_ManagerM *mCmdManager = bt_ble.mCmdManager;
    [mCmdManager cmdWatchFlashPath:nil Flag:0x00
                            Result:^(uint8_t flag, uint32_t size,
                                     NSString * _Nullable path,
                                     NSString * _Nullable describe) {
        [JL_Tools mainTask:^{
            NSString *txt = @"获取表盘成功!";
            if (flag != 0) txt = @"获取表盘失败~";
            [DFUITools showText:txt onView:self delay:1.0];
            
            self->deviceText = [path stringByReplacingOccurrencesOfString:@"/" withString:@""];
            [self->subTableView reloadData];
        }];
    }];
获取FAT系统剩余空间
//调⽤该API需要⽤异步
        [JL_Tools subTask:^{
        JLModel_Device *model = [self->bt_ble.mCmdManager outputDeviceModel];
        uint32_t flashSize = model.flashInfo.mFlashSize;
        uint32_t fatsSize = model.flashInfo.mFatfsSize;
        
        uint32_t fatsFree = [FatsObject makeGetFree];
        NSLog(@"--->FatsFree ==> %u",fatsFree);

        self->realFreeSize = flashSize - (fatsSize - (fatsFree * 4096));
        NSLog(@"--->剩余空间 ==> %u",self->realFreeSize);
    }];

3、使用内部的蓝牙API接入SDK

参考Demo:「OTA_Update_M(内部BLE)

1、支持的功能

  • BLE设备的扫描、连接、断开、收发数据;

  • BLE设备过滤;

  • BLE设备握手连接;

  • BLE连接服务号和特征值设置;

  • 获取设备信息;

  • OTA升级能实现;

2、接触到的类

  • JL_BLEMultiple

    1、BLE设备过滤,可选关闭;(可选)

    2、BLE配对码设置,可选关闭;(可选,需固件支持功能)

    3、连接超时设置;

    4、BLE连接服务号和特征值设置;

    5、缓存已连接和发现的BLE设备;

  • JL_EntityM:BLE设备的模型类;(必须)

  • JL_ManagerM:命令处理中心,所有的命令操作都集中于此;(必须)

  • JLModel_Device:设备信息存储的数据模型;(必须)

3、BLE参数

  • 【服务号】:AE00
  • 【写】特征值:AE01
  • 【读 】特征值:AE02

3.1、初始化SDK

//1、外部的引用
@property(strong,nonatomic) JL_BLEMultiple  *mBleMultiple;
@property(weak  ,nonatomic) JL_EntityM      *mBleEntityM;    //需要Weak引用,断开设备重新搜索,SDK需释放。(作为当前正在操作的设备使用)
@property(strong,nonatomic) NSString        *mBleUUID;
@property(weak  ,nonatomic) NSArray         *mFoundArray; //需要Weak引用,扫描到的设备。
@property(weak  ,nonatomic) NSArray         *mConnectedArray;//需要Weak引用,已连接的设备。

//2、实例化SDK
self.mBleMultiple = [[JL_BLEMultiple alloc] init];
self.mBleMultiple.BLE_FILTER_ENABLE = YES;
self.mBleMultiple.BLE_PAIR_ENABLE = YES;
self.mBleMultiple.BLE_TIMEOUT = 7;

//1、SDK搜索到的设备,点击连接后,会加入bleConnectedArr数组中。
//2、调用[self.mBleMultiple scanStart]会释放掉blePeripheralArr的JL_EntityM。
self.mFoundArray = self.mBleMultiple.blePeripheralArr;
    
//SDk已连接上的设备,断开连接后,会加入blePeripheralArr数组中。
self.mConnectedArray = self.mBleMultiple.bleConnectedArr;

//后续会用mBleEntityM内的【JL_ManagerM】发命令。

3.2、监听发现、连接、断开、蓝牙状态等通知回调

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;          //经典蓝牙输出通道变化

3.3、连接设备

//从已发现的设备列表里连接一个。
JL_EntityM *entity = self.mFoundArray[indexPath.row];

[self.mBleMultiple connectEntity:entity
                          Result:^(JL_EntityM_Status status) {
    [JL_Tools mainTask:^{
        /*【status】错误码与错误原因
    JL_EntityM_StatusBleOFF         = 0,    //BLE蓝牙未开启
    JL_EntityM_StatusConnectFail    = 1,    //BLE连接失败
    JL_EntityM_StatusConnecting     = 2,    //BLE正在连接
    JL_EntityM_StatusConnectRepeat  = 3,    //BLE重复连接
    JL_EntityM_StatusConnectTimeout = 4,    //BLE连接超时
    JL_EntityM_StatusConnectRefuse  = 5,    //BLE被拒绝
    JL_EntityM_StatusPairFail       = 6,    //配对失败
    JL_EntityM_StatusPairTimeout    = 7,    //配对超时
    JL_EntityM_StatusPaired         = 8,    //已配对
    JL_EntityM_StatusMasterChanging = 9,    //正在主从切换
    JL_EntityM_StatusDisconnectOk   = 10,   //已断开成功
    JL_EntityM_StatusNull           = 11,   //Entity为空 */
    
        if (status == JL_EntityM_StatusPaired) {
        NSString *txt = [NSString stringWithFormat:@"连接成功:%@",deviceName];
        [DFUITools showText:txt onView:wSelf.view delay:1.0];
    }else{
        NSString *txt = [NSString stringWithFormat:@"连接失败:%@",deviceName];
      [DFUITools showText:txt onView:wSelf.view delay:1.0];
    }
    }];
}];

3.4、断开设备

[self.mBleMultiple disconnectEntity:entity Result:^(JL_EntityM_Status status) {
        [JL_Tools mainTask:^{
        if (status == JL_EntityM_StatusDisconnectOk) {
          NSString *txt = [NSString stringWithFormat:@"已断开:%@",deviceName];
          [DFUITools showText:txt onView:wSelf.view delay:1.0];
        }
        }];
}];

3.5、功能实现

3.5.1、获取设备信息

[self.mBleEntityM.mCmdManager cmdTargetFeatureResult:^(NSArray * _Nullable array) {
    JL_CMDStatus st = [array[0] intValue];
        if (st == JL_CMDStatusSuccess) {
            JLModel_Device *model = [self.mBleEntityM.mCmdManager outputDeviceModel];
            JL_OtaStatus upSt = model.otaStatus;
            if (upSt == JL_OtaStatusForce) {
                NSLog(@"---> 进入强制升级.");
                [self noteOtaUpdate:nil];
                return;
            }else{
                if (model.otaHeadset == JL_OtaHeadsetYES) {
                    NSLog(@"---> 进入强制升级: OTA另一只耳机.");
                    [self noteOtaUpdate:nil];
                    return;
                }
            }
            NSLog(@"---> 设备正常使用...");
        }else{
        NSLog(@"---> ERROR:设备信息获取错误!");
    }
}];

3.5.2、OTA升级

   //升级流程:连接设备-->获取设备信息-->是否强制升级-->(是)则必须调用该API去OTA升级;
     //                                                                        |_______>(否)则可以正常使用APP;

        NSString *filePath = [[NSBundle mainBundle]pathForResource:@"update_watch" ofType:@"ufw"];
    NSData *otaData = [[NSData alloc] initWithContentsOfFile:filePath];
    
    [self.mBleEntityM.mCmdManager cmdOTAData:otaData Result:^(JL_OTAResult result, float progress) {
        if (result == JL_OTAResultSuccess) {
            NSLog(@"--->升级成功.");
        }
        if (result == JL_OTAResultFail) {
            NSLog(@"--->OTA升级失败");
        }
        if (result == JL_OTAResultDataIsNull) {
            NSLog(@"--->OTA升级数据为空!");
        }
        if (result == JL_OTAResultCommandFail) {
            NSLog(@"--->OTA指令失败!");
        }
        if (result == JL_OTAResultSeekFail) {
            NSLog(@"--->OTA标示偏移查找失败!");
        }
        if (result == JL_OTAResultInfoFail) {
            NSLog(@"--->OTA升级固件信息错误!");
        }
        if (result == JL_OTAResultLowPower) {
            NSLog(@"--->OTA升级设备电压低!");
        }
        if (result == JL_OTAResultEnterFail) {
            NSLog(@"--->未能进入OTA升级模式!");
        }
        if (result == JL_OTAResultUnknown) {
            NSLog(@"--->OTA未知错误!");
        }
        if (result == JL_OTAResultFailSameVersion) {
            NSLog(@"--->相同版本!");
        }
        if (result == JL_OTAResultFailTWSDisconnect) {
            NSLog(@"--->TWS耳机未连接");
        }
        if (result == JL_OTAResultFailNotInBin) {
            NSLog(@"--->耳机未在充电仓");
        }
        
        if (result == JL_OTAResultPreparing ||
            result == JL_OTAResultUpgrading)
        {
            if (result == JL_OTAResultUpgrading) NSLog(@"---> 正在升级:%.1f",progress*100.0f);
            if (result == JL_OTAResultPreparing) NSLog(@"---> 检验文件:%.1f",progress*100.0f);
        }
        
        if (result == JL_OTAResultPrepared) {
            NSLog(@"---> 检验文件【完成】");
        }
        if (result == JL_OTAResultReconnect) {
            NSLog(@"---> OTA正在回连设备... %@",self.mBleEntityM.mItem);
            [self.mBleMultiple connectEntity:self.mBleEntityM Result:^(JL_EntityM_Status status) {
                if (status != JL_EntityM_StatusPaired) {
                    NSLog(@"---> Error:OTA回连设备失败!");
                }
            }];
        }
    }];

4、其他功能实现,请看《杰理蓝牙控制库_IOS_SDK开发说明》

        //全都用JL_ManagerM内的方法,详情看头文件JL_ManagerM.h
        //
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

iOS杰理蓝牙SDK接入基础 expand collapse
Apache-2.0
Cancel

Releases

No release

Contributors

All

Activities

Load More
can not load any more
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/Jieli-Tech/iOS-JL_Bluetooth.git
git@gitee.com:Jieli-Tech/iOS-JL_Bluetooth.git
Jieli-Tech
iOS-JL_Bluetooth
iOS-JL_Bluetooth
main

Search

344bd9b3 5694891 D2dac590 5694891