You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RingTestDemoVC.m 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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. #pragma mark - BleManagerDelegate
  120. - (void)initBle {
  121. [ELSmartRingManager sharedManager].delegate = self;
  122. [[ELSmartRingManager sharedManager] stopScan];
  123. [[ELSmartRingManager sharedManager] connectAILinkPeripheral:self.per];
  124. }
  125. - (void)scanBle {
  126. }
  127. - (void)connect:(ELAILinkPeripheral *)peripheral {
  128. }
  129. - (void)deinitBle {
  130. [ELSmartRingManager sharedManager].delegate = nil;
  131. [[ELSmartRingManager sharedManager] disconnectPeripheral];
  132. }
  133. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager managerDidDiscoverPeripheral:(ELAILinkPeripheral *)peripheral
  134. {
  135. if ([peripheral.peripheral.identifier isEqual:self.per.peripheral.identifier]) {
  136. [[ELSmartRingManager sharedManager] stopScan];
  137. [[ELSmartRingManager sharedManager] connectAILinkPeripheral:peripheral];
  138. }
  139. }
  140. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager managerDidUpdateState:(CBCentralManager *)central
  141. {
  142. NSLog(@"%s state:%@", __func__, @(central.state));
  143. if (central.state == CBManagerStatePoweredOn) {
  144. self.bleConnectState = NELBleManagerConnectStateCentralScanning;
  145. } else if (central.state == CBManagerStatePoweredOff) {
  146. self.bleConnectState = NELBleManagerConnectStateCentralPowerOff;
  147. }
  148. }
  149. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager ConnectState:(NELBleManagerConnectState)bleConnectState
  150. {
  151. NSLog(@"%s ConnectState :%@", __func__, @(bleConnectState));
  152. self.bleConnectState = bleConnectState;
  153. if (bleConnectState == ELBluetoothStateUnavailable) {
  154. } else if (bleConnectState == NELBleManagerConnectStatePassed) {
  155. // 同步时间到设备
  156. [[ELSmartRingManager sharedManager] syncMCUNowDate];
  157. // 获取蓝牙版本号
  158. [[ELSmartRingManager sharedManager] smartRingGetVersion];
  159. // 获取Mcu版本号
  160. [[ELSmartRingManager sharedManager] smartRingGetJFInfo];
  161. //获取设备信息
  162. [[ELSmartRingManager sharedManager] smartRingGetDeviceStatus];
  163. //获取日常监测是否开启
  164. [[ELSmartRingManager sharedManager] smartRingGetAutoCheckOpen];
  165. //获取监测间隔时间
  166. [[ELSmartRingManager sharedManager] smartRingSetDetectionPeriodWith:0];
  167. //获取监测模式返回rri数
  168. [[ELSmartRingManager sharedManager] smartRingGetRRI];
  169. //
  170. }else if (bleConnectState == NELBleManagerConnectStateDisconnected)
  171. {
  172. }
  173. }
  174. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager DeviceStatus:(ELSmartRingDeviceStatus)deviceStatus Battery:(struct ELBatteryStruct)battery wearStatue:(NSInteger)wearStatue
  175. {
  176. NSLog(@"%s DeviceStatus :%@", __func__, @(deviceStatus));
  177. [self addLog:[NSString stringWithFormat:@"%s deviceStatus :%@ battery :%d wearStatue :%@", __func__, @(deviceStatus),battery.power,@(wearStatue)]];
  178. if(deviceStatus == ELSmartRingDeviceStatus_failed)
  179. {
  180. ///历史时间未就绪(未获取unix时间) 需要 先获取unix时间
  181. [[ELSmartRingManager sharedManager] smartRingSetUnix];
  182. }else if (deviceStatus == ELSmartRingDeviceStatus_success)
  183. {
  184. // 历史时间已就绪(此状态才可获取设备历史记录)
  185. }
  186. }
  187. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager AutoCheck:(BOOL)open
  188. {
  189. NSLog(@"%s AutoCheck :%@", __func__, @(open));
  190. [self addLog:[NSString stringWithFormat:@"%s open:%@", __func__,@(open)]];
  191. self.AutoSwitch.on = open;
  192. }
  193. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager DetectionPeriod:(NSUInteger)interval
  194. {
  195. NSLog(@"%s DetectionPeriod :%@", __func__, @(interval));
  196. [self addLog:[NSString stringWithFormat:@"%s interval:%@", __func__,@(interval)]];
  197. }
  198. - (void)smartRingManager:(ELSmartRingManager *)smartRingManager getBmVersion:(NSString *)bmVersion
  199. {
  200. NSLog(@"%s getBmVersion :%@", __func__,bmVersion);
  201. [self addLog:[NSString stringWithFormat:@"%s bmVersion:%@", __func__,bmVersion]];
  202. self.BleVersionLabel.text = bmVersion;
  203. }
  204. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager GetJFInfo:(NSString *)info
  205. {
  206. NSLog(@"%s GetJFInfo :%@", __func__, info);
  207. [self addLog:[NSString stringWithFormat:@"%s GetJFInfo:%@", __func__,info]];
  208. self.McuVersionLabel.text = info;
  209. }
  210. //返回 RRI 条数 默认为 72条 是全面数据 30条为快速数据
  211. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager RRI:(NSInteger)RRI
  212. {
  213. NSLog(@"%s RRI :%@", __func__, @(RRI));
  214. [self addLog:[NSString stringWithFormat:@"%s RRI:%@", __func__,@(RRI)]];
  215. }
  216. //
  217. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager record:(ELSmartRingBleModel *)smartRingBleModel isEnd:(BOOL)isEnd
  218. {
  219. NSLog(@"%s record :%@", __func__, @(isEnd));
  220. [self addLog:[NSString stringWithFormat:@"%s record:%@ isEnd:%@", __func__,smartRingBleModel,@(isEnd)]];
  221. // nowIndex == totle 表示当前为最后一页 isEnd 为no 表示 当前页还有记录数据 为 yes表示为当前页最后一条数据
  222. if (smartRingBleModel.nowIndex < smartRingBleModel.totle )
  223. {
  224. if (isEnd ==YES) {
  225. //当前页获记录取完 获取下一页记录
  226. [[ELSmartRingManager sharedManager] smartRingReocrdWithType:1];
  227. }
  228. }else {
  229. //历史记录全部获取完成
  230. if (isEnd ==YES) {
  231. //结束获取
  232. [[ELSmartRingManager sharedManager] smartRingReocrdWithType:2];
  233. //删除历史记录
  234. [[ELSmartRingManager sharedManager] smartRingReocrdWithType:3];
  235. }
  236. }
  237. }
  238. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager haveRecord:(NSInteger)haveRecord
  239. {
  240. NSLog(@"%s haveRecord :%@", __func__, @(haveRecord));
  241. [self addLog:[NSString stringWithFormat:@"%s haveRecord:%@ ", __func__,@(haveRecord)]];
  242. }
  243. -(void)smartRingManager:(ELSmartRingManager *)smartRingManager SetCheck:(ELSmartRingBleModel *)smartRingBleModel
  244. {
  245. NSLog(@"%s SetCheck :%@", __func__, smartRingBleModel);
  246. [self addLog:[NSString stringWithFormat:@"%s smartRingBleModel:%@ ", __func__,smartRingBleModel]];
  247. }
  248. -(void)smartRingOTAUpdateProgress:(double)progress
  249. {
  250. NSLog(@"%s progress :%@", __func__, @(progress));
  251. [self addLog:[NSString stringWithFormat:@"%s progress:%@ ", __func__,@(progress)]];
  252. }
  253. //ble OTA 升级成功后需要充电重新激活戒指
  254. -(void)smartRingOTAUpdateResult:(BOOL)isSuccess errorMsg:(NSString *)errorMsg
  255. {
  256. NSLog(@"%s isSuccess :%@ errorMsg :%@", __func__, @(isSuccess),errorMsg);
  257. [self addLog:[NSString stringWithFormat:@"%s isSuccess:%@ errorMsg :%@", __func__,@(isSuccess),errorMsg]];
  258. }
  259. #pragma mark - addLog
  260. - (void)addLog:(NSString *)log {
  261. [self addLog:log newline:YES];
  262. }
  263. - (void)addWithoutNewlineLog:(NSString *)log {
  264. [self addLog:log newline:NO];
  265. }
  266. - (void)addLog:(NSString *)log newline:(BOOL)newline {
  267. NSDateFormatter *format = [[NSDateFormatter alloc] init];
  268. format.dateFormat = @"HH:mm:ss.SSS";
  269. NSString *time = [format stringFromDate:[NSDate date]];
  270. if (newline) {
  271. self.logTextView.text = [self.logTextView.text stringByAppendingFormat:@"%@ %@\n", time, log];
  272. } else {
  273. self.logTextView.text = [self.logTextView.text stringByAppendingFormat:@"%@ %@ ", time, log];
  274. }
  275. [self.logTextView scrollRangeToVisible:NSMakeRange(self.logTextView.text.length, 1)];
  276. }
  277. @end