diff options
Diffstat (limited to 'libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG1Module.m')
| -rw-r--r-- | libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG1Module.m | 236 |
1 files changed, 236 insertions, 0 deletions
diff --git a/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG1Module.m b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG1Module.m new file mode 100644 index 0000000..c5c33d3 --- /dev/null +++ b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG1Module.m | |||
| @@ -0,0 +1,236 @@ | |||
| 1 | // | ||
| 2 | // BG1Module.m | ||
| 3 | // ReactNativeIOSLibrary | ||
| 4 | // | ||
| 5 | // Created by daiqingquan on 2016/11/23. | ||
| 6 | // Copyright © 2016年 daiqingquan. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #import "BG1Module.h" | ||
| 10 | #import "BG1ProfileModule.h" | ||
| 11 | #import "BGMacroFile.h" | ||
| 12 | #import "BG1Controller.h" | ||
| 13 | #import "BG1.h" | ||
| 14 | #define EVENT_NOTIFY @"event_notify_bg1" | ||
| 15 | |||
| 16 | @implementation BG1Module | ||
| 17 | |||
| 18 | |||
| 19 | RCT_EXPORT_MODULE() | ||
| 20 | - (NSArray<NSString *> *)supportedEvents { | ||
| 21 | return @[@"event_notify", @"event_scan_device", @"event_scan_finish", | ||
| 22 | @"event_device_connected", @"event_device_connect_failed", | ||
| 23 | @"event_device_disconnect", @"event_authenticate_result", | ||
| 24 | @"event_notify_ts28b", @"event_notify_bg1", | ||
| 25 | @"action_connect_result_for_bg1"]; | ||
| 26 | } | ||
| 27 | |||
| 28 | |||
| 29 | - (NSDictionary *)constantsToExport | ||
| 30 | { | ||
| 31 | return @{ | ||
| 32 | @"Event_Notify":@"event_notify_bg1", | ||
| 33 | |||
| 34 | }; | ||
| 35 | } | ||
| 36 | + (BOOL)requiresMainQueueSetup | ||
| 37 | { | ||
| 38 | return YES; | ||
| 39 | } | ||
| 40 | |||
| 41 | #pragma mark | ||
| 42 | #pragma mark - Init | ||
| 43 | -(id)init | ||
| 44 | { | ||
| 45 | if (self=[super init]) | ||
| 46 | { | ||
| 47 | |||
| 48 | [BG1Controller shareBG1Controller]; | ||
| 49 | |||
| 50 | } | ||
| 51 | return self; | ||
| 52 | } | ||
| 53 | |||
| 54 | |||
| 55 | |||
| 56 | -(BG1*)getBG1Instance{ | ||
| 57 | |||
| 58 | BG1Controller *controller = [BG1Controller shareBG1Controller]; | ||
| 59 | BG1 *bg1Instance = [controller getCurrentBG1Instance]; | ||
| 60 | if(bg1Instance != nil) | ||
| 61 | { | ||
| 62 | return bg1Instance; | ||
| 63 | } | ||
| 64 | else | ||
| 65 | { | ||
| 66 | return nil; | ||
| 67 | } | ||
| 68 | |||
| 69 | } | ||
| 70 | |||
| 71 | |||
| 72 | #pragma mark | ||
| 73 | #pragma mark - Method | ||
| 74 | |||
| 75 | |||
| 76 | RCT_EXPORT_METHOD(sendCode:(nonnull NSString *)QR:(nonnull NSNumber *)codeType:(nonnull NSNumber *)testType){ | ||
| 77 | |||
| 78 | |||
| 79 | if ([self getBG1Instance]!=nil) { | ||
| 80 | |||
| 81 | if (QR ==nil || QR.length<30) { | ||
| 82 | NSDictionary* deviceInfo = @{@"mac":@"",@"action":@"action_measure_error_for_bg1",@"action_measure_error_for_bg1":@400,@"description":@"Parameter input error."}; | ||
| 83 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 84 | |||
| 85 | return; | ||
| 86 | } | ||
| 87 | |||
| 88 | NSDictionary *codeDic = [[self getBG1Instance]codeStripStrAnalysis:QR]; | ||
| 89 | NSNumber *bottleID = [codeDic objectForKey:@"bottleId"]; | ||
| 90 | NSDate *dueDate = [codeDic objectForKey:@"overDate"]; | ||
| 91 | NSNumber *remainNum = [codeDic objectForKey:@"stripNum"]; | ||
| 92 | |||
| 93 | BGMeasureMode bgMeasureModel = BGMeasureMode_Blood; | ||
| 94 | if(codeType.integerValue == 2) | ||
| 95 | { | ||
| 96 | bgMeasureModel = BGMeasureMode_NoBlood; | ||
| 97 | } | ||
| 98 | |||
| 99 | BGCodeMode bgCodeModel =BGCodeMode_GOD; | ||
| 100 | if(codeType.integerValue == 2) | ||
| 101 | { | ||
| 102 | bgCodeModel = BGCodeMode_GDH; | ||
| 103 | } | ||
| 104 | [[self getBG1Instance] commandBG1MeasureMode:bgMeasureModel withCodeMode:bgCodeModel withCodeString:QR withSendCodeResultBlock:^{ | ||
| 105 | |||
| 106 | NSDictionary* deviceInfo = @{@"mac":@"",@"action":@"action_sendcode_result_for_bg1",@"set_bottle_message":@true}; | ||
| 107 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 108 | |||
| 109 | } withStripInBlock:^{ | ||
| 110 | |||
| 111 | NSDictionary* deviceInfo = @{@"mac":@"",@"action":@"action_measure_strip_in_for_bg1"}; | ||
| 112 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 113 | |||
| 114 | } withBloodBlock:^{ | ||
| 115 | |||
| 116 | NSDictionary* deviceInfo = @{@"mac":@"",@"action":@"action_measure_get_blood_for_bg1"}; | ||
| 117 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 118 | |||
| 119 | } withResultBlock:^(NSDictionary *result) { | ||
| 120 | |||
| 121 | NSDate *measureDate = [result objectForKey:@"Date"]; | ||
| 122 | |||
| 123 | //将时间格式转化成字符串,适配plugin和react native | ||
| 124 | NSDateFormatter *mydateFormatter = [[NSDateFormatter alloc] init]; | ||
| 125 | [mydateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; | ||
| 126 | NSString *dateStr = [mydateFormatter stringFromDate:measureDate]; | ||
| 127 | |||
| 128 | NSDictionary *resultDic = [NSDictionary dictionaryWithObjectsAndKeys:dateStr,@"date",[result objectForKey:@"Result"],@"value",[result objectForKey:@"dataID"],@"dataID", nil]; | ||
| 129 | |||
| 130 | NSDictionary* deviceInfo = @{@"mac":@"",@"action":@"action_measure_result_for_bg1",@"result":resultDic}; | ||
| 131 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 132 | |||
| 133 | } withStripOutBlock:^{ | ||
| 134 | |||
| 135 | NSDictionary* deviceInfo = @{@"mac":@"",@"action":@"action_measure_strip_out_for_bg1"}; | ||
| 136 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 137 | |||
| 138 | } withErrorBlock:^(BG1Error errorID) { | ||
| 139 | |||
| 140 | |||
| 141 | NSString *descriptionStr = @""; | ||
| 142 | |||
| 143 | switch (errorID) { | ||
| 144 | case BG1Error_LowBattery: | ||
| 145 | descriptionStr=@"Battery is low."; | ||
| 146 | break; | ||
| 147 | case BG1Error_ResultOutOfMeasurementRage: | ||
| 148 | descriptionStr=@"Glucose test result is out of the measurement range."; | ||
| 149 | break; | ||
| 150 | case BG1Error_UnvalidReferenceVoltage: | ||
| 151 | descriptionStr=@"2.5V reference voltage error, not normal measurement, please repeat the test."; | ||
| 152 | break; | ||
| 153 | case BG1Error_StripUsed: | ||
| 154 | descriptionStr=@"Strip is used or unknown moisture detected, discard the test strip and repeat the test with a new strip."; | ||
| 155 | break; | ||
| 156 | case BG1Error_CodeError: | ||
| 157 | descriptionStr=@"CODE value check error. This error need let user scan code and call the send code function again,no alert need to show."; | ||
| 158 | break; | ||
| 159 | case BG1Error_RoomTemperatureOutOfRange1: | ||
| 160 | case BG1Error_RoomTemperatureOutOfRange2: | ||
| 161 | descriptionStr=@"The environmental temperature is beyond normal range, place the meter at room temperature for at least 30 minutes, then repeat the test."; | ||
| 162 | break; | ||
| 163 | case BG1Error_ResultLow: | ||
| 164 | descriptionStr=@"Glucose test result is low."; | ||
| 165 | break; | ||
| 166 | case BG1Error_ResultHigh: | ||
| 167 | descriptionStr=@"Glucose test result is high."; | ||
| 168 | break; | ||
| 169 | case BG1Error_DisConnented: | ||
| 170 | descriptionStr=@"BG disConnented."; | ||
| 171 | break; | ||
| 172 | case BG1Error_SleepingMode: | ||
| 173 | descriptionStr=@"BG sleeping mode."; | ||
| 174 | break; | ||
| 175 | case BG1Error_ParameterError: | ||
| 176 | descriptionStr=@"Parameter input error."; | ||
| 177 | break; | ||
| 178 | default: | ||
| 179 | descriptionStr=@"BG unknown."; | ||
| 180 | break; | ||
| 181 | } | ||
| 182 | |||
| 183 | NSDictionary* deviceInfo = @{@"mac":@"",@"action":@"action_measure_error_for_bg1",@"action_measure_error_for_bg1":[NSNumber numberWithInt:errorID],@"description":descriptionStr}; | ||
| 184 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 185 | |||
| 186 | }]; | ||
| 187 | |||
| 188 | |||
| 189 | |||
| 190 | |||
| 191 | |||
| 192 | }else{ | ||
| 193 | |||
| 194 | NSDictionary* deviceInfo = @{@"mac":@"",@"action":@"action_measure_error_for_bg1",@"action_measure_error_for_bg1":@100,@"description":@"BG disConnented." }; | ||
| 195 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 196 | |||
| 197 | } | ||
| 198 | |||
| 199 | } | ||
| 200 | |||
| 201 | |||
| 202 | |||
| 203 | |||
| 204 | |||
| 205 | RCT_EXPORT_METHOD(getBottleInfoFromQR:(nonnull NSString *)QR){ | ||
| 206 | |||
| 207 | |||
| 208 | if ([self getBG1Instance]!=nil) { | ||
| 209 | |||
| 210 | NSDictionary *codeDic = [[self getBG1Instance]codeStripStrAnalysis:QR]; | ||
| 211 | NSDate *tempDate = [codeDic objectForKey:@"DueDate"]; | ||
| 212 | |||
| 213 | //将时间格式转化成字符串,适配plugin和react native | ||
| 214 | NSDateFormatter *mydateFormatter = [[NSDateFormatter alloc] init]; | ||
| 215 | [mydateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; | ||
| 216 | NSTimeZone *dongBaTimeZone = [NSTimeZone timeZoneForSecondsFromGMT:8*60*60]; | ||
| 217 | [mydateFormatter setTimeZone:dongBaTimeZone]; | ||
| 218 | NSString *dateStr = [mydateFormatter stringFromDate:tempDate]; | ||
| 219 | |||
| 220 | NSNumber *bottleID = [codeDic objectForKey:@"BottleID"]; | ||
| 221 | NSNumber *remainNum = [codeDic objectForKey:@"StripNum"]; | ||
| 222 | |||
| 223 | NSDictionary* deviceInfo = @{@"mac":@"",@"action":@"action_code_analysis_bg",@"stripNum":remainNum,@"overDate":dateStr,@"bottleId":bottleID}; | ||
| 224 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 225 | |||
| 226 | }else{ | ||
| 227 | |||
| 228 | NSDictionary* deviceInfo = @{@"mac":@"",@"action":@"action_measure_error_for_bg1",@"action_measure_error_for_bg1":@100,@"description":@"BG disConnented."}; | ||
| 229 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 230 | |||
| 231 | } | ||
| 232 | |||
| 233 | } | ||
| 234 | |||
| 235 | |||
| 236 | @end | ||
