diff options
Diffstat (limited to 'libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG5SModule.m')
| -rw-r--r-- | libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG5SModule.m | 529 |
1 files changed, 529 insertions, 0 deletions
diff --git a/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG5SModule.m b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG5SModule.m new file mode 100644 index 0000000..0857956 --- /dev/null +++ b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG5SModule.m | |||
| @@ -0,0 +1,529 @@ | |||
| 1 | // | ||
| 2 | // BG5SModule.m | ||
| 3 | // ReactNativeIOSLibrary | ||
| 4 | // | ||
| 5 | // Created by soso on 2019/4/24. | ||
| 6 | // Copyright © 2019 daiqingquan. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #import "BG5SModule.h" | ||
| 10 | |||
| 11 | #import "BG5SProfileModule.h" | ||
| 12 | #import "BGMacroFile.h" | ||
| 13 | #import "BG5SController.h" | ||
| 14 | #import "BG5S.h" | ||
| 15 | #import "ManageDeviceController.h" | ||
| 16 | |||
| 17 | |||
| 18 | #define EVENT_NOTIFY @"event_notify_bg5s" | ||
| 19 | #define kMAC_KEY @"mac" | ||
| 20 | #define kACTION_KEY @"action" | ||
| 21 | |||
| 22 | #define kFUNCTION_BatteryValue @"batteryValue" | ||
| 23 | #define kFUNCTION_DeviceDate @"deviceDate" | ||
| 24 | #define kFUNCTION_DeviceTimeZone @"deviceTimeZone" | ||
| 25 | #define kFUNCTION_StripUsedValue @"stripUsedValue" | ||
| 26 | #define kFUNCTION_OfflineDataQuantity @"offlineDataQuantity" | ||
| 27 | #define kFUNCTION_BloodCodeVersion @"bloodCodeVersion" | ||
| 28 | #define kFUNCTION_CtlCodeVersion @"ctlCodeVersion" | ||
| 29 | #define kFUNCTION_Unit @"unit" | ||
| 30 | |||
| 31 | |||
| 32 | @interface BG5SModule ()<BG5SDelegate> | ||
| 33 | @property (nonatomic, assign) BOOL isMeasuring; | ||
| 34 | |||
| 35 | @end | ||
| 36 | @implementation BG5SModule | ||
| 37 | RCT_EXPORT_MODULE() | ||
| 38 | - (NSArray<NSString *> *)supportedEvents { | ||
| 39 | return @[@"event_notify", @"event_scan_device", @"event_scan_finish", | ||
| 40 | @"event_device_connected", @"event_device_connect_failed", | ||
| 41 | @"event_device_disconnect", @"event_authenticate_result", | ||
| 42 | @"event_notify_ts28b", @"event_notify_bg1", | ||
| 43 | @"action_connect_result_for_bg1"]; | ||
| 44 | } | ||
| 45 | |||
| 46 | |||
| 47 | - (NSDictionary *)constantsToExport | ||
| 48 | { | ||
| 49 | return @{ @"Event_Notify": EVENT_NOTIFY }; | ||
| 50 | } | ||
| 51 | |||
| 52 | + (BOOL)requiresMainQueueSetup | ||
| 53 | { | ||
| 54 | return YES; | ||
| 55 | } | ||
| 56 | |||
| 57 | |||
| 58 | -(BG5S*)getDeviceWithMac:(NSString*)mac{ | ||
| 59 | |||
| 60 | BG5SController *controller = [BG5SController sharedController]; | ||
| 61 | NSArray *bgDeviceArray = [controller getAllCurrentInstace]; | ||
| 62 | |||
| 63 | for(BG5S *tempDevice in bgDeviceArray){ | ||
| 64 | if([mac isEqualToString:tempDevice.serialNumber]){ | ||
| 65 | tempDevice.delegate = self; | ||
| 66 | return tempDevice; | ||
| 67 | } | ||
| 68 | } | ||
| 69 | return nil; | ||
| 70 | } | ||
| 71 | |||
| 72 | RCT_EXPORT_METHOD(getAllConnectedDevices){ | ||
| 73 | |||
| 74 | |||
| 75 | NSArray*bgDeviceArray= [[BG5SController sharedController] getAllCurrentInstace]; | ||
| 76 | |||
| 77 | NSMutableArray*deviceMacArray=[NSMutableArray array]; | ||
| 78 | |||
| 79 | for (int i=0; i<[bgDeviceArray count]; i++) { | ||
| 80 | |||
| 81 | BG5S *bg5s = [bgDeviceArray objectAtIndex:i]; | ||
| 82 | |||
| 83 | [deviceMacArray addObject:bg5s.serialNumber]; | ||
| 84 | |||
| 85 | } | ||
| 86 | |||
| 87 | NSDictionary* deviceInfo = @{kACTION_KEY:@"ACTION_GET_ALL_CONNECTED_DEVICES",@"devices":deviceMacArray}; | ||
| 88 | |||
| 89 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 90 | } | ||
| 91 | |||
| 92 | |||
| 93 | //综合查询 | ||
| 94 | RCT_EXPORT_METHOD(getStatusInfo:(nonnull NSString *)mac){ | ||
| 95 | |||
| 96 | if ([self getDeviceWithMac:mac]!=nil) { | ||
| 97 | __weak typeof(self) weakSelf = self; | ||
| 98 | [[self getDeviceWithMac:mac] queryStateInfoWithSuccess:^(BG5SStateInfo *stateInfo) { | ||
| 99 | |||
| 100 | |||
| 101 | NSDateFormatter *mydateFormatter = [[NSDateFormatter alloc] init]; | ||
| 102 | [mydateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; | ||
| 103 | NSString *dateStr = [mydateFormatter stringFromDate:stateInfo.deviceDate]; | ||
| 104 | |||
| 105 | NSDictionary* response = @{ | ||
| 106 | kMAC_KEY:mac, | ||
| 107 | kACTION_KEY:kACTION_GET_STATUS_INFO, | ||
| 108 | INFO_BATTERY_LEVEL:@(stateInfo.batteryValue), | ||
| 109 | INFO_TIME:dateStr, | ||
| 110 | INFO_TIMEZONE:@(stateInfo.deviceTimeZone), | ||
| 111 | INFO_USED_STRIP:@(stateInfo.stripUsedValue), | ||
| 112 | INFO_OFFLINE_DATA_NUM:@(stateInfo.offlineDataQuantity), | ||
| 113 | INFO_CODE_VERSION_BLOOD:@(stateInfo.bloodCodeVersion), | ||
| 114 | INFO_CODE_VERSION_CTL:@(stateInfo.ctlCodeVersion), | ||
| 115 | INFO_UNIT:(stateInfo.unit == BGUnit_mmolPL)?@"mmol":((stateInfo.unit == BGUnit_mgPmL)?@"mg":@"unknown"), | ||
| 116 | }; | ||
| 117 | |||
| 118 | [weakSelf sendEventWithName:EVENT_NOTIFY body:response]; | ||
| 119 | |||
| 120 | |||
| 121 | } errorBlock:^(BG5SError error, NSString *detailInfo) { | ||
| 122 | [weakSelf sendMeasureErrorEventWithMac:mac errorId:error]; | ||
| 123 | }]; | ||
| 124 | }else{ | ||
| 125 | [self sendNoMatchedDeviceEventWithMac:mac]; | ||
| 126 | } | ||
| 127 | } | ||
| 128 | |||
| 129 | //同步时间 | ||
| 130 | RCT_EXPORT_METHOD(setTime:(nonnull NSString *)mac date:(nonnull NSString *)date timezone:(nonnull NSNumber *)timezone){ | ||
| 131 | if ([self getDeviceWithMac:mac]) { | ||
| 132 | |||
| 133 | |||
| 134 | NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | ||
| 135 | |||
| 136 | [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; | ||
| 137 | |||
| 138 | NSDate*mydate=[dateFormatter dateFromString:date]; | ||
| 139 | |||
| 140 | |||
| 141 | __weak typeof(self) weakSelf = self; | ||
| 142 | [[self getDeviceWithMac:mac] setTimeWithDate:mydate timezone:[timezone floatValue] successBlock:^{ | ||
| 143 | [weakSelf sendEventWithName:EVENT_NOTIFY body:@{ | ||
| 144 | kMAC_KEY:mac, | ||
| 145 | kACTION_KEY:kACTION_SET_TIME, | ||
| 146 | }]; | ||
| 147 | } errorBlock:^(BG5SError error, NSString *detailInfo) { | ||
| 148 | [weakSelf sendMeasureErrorEventWithMac:mac errorId:error]; | ||
| 149 | }]; | ||
| 150 | }else{ | ||
| 151 | [self sendNoMatchedDeviceEventWithMac:mac]; | ||
| 152 | } | ||
| 153 | } | ||
| 154 | |||
| 155 | ////同步时间 | ||
| 156 | //RCT_EXPORT_METHOD(setTime:(nonnull NSString *)mac){ | ||
| 157 | // if ([self getDeviceWithMac:mac]) { | ||
| 158 | // | ||
| 159 | // __weak typeof(self) weakSelf = self; | ||
| 160 | // | ||
| 161 | // NSString *zone = [[NSTimeZone systemTimeZone] description]; | ||
| 162 | // NSString *time = [[zone componentsSeparatedByString:@"offset "] objectAtIndex:1]; | ||
| 163 | // float floatTimeZone = time.floatValue/3600; | ||
| 164 | // | ||
| 165 | // [[self getDeviceWithMac:mac] setTimeWithDate:[NSDate date] timezone:floatTimeZone successBlock:^{ | ||
| 166 | // [weakSelf sendEventWithName:EVENT_NOTIFY body:@{ | ||
| 167 | // kMAC_KEY:mac, | ||
| 168 | // kACTION_KEY:kACTION_SET_TIME, | ||
| 169 | // }]; | ||
| 170 | // } errorBlock:^(BG5SError error, NSString *detailInfo) { | ||
| 171 | // [weakSelf sendMeasureErrorEventWithMac:mac errorId:error]; | ||
| 172 | // }]; | ||
| 173 | // }else{ | ||
| 174 | // [self sendNoMatchedDeviceEventWithMac:mac]; | ||
| 175 | // } | ||
| 176 | //} | ||
| 177 | |||
| 178 | //设置单位 | ||
| 179 | RCT_EXPORT_METHOD(setUnit:(nonnull NSString *)mac type:(nonnull NSNumber *)type){ | ||
| 180 | if ([self getDeviceWithMac:mac]) { | ||
| 181 | |||
| 182 | BGUnit tempUnit = BGUnit_mmolPL; | ||
| 183 | if ([type isEqual:@(BGUnit_mmolPL)]) { | ||
| 184 | tempUnit = BGUnit_mmolPL; | ||
| 185 | } else if([type isEqual:@(BGUnit_mgPmL)]) { | ||
| 186 | tempUnit = BGUnit_mgPmL; | ||
| 187 | } else { | ||
| 188 | [self sendNoMatchedDeviceEventWithMac:mac]; | ||
| 189 | return; | ||
| 190 | } | ||
| 191 | __weak typeof(self) weakSelf = self; | ||
| 192 | |||
| 193 | [[self getDeviceWithMac:mac] setUnit:tempUnit successBlock:^{ | ||
| 194 | [weakSelf sendEventWithName:EVENT_NOTIFY body:@{ | ||
| 195 | kMAC_KEY:mac, | ||
| 196 | kACTION_KEY:kACTION_SET_UNIT, | ||
| 197 | }]; | ||
| 198 | } errorBlock:^(BG5SError error, NSString *detailInfo) { | ||
| 199 | [weakSelf sendMeasureErrorEventWithMac:mac errorId:error]; | ||
| 200 | |||
| 201 | }]; | ||
| 202 | |||
| 203 | }else{ | ||
| 204 | [self sendNoMatchedDeviceEventWithMac:mac]; | ||
| 205 | } | ||
| 206 | } | ||
| 207 | |||
| 208 | //设置离线模式 Is offline measurement allowed 0:allowed 1:Offline measurement is not allowed | ||
| 209 | RCT_EXPORT_METHOD(setOfflineModel:(nonnull NSString *)mac type:(nonnull NSNumber *)type){ | ||
| 210 | if ([self getDeviceWithMac:mac]) { | ||
| 211 | |||
| 212 | BOOL modelType=YES; | ||
| 213 | |||
| 214 | if ([type intValue]==0) { | ||
| 215 | modelType=NO; | ||
| 216 | }else{ | ||
| 217 | |||
| 218 | modelType=YES; | ||
| 219 | } | ||
| 220 | |||
| 221 | |||
| 222 | __weak typeof(self) weakSelf = self; | ||
| 223 | |||
| 224 | |||
| 225 | [[self getDeviceWithMac:mac] setIsOfflineMeasurementAllowed:modelType successBlock:^{ | ||
| 226 | [weakSelf sendEventWithName:EVENT_NOTIFY body:@{ | ||
| 227 | kMAC_KEY:mac, | ||
| 228 | kACTION_KEY:kACTION_SET_OFFINEMODEL, | ||
| 229 | }]; | ||
| 230 | } errorBlock:^(BG5SError error, NSString *detailInfo) { | ||
| 231 | |||
| 232 | [weakSelf sendMeasureErrorEventWithMac:mac errorId:error]; | ||
| 233 | }]; | ||
| 234 | |||
| 235 | }else{ | ||
| 236 | [self sendNoMatchedDeviceEventWithMac:mac]; | ||
| 237 | } | ||
| 238 | } | ||
| 239 | |||
| 240 | |||
| 241 | //删除试条使用条数 | ||
| 242 | RCT_EXPORT_METHOD(deleteUsedStrip:(nonnull NSString *)mac){ | ||
| 243 | if ([self getDeviceWithMac:mac]) { | ||
| 244 | __weak typeof(self) weakSelf = self; | ||
| 245 | [[self getDeviceWithMac:mac] deleteStripUsedInfoWithSuccessBlock:^{ | ||
| 246 | [self sendEventWithName:EVENT_NOTIFY body:@{ | ||
| 247 | kMAC_KEY:mac, | ||
| 248 | kACTION_KEY:kACTION_DELETE_USED_STRIP, | ||
| 249 | }]; | ||
| 250 | } errorBlock:^(BG5SError error, NSString *detailInfo) { | ||
| 251 | [weakSelf sendMeasureErrorEventWithMac:mac errorId:error]; | ||
| 252 | }]; | ||
| 253 | }else{ | ||
| 254 | [self sendNoMatchedDeviceEventWithMac:mac]; | ||
| 255 | } | ||
| 256 | } | ||
| 257 | |||
| 258 | //删除离线数据 | ||
| 259 | RCT_EXPORT_METHOD(deleteOfflineData:(nonnull NSString *)mac){ | ||
| 260 | if ([self getDeviceWithMac:mac]) { | ||
| 261 | __weak typeof(self) weakSelf = self; | ||
| 262 | [[self getDeviceWithMac:mac] deleteRecordWithSuccessBlock:^{ | ||
| 263 | [self sendEventWithName:EVENT_NOTIFY body:@{ | ||
| 264 | kMAC_KEY:mac, | ||
| 265 | kACTION_KEY:kACTION_DELETE_OFFLINE_DATA, | ||
| 266 | }]; | ||
| 267 | } errorBlock:^(BG5SError error, NSString *detailInfo) { | ||
| 268 | [weakSelf sendMeasureErrorEventWithMac:mac errorId:error]; | ||
| 269 | |||
| 270 | }]; | ||
| 271 | }else{ | ||
| 272 | [self sendNoMatchedDeviceEventWithMac:mac]; | ||
| 273 | } | ||
| 274 | } | ||
| 275 | |||
| 276 | |||
| 277 | //同步离线数据 | ||
| 278 | RCT_EXPORT_METHOD(getOfflineData:(nonnull NSString *)mac){ | ||
| 279 | |||
| 280 | if ([self getDeviceWithMac:mac]) { | ||
| 281 | __weak typeof(self) weakSelf = self; | ||
| 282 | [[self getDeviceWithMac:mac] queryRecordWithSuccessBlock:^(NSArray *array) { | ||
| 283 | |||
| 284 | NSMutableArray * tempArr = [[NSMutableArray alloc]init]; | ||
| 285 | |||
| 286 | for(BG5SRecordModel *model in array) { | ||
| 287 | NSDate *tempDate = model.measureDate; | ||
| 288 | BOOL flag = model.canCorrect; | ||
| 289 | |||
| 290 | //将时间格式转化成字符串,适配plugin和react native | ||
| 291 | NSDateFormatter *mydateFormatter = [[NSDateFormatter alloc] init]; | ||
| 292 | [mydateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; | ||
| 293 | NSString *dateStr = [mydateFormatter stringFromDate:tempDate]; | ||
| 294 | |||
| 295 | NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:dateStr,@"data_measure_time",@(model.value),@"data_value",model.dataID,@"dataID",@(model.timeZone),@"data_measure_timezone",flag,@"data_time_proof", nil]; | ||
| 296 | |||
| 297 | [tempArr addObject:dic]; | ||
| 298 | } | ||
| 299 | |||
| 300 | NSDictionary*hisDic=[NSDictionary dictionaryWithObjectsAndKeys:tempArr,@"history", nil]; | ||
| 301 | |||
| 302 | |||
| 303 | NSDictionary *deviceInfo = @{@"mac":mac,@"action":kACTION_GET_OFFLINE_DATA,kGET_OFFLINEDATA:hisDic,@"type":@"BG5S"}; | ||
| 304 | |||
| 305 | [weakSelf sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 306 | |||
| 307 | } errorBlock:^(BG5SError error, NSString *detailInfo) { | ||
| 308 | [weakSelf sendMeasureErrorEventWithMac:mac errorId:error]; | ||
| 309 | }]; | ||
| 310 | }else{ | ||
| 311 | [self sendNoMatchedDeviceEventWithMac:mac]; | ||
| 312 | |||
| 313 | } | ||
| 314 | } | ||
| 315 | |||
| 316 | |||
| 317 | //开始测量 | ||
| 318 | RCT_EXPORT_METHOD(startMeasure:(nonnull NSString *)mac type:(nonnull NSNumber *)type){ | ||
| 319 | if ([self getDeviceWithMac:mac]) { | ||
| 320 | __weak typeof(self) weakSelf = self; | ||
| 321 | |||
| 322 | BGMeasureMode measureMode = BGMeasureMode_Blood; | ||
| 323 | if ([type isEqual:@(BGMeasureMode_Blood)]) { | ||
| 324 | measureMode = BGMeasureMode_Blood; | ||
| 325 | } else if([type isEqual:@(BGMeasureMode_NoBlood)]) { | ||
| 326 | measureMode = BGMeasureMode_NoBlood; | ||
| 327 | } else { | ||
| 328 | [self sendNoMatchedDeviceEventWithMac:mac]; | ||
| 329 | return; | ||
| 330 | } | ||
| 331 | |||
| 332 | [[self getDeviceWithMac:mac] startMeasure:measureMode withSuccessBlock:^{ | ||
| 333 | [weakSelf sendEventWithName:EVENT_NOTIFY body:@{ | ||
| 334 | kMAC_KEY:mac, | ||
| 335 | kACTION_KEY:kACTION_START_MEASURE, | ||
| 336 | }]; | ||
| 337 | } errorBlock:^(BG5SError error, NSString *detailInfo) { | ||
| 338 | [weakSelf sendMeasureErrorEventWithMac:mac errorId:error]; | ||
| 339 | |||
| 340 | }]; | ||
| 341 | }else{ | ||
| 342 | [self sendNoMatchedDeviceEventWithMac:mac]; | ||
| 343 | } | ||
| 344 | } | ||
| 345 | |||
| 346 | - (void)device:(BG5S *)device occurError:(BG5SError)error errorDescription:(NSString *)errorDescription{ | ||
| 347 | NSLog(@"下位机主发的错误信息:%d",(int)error); | ||
| 348 | [self sendMeasureErrorEventWithMac:device.serialNumber errorId:error]; | ||
| 349 | |||
| 350 | } | ||
| 351 | - (void)device:(BG5S *)device stripStateDidUpdate:(BG5SStripState)state{ | ||
| 352 | NSLog(@"试条状态:%@",(state == BG5SStripState_Insert)?@"插入":@"拔出"); | ||
| 353 | |||
| 354 | if (state == BG5SStripState_Insert) { | ||
| 355 | [self sendEventWithName:EVENT_NOTIFY body:@{ | ||
| 356 | kMAC_KEY:device.serialNumber, | ||
| 357 | kACTION_KEY:kACTION_STRIP_IN, | ||
| 358 | }]; | ||
| 359 | }else{ | ||
| 360 | [self sendEventWithName:EVENT_NOTIFY body:@{ | ||
| 361 | kMAC_KEY:device.serialNumber, | ||
| 362 | kACTION_KEY:kACTION_STRIP_OUT, | ||
| 363 | }]; | ||
| 364 | } | ||
| 365 | |||
| 366 | |||
| 367 | } | ||
| 368 | - (void)deviceDropBlood:(BG5S *)device{ | ||
| 369 | NSLog(@"滴血"); | ||
| 370 | [self sendEventWithName:EVENT_NOTIFY body:@{ | ||
| 371 | kMAC_KEY:device.serialNumber, | ||
| 372 | kACTION_KEY:kACTION_GET_BLOOD, | ||
| 373 | }]; | ||
| 374 | } | ||
| 375 | - (void)device:(BG5S *)device dataID:(NSString *)dataID measureReult:(NSInteger)result{ | ||
| 376 | NSLog(@"结果:%d",(int)result); | ||
| 377 | // NSDictionary *resultDic = [NSDictionary dictionaryWithObjectsAndKeys:@(result),@"value",dataID,@"dataID", nil]; | ||
| 378 | |||
| 379 | [self sendEventWithName:EVENT_NOTIFY body:@{ | ||
| 380 | kMAC_KEY:device.serialNumber, | ||
| 381 | RESULT_VALUE:@(result), | ||
| 382 | kDATA_ID:dataID, | ||
| 383 | |||
| 384 | kACTION_KEY:kACTION_RESULT, | ||
| 385 | }]; | ||
| 386 | } | ||
| 387 | - (void)device:(BG5S *)device chargeStateDidUpdate:(BG5SChargeState)state{ | ||
| 388 | NSLog(@"充电线状态:%@",(state == BG5SChargeState_Charging)?@"插入":@"拔出"); | ||
| 389 | |||
| 390 | if (state == BG5SChargeState_Charging) { | ||
| 391 | [self sendEventWithName:EVENT_NOTIFY body:@{ | ||
| 392 | kMAC_KEY:device.serialNumber, | ||
| 393 | kACTION_KEY:kACTION_ENTER_CHARGED_STATE, | ||
| 394 | }]; | ||
| 395 | }else{ | ||
| 396 | [self sendEventWithName:EVENT_NOTIFY body:@{ | ||
| 397 | kMAC_KEY:device.serialNumber, | ||
| 398 | kACTION_KEY:kACTION_LEAVE_CHARGED_STATE, | ||
| 399 | }]; | ||
| 400 | |||
| 401 | } | ||
| 402 | |||
| 403 | } | ||
| 404 | |||
| 405 | |||
| 406 | //断开连接 | ||
| 407 | RCT_EXPORT_METHOD(disConnect:(nonnull NSString *)mac){ | ||
| 408 | if ([self getDeviceWithMac:mac]!=nil) { | ||
| 409 | |||
| 410 | [[self getDeviceWithMac:mac] disconnectDevice]; | ||
| 411 | }else{ | ||
| 412 | |||
| 413 | } | ||
| 414 | } | ||
| 415 | |||
| 416 | //开始离线数据修正 | ||
| 417 | RCT_EXPORT_METHOD(adjustOfflineData:(nonnull NSString *)mac timeString:(nonnull NSString *)timeString array:(nonnull NSArray *)array ){ | ||
| 418 | if ([self getDeviceWithMac:mac]!=nil) { | ||
| 419 | |||
| 420 | if (array.count > 0 ) { | ||
| 421 | NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; | ||
| 422 | [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; | ||
| 423 | NSDate *date = [formatter dateFromString:timeString]; | ||
| 424 | |||
| 425 | NSArray *correctArray = [[self getDeviceWithMac:mac] processData:array deviceDate:date]; | ||
| 426 | } | ||
| 427 | |||
| 428 | [self sendEventWithName:EVENT_NOTIFY body:@{ | ||
| 429 | kMAC_KEY:mac, | ||
| 430 | kACTION_KEY:kACTION_ADJUST_OFFLINE_DATA, | ||
| 431 | }]; | ||
| 432 | |||
| 433 | }else{ | ||
| 434 | [self sendNoMatchedDeviceEventWithMac:mac]; | ||
| 435 | |||
| 436 | } | ||
| 437 | } | ||
| 438 | |||
| 439 | - (void)sendMeasureErrorEventWithMac:(NSString *)mac errorId:(BG5SError)errorId{ | ||
| 440 | |||
| 441 | |||
| 442 | NSString *errorDescription = @""; | ||
| 443 | |||
| 444 | switch (errorId) { | ||
| 445 | case 0: | ||
| 446 | errorDescription = @"Only showed in BG5S's screen and need charging."; | ||
| 447 | break; | ||
| 448 | case 1: | ||
| 449 | errorDescription = @"Strip removed in the middle of reading, repeat the test with a new strip."; | ||
| 450 | break; | ||
| 451 | case 2: | ||
| 452 | errorDescription = @"Reference voltage error, not normal measurement, please repeat the test."; | ||
| 453 | break; | ||
| 454 | case 3: | ||
| 455 | errorDescription = @"Strip is used or unknown moisture detected, discard the test strip and repeat the test with a new strip."; | ||
| 456 | break; | ||
| 457 | case 4: | ||
| 458 | errorDescription = @"Reading transmission error. Repeat the test with a new test strip. If the problem persists, contact iHealth customer service for assistance."; | ||
| 459 | break; | ||
| 460 | case 5: | ||
| 461 | errorDescription = @"The environmental temperature is beyond normal range, place the meter at room temperature for at least 30 minutes, then repeat the test."; | ||
| 462 | break; | ||
| 463 | case 6: | ||
| 464 | errorDescription = @"The environmental temperature is beyond normal range, place the meter at room temperature for at least 30 minutes, then repeat the test."; | ||
| 465 | break; | ||
| 466 | case 7: | ||
| 467 | errorDescription = @"Only showed in BG5S's screen."; | ||
| 468 | break; | ||
| 469 | case 8: | ||
| 470 | errorDescription = @"Glucose test result is low."; | ||
| 471 | break; | ||
| 472 | case 9: | ||
| 473 | errorDescription = @"Glucose test result is high."; | ||
| 474 | break; | ||
| 475 | case 10: | ||
| 476 | errorDescription = @"Reset and if the problem persists, contact iHealth customer service for assistance."; | ||
| 477 | break; | ||
| 478 | case 400: | ||
| 479 | errorDescription = @"arameter input error."; | ||
| 480 | break; | ||
| 481 | case 401: | ||
| 482 | errorDescription = @"Quantity not match"; | ||
| 483 | break; | ||
| 484 | case 402: | ||
| 485 | errorDescription = @"Single packet is not full."; | ||
| 486 | break; | ||
| 487 | case 403: | ||
| 488 | errorDescription = @"Packet index not match."; | ||
| 489 | break; | ||
| 490 | case 500: | ||
| 491 | errorDescription = @"Command timeout"; | ||
| 492 | break; | ||
| 493 | case 501: | ||
| 494 | errorDescription = @"Command is not supported for current device."; | ||
| 495 | break; | ||
| 496 | default: | ||
| 497 | break; | ||
| 498 | } | ||
| 499 | |||
| 500 | [self sendEventWithName:EVENT_NOTIFY body:@{ | ||
| 501 | kMAC_KEY:mac, | ||
| 502 | kACTION_KEY:kACTION_ERROR_BG, | ||
| 503 | kERROR_NUM_BG:@(errorId), | ||
| 504 | kERROR_DESCRIPTION_BG:errorDescription | ||
| 505 | }]; | ||
| 506 | } | ||
| 507 | |||
| 508 | |||
| 509 | - (void)sendNoMatchedDeviceEventWithMac:(NSString *)mac{ | ||
| 510 | if (mac && mac.length > 0) { | ||
| 511 | [self sendEventWithName:EVENT_NOTIFY body:@{ | ||
| 512 | kMAC_KEY:mac, | ||
| 513 | kACTION_KEY:kACTION_ERROR_BG, | ||
| 514 | kERROR_NUM_BG:@100 | ||
| 515 | }]; | ||
| 516 | } else { | ||
| 517 | [self sendEventWithName:EVENT_NOTIFY body:@{ | ||
| 518 | kACTION_KEY:kACTION_ERROR_BG, | ||
| 519 | |||
| 520 | kERROR_NUM_BG:@100, | ||
| 521 | kERROR_DESCRIPTION_BG:@"Device disconnect." | ||
| 522 | |||
| 523 | }]; | ||
| 524 | } | ||
| 525 | } | ||
| 526 | |||
| 527 | |||
| 528 | |||
| 529 | @end | ||
