FeasyBlue SDK iOS接入文档

English

一、FeasyBlue SDK 接入方式

1、解压SDK,把解压的全部文件拖到工程里。

2、设置链接器标志,TARGETS -> Build Settings -> Linking -> Other Linker Flags,添加-ObjC

Other linker flags

二、搜索(FEBluetoothSDK)

1、介绍:

搜索 BLE 设备

2、方法

/// 搜索普通通讯设备
/// @param scanBlock 回调(peripheral:搜索到的设备)
- (void)scan:(void(^)(FEPeripheral* peripheral, BOOL isNew))scanBlock;

3、搜索例子

[[FEBluetoothSDK sharedFEBluetoothSDK] scan:^(FEPeripheral *peripheral, BOOL isNew) {
            if (isNew){
                // peripheral 是新设备
            }else{
                // peripheral 非新设备,建议刷新该设备信息
            }
        }];

4、停止搜索

[[FEBluetoothSDK sharedFEBluetoothSDK] stopScan];

5、搜索过滤设备

(如需过滤,搜索前先设置过滤条件。设置过滤条件后 scanPeripherals 会改变,请及时刷新列表)

(1)过滤信号范围设备

参数

描述

isFilterRSSI

是否按信号值过滤

minRSSI

过滤最小信号值,达不到此信号不回调, 设置范围是 -100 ~ 0,默认-100

maxRSSI

过滤最大信号值,超过此信号不回调, 设置范围是 -100 ~ 0,默认0

过滤例子

// 开启过滤
[FEBluetoothSDK sharedFEBluetoothSDK].filter.isFilterRSSI = YES;
// 过滤小于-60的设备
[FEBluetoothSDK sharedFEBluetoothSDK].filter.minRSSI = -60;
// 过滤大于0的设备
[FEBluetoothSDK sharedFEBluetoothSDK].filter.maxRSSI = 0;

(2)过滤设备名

参数

描述

isFilterName

是否按设备名过滤

filtrationName

过滤设备名(包含此名称的才回调)

过滤例子

// 开启过滤
[FEBluetoothSDK sharedFEBluetoothSDK].filter.isFilterName = YES;
// 过滤不包含Feasycom的设备,不区分大小写
[FEBluetoothSDK sharedFEBluetoothSDK].filter.filtrationName = @"Feasycom";

三、连接(FEBluetoothSDK)

1、介绍:

连接设备

2、方法

/// 连接设备进入普通通讯模式
/// @param peripheral 设备
/// @param isConnectedBlock 是否连接成功回调,断开连接也从这里回调
- (void)connect:(FEPeripheral *)peripheral connectState:(void(^)(FEPeripheral *peripheral, CONNECTSTATE connectState))connectStateBlock;

值得注意的是, 1、为了保证通讯的有效和高速传输,我司自研FACP通讯协议,建议开启此协议,目前FACP有两个版本:FSCFacpType_2_0和FSCFacpType_2_1,其中FSCFacpType_2_1支持数据重传; 2、模块实现数据重传需要能支持FSCFacpType_2_1功能的模块固件,若固件不支持,即使APP选择启用FSCFacpType_2_1,实际为FSCFacpType_2_0; 3、为了成功启用FACP通讯协议,必须在连接设备前配置该属性(FEPeripheral类的facpType属性),如下:

peripheral.facpTpye = FSCFacpType_2_1;

3、连接例子

[[FEBluetoothSDK sharedFEBluetoothSDK] connect:peripheral isConnected:^(FEPeripheral *peripheral, CONNECTSTATE connectState) {
                    // 根据 connectState 判断连接结果
                }];

4、断开连接

[[FEBluetoothSDK sharedFEBluetoothSDK] disconnect:peripheral complete:^(FEPeripheral * _Nonnull peripheral) {
        // 断开完成
    }];

四、回调,含接收数据(FEPeripheral)

1、介绍:

集合多个回调

2、方法

