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ů.

ELWIFIBloodPressureVC.m 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. //
  2. // ELWIFIBloodPressureVC.m
  3. // AILinkBleSDK_Example
  4. //
  5. // Created by LarryZhang on 2023/10/6.
  6. // Copyright © 2023 zhengzida. All rights reserved.
  7. //
  8. #import "ELWIFIBloodPressureVC.h"
  9. #import <AILinkBleSDK/ELAILinkBleManager.h>
  10. #import <AILinkBleSDK/ELBluetoothManager+BleWifi.h>
  11. #import <AILinkBleSDK/ElBloodBleWifiManager.h>
  12. #import <AILinkBleSDK/ELbloodPresureBleWifiDataModel.h>
  13. #import "ELBfsWifiConnectTableViewCell.h"
  14. @interface ELWIFIBloodPressureVC () <ELBluetoothManagerDelegate, ElBleWifiDelegate, ELBloodBleWifiManagerDelegate, UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource>
  15. @property (weak, nonatomic) IBOutlet UITextField *urlTexField;
  16. @property (weak, nonatomic) IBOutlet UITextField *portTexField;
  17. @property (weak, nonatomic) IBOutlet UITextField *pathTexField;
  18. @property (weak, nonatomic) IBOutlet UILabel *bleStatusLabel;
  19. @property (weak, nonatomic) IBOutlet UITextView *logTextView;
  20. @property (weak, nonatomic) IBOutlet UITableView *tableView;
  21. @property (nonatomic, strong) NSMutableArray<ELBleWifiDetailModel *> *dataSource;
  22. @end
  23. @implementation ELWIFIBloodPressureVC
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. // Do any additional setup after loading the view from its nib.
  27. [ElBloodBleWifiManager shareManager].delegate = self;
  28. [ElBloodBleWifiManager shareManager].bleWifiDelegate = self;
  29. [ElBloodBleWifiManager shareManager].bloodDelegate = self;
  30. [[ElBloodBleWifiManager shareManager] startScanFilterCids:@[@(ELSupportDeviceTypeBLE_WIFIBlood)]];
  31. NSString *log = @"开始扫描";
  32. [self addLog:log];
  33. self.urlTexField.text = self.defaultURL;//@"iot.elink.com";
  34. self.portTexField.text = self.defaultPort;//@"80";
  35. self.pathTexField.text = self.defaultPath;//@"";
  36. self.dataSource = [NSMutableArray array];
  37. }
  38. -(void)viewDidDisappear:(BOOL)animated{
  39. [super viewDidDisappear:animated];
  40. [[ElBloodBleWifiManager shareManager] stopScan];
  41. [[ElBloodBleWifiManager shareManager] disconnectPeripheral];
  42. [ElBloodBleWifiManager shareManager].delegate = nil;
  43. [ElBloodBleWifiManager shareManager].bleWifiDelegate = nil;
  44. [ElBloodBleWifiManager shareManager].bloodDelegate = nil;
  45. }
  46. #pragma mark - Action
  47. - (IBAction)requestWifiNameAction:(id)sender {
  48. [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiName];
  49. NSString *log = @"获取当前 wifi 名称";
  50. [self addLog:log];
  51. }
  52. - (IBAction)requestDeviceStatusAcion:(id)sender {
  53. //获取蓝牙和WiFi连接状态
  54. [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetConnectState)];
  55. NSString *log = [NSString stringWithFormat:@"获取蓝牙和WiFi连接状态"];
  56. [self addLog:log];
  57. }
  58. - (IBAction)requestWifiListAction:(id)sender {
  59. [self.dataSource removeAllObjects];
  60. [self.tableView reloadData];
  61. [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetNearbyWifi];
  62. NSString *log = @"获取 附近的 WIFI 列表";
  63. [self addLog:log];
  64. }
  65. - (IBAction)setupServerInfoAcion:(id)sender {
  66. NSString *url = self.urlTexField.text;
  67. NSString *port = self.portTexField.text;
  68. NSString *path = self.pathTexField.text;
  69. self.defaultURL = url;
  70. self.defaultPort = port;
  71. self.defaultPath = path;
  72. [[ElBloodBleWifiManager shareManager] setDevAccessIpAddress:url portNumber:port.intValue path:path];
  73. NSString *log = @"设置 服务器信息";
  74. [self addLog:log];
  75. }
  76. - (IBAction)requestServerInfoAcion:(id)sender {
  77. [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetURL];
  78. [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetPort];
  79. [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetPathAddress];
  80. NSString *log = @"获取 服务器信息";
  81. [self addLog:log];
  82. }
  83. - (IBAction)requestDeviceIdAcion:(id)sender {
  84. //获取wifi设备的SN号,即设备id
  85. [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetSNNumber];
  86. NSString *log = @"获取 设备ID";
  87. [self addLog:log];
  88. }
  89. - (IBAction)switchUintAction:(id)sender {
  90. static BOOL value = YES;
  91. if (value) {
  92. [[ElBloodBleWifiManager shareManager] changeUnit:ELDeviceBloodPressureUnit_mmhg];
  93. NSString *log = @"设置单位 mmhg";
  94. [self addLog:log];
  95. } else {
  96. [[ElBloodBleWifiManager shareManager] changeUnit:ELDeviceBloodPressureUnit_kPa];
  97. NSString *log = @"设置单位 kPa";
  98. [self addLog:log];
  99. }
  100. value = !value;
  101. }
  102. - (IBAction)switchSpeechAtion:(id)sender {
  103. static BOOL value = YES;
  104. if (value) {
  105. [[ElBloodBleWifiManager shareManager] sendSwitchVoice:ELBloodBleSwitchVoiceTypeOn];
  106. NSString *log = @"打开 语音";
  107. [self addLog:log];
  108. } else {
  109. [[ElBloodBleWifiManager shareManager] sendSwitchVoice:ELBloodBleSwitchVoiceTypeOff];
  110. NSString *log = @"关闭 语音";
  111. [self addLog:log];
  112. }
  113. value = !value;
  114. }
  115. - (IBAction)startMeasureAction:(id)sender {
  116. [[ElBloodBleWifiManager shareManager] sendInteractiveInstructions:ELBloodInteractionTypeStartTest];
  117. NSString *log = @"开始 测量";
  118. [self addLog:log];
  119. }
  120. - (IBAction)stopMeasureAction:(id)sender {
  121. [[ElBloodBleWifiManager shareManager] sendInteractiveInstructions:ELBloodInteractionTypeStopTest];
  122. NSString *log = @"停止 测量";
  123. [self addLog:log];
  124. }
  125. - (IBAction)restoreFactoryAction:(id)sender {
  126. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"恢复出厂设置" message:@"确认要恢复出厂设置吗?" preferredStyle:UIAlertControllerStyleAlert];
  127. UIAlertAction *conform = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  128. NSLog(@"点击了确认按钮");
  129. [[ElBloodBleWifiManager shareManager] setFactoryDataReset];
  130. NSString *log = @"恢复出厂设置";
  131. [self addLog:log];
  132. }];
  133. UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  134. NSLog(@"点击了取消按钮");
  135. }];
  136. [alert addAction:conform];
  137. [alert addAction:cancel];
  138. [self presentViewController:alert animated:YES completion:nil];
  139. }
  140. - (IBAction)clearAction:(id)sender {
  141. self.logTextView.text = @"";
  142. }
  143. - (IBAction)shareLogAction:(id)sender {
  144. }
  145. #pragma mark -
  146. - (NSString *)defaultURL {
  147. return [[NSUserDefaults standardUserDefaults] stringForKey:@"defaultURL"];
  148. }
  149. - (void)setDefaultURL:(NSString *)defautlURL {
  150. [[NSUserDefaults standardUserDefaults] setObject:defautlURL forKey:@"defaultURL"];
  151. [[NSUserDefaults standardUserDefaults] synchronize];
  152. }
  153. - (NSString *)defaultPort {
  154. return [[NSUserDefaults standardUserDefaults] stringForKey:@"defaultPort"];
  155. }
  156. - (void)setDefaultPort:(NSString *)defaultPort {
  157. [[NSUserDefaults standardUserDefaults] setObject:defaultPort forKey:@"defaultPort"];
  158. [[NSUserDefaults standardUserDefaults] synchronize];
  159. }
  160. - (NSString *)defaultPath {
  161. return [[NSUserDefaults standardUserDefaults] stringForKey:@"defaultPath"];
  162. }
  163. - (void)setDefaultPath:(NSString *)defaultPath {
  164. [[NSUserDefaults standardUserDefaults] setObject:defaultPath forKey:@"defaultPath"];
  165. [[NSUserDefaults standardUserDefaults] synchronize];
  166. }
  167. #pragma mark - textField Delegate
  168. - (void)textFieldDidEndEditing:(UITextField *)textField {
  169. if (textField.tag == 119) {
  170. NSLog(@"%@",textField.text);
  171. //MARK:7.再发送配置wifi的密码的指令
  172. [[ElBloodBleWifiManager shareManager] bleWifiSetWifiPwd:textField.text];
  173. }
  174. }
  175. #pragma mark - tableView Delegate And DataSource
  176. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  177. return 1;
  178. }
  179. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  180. return self.dataSource.count;
  181. }
  182. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  183. return 0.f;
  184. }
  185. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  186. return nil;
  187. }
  188. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  189. static NSString *cellId = @"ELBfsWifiConnectTableViewCell";
  190. ELBfsWifiConnectTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
  191. if (!cell) {
  192. cell = [[ELBfsWifiConnectTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
  193. }
  194. ELBleWifiDetailModel *model = self.dataSource[indexPath.row];
  195. cell.wifiName = model.wifiName;
  196. if (model.wifiState == ELBleWifiUseStateConnected) {
  197. cell.isLink = YES;
  198. } else {
  199. cell.isLink = NO;
  200. }
  201. return cell;
  202. }
  203. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  204. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  205. ELBleWifiDetailModel *model = self.dataSource[indexPath.row];
  206. //MARK:5.先发送配置wifi的mac地址的指令
  207. [[ElBloodBleWifiManager shareManager] bleWifiSetConnectWifiMac:model.macData];
  208. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"请输入wifi密码" message:model.wifiName preferredStyle:UIAlertControllerStyleAlert];
  209. UIAlertAction *conform = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  210. NSLog(@"点击了确认按钮");
  211. }];
  212. UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  213. NSLog(@"点击了取消按钮");
  214. }];
  215. //MARK:6.输入wifi密码
  216. [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  217. textField.placeholder = @"密码";
  218. textField.delegate = self;
  219. textField.tag = 119;
  220. }];
  221. [alert addAction:conform];
  222. [alert addAction:cancel];
  223. [self presentViewController:alert animated:YES completion:nil];
  224. }
  225. #pragma mark - ELBluetoothManagerDelegate
  226. /**
  227. Callback Bluetooth status(回调蓝牙状态)
  228. @param state Bluetooth status(蓝牙状态)
  229. */
  230. -(void)bloodBleManagerUpdateBleState:(ELBluetoothState)state {
  231. NSLog(@"## bluetoothManagerUpdateBleState = %ld", state);
  232. if (state == ELBluetoothStateScaning) {
  233. self.bleStatusLabel.text = @"正在连接...";
  234. // NSString *log = @"正在连接...";
  235. // [self addLog:log];
  236. } else if (state == ELBluetoothStateDidValidationPass) {
  237. self.bleStatusLabel.text = [@"连接成功 " stringByAppendingString:self.per.macAddressString];
  238. NSString *log = [@"连接成功 " stringByAppendingString:self.per.macAddressString];
  239. [self addLog:log];
  240. // //获取蓝牙和WiFi连接状态
  241. // [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetConnectState)];
  242. // log = [NSString stringWithFormat:@"获取蓝牙和WiFi连接状态"];
  243. // [self addLog:log];
  244. } else if (state == ELBluetoothStateDidDisconnect) {
  245. self.bleStatusLabel.text = @"连接已断开";
  246. NSString *log = @"连接已断开";
  247. [self addLog:log];
  248. } else {
  249. // self.bleStatusLabel.text = @"";
  250. }
  251. }
  252. /**
  253. Callback scanned device(回调扫描到的设备)
  254. @param devices 设备
  255. */
  256. - (void)bloodBleManagerScanDevices:(NSArray<ELPeripheralModel *> *_Nullable)devices {
  257. NSLog(@"## bloodBleManagerScanDevices = %@", devices);
  258. for (int i = 0; i < devices.count; i++) {
  259. ELPeripheralModel *device = devices[i];
  260. if ([device.macAddress isEqualToString:self.per.macAddressString]) {
  261. [[ElBloodBleWifiManager shareManager] stopScan];
  262. [[ElBloodBleWifiManager shareManager] connectPeripheral:device];
  263. return;
  264. }
  265. }
  266. }
  267. #pragma mark - ElBleWifiDelegate
  268. /**
  269. Callback Wifi details(回调Wifi详情)
  270. @param model 模型
  271. */
  272. - (void)bleWifiReceiveWifiDetailModel:(ELBleWifiDetailModel *)model {
  273. NSLog(@"## bleWifiReceiveWifiDetailModel");
  274. // [self addLog:[NSString stringWithFormat:@"wifi type---%lu name---%@ link state--%zd",(unsigned long)model.wifiState,model.wifiName,model.wifiState]];
  275. // MARK:3.WiFi配置得到Wifi列表
  276. if (model.wifiName.length > 0) {
  277. [self.dataSource addObject:model];
  278. }
  279. [self.tableView reloadData];
  280. }
  281. /**
  282. Scan nearby wifi results(扫描附近wifi结果)
  283. @param count Number of nearby wifi(附近wifi数量)
  284. */
  285. - (void)bleWifiReceiveScanedWifiCount:(int)count {
  286. NSLog(@"## bleWifiReceiveScanedWifiCount() count:%@", @(count));
  287. //MARK:4.WiFi配置得到一个附近wifi的列表,点击选择一个wifi,进行配置
  288. [self.tableView reloadData];
  289. }
  290. /**
  291. Callback Wifi MAC address(回调Wifi MAC地址)
  292. @param macData mac
  293. */
  294. - (void)bleWifiReceiveWifiMacData:(NSData *_Nullable)macData {
  295. NSLog(@"## bleWifiReceiveWifiMacData");
  296. }
  297. /**
  298. Callback WIFI password(回调WIFI密码)
  299. @param pwd password(密码)
  300. */
  301. - (void)bleWifiReceiveWifiPwd:(NSString *_Nonnull)pwd {
  302. NSLog(@"## bleWifiReceiveWifiPwd");
  303. }
  304. /**
  305. Get DTIM interval (unit: ms)(获取DTIM间隔(单位:ms))
  306. @param interval Interval (unit: ms)(间隔(单位:ms))
  307. */
  308. - (void)bleWifiReceiveWifiDTIMInterval:(NSInteger)interval {
  309. NSLog(@"## bleWifiReceiveWifiDTIMInterval");
  310. }
  311. /**
  312. Returns the visited URL(返回访问的url)
  313. @param url url
  314. */
  315. - (void)bleWifiReceiveWifiAccessURL:(NSString *)url {
  316. NSLog(@"## bleWifiReceiveWifiAccessURL() url:%@", url);
  317. NSString *log = [NSString stringWithFormat:@"url:%@", url];
  318. [self addLog:log];
  319. }
  320. /**
  321. Call back wifi port number(回调wifi的端口号)
  322. @param port 端口号
  323. */
  324. - (void)bleWifiReceiveWifiPort:(int)port {
  325. NSLog(@"## bleWifiReceiveWifiPort() port:%@", @(port));
  326. NSString *log = [NSString stringWithFormat:@"port:%@", @(port)];
  327. [self addLog:log];
  328. }
  329. //Returns the visited path(返回访问的path)
  330. - (void)bleWifiReceiveWifiPath:(NSString *)path {
  331. NSLog(@"## bleWifiReceiveWifiPath() path:%@", path);
  332. NSString *log = [NSString stringWithFormat:@"path:%@", path];
  333. [self addLog:log];
  334. }
  335. /**
  336. Set or query the callback of the instruction execution result(设置指令蓝牙WIFI响应回调方法)
  337. 只支持蓝牙Wifi部分枚举
  338. @param type Type of setting (设置的类型)
  339. @param result Set result(设置的结果)
  340. */
  341. - (void)bleWifiReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result {
  342. NSLog(@"## bleWifiReceiceResponseType");
  343. if (result == ELSetBluetoothResponseTypeSuccess) {
  344. //设置WiFi结果
  345. if (type == ELInetSetCmdTypeBleWifiSetWifiMac) {
  346. } else if (type == ELInetSetCmdTypeBleWifiSetWifiPwd){
  347. //MARK:8.然后发起连接Wifi
  348. [[ElBloodBleWifiManager shareManager] bleWifiSetupWifiConnect:YES];
  349. } else if (type == ELInetSetCmdTypeBleWifiSetConnectWifi){
  350. //获取连接状态,更新Wi-Fi列表
  351. // [self.dataSource removeAllObjects];
  352. // [self.tableView reloadData];
  353. // [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetNearbyWifi];
  354. }
  355. } else {
  356. //TODO:Wifi配置过程中失败的情况自行处理
  357. }
  358. }
  359. /**
  360. 获取会话码(deviceId)
  361. @param code (deviceId) deviceId(0 means no:为0时表示不存在)
  362. */
  363. - (void)bleWifiReceiveWifiSNCode:(int)code {
  364. NSLog(@"## bleWifiReceiveWifiSNCode() code:%@", @(code));
  365. if (code == 0) {
  366. //失败
  367. }
  368. NSString *log = [NSString stringWithFormat:@"会话码(deviceId): %@", @(code)];
  369. [self addLog:log];
  370. }
  371. /** 返回wifi名称 */
  372. - (void)bleWifiName:(NSString *)wifiName {
  373. NSLog(@"## bleWifiName() wifi名称: %@", wifiName);
  374. NSString *log = [NSString stringWithFormat:@"wifi名称: %@", wifiName];
  375. [self addLog:log];
  376. }
  377. //- (void)bluetoothManagerReceiveMCUConnectedState:(struct ELMCUStateStruct)stateStrct {
  378. // NSLog(@"## bluetoothManagerReceiveMCUConnectedState");
  379. // BleWiFiConnectState wifiState = stateStrct.wifiState;
  380. //
  381. //// //请求会话码
  382. //// [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetSNNumber];
  383. // //MARK:1.WiFi配置提示用户配网
  384. // //TODO:注意:wifi配置过程必须保持蓝牙与设备的连接
  385. // if (wifiState == BleWiFiConnectStateNoWiFi) {
  386. // //1.如果没有配网,则提示用户去配网
  387. // //MARK:2.WiFi配置先获取wifi列表
  388. // [self.dataSource removeAllObjects];
  389. // [self.tableView reloadData];
  390. // [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetNearbyWifi];
  391. // NSString *log = @"获取附近 wifi 列表";
  392. // [self addLog:log];
  393. // } else if (wifiState == BleWiFiConnectStateSuccess) {
  394. // [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiName];
  395. //
  396. // NSString *log = @"获取当前 wifi 名称";
  397. // [self addLog:log];
  398. // } else {
  399. //// //MARK:2.没网也可以获取Wi-Fi列表,如果需要更新Wi-Fi的话
  400. //// [self.dataSource removeAllObjects];
  401. //// [self.tableView reloadData];
  402. //// [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetNearbyWifi];
  403. // }
  404. //
  405. // ///MARK:9.wifi配置结果
  406. // //wifi相关的其他指令和数据接收,请查看ELBluetoothManager.h文件
  407. // if (stateStrct.wifiState == BleWiFiConnectStateSuccess) {
  408. // //成功
  409. // //MARK:10.获取wifi设备的SN号,即设备id
  410. // [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetSNNumber];
  411. // }
  412. //}
  413. -(void)bluetoothManagerReceiveWMState:(ELWMStateStruct)stateStrct {
  414. NSString *bleString = @"0_无连接";
  415. if (stateStrct.bleState == WMBleStateConnected) {
  416. bleString = @"1_已连接";
  417. } else if (stateStrct.bleState == WMBleStatePaired) {
  418. bleString = @"2_配对完成";
  419. }
  420. NSString *wifiString = @"0_未配置AP";
  421. if (stateStrct.wifiState == WMWiFiStateConnectAPFail) {
  422. wifiString = @"1_连接AP失败";
  423. } else if (stateStrct.wifiState == WMWiFiStateConnectServerFail) {
  424. wifiString = @"2_与服务器通讯失败";
  425. } else if (stateStrct.wifiState == WMWiFiStateConnectedAP) {
  426. wifiString = @"3_成功连接上AP";
  427. } else if (stateStrct.wifiState == WMWiFiStateConnectingAP) {
  428. wifiString = @"4_正在连接AP";
  429. }
  430. NSString *workString = @"0_唤醒";
  431. if (stateStrct.workState == WMWorkStateSleep) {
  432. workString = @"1_进入休眠";
  433. } else if (stateStrct.workState == WMWorkStateReady) {
  434. workString = @"2_模块准备就绪";
  435. }
  436. NSString *errorString = @"0_未知原因";
  437. if (stateStrct.failCode == WMWorkStateFailCodeAPSignalBad) {
  438. errorString = @"1_AP信号差";
  439. } else if (stateStrct.failCode == WMWorkStateFailCodeWrongPassword) {
  440. errorString = @"2_密码错误";
  441. } else if (stateStrct.failCode == WMWorkStateFailCodeNoIP) {
  442. errorString = @"3_获取不到IP";
  443. } else {
  444. errorString = @"";
  445. }
  446. NSLog(@"## bluetoothManagerReceiveMCUConnectedState()模块状态 蓝牙状态: %@, wifi状态: %@, 工作状态: %@ 失败原因: %@", bleString, wifiString, workString, errorString);
  447. if (errorString.length > 0) {
  448. NSString *log = [NSString stringWithFormat:@"模块状态 蓝牙状态: %@, wifi状态: %@, 工作状态: %@ 失败原因: %@", bleString, wifiString, workString, errorString];
  449. [self addLog:log];
  450. } else {
  451. NSString *log = [NSString stringWithFormat:@"模块状态\n 蓝牙状态: %@,\n wifi状态: %@,\n 工作状态: %@", bleString, wifiString, workString];
  452. [self addLog:log];
  453. }
  454. }
  455. //-(void)bluetoothManagerReceiveWMStateFailCode:(WMWorkStateFailCode)failCode {
  456. // NSLog(@"## bluetoothManagerReceiveMCUConnectedState");
  457. //
  458. //}
  459. #pragma mark - ELBloodBleWifiManagerDelegate
  460. /**
  461. Call back real-time, stable data(回调实时、稳定数据)
  462. @param model 数据
  463. @param type 类型
  464. */
  465. - (void)bloodBleManagerReceiceTestData:(ELbloodPresureBleWifiDataModel *)model type:(ELBloodBleDataModelType)type {
  466. NSLog(@"## bloodBleManagerReceiceTestData");
  467. static BOOL testEnd = NO;
  468. if (type == ELBloodBleDataModelTypeStable) {
  469. if (testEnd == NO) {
  470. testEnd = YES;
  471. }
  472. NSString *log = [NSString stringWithFormat:@"收缩压:%@, 舒张压:%@, ", model.sys, model.dia];
  473. [self addLog:log];
  474. } else if (type == ELBloodBleDataModelTypeRealTime) {
  475. testEnd = NO;
  476. NSString *log = [NSString stringWithFormat:@"压力:%@", model.dia];
  477. [self addLog:log];
  478. }
  479. }
  480. /**
  481. Set unit callback(设置单位回调)
  482. @param type 结果
  483. */
  484. - (void)bloodBleManagerReceiveSetUnitResult:(ELSetBluetoothResponseType)type {
  485. NSLog(@"## bloodBleManagerReceiveSetUnitResult() type:%@", @(type));
  486. if (type == ELSetBluetoothResponseTypeSuccess) {
  487. NSString *log = @"切换单位 成功";
  488. [self addLog:log];
  489. } else if (type == ELSetBluetoothResponseTypeFailure) {
  490. NSString *log = @"切换单位 失败";
  491. [self addLog:log];
  492. } else if (type == ELSetBluetoothResponseTypeNoSupport) {
  493. NSString *log = @"切换单位 不支持";
  494. [self addLog:log];
  495. }
  496. }
  497. /**
  498. Set the interaction type(设置交互类型)
  499. @param type 结果
  500. */
  501. - (void)bloodBleManagerReceiveInteractionType:(ELBloodInteractionType)type {
  502. NSLog(@"## bloodBleManagerReceiveInteractionType");
  503. if (type == ELBloodInteractionTypeStartTest) {
  504. NSString *log = @"设备状态 已开始测量";
  505. [self addLog:log];
  506. } else if (type == ELBloodInteractionTypeStopTest) {
  507. NSString *log = @"设备状态 已停止测量";
  508. [self addLog:log];
  509. } else if (type == ELBloodInteractionTypeShutdown) {
  510. NSString *log = @"设备状态 已关机";
  511. [self addLog:log];
  512. } else if (type == ELBloodInteractionTypeBoot) {
  513. NSString *log = @"设备状态 已开机";
  514. [self addLog:log];
  515. }
  516. }
  517. /**
  518. Error code sent on the device(设备上发错误码)
  519. @param code error code(错误码)
  520. */
  521. - (void)bloodBleManagerReceiveFailCode:(ELBloodFailCode)code {
  522. NSLog(@"## bloodBleManagerReceiveFailCode");
  523. }
  524. /**
  525. Send voice alarm setting result(下发语音报警设置结果)
  526. @param type 操作类型
  527. @param result 结果
  528. */
  529. - (void)bloodBleManagerReceiveSetSwitchVoiceOperationType:(ELBloodBleSwitchVoiceType)type result:(ELSetBluetoothResponseType)result {
  530. NSLog(@"## bloodBleManagerReceiveSetSwitchVoiceOperationType");
  531. if (result == ELSetBluetoothResponseTypeSuccess) {
  532. if (type == ELBloodBleSwitchVoiceTypeOn) {
  533. NSString *log = @"语音 打开 成功";
  534. [self addLog:log];
  535. }else if (type == ELBloodBleSwitchVoiceTypeOff){
  536. NSString *log = @"语音 关闭 成功";
  537. [self addLog:log];
  538. }
  539. } else {
  540. NSString *log = @"语音 设置 失败";
  541. [self addLog:log];
  542. }
  543. }
  544. //获取版本号
  545. - (void)bluetoothManagerReceiveBMVersion:(NSString *)bmVersion {
  546. NSLog(@"%@", bmVersion);
  547. NSString *log = [NSString stringWithFormat:@"模块版本: %@", bmVersion];
  548. [self addLog:log];
  549. }
  550. #pragma mark - addLog
  551. - (void)addLog:(NSString *)log {
  552. [self addLog:log newline:YES];
  553. }
  554. - (void)addWithoutNewlineLog:(NSString *)log {
  555. [self addLog:log newline:NO];
  556. }
  557. - (void)addLog:(NSString *)log newline:(BOOL)newline {
  558. NSDateFormatter *format = [[NSDateFormatter alloc] init];
  559. format.dateFormat = @"HH:mm:ss.SSS";
  560. NSString *time = [format stringFromDate:[NSDate date]];
  561. if (newline) {
  562. self.logTextView.text = [self.logTextView.text stringByAppendingFormat:@"%@ %@\n", time, log];
  563. } else {
  564. self.logTextView.text = [self.logTextView.text stringByAppendingFormat:@"%@ %@", time, log];
  565. }
  566. [self.logTextView scrollRangeToVisible:NSMakeRange(self.logTextView.text.length, 1)];
  567. }
  568. @end