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