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.

BloodConnectViewController.m 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. //
  2. // BloodConnectViewController.m
  3. // AILinkBleSDKSourceCode
  4. //
  5. // Created by iot_user on 2020/4/7.
  6. // Copyright © 2020 IOT. All rights reserved.
  7. //
  8. #import "BloodConnectViewController.h"
  9. #import "Masonry.h"
  10. #import <AILinkBleSDK/ELBloodBleManager.h>
  11. @interface BloodConnectViewController ()<ELBluetoothManagerDelegate,ELBloodBleManagerDelegate>
  12. @property (nonatomic, strong) UITextView *textView;
  13. @end
  14. @implementation BloodConnectViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. self.view.backgroundColor = [UIColor whiteColor];
  18. [ELBloodBleManager shareManager].bloodDelegate = self;
  19. [ELBloodBleManager shareManager].delegate =self;
  20. [[ELBloodBleManager shareManager] connectPeripheral:self.p];
  21. [self setupUIView];
  22. }
  23. -(void)viewWillDisappear:(BOOL)animated{
  24. [super viewWillDisappear:animated];
  25. [[ELBloodBleManager shareManager] disconnectPeripheral];
  26. }
  27. -(void)addLog:(NSString *)log{
  28. self.textView.text = [NSString stringWithFormat:@"%@\n%@",log,self.textView.text];
  29. }
  30. -(void)buttonAction:(UIButton *)sender{
  31. if ([ELBloodBleManager shareManager].state != ELBluetoothStateDidValidationPass) {
  32. [self addLog:@"Disconnected"];
  33. return;
  34. }
  35. [self addLog:sender.titleLabel.text];
  36. NSInteger tag = sender.tag;
  37. if (tag == 1) {
  38. //getBluetoothInfoWithELInetGetCmdType是获取设备信息的方法
  39. [[ELBloodBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetBMVersion)];
  40. }else if (tag == 2){
  41. [[ELBloodBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetC_V_P_ID)];
  42. }else if (tag == 3){
  43. [[ELBloodBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetName)];
  44. }else if (tag == 4){
  45. [[ELBloodBleManager shareManager] setBluetoothName:@"AILink"];
  46. }else if (tag == 5){
  47. [[ELBloodBleManager shareManager] sendInteractiveInstructions:(ELBloodInteractionTypeStartTest)];
  48. }else if (tag == 6){
  49. [[ELBloodBleManager shareManager] sendInteractiveInstructions:(ELBloodInteractionTypeStopTest)];
  50. }else if (tag == 7){
  51. [[ELBloodBleManager shareManager] changeUnit:(ELDeviceBloodPressureUnit_mmhg)];
  52. }else if (tag == 8){
  53. [[ELBloodBleManager shareManager] sendSwitchVoice:(ELBloodBleSwitchVoiceTypeOff)];
  54. }else if (tag == 9){
  55. [[ELBloodBleManager shareManager] sendSwitchVoice:(ELBloodBleSwitchVoiceTypeOn)];
  56. }
  57. }
  58. -(void)setupUIView{
  59. UIButton *button1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  60. [button1 setTitle:@"Get BM Version" forState:(UIControlStateNormal)];
  61. button1.tag = 1;
  62. button1.titleLabel.adjustsFontSizeToFitWidth = YES;
  63. button1.titleLabel.numberOfLines = 2;
  64. button1.backgroundColor = [UIColor blackColor];
  65. [button1 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  66. [self.view addSubview:button1];
  67. [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.left.mas_equalTo(10);
  69. make.top.mas_equalTo(80);
  70. make.width.mas_equalTo(100);
  71. make.height.mas_equalTo(40);
  72. }];
  73. UIButton *button2 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  74. [button2 setTitle:@"Get C V P ID" forState:(UIControlStateNormal)];
  75. button2.tag = 2;
  76. button2.titleLabel.adjustsFontSizeToFitWidth = YES;
  77. button2.titleLabel.numberOfLines = 2;
  78. button2.backgroundColor = [UIColor blackColor];
  79. [button2 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  80. [self.view addSubview:button2];
  81. [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.left.equalTo(button1.mas_right).mas_offset(10);
  83. make.top.mas_equalTo(80);
  84. make.width.mas_equalTo(100);
  85. make.height.mas_equalTo(40);
  86. }];
  87. UIButton *button3 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  88. [button3 setTitle:@"Get Name" forState:(UIControlStateNormal)];
  89. button3.tag = 3;
  90. button3.titleLabel.adjustsFontSizeToFitWidth = YES;
  91. button3.titleLabel.numberOfLines = 2;
  92. button3.backgroundColor = [UIColor blackColor];
  93. [button3 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  94. [self.view addSubview:button3];
  95. [button3 mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.left.equalTo(button2.mas_right).mas_offset(10);
  97. make.top.mas_equalTo(80);
  98. make.width.mas_equalTo(100);
  99. make.height.mas_equalTo(40);
  100. }];
  101. //
  102. UIButton *button4 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  103. [button4 setTitle:@"Set Name" forState:(UIControlStateNormal)];
  104. button4.tag = 4;
  105. button4.titleLabel.adjustsFontSizeToFitWidth = YES;
  106. button4.titleLabel.numberOfLines = 2;
  107. button4.backgroundColor = [UIColor blackColor];
  108. [button4 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  109. [self.view addSubview:button4];
  110. [button4 mas_makeConstraints:^(MASConstraintMaker *make) {
  111. make.left.mas_equalTo(10);
  112. make.top.equalTo(button1.mas_bottom).mas_offset(10);
  113. make.width.mas_equalTo(100);
  114. make.height.mas_equalTo(40);
  115. }];
  116. //
  117. UIButton *button5 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  118. [button5 setTitle:@"Start Test" forState:(UIControlStateNormal)];
  119. button5.tag = 5;
  120. button5.titleLabel.adjustsFontSizeToFitWidth = YES;
  121. button5.titleLabel.numberOfLines = 2;
  122. button5.backgroundColor = [UIColor blackColor];
  123. [button5 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  124. [self.view addSubview:button5];
  125. [button5 mas_makeConstraints:^(MASConstraintMaker *make) {
  126. make.left.equalTo(button4.mas_right).mas_offset(10);
  127. make.top.equalTo(button1.mas_bottom).mas_offset(10);
  128. make.width.mas_equalTo(100);
  129. make.height.mas_equalTo(40);
  130. }];
  131. //
  132. //
  133. UIButton *button6 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  134. [button6 setTitle:@"Stop Test" forState:(UIControlStateNormal)];
  135. button6.tag = 6;
  136. button6.titleLabel.adjustsFontSizeToFitWidth = YES;
  137. button6.titleLabel.numberOfLines = 2;
  138. button6.backgroundColor = [UIColor blackColor];
  139. [button6 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  140. [self.view addSubview:button6];
  141. [button6 mas_makeConstraints:^(MASConstraintMaker *make) {
  142. make.left.equalTo(button5.mas_right).mas_offset(10);
  143. make.top.equalTo(button1.mas_bottom).mas_offset(10);
  144. make.width.mas_equalTo(100);
  145. make.height.mas_equalTo(40);
  146. }];
  147. //
  148. UIButton *button7 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  149. [button7 setTitle:@"Change Unit" forState:(UIControlStateNormal)];
  150. button7.tag = 7;
  151. button7.titleLabel.adjustsFontSizeToFitWidth = YES;
  152. button7.titleLabel.numberOfLines = 2;
  153. button7.backgroundColor = [UIColor blackColor];
  154. [button7 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  155. [self.view addSubview:button7];
  156. [button7 mas_makeConstraints:^(MASConstraintMaker *make) {
  157. make.left.mas_equalTo(10);
  158. make.top.equalTo(button4.mas_bottom).mas_offset(10);
  159. make.width.mas_equalTo(100);
  160. make.height.mas_equalTo(40);
  161. }];
  162. UIButton *button8 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  163. [button8 setTitle:@"Close Voice" forState:(UIControlStateNormal)];
  164. button8.tag = 8;
  165. button8.titleLabel.adjustsFontSizeToFitWidth = YES;
  166. button8.titleLabel.numberOfLines = 2;
  167. button8.backgroundColor = [UIColor blackColor];
  168. [button8 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  169. [self.view addSubview:button8];
  170. [button8 mas_makeConstraints:^(MASConstraintMaker *make) {
  171. make.left.mas_equalTo(10);
  172. make.top.equalTo(button4.mas_bottom).mas_offset(10);
  173. make.width.mas_equalTo(100);
  174. make.height.mas_equalTo(40);
  175. }];
  176. UIButton *button9 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  177. [button9 setTitle:@"Open Voice" forState:(UIControlStateNormal)];
  178. button9.tag = 9;
  179. button9.titleLabel.adjustsFontSizeToFitWidth = YES;
  180. button9.titleLabel.numberOfLines = 2;
  181. button9.backgroundColor = [UIColor blackColor];
  182. [button9 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  183. [self.view addSubview:button9];
  184. [button9 mas_makeConstraints:^(MASConstraintMaker *make) {
  185. make.left.equalTo(button8.mas_right).mas_offset(10);
  186. make.top.equalTo(button4.mas_bottom).mas_offset(10);
  187. make.width.mas_equalTo(100);
  188. make.height.mas_equalTo(40);
  189. }];
  190. //
  191. self.textView = [[UITextView alloc] init];
  192. self.textView.backgroundColor = [UIColor blackColor];
  193. self.textView.text = @"Log";
  194. self.textView.textColor = [UIColor redColor];
  195. [self.view addSubview:self.textView];
  196. [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
  197. make.left.mas_equalTo(10);
  198. make.right.bottom.mas_equalTo(-10);
  199. make.height.mas_equalTo(200);
  200. }];
  201. }
  202. -(void)bluetoothManagerReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result{
  203. if (type == ELInetSetCmdTypeSetName) {
  204. if (result == ELSetBluetoothResponseTypeSuccess) {
  205. [self addLog:@"Set name Success "];
  206. }else if (result == ELSetBluetoothResponseTypeFailure){
  207. [self addLog:@"Set name failure "];
  208. }else if (result == ELSetBluetoothResponseTypeNoSupport){
  209. [self addLog:@"Set name unsupport "];
  210. }
  211. }
  212. }
  213. -(void)bluetoothManagerReceiceName:(NSString *)name{
  214. [self addLog:name];
  215. }
  216. -(void)bluetoothManagerReceiveDID:(struct ELDIDStruct)did{
  217. [self addLog:[NSString stringWithFormat:@"CID = %lu,VID = %d,PID = %d",(unsigned long)did.deviceType,did.vendorID,did.productID]];
  218. }
  219. -(void)bluetoothManagerReceiveBMVersion:(NSString *)bmVersion{
  220. [self addLog:bmVersion];
  221. }
  222. //MARK:获取设备支持的单位
  223. -(void)bluetoothManagerBackDeviceSupportUnitWithWeight:(NSArray<NSNumber *> *)weightArray Height:(NSArray<NSNumber *> *)heightArray Temperature:(NSArray<NSNumber *> *)temperatureArray BloodPressure:(NSArray<NSNumber *> *)bloodPressureArray Pressure:(NSArray<NSNumber *> *)pressureArray{
  224. //这里要血压单位
  225. //设置单位时,要设置设备支持的单位
  226. }
  227. -(void)bloodBleManagerReceiceTestData:(ELBloodBleDataModel *)model type:(ELBloodBleDataModelType)type{
  228. [self addLog:[NSString stringWithFormat:@"dia = %@--sys=%@ unit = %zd point = %d",model.dia,model.sys,model.unit,model.point]];
  229. }
  230. -(void)bloodBleManagerReceiveSetSwitchVoiceOperationType:(ELBloodBleSwitchVoiceType)type result:(ELSetBluetoothResponseType)result{
  231. if (type == ELBloodBleSwitchVoiceTypeOff) {
  232. [self addLog:[NSString stringWithFormat:@"close voice result = %ld",result]];
  233. }else{
  234. [self addLog:[NSString stringWithFormat:@"open voice result = %ld",result]];
  235. }
  236. }
  237. -(void)bloodBleManagerReceiveSetUnitResult:(ELSetBluetoothResponseType)type{
  238. [self addLog:[NSString stringWithFormat:@"change unit result = %ld",type]];
  239. }
  240. -(void)bloodBleManagerReceiveFailCode:(ELBloodFailCode)code{
  241. [self addLog:[NSString stringWithFormat:@"error code = %ld",code]];
  242. }
  243. -(void)bloodBleManagerUpdateBleState:(ELBluetoothState)state{
  244. switch (state) {
  245. case ELBluetoothStateUnavailable:
  246. {
  247. self.title = @"Please open the bluetooth";
  248. }
  249. break;
  250. case ELBluetoothStateAvailable:
  251. {
  252. self.title = @"Bluetooth is open";
  253. }
  254. break;
  255. case ELBluetoothStateScaning:
  256. {
  257. self.title = @"Scaning";
  258. }
  259. break;
  260. case ELBluetoothStateConnectFail:
  261. {
  262. self.title = @"Connect fail";
  263. }
  264. break;
  265. case ELBluetoothStateDidDisconnect:
  266. {
  267. self.title = @"Disconnected";
  268. }
  269. break;
  270. case ELBluetoothStateDidValidationPass:
  271. {
  272. self.title = @"Connected";
  273. [[ELBloodBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeReadDeviceSupportUnit)];
  274. }
  275. break;
  276. case ELBluetoothStateFailedValidation:
  277. {
  278. self.title = @"Illegal equipment";
  279. }
  280. break;
  281. case ELBluetoothStateWillConnect:
  282. self.title = @"Connecting";
  283. break;
  284. default:
  285. break;
  286. }
  287. }
  288. -(void)dealloc{
  289. }
  290. @end