iOS AILinkBleSDK - 蓝牙SDK
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ELBluetoothManager.h 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. //
  2. // ELBluetoothManager.h
  3. // Elink
  4. //
  5. // Created by iot_user on 2019/4/22.
  6. // Copyright © 2019 iot_iMac. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import "ELPeripheralModel.h"
  10. #import "ELSDKHeader.h"
  11. #import "ELBlePublicTool.h"
  12. #import "ELBluetoothManager+Settings_Callback.h"
  13. #import "ELBluetoothManager+BleWifi_Callback.h"
  14. #import "AILinkBleSDK_Version.h"
  15. NS_ASSUME_NONNULL_BEGIN
  16. /// 有些设备需要页面获取到发送的数据内容,给服务器,监听该通知获得发送数据,保险起见需要判断一个header.内容是data
  17. /// 发送A7不加密数据
  18. static NSString *SEND_A7_BLE_DATA_CONTENT = @"SEND_A7_BLE_DATA_CONTENT";
  19. /// 发送A7加密数据
  20. static NSString *SEND_A7_ENCRYPTED_BLE_DATA_CONTENT = @"SEND_A7_ENCRYPTED_BLE_DATA_CONTENT";
  21. /// 设备返回A7解密的payload数据
  22. static NSString *GET_A7_DECRYPT_BLE_PAYLOAD_DATA_CONTENT = @"GET_A7_DECRYPT_BLE_PAYLOAD_DATA_CONTENT";
  23. @interface ELBluetoothManager : NSObject
  24. @property (nonatomic, assign, readonly) BOOL isOn;
  25. //Bluetooth status(蓝牙状态)
  26. @property (nonatomic, assign, readonly) ELBluetoothState state;
  27. //version number(版本号)
  28. @property (nonatomic, copy, readonly) NSString *bmVersion;
  29. // 好身材秤 连接秤特有区分ac02和ac03
  30. @property (nonatomic,assign) Byte acByte;
  31. /**
  32. Save the model corresponding to the currently connected device
  33. 保存当前连接的设备对应的模型
  34. */
  35. @property (nonatomic, strong, readonly) ELPeripheralModel *peripheralModel;
  36. //Bluetooth proxy(蓝牙代理)
  37. @property (nonatomic, weak) id<ELBluetoothManagerDelegate> delegate;
  38. //Bluetooth wifi proxy(蓝牙wifi代理)
  39. @property (nonatomic, weak) id<ElBleWifiDelegate> bleWifiDelegate;
  40. //Bluetooth Broadcast Device Protocol(蓝牙广播设备协议)
  41. @property (nonatomic, weak) id<ELBleBroadcastDelegate> broadDelegate;
  42. /** 需要搜索与系统绑定的蓝牙设备 */
  43. @property (nonatomic, assign) BOOL needScanBindSysDevice;
  44. //SDK 自动重连超时 0~5秒,仅指定设备可使用此功能,其他设备可能会引起逻辑问题
  45. @property (nonatomic, assign) NSInteger reconnectionTimeout;
  46. //设置支持设备列表 - 扫描过滤
  47. - (void)setSupportDeviceCids:(NSArray<NSNumber *> *)cids;
  48. //
  49. +(__kindof ELBluetoothManager * _Nonnull)shareManager;
  50. /**
  51. Get the SDK version number
  52. 获取SDK版本号
  53. */
  54. -(NSString *)sdkVersion;
  55. //Start scanning(开始扫描)
  56. -(void)startScan;
  57. //Start scanning(开始扫描)- 过滤 cid 列表
  58. -(void)startScanFilterCids:(NSArray<NSNumber *> *)cids;
  59. -(void)startScanAllFilterCids:(NSArray<NSNumber *> *)cids;
  60. //Start scanning all (开始扫描附近所有设备)
  61. - (void)startScanAll;
  62. //Stop scanning(停止扫描)
  63. -(void)stopScan;
  64. //Connecting device(连接设备)
  65. -(void)connectPeripheral:(ELPeripheralModel *)peripheralModel;
  66. //Disconnect device(断开设备)
  67. -(void)disconnectPeripheral;
  68. - (void)readRSSI;
  69. /**
  70. Get Bluetooth information(获取蓝牙信息)
  71. @param type ELInetGetCmdType (ELInetGetCmdTypeGetHandshake除外)
  72. */
  73. -(void)getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdType)type;
  74. /**
  75. Sync the current time of phone to BLE(设置手机本地时间给蓝牙模块,只在蓝牙体脂秤等需要蓝牙模块保存历史记录时才调用)
  76. @param enable
  77. NO: In addition to the ability to turn off the time function, you can save part of the current (default)(除能,关闭时间功能,可省部分电流(默认))
  78. YES:Enable, turn on the timer function timer(使能,开启计时功能定时器)
  79. */
  80. -(void)syncBleNowDate:(BOOL)enable;
  81. ///仅WIFI秤调用,同步世界时间(0时区)到wifi-ble模块
  82. -(void)syncBleGMTNowDate:(BOOL)enable;
  83. ///同步手机本地时间给mcu,每次连接成功后会自动调用
  84. -(void)syncMCUNowDate;
  85. #pragma mark ============ 发送指令的3种方法 ==============
  86. /**
  87. Shortcut method to send A6 data to BLE(发送A6数据给BLE的快捷方法)
  88. @param data The stitched payload part(拼接好的payload部分)
  89. */
  90. -(void)sendCmdToMCUWithA6PayloadData:(NSData *)data;
  91. /**
  92. Shortcut method of sending A7 data to MCU(发送A7数据给MCU的快捷方法)
  93. @param data The stitched payload part(拼接好的payload部分)
  94. @param type Equipment type(设备类型)
  95. */
  96. -(void)sendCmdToMCUWithA7PayloadData:(NSData *)data deviceType:(ELSupportDeviceType)type;
  97. - (void)sendCmdToMCUWithA7PayloadDataNew:(NSData *)data deviceType:(ELSupportDeviceType)type;
  98. /// 直接发送A7命令,不加载在队列中
  99. -(void)immediatelySendCmdToMCUWithA7PayloadData:(NSData *)data deviceType:(ELSupportDeviceType)type;
  100. /**
  101. General method of sending data (support data transparent transmission)(发送数据通用方法(支持数据透传))
  102. @param data 数据
  103. */
  104. -(void)sendData:(NSData *)data;
  105. //恢复出厂设置
  106. - (void)setFactoryDataReset;
  107. #pragma mark ============ Please rewrite the following methods in the subclass(请在子类重写以下方法) BEGIN==============
  108. -(void)bluetoothUpdateState:(ELBluetoothState)state;
  109. -(void)bluetoothScanPeripherals:(NSArray *)peripherals;
  110. /**
  111. Callback decrypted A7 transparent data (payload part), type device type( 回调解密后的A7透传数据(payload部分),type设备类型)
  112. */
  113. -(void)bluetoothReceiveData:(NSData *)playload deviceType:(ELSupportDeviceType)type;
  114. /**
  115. 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.
  116. 特殊的A6数据,只有支持的设备才会收到,将完整A6数据(A6不加密)传给子类解析
  117. ELSupportDeviceType support:
  118. ELSupportDeviceTypeBodyFatScale
  119. ELSupportDeviceTypeSmartLock
  120. */
  121. -(void)bluetoothBackA6Data:(NSData *)data withClassId:(ELSupportDeviceType)type;
  122. /**
  123. Callback to scan special devices that can be bound, such as door locks(回调扫描到的可以绑定的特殊设备,如门锁)
  124. */
  125. -(void)bluetoothScanCanBindSpecialPeripherals:(NSArray *)peripherals;
  126. //Call back the scanned broadcast device(回调扫描到的广播设备)
  127. -(void)bluetoothScanBroadcastPeripherals:(NSArray *)peripherals;
  128. /**
  129. Callback device basic information(回调设备基本信息)
  130. @param data Device basic information payload data (length is 16 bytes)(设备基本信息payload数据(长度为16个byte))
  131. */
  132. -(void)bluetoothReceiveBasicInfoPayloadData:(NSData *)data;
  133. ///Callback transparent transmission data(回调透传数据)
  134. /// @param data Transparent data(透传数据)
  135. -(void)bluetoothReceivePassData:(NSData *)data;
  136. /** 滑板车专用,返回设备消息推送内容 */
  137. - (void)bluetoothManagerScooterMessageWithUUID:(NSString *)uuid data:(NSData *)data;
  138. /** 返回滑板车软件版本号 */
  139. - (void)bluetoothManagerScooterSoftwareRevision:(NSString *)version;
  140. //Broadcast equipment dedicated(广播设备专用)
  141. /// Broadcast device data
  142. /// @param cid cid
  143. /// @param vid vid
  144. /// @param pid pid
  145. /// @param mac mac
  146. /// @param data custom data(自定义数据)
  147. -(void)bluetoothReceiveBroadcastDataWithCid:(int)cid vid:(int)vid pid:(int)pid mac:(NSString *_Nonnull)mac data:(NSData *_Nonnull)data;
  148. #pragma mark ============ Please rewrite the following methods in the subclass(子类重写方法) END==============
  149. @end
  150. NS_ASSUME_NONNULL_END