iOS AILinkBleSDK - 蓝牙SDK
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ELBfsWifiConnectVC.m 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. //
  2. // BodyFatScaleConnectViewController.m
  3. // AILinkBleSDKSourceCode
  4. //
  5. // Created by iot_user on 2020/4/8.
  6. // Copyright © 2020 IOT. All rights reserved.
  7. //
  8. #import "ELBfsWifiConnectVC.h"
  9. #import "Masonry.h"
  10. #import <AILinkBleSDK/ELBodyFatScaleBleManager.h>
  11. #import <AILinkBleSDK/ELBodyFatScaleBleUserModel.h>
  12. #import <AILinkBleSDK/ELBodyFatScaleBleWeightModel.h>
  13. #import "ELBfsWifiConnectTableViewCell.h"
  14. #import <AILinkBleSDK/ELBluetoothManager+Settings.h>
  15. #import <AILinkBleSDK/ELBleWifiDetailModel.h>
  16. #import <AILinkBleSDK/ELBluetoothManager+BleWifi.h>
  17. @interface ELBfsWifiConnectVC ()<ELBluetoothManagerDelegate,ELBodyFatScaleBleDelegate,ElBleWifiDelegate,UITextFieldDelegate,UITableViewDelegate,UITableViewDataSource>
  18. @property (nonatomic, strong) UITableView *tableView;
  19. @property (nonatomic, strong) NSMutableArray<ELBleWifiDetailModel *> *dataSource;
  20. @property (nonatomic, strong) UITextView *textView;
  21. @property (nonatomic, strong) UIButton *changeIpBtn;
  22. @end
  23. @implementation ELBfsWifiConnectVC
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. self.view.backgroundColor = [UIColor whiteColor];
  27. [ELBodyFatScaleBleManager shareManager].bodyFatScaleDelegate = self;
  28. [ELBodyFatScaleBleManager shareManager].delegate = self;
  29. [[ELBodyFatScaleBleManager shareManager] connectPeripheral:self.p];
  30. [ELBodyFatScaleBleManager shareManager].bleWifiDelegate = self;
  31. self.dataSource = [NSMutableArray array];
  32. [self setupUIView];
  33. }
  34. -(void)viewWillDisappear:(BOOL)animated{
  35. [super viewWillDisappear:animated];
  36. [[ELBodyFatScaleBleManager shareManager] disconnectPeripheral];
  37. }
  38. -(void)addLog:(NSString *)log{
  39. self.textView.text = [NSString stringWithFormat:@"%@\n%@",log,self.textView.text];
  40. }
  41. -(void)buttonAction:(UIButton *)sender{
  42. if ([ELBodyFatScaleBleManager shareManager].state != ELBluetoothStateDidValidationPass) {
  43. [self addLog:@"Disconnected"];
  44. return;
  45. }
  46. switch (sender.tag) {
  47. case 1: {
  48. //获取BM Version
  49. [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeGetBMVersion];
  50. }
  51. break;
  52. case 2: {
  53. //Get CVP ID
  54. [self addLog:[NSString stringWithFormat:@"Cid:%zd, Vid:%zd, Pid:%zd",self.p.deviceType,self.p.vendorID,self.p.productID]];
  55. }
  56. break;
  57. case 3: {
  58. //Get Name
  59. [self addLog:[NSString stringWithFormat:@"DeviceName:%@",self.p.deviceName]];
  60. }
  61. break;
  62. case 4: {
  63. //Set name
  64. [[ELBodyFatScaleBleManager shareManager] setBluetoothName:@"Ailink_Dev"];
  65. }
  66. break;
  67. case 5: {
  68. //Change unit
  69. if (sender.selected) {
  70. [[ELBodyFatScaleBleManager shareManager] changeBodyFatScaleUnit:ELDeviceWeightUnit_LB];
  71. [self addLog:@"set lb unit"];
  72. } else {
  73. [[ELBodyFatScaleBleManager shareManager] changeBodyFatScaleUnit:ELDeviceWeightUnit_KG];
  74. [self addLog:@"set kg unit"];
  75. }
  76. sender.selected = !sender.selected;
  77. }
  78. break;
  79. default:
  80. break;
  81. }
  82. [self addLog:sender.titleLabel.text];
  83. }
  84. -(void)setupUIView{
  85. // UIButton *button1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  86. // [button1 setTitle:@"Get BM Version" forState:(UIControlStateNormal)];
  87. // button1.tag = 1;
  88. // button1.titleLabel.adjustsFontSizeToFitWidth = YES;
  89. // button1.titleLabel.numberOfLines = 2;
  90. // button1.backgroundColor = [UIColor blackColor];
  91. // [button1 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  92. // [self.view addSubview:button1];
  93. // [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
  94. // make.left.mas_equalTo(10);
  95. // make.top.mas_equalTo(85);
  96. // make.width.mas_equalTo(100);
  97. // make.height.mas_equalTo(40);
  98. // }];
  99. //
  100. // UIButton *button2 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  101. // [button2 setTitle:@"Get C V P ID" forState:(UIControlStateNormal)];
  102. // button2.tag = 2;
  103. // button2.titleLabel.adjustsFontSizeToFitWidth = YES;
  104. // button2.titleLabel.numberOfLines = 2;
  105. // button2.backgroundColor = [UIColor blackColor];
  106. // [button2 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  107. // [self.view addSubview:button2];
  108. // [button2 mas_makeConstraints:^(MASConstraintMaker *make) {
  109. // make.left.equalTo(button1.mas_right).mas_offset(10);
  110. // make.top.mas_equalTo(85);
  111. // make.width.mas_equalTo(100);
  112. // make.height.mas_equalTo(40);
  113. // }];
  114. //
  115. // UIButton *button3 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  116. // [button3 setTitle:@"Get Name" forState:(UIControlStateNormal)];
  117. // button3.tag = 3;
  118. // button3.titleLabel.adjustsFontSizeToFitWidth = YES;
  119. // button3.titleLabel.numberOfLines = 2;
  120. // button3.backgroundColor = [UIColor blackColor];
  121. // [button3 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  122. // [self.view addSubview:button3];
  123. // [button3 mas_makeConstraints:^(MASConstraintMaker *make) {
  124. // make.left.equalTo(button2.mas_right).mas_offset(10);
  125. // make.top.mas_equalTo(85);
  126. // make.width.mas_equalTo(100);
  127. // make.height.mas_equalTo(40);
  128. // }];
  129. // //
  130. // UIButton *button4 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  131. // [button4 setTitle:@"Set Name" forState:(UIControlStateNormal)];
  132. // button4.tag = 4;
  133. // button4.titleLabel.adjustsFontSizeToFitWidth = YES;
  134. // button4.titleLabel.numberOfLines = 2;
  135. // button4.backgroundColor = [UIColor blackColor];
  136. // [button4 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  137. // [self.view addSubview:button4];
  138. // [button4 mas_makeConstraints:^(MASConstraintMaker *make) {
  139. // make.left.mas_equalTo(10);
  140. // make.top.equalTo(button1.mas_bottom).mas_offset(10);
  141. // make.width.mas_equalTo(100);
  142. // make.height.mas_equalTo(40);
  143. // }];
  144. UIButton *button5 = [UIButton buttonWithType:(UIButtonTypeCustom)];
  145. [button5 setTitle:@"Change unit" forState:(UIControlStateNormal)];
  146. button5.tag = 5;
  147. button5.titleLabel.adjustsFontSizeToFitWidth = YES;
  148. button5.titleLabel.numberOfLines = 2;
  149. button5.backgroundColor = [UIColor blackColor];
  150. [button5 addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
  151. [self.view addSubview:button5];
  152. [button5 mas_makeConstraints:^(MASConstraintMaker *make) {
  153. // make.left.equalTo(button4.mas_right).mas_offset(10);
  154. // make.top.equalTo(button1.mas_bottom).mas_offset(10);
  155. make.left.offset(10);
  156. make.top.offset(90);
  157. make.width.mas_equalTo(100);
  158. make.height.mas_equalTo(40);
  159. }];
  160. //
  161. self.textView = [[UITextView alloc] init];
  162. self.textView.backgroundColor = [UIColor blackColor];
  163. self.textView.text = @"Log";
  164. self.textView.textColor = [UIColor redColor];
  165. [self.view addSubview:self.textView];
  166. [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
  167. make.left.mas_equalTo(10);
  168. make.right.bottom.mas_equalTo(-10);
  169. make.height.mas_equalTo(300);
  170. }];
  171. self.changeIpBtn = [[UIButton alloc] init];
  172. [self.changeIpBtn setTitle:@"Switch to the test environment" forState:UIControlStateNormal];
  173. [self.changeIpBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  174. [self.changeIpBtn setTitle:@"Switch to the formal environment" forState:UIControlStateSelected];
  175. [self.changeIpBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
  176. self.changeIpBtn.adjustsImageWhenHighlighted = YES;
  177. self.changeIpBtn.backgroundColor = [UIColor blackColor];
  178. self.changeIpBtn.titleLabel.font = [UIFont systemFontOfSize:13];
  179. self.changeIpBtn.titleLabel.numberOfLines = 2;
  180. [self.changeIpBtn addTarget:self action:@selector(changeDevIpAddress:) forControlEvents:UIControlEventTouchUpInside];
  181. [self.view addSubview:self.changeIpBtn];
  182. [self.changeIpBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  183. make.left.equalTo(button5.mas_right).mas_offset(10);
  184. make.centerY.equalTo(button5.mas_centerY);
  185. make.width.mas_equalTo(120);
  186. make.height.mas_equalTo(40);
  187. // make.left.offset(20);
  188. // make.top.offset(100);
  189. // make.size.mas_equalTo(CGSizeMake(120, 30));
  190. }];
  191. self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
  192. self.tableView.delegate = self;
  193. self.tableView.dataSource = self;
  194. [self.view addSubview:self.tableView];
  195. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  196. make.left.right.offset(0);
  197. make.top.equalTo(self.changeIpBtn.mas_bottom).offset(15);
  198. make.bottom.equalTo(self.textView.mas_top).offset(-20);
  199. }];
  200. }
  201. -(void)bodyFatScaleManagerUpdateState:(ELBluetoothState)state{
  202. switch (state) {
  203. case ELBluetoothStateUnavailable:
  204. {
  205. self.title = @"Please open the bluetooth";
  206. }
  207. break;
  208. case ELBluetoothStateAvailable:
  209. {
  210. self.title = @"Bluetooth is open";
  211. }
  212. break;
  213. case ELBluetoothStateScaning:
  214. {
  215. self.title = @"Scaning";
  216. }
  217. break;
  218. case ELBluetoothStateConnectFail:
  219. {
  220. self.title = @"Connect fail";
  221. }
  222. break;
  223. case ELBluetoothStateDidDisconnect:
  224. {
  225. self.title = @"Disconnected";
  226. }
  227. break;
  228. case ELBluetoothStateDidValidationPass:
  229. {
  230. self.title = @"Connected";
  231. if (self.p.deviceType == ELSupportDeviceTypeBLE_WIFIScale) {
  232. //获取蓝牙连接状态
  233. [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeGetConnectState)];
  234. }
  235. }
  236. break;
  237. case ELBluetoothStateFailedValidation:
  238. {
  239. self.title = @"Illegal equipment";
  240. }
  241. break;
  242. case ELBluetoothStateWillConnect:
  243. self.title = @"Connecting";
  244. break;
  245. default:
  246. break;
  247. }
  248. }
  249. -(void)bluetoothManagerReceiveMCUConnectedState:(struct ELMCUStateStruct)stateStrct{
  250. BleWiFiConnectState wifiState = stateStrct.wifiState;
  251. if (self.p.deviceType == ELSupportDeviceTypeBLE_WIFIScale) { //蓝牙WiFi体脂秤
  252. //请求会话码
  253. [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetSNNumber];
  254. //MARK:1.WiFi配置提示用户配网
  255. //TODO:注意:wifi配置过程必须保持蓝牙与设备的连接
  256. if (wifiState == BleWiFiConnectStateNoWiFi) {
  257. //1.如果没有配网,则提示用户去配网
  258. //MARK:2.WiFi配置先获取wifi列表
  259. [self.dataSource removeAllObjects];
  260. [self.tableView reloadData];
  261. [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetNearbyWifi];
  262. } else {
  263. //MARK:2.没网也可以获取Wi-Fi列表,如果需要更新Wi-Fi的话
  264. [self.dataSource removeAllObjects];
  265. [self.tableView reloadData];
  266. [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetNearbyWifi];
  267. }
  268. }
  269. ///MARK:9.wifi配置结果
  270. //wifi相关的其他指令和数据接收,请查看ELBluetoothManager.h文件
  271. if (stateStrct.wifiState == BleWiFiConnectStateSuccess) {
  272. //成功
  273. //MARK:10.获取wifi设备的SN号,即设备id
  274. [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:(ELInetGetCmdTypeBleWifiGetSNNumber)];
  275. }else{
  276. //失败
  277. }
  278. }
  279. //MARK:回调Wifi列表
  280. -(void)bleWifiReceiveWifiDetailModel:(ELBleWifiDetailModel *)model{
  281. //用一个tableview显示喽
  282. [self addLog:[NSString stringWithFormat:@"wifi type---%lu name---%@ link state--%zd",(unsigned long)model.wifiState,model.wifiName,model.wifiState]];
  283. // MARK:3.WiFi配置得到Wifi列表
  284. if (model.wifiName.length > 0) {
  285. [self.dataSource addObject:model];
  286. }
  287. [self.tableView reloadData];
  288. }
  289. -(void)bleWifiReceiveScanedWifiCount:(int)count {
  290. //MARK:扫描Wifi结束
  291. //MARK:4.WiFi配置得到一个附近wifi的列表,点击选择一个wifi,进行配置
  292. [self.tableView reloadData];
  293. }
  294. -(void)bleWifiReceiceResponseType:(ELInetSetCmdType)type result:(ELSetBluetoothResponseType)result{
  295. [self addLog:[NSString stringWithFormat:@"bleWifiReceiceResponseType==%lu----%lu",type,result]];
  296. if (result == ELSetBluetoothResponseTypeSuccess) {
  297. //设置WiFi结果
  298. if (type == ELInetSetCmdTypeBleWifiSetWifiMac) {
  299. }else if (type == ELInetSetCmdTypeBleWifiSetWifiPwd){
  300. //MARK:8.然后发起连接Wifi
  301. [[ELBodyFatScaleBleManager shareManager] bleWifiSetupWifiConnect:YES];
  302. }else if (type == ELInetSetCmdTypeBleWifiSetConnectWifi){
  303. //获取连接状态,更新Wi-Fi列表
  304. [self.dataSource removeAllObjects];
  305. [self.tableView reloadData];
  306. [[ELBodyFatScaleBleManager shareManager] getBluetoothInfoWithELInetGetCmdType:ELInetGetCmdTypeBleWifiGetNearbyWifi];
  307. }
  308. }
  309. else{
  310. //TODO:Wifi配置过程中失败的情况自行处理
  311. }
  312. }
  313. -(void)bleWifiReceiveWifiSNCode:(int)code{
  314. //MARK:11.根据wifi设备的设备id从服务器获取离线数据(找自己后台要接口)
  315. }
  316. #pragma mark - textField Delegate
  317. - (void)textFieldDidEndEditing:(UITextField *)textField {
  318. NSLog(@"%@",textField.text);
  319. //MARK:7.再发送配置wifi的密码的指令
  320. [[ELBodyFatScaleBleManager shareManager] bleWifiSetWifiPwd:textField.text];
  321. }
  322. #pragma mark - tableView Delegate And DataSource
  323. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  324. return 1;
  325. }
  326. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  327. return self.dataSource.count;
  328. }
  329. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  330. return 0.f;
  331. }
  332. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  333. return nil;
  334. }
  335. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  336. static NSString *cellId = @"ELBfsWifiConnectTableViewCell";
  337. ELBfsWifiConnectTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
  338. if (!cell) {
  339. cell = [[ELBfsWifiConnectTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
  340. }
  341. ELBleWifiDetailModel *model = self.dataSource[indexPath.row];
  342. cell.wifiName = model.wifiName;
  343. if (model.wifiState == ELBleWifiUseStateConnected) {
  344. cell.isLink = YES;
  345. } else {
  346. cell.isLink = NO;
  347. }
  348. return cell;
  349. }
  350. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  351. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  352. ELBleWifiDetailModel *model = self.dataSource[indexPath.row];
  353. //MARK:5.先发送配置wifi的mac地址的指令
  354. [[ELBodyFatScaleBleManager shareManager] bleWifiSetConnectWifiMac:model.macData];
  355. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"请输入wifi密码" message:model.wifiName preferredStyle:UIAlertControllerStyleAlert];
  356. UIAlertAction *conform = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  357. NSLog(@"点击了确认按钮");
  358. }];
  359. UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  360. NSLog(@"点击了取消按钮");
  361. }];
  362. //MARK:6.输入wifi密码
  363. [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  364. textField.placeholder = @"密码";
  365. textField.delegate = self;
  366. }];
  367. [alert addAction:conform];
  368. [alert addAction:cancel];
  369. [self presentViewController:alert animated:YES completion:nil];
  370. }
  371. #pragma mark - 切换秤环境
  372. static NSString *formalAddress = @"ailink.iot.aicare.net.cn";
  373. static NSString *testAddress = @"test.ailink.revice.aicare.net.cn";
  374. //static NSString *pathURL = @"/devivce/serverRedirect/";
  375. static NSInteger portNumber = 80;
  376. - (void)changeDevIpAddress:(UIButton *)sender {
  377. // if ([self.title isEqualToString:@"Connected"]) {
  378. if (sender.selected) {
  379. //切换到生产环境
  380. [[ELBodyFatScaleBleManager shareManager] setDevAccessIpAddress:formalAddress portNumber:portNumber path:@""];
  381. [self addLog:@"Start to configure as a production environment(开始配置为生产环境"];
  382. } else {
  383. //切到测试环境
  384. [[ELBodyFatScaleBleManager shareManager] setDevAccessIpAddress:testAddress portNumber:portNumber path:@""];
  385. // [[ELBodyFatScaleBleManager shareManager] setDevAccessIpAddress:@"ABCD1234567890" path:pathURL];
  386. [self addLog:@"Start to configure as a test environment(开始配置为测试环境"];
  387. }
  388. // sender.selected = !sender.selected;
  389. // } else {
  390. // [self addLog:@"当前设备未连接"];
  391. // }
  392. }
  393. /** 返回ip地址配置结果 */
  394. - (void)bodyFatScaleManagerCallBackSetIPAddressResult:(NSInteger)result {
  395. NSString *resultStr = @"";
  396. if (result == 0) {
  397. //失败
  398. resultStr = @"Environment configuration failed(环境配置失败";
  399. } else if (result == 1) {
  400. //成功
  401. resultStr = @"Environment configuration is successful(环境配置成功";
  402. self.changeIpBtn.selected = !self.changeIpBtn.selected;
  403. } else {
  404. //不支持
  405. resultStr = @"The current device does not support environment configuration(当前设备不支持环境配置";
  406. }
  407. [self addLog:resultStr];
  408. }
  409. #pragma mark -
  410. - (void)dealloc
  411. {
  412. [[ELBodyFatScaleBleManager shareManager] disconnectPeripheral];
  413. }
  414. #pragma mark ============ 如下是蓝牙交互部分,wifi不用管 ==============
  415. - (void)bluetoothManagerReceiveBMVersion:(NSString *)bmVersion {
  416. [self addLog:[NSString stringWithFormat:@"BMVersion :%@",bmVersion]];
  417. }
  418. /**
  419. MCU requests user information( MCU 请求用户信息)
  420. @param status 请求状态
  421. */
  422. - (void)bodyFatScaleManagerMCURequestAppUserInfoType:(BodyFatScaleMCURequestUserInfoStatus)status{
  423. if (status == BodyFatScaleMCURequestUserInfoStatus_Get) {
  424. //下发当前用户给秤
  425. [[ELBodyFatScaleBleManager shareManager] sendCurrentUserToBle:[self getOneUser]];
  426. }else if (status == BodyFatScaleMCURequestUserInfoStatus_Success){
  427. [self addLog:@"MCU requests user information success"];
  428. }else if (BodyFatScaleMCURequestUserInfoStatus_Fail){
  429. [self addLog:@"MCU requests user information failure"];
  430. }
  431. }
  432. /**
  433. Return weight and body fat model(返回重量及体脂model)
  434. */
  435. -(void)bodyFatScaleManagerCallBackWeight:(ELBodyFatScaleBleWeightModel *)weightModel state:(BodyFatScaleMeasureStatus)status{
  436. switch (status) {
  437. case BodyFatScaleMeasureStatus_Unstable:
  438. {
  439. [self addLog:[NSString stringWithFormat:@"Unstable data weight = %ld unit = %@ point = %ld adc = %ld",weightModel.weight,AiLinkBleWeightUnitDic[@(weightModel.weightUnit)],weightModel.weightPoint,weightModel.adc]];
  440. }
  441. break;
  442. case BodyFatScaleMeasureStatus_Stable:
  443. {
  444. [self addLog:[NSString stringWithFormat:@"Stable data weight = %ld unit = %@ point = %ld adc = %ld",weightModel.weight,AiLinkBleWeightUnitDic[@(weightModel.weightUnit)],weightModel.weightPoint,weightModel.adc]];
  445. }
  446. break;
  447. case BodyFatScaleMeasureStatus_Failed:
  448. {
  449. [self addLog:@"Test failure"];
  450. }
  451. break;
  452. case BodyFatScaleMeasureStatus_Complete:
  453. {
  454. [self addLog:[NSString stringWithFormat:@"Tested weight = %ld unit = %@ point = %ld adc = %ld",weightModel.weight,AiLinkBleWeightUnitDic[@(weightModel.weightUnit)],weightModel.weightPoint,weightModel.adc]];
  455. //更新用户信息给秤
  456. [[ELBodyFatScaleBleManager shareManager] sendCurrentUserToBle:[self getOneUser]];
  457. //下发用户列表
  458. [[ELBodyFatScaleBleManager shareManager] sendOfflineUserListToBle:[self get8Users]];
  459. }
  460. break;
  461. default:
  462. break;
  463. }
  464. }
  465. /**
  466. Return temperature (unit: ° C)(返回温度(单位:°C))
  467. @param temp 温度(单位:°C)
  468. */
  469. -(void)bodyFatScaleManagerCallBackTemp:(NSString *)temp{
  470. [self addLog:[NSString stringWithFormat:@"temperature is %@",temp]];
  471. }
  472. /**
  473. Back to impedance measurement(返回阻抗测量)
  474. @param status 阻抗测量状态
  475. @param adc 阻抗
  476. */
  477. -(void)bodyFatScaleManagerCallBackAdcMeasureStatus:(BodyFatScaleAdcMeasureStatus)status adcValue:(NSInteger)adc{
  478. switch (status) {
  479. case BodyFatScaleAdcMeasureStatus_Testing:
  480. {
  481. [self addLog:@"adc testing"];
  482. }
  483. break;
  484. case BodyFatScaleAdcMeasureStatus_Success:
  485. {
  486. [self addLog:[NSString stringWithFormat:@"adc is %ld",adc]];
  487. }
  488. break;
  489. case BodyFatScaleAdcMeasureStatus_Fail:
  490. {
  491. [self addLog:@"adc test failure"];
  492. }
  493. break;
  494. case BodyFatScaleAdcMeasureStatus_SuccessCustom:
  495. {
  496. [self addLog:[NSString stringWithFormat:@"adc is %ld and user app algum",adc]];
  497. }
  498. break;
  499. default:
  500. break;
  501. }
  502. }
  503. /**
  504. Callback heart rate measurement(回调心率测量)
  505. @param status 心率测量状态
  506. @param heartRate 心率
  507. */
  508. -(void)bodyFatScaleManagerCallBackHeartRateMeasureStatus:(BodyFatScaleHeartRateMeasureStatus)status heartRateValue:(NSInteger)heartRate{
  509. switch (status) {
  510. case BodyFatScaleHeartRateMeasureStatus_Testing:
  511. {
  512. [self addLog:@"Heart Rate Testing"];
  513. }
  514. break;
  515. case BodyFatScaleHeartRateMeasureStatus_Success:
  516. {
  517. [self addLog:[NSString stringWithFormat:@"Heart Rate is %ld",heartRate]];
  518. }
  519. break;
  520. case BodyFatScaleHeartRateMeasureStatus_Fail:
  521. {
  522. [self addLog:@"Heart Rate Test failure"];
  523. }
  524. break;
  525. default:
  526. break;
  527. }
  528. }
  529. /**
  530. Return error code(返回错误码)
  531. @param code 错误码
  532. 1:超重
  533. */
  534. -(void)bodyFatScaleManagerCallBackErrorCode:(NSInteger)code{
  535. [self addLog:[NSString stringWithFormat:@"error code = %ld",code]];
  536. }
  537. ////MARK:回调A6指令数据
  538. //
  539. ///**
  540. // Send success or failure callback for offline user list(发送离线用户列表的成功或失败回调)
  541. //
  542. // @param status 状态
  543. // */
  544. //-(void)bodyFatScaleManagerCallBackUpdateRecordStatus:(BodyFatScaleUpdateRecordStatus)status{
  545. // switch (status) {
  546. // case BodyFatScaleUpdateRecordStatus_AllSuccess:
  547. // {
  548. // [self addLog:@"Update All Users Success"];
  549. // }
  550. // break;
  551. // case BodyFatScaleUpdateRecordStatus_OneSuccess:
  552. // {
  553. // [self addLog:@"Update A User Success"];
  554. // }
  555. // break;
  556. // case BodyFatScaleUpdateRecordStatus_OneFail:
  557. // {
  558. // [self addLog:@"Update A User Failure"];
  559. // }
  560. // break;
  561. // case BodyFatScaleUpdateRecordStatus_AllFail:
  562. // {
  563. // [self addLog:@"Update All Users Failure"];
  564. // }
  565. // break;
  566. // default:
  567. // break;
  568. // }
  569. //}
  570. //
  571. ///**
  572. // Request callback for offline history(请求离线历史记录的回调)
  573. //
  574. // @param status 状态
  575. // */
  576. //-(void)bodyFatScaleManagerCallBackSendHistoryDataStatus:(BodyFatScaleSendHistoryDataStatus)status{
  577. // if (status == BodyFatScaleSendHistoryDataStatus_No) {
  578. // [self addLog:@"No offline datas"];
  579. // }else if (status == BodyFatScaleSendHistoryDataStatus_Begin){
  580. // [self addLog:@"Begin receive offline datas"];
  581. // }else if (status == BodyFatScaleSendHistoryDataStatus_End){
  582. // [self addLog:@"End receive offline datas"];
  583. // }
  584. //
  585. //}
  586. //
  587. ///**
  588. // APP algorithm-offline history data(APP 算法-离线历史记录数据)
  589. //
  590. // @param user 用户信息
  591. // */
  592. //-(void)bodyFatScaleManagerCallBackBleUserHistoryDataCustomADCModel:(ELBodyFatScaleBleUserModel *)user bodyDataModel:(ELBodyFatScaleBleWeightModel *)bodyModel{
  593. // //这里的身体指标等数据由app自定义算法计算得到,请区分bodyModel.algNum来调用算法
  594. // [self addLog:[NSString stringWithFormat:@"App algorithm-offline history data:userId = %ld weight = %ld unit =%@ point = %ld",user.usrID,bodyModel.weight,AiLinkBleWeightUnitDic[@(bodyModel.weightUnit)],bodyModel.weightPoint]];
  595. //}
  596. //
  597. ///**
  598. // MCU algorithm-offline history data(MCU 算法-离线历史记录数据)
  599. //
  600. // @param user 用户信息
  601. // @param bodyModel 体脂数据
  602. // */
  603. //-(void)bodyFatScaleManagerCallBackBleUserHistoryDataModel:(ELBodyFatScaleBleUserModel *)user bodyDataModel:(ELBodyFatScaleBleWeightModel *)bodyModel{
  604. // //这里的身体指标数据由秤计算得到
  605. // [self addLog:[NSString stringWithFormat:@"MCU algorithm-offline history data:userId = %ld weight = %ld unit =%@ point = %ld",user.usrID,bodyModel.weight,AiLinkBleWeightUnitDic[@(bodyModel.weightUnit)],bodyModel.weightPoint]];
  606. //}
  607. -(NSArray<ELBodyFatScaleBleUserModel *> *)get8Users{
  608. NSMutableArray *users = [[NSMutableArray alloc] init];
  609. for (int i=0; i<8; i++) {
  610. ELBodyFatScaleBleUserModel *user = [[ELBodyFatScaleBleUserModel alloc] init];
  611. user.createTime = [[NSDate date] timeIntervalSince1970];
  612. user.usrID = i;
  613. user.role = i%4;
  614. user.sex = i%2;
  615. user.age = 26+i;
  616. user.height = 170+i;
  617. user.weight = 600+i;
  618. user.adc = 560+i;
  619. [users addObject:user];
  620. }
  621. return users.copy;
  622. }
  623. -(ELBodyFatScaleBleUserModel *)getOneUser{
  624. ELBodyFatScaleBleUserModel *user = [[ELBodyFatScaleBleUserModel alloc] init];
  625. user.createTime = [[NSDate date] timeIntervalSince1970];
  626. user.usrID = 0;
  627. user.role = BodyFatScaleRole_Ordinary;
  628. user.sex = ELBluetoothUserSex_Woman;
  629. user.age = 26;
  630. user.height = 170;
  631. user.weight = 600;
  632. user.adc = 560;
  633. return user;
  634. }
  635. @end