/// 回调
/// @param connectStatusBlock 连接状
/// @param deviceInfoBlock 读取模块信息
/// @param rssiBlock 信号值
/// @param sendBlock 发送回调(error:发送错误信息,发送成功为nil。pause:表示是否暂停。finish:表示是否发送完毕)
/// @param receiveBlock 接收数据
- (void)callBackConnectStatus:(void(^ _Nullable)(FEPeripheral *peripheral, CBPeripheralState state))connectStatusBlock
      deviceInfo:(void(^ _Nullable)(FEPeripheral *peripheral, FEDeviceInfo * _Nullable deviceInfo))deviceInfoBlock
            RSSI:(void(^ _Nullable)(FEPeripheral *peripheral, NSNumber* _Nullable RSSI, NSError* _Nullable error))rssiBlock
            send:(void(^ _Nullable)(FEPeripheral *peripheral, NSError* _Nullable error, BOOL pause, BOOL finish))sendBlock
         receive:(void(^ _Nullable)(FEPeripheral *peripheral, CBCharacteristic* characteristic, NSError* _Nullable error))receiveBlock;

3、回调例子

注意:当前接收的数据是characteristic.value。peripheral.reData是拼接的数据,达到一定量后自动清除前面的数据。

[self.peripheral callBackConnectStatus:^(FEPeripheral * _Nonnull peripheral, CBPeripheralState state) {
        // 连接状态回调
    } deviceInfo:^(FEPeripheral * _Nonnull peripheral, FEDeviceInfo * _Nullable deviceInfo) {
        // 设备信息回调(需模块支持)
    } RSSI:^(FEPeripheral * _Nonnull peripheral, NSNumber * _Nullable RSSI, NSError * _Nullable error) {
        // 信号值回调
    } send:^(FEPeripheral * _Nonnull peripheral, NSError * _Nullable error, BOOL pause, BOOL finish) {
        // 发送完成回调,pauss为YES表示暂停,finish为YES表示全部数据发送完成
    } receive:^(FEPeripheral * _Nonnull peripheral, CBCharacteristic * _Nonnull characteristic, NSError * _Nullable error) {
        // 接收数据(当前接收的数据是characteristic.value)
    }];

五、发送数据(FEPeripheral)

1、介绍:

不用考虑分包,直接传全部数据,内部自动按最合适的方式分包,以达到最高传输速度。

2、方法

/// 发送数据
/// @param data 发送的数据
/// @param isResponse 是否带反馈
- (void)send:(NSData * _Nullable)data withResponse:(BOOL)isResponse;

3、发送例子

[self.peripheral send:data withResponse:NO];

4、停止发送

[self.peripheral stopSend];

六、数据校验(FEPeripheral)

1、介绍:

含数量、CRC32、发送时间。

2、属性介绍

属性

描述

receiveCount

接收数量

sendCount

发送数量

sendTimeInterval

发送时间

crc32_re

接收数据的CRC32

crc32_se

发送数据的CRC32

other

辅助变量(用户随意自定义使用)

七、其他

开关SDK日志:isShowLog。(FEBluetoothSDK)

// 打开日志
[FEBluetoothSDK sharedFEBluetoothSDK].isShowLog  = YES;

八、FeasyBlue 升级相关接口

连接成功后,按需要使用以下升级接口

8.1 升级进度回调

/**
 * update progress callbacks 升级进度回调
 * status 0:正常,1:取消,2:超时
 */
- (void)otaProgressUpdate:(void (^)(CGFloat percentage,int status))block;

8.2 升级型号不匹配回调

/**
 * 升级型号不匹配回调
 */
- (void)upgradeModuleNotMatched:(void (^)(void))bloack;

8.3 检查固件信息

/**
 * load file and check file information 检查固件信息
 * dfuFileName 是固件的文件路径
 */
- (NSDictionary *)checkDfuFile:(NSString *)dfuFileName;

8.4 开始空中升级

/**
 * upgrade and restore default settings 开始空中升级
 * dfuFileName 是固件的文件路径
 */
- (void)startOTA:(NSString *)dfuFileName withRestoreDefaultSettings:(BOOL)restore;

附录