# AILinkBleSDK使用说明 [English](README.md) ## 更新说明 |版本号 |更新时间 |作者 |更新信息| |------ | ------- | ---- | ----- | |v1.0.2_20200407|2020-04-09| JosonXiong |初始化| | v1.0.3_20200421 | 2020-04-21 | JosonXiong | 1.修改多次开关蓝牙和连接断开后state状态无法同步的问题;2增加父类“ELBluetoothManager”数据透传方法,请在子类中调用 | ## 使用条件 1.iOS 9.0及以上版本; 2.蓝牙4.0及以上版本。 ## 使用前准备 1.申请SDK的key和secret,申请地址:http://sdk.aicare.net.cn; 2.在info.plist文件中加入“Privacy - Bluetooth Always Usage Description”; 3.下载AILinkBleSDK并解压;下载地址: 4.将AILinkBleSDK.framework文件导入项目; 5.在AppDelegate设置key和secret,如下: ``` #import - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {          // Override point for customization after application launch.     [ELBluetoothManager setAppKey:@"key" appSecret:@"secret"];          return YES; } ``` ## 开始使用 ### 一、公共部分 SDK的ELBluetoothManager是SDK的父类,它分为以下几个公共部分: #### 1.公共属性 ``` @property (nonatomic, assign, readonly) BOOL isOn; //Bluetooth status(蓝牙状态) @property (nonatomic, assign, readonly) ELBluetoothState state; //version number(版本号) @property (nonatomic, copy, readonly) NSString *bmVersion; /**  Save the model corresponding to the currently connected device  保存当前连接的设备对应的模型  */ @property (nonatomic, strong, readonly) ELPeripheralModel *peripheralModel; //Bluetooth proxy(蓝牙代理) @property (nonatomic, weak) id delegate; //Bluetooth wifi proxy(蓝牙wifi代理) @property (nonatomic, weak) id bleWifiDelegate; ``` #### 2.公共方法 ``` // +(__kindof ELBluetoothManager * _Nonnull)shareManager; /**  Get the SDK version number  获取SDK版本号  */ -(NSString *)sdkVersion; //Start scanning(开始扫描) -(void)startScan; //Stop scanning(停止扫描) -(void)stopScan; //Connecting device(连接设备) -(void)connectPeripheral:(ELPeripheralModel *)peripheralModel; //Disconnect device(断开设备) -(void)disconnectPeripheral; #pragma mark ============ 发送指令的3种方法 ============== /**  Shortcut method to send A6 data to BLE(发送A6数据给BLE的快捷方法)  @param data The stitched payload part(拼接好的payload部分)  */ -(void)sendCmdToMCUWithA6PayloadData:(NSData *)data; /**  Shortcut method of sending A7 data to MCU(发送A7数据给MCU的快捷方法)  @param data The stitched payload part(拼接好的payload部分)  @param type Equipment type(设备类型)  */ -(void)sendCmdToMCUWithA7PayloadData:(NSData *)data deviceType:(ELSupportDeviceType)type; /**  General method of sending data (support data transparent transmission)(发送数据通用方法(支持数据透传))  @param data 数据  */ -(void)sendData:(NSData *)data; #pragma mark ============ Please rewrite the following methods in the subclass(请在子类重写以下方法) BEGIN============== -(void)bluetoothUpdateState:(ELBluetoothState)state; -(void)bluetoothScanPeripherals:(NSArray *)peripherals; /** Callback decrypted A7 transparent data (payload part), type device type( 回调解密后的A7透传数据(payload部分),type设备类型)  */ -(void)bluetoothReceiveData:(NSData *)playload deviceType:(ELSupportDeviceType)type; /**  The special A6 data will only be received by the supported devices, and the complete A6 data (A6 is not encrypted) is passed to the subclass resolution.  特殊的A6数据,只有支持的设备才会收到,将完整A6数据(A6不加密)传给子类解析  ELSupportDeviceType support:  ELSupportDeviceTypeBodyFatScale  ELSupportDeviceTypeSmartLock  */ -(void)bluetoothBackA6Data:(NSData *)data withClassId:(ELSupportDeviceType)type; /**  Callback to scan special devices that can be bound, such as door locks(回调扫描到的可以绑定的特殊设备,如门锁)  */ -(void)bluetoothScanCanBindSpecialPeripherals:(NSArray *)peripherals; /**  Callback device basic information(回调设备基本信息)  @param data Device basic information payload data (length is 16 bytes)(设备基本信息payload数据(长度为16个byte))  */ -(void)bluetoothReceiveBasicInfoPayloadData:(NSData *)data; #pragma mark ============ Please rewrite the following methods in the subclass(子类重写方法) END============== #pragma mark ============ A6 Set or query instructions(设置或查询指令)  ============== /**  Get Bluetooth information(获取蓝牙信息)  @param type ELInetGetCmdType (ELInetGetCmdTypeGetHandshake除外)  */ -(void)getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdType)type; /**  Set the Bluetooth name(设置蓝牙名称)  @param name Name, less than 14 bytes(名称,小于14个byte)  */ -(void)setBluetoothName:(NSString * _Nonnull)name; /**  Set the broadcast interval(设置广播间隔时间)  @param interval 20~2000  */ -(void)setBroadcastInterval:(int)interval; /**  Set the connection interval 10(设置连接间隔)  @param interval The interval range is 20~2000ms.(interval范围是20~2000ms)  @param timeout  The timeout range is 1000~6000ms(timeout范围是1000~6000ms)  @param latency  The latency range is 0~4(latency范围是0〜4)  */ -(void)setConnectedInterval:(int)interval timeout:(int)timeout Latency:(int)latency; /**  Set the transmit power(设置发射功率)  @param power The range of power is 0~10(power的范围是0~10)  */ -(void)setTransmittingPower:(int)power; /**  Set the serial port baud rate(设置串口波特率)  @param rate The range of rate is 0~5(rate的范围是0~5)  0:9600  1:19200  2:38400  3:57600  4:115200  5:921600  */ -(void)setSerialPortbaudRate:(int)rate; /**  Set the MCU software and hardware version number(设置MCU软硬件版本号)  @param hardware 硬件  @param software 软件  如果是:S1.1,S11.1,S111.1, .....  请传:11,111,1111, ....  @param type Manufacturer's own definition(厂家自己定义)  @param year 年  @param month 月  @param day 日  */ -(void)setMCUVersion:(unsigned int)hardware software:(unsigned int)software mcuType:(unsigned int)type year:(unsigned int)year month:(unsigned int)month day:(unsigned int)day; /**  Set the big endian or little endian of the Mac address in the broadcast manufacturer's custom data.(设置广播厂家自定义数据中Mac地址的大端序或小端序)  @param type type  0:Little endian (default)(小端序 (默认))  1:Big endian(大端序)  */ -(void)setSetMACAddressType:(int)type; /**  Set up the module's service and feature services(设置模块的服务和特征服务)  @param serverUUIDData server  @param charateristicUUIDData charateristic  @param type UUID length:  0 : 16 bytes(default)  1:2 bytes  */ -(void)setBluetoothServerUUID:(NSData *)serverUUIDData charateristicUUID:(NSData *)charateristicUUIDData UUIDType:(int)type; /**  Set the master-slave mode of the module(设置模块的主从模式)  @param type Value:  0:Slave mode (default)(从机模式(默认))  1:Host mode(主机模式)  */ -(void)setMCUModel:(int)type; /**  Set the module's automatic sleep time without connection(设置模块无连接的自动休眠时间)  @param open Automatic sleep flag(自动睡眠标志位):  0:Do not turn on automatic sleep(不开启自动休眠)  1:Turn on auto sleep, the module is not connected(开启自动休眠,模块没有连接)  @param time Automatic sleep time (ms)(自动睡眠时间(ms))  @param radio Whether to enable low frequency broadcast after sleep: (unit: ms)(睡眠后是否开启低频广播:(单位:ms))  0:Not open(不开启)  1:Open(开启)  @param interval 低频广播间隔时间,20~2000ms  */ -(void)setAutoSleepTimeIsOpen:(BOOL)open autoSleepTime:(unsigned int)time isRadio:(BOOL)radio radioInterval:(int)interval; /**  Set to sleep(设置进入睡眠)  @param radio Whether to enable low frequency broadcast after sleep: (in ms)(睡眠后是否开启低频广播:(单位 ms))  0:Not open(不开启)  1:Open(开启)  @param interval 低频广播间隔时间,20~2000ms  */ -(void)setGotoSleepIsRadio:(BOOL)radio interval:(int)interval; /**  Set module wake up(设置模块唤醒)  */ -(void)setMCUWakeUp; /**  Set the current time of the system(设置系统当前时间)  @param enable  NO: In addition to the ability to turn off the time function, you can save part of the current (default)(除能,关闭时间功能,可省部分电流(默认))  YES:Enable, turn on the timer function timer(使能,开启计时功能定时器)  */ -(void)setMCUNowDateWithEnable:(BOOL)enable; /**  Setting CID, VID, PID(设置CID、VID、PID)  @param setC Whether to set the CID(是否设置CID)  @param setV Whether to set the VID(是否设置VID)  @param setP Whether to set the PID(是否设置PID)  @param cid Product Type ID: Less than 65536(产品类型ID:小于65536)  @param vid Manufacturer ID: less than 65536(厂家ID:小于65536)  @param pid Product ID: Less than 65536(产品ID:小于65536)  */ -(void)setC_V_P_IDWithIsSetCID:(BOOL)setC isSetVID:(BOOL)setV isSetPID:(BOOL)setP CID:(unsigned int)cid VID:(unsigned int)vid PID:(unsigned int)pid; /**  Set module communication mode  设置模块通信模式  @param mode communication mode(通信模式)  */ -(void)setCommunicationMode:(ELCommunicationModeType)mode; /**  Set module restart  设置模块重启  */ -(void)setMCURestart; /**  Set factory reset  设置恢复出厂设置  */ -(void)setFactoryDataReset; /**  Set the Bluetooth connection status(设置蓝牙连接状态)  @param disconnect Active disconnect flag(主动断开连接标志位)  1:Disconnect immediately(立刻断开连接)  0:Not disconnected(不断开连接)  */ -(void)setDisconnected:(BOOL)disconnect; /**  Send decoding key(发送解码密钥)  @param data The length of the decoding key is 19, the first 16 are keys, and the last 3 are random texts. You need to save this value on the app and MCU to generate a one-time password. (解码密钥的长度为19,前16个为密钥,后3个为随机文,需要在app端和MCU端保存这个值,用于生成一次性密码)  */ - (void)setKeyWithData:(NSData *)data; #pragma mark ============ Bluetooth WIFI calling method(蓝牙WIFI调用方法) ============== /**  WIFI initiate connection and disconnect(WIFI 发起连接、断开连接)  @param connect YES: initiate connection NO: disconnect(YES:发起连接 NO:断开连接)  */ -(void)bleWifiSetupWifiConnect:(BOOL)connect; /**  Set WIFI access URL(设置WIFI访问URL)    @param url url(Not more than 56chars(不超过56chars))  */ -(void)bleWifiSetWifiURL:(NSString *)url; /**  Set Wifi access port number(设置Wifi访问端口号)    @param port 端口号  */ -(void)bleWifiSetPort:(int)port; /**  Set DTIM interval(设置DTIM间隔)  @param interval 间隔  */ -(void)bleWifiSetDTIMInterval:(int)interval; /**  Set WIFI password(设置WIFI密码)    @param pwd WIFI password (8 ~ 56 chars)(WIFI密码(8~56 个chars))  */ -(void)bleWifiSetWifiPwd:(NSString *)pwd; /**  Set up connected WIFI(设置连接的WIFI)  @param macData wifi MAC (little endian)(wifi的MAC(小端序))  */ -(void)bleWifiSetConnectWifiMac:(NSData *)macData; ``` #### 3.公共协议 ``` //MARK:蓝牙通用协议 @protocol ELBluetoothManagerDelegate @optional //Callback Bluetooth status(回调蓝牙状态) -(void)bluetoothManagerUpdateBleState:(ELBluetoothState)state; //Callback to scanned device(回调扫描到的设备) -(void)bluetoothManagerScanedPeripherals:(NSArray *_Nonnull)peripherals; //Special devices that can be bound in the callback, such as door locks(回调中扫描到的可以绑定的特殊设备,如门锁) -(void)bluetoothManagerScanedCanBindSpecialPeripherals:(NSArray *_Nonnull)peripherals; //Callback decrypted transparent data (A7 decrypted payload data)(回调解密后的数据(A7解密后payload数据)) -(void)bluetoothManagerReceiveData:(NSData *_Nonnull)data deviceType:(ELSupportDeviceType)type; /**  回调透传数据  @param data 透传数据(此数据不能以A6或A7开头)  */ -(void)bluetoothManagerReceivePassData:(NSData *_Nullable)data; #pragma mark ============ A6 Set or query the callback of the instruction execution result(设置或查询指令执行结果的回调) ============== /**  Set or query the callback of the instruction execution result(设置指令蓝牙响应回调方法(握手指令除外))  @param type Type of setting (设置的类型)  @param result Set result(设置的结果)  */ -(void)bluetoothManagerReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result; /**  Query module status callback(查询模块状态的回调)  @param stateStrct 结构体  */ -(void)bluetoothManagerReceiveMCUConnectedState:(struct ELMCUStateStruct)stateStrct; /**  Query the callback of the communication mode(查询通信模式的回调)  @param type communication mode(通信模式)  */ -(void)bluetoothManagerReceiveCommunicationMode:(ELCommunicationModeType)type; /**  Query the callback of automatic sleep time(查询自动睡眠时间的回调)  @param sleetStrct Automatic sleep time(自动睡眠时间)  */ -(void)bluetoothManagerReceiveAutoSleepTime:(struct ELAutoSleepTimeStruct)sleetStrct; /**  Query master-slave mode callback(查询主从模式回调)  @param mode 模式  0:Slave mode(从机模式)  1:Host mode(主机模式)  */ -(void)bluetoothManagerReceiveMCUMode:(int)mode; /**  Query the callback of UUID information(查询UUID信息的回调)  @param uuid ELUUIDStruct  */ -(void)bluetoothManagerReceiveUUID:(struct ELUUIDStruct)uuid; /**  Query the callback of the MAC address size endian(查询MAC地址大小端序的回调)  @param type 类型  0:Little endian(小端序)  1:Big endian (大端序)  */ -(void)bluetoothManagerReceiveMacAddressType:(int)type; /**  Query the callback of the Bluetooth serial port baud rate(查询蓝牙串口波特率的回调)  @param rate Serial port baud rate(串口波特率)  0:9600  1:19200  2:38400  3:57600  4:115200  5:921600  */ -(void)bluetoothManagerReceiveSerialPostBaudRate:(int)rate; /**  Query the callback of Bluetooth transmit power(查询蓝牙发射功率的回调)  @param dbm Transmit power(发射功率)  */ -(void)bluetoothManagerReceiveTransmittingPower:(int)dbm; /**  Query the callback of the Bluetooth connection interval(查询蓝牙连接间隔的回调)  @param intervalStrct connection interval  */ -(void)bluetoothManagerReceiveConnectInterval:(struct ELConnectIntervalStruct)intervalStrct; /**  Query the callback of the Bluetooth name(查询蓝牙名称的回调)  @param name Bluetooth name(蓝牙名称)  */ -(void)bluetoothManagerReceiceName:(NSString *_Nullable)name; /**  Query the callback of the Bluetooth broadcast interval(查询蓝牙广播间隔的回调)  @param interval broadcast interval(广播间隔)  */ -(void)bluetoothManagerReceiveBroadcastInterval:(int)interval; /**  Query the callback of the Bluetooth MAC address(查询蓝牙MAC地址的回调)  @param macAddress MAC  */ -(void)bluetoothManagerReceiveMACAddress:(NSString *_Nonnull)macAddress; /**  Query the callback of the software and hardware version number of the BM module(查询BM模块软硬件版本号的回调)  @param bmVersion BM module software and hardware version number(BM模块软硬件版本号)  */ -(void)bluetoothManagerReceiveBMVersion:(NSString *_Nonnull)bmVersion; /**  Query the callback of the MCU software and hardware version number(查询MCU软硬件版本号的回调)    @param mcuVersion Callback of MCU software and hardware version number(MCU软硬件版本号的回调)  */ -(void)bluetoothManagerReceiveMCUVersion:(NSString *_Nonnull)mcuVersion; /**  Query the callback of Bluetooth time(查询蓝牙时间的回调)  @param date yyyy-MM-dd HH:mm:ss  @param effective Time is invalid(时间有无效)  0:effective(系统时间无效)  1:invalid(系统时间有效)  */ -(void)bluetoothManagerReceiveBluetoothDate:(NSString * _Nonnull)date effective:(BOOL)effective; /**  Query CID, VID, PID callback(查询CID,VID,PID的回调)  @param did CID,VID,PID  */ -(void)bluetoothManagerReceiveDID:(struct ELDIDStruct)did; /**  Query the callback of the battery status(查询电池状态的回调)  @param battery Structure of battery charge status and charge percentage(电池充电状态和电量百分比的结构体)  */ -(void)bluetoothManagerReceiveBattery:(struct ELBatteryStruct)battery; /**  * Query the callback of the device support unit(查询设备支持单位的回调)    */ - (void)bluetoothManagerBackDeviceSupportUnitWithWeight:(NSArray *_Nullable)weightArray                                                  Height:(NSArray *_Nullable)heightArray                                             Temperature:(NSArray *_Nullable)temperatureArray                                           BloodPressure:(NSArray *_Nullable)bloodPressureArray                                                Pressure:(NSArray *_Nullable)pressureArray; /**  Set the result of the decoding key(设置解码密钥的结果)  @param result 结果  */ -(void)bluetoothManagerReceiveSetKeyResult:(BOOL)result; 4.WiFi协议 //MARK:Bluetooth Wifi protocol(蓝牙Wifi协议) @protocol ElBleWifiDelegate @optional /**  Callback Wifi details(回调Wifi详情)  @param model 模型  */ -(void)bleWifiReceiveWifiDetailModel:(ELBleWifiDetailModel *_Nonnull)model; /** Scan nearby wifi results(扫描附近wifi结果)  @param count Number of nearby wifi(附近wifi数量)  */ -(void)bleWifiReceiveScanedWifiCount:(int)count; /**  Callback Wifi MAC address(回调Wifi MAC地址)  @param macData mac  */ -(void)bleWifiReceiveWifiMacData:(NSData *_Nullable)macData; /** Callback WIFI password(回调WIFI密码)  @param pwd password(密码)  */ -(void)bleWifiReceiveWifiPwd:(NSString *_Nonnull)pwd; /**  Get DTIM interval (unit: ms)(获取DTIM间隔(单位:ms))  @param interval Interval (unit: ms)(间隔(单位:ms))  */ -(void)bleWifiReceiveWifiDTIMInterval:(NSInteger)interval; /**  Returns the visited URL(返回访问的url)  @param url url  */ -(void)bleWifiReceiveWifiAccessURL:(NSString *_Nonnull)url; /**   Call back wifi port number(回调wifi的端口号)  @param port 端口号  */ -(void)bleWifiReceiveWifiPort:(int)port; /**  Set or query the callback of the instruction execution result(设置指令蓝牙WIFI响应回调方法)  只支持蓝牙Wifi部分枚举  @param type Type of setting (设置的类型)  @param result Set result(设置的结果)  */ -(void)bleWifiReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result; /**  获取会话码  @param code 会话码(为0时表示不存在)  */ -(void)bleWifiReceiveWifiSNCode:(int)code; ``` #### 5.说明 内容很多,需要调用什么自己按需要调用,如果是接入指定的设备,可查看四~十一。 ### 二、自己定义协议走透传 #### 1.导入父类或子类的头文件 (1)以体脂秤为例,导入头文件#import (2)设置代理: ``` [ELBodyFatScaleBleManager shareManager].bodyFatScaleDelegate = self; [ELBodyFatScaleBleManager shareManager].delegate  =self; ``` #### 2.连接设备 (1)扫描到设备 ``` [[ELBodyFatScaleBleManager shareManager] startScan]; ``` (2)选择设备并发起连接 ``` -(void)bodyFatScaleManagerScanDevices:(NSArray *)scaleDevices{     [[ELBodyFatScaleBleManager shareManager] connectPeripheral:device]; } ``` #### 3.发送透传数据 ``` [[ELBodyFatScaleBleManager shareManager] sendData:data]; ``` #### 4.接收透传数据 //MARK:接收透传数据(不符合AILink协议的数据,需要做透传的客户可在此根据自己的协议解析数据,透传数据不可以"A6"或"A7"开头) ``` -(void)bluetoothManagerReceivePassData:(NSData *)data{     NSLog(@"bluetoothManagerReceivePassData = %@",data.description);     } ``` #### 5.说明 所有设备都支持透传,可使用AILink协议的同时,自定义协议走透传实现一些额外的功能。 ## 三、有AILink协议自己解析数据 #### 1.继承 ``` @interface SubBleManager : ELBluetoothManager ``` #### 2.设置单例 ``` +(instancetype)shareManager; ``` #### 3.实现父类的方法 ``` -(void)bluetoothUpdateState:(ELBluetoothState)state; -(void)bluetoothScanPeripherals:(NSArray *)peripherals; /** Callback decrypted A7 transparent data (payload part), type device type( 回调解密后的A7透传数据(payload部分),type设备类型)  */ -(void)bluetoothReceiveData:(NSData *)playload deviceType:(ELSupportDeviceType)type; /**  The special A6 data will only be received by the supported devices, and the complete A6 data (A6 is not encrypted) is passed to the subclass resolution.  特殊的A6数据,只有支持的设备才会收到,将完整A6数据(A6不加密)传给子类解析  ELSupportDeviceType support:  ELSupportDeviceTypeBodyFatScale  ELSupportDeviceTypeSmartLock  */ -(void)bluetoothBackA6Data:(NSData *)data withClassId:(ELSupportDeviceType)type; /**  Callback to scan special devices that can be bound, such as door locks(回调扫描到的可以绑定的特殊设备,如门锁)  */ -(void)bluetoothScanCanBindSpecialPeripherals:(NSArray *)peripherals; /**  Callback device basic information(回调设备基本信息)  @param data Device basic information payload data (length is 16 bytes)(设备基本信息payload数据(长度为16个byte))  */ -(void)bluetoothReceiveBasicInfoPayloadData:(NSData *)data; ///Callback transparent transmission data(回调透传数据) /// @param data Transparent data(透传数据) -(void)bluetoothReceivePassData:(NSData *)data{ //Parsing transparent transmission data(解析透传数据) } ``` #### 4.定义自己的协议 ``` @protocol SubBleManagerDelegate ``` #### 5.实现自定义方法 ``` /// 发送数据给mcu /// @param data 协议对应数据 -(void)subBleSendA6Data:(NSData *)data; /// 发送数据给蓝牙 /// @param payload 协议的payload部分数据 -(void)subBleSendA7Data:(NSData *)payload; ``` #### 6.调用 遵守协议--》设置代理--》连接设备--》发送和接收数据 #### 7.说明 自己的协议名称不能与父类中的协议同名,具体的实现请参考Demo ### 四、集成婴儿秤 #### 1.导入头文件并遵守协议 ``` #import @interface BabyScaleConnectViewController () ``` #### 2.设置代理 ``` [ELBabyScaleBleManager shareManager].babyScaleDelegate = self;     [ELBabyScaleBleManager shareManager].delegate  =self; ``` #### 3.扫描并连接设备 ``` [[ELBabyScaleBleManager shareManager] startScan]; -(void)babyScaleManagerScanDevices:(NSArray *)babyScaleDevices{     [[ELBabyScaleBleManager shareManager] connectPeripheral:device] } ``` #### 4.发送数据 (1)获取BM版本号 ``` [[ELBabyScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetBMVersion)]; ``` (2)设置蓝牙名称 ``` [[ELBabyScaleBleManager shareManager] setBluetoothName:@"AILink"]; ``` (3)发送Hold ``` [[ELBabyScaleBleManager shareManager] changeHold:YES]; ``` (4)发送去皮 ``` [[ELBabyScaleBleManager shareManager] changeHold:NO]; ``` (5)修改单位 ``` [[ELBabyScaleBleManager shareManager] changeHeightUnit:(ELDeviceHeightUnit_CM) AndWeightUnit:(ELDeviceWeightUnit_KG)]; ``` #### 5.接收数据 ``` -(void)bluetoothManagerReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result{     if (type == ELInetSetCmdTypeSetName) {         if (result == ELSetBluetoothResponseTypeSuccess) {             [self addLog:@"Set name Success "];         }else if (result == ELSetBluetoothResponseTypeFailure){             [self addLog:@"Set name failure "];         }else if (result == ELSetBluetoothResponseTypeNoSupport){             [self addLog:@"Set name unsupport "];         }     } } //MARK:获取设备支持的单位 -(void)bluetoothManagerBackDeviceSupportUnitWithWeight:(NSArray *)weightArray Height:(NSArray *)heightArray Temperature:(NSArray *)temperatureArray BloodPressure:(NSArray *)bloodPressureArray Pressure:(NSArray *)pressureArray{     //这里体重和身高单位     //设置单位时,要设置设备支持的单位      } -(void)bluetoothManagerReceiveBMVersion:(NSString *)bmVersion{     [self addLog:bmVersion]; } //错误 -(void)babyScaleBackDeviceErrorCode:(BabyScaleDeviceErrorCode)code{     [self addLog:[NSString stringWithFormat:@"error code = %ld",code]]; } //体重 -(void)babyScaleManagerReceiveWeightModel:(ELBabyScaleBleWeightModel *)model{     [self addLog:[NSString stringWithFormat:@"weight = %ld unit=%@ point = %ld",model.weight,model.unitStr,model.weightPoint]]; } //身长数据 -(void)babyScaleManagerHeightModel:(ELBabyScaleBleHeightModel *)model{     [self addLog:[NSString stringWithFormat:@"height = %ld unit=%@ point = %ld",model.height,model.unitStr,model.heightPoint]]; } -(void)babyScaleBackCtrlType:(NSInteger)type Results:(BabyScaleResultType)result{ //    0去皮,1锁定)     if (type == 0) {         if (result == BabyScaleResultType_Succeed) {             [self addLog:@"Zero Unit success"];         }else if (result == BabyScaleResultType_Failure){             [self addLog:@"Zero Unit failure"];         }else if (result == BabyScaleResultType_Unsupported){             [self addLog:@"Zero Unit unsupported"];         }     }else{         if (result == BabyScaleResultType_Succeed) {             [self addLog:@"Hold Unit success"];         }else if (result == BabyScaleResultType_Failure){             [self addLog:@"Hold Unit failure"];         }else if (result == BabyScaleResultType_Unsupported){             [self addLog:@"Hold Unit unsupported"];         }     } } -(void)babyScaleBackSetUnitResults:(BabyScaleResultType)result{     if (result == BabyScaleResultType_Succeed) {         [self addLog:@"Change Unit success"];     }else if (result == BabyScaleResultType_Failure){         [self addLog:@"Change Unit failure"];     }else if (result == BabyScaleResultType_Unsupported){         [self addLog:@"Change Unit unsupported"];     } } -(void)babyScaleManagerUpdateState:(ELBluetoothState)state{     switch (state) {         case ELBluetoothStateUnavailable:         {             self.title = @"Please open the bluetooth";         }             break;         case ELBluetoothStateAvailable:         {             self.title = @"Bluetooth is open";         }             break;         case ELBluetoothStateScaning:         {             self.title = @"Scaning";         }             break;         case ELBluetoothStateConnectFail:         {             self.title = @"Connect fail";         }             break;         case ELBluetoothStateDidDisconnect:         {             self.title = @"Disconnected";         }             break;         case ELBluetoothStateDidValidationPass:         {             self.title = @"Connected";             [[ELBabyScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeReadDeviceSupportUnit)];         }             break;         case ELBluetoothStateFailedValidation:         {             self.title = @"Illegal equipment";         }             break;             case ELBluetoothStateWillConnect:             self.title = @"Connecting";             break;         default:             break;     } } ``` #### 6.说明 婴儿秤需要从设备读取支持的身高单位和体重单位,单位切换时要以支持的单位为准 ### 五、集成血压计 #### 1.导入头文件并遵守协议 ``` #import @interface BloodConnectViewController () ``` #### 2.设置代理 ``` [ELBloodBleManager shareManager].bloodDelegate = self;     [ELBloodBleManager shareManager].delegate  =self; ``` #### 3.扫描并连接设备 ``` [[ELBloodBleManager shareManager] startScan]; -(void)bloodBleManagerScanDevices:(NSArray *)devices{     [[ELBloodBleManager shareManager] connectPeripheral:device]; } ``` #### 4.发送数据 (1)获取BM版本号 ``` [[ELBloodBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetBMVersion)]; ``` (2)设置蓝牙名称 ``` [[ELBloodBleManager shareManager] setBluetoothName:@"AILink"]; ``` (3)开始测量 ``` [[ELBloodBleManager shareManager] sendInteractiveInstructions:(ELBloodInteractionTypeStartTest)]; ``` (4)停止测量 ``` [[ELBloodBleManager shareManager] sendInteractiveInstructions:(ELBloodInteractionTypeStopTest)]; ``` (5)切换单位 ``` [[ELBloodBleManager shareManager] changeUnit:(ELDeviceBloodPressureUnit_mmhg)]; ``` (6)开关语音 ``` [[ELBloodBleManager shareManager] sendSwitchVoice:(ELBloodBleSwitchVoiceTypeOff)]; ``` #### 5.接收数据 ``` -(void)bluetoothManagerReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result{     if (type == ELInetSetCmdTypeSetName) {         if (result == ELSetBluetoothResponseTypeSuccess) {             [self addLog:@"Set name Success "];         }else if (result == ELSetBluetoothResponseTypeFailure){             [self addLog:@"Set name failure "];         }else if (result == ELSetBluetoothResponseTypeNoSupport){             [self addLog:@"Set name unsupport "];         }     } } //MARK:获取设备支持的单位 -(void)bluetoothManagerBackDeviceSupportUnitWithWeight:(NSArray *)weightArray Height:(NSArray *)heightArray Temperature:(NSArray *)temperatureArray BloodPressure:(NSArray *)bloodPressureArray Pressure:(NSArray *)pressureArray{     //这里体重和身高单位     //设置单位时,要设置设备支持的单位      } -(void)bluetoothManagerReceiveBMVersion:(NSString *)bmVersion{     [self addLog:bmVersion]; } -(void)bloodBleManagerReceiceTestData:(ELBloodBleDataModel *)model type:(ELBloodBleDataModelType)type{     [self addLog:[NSString stringWithFormat:@"dia = %@--sys=%@ unit = %ld point = %ld",model.dia,model.sys,AiLinkBloodUnitDic[@(model.unit)],model.point]]; } -(void)bloodBleManagerReceiveSetSwitchVoiceOperationType:(ELBloodBleSwitchVoiceType)type result:(ELSetBluetoothResponseType)result{     if (type == ELBloodBleSwitchVoiceTypeOff) {         [self addLog:[NSString stringWithFormat:@"close voice result = %ld",result]];     }else{         [self addLog:[NSString stringWithFormat:@"open voice result = %ld",result]];     } } -(void)bloodBleManagerReceiveSetUnitResult:(ELSetBluetoothResponseType)type{     [self addLog:[NSString stringWithFormat:@"change unit result = %ld",type]]; } -(void)bloodBleManagerReceiveFailCode:(ELBloodFailCode)code{     [self addLog:[NSString stringWithFormat:@"error code = %ld",code]]; } -(void)bloodBleManagerUpdateBleState:(ELBluetoothState)state{     switch (state) {         case ELBluetoothStateUnavailable:         {             self.title = @"Please open the bluetooth";         }             break;         case ELBluetoothStateAvailable:         {             self.title = @"Bluetooth is open";         }             break;         case ELBluetoothStateScaning:         {             self.title = @"Scaning";         }             break;         case ELBluetoothStateConnectFail:         {             self.title = @"Connect fail";         }             break;         case ELBluetoothStateDidDisconnect:         {             self.title = @"Disconnected";         }             break;         case ELBluetoothStateDidValidationPass:         {             self.title = @"Connected";             [[ELBloodBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeReadDeviceSupportUnit)];         }             break;         case ELBluetoothStateFailedValidation:         {             self.title = @"Illegal equipment";         }             break;             case ELBluetoothStateWillConnect:             self.title = @"Connecting";             break;         default:             break;     } } ``` #### 6.说明 血压计需要从设备读取支持的血压单位,单位切换时要以支持的单位为准 ### 六、集成身高仪 #### 1.导入头文件并遵守协议 ``` #import @interface HeightGuageConnectViewController () ``` #### 2.设置代理 ``` [ELHeightGaugeBleManager shareManager].heightGaugeDelegate = self;     [ELHeightGaugeBleManager shareManager].delegate  =self; ``` #### 3.扫描并连接设备 ``` [[ELHeightGaugeBleManager shareManager] startScan]; -(void)heightGaugeBleManagerScanDevices:(NSArray *)devices{     [[ELHeightGaugeBleManager shareManager] connectPeripheral:device]; } ``` #### 4.发送数据 (1)获取BM版本号 ``` [[ELHeightGaugeBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetBMVersion)]; ``` (2)设置蓝牙名称 ``` [[ELHeightGaugeBleManager shareManager] setBluetoothName:@"AILink"]; ``` (3)切换单位 ``` [[ELHeightGaugeBleManager shareManager] changeUnit:(ELDeviceHeightUnit_CM)]; ``` #### 5.接收数据 ``` -(void)bluetoothManagerReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result{     if (type == ELInetSetCmdTypeSetName) {         if (result == ELSetBluetoothResponseTypeSuccess) {             [self addLog:@"Set name Success "];         }else if (result == ELSetBluetoothResponseTypeFailure){             [self addLog:@"Set name failure "];         }else if (result == ELSetBluetoothResponseTypeNoSupport){             [self addLog:@"Set name unsupport "];         }     } } //MARK:获取设备支持的单位 -(void)bluetoothManagerBackDeviceSupportUnitWithWeight:(NSArray *)weightArray Height:(NSArray *)heightArray Temperature:(NSArray *)temperatureArray BloodPressure:(NSArray *)bloodPressureArray Pressure:(NSArray *)pressureArray{     //这里体重和身高单位     //设置单位时,要设置设备支持的单位      } -(void)bluetoothManagerReceiveBMVersion:(NSString *)bmVersion{     [self addLog:bmVersion]; } /**  call back ELHeightGaugeBleDataModel  */ -(void)heightGaugeBleManagerReceiceTestData:(ELHeightGaugeBleDataModel *_Nonnull)model{     [self addLog:[NSString stringWithFormat:@"height = %ld  unit = %@ point = %ld",model.height,AiLinkBleHeightUnitDic[@(model.heightUnit)],model.heightPoint]]; } /**  call back the result of set unit  */ -(void)heightGaugeBleManagerReceiveSetUnitResult:(ELSetBluetoothResponseType)type{     [self addLog:[NSString stringWithFormat:@"change unit result = %lu",(unsigned long)type]]; } /**  call back fail code  */ -(void)heightGaugeBleManagerReceiveFailCode:(ELHeightGaugeFailCode)code{     [self addLog:[NSString stringWithFormat:@"error code = %lu",(unsigned long)code]]; } -(void)heightGaugeBleManagerUpdateBleState:(ELBluetoothState)state{     switch (state) {         case ELBluetoothStateUnavailable:         {             self.title = @"Please open the bluetooth";         }             break;         case ELBluetoothStateAvailable:         {             self.title = @"Bluetooth is open";         }             break;         case ELBluetoothStateScaning:         {             self.title = @"Scaning";         }             break;         case ELBluetoothStateConnectFail:         {             self.title = @"Connect fail";         }             break;         case ELBluetoothStateDidDisconnect:         {             self.title = @"Disconnected";         }             break;         case ELBluetoothStateDidValidationPass:         {             self.title = @"Connected";             [[ELHeightGaugeBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeReadDeviceSupportUnit)];         }             break;         case ELBluetoothStateFailedValidation:         {             self.title = @"Illegal equipment";         }             break;             case ELBluetoothStateWillConnect:             self.title = @"Connecting";             break;         default:             break;     } } ``` #### 6.说明 身高仪需要从设备读取支持的身高单位,单位切换时要以支持的单位为准 ### 七、集成遥控器 #### 1.导入头文件并遵守协议 ``` #import @interface RemoteControlConnectViewController () ``` #### 2.设置代理 ``` [ELRemoteControlBleManager shareManager].remoteControlDelegate = self;     [ELRemoteControlBleManager shareManager].delegate  =self; ``` #### 3.扫描并连接设备 ``` [[ELRemoteControlBleManager shareManager] startScan]; -(void)remoteControlManagerScanDevices:(NSArray *)deviceList{     [[ELRemoteControlBleManager shareManager] connectPeripheral:device]; } ``` #### 4.发送数据 (1)获取BM版本号 ``` [[ELRemoteControlBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetBMVersion)]; ``` (2)设置蓝牙名称 ``` [[ELRemoteControlBleManager shareManager] setBluetoothName:@"AILink"]; ``` (3)发送指令 ``` [[ELRemoteControlBleManager shareManager] sendRemoreControlData:(RemoteControlType_8_4)]; ``` #### 5.接收数据 ``` -(void)bluetoothManagerReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result{     if (type == ELInetSetCmdTypeSetName) {         if (result == ELSetBluetoothResponseTypeSuccess) {             [self addLog:@"Set name Success "];         }else if (result == ELSetBluetoothResponseTypeFailure){             [self addLog:@"Set name failure "];         }else if (result == ELSetBluetoothResponseTypeNoSupport){             [self addLog:@"Set name unsupport "];         }     } } -(void)bluetoothManagerReceiveBMVersion:(NSString *)bmVersion{     [self addLog:bmVersion]; } -(void)remoteControlManagerUpdateState:(ELBluetoothState)state{     switch (state) {         case ELBluetoothStateUnavailable:         {             self.title = @"Please open the bluetooth";         }             break;         case ELBluetoothStateAvailable:         {             self.title = @"Bluetooth is open";         }             break;         case ELBluetoothStateScaning:         {             self.title = @"Scaning";         }             break;         case ELBluetoothStateConnectFail:         {             self.title = @"Connect fail";         }             break;         case ELBluetoothStateDidDisconnect:         {             self.title = @"Disconnected";         }             break;         case ELBluetoothStateDidValidationPass:         {             self.title = @"Connected";         }             break;         case ELBluetoothStateFailedValidation:         {             self.title = @"Illegal equipment";         }             break;             case ELBluetoothStateWillConnect:             self.title = @"Connecting";             break;         default:             break;     } } ``` #### 6.说明 遥控器没有单位,发送指令也不需要回调数据处理 ### 八、集成额温枪 #### 1.导入头文件并遵守协议 ``` #import @interface ForeheadConnectViewController () ``` #### 2.设置代理 ``` [ELForeHeadBleManager shareManager].foreheadDelegate = self;     [ELForeHeadBleManager shareManager].delegate  =self; ``` #### 3.扫描并连接设备 ``` [[ELForeHeadBleManager shareManager] startScan]; -(void)foreheadBleManagerScanDevices:(NSArray *)devices{     [[ELForeHeadBleManager shareManager] connectPeripheral:device]; } ``` #### 4.发送数据 (1)获取BM的版本号 ``` [[ELForeHeadBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetBMVersion)]; ``` (2)设置蓝牙名称 ``` [[ELForeHeadBleManager shareManager] setBluetoothName:@"AILink"]; ``` (3)切换单位 ``` [[ELForeHeadBleManager shareManager] changeUnit:(ELDeviceTemperatureUnit_C)]; ``` #### 5.接收数据 ``` -(void)bluetoothManagerReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result{     if (type == ELInetSetCmdTypeSetName) {         if (result == ELSetBluetoothResponseTypeSuccess) {             [self addLog:@"Set name Success "];         }else if (result == ELSetBluetoothResponseTypeFailure){             [self addLog:@"Set name failure "];         }else if (result == ELSetBluetoothResponseTypeNoSupport){             [self addLog:@"Set name unsupport "];         }     } } //MARK:获取设备支持的单位 -(void)bluetoothManagerBackDeviceSupportUnitWithWeight:(NSArray *)weightArray Height:(NSArray *)heightArray Temperature:(NSArray *)temperatureArray BloodPressure:(NSArray *)bloodPressureArray Pressure:(NSArray *)pressureArray{     //这里体重和身高单位     //设置单位时,要设置设备支持的单位      } -(void)bluetoothManagerReceiveBMVersion:(NSString *)bmVersion{     [self addLog:bmVersion]; } /**  Callback temperature(回调温度)  @param model ELForeheadBleDataModel  */ -(void)foreheadBleManagerReceiveTemperature:(ELForeheadBleDataModel *_Nonnull)model dataType:(ForeheadBleDataType)dataType{     [self addLog:[NSString stringWithFormat:@"temperature = %@ unit = %@  point = %ld",model.temperature,AiLinkBleTempUnitDic[@(model.unit)],model.point]]; } /** Set unit callback( 设置单位回调)  @param type 结果  */ -(void)foreheadBleManagerReceiveSetUnitResult:(ELSetBluetoothResponseType)type{     [self addLog:[NSString stringWithFormat:@"Change Unit result = %lu",(unsigned long)type]]; } /**  Error code sent on the device(设备上发错误码)  @param code 错误码  */ -(void)foreheadBleManagerReceiveFailCode:(ForeheadFailCode)code{     [self addLog:[NSString stringWithFormat:@"error code = %lu",(unsigned long)code]]; } -(void)foreheadBleManagerUpdateBleState:(ELBluetoothState)state{     switch (state) {         case ELBluetoothStateUnavailable:         {             self.title = @"Please open the bluetooth";         }             break;         case ELBluetoothStateAvailable:         {             self.title = @"Bluetooth is open";         }             break;         case ELBluetoothStateScaning:         {             self.title = @"Scaning";         }             break;         case ELBluetoothStateConnectFail:         {             self.title = @"Connect fail";         }             break;         case ELBluetoothStateDidDisconnect:         {             self.title = @"Disconnected";         }             break;         case ELBluetoothStateDidValidationPass:         {             self.title = @"Connected";             [[ELForeHeadBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeReadDeviceSupportUnit)];         }             break;         case ELBluetoothStateFailedValidation:         {             self.title = @"Illegal equipment";         }             break;             case ELBluetoothStateWillConnect:             self.title = @"Connecting";             break;         default:             break;     } } ``` #### 6.说明 额温枪需要从设备读取支持的温度单位,单位切换时要以支持的单位为准 ### 九、集成温度计 #### 1.导入头文件并遵守协议 ``` #import @interface ThermometerConnectViewController () ``` #### 2.设置代理 ``` [ELThermometerBleManager shareManager].thermometerDelegate = self;     [ELThermometerBleManager shareManager].delegate  =self; ``` #### 3.扫描并连接设备 ``` [[ELThermometerBleManager shareManager] startScan]; -(void)thermometerManagerScanDevices:(NSArray *)thermometerDevices{     [[ELThermometerBleManager shareManager] connectPeripheral:device]; } ``` #### 4.发送数据 (1)获取BM版本号 ``` [[ELThermometerBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetBMVersion)]; ``` (2)设置蓝牙名称 ``` [[ELThermometerBleManager shareManager] setBluetoothName:@"AILink"]; ``` (3)切换单位 ``` [[ELThermometerBleManager shareManager] changeThermometerUnit:(ELDeviceTemperatureUnit_F)]; ``` #### 5.接收数据 ``` -(void)bluetoothManagerReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result{     if (type == ELInetSetCmdTypeSetName) {         if (result == ELSetBluetoothResponseTypeSuccess) {             [self addLog:@"Set name Success "];         }else if (result == ELSetBluetoothResponseTypeFailure){             [self addLog:@"Set name failure "];         }else if (result == ELSetBluetoothResponseTypeNoSupport){             [self addLog:@"Set name unsupport "];         }     } } //MARK:获取设备支持的单位 -(void)bluetoothManagerBackDeviceSupportUnitWithWeight:(NSArray *)weightArray Height:(NSArray *)heightArray Temperature:(NSArray *)temperatureArray BloodPressure:(NSArray *)bloodPressureArray Pressure:(NSArray *)pressureArray{     //这里体重和身高单位     //设置单位时,要设置设备支持的单位      } -(void)bluetoothManagerReceiveBMVersion:(NSString *)bmVersion{     [self addLog:bmVersion]; } /**  Callback temperature(回调温度)  @param model ELForeheadBleDataModel  */ -(void)thermometerManagerReceiveModel:(ELThermometerBleModel *)model{     [self addLog:[NSString stringWithFormat:@"temperature = %ld unit = %@  point = %ld",model.temperature,AiLinkBleTempUnitDic[@(model.unit)],model.tempPoint]]; } /** Set unit callback( 设置单位回调)  @param type 结果  */ -(void)thermometerManagerSetUnitResults:(ThermometerBleResultType)result{     [self addLog:[NSString stringWithFormat:@"Change Unit result = %lu",(unsigned long)result]]; } /**  Error code sent on the device(设备上发错误码)  @param code 错误码  */ -(void)thermometerManagerBackDeviceErrorCode:(ThermometerBleErrorCode)code{     [self addLog:[NSString stringWithFormat:@"error code = %lu",(unsigned long)code]]; } -(void)thermometerManagerUpdateState:(ELBluetoothState)state{     switch (state) {         case ELBluetoothStateUnavailable:         {             self.title = @"Please open the bluetooth";         }             break;         case ELBluetoothStateAvailable:         {             self.title = @"Bluetooth is open";         }             break;         case ELBluetoothStateScaning:         {             self.title = @"Scaning";         }             break;         case ELBluetoothStateConnectFail:         {             self.title = @"Connect fail";         }             break;         case ELBluetoothStateDidDisconnect:         {             self.title = @"Disconnected";         }             break;         case ELBluetoothStateDidValidationPass:         {             self.title = @"Connected";             [[ELThermometerBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeReadDeviceSupportUnit)];         }             break;         case ELBluetoothStateFailedValidation:         {             self.title = @"Illegal equipment";         }             break;             case ELBluetoothStateWillConnect:             self.title = @"Connecting";             break;         default:             break;     } } ``` #### 6.说明 温度计需要从设备读取支持的温度单位,单位切换时要以支持的单位为准 ### 十、集成胎压监测 #### 1.导入头文件并遵守协议 ``` #import @interface WheelMonitorConnectViewController () ``` #### 2.设置代理 ``` [ELWheelMonitorBleManager shareManager].wheelMonitordelegate = self;     [ELWheelMonitorBleManager shareManager].delegate  =self; ``` #### 3.扫描并连接设备 ``` [[ELWheelMonitorBleManager shareManager] startScan]; -(void)wheelMonitorBleManagerScanDevices:(NSArray *)devices{     [[ELWheelMonitorBleManager shareManager] connectPeripheral:device]; } ``` #### 4.发送数据 (1)获取BM版本号 ``` [[ELWheelMonitorBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetBMVersion)]; ``` (2)设置蓝牙名称 ``` [[ELWheelMonitorBleManager shareManager] setBluetoothName:@"AILink"]; ``` (3)切换单位 ``` [[ELWheelMonitorBleManager shareManager] changePressureUnit:(ELDevicePressureUnit_kPa) tempUnit:(ELDeviceTemperatureUnit_C)]; ``` (4)获取胎压记录 ``` [[ELWheelMonitorBleManager shareManager] getWheelData:(WheelMonitorGetWheelData_LeftBack)];         [[ELWheelMonitorBleManager shareManager] getWheelData:(WheelMonitorGetWheelData_LeftFront)];         [[ELWheelMonitorBleManager shareManager] getWheelData:(WheelMonitorGetWheelData_RightBack)];         [[ELWheelMonitorBleManager shareManager] getWheelData:(WheelMonitorGetWheelData_RightFront)]; ``` (5)设置胎压阈值 ``` [[ELWheelMonitorBleManager shareManager] sendSettingWheelPressureLimitWithFrontMax:300 frontMin:200 backMax:300 backMin:200 pressureUnit:(ELDevicePressureUnit_kPa) valuePoint:0]; ``` (6)设置胎温阈值 ``` [[ELWheelMonitorBleManager shareManager] sendSettingWheelTempLimitWithTempMax:100 tempMin:50 tempUnit:(ELDeviceTemperatureUnit_C) valuePoint:0 openVoice:YES]; ``` (7)切换语音报警 ``` [[ELWheelMonitorBleManager shareManager] sendSettingWheelOpenVoice:YES]; ``` #### 5.接收数据 ``` -(void)bluetoothManagerReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result{     if (type == ELInetSetCmdTypeSetName) {         if (result == ELSetBluetoothResponseTypeSuccess) {             [self addLog:@"Set name Success "];         }else if (result == ELSetBluetoothResponseTypeFailure){             [self addLog:@"Set name failure "];         }else if (result == ELSetBluetoothResponseTypeNoSupport){             [self addLog:@"Set name unsupport "];         }     } } //MARK:获取设备支持的单位 -(void)bluetoothManagerBackDeviceSupportUnitWithWeight:(NSArray *)weightArray Height:(NSArray *)heightArray Temperature:(NSArray *)temperatureArray BloodPressure:(NSArray *)bloodPressureArray Pressure:(NSArray *)pressureArray{     //这里体重和身高单位     //设置单位时,要设置设备支持的单位      } -(void)bluetoothManagerReceiveBMVersion:(NSString *)bmVersion{     [self addLog:bmVersion]; } /**  Set unit callback(设置单位回调)    @param type 结果  @param settingType 支持类型:  WheelMonitorBleDataTypeSetUnitResult  WheelMonitorBleDataTypeSetPressureLimit  WheelMonitorBleDataTypeSetTempLimit  WheelMonitorBleDataTypeSetVoice  */ -(void)wheelMonitorBleManagerReceiveSetResult:(ELSetBluetoothResponseType)type settingType:(WheelMonitorBleDataType)settingType{     [self addLog:[NSString stringWithFormat:@"set type = %lu set result = %lu",settingType,type]]; } /**  Callback tire pressure data(回调胎压数据)  @param model 胎压数据模型  */ -(void)wheelMonitorBleManagerWheelMonitorData:(ELWheelMonitorBleModel *_Nonnull)model{     [self addLog:[NSString stringWithFormat:@"wheel number = %ld voltage = %@ pressure = %@%@ temperature=%@%@",model.wheelType,model.v,model.p,AiLinkBlePressureUnitDic[@(model.pressureUnit)],model.t,AiLinkBlePressureUnitDic[@(model.tempUnit)]]]; } /**  Get front and rear wheel parameter setting type(获取前后轮参数设置类型)  @param type 类型  */ -(void)wheelMonitorBleManagerReceiveSettingType:(WheelMonitorSettingType)type{     [self addLog:[NSString stringWithFormat:@"setting type = %lu",type]]; } -(void)wheelMonitorBleManagerUpdateBleState:(ELBluetoothState)state{     switch (state) {         case ELBluetoothStateUnavailable:         {             self.title = @"Please open the bluetooth";         }             break;         case ELBluetoothStateAvailable:         {             self.title = @"Bluetooth is open";         }             break;         case ELBluetoothStateScaning:         {             self.title = @"Scaning";         }             break;         case ELBluetoothStateConnectFail:         {             self.title = @"Connect fail";         }             break;         case ELBluetoothStateDidDisconnect:         {             self.title = @"Disconnected";         }             break;         case ELBluetoothStateDidValidationPass:         {             self.title = @"Connected";  //前后轮胎压的阀值是一起设备还是分开设置             [[ELWheelMonitorBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeGetBasicInfoData];             //获取设备支持的单位             [[ELWheelMonitorBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeReadDeviceSupportUnit)];         }             break;         case ELBluetoothStateFailedValidation:         {             self.title = @"Illegal equipment";         }             break;             case ELBluetoothStateWillConnect:             self.title = @"Connecting";             break;         default:             break;     } } ``` #### 6.说明 胎压监测需要从设备读取支持的压力单位和温度单位,单位切换时要以支持的单位为准 连接成功后,调用如下方法获取前后轮胎压的阀值是一起设备还是分开设置 ```             [[ELWheelMonitorBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeGetBasicInfoData]; ``` ### 十一、集成体脂秤 #### 1.导入头文件并遵守协议 ``` #import @interface BodyFatScaleConnectViewController () ``` #### 2.设置代理 ``` [ELBodyFatScaleBleManager shareManager].bodyFatScaleDelegate = self;     [ELBodyFatScaleBleManager shareManager].delegate  =self; //如果是wifi+ble的秤,需要设置wif代理     [ELBodyFatScaleBleManager shareManager].bleWifiDelegate = self; ``` #### 3.扫描并连接设备 ``` [[ELBodyFatScaleBleManager shareManager] startScan]; -(void)bodyFatScaleManagerScanDevices:(NSArray *)scaleDevices{     [[ELBodyFatScaleBleManager shareManager] connectPeripheral:device]; } ``` #### 4.发送数据 (1)获取BM版本号 (2)设置蓝牙名称 (3)切换单位 #### 5.接收数据、处理数据、交互 ``` -(void)bluetoothManagerReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result{     if (type == ELInetSetCmdTypeSetName) {         if (result == ELSetBluetoothResponseTypeSuccess) {             [self addLog:@"Set name Success "];         }else if (result == ELSetBluetoothResponseTypeFailure){             [self addLog:@"Set name failure "];         }else if (result == ELSetBluetoothResponseTypeNoSupport){             [self addLog:@"Set name unsupport "];         }     } } //MARK:获取设备支持的单位 -(void)bluetoothManagerBackDeviceSupportUnitWithWeight:(NSArray *)weightArray Height:(NSArray *)heightArray Temperature:(NSArray *)temperatureArray BloodPressure:(NSArray *)bloodPressureArray Pressure:(NSArray *)pressureArray{     //这里体重和身高单位     //设置单位时,要设置设备支持的单位     //这里只要体重数据     self.units = weightArray; } -(void)bluetoothManagerReceiveBMVersion:(NSString *)bmVersion{     [self addLog:bmVersion]; } -(void)bluetoothManagerReceiveMCUConnectedState:(struct ELMCUStateStruct)stateStrct{          BleWiFiConnectState wifiState = stateStrct.wifiState;          if (self.p.deviceType == ELSupportDeviceTypeBLE_WIFIScale) {         //蓝牙WiFi体脂秤         //请求会话码         [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetSNNumber];         //MARK:1.WiFi配置提示用户配网         //TODO:注意:wifi配置过程必须保持蓝牙与设备的连接         if (wifiState == BleWiFiConnectStateNoWiFi) {             //1.如果没有配网,则提示用户去配网             //MARK:2.WiFi配置先获取wifi列表             //             [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetNearbyWifi];             // //            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Change Unit" message:@"" preferredStyle:(UIAlertControllerStyleAlert)]; //            UIAlertAction *action = [UIAlertAction actionWithTitle:@"去配网" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { //                if ([ELBodyFatScaleBleManager shareManager].state == ELBluetoothStateDidValidationPass) { //                    WiFiSetupViewController *vc = [[WiFiSetupViewController alloc] init]; //                    [self.navigationController pushViewController:vc animated:YES]; //                }else{ //                    [self addLog:@"Disconnected"]; //                } // //            }]; //            UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { // //            }]; //            [alert addAction:action]; //            [alert addAction:action2]; //            [self presentViewController:alert animated:YES completion:nil];         }     }     ///MARK:9.wifi配置结果     //wifi相关的其他指令和数据接收,请查看ELBluetoothManager.h文件     if (stateStrct.wifiState == BleWiFiConnectStateSuccess) {         //成功         //MARK:10.获取wifi设备的SN号,即设备id         [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeBleWifiGetSNNumber)];     }else{         //失败     } } /**  Callback to set unit result(回调设置单位结果)    @param result 结果  */ - (void)bodyFatScaleManagerCallBackSetUnitResult:(ELSetBluetoothResponseType)result{     switch (result) {         case ELSetBluetoothResponseTypeSuccess:         {             [self addLog:@"Change Unit Success"];         }             break;         case ELSetBluetoothResponseTypeFailure:         {             [self addLog:@"Change Unit Failure"];         }             break;         case ELSetBluetoothResponseTypeNoSupport:         {             [self addLog:@"Unsupport Change Unit"];         }             break;         default:             break;     } } //MARK:回调Wifi列表 -(void)bleWifiReceiveWifiDetailModel:(ELBleWifiDetailModel *)model{ //    MARK:3.WiFi配置得到Wifi列表     //用一个tableview显示喽     [self addLog:[NSString stringWithFormat:@"wifi类型---%lu 名称---%@",(unsigned long)model.wifiState,model.wifiName]];      } -(void)bleWifiReceiveScanedWifiCount:(int)count {     //MARK:扫描Wifi结束     //MARK:4.WiFi配置得到一个附近wifi的列表,点击选择一个wifi,进行配置     //MARK:5.输入wifi密码     //写个“textfield”输入密码     //MARK:6.先发送配置wifi的mac地址的指令 //    [[ELBodyFatScaleBleManager shareManager] bleWifiSetConnectWifiMac:[NSData data]]; } -(void)bleWifiReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result{          [self addLog:[NSString stringWithFormat:@"bleWifiReceiceResponseType==%lu----%lu",type,result]];     if (result == ELSetBluetoothResponseTypeSuccess) {         //设置WiFi结果         if (type == ELInetSetCmdTypeBleWifiSetWifiMac) {             //MARK:7.再发送配置wifi的密码的指令             [[ELBodyFatScaleBleManager shareManager] bleWifiSetWifiPwd:@"WiFi密码"];         }else if (type == ELInetSetCmdTypeBleWifiSetWifiPwd){             //MARK:8.然后发起连接Wifi             [[ELBodyFatScaleBleManager shareManager] bleWifiSetupWifiConnect:YES];         }else if (type == ELInetSetCmdTypeBleWifiSetConnectWifi){             //获取连接状态         }     }     else{         //TODO:Wifi配置过程中失败的情况自行处理     }      } /**  MCU requests user information( MCU 请求用户信息)    @param status 请求状态  */ - (void)bodyFatScaleManagerMCURequestAppUserInfoType:(BodyFatScaleMCURequestUserInfoStatus)status{     if (status == BodyFatScaleMCURequestUserInfoStatus_Get) {         //下发当前用户给秤         [[ELBodyFatScaleBleManager shareManager] sendCurrentUserToBle:[self getOneUser]];     }else if (status == BodyFatScaleMCURequestUserInfoStatus_Success){         [self addLog:@"MCU requests user information success"];     }else if (BodyFatScaleMCURequestUserInfoStatus_Fail){         [self addLog:@"MCU requests user information failure"];     } } /**  Return weight and body fat model(返回重量及体脂model)  */ -(void)bodyFatScaleManagerCallBackWeight:(ELBodyFatScaleBleWeightModel *)weightModel state:(BodyFatScaleMeasureStatus)status{     switch (status) {         case BodyFatScaleMeasureStatus_Unstable:         {             [self addLog:[NSString stringWithFormat:@"Unstable data weight = %ld unit = %@ point = %ld adc = %ld",weightModel.weight,AiLinkBleWeightUnitDic[@(weightModel.weightUnit)],weightModel.weightPoint,weightModel.adc]];         }             break;         case BodyFatScaleMeasureStatus_Stable:         {             [self addLog:[NSString stringWithFormat:@"Stable data weight = %ld unit = %@ point = %ld adc = %ld",weightModel.weight,AiLinkBleWeightUnitDic[@(weightModel.weightUnit)],weightModel.weightPoint,weightModel.adc]];         }             break;         case BodyFatScaleMeasureStatus_Failed:         {             [self addLog:@"Test failure"];         }             break;         case BodyFatScaleMeasureStatus_Complete:         {             [self addLog:[NSString stringWithFormat:@"Tested weight = %ld unit = %@ point = %ld adc = %ld",weightModel.weight,AiLinkBleWeightUnitDic[@(weightModel.weightUnit)],weightModel.weightPoint,weightModel.adc]];                          //更新用户信息给秤             [[ELBodyFatScaleBleManager shareManager] sendCurrentUserToBle:[self getOneUser]];             //下发用户列表             [[ELBodyFatScaleBleManager shareManager] sendOfflineUserListToBle:[self get8Users]];         }             break;         default:             break;     } } /**  Return temperature (unit: ° C)(返回温度(单位:°C))    @param temp 温度(单位:°C)  */ -(void)bodyFatScaleManagerCallBackTemp:(NSString *)temp{     [self addLog:[NSString stringWithFormat:@"temperature is %@",temp]]; } /**  Back to impedance measurement(返回阻抗测量)    @param status 阻抗测量状态  @param adc 阻抗  */ -(void)bodyFatScaleManagerCallBackAdcMeasureStatus:(BodyFatScaleAdcMeasureStatus)status adcValue:(NSInteger)adc{     switch (status) {         case BodyFatScaleAdcMeasureStatus_Testing:         {             [self addLog:@"adc testing"];         }             break;         case BodyFatScaleAdcMeasureStatus_Success:         {             [self addLog:[NSString stringWithFormat:@"adc is %ld",adc]];         }             break;         case BodyFatScaleAdcMeasureStatus_Fail:         {             [self addLog:@"adc test failure"];         }             break;         case BodyFatScaleAdcMeasureStatus_SuccessCustom:         {             [self addLog:[NSString stringWithFormat:@"adc is %ld and user app algum",adc]];         }             break;         default:             break;     } } /**  Callback heart rate measurement(回调心率测量)    @param status 心率测量状态  @param heartRate 心率  */ -(void)bodyFatScaleManagerCallBackHeartRateMeasureStatus:(BodyFatScaleHeartRateMeasureStatus)status heartRateValue:(NSInteger)heartRate{     switch (status) {         case BodyFatScaleHeartRateMeasureStatus_Testing:         {             [self addLog:@"Heart Rate Testing"];         }             break;         case BodyFatScaleHeartRateMeasureStatus_Success:         {             [self addLog:[NSString stringWithFormat:@"Heart Rate is %ld",heartRate]];         }             break;         case BodyFatScaleHeartRateMeasureStatus_Fail:         {             [self addLog:@"Heart Rate Test failure"];         }             break;         default:             break;     } } /**  Return error code(返回错误码)    @param code 错误码  1:超重  */ -(void)bodyFatScaleManagerCallBackErrorCode:(NSInteger)code{     [self addLog:[NSString stringWithFormat:@"error code = %ld",code]]; } //MARK:回调A6指令数据 /**  Send success or failure callback for offline user list(发送离线用户列表的成功或失败回调)    @param status 状态  */ -(void)bodyFatScaleManagerCallBackUpdateRecordStatus:(BodyFatScaleUpdateRecordStatus)status{     switch (status) {         case BodyFatScaleUpdateRecordStatus_AllSuccess:         {             [self addLog:@"Update All Users Success"];         }             break;         case BodyFatScaleUpdateRecordStatus_OneSuccess:         {             [self addLog:@"Update A User Success"];         }             break;         case BodyFatScaleUpdateRecordStatus_OneFail:         {             [self addLog:@"Update A User Failure"];         }             break;         case BodyFatScaleUpdateRecordStatus_AllFail:         {             [self addLog:@"Update All Users Failure"];         }             break;         default:             break;     } } /**  Request callback for offline history(请求离线历史记录的回调)    @param status 状态  */ -(void)bodyFatScaleManagerCallBackSendHistoryDataStatus:(BodyFatScaleSendHistoryDataStatus)status{     if (status == BodyFatScaleSendHistoryDataStatus_No) {         [self addLog:@"No offline datas"];     }else if (status == BodyFatScaleSendHistoryDataStatus_Begin){         [self addLog:@"Begin receive offline datas"];     }else if (status == BodyFatScaleSendHistoryDataStatus_End){         [self addLog:@"End receive offline datas"];     }      } /**  APP algorithm-offline history data(APP 算法-离线历史记录数据)    @param user 用户信息  */ -(void)bodyFatScaleManagerCallBackBleUserHistoryDataCustomADCModel:(ELBodyFatScaleBleUserModel *)user bodyDataModel:(ELBodyFatScaleBleWeightModel *)bodyModel{     //这里的身体指标等数据由app自定义算法计算得到,请区分bodyModel.algNum来调用算法     [self addLog:[NSString stringWithFormat:@"App algorithm-offline history data:userId = %ld weight = %ld unit =%@ point = %ld",user.usrID,bodyModel.weight,AiLinkBleWeightUnitDic[@(bodyModel.weightUnit)],bodyModel.weightPoint]]; } /**  MCU algorithm-offline history data(MCU 算法-离线历史记录数据)    @param user 用户信息  @param bodyModel 体脂数据  */ -(void)bodyFatScaleManagerCallBackBleUserHistoryDataModel:(ELBodyFatScaleBleUserModel *)user bodyDataModel:(ELBodyFatScaleBleWeightModel *)bodyModel{     //这里的身体指标数据由秤计算得到     [self addLog:[NSString stringWithFormat:@"MCU algorithm-offline history data:userId = %ld weight = %ld unit =%@ point = %ld",user.usrID,bodyModel.weight,AiLinkBleWeightUnitDic[@(bodyModel.weightUnit)],bodyModel.weightPoint]]; } -(void)bleWifiReceiveWifiSNCode:(int)code{     //MARK:11.根据wifi设备的设备id从服务器获取离线数据(找自己后台要接口) } -(void)bodyFatScaleManagerUpdateState:(ELBluetoothState)state{     switch (state) {         case ELBluetoothStateUnavailable:         {             self.title = @"Please open the bluetooth";         }             break;         case ELBluetoothStateAvailable:         {             self.title = @"Bluetooth is open";         }             break;         case ELBluetoothStateScaning:         {             self.title = @"Scaning";         }             break;         case ELBluetoothStateConnectFail:         {             self.title = @"Connect fail";         }             break;         case ELBluetoothStateDidDisconnect:         {             self.title = @"Disconnected";         }             break;         case ELBluetoothStateDidValidationPass:         {             self.title = @"Connected";             //获取设备支持的单位             [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeReadDeviceSupportUnit)];             //将你自己设置的单位发给秤             ELDeviceWeightUnit unit = ELDeviceWeightUnit_KG;             [[ELBodyFatScaleBleManager shareManager] changeBodyFatScaleUnit:unit];             //请求历史记录             [[ELBodyFatScaleBleManager shareManager] sendCmd_RequestHistory];                          //下发用户列表             [[ELBodyFatScaleBleManager shareManager] sendOfflineUserListToBle:[self get8Users]];                          if (self.p.deviceType == ELSupportDeviceTypeBLE_WIFIScale) {                 //获取蓝牙连接状态                 [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetConnectState)];             }         }             break;         case ELBluetoothStateFailedValidation:         {             self.title = @"Illegal equipment";         }             break;         case ELBluetoothStateWillConnect:             self.title = @"Connecting";             break;         default:             break;     } } -(NSArray *)get8Users{     NSMutableArray *users = [[NSMutableArray alloc] init];     for (int i=0; i<8; i++) {         ELBodyFatScaleBleUserModel *user = [[ELBodyFatScaleBleUserModel alloc] init];         user.createTime = [[NSDate date] timeIntervalSince1970];         user.usrID = i;         user.role = i%4;         user.sex = i%2;         user.age = 26+i;         user.height = 170+i;         user.weight = 600+i;         user.adc = 560+i;         [users addObject:user];     }     return users.copy; } -(ELBodyFatScaleBleUserModel *)getOneUser{     ELBodyFatScaleBleUserModel *user = [[ELBodyFatScaleBleUserModel alloc] init];     user.createTime = [[NSDate date] timeIntervalSince1970];     user.usrID = 0;     user.role = BodyFatScaleRole_Ordinary;     user.sex = ELBluetoothUserSex_Woman;     user.age = 26;     user.height = 170;     user.weight = 600;     user.adc = 560;     return user; } ``` ### 十三、广播体脂秤 #### 1.文件说明 >* `ELBroadcastScaleBleHeader `一些用到的枚举; >* `ELBroadcastScaleBleManager`续承自`ELBluetoothManager`的类,用于扫描附近设备和接收数据; >* `ELBroadcastScaleDataModel`广播秤的数据结构模型. #### 2.使用范例Demo 打开`AILinkBleSDKDemo_iOS`,运行到手机上,选择`集成广播秤`,参照`BroadcastScaleViewController.m`的使用. ### 十四、八电极体脂秤 #### 1.文件说明 >* `ELEightScaleSDKHeader `一些用到的枚举和数据结构; >* `ELEightScaleBleManager`续承自`ELBluetoothManager`的类,用于扫描附近设备、连接设备、接收数据和发送数据给设备; >* `ELEightScaleBleDataModel`称量结果的数据结构模型. #### 2.使用范例Demo 打开`AILinkBleSDKDemo_iOS`,运行到手机上,选择`八电极体脂秤`,参照`EightScaleScanViewController.m`和`EightScaleConnectionViewController.m`的使用. ### 十五、蓝牙WiFi牙刷 #### 1.文件说明 >* `ELToothburshHeader`一些用到的枚举和数据结构; >* `ELToothbrushBleManager`续承自`ELBluetoothManager`的类,用于扫描附近设备、连接设备、接收数据和发送数据给设备. #### 2.使用范例Demo 打开`AILinkBleSDKDemo_iOS`,运行到手机上,选择`蓝牙WiFi牙刷`,参照`ToothbrushScanViewController.m`和`ToothbrushConnectionViewController.m`的使用. #### 6.说明 体脂秤需要从设备读取支持的体重单位,单位切换时要以支持的单位为准 ## 详情及wifi配置逻辑请见协议和demo ## 联系我们 感谢您使用品网SDK进行产品研发,如在使用过程中有任何疑问,欢迎随时与我们联系。帮助企业实现产品的快速智能化,是我们不断前行的动力。 Web: www.inet-tek.com Email : iot.support@inet-tek.com