iOS AILinkBleSDK - 蓝牙SDK
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SubBleManager.m 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // SubBleManager.m
  3. // AILinkBleSDKSourceCode
  4. //
  5. // Created by iot_user on 2020/4/7.
  6. // Copyright © 2020 IOT. All rights reserved.
  7. //
  8. #import "SubBleManager.h"
  9. @implementation SubBleManager
  10. +(instancetype)shareManager{
  11. static SubBleManager *manager = nil;
  12. static dispatch_once_t onceToken;
  13. dispatch_once(&onceToken, ^{
  14. manager = [[self alloc] init];
  15. });
  16. return manager;
  17. }
  18. #pragma mark ============ 实现父类的方法 ==============
  19. -(void)bluetoothUpdateState:(ELBluetoothState)state{
  20. if ([self.subDelegate respondsToSelector:@selector(subBluetoothUpdateState:)]) {
  21. [self.subDelegate subBluetoothUpdateState:state];
  22. }
  23. }
  24. - (void)bluetoothScanPeripherals:(NSArray *)peripherals {
  25. NSArray *device = peripherals;
  26. //筛选单种设备
  27. //这里以体脂秤为例
  28. // NSArray *device = [ELPeripheralModel getDevicesWithPeripherals:peripherals supportDeviceType:(ELSupportDeviceTypeHPLuxMeter)];
  29. // NSArray *device = [ELPeripheralModel getDevicesWithPeripherals:peripherals supportDeviceType:(ELSupportDeviceTypeBodyFatScale)];
  30. // NSArray *device = [ELPeripheralModel getDevicesWithPeripherals:peripherals supportDeviceTypes:@[@(ELSupportDeviceTypeBodyFatScale),@(ELSupportDeviceTypeBLE_WIFIScale)]];
  31. if ([self.subDelegate respondsToSelector:@selector(subBluetoothScanPeripherals:)]) {
  32. [self.subDelegate subBluetoothScanPeripherals:device];
  33. }
  34. }
  35. /**
  36. Callback decrypted A7 transparent data (payload part), type device type( 回调解密后的A7透传数据(payload部分),type设备类型)
  37. */
  38. -(void)bluetoothReceiveData:(NSData *)playload deviceType:(ELSupportDeviceType)type{
  39. if (type == ELSupportDeviceTypeBodyFatScale /*|| type == ELSupportDeviceTypeBLE_WIFIScale*/) {
  40. //根据体脂秤协议解析playload部分
  41. }
  42. NSLog(@"bluetoothReceiveData() type:%ld playload:%@", type, playload);
  43. }
  44. /**
  45. 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.
  46. 特殊的A6数据,只有支持的设备才会收到,将完整A6数据(A6不加密)传给子类解析
  47. ELSupportDeviceType support:
  48. ELSupportDeviceTypeBodyFatScale
  49. ELSupportDeviceTypeSmartLock
  50. */
  51. -(void)bluetoothBackA6Data:(NSData *)data withClassId:(ELSupportDeviceType)type{
  52. if (type == ELSupportDeviceTypeBodyFatScale /*|| type == ELSupportDeviceTypeBLE_WIFIScale*/) {
  53. //根据体脂秤协议解析data部分
  54. }
  55. }
  56. /**
  57. Callback to scan special devices that can be bound, such as door locks(回调扫描到的可以绑定的特殊设备,如门锁)
  58. */
  59. -(void)bluetoothScanCanBindSpecialPeripherals:(NSArray *)peripherals{
  60. //特殊数据:这个方法目前只有门锁会用到
  61. }
  62. /**
  63. Callback device basic information(回调设备基本信息)
  64. @param data Device basic information payload data (length is 16 bytes)(设备基本信息pabyload数据(长度为16个byte))
  65. */
  66. -(void)bluetoothReceiveBasicInfoPayloadData:(NSData *)data{
  67. //特殊数据:门锁和胎压监测会用到,需根据具体协议解析
  68. }
  69. ///Callback transparent transmission data(回调透传数据)
  70. /// @param data Transparent data(透传数据)
  71. -(void)bluetoothReceivePassData:(NSData *)data{
  72. //Parsing transparent transmission data(解析透传数据)
  73. }
  74. #pragma mark ============ 发送数据给蓝牙 ==============
  75. -(void)subBleSendA6Data:(NSData *)data{
  76. [self sendCmdToMCUWithA6PayloadData:data];
  77. }
  78. -(void)subBleSendA7Data:(NSData *)payload{
  79. [self sendCmdToMCUWithA7PayloadData:payload deviceType:(ELSupportDeviceTypeBodyFatScale)];
  80. }
  81. @end