// // RingTestDemoVC.m // AICareComponentRingBleSDK // // Created by zp on 03/011/2024. // Copyright (c) 2024 zp. All rights reserved. // #import "RingTestDemoVC.h" #import @interface RingTestDemoVC () @property (weak, nonatomic) IBOutlet UILabel *bleStatusLabel; @property (weak, nonatomic) IBOutlet UILabel *nameLabel; @property (weak, nonatomic) IBOutlet UITextView *logTextView; @property (weak, nonatomic) IBOutlet UILabel *filenameLabel; @property (weak, nonatomic) IBOutlet UILabel *BleVersionLabel; @property (weak, nonatomic) IBOutlet UILabel *McuVersionLabel; @property (weak, nonatomic) IBOutlet UISwitch *AutoSwitch; @property (nonatomic, strong) ELSmartRingManager *smartRingManager; @property (nonatomic, assign) NELBleManagerConnectState bleConnectState; @property (nonatomic, strong) NSData *fileData; @property (nonatomic, assign) UInt16 address; @property (nonatomic, copy) NSString *filename; @property (nonatomic, copy) NSString *filepath; @end @implementation RingTestDemoVC - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. self.bleStatusLabel.text = @""; self.nameLabel.text = @""; [self initBle]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; } - (void)dealloc { [self deinitBle]; } #pragma mark - Action - (IBAction)getDeviceStatusAction:(id)sender { [[ELSmartRingManager sharedManager] smartRingGetDeviceStatus]; } - (IBAction)startBleOTAAction:(id)sender { NSString *fileName = @"BR01H1S1.0.0_20230923.img"; // NSString *fileName = @"BR01H1S1.0.0_20240125.img"; NSString *path =[[NSBundle bundleForClass:[self class]] pathForResource:fileName ofType:nil]; _filenameLabel.text = fileName; [[ELSmartRingManager sharedManager] startBleOTAWithPath:path]; } - (IBAction)startMcuOTAAction:(id)sender { NSString *fileName = @"JFH_01_1234a_APP-202401021530-0xa8b3.bin"; // NSString *fileName = @"JFH_01_1234a_APP-202309231223-0xf1d8.bin"; NSString *path =[[NSBundle bundleForClass:[self class]] pathForResource:fileName ofType:nil]; _filenameLabel.text = fileName; [[ELSmartRingManager sharedManager] startMcuOTAWithPath:path]; } -(IBAction)setAutoCheckAction:(UISwitch *)sender { if (sender.on == YES){ [[ELSmartRingManager sharedManager] smartRingSetAutoCheckOpen:YES]; }else { [[ELSmartRingManager sharedManager] smartRingSetAutoCheckOpen:NO]; } } - (IBAction)getDetectionPeriodAction:(id)sender { [[ELSmartRingManager sharedManager] smartRingSetDetectionPeriodWith:0]; } - (IBAction)setDetectionPeriod15Action:(id)sender { [[ELSmartRingManager sharedManager] smartRingSetDetectionPeriodWith:15]; } - (IBAction)setDetectionPeriod30Action:(id)sender { [[ELSmartRingManager sharedManager] smartRingSetDetectionPeriodWith:30]; } - (IBAction)setDetectionPeriod60Action:(id)sender { [[ELSmartRingManager sharedManager] smartRingSetDetectionPeriodWith:60]; } - (IBAction)getAutoCheckAction:(id)sender { [[ELSmartRingManager sharedManager] smartRingGetAutoCheckOpen]; } - (IBAction)startCheckAction:(id)sender { [[ELSmartRingManager sharedManager] smartRingStartCheck]; } - (IBAction)endCheckAction:(id)sender { [[ELSmartRingManager sharedManager] smartRingCloseCheck]; } - (IBAction)getRRIAction:(id)sender { //获取RRI数 通过RRI数控制监测模式 [[ELSmartRingManager sharedManager] smartRingGetRRI]; } - (IBAction)setRRI72Action:(id)sender { //默认 模式 0 全面模式 1 快速模式 [[ELSmartRingManager sharedManager] smartRingSetRRIWithType:0]; } - (IBAction)setRRI30Action:(id)sender { //默认 模式 0 全面模式 1 快速模式 [[ELSmartRingManager sharedManager] smartRingSetRRIWithType:1]; } - (IBAction)getRecordAction:(id)sender { //获取日常检测历史记录 //0 开始获取 1 继续获取 2 结束获取 3 删除历史记录 [[ELSmartRingManager sharedManager] smartRingReocrdWithType:0]; } - (IBAction)getBleVersionAction:(id)sender { [[ELSmartRingManager sharedManager] smartRingGetVersion]; } - (IBAction)getMcuVersionAction:(id)sender { [[ELSmartRingManager sharedManager] smartRingGetJFInfo]; } - (IBAction)customWriteAction:(id)sender { } - (IBAction)clearAction:(id)sender { self.logTextView.text = @""; } - (IBAction)shareLogAction:(id)sender { } - (IBAction)sleepStepDataAction:(UIButton *)sender { [[ELSmartRingManager sharedManager] smartRingSleepReocrdWithType:0]; } #pragma mark - BleManagerDelegate - (void)initBle { [ELSmartRingManager sharedManager].delegate = self; [[ELSmartRingManager sharedManager] stopScan]; [[ELSmartRingManager sharedManager] connectAILinkPeripheral:self.per]; } - (void)scanBle { } - (void)connect:(ELAILinkPeripheral *)peripheral { } - (void)deinitBle { [ELSmartRingManager sharedManager].delegate = nil; [[ELSmartRingManager sharedManager] disconnectPeripheral]; } -(void)smartRingManager:(ELSmartRingManager *)smartRingManager managerDidDiscoverPeripheral:(ELAILinkPeripheral *)peripheral { if ([peripheral.peripheral.identifier isEqual:self.per.peripheral.identifier]) { [[ELSmartRingManager sharedManager] stopScan]; [[ELSmartRingManager sharedManager] connectAILinkPeripheral:peripheral]; } } -(void)smartRingManager:(ELSmartRingManager *)smartRingManager managerDidUpdateState:(CBCentralManager *)central { NSLog(@"%s state:%@", __func__, @(central.state)); if (central.state == CBManagerStatePoweredOn) { self.bleConnectState = NELBleManagerConnectStateCentralScanning; } else if (central.state == CBManagerStatePoweredOff) { self.bleConnectState = NELBleManagerConnectStateCentralPowerOff; } } -(void)smartRingManager:(ELSmartRingManager *)smartRingManager ConnectState:(NELBleManagerConnectState)bleConnectState { NSLog(@"%s ConnectState :%@", __func__, @(bleConnectState)); self.bleConnectState = bleConnectState; if (bleConnectState == ELBluetoothStateUnavailable) { } else if (bleConnectState == NELBleManagerConnectStatePassed) { // 同步时间到设备 [[ELSmartRingManager sharedManager] syncMCUNowDate]; // 获取蓝牙版本号 [[ELSmartRingManager sharedManager] smartRingGetVersion]; // 获取Mcu版本号 [[ELSmartRingManager sharedManager] smartRingGetJFInfo]; //获取设备信息 [[ELSmartRingManager sharedManager] smartRingGetDeviceStatus]; //获取日常监测是否开启 [[ELSmartRingManager sharedManager] smartRingGetAutoCheckOpen]; //获取监测间隔时间 [[ELSmartRingManager sharedManager] smartRingSetDetectionPeriodWith:0]; //获取监测模式返回rri数 [[ELSmartRingManager sharedManager] smartRingGetRRI]; // }else if (bleConnectState == NELBleManagerConnectStateDisconnected) { } } -(void)smartRingManager:(ELSmartRingManager *)smartRingManager DeviceStatus:(ELSmartRingDeviceStatus)deviceStatus Battery:(struct ELBatteryStruct)battery wearStatue:(NSInteger)wearStatue { NSLog(@"%s DeviceStatus :%@", __func__, @(deviceStatus)); [self addLog:[NSString stringWithFormat:@"%s deviceStatus :%@ battery :%d wearStatue :%@", __func__, @(deviceStatus),battery.power,@(wearStatue)]]; if(deviceStatus == ELSmartRingDeviceStatus_failed) { ///历史时间未就绪(未获取unix时间) 需要 先获取unix时间 [[ELSmartRingManager sharedManager] smartRingSetUnix]; }else if (deviceStatus == ELSmartRingDeviceStatus_success) { // 历史时间已就绪(此状态才可获取设备历史记录) } } -(void)smartRingManager:(ELSmartRingManager *)smartRingManager AutoCheck:(BOOL)open { NSLog(@"%s AutoCheck :%@", __func__, @(open)); [self addLog:[NSString stringWithFormat:@"%s open:%@", __func__,@(open)]]; self.AutoSwitch.on = open; } -(void)smartRingManager:(ELSmartRingManager *)smartRingManager DetectionPeriod:(NSUInteger)interval { NSLog(@"%s DetectionPeriod :%@", __func__, @(interval)); [self addLog:[NSString stringWithFormat:@"%s interval:%@", __func__,@(interval)]]; } - (void)smartRingManager:(ELSmartRingManager *)smartRingManager getBmVersion:(NSString *)bmVersion { NSLog(@"%s getBmVersion :%@", __func__,bmVersion); [self addLog:[NSString stringWithFormat:@"%s bmVersion:%@", __func__,bmVersion]]; self.BleVersionLabel.text = bmVersion; } -(void)smartRingManager:(ELSmartRingManager *)smartRingManager GetJFInfo:(NSString *)info { NSLog(@"%s GetJFInfo :%@", __func__, info); [self addLog:[NSString stringWithFormat:@"%s GetJFInfo:%@", __func__,info]]; self.McuVersionLabel.text = info; } //返回 RRI 条数 默认为 72条 是全面数据 30条为快速数据 -(void)smartRingManager:(ELSmartRingManager *)smartRingManager RRI:(NSInteger)RRI { NSLog(@"%s RRI :%@", __func__, @(RRI)); [self addLog:[NSString stringWithFormat:@"%s RRI:%@", __func__,@(RRI)]]; } // -(void)smartRingManager:(ELSmartRingManager *)smartRingManager record:(ELSmartRingBleModel *)smartRingBleModel isEnd:(BOOL)isEnd { NSLog(@"%s record :%@", __func__, @(isEnd)); [self addLog:[NSString stringWithFormat:@"%s record:%@ isEnd:%@", __func__,smartRingBleModel,@(isEnd)]]; // nowIndex == totle 表示当前为最后一页 isEnd 为no 表示 当前页还有记录数据 为 yes表示为当前页最后一条数据 if (smartRingBleModel.nowIndex < smartRingBleModel.totle ) { if (isEnd ==YES) { //当前页获记录取完 获取下一页记录 [[ELSmartRingManager sharedManager] smartRingReocrdWithType:1]; } }else { //历史记录全部获取完成 if (isEnd ==YES) { //结束获取 [[ELSmartRingManager sharedManager] smartRingReocrdWithType:2]; //删除历史记录 [[ELSmartRingManager sharedManager] smartRingReocrdWithType:3]; } } } -(void)smartRingManager:(ELSmartRingManager *)smartRingManager haveRecord:(NSInteger)haveRecord { NSLog(@"%s haveRecord :%@", __func__, @(haveRecord)); [self addLog:[NSString stringWithFormat:@"%s haveRecord:%@ ", __func__,@(haveRecord)]]; } -(void)smartRingManager:(ELSmartRingManager *)smartRingManager SetCheck:(ELSmartRingBleModel *)smartRingBleModel { NSLog(@"%s SetCheck :%@", __func__, smartRingBleModel); [self addLog:[NSString stringWithFormat:@"%s smartRingBleModel:%@ ", __func__,smartRingBleModel]]; } -(void)smartRingOTAUpdateProgress:(double)progress { NSLog(@"%s progress :%@", __func__, @(progress)); [self addLog:[NSString stringWithFormat:@"%s progress:%@ ", __func__,@(progress)]]; } //ble OTA 升级成功后需要充电重新激活戒指 -(void)smartRingOTAUpdateResult:(BOOL)isSuccess errorMsg:(NSString *)errorMsg { NSLog(@"%s isSuccess :%@ errorMsg :%@", __func__, @(isSuccess),errorMsg); [self addLog:[NSString stringWithFormat:@"%s isSuccess:%@ errorMsg :%@", __func__,@(isSuccess),errorMsg]]; } //步数,睡眠数据 - (void)smartRingBleParser:(ELSmartRingBleParser *)bleParser SleepRecordArray:(nonnull NSArray *)smartRingBleModelArray { for (ELSmartRingBleModel * smartRingBleModel in smartRingBleModelArray) { ELSmartRingSleepDataModel *model = [[ELSmartRingSleepDataModel alloc]init]; model.type = smartRingBleModel.sleepType; model.step = smartRingBleModel.step; model.uploadTime = smartRingBleModel.recordTime/1000; NSLog(@"%s smartRingBleModelArray :%@", __func__, model); } } #pragma mark - addLog - (void)addLog:(NSString *)log { [self addLog:log newline:YES]; } - (void)addWithoutNewlineLog:(NSString *)log { [self addLog:log newline:NO]; } - (void)addLog:(NSString *)log newline:(BOOL)newline { NSDateFormatter *format = [[NSDateFormatter alloc] init]; format.dateFormat = @"HH:mm:ss.SSS"; NSString *time = [format stringFromDate:[NSDate date]]; if (newline) { self.logTextView.text = [self.logTextView.text stringByAppendingFormat:@"%@ %@\n", time, log]; } else { self.logTextView.text = [self.logTextView.text stringByAppendingFormat:@"%@ %@ ", time, log]; } [self.logTextView scrollRangeToVisible:NSMakeRange(self.logTextView.text.length, 1)]; } @end