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

RingTestDemoVC.m 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. //
  2. // RingTestDemoVC.m
  3. // AICareComponentRingBleSDK
  4. //
  5. // Created by zp on 03/011/2024.
  6. // Copyright (c) 2024 zp. All rights reserved.
  7. //
  8. #import "RingTestDemoVC.h"
  9. #import <AICareComponentRingBleSDK/ELSmartRingManager.h>
  10. @interface RingTestDemoVC () <ELSmartRingManagerDelegate>
  11. @property (weak, nonatomic) IBOutlet UILabel *bleStatusLabel;
  12. @property (weak, nonatomic) IBOutlet UILabel *nameLabel;
  13. @property (weak, nonatomic) IBOutlet UITextView *logTextView;
  14. @property (weak, nonatomic) IBOutlet UILabel *filenameLabel;
  15. @property (weak, nonatomic) IBOutlet UILabel *BleVersionLabel;
  16. @property (weak, nonatomic) IBOutlet UILabel *McuVersionLabel;
  17. @property (weak, nonatomic) IBOutlet UISwitch *AutoSwitch;
  18. @property (nonatomic, strong) ELSmartRingManager *smartRingManager;
  19. @property (nonatomic, assign) NELBleManagerConnectState bleConnectState;
  20. @property (nonatomic, strong) NSData *fileData;
  21. @property (nonatomic, assign) UInt16 address;
  22. @property (nonatomic, copy) NSString *filename;
  23. @property (nonatomic, copy) NSString *filepath;
  24. @end
  25. @implementation RingTestDemoVC
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. // Do any additional setup after loading the view from its nib.
  29. self.bleStatusLabel.text = @"";
  30. self.nameLabel.text = @"";
  31. [self initBle];
  32. }
  33. - (void)viewWillAppear:(BOOL)animated {
  34. [super viewWillAppear:animated];
  35. }
  36. - (void)viewWillDisappear:(BOOL)animated {
  37. [super viewWillDisappear:animated];
  38. }
  39. - (void)dealloc {
  40. [self deinitBle];
  41. }
  42. #pragma mark - Action
  43. - (IBAction)getDeviceStatusAction:(id)sender {
  44. [[ELSmartRingManager sharedManager] smartRingGetDeviceStatus];
  45. }
  46. - (IBAction)startBleOTAAction:(id)sender {
  47. NSString *fileName = @"BR01H1S1.0.0_20230923.img";
  48. // NSString *fileName = @"BR01H1S1.0.0_20240125.img";
  49. NSString *path =[[NSBundle bundleForClass:[self class]] pathForResource:fileName ofType:nil];
  50. _filenameLabel.text = fileName;
  51. [[ELSmartRingManager sharedManager] startBleOTAWithPath:path];
  52. }
  53. - (IBAction)startMcuOTAAction:(id)sender
  54. {
  55. NSString *fileName = @"JFH_01_1234a_APP-202401021530-0xa8b3.bin";
  56. // NSString *fileName = @"JFH_01_1234a_APP-202309231223-0xf1d8.bin";
  57. NSString *path =[[NSBundle bundleForClass:[self class]] pathForResource:fileName ofType:nil];
  58. _filenameLabel.text = fileName;
  59. [[ELSmartRingManager sharedManager] startMcuOTAWithPath:path];
  60. }
  61. -(IBAction)setAutoCheckAction:(UISwitch *)sender
  62. {
  63. if (sender.on == YES){
  64. [[ELSmartRingManager sharedManager] smartRingSetAutoCheckOpen:YES];
  65. }else {
  66. [[ELSmartRingManager sharedManager] smartRingSetAutoCheckOpen:NO];
  67. }
  68. }
  69. - (IBAction)getDetectionPeriodAction:(id)sender {
  70. [[ELSmartRingManager sharedManager] smartRingSetDetectionPeriodWith:0];
  71. }
  72. - (IBAction)setDetectionPeriod15Action:(id)sender {
  73. [[ELSmartRingManager sharedManager] smartRingSetDetectionPeriodWith:15];
  74. }
  75. - (IBAction)setDetectionPeriod30Action:(id)sender {
  76. [[ELSmartRingManager sharedManager] smartRingSetDetectionPeriodWith:30];
  77. }
  78. - (IBAction)setDetectionPeriod60Action:(id)sender {
  79. [[ELSmartRingManager sharedManager] smartRingSetDetectionPeriodWith:60];
  80. }
  81. - (IBAction)getAutoCheckAction:(id)sender {
  82. [[ELSmartRingManager sharedManager] smartRingGetAutoCheckOpen];
  83. }
  84. - (IBAction)startCheckAction:(id)sender {
  85. [[ELSmartRingManager sharedManager] smartRingStartCheck];
  86. }
  87. - (IBAction)endCheckAction:(id)sender {
  88. [[ELSmartRingManager sharedManager] smartRingCloseCheck];
  89. }
  90. - (IBAction)getRRIAction:(id)sender {
  91. //获取RRI数 通过RRI数控制监测模式
  92. [[ELSmartRingManager sharedManager] smartRingGetRRI];
  93. }
  94. - (IBAction)setRRI72Action:(id)sender {
  95. //默认 模式 0 全面模式 1 快速模式
  96. [[ELSmartRingManager sharedManager] smartRingSetRRIWithType:0];
  97. }
  98. - (IBAction)setRRI30Action:(id)sender {
  99. //默认 模式 0 全面模式 1 快速模式
  100. [[ELSmartRingManager sharedManager] smartRingSetRRIWithType:1];
  101. }
  102. - (IBAction)getRecordAction:(id)sender {
  103. //获取日常检测历史记录 //0 开始获取 1 继续获取 2 结束获取 3 删除历史记录
  104. [[ELSmartRingManager sharedManager] smartRingReocrdWithType:0];
  105. }
  106. - (IBAction)getBleVersionAction:(id)sender {
  107. [[ELSmartRingManager sharedManager] smartRingGetVersion];
  108. }
  109. - (IBAction)getMcuVersionAction:(id)sender {
  110. [[ELSmartRingManager sharedManager] smartRingGetJFInfo];
  111. }
  112. - (IBAction)customWriteAction:(id)sender {
  113. }
  114. - (IBAction)clearAction:(id)sender {
  115. self.logTextView.text = @"";
  116. }
  117. - (IBAction)shareLogAction:(id)sender {
  118. }
  119. - (IBAction)sleepStepDataAction:(UIButton *)sender {
  120. [[ELSmartRingManager sharedManager] smartRingSleepReocrdWithType:0];
  121. }
  122. #pragma mark - BleManagerDelegate
  123. - (void)initBle {
  124. [ELSmartRingManager sharedManager].delegate = self;
  125. [[ELSmartRingManager sharedManager] stopScan];
  126. [[ELSmartRingManager sharedManager] connectAILinkPeripheral:self.per];
  127. }
  128. - (void)scanBle {
  129. }
  130. - (void)connect:(ELAILinkPeripheral *)peripheral {
  131. }
  132. - (void)deinitBle {
  133. [ELSmartRingManager sharedManager].delegate = nil;
  134. [[ELSmartRingManager sharedManager] disconnectPeripheral];
  135. }
  136. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager managerDidDiscoverPeripheral:(ELAILinkPeripheral *)peripheral
  137. {
  138. if ([peripheral.peripheral.identifier isEqual:self.per.peripheral.identifier]) {
  139. [[ELSmartRingManager sharedManager] stopScan];
  140. [[ELSmartRingManager sharedManager] connectAILinkPeripheral:peripheral];
  141. }
  142. }
  143. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager managerDidUpdateState:(CBCentralManager *)central
  144. {
  145. NSLog(@"%s state:%@", __func__, @(central.state));
  146. if (central.state == CBManagerStatePoweredOn) {
  147. self.bleConnectState = NELBleManagerConnectStateCentralScanning;
  148. } else if (central.state == CBManagerStatePoweredOff) {
  149. self.bleConnectState = NELBleManagerConnectStateCentralPowerOff;
  150. }
  151. }
  152. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager ConnectState:(NELBleManagerConnectState)bleConnectState
  153. {
  154. NSLog(@"%s ConnectState :%@", __func__, @(bleConnectState));
  155. self.bleConnectState = bleConnectState;
  156. if (bleConnectState == ELBluetoothStateUnavailable) {
  157. } else if (bleConnectState == NELBleManagerConnectStatePassed) {
  158. // 同步时间到设备
  159. [[ELSmartRingManager sharedManager] syncMCUNowDate];
  160. // 获取蓝牙版本号
  161. [[ELSmartRingManager sharedManager] smartRingGetVersion];
  162. // 获取Mcu版本号
  163. [[ELSmartRingManager sharedManager] smartRingGetJFInfo];
  164. //获取设备信息
  165. [[ELSmartRingManager sharedManager] smartRingGetDeviceStatus];
  166. //获取日常监测是否开启
  167. [[ELSmartRingManager sharedManager] smartRingGetAutoCheckOpen];
  168. //获取监测间隔时间
  169. [[ELSmartRingManager sharedManager] smartRingSetDetectionPeriodWith:0];
  170. //获取监测模式返回rri数
  171. [[ELSmartRingManager sharedManager] smartRingGetRRI];
  172. //
  173. }else if (bleConnectState == NELBleManagerConnectStateDisconnected)
  174. {
  175. }
  176. }
  177. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager DeviceStatus:(ELSmartRingDeviceStatus)deviceStatus Battery:(struct ELBatteryStruct)battery wearStatue:(NSInteger)wearStatue
  178. {
  179. NSLog(@"%s DeviceStatus :%@", __func__, @(deviceStatus));
  180. [self addLog:[NSString stringWithFormat:@"%s deviceStatus :%@ battery :%d wearStatue :%@", __func__, @(deviceStatus),battery.power,@(wearStatue)]];
  181. if(deviceStatus == ELSmartRingDeviceStatus_failed)
  182. {
  183. ///历史时间未就绪(未获取unix时间) 需要 先获取unix时间
  184. [[ELSmartRingManager sharedManager] smartRingSetUnix];
  185. }else if (deviceStatus == ELSmartRingDeviceStatus_success)
  186. {
  187. // 历史时间已就绪(此状态才可获取设备历史记录)
  188. }
  189. }
  190. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager AutoCheck:(BOOL)open
  191. {
  192. NSLog(@"%s AutoCheck :%@", __func__, @(open));
  193. [self addLog:[NSString stringWithFormat:@"%s open:%@", __func__,@(open)]];
  194. self.AutoSwitch.on = open;
  195. }
  196. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager DetectionPeriod:(NSUInteger)interval
  197. {
  198. NSLog(@"%s DetectionPeriod :%@", __func__, @(interval));
  199. [self addLog:[NSString stringWithFormat:@"%s interval:%@", __func__,@(interval)]];
  200. }
  201. - (void)smartRingManager:(ELSmartRingManager *)smartRingManager getBmVersion:(NSString *)bmVersion
  202. {
  203. NSLog(@"%s getBmVersion :%@", __func__,bmVersion);
  204. [self addLog:[NSString stringWithFormat:@"%s bmVersion:%@", __func__,bmVersion]];
  205. self.BleVersionLabel.text = bmVersion;
  206. }
  207. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager GetJFInfo:(NSString *)info
  208. {
  209. NSLog(@"%s GetJFInfo :%@", __func__, info);
  210. [self addLog:[NSString stringWithFormat:@"%s GetJFInfo:%@", __func__,info]];
  211. self.McuVersionLabel.text = info;
  212. }
  213. //返回 RRI 条数 默认为 72条 是全面数据 30条为快速数据
  214. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager RRI:(NSInteger)RRI
  215. {
  216. NSLog(@"%s RRI :%@", __func__, @(RRI));
  217. [self addLog:[NSString stringWithFormat:@"%s RRI:%@", __func__,@(RRI)]];
  218. }
  219. //
  220. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager record:(ELSmartRingBleModel *)smartRingBleModel isEnd:(BOOL)isEnd
  221. {
  222. NSLog(@"%s record :%@", __func__, @(isEnd));
  223. [self addLog:[NSString stringWithFormat:@"%s record:%@ isEnd:%@", __func__,smartRingBleModel,@(isEnd)]];
  224. // nowIndex == totle 表示当前为最后一页 isEnd 为no 表示 当前页还有记录数据 为 yes表示为当前页最后一条数据
  225. if (smartRingBleModel.nowIndex < smartRingBleModel.totle )
  226. {
  227. if (isEnd ==YES) {
  228. //当前页获记录取完 获取下一页记录
  229. [[ELSmartRingManager sharedManager] smartRingReocrdWithType:1];
  230. }
  231. }else {
  232. //历史记录全部获取完成
  233. if (isEnd ==YES) {
  234. //结束获取
  235. [[ELSmartRingManager sharedManager] smartRingReocrdWithType:2];
  236. //删除历史记录
  237. [[ELSmartRingManager sharedManager] smartRingReocrdWithType:3];
  238. }
  239. }
  240. }
  241. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager haveRecord:(NSInteger)haveRecord
  242. {
  243. NSLog(@"%s haveRecord :%@", __func__, @(haveRecord));
  244. [self addLog:[NSString stringWithFormat:@"%s haveRecord:%@ ", __func__,@(haveRecord)]];
  245. }
  246. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager SetCheck:(ELSmartRingBleModel *)smartRingBleModel
  247. {
  248. NSLog(@"%s SetCheck :%@", __func__, smartRingBleModel);
  249. [self addLog:[NSString stringWithFormat:@"%s smartRingBleModel:%@ ", __func__,smartRingBleModel]];
  250. }
  251. -(void)smartRingOTAUpdateProgress:(double)progress
  252. {
  253. NSLog(@"%s progress :%@", __func__, @(progress));
  254. [self addLog:[NSString stringWithFormat:@"%s progress:%@ ", __func__,@(progress)]];
  255. }
  256. //ble OTA 升级成功后需要充电重新激活戒指
  257. -(void)smartRingOTAUpdateResult:(BOOL)isSuccess errorMsg:(NSString *)errorMsg
  258. {
  259. NSLog(@"%s isSuccess :%@ errorMsg :%@", __func__, @(isSuccess),errorMsg);
  260. [self addLog:[NSString stringWithFormat:@"%s isSuccess:%@ errorMsg :%@", __func__,@(isSuccess),errorMsg]];
  261. }
  262. //步数,睡眠数据
  263. - (void)smartRingBleParser:(ELSmartRingBleParser *)bleParser SleepRecordArray:(nonnull NSArray *)smartRingBleModelArray {
  264. for (ELSmartRingBleModel * smartRingBleModel in smartRingBleModelArray) {
  265. ELSmartRingSleepDataModel *model = [[ELSmartRingSleepDataModel alloc]init];
  266. model.type = smartRingBleModel.sleepType;
  267. model.step = smartRingBleModel.step;
  268. model.uploadTime = smartRingBleModel.recordTime/1000;
  269. NSLog(@"%s smartRingBleModelArray :%@", __func__, model);
  270. }
  271. }
  272. #pragma mark - addLog
  273. - (void)addLog:(NSString *)log {
  274. [self addLog:log newline:YES];
  275. }
  276. - (void)addWithoutNewlineLog:(NSString *)log {
  277. [self addLog:log newline:NO];
  278. }
  279. - (void)addLog:(NSString *)log newline:(BOOL)newline {
  280. NSDateFormatter *format = [[NSDateFormatter alloc] init];
  281. format.dateFormat = @"HH:mm:ss.SSS";
  282. NSString *time = [format stringFromDate:[NSDate date]];
  283. if (newline) {
  284. self.logTextView.text = [self.logTextView.text stringByAppendingFormat:@"%@ %@\n", time, log];
  285. } else {
  286. self.logTextView.text = [self.logTextView.text stringByAppendingFormat:@"%@ %@ ", time, log];
  287. }
  288. [self.logTextView scrollRangeToVisible:NSMakeRange(self.logTextView.text.length, 1)];
  289. }
  290. @end