iOS AILinkBleSDK - 蓝牙SDK
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

ELAILinkBleManager.h 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. //
  2. // ELAILinkBleManager.h
  3. //
  4. // Created by LarryZhang on 2022/8/13.
  5. // Copyright © 2022 iot_iMac. All rights reserved.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import <CoreBluetooth/CoreBluetooth.h>
  9. #import "NELBleManagerHeader.h"
  10. #import "ELSDKHeader.h"
  11. #import "AILinkBleSDK_Version.h"
  12. #import "ELAILinkBleManagerProtocol.h"
  13. #import "ELAILinkPeripheral.h"
  14. NS_ASSUME_NONNULL_BEGIN
  15. @class ELAILinkPeripheral;
  16. @class ELBleWifiDetailModel;
  17. @protocol ELAILinkBleWifiDelegate;
  18. @protocol ELAILinkBleManagerDelegate;
  19. @interface ELAILinkBleManager : NSObject
  20. //不是必须使用单例
  21. + (instancetype)sharedManager;
  22. - (NSString *)sdkVersion;
  23. + (NSString *)sdkVersion;
  24. //扫描状态
  25. @property(nonatomic, assign, readonly, getter=isScanning) BOOL scanning;
  26. //BLE设备连接状态
  27. @property(nonatomic, assign, readonly) NELBleManagerConnectState connectState;
  28. @property(nonatomic, strong, readonly) CBCentralManager *central;
  29. @property (nonatomic, weak) id<ELAILinkBleManagerDelegate> delegate DEPRECATED_MSG_ATTRIBUTE("use 'ailinkDelegate' only");
  30. @property (nonatomic, weak) id<ELAILinkBleManagerDelegate> ailinkDelegate;
  31. //Bluetooth wifi proxy(蓝牙wifi代理)
  32. @property (nonatomic, weak) id<ELAILinkBleWifiDelegate> bleWifiDelegate;
  33. //模块版本号
  34. @property (nonatomic, copy) NSString *bmVersion;
  35. @property (nonatomic, copy) NSString *bmVersionPro;
  36. //电池状态
  37. @property (nonatomic, assign) struct ELBatteryStruct battery;
  38. //单位列表
  39. @property (nonatomic, strong) NSArray<NSNumber *> *weightArray;
  40. @property (nonatomic, strong) NSArray<NSNumber *> *heightArray;
  41. @property (nonatomic, strong) NSArray<NSNumber *> *temperatureArray;
  42. @property (nonatomic, strong) NSArray<NSNumber *> *bloodPressureArray;
  43. @property (nonatomic, strong) NSArray<NSNumber *> *pressureArray;
  44. @property (nonatomic, strong) NSArray<NSNumber *> *bloodSugarUnitArray;
  45. @property (nonatomic, strong) NSArray<NSNumber *> *volumeUnitArray;
  46. //SDK 自动重连超时 0~5秒,仅指定设备可使用此功能,其他设备可能会引起逻辑问题
  47. @property (nonatomic, assign) NSInteger reconnectionTimeout;
  48. @end
  49. #pragma mark - scan
  50. @interface ELAILinkBleManager (scan)
  51. - (void)scanAll;
  52. - (void)scanFilterWithCidArray:(NSArray<NSNumber *> *)cidArray;
  53. - (void)scanFilterWithMacArray:(NSArray<NSString *> *)macArray;
  54. - (void)scanFilterWithCidArray:(NSArray<NSNumber *> *)cidArray macArray:(NSArray<NSString *> *)macArray;
  55. - (void)scanAllowDuplicatesFilterWithCidArray:(NSArray<NSNumber *> *)cidArray macArray:(NSArray<NSString *> *)macArray;
  56. // 新扫描方法
  57. - (void)scanWithServices:(NSArray<CBUUID *> *)serviceUUIDs options:(NSDictionary<NSString *, id> * _Nullable)options;
  58. - (void)setFilterCids:(NSArray<NSNumber *> *)cids;
  59. - (void)setFilterMacs:(NSArray<NSString *> *)macs;
  60. // 获取当前连接到系统的 peripheral 设备的列表(如被其它程序连接着)
  61. - (NSArray<CBPeripheral *> *)retrieveConnectedPeripherals;
  62. //NELBleManager
  63. - (void)stopScan;
  64. @end
  65. #pragma mark - connect
  66. @interface ELAILinkBleManager (connect)
  67. - (void)disconnectPeripheral;
  68. - (void)connectAILinkPeripheral:(ELAILinkPeripheral * _Nonnull)ailinkPeripheral;
  69. - (ELAILinkPeripheral * _Nullable)currentAILinkPeripheral;
  70. - (void)readRSSI;
  71. @end
  72. #pragma mark - send
  73. @interface ELAILinkBleManager (send)
  74. - (void)sendA7Payload:(NSData *)payload;
  75. - (void)sendA7PayloadNoEncryption:(NSData *)payload;
  76. - (void)sendA6Payload:(NSData *)payload;
  77. /// base method of 'sendA7Payload' & 'sendA6Payload'
  78. - (void)sendCmd:(NSData *)cmdData;
  79. //直接发送
  80. - (void)sendDirectCmd:(NSData *)cmdData;
  81. //最大发送数据长度
  82. - (NSUInteger)maximumWriteValueLength DEPRECATED_MSG_ATTRIBUTE("use 'maximumWriteValueLengthForWriteWithResponse' or 'maximumWriteValueLengthForWriteWithoutResponse' instead");
  83. //最大发送A7 payload长度
  84. - (NSUInteger)maximumWriteA7PayloadLength DEPRECATED_MSG_ATTRIBUTE("use 'maximumWriteValueLengthForWriteWithResponse' or 'maximumWriteValueLengthForWriteWithoutResponse' instead");
  85. //最大发送A6 payload长度
  86. - (NSUInteger)maximumWriteA6PayloadLength DEPRECATED_MSG_ATTRIBUTE("use 'maximumWriteValueLengthForWriteWithResponse' or 'maximumWriteValueLengthForWriteWithoutResponse' instead");
  87. //可发送的最大字节数
  88. @property(nonatomic, assign, readonly) NSUInteger maximumWriteValueLengthForWriteWithResponse;
  89. //可发送的最大字节数
  90. @property(nonatomic, assign, readonly) NSUInteger maximumWriteValueLengthForWriteWithoutResponse;
  91. //发送队列发送周期
  92. - (void)configWriteDataQueueInterval:(CGFloat)interval;
  93. - (void)configWriteCharacteristicWriteType:(CBCharacteristicWriteType)type;
  94. @end
  95. #pragma mark - Open
  96. @interface ELAILinkBleManager (Open)
  97. //解析指令 外部开放 Method
  98. - (void)processA7Data:(NSMutableData *)rawData withMac:(NSData *)mac withCid:(UInt16)cid;
  99. - (void)processA6Data:(NSMutableData *)rawData;
  100. //生成数据包 外部开放 Method
  101. - (NSData * _Nullable)makePacketA7Payload:(NSData *)payload withMac:(NSData *)mac withCid:(UInt16)cid;
  102. - (NSData * _Nullable)makePacketA6Payload:(NSData *)payload;
  103. @end
  104. #pragma mark - A6Method
  105. @interface ELAILinkBleManager (A6Method)
  106. /**
  107. Get Bluetooth information(获取蓝牙信息)
  108. @param type ELInetGetCmdType (ELInetGetCmdTypeGetHandshake除外)
  109. */
  110. - (void)getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdType)type;
  111. /**
  112. Sync the current time of phone to BLE(设置手机本地时间给蓝牙模块,只在蓝牙体脂秤等需要蓝牙模块保存历史记录时才调用)
  113. @param enable
  114. NO: In addition to the ability to turn off the time function, you can save part of the current (default)(除能,关闭时间功能,可省部分电流(默认))
  115. YES:Enable, turn on the timer function timer(使能,开启计时功能定时器)
  116. */
  117. - (void)syncBleNowDate:(BOOL)enable;
  118. ///仅WIFI秤调用,同步世界时间(0时区)到wifi-ble模块
  119. - (void)syncBleGMTNowDate:(BOOL)enable;
  120. ///同步手机本地时间给mcu,每次连接成功后会自动调用
  121. - (void)syncMCUNowDate;
  122. ///同步手机时间戳给设备 //0x45
  123. - (void)syncUnixTimestamp;
  124. ///查询mqtt链接状态 CMD=0xC5
  125. - (void)checkMqttState;
  126. #pragma mark - 发现服务
  127. - (void)discoverServiceWithUUIDString:(NSString *)UUIDString;
  128. #pragma mark - 设置已发现特征notifyValue
  129. - (void)setCharacteristicsNotifyValue:(BOOL)enabled;
  130. @end
  131. NS_ASSUME_NONNULL_END