summaryrefslogtreecommitdiff
path: root/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG5Module.m
diff options
context:
space:
mode:
Diffstat (limited to 'libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG5Module.m')
-rw-r--r--libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG5Module.m643
1 files changed, 643 insertions, 0 deletions
diff --git a/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG5Module.m b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG5Module.m
new file mode 100644
index 0000000..c0a7fcf
--- /dev/null
+++ b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG5Module.m
@@ -0,0 +1,643 @@
1//
2// BG5Module.m
3// ReactNativeIOSLibrary
4//
5// Created by daiqingquan on 2016/11/23.
6// Copyright © 2016年 daiqingquan. All rights reserved.
7//
8
9#import "BG5Module.h"
10#import "BGProfileModule.h"
11#import "BGMacroFile.h"
12#import "BG5Controller.h"
13#import "BG5.h"
14
15#define EVENT_NOTIFY @"event_notify_bg5"
16#define kMAC_KEY @"mac"
17#define kACTION_KEY @"action"
18
19@interface BG5Module()
20
21/**
22 保存设备回复的开机模式
23 */
24@property (assign, nonatomic) NSInteger deviceSelectedOpenMode;
25
26/**
27 保存用户传入的测量模式
28 */
29@property (assign, nonatomic) NSInteger userSelectedMeasureMode;
30
31@end
32
33@implementation BG5Module
34
35
36RCT_EXPORT_MODULE()
37- (NSArray<NSString *> *)supportedEvents {
38 return @[@"event_notify", @"event_scan_device", @"event_scan_finish",
39 @"event_device_connected", @"event_device_connect_failed",
40 @"event_device_disconnect", @"event_authenticate_result",
41 @"event_notify_ts28b", @"event_notify_bg1",
42 @"action_connect_result_for_bg1"];
43}
44
45
46- (NSDictionary *)constantsToExport{
47 return @{
48 @"Event_Notify":EVENT_NOTIFY,
49 };
50}
51+ (BOOL)requiresMainQueueSetup
52{
53 return YES;
54}
55#pragma mark - Objc Method
56-(id)init{
57 self = [super init];
58 if (self) {
59 [BG5Controller shareIHBg5Controller];
60 self.deviceSelectedOpenMode = 0;// 初始化时,将开机模式设置为0;目的是,在用户调用开始测量方法时,判断用户是否已经调用过发码方法。调用过发码方法后,openMode的值是1或2
61 self.userSelectedMeasureMode = 0;// 初始化时,将开机模式设置为0;目的是,在用户调用开始测量方法时,判断用户发码时传入的测量模式 是否等于 开始测量传入的测量模式
62 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clear) name:BG5DisConnectNoti object:nil];
63 }
64 return self;
65}
66
67-(void)dealloc{
68 [[NSNotificationCenter defaultCenter]removeObserver:self];
69}
70
71- (void)clear{
72 self.deviceSelectedOpenMode = 0;
73 self.userSelectedMeasureMode = 0;
74}
75
76/**
77 返回传入的Mac地址对应的BG5对象
78
79 @param mac mac地址,需要完整的mac地址
80 @return BG5对象;如果没有匹配mac地址的BG5对象,那么返回nil
81 */
82-(BG5*)getDeviceWithMac:(NSString*)mac{
83
84 BG5Controller *controller = [BG5Controller shareIHBg5Controller];
85 NSArray *BGDeviceArray = [controller getAllCurrentBG5Instace];
86 NSLog(@"%@",BGDeviceArray);
87 for(BG5 *tempBG5 in BGDeviceArray){
88 if([mac isEqualToString:tempBG5.serialNumber]){
89 return tempBG5;
90 }
91 }
92 return nil;
93}
94
95- (void)sendMeasureErrorEventWithMac:(NSString *)mac errorId:(NSNumber *)errorId{
96
97
98 NSString *errorDescription = @"";
99
100 switch (errorId.integerValue) {
101 case 0:
102 errorDescription = @"Battery is low.";
103 break;
104 case 1:
105 errorDescription = @"Glucose test result is out of the measurement range.";
106 break;
107 case 2:
108 errorDescription = @"Unknown interference detected, please repeat the test.";
109 break;
110 case 3:
111 errorDescription = @"Strip is used or unknown moisture detected, discard the test strip and repeat the test with a new strip.";
112 break;
113 case 4:
114 errorDescription = @"Reading transmission error. Repeat the test with a new test strip. If the problem persists, contact iHealth customer service for assistance.";
115 break;
116 case 5:
117 errorDescription = @"The environmental temperature is beyond normal range, place the meter at room temperature for at least 30 minutes, then repeat the test.";
118 break;
119 case 6:
120 errorDescription = @"The environmental temperature is beyond normal range, place the meter at room temperature for at least 30 minutes, then repeat the test.";
121 break;
122 case 7:
123 errorDescription = @"Test strip coding error.";
124 break;
125 case 8:
126 errorDescription = @"Communication error, press \"START\" or rescan the code to repeat the test.";
127 break;
128 case 9:
129 errorDescription = @"Strip removed in the middle of reading, repeat the test with a new strip.";
130 break;
131 case 10:
132 errorDescription = @"Insert a new test strip and repeat the test.";
133 break;
134 case 11:
135 errorDescription = @"Cannot write to SN or KEY.";
136 break;
137 case 12:
138 errorDescription = @"Please set time.";
139 break;
140 case 13:
141 errorDescription = @"0 test strips remaining.";
142 break;
143 case 14:
144 errorDescription = @"Test strip expired.";
145 break;
146 case 15:
147 errorDescription = @"Unplug the charging cable before testing.";
148 break;
149 case 18:
150 errorDescription = @"Unplug the charging cable before read the history data";
151 break;
152 case 19:
153 errorDescription = @"Charging line is inserted";
154 break;
155 case 20:
156 errorDescription = @"Charging line pull out";
157 break;
158 case 21:
159 errorDescription = @"The bluetooth module failure";
160 break;
161 case 22:
162 errorDescription = @"Need to set time at first.";
163 break;
164 case 30:
165 errorDescription = @"BG Over Time Error.";
166 break;
167 case 112:
168 errorDescription = @"Device don't support to query energy.";
169 break;
170 case RNBGError_InputParameterError:
171 errorDescription = @"Parameters out of range.";
172 break;
173 case RNBGError_FunctionCallOrderError:
174 errorDescription = @"The order of call is wrong.";
175 break;
176 case RNBGError_MeasureModeNotMatched:
177 errorDescription = @"Measure Mode is not matched in fucntion call (setBottleMessageWithInfo and startMeasure)";
178 break;
179 case RNBGError_DisconnectFunctionNotSupportIniOSPlatform:
180 errorDescription = @"Function(disConnect) is not supported in iOS platform.";
181 break;
182 case RNBGError_getBottleInfoFromQRFunctionInpurParameterError:
183 errorDescription = @"Function(getBottleInfoFromQR) Input Parameter Error";
184 break;
185 default:
186 break;
187 }
188
189 [self sendEventWithName:EVENT_NOTIFY body:@{
190 kMAC_KEY:mac,
191 kACTION_KEY:kACTION_ERROR_BG,
192 kERROR_NUM_BG:errorId,
193 kERROR_DESCRIPTION_BG:errorDescription
194 }];
195}
196
197- (void)sendNoMatchedDeviceEventWithMac:(NSString *)mac{
198 if (mac && mac.length > 0) {
199 [self sendEventWithName:EVENT_NOTIFY body:@{
200 kMAC_KEY:mac,
201 kACTION_KEY:kACTION_ERROR_BG,
202 kERROR_NUM_BG:@100
203 }];
204 } else {
205 [self sendEventWithName:EVENT_NOTIFY body:@{
206 kACTION_KEY:kACTION_ERROR_BG,
207 kERROR_NUM_BG:@100
208 }];
209 }
210
211}
212
213- (void)sendInputParameterErrorEventWithMac:(NSString *)mac{
214 if (mac && mac.length > 0) {
215 [self sendEventWithName:EVENT_NOTIFY body:@{
216 kMAC_KEY:mac,
217 kACTION_KEY:kACTION_ERROR_BG,
218 kERROR_NUM_BG:@400,
219 kERROR_DESCRIPTION_BG:@"Parameters out of range."
220 }];
221 } else {
222 [self sendEventWithName:EVENT_NOTIFY body:@{
223 kACTION_KEY:kACTION_ERROR_BG,
224 kERROR_NUM_BG:@400,
225 kERROR_DESCRIPTION_BG:@"Parameters out of range."
226 }];
227 }
228
229}
230
231#pragma mark - Objc method for BG5Module.js function
232
233#pragma mark-获取连接设备
234RCT_EXPORT_METHOD(getAllConnectedDevices){
235
236
237 NSArray*bg5array= [[BG5Controller shareIHBg5Controller] getAllCurrentBG5Instace];
238
239 NSMutableArray*deviceMacArray=[NSMutableArray array];
240
241 for (int i=0; i<[bg5array count]; i++) {
242
243 BG5*bg5=[bg5array objectAtIndex:i];
244
245 [deviceMacArray addObject:bg5.serialNumber];
246
247 }
248
249 NSDictionary* deviceInfo = @{kACTION_KEY:@"ACTION_GET_ALL_CONNECTED_DEVICES",@"devices":deviceMacArray};
250
251 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
252
253
254}
255
256#pragma mark 保持连接
257RCT_EXPORT_METHOD(holdLink:(nonnull NSString *)mac){
258
259 if ([self getDeviceWithMac:mac]) {
260 __weak typeof(self) weakSelf = self;
261 [[self getDeviceWithMac:mac] commandKeepConnect:^(BOOL sendOk) {
262 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
263 kMAC_KEY:mac,
264 kACTION_KEY:kACTION_KEEP_LINK,
265 }];
266 } DisposeErrorBlock:^(NSNumber *errorID) {
267 [weakSelf sendMeasureErrorEventWithMac:mac errorId:errorID];
268 }];
269 }else{
270 [self sendNoMatchedDeviceEventWithMac:mac];
271 }
272}
273
274#pragma mark 获得电池电量
275RCT_EXPORT_METHOD(getBattery:(nonnull NSString *)mac){
276
277 if ([self getDeviceWithMac:mac]) {
278 __weak typeof(self) weakSelf = self;
279 [[self getDeviceWithMac:mac] commandQueryBattery:^(NSNumber *energy) {
280 NSLog(@"电量");
281 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
282 kMAC_KEY:mac,
283 kACTION_KEY:kACTION_GET_BATTERY,
284 kGET_BATTERY:energy
285 }];
286
287 } DisposeErrorBlock:^(NSNumber *errorID) {
288 [weakSelf sendMeasureErrorEventWithMac:mac errorId:errorID];
289 }];
290
291 }else{
292 [self sendNoMatchedDeviceEventWithMac:mac];
293 }
294}
295#pragma mark 设置时间
296RCT_EXPORT_METHOD(setTime:(nonnull NSString *)mac){
297
298
299 if ([self getDeviceWithMac:mac]) {
300 __weak typeof(self) weakSelf = self;
301 [[self getDeviceWithMac:mac] commandBGSetTime:^(BOOL setResult) {
302 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
303 kMAC_KEY:mac,
304 kACTION_KEY:kACTION_SET_TIME,
305 }];
306 } DisposeBGErrorBlock:^(NSNumber *errorID) {
307 [weakSelf sendMeasureErrorEventWithMac:mac errorId:errorID];
308 }];
309 }else{
310 [self sendNoMatchedDeviceEventWithMac:mac];
311
312 }
313}
314
315#pragma mark 设置单位
316RCT_EXPORT_METHOD(setUnit:(nonnull NSString *)mac unitType:(nonnull NSNumber *)type){
317#warning 下位机回复是否表示设置成功
318 if ([self getDeviceWithMac:mac]) {
319
320 BGUnit tempUnit = BGUnit_mmolPL;
321 if ([type isEqual:@(BGUnit_mmolPL)]) {
322 tempUnit = BGUnit_mmolPL;
323 } else if([type isEqual:@(BGUnit_mgPmL)]) {
324 tempUnit = BGUnit_mgPmL;
325 } else {
326 [self sendInputParameterErrorEventWithMac:mac];
327 return;
328 }
329 __weak typeof(self) weakSelf = self;
330 [[self getDeviceWithMac:mac] commandBGSetUnit:tempUnit DisposeSetUnitResult:^(BOOL setResult) {
331 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
332 kMAC_KEY:mac,
333 kACTION_KEY:kACTION_SET_UNIT,
334 }];
335
336 } DisposeBGErrorBlock:^(NSNumber *errorID) {
337
338 [weakSelf sendMeasureErrorEventWithMac:mac errorId:errorID];
339 }];
340
341 }else{
342 [self sendNoMatchedDeviceEventWithMac:mac];
343 }
344}
345
346#pragma mark 获得Bottle ID
347RCT_EXPORT_METHOD(getBottleId:(nonnull NSString *)mac){
348
349 if ([self getDeviceWithMac:mac]) {
350 __weak typeof(self) weakSelf = self;
351 [[self getDeviceWithMac:mac]commandBGGetBottleID:^(NSNumber *bottleID) {
352 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
353 kMAC_KEY:mac,
354 kACTION_KEY:kACTION_GET_BOTTLEID,
355 kGET_BOTTLEID:bottleID,
356 }];
357
358 } DisposeBGErrorBlock:^(NSNumber *errorID) {
359 [weakSelf sendMeasureErrorEventWithMac:mac errorId:errorID];
360 }];
361
362 }else{
363 [self sendNoMatchedDeviceEventWithMac:mac];
364 }
365}
366
367#pragma mark 开始测量
368RCT_EXPORT_METHOD(startMeasure:(nonnull NSString *)mac measureType:(nonnull NSNumber *)measureType){
369
370
371 if ([self getDeviceWithMac:mac]) {
372
373 /* 优先判断输入参数的内容正确性 */
374 if (![measureType isEqual: @(BGMeasureMode_Blood)] && ![measureType isEqual: @(BGMeasureMode_NoBlood)]) {
375 //输入参数错误
376 [self sendInputParameterErrorEventWithMac:mac];
377 return;
378 }
379
380 /* 再检查setBottleMessageWithInfo方法中传入的测量模式和本次传入的一致一致性 */
381 if (self.userSelectedMeasureMode != measureType.integerValue) {
382 [self sendMeasureErrorEventWithMac:mac errorId:@(RNBGError_MeasureModeNotMatched)];
383 return;
384 }
385
386 if (self.deviceSelectedOpenMode == 0) {
387 [self sendMeasureErrorEventWithMac:mac errorId:@(RNBGError_FunctionCallOrderError)];
388 return;
389 }
390
391 [self sendEventWithName:EVENT_NOTIFY body:@{
392 kMAC_KEY:mac,
393 kACTION_KEY:kACTION_START_MEASURE,
394 }];
395 }else{
396
397 [self sendNoMatchedDeviceEventWithMac:mac];
398 }
399
400}
401
402#pragma mark 获得离线数据
403RCT_EXPORT_METHOD(getOfflineData:(nonnull NSString *)mac){
404
405 if ([self getDeviceWithMac:mac]) {
406 __weak typeof(self) weakSelf = self;
407 [[self getDeviceWithMac:mac]commandTransferMemorryData:^(NSNumber *dataCount) {
408
409 NSDictionary *deviceInfo = @{@"mac":mac,@"action":kACTION_GET_OFFLINEDATA_COUNT,kGET_OFFLINEDATA_COUNT:dataCount,@"type":@"BG5"};
410
411 [weakSelf sendEventWithName:EVENT_NOTIFY body:deviceInfo];
412 } DisposeBGHistoryData:^(NSDictionary *historyDataDic) {
413
414 NSArray *historyArr = [NSArray arrayWithArray:[historyDataDic objectForKey:@"ResultList"]];
415 NSMutableArray * tempArr = [[NSMutableArray alloc]init];
416
417 for(NSDictionary *history in historyArr) {
418 NSDate *tempDate = [history objectForKey:@"Date"];
419
420 //将时间格式转化成字符串,适配plugin和react native
421 NSDateFormatter *mydateFormatter = [[NSDateFormatter alloc] init];
422 [mydateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
423 NSString *dateStr = [mydateFormatter stringFromDate:tempDate];
424
425 NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:dateStr,@"date",[history objectForKey:@"Result"],@"value",[history objectForKey:@"dataID"],@"dataID", nil];
426
427 [tempArr addObject:dic];
428 }
429
430 NSDictionary*hisDic=[NSDictionary dictionaryWithObjectsAndKeys:tempArr,@"history", nil];
431
432
433 NSDictionary *deviceInfo = @{@"mac":mac,@"action":kACTION_GET_OFFLINEDATA,kGET_OFFLINEDATA:hisDic,@"type":@"BG5"};
434
435 [weakSelf sendEventWithName:EVENT_NOTIFY body:deviceInfo];
436 } DisposeBGErrorBlock:^(NSNumber *errorID) {
437 [weakSelf sendMeasureErrorEventWithMac:mac errorId:errorID];
438 }];
439 }else{
440 [self sendNoMatchedDeviceEventWithMac:mac];
441 }
442}
443
444#pragma mark 删除离线数据
445RCT_EXPORT_METHOD(deleteOfflineData:(nonnull NSString *)mac){
446
447 if ([self getDeviceWithMac:mac]) {
448
449 [[self getDeviceWithMac:mac] commandDeleteMemorryData:^(BOOL deleteOk) {
450
451 [self sendEventWithName:EVENT_NOTIFY body:@{
452 kMAC_KEY:mac,
453 kACTION_KEY:kACTION_DELETE_OFFLINEDATA,
454 }];
455
456 } DisposeBGErrorBlock:^(NSNumber *errorID) {
457
458 }];
459
460
461 }else{
462 [self sendNoMatchedDeviceEventWithMac:mac];
463 }
464}
465
466#pragma mark 发Code信息方法
467RCT_EXPORT_METHOD(setBottleMessageWithInfo:(nonnull NSString *)mac codeMode:(nonnull NSNumber *)codeType measureMode:(nonnull NSNumber *)testType qrCode:(nonnull NSString *)qrCode stripNum:(nonnull NSNumber *)stripNum overDate:(nonnull NSString *)overDate){
468
469
470 if ([self getDeviceWithMac:mac]) {
471 // 检查输入参数是否合法,交给SDK的方法去做,不在原生模块中校验,但是SDK中发码方法没有校验,所以先在RN模块中校验
472 if ((codeType.integerValue == BGCodeMode_GOD) || (codeType.integerValue == BGCodeMode_GDH)) {
473
474 } else {
475 [self sendInputParameterErrorEventWithMac:mac];
476 return;
477 }
478 self.userSelectedMeasureMode = testType.integerValue;
479 //code的截止时期是东八区的时间,String 转 Date
480 NSDateFormatter *dongBaFormatter = [[NSDateFormatter alloc] init];
481 NSTimeZone *dongBaTimeZone = [NSTimeZone timeZoneForSecondsFromGMT:8*60*60];
482 [dongBaFormatter setTimeZone:dongBaTimeZone];
483 [dongBaFormatter setDateFormat:@"yyyy-MM-dd"];
484 NSCalendar *canlendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
485 [dongBaFormatter setCalendar:canlendar];
486 NSDate *dueDate = [dongBaFormatter dateFromString:overDate];//过期时间
487
488 NSDictionary *codeDic = [[self getDeviceWithMac:mac]codeStripStrAnalysis:qrCode];
489 NSNumber *bottleID = [codeDic objectForKey:@"BottleID"];
490
491 __weak typeof(self) weakSelf = self;
492 [[self getDeviceWithMac:mac]commandSendBGCodeWithMeasureType:(BGMeasureMode)testType.integerValue
493 CodeType:(BGCodeMode)codeType.integerValue
494 CodeString:qrCode
495 validDate:dueDate
496 remainNum:stripNum
497 DisposeBGSendCodeBlock:^(BOOL sendOk) {
498 // 发码成功,发送事件
499 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
500 kMAC_KEY:mac,
501 kACTION_KEY:kACTION_SET_BOTTLEMESSAGE,
502 }];
503 } DisposeBGStartModel:^(BGOpenMode mode) {
504 weakSelf.deviceSelectedOpenMode = mode;
505 if (mode == BGOpenMode_Strip) {
506 [[weakSelf getDeviceWithMac:mac]commandCreateBGtestStripInBlock:^{
507 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
508 kMAC_KEY:mac,
509 kACTION_KEY:kACTION_STRIP_IN,
510 }];
511 } DisposeBGBloodBlock:^{
512 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
513 kMAC_KEY:mac,
514 kACTION_KEY:kACTION_GET_BLOOD,
515 }];
516 } DisposeBGResultBlock:^(NSDictionary *result) {
517 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
518 kMAC_KEY:mac,
519 kACTION_KEY:kACTION_ONLINE_RESULT_BG,
520 kONLINE_RESULT_BG:[result objectForKey:@"Result"],
521 kDATA_ID:[result objectForKey:@"dataID"],
522 }];
523
524 } DisposeBGErrorBlock:^(NSNumber *errorID) {
525 [weakSelf sendMeasureErrorEventWithMac:mac errorId:errorID];
526 }];
527 } else {
528 [[weakSelf getDeviceWithMac:mac]commandCreateBGtestModel:(BGMeasureMode)testType.integerValue DisposeBGStripInBlock:^{
529 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
530 kMAC_KEY:mac,
531 kACTION_KEY:kACTION_STRIP_IN,
532 }];
533 } DisposeBGBloodBlock:^{
534 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
535 kMAC_KEY:mac,
536 kACTION_KEY:kACTION_GET_BLOOD,
537 }];
538 } DisposeBGResultBlock:^(NSDictionary *result) {
539 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
540 kMAC_KEY:mac,
541 kACTION_KEY:kACTION_ONLINE_RESULT_BG,
542 kONLINE_RESULT_BG:[result objectForKey:@"Result"],
543 kDATA_ID:[result objectForKey:@"dataID"],
544 }];
545
546 } DisposeBGErrorBlock:^(NSNumber *errorID) {
547 [weakSelf sendMeasureErrorEventWithMac:mac errorId:errorID];
548 }];
549 }
550
551 } DisposeBGErrorBlock:^(NSNumber *errorID) {
552 [weakSelf sendMeasureErrorEventWithMac:mac errorId:errorID];
553 }];
554
555
556
557 }else{
558 [self sendNoMatchedDeviceEventWithMac:mac];
559 }
560}
561
562#pragma mark 读取试条信息
563RCT_EXPORT_METHOD(getBottleMessage:(nonnull NSString *)mac){
564
565 if ([self getDeviceWithMac:mac]) {
566 __weak typeof(self) weakSelf = self;
567 [[self getDeviceWithMac:mac]commandReadBGCodeDic:^(NSDictionary *codeDic) {
568
569 NSDate *tempDate = [codeDic objectForKey:@"Date"];
570 //将时间格式转化成字符串,适配plugin和react native
571 NSDateFormatter *mydateFormatter = [[NSDateFormatter alloc] init];
572 [mydateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
573 NSTimeZone *dongBaTimeZone = [NSTimeZone timeZoneForSecondsFromGMT:8*60*60];
574 [mydateFormatter setTimeZone:dongBaTimeZone];
575 NSString *dateStr = [mydateFormatter stringFromDate:tempDate];
576
577 [self sendEventWithName:EVENT_NOTIFY body:@{
578 kMAC_KEY:mac,
579 kACTION_KEY:kACTION_GET_BOTTLEMESSAGE,
580 kGET_EXPIRECTIME:dateStr,
581 kGET_USENUM:[codeDic objectForKey:@"Strips"],
582 }];
583 } DisposeBGErrorBlock:^(NSNumber *errorID) {
584 [weakSelf sendMeasureErrorEventWithMac:mac errorId:errorID];
585 }];
586
587 }else{
588
589 [self sendNoMatchedDeviceEventWithMac:mac];
590
591 }
592
593}
594
595#pragma mark 设置试条信息
596RCT_EXPORT_METHOD(setBottleId:(nonnull NSString *)mac bottleId:(nonnull NSString *)bottleId){
597 if ([self getDeviceWithMac:mac]) {
598 __weak typeof(self) weakSelf = self;
599
600 [[self getDeviceWithMac:mac] commandSendBottleID:bottleId.longLongValue DisposeBGSendBottleIDBlock:^(BOOL sendOk) {
601 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
602 kMAC_KEY:mac,
603 kACTION_KEY:kACTION_SET_BOTTLEID,
604 }];
605 } DisposeBGErrorBlock:^(NSNumber *errorID) {
606 [weakSelf sendMeasureErrorEventWithMac:mac errorId:errorID];
607 }];
608 } else {
609 [self sendNoMatchedDeviceEventWithMac:mac];
610 }
611}
612
613#pragma mark 断开连接
614RCT_EXPORT_METHOD(disConnect:(nonnull NSString *)mac){
615 [self sendMeasureErrorEventWithMac:mac errorId:@(RNBGError_DisconnectFunctionNotSupportIniOSPlatform)];
616}
617
618#pragma mark 二维码解析
619RCT_EXPORT_METHOD(getBottleInfoFromQR:(NSString *)qrCode){
620 BG5 *bg = [BG5 new];
621 NSDictionary *codeDic = [bg codeStripStrAnalysis:qrCode];
622 if (codeDic) {
623
624 NSDate *tempDate = [codeDic objectForKey:@"DueDate"];
625
626
627 NSDateFormatter *mydateFormatter = [[NSDateFormatter alloc] init];
628 [mydateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
629 NSString *dateStr = [mydateFormatter stringFromDate:tempDate];
630
631 [self sendEventWithName:EVENT_NOTIFY body:@{
632 kACTION_KEY:kACTION_CODE_ANALYSIS,
633 kSTRIP_NUM_BG:codeDic[@"StripNum"],
634 kSTRIP_EXPIRETIME_BG:dateStr,
635 kBOTTLEID_BG:[NSString stringWithFormat:@"%@",codeDic[@"BottleID"]],// String
636 }];
637 } else {
638 [self sendMeasureErrorEventWithMac:nil errorId:@(RNBGError_getBottleInfoFromQRFunctionInpurParameterError)];
639 }
640
641}
642
643@end