iOS AILinkBleSDK - 蓝牙SDK
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ELWIFIBloodPressureVC.m 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  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 = @"iot.elink.com";
  34. self.portTexField.text = @"80";
  35. self.pathTexField.text = @"";
  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)requestWifiListAction:(id)sender {
  48. [self.dataSource removeAllObjects];
  49. [self.tableView reloadData];
  50. [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetNearbyWifi];
  51. NSString *log = @"获取 附近的 WIFI 列表";
  52. [self addLog:log];
  53. }
  54. - (IBAction)setupServerInfoAcion:(id)sender {
  55. NSString *url = self.urlTexField.text;
  56. NSString *port = self.portTexField.text;
  57. NSString *path = self.pathTexField.text;
  58. [[ElBloodBleWifiManager shareManager] setDevAccessIpAddress:url portNumber:port.intValue path:path];
  59. NSString *log = @"设置 服务器信息";
  60. [self addLog:log];
  61. }
  62. - (IBAction)requestServerInfoAcion:(id)sender {
  63. [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetURL];
  64. [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetPort];
  65. [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetPathAddress];
  66. NSString *log = @"获取 服务器信息";
  67. [self addLog:log];
  68. }
  69. - (IBAction)switchUintAction:(id)sender {
  70. static BOOL value = YES;
  71. if (value) {
  72. [[ElBloodBleWifiManager shareManager] changeUnit:ELDeviceBloodPressureUnit_mmhg];
  73. NSString *log = @"设置单位 mmhg";
  74. [self addLog:log];
  75. } else {
  76. [[ElBloodBleWifiManager shareManager] changeUnit:ELDeviceBloodPressureUnit_kPa];
  77. NSString *log = @"设置单位 kPa";
  78. [self addLog:log];
  79. }
  80. value = !value;
  81. }
  82. - (IBAction)switchSpeechAtion:(id)sender {
  83. static BOOL value = YES;
  84. if (value) {
  85. [[ElBloodBleWifiManager shareManager] sendSwitchVoice:ELBloodBleSwitchVoiceTypeOn];
  86. NSString *log = @"打开 语音";
  87. [self addLog:log];
  88. } else {
  89. [[ElBloodBleWifiManager shareManager] sendSwitchVoice:ELBloodBleSwitchVoiceTypeOff];
  90. NSString *log = @"关闭 语音";
  91. [self addLog:log];
  92. }
  93. value = !value;
  94. }
  95. - (IBAction)startMeasureAction:(id)sender {
  96. [[ElBloodBleWifiManager shareManager] sendInteractiveInstructions:ELBloodInteractionTypeStartTest];
  97. NSString *log = @"开始 测量";
  98. [self addLog:log];
  99. }
  100. - (IBAction)stopMeasureAction:(id)sender {
  101. [[ElBloodBleWifiManager shareManager] sendInteractiveInstructions:ELBloodInteractionTypeStopTest];
  102. NSString *log = @"停止 测量";
  103. [self addLog:log];
  104. }
  105. - (IBAction)clearAction:(id)sender {
  106. self.logTextView.text = @"";
  107. }
  108. - (IBAction)shareLogAction:(id)sender {
  109. }
  110. #pragma mark - textField Delegate
  111. - (void)textFieldDidEndEditing:(UITextField *)textField {
  112. if (textField.tag == 119) {
  113. NSLog(@"%@",textField.text);
  114. //MARK:7.再发送配置wifi的密码的指令
  115. [[ElBloodBleWifiManager shareManager] bleWifiSetWifiPwd:textField.text];
  116. }
  117. }
  118. #pragma mark - tableView Delegate And DataSource
  119. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  120. return 1;
  121. }
  122. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  123. return self.dataSource.count;
  124. }
  125. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  126. return 0.f;
  127. }
  128. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  129. return nil;
  130. }
  131. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  132. static NSString *cellId = @"ELBfsWifiConnectTableViewCell";
  133. ELBfsWifiConnectTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
  134. if (!cell) {
  135. cell = [[ELBfsWifiConnectTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
  136. }
  137. ELBleWifiDetailModel *model = self.dataSource[indexPath.row];
  138. cell.wifiName = model.wifiName;
  139. if (model.wifiState == ELBleWifiUseStateConnected) {
  140. cell.isLink = YES;
  141. } else {
  142. cell.isLink = NO;
  143. }
  144. return cell;
  145. }
  146. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  147. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  148. ELBleWifiDetailModel *model = self.dataSource[indexPath.row];
  149. //MARK:5.先发送配置wifi的mac地址的指令
  150. [[ElBloodBleWifiManager shareManager] bleWifiSetConnectWifiMac:model.macData];
  151. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"请输入wifi密码" message:model.wifiName preferredStyle:UIAlertControllerStyleAlert];
  152. UIAlertAction *conform = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  153. NSLog(@"点击了确认按钮");
  154. }];
  155. UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  156. NSLog(@"点击了取消按钮");
  157. }];
  158. //MARK:6.输入wifi密码
  159. [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  160. textField.placeholder = @"密码";
  161. textField.delegate = self;
  162. textField.tag = 119;
  163. }];
  164. [alert addAction:conform];
  165. [alert addAction:cancel];
  166. [self presentViewController:alert animated:YES completion:nil];
  167. }
  168. #pragma mark - ELBluetoothManagerDelegate
  169. /**
  170. Callback Bluetooth status(回调蓝牙状态)
  171. @param state Bluetooth status(蓝牙状态)
  172. */
  173. -(void)bloodBleManagerUpdateBleState:(ELBluetoothState)state {
  174. NSLog(@"## bluetoothManagerUpdateBleState = %ld", state);
  175. if (state == ELBluetoothStateScaning) {
  176. self.bleStatusLabel.text = @"正在连接...";
  177. // NSString *log = @"正在连接...";
  178. // [self addLog:log];
  179. } else if (state == ELBluetoothStateDidValidationPass) {
  180. self.bleStatusLabel.text = @"连接成功";
  181. NSString *log = @"连接成功";
  182. [self addLog:log];
  183. } else if (state == ELBluetoothStateDidDisconnect) {
  184. self.bleStatusLabel.text = @"连接已断开";
  185. NSString *log = @"连接已断开";
  186. [self addLog:log];
  187. } else {
  188. // self.bleStatusLabel.text = @"";
  189. }
  190. }
  191. /**
  192. Callback scanned device(回调扫描到的设备)
  193. @param devices 设备
  194. */
  195. - (void)bloodBleManagerScanDevices:(NSArray<ELPeripheralModel *> *_Nullable)devices {
  196. NSLog(@"## bloodBleManagerScanDevices = %@", devices);
  197. for (int i = 0; i < devices.count; i++) {
  198. ELPeripheralModel *device = devices[i];
  199. if ([device.macAddress isEqualToString:self.per.macAddressString]) {
  200. [[ElBloodBleWifiManager shareManager] stopScan];
  201. [[ElBloodBleWifiManager shareManager] connectPeripheral:device];
  202. return;
  203. }
  204. }
  205. }
  206. #pragma mark - ElBleWifiDelegate
  207. /**
  208. Callback Wifi details(回调Wifi详情)
  209. @param model 模型
  210. */
  211. - (void)bleWifiReceiveWifiDetailModel:(ELBleWifiDetailModel *)model {
  212. NSLog(@"## bleWifiReceiveWifiDetailModel");
  213. // [self addLog:[NSString stringWithFormat:@"wifi type---%lu name---%@ link state--%zd",(unsigned long)model.wifiState,model.wifiName,model.wifiState]];
  214. // MARK:3.WiFi配置得到Wifi列表
  215. if (model.wifiName.length > 0) {
  216. [self.dataSource addObject:model];
  217. }
  218. [self.tableView reloadData];
  219. }
  220. /**
  221. Scan nearby wifi results(扫描附近wifi结果)
  222. @param count Number of nearby wifi(附近wifi数量)
  223. */
  224. - (void)bleWifiReceiveScanedWifiCount:(int)count {
  225. NSLog(@"## bleWifiReceiveScanedWifiCount() count:%@", @(count));
  226. //MARK:4.WiFi配置得到一个附近wifi的列表,点击选择一个wifi,进行配置
  227. [self.tableView reloadData];
  228. }
  229. /**
  230. Callback Wifi MAC address(回调Wifi MAC地址)
  231. @param macData mac
  232. */
  233. - (void)bleWifiReceiveWifiMacData:(NSData *_Nullable)macData {
  234. NSLog(@"## bleWifiReceiveWifiMacData");
  235. }
  236. /**
  237. Callback WIFI password(回调WIFI密码)
  238. @param pwd password(密码)
  239. */
  240. - (void)bleWifiReceiveWifiPwd:(NSString *_Nonnull)pwd {
  241. NSLog(@"## bleWifiReceiveWifiPwd");
  242. }
  243. /**
  244. Get DTIM interval (unit: ms)(获取DTIM间隔(单位:ms))
  245. @param interval Interval (unit: ms)(间隔(单位:ms))
  246. */
  247. - (void)bleWifiReceiveWifiDTIMInterval:(NSInteger)interval {
  248. NSLog(@"## bleWifiReceiveWifiDTIMInterval");
  249. }
  250. /**
  251. Returns the visited URL(返回访问的url)
  252. @param url url
  253. */
  254. - (void)bleWifiReceiveWifiAccessURL:(NSString *)url {
  255. NSLog(@"## bleWifiReceiveWifiAccessURL() url:%@", url);
  256. NSString *log = [NSString stringWithFormat:@"url:%@", url];
  257. [self addLog:log];
  258. }
  259. /**
  260. Call back wifi port number(回调wifi的端口号)
  261. @param port 端口号
  262. */
  263. - (void)bleWifiReceiveWifiPort:(int)port {
  264. NSLog(@"## bleWifiReceiveWifiPort() port:%@", @(port));
  265. NSString *log = [NSString stringWithFormat:@"port:%@", @(port)];
  266. [self addLog:log];
  267. }
  268. //Returns the visited path(返回访问的path)
  269. - (void)bleWifiReceiveWifiPath:(NSString *)path {
  270. NSLog(@"## bleWifiReceiveWifiPath() path:%@", path);
  271. NSString *log = [NSString stringWithFormat:@"path:%@", path];
  272. [self addLog:log];
  273. }
  274. /**
  275. Set or query the callback of the instruction execution result(设置指令蓝牙WIFI响应回调方法)
  276. 只支持蓝牙Wifi部分枚举
  277. @param type Type of setting (设置的类型)
  278. @param result Set result(设置的结果)
  279. */
  280. - (void)bleWifiReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result {
  281. NSLog(@"## bleWifiReceiceResponseType");
  282. if (result == ELSetBluetoothResponseTypeSuccess) {
  283. //设置WiFi结果
  284. if (type == ELInetSetCmdTypeBleWifiSetWifiMac) {
  285. } else if (type == ELInetSetCmdTypeBleWifiSetWifiPwd){
  286. //MARK:8.然后发起连接Wifi
  287. [[ElBloodBleWifiManager shareManager] bleWifiSetupWifiConnect:YES];
  288. } else if (type == ELInetSetCmdTypeBleWifiSetConnectWifi){
  289. //获取连接状态,更新Wi-Fi列表
  290. [self.dataSource removeAllObjects];
  291. [self.tableView reloadData];
  292. [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetNearbyWifi];
  293. }
  294. } else {
  295. //TODO:Wifi配置过程中失败的情况自行处理
  296. }
  297. }
  298. /**
  299. 获取会话码(deviceId)
  300. @param code (deviceId) deviceId(0 means no:为0时表示不存在)
  301. */
  302. - (void)bleWifiReceiveWifiSNCode:(int)code {
  303. NSLog(@"## bleWifiReceiveWifiSNCode() code:%@", @(code));
  304. if (code == 0) {
  305. //失败
  306. }
  307. NSString *log = [NSString stringWithFormat:@"bleWifiReceiveWifiSNCode :%@", @(code)];
  308. [self addLog:log];
  309. }
  310. /** 返回wifi名称 */
  311. - (void)bleWifiName:(NSString *)wifiName {
  312. NSLog(@"## bleWifiName() wifiName:%@", wifiName);
  313. NSString *log = [NSString stringWithFormat:@"bleWifiName:%@", wifiName];
  314. [self addLog:log];
  315. }
  316. - (void)bluetoothManagerReceiveMCUConnectedState:(struct ELMCUStateStruct)stateStrct {
  317. NSLog(@"## bluetoothManagerReceiveMCUConnectedState");
  318. BleWiFiConnectState wifiState = stateStrct.wifiState;
  319. //请求会话码
  320. [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetSNNumber];
  321. //MARK:1.WiFi配置提示用户配网
  322. //TODO:注意:wifi配置过程必须保持蓝牙与设备的连接
  323. if (wifiState == BleWiFiConnectStateNoWiFi) {
  324. //1.如果没有配网,则提示用户去配网
  325. //MARK:2.WiFi配置先获取wifi列表
  326. [self.dataSource removeAllObjects];
  327. [self.tableView reloadData];
  328. [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetNearbyWifi];
  329. NSString *log = @"获取附近 wifi 列表";
  330. [self addLog:log];
  331. } else if (wifiState == BleWiFiConnectStateSuccess) {
  332. [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiName];
  333. NSString *log = @"获取当前 wifi 名称";
  334. [self addLog:log];
  335. } else {
  336. // //MARK:2.没网也可以获取Wi-Fi列表,如果需要更新Wi-Fi的话
  337. // [self.dataSource removeAllObjects];
  338. // [self.tableView reloadData];
  339. // [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetNearbyWifi];
  340. }
  341. ///MARK:9.wifi配置结果
  342. //wifi相关的其他指令和数据接收,请查看ELBluetoothManager.h文件
  343. if (stateStrct.wifiState == BleWiFiConnectStateSuccess) {
  344. //成功
  345. //MARK:10.获取wifi设备的SN号,即设备id
  346. [[ElBloodBleWifiManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetSNNumber];
  347. }
  348. }
  349. -(void)bluetoothManagerReceiveWMState:(ELWMStateStruct)stateStrct {
  350. NSLog(@"## bluetoothManagerReceiveMCUConnectedState");
  351. }
  352. -(void)bluetoothManagerReceiveWMStateFailCode:(WMWorkStateFailCode)failCode {
  353. NSLog(@"## bluetoothManagerReceiveMCUConnectedState");
  354. }
  355. #pragma mark - ELBloodBleWifiManagerDelegate
  356. /**
  357. Call back real-time, stable data(回调实时、稳定数据)
  358. @param model 数据
  359. @param type 类型
  360. */
  361. - (void)bloodBleManagerReceiceTestData:(ELbloodPresureBleWifiDataModel *)model type:(ELBloodBleDataModelType)type {
  362. NSLog(@"## bloodBleManagerReceiceTestData");
  363. static BOOL testEnd = NO;
  364. if (type == ELBloodBleDataModelTypeStable) {
  365. if (testEnd == NO) {
  366. testEnd = YES;
  367. }
  368. NSString *log = [NSString stringWithFormat:@"收缩压:%@, 舒张压:%@, ", model.sys, model.dia];
  369. [self addLog:log];
  370. } else if (type == ELBloodBleDataModelTypeRealTime) {
  371. testEnd = NO;
  372. NSString *log = [NSString stringWithFormat:@"压力:%@", model.dia];
  373. [self addLog:log];
  374. }
  375. }
  376. /**
  377. Set unit callback(设置单位回调)
  378. @param type 结果
  379. */
  380. - (void)bloodBleManagerReceiveSetUnitResult:(ELSetBluetoothResponseType)type {
  381. NSLog(@"## bloodBleManagerReceiveSetUnitResult() type:%@", @(type));
  382. if (type == ELSetBluetoothResponseTypeSuccess) {
  383. NSString *log = @"切换单位 成功";
  384. [self addLog:log];
  385. } else if (type == ELSetBluetoothResponseTypeFailure) {
  386. NSString *log = @"切换单位 失败";
  387. [self addLog:log];
  388. } else if (type == ELSetBluetoothResponseTypeNoSupport) {
  389. NSString *log = @"切换单位 不支持";
  390. [self addLog:log];
  391. }
  392. }
  393. /**
  394. Set the interaction type(设置交互类型)
  395. @param type 结果
  396. */
  397. - (void)bloodBleManagerReceiveInteractionType:(ELBloodInteractionType)type {
  398. NSLog(@"## bloodBleManagerReceiveInteractionType");
  399. if (type == ELBloodInteractionTypeStartTest) {
  400. NSString *log = @"设备状态 已开始测量";
  401. [self addLog:log];
  402. } else if (type == ELBloodInteractionTypeStopTest) {
  403. NSString *log = @"设备状态 已停止测量";
  404. [self addLog:log];
  405. } else if (type == ELBloodInteractionTypeShutdown) {
  406. NSString *log = @"设备状态 已关机";
  407. [self addLog:log];
  408. } else if (type == ELBloodInteractionTypeBoot) {
  409. NSString *log = @"设备状态 已开机";
  410. [self addLog:log];
  411. }
  412. }
  413. /**
  414. Error code sent on the device(设备上发错误码)
  415. @param code error code(错误码)
  416. */
  417. - (void)bloodBleManagerReceiveFailCode:(ELBloodFailCode)code {
  418. NSLog(@"## bloodBleManagerReceiveFailCode");
  419. }
  420. /**
  421. Send voice alarm setting result(下发语音报警设置结果)
  422. @param type 操作类型
  423. @param result 结果
  424. */
  425. - (void)bloodBleManagerReceiveSetSwitchVoiceOperationType:(ELBloodBleSwitchVoiceType)type result:(ELSetBluetoothResponseType)result {
  426. NSLog(@"## bloodBleManagerReceiveSetSwitchVoiceOperationType");
  427. if (result == ELSetBluetoothResponseTypeSuccess) {
  428. if (type == ELBloodBleSwitchVoiceTypeOn) {
  429. NSString *log = @"语音 打开 成功";
  430. [self addLog:log];
  431. }else if (type == ELBloodBleSwitchVoiceTypeOff){
  432. NSString *log = @"语音 关闭 成功";
  433. [self addLog:log];
  434. }
  435. } else {
  436. NSString *log = @"语音 设置 失败";
  437. [self addLog:log];
  438. }
  439. }
  440. //获取版本号
  441. - (void)bluetoothManagerReceiveBMVersion:(NSString *)bmVersion {
  442. NSLog(@"%@", bmVersion);
  443. NSString *log = [NSString stringWithFormat:@"模块版本: %@", bmVersion];
  444. [self addLog:log];
  445. }
  446. #pragma mark - addLog
  447. - (void)addLog:(NSString *)log {
  448. [self addLog:log newline:YES];
  449. }
  450. - (void)addWithoutNewlineLog:(NSString *)log {
  451. [self addLog:log newline:NO];
  452. }
  453. - (void)addLog:(NSString *)log newline:(BOOL)newline {
  454. NSDateFormatter *format = [[NSDateFormatter alloc] init];
  455. format.dateFormat = @"HH:mm:ss.SSS";
  456. NSString *time = [format stringFromDate:[NSDate date]];
  457. if (newline) {
  458. self.logTextView.text = [self.logTextView.text stringByAppendingFormat:@"%@ %@\n", time, log];
  459. } else {
  460. self.logTextView.text = [self.logTextView.text stringByAppendingFormat:@"%@ %@", time, log];
  461. }
  462. [self.logTextView scrollRangeToVisible:NSMakeRange(self.logTextView.text.length, 1)];
  463. }
  464. @end