iOS AILinkBleSDK - 蓝牙SDK
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

AilinkSuperConnectViewController.m 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. //
  2. // AilinkSuperConnectViewController.m
  3. // AILinkBleSDKSourceCode
  4. //
  5. // Created by iot_user on 2020/4/7.
  6. // Copyright © 2020 IOT. All rights reserved.
  7. //
  8. #import "AilinkSuperConnectViewController.h"
  9. #import <AILinkBleSDK/ELBluetoothManager.h>
  10. #import "Masonry.h"
  11. @interface AilinkSuperConnectViewController ()<ELBluetoothManagerDelegate>
  12. @property (nonatomic, strong) UITextView *textView;
  13. @end
  14. @implementation AilinkSuperConnectViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. self.view.backgroundColor = [UIColor whiteColor];
  18. [ELBluetoothManager shareManager].delegate = self;
  19. [[ELBluetoothManager shareManager] connectPeripheral:self.p];
  20. [self setupUIView];
  21. }
  22. -(void)viewWillDisappear:(BOOL)animated{
  23. [super viewWillDisappear:animated];
  24. [[ELBluetoothManager shareManager] disconnectPeripheral];
  25. }
  26. -(void)addLog:(NSString *)log{
  27. self.textView.text = [NSString stringWithFormat:@"%@\n%@",log,self.textView.text];
  28. }
  29. -(void)buttonAction:(UIButton *)sender{
  30. if ([ELBluetoothManager shareManager].state != ELBluetoothStateDidValidationPass) {
  31. [self addLog:@"Disconnected"];
  32. return;
  33. }
  34. [self addLog:sender.titleLabel.text];
  35. NSInteger tag = sender.tag;
  36. if (tag == 1) {
  37. //getBluetoothInfoWithELInetGetCmdType是获取设备信息的方法
  38. [[ELBluetoothManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetBMVersion)];
  39. }else if (tag == 2){
  40. [[ELBluetoothManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetC_V_P_ID)];
  41. }else if (tag == 3){
  42. [[ELBluetoothManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetName)];
  43. }else if (tag == 4){
  44. [[ELBluetoothManager shareManager] setBluetoothName:@"AILink"];
  45. }else if (tag == 5){
  46. //MARK:发送透传数据
  47. Byte b[5] = {0x0A,0x00,0x01,0x02,0xA0};
  48. NSData *data = [[NSData alloc] initWithBytes:b length:5];
  49. [self addLog:data.description];
  50. [[ELBluetoothManager shareManager] sendData:data];
  51. }
  52. }
  53. -(void)setupUIView{
  54. UIButton *button1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  55. [button1 setTitle:@"Get BM Version" forState:(UIControlStateNormal)];
  56. button1.tag = 1;
  57. button1.titleLabel.adjustsFontSizeToFitWidth = YES;
  58. button1.titleLabel.numberOfLines = 2;
  59. button1.backgroundColor = [UIColor blackColor];
  60. [button1 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  61. [self.view addSubview:button1];
  62. [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
  63. make.left.mas_equalTo(10);
  64. make.top.mas_equalTo(80);
  65. make.width.mas_equalTo(100);
  66. make.height.mas_equalTo(40);
  67. }];
  68. UIButton *button2 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  69. [button2 setTitle:@"Get C V P ID" forState:(UIControlStateNormal)];
  70. button2.tag = 2;
  71. button2.titleLabel.adjustsFontSizeToFitWidth = YES;
  72. button2.titleLabel.numberOfLines = 2;
  73. button2.backgroundColor = [UIColor blackColor];
  74. [button2 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  75. [self.view addSubview:button2];
  76. [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.left.equalTo(button1.mas_right).mas_offset(10);
  78. make.top.mas_equalTo(80);
  79. make.width.mas_equalTo(100);
  80. make.height.mas_equalTo(40);
  81. }];
  82. UIButton *button3 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  83. [button3 setTitle:@"Get Name" forState:(UIControlStateNormal)];
  84. button3.tag = 3;
  85. button3.titleLabel.adjustsFontSizeToFitWidth = YES;
  86. button3.titleLabel.numberOfLines = 2;
  87. button3.backgroundColor = [UIColor blackColor];
  88. [button3 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  89. [self.view addSubview:button3];
  90. [button3 mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.left.equalTo(button2.mas_right).mas_offset(10);
  92. make.top.mas_equalTo(80);
  93. make.width.mas_equalTo(100);
  94. make.height.mas_equalTo(40);
  95. }];
  96. //
  97. UIButton *button4 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  98. [button4 setTitle:@"Set Name" forState:(UIControlStateNormal)];
  99. button4.tag = 4;
  100. button4.titleLabel.adjustsFontSizeToFitWidth = YES;
  101. button4.titleLabel.numberOfLines = 2;
  102. button4.backgroundColor = [UIColor blackColor];
  103. [button4 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  104. [self.view addSubview:button4];
  105. [button4 mas_makeConstraints:^(MASConstraintMaker *make) {
  106. make.left.mas_equalTo(10);
  107. make.top.equalTo(button1.mas_bottom).mas_offset(10);
  108. make.width.mas_equalTo(100);
  109. make.height.mas_equalTo(40);
  110. }];
  111. //
  112. UIButton *button5 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  113. [button5 setTitle:@"Send Data" forState:(UIControlStateNormal)];
  114. button5.tag = 5;
  115. button5.titleLabel.adjustsFontSizeToFitWidth = YES;
  116. button5.titleLabel.numberOfLines = 2;
  117. button5.backgroundColor = [UIColor blackColor];
  118. [button5 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  119. [self.view addSubview:button5];
  120. [button5 mas_makeConstraints:^(MASConstraintMaker *make) {
  121. make.left.equalTo(button4.mas_right).mas_offset(10);
  122. make.top.equalTo(button1.mas_bottom).mas_offset(10);
  123. make.width.mas_equalTo(100);
  124. make.height.mas_equalTo(40);
  125. }];
  126. //
  127. self.textView = [[UITextView alloc] init];
  128. self.textView.backgroundColor = [UIColor blackColor];
  129. self.textView.text = @"Log";
  130. self.textView.textColor = [UIColor redColor];
  131. [self.view addSubview:self.textView];
  132. [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
  133. make.left.mas_equalTo(10);
  134. make.right.bottom.mas_equalTo(-10);
  135. make.height.mas_equalTo(200);
  136. }];
  137. }
  138. -(void)bluetoothManagerReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result{
  139. if (type == ELInetSetCmdTypeSetName) {
  140. if (result == ELSetBluetoothResponseTypeSuccess) {
  141. [self addLog:@"Set name Success "];
  142. }else if (result == ELSetBluetoothResponseTypeFailure){
  143. [self addLog:@"Set name failure "];
  144. }else if (result == ELSetBluetoothResponseTypeNoSupport){
  145. [self addLog:@"Set name unsupport "];
  146. }
  147. }
  148. }
  149. -(void)bluetoothManagerReceiceName:(NSString *)name{
  150. [self addLog:name];
  151. }
  152. -(void)bluetoothManagerReceiveDID:(struct ELDIDStruct)did{
  153. [self addLog:[NSString stringWithFormat:@"CID = %d,VID = %d,PID = %d",did.deviceType,did.vendorID,did.productID]];
  154. }
  155. -(void)bluetoothManagerReceiveBMVersion:(NSString *)bmVersion{
  156. [self addLog:bmVersion];
  157. }
  158. //MARK:接收透传数据(不符合AILink协议的数据,需要做透传的客户可在此根据自己的协议解析数据,透传数据不可以"A6"或"A7"开头)
  159. -(void)bluetoothManagerReceivePassData:(NSData *)data{
  160. NSLog(@"bluetoothManagerReceivePassData = %@",data.description);
  161. [self addLog:[NSString stringWithFormat:@"Penetrate:%@",data.description]];
  162. }
  163. //MARK:获取设备支持的单位
  164. -(void)bluetoothManagerBackDeviceSupportUnitWithWeight:(NSArray<NSNumber *> *)weightArray Height:(NSArray<NSNumber *> *)heightArray Temperature:(NSArray<NSNumber *> *)temperatureArray BloodPressure:(NSArray<NSNumber *> *)bloodPressureArray Pressure:(NSArray<NSNumber *> *)pressureArray{
  165. //这里要压力和温度单位
  166. //设置单位时,要设置设备支持的单位
  167. }
  168. -(void)bluetoothManagerUpdateBleState:(ELBluetoothState)state{
  169. switch (state) {
  170. case ELBluetoothStateUnavailable:
  171. {
  172. self.title = @"Please open the bluetooth";
  173. }
  174. break;
  175. case ELBluetoothStateAvailable:
  176. {
  177. self.title = @"Bluetooth is open";
  178. }
  179. break;
  180. case ELBluetoothStateScaning:
  181. {
  182. self.title = @"Scaning";
  183. }
  184. break;
  185. case ELBluetoothStateConnectFail:
  186. {
  187. self.title = @"Connect fail";
  188. }
  189. break;
  190. case ELBluetoothStateDidDisconnect:
  191. {
  192. self.title = @"Disconnected";
  193. }
  194. break;
  195. case ELBluetoothStateDidValidationPass:
  196. {
  197. self.title = @"Connected";
  198. [[ELBluetoothManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeReadDeviceSupportUnit)];
  199. }
  200. break;
  201. case ELBluetoothStateFailedValidation:
  202. {
  203. self.title = @"Illegal equipment";
  204. }
  205. break;
  206. case ELBluetoothStateWillConnect:
  207. self.title = @"Connecting";
  208. break;
  209. default:
  210. break;
  211. }
  212. }
  213. -(void)dealloc{
  214. }
  215. @end