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

BodyFatScaleConnectViewController.m 26KB

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