summaryrefslogtreecommitdiff
path: root/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG1SModule.m
diff options
context:
space:
mode:
Diffstat (limited to 'libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG1SModule.m')
-rw-r--r--libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG1SModule.m224
1 files changed, 224 insertions, 0 deletions
diff --git a/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG1SModule.m b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG1SModule.m
new file mode 100644
index 0000000..f841037
--- /dev/null
+++ b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BG1SModule.m
@@ -0,0 +1,224 @@
1//
2// BG1SModule.m
3// ReactNativeIOSLibrary
4//
5// Created by user on 2019/11/12.
6// Copyright © 2019 daiqingquan. All rights reserved.
7//
8
9#import "BG1SModule.h"
10#import "BG1S.h"
11#import "BG1SController.h"
12#import "BG1SProfileModule.h"
13
14#import "BGHeader.h"
15
16@implementation BG1SModule
17RCT_EXPORT_MODULE()
18- (NSArray<NSString *> *)supportedEvents {
19 return @[@"event_notify", @"event_scan_device", @"event_scan_finish",
20 @"event_device_connected", @"event_device_connect_failed",
21 @"event_device_disconnect", @"event_authenticate_result",
22 @"event_notify_ts28b", @"event_notify_bg1",
23 @"action_connect_result_for_bg1"];
24}
25
26
27- (NSDictionary *)constantsToExport
28{
29 return @{ @"Event_Notify": BG1S_EVENT_NOTIFY ,
30
31 };
32}
33
34+ (BOOL)requiresMainQueueSetup
35{
36 return YES;
37}
38
39
40-(BG1S*)getDeviceWithMac:(NSString*)mac{
41
42 BG1SController *controller = [BG1SController shareIHBG1SController];
43 NSArray *BG1SDeviceArray = [controller getAllCurrentBG1SInstace];
44
45 for(BG1S *tempDevice in BG1SDeviceArray){
46 if([mac isEqualToString:tempDevice.serialNumber]){
47
48 return tempDevice;
49 }
50 }
51 return nil;
52}
53
54RCT_EXPORT_METHOD(getAllConnectedDevices){
55
56
57 NSArray*BG1SDeviceArray= [[BG1SController shareIHBG1SController] getAllCurrentBG1SInstace];
58
59 NSMutableArray*deviceMacArray=[NSMutableArray array];
60
61 for (int i=0; i<[BG1SDeviceArray count]; i++) {
62
63 BG1S *BG1S = [BG1SDeviceArray objectAtIndex:i];
64
65 [deviceMacArray addObject:BG1S.serialNumber];
66
67 }
68
69 NSDictionary* deviceInfo = @{BG1S_ACTION:kACTION_GET_ALL_CONNECTED_DEVICES,BG1S_DEVICE:deviceMacArray};
70
71 [self sendEventWithName:BG1S_EVENT_NOTIFY body:deviceInfo];
72}
73
74RCT_EXPORT_METHOD(measure:(nonnull NSString *)mac measureMode:(nonnull NSNumber *)testType){
75
76
77 if ([self getDeviceWithMac:mac] != nil) {
78
79 BGMeasureMode models= BGMeasureMode_Blood;
80
81 if ([testType intValue]==1) {
82
83 models=BGMeasureMode_NoBlood;
84
85 }else{
86
87 models=BGMeasureMode_Blood;
88 }
89
90 [[self getDeviceWithMac:mac] commandCreateBG1STestModel:models DisposeBGStripInBlock:^(BOOL inORout) {
91
92 if (inORout) {
93 [self sendEventWithName:BG1S_EVENT_NOTIFY body:@{
94 BG1S_ACTION:ACTION_STRIP_INSERTION_STATUS,
95 BG1S_KEY_MAC:mac,
96 BG1S_TYPE:@"BG1S",
97 OPERATION_DESCRIBE:@"strip in",
98 STRIP_INSERTION_STATUS:@1,
99 }];
100 }else{
101
102 [self sendEventWithName:BG1S_EVENT_NOTIFY body:@{
103 BG1S_ACTION:ACTION_STRIP_INSERTION_STATUS,
104 BG1S_KEY_MAC:mac,
105 BG1S_TYPE:@"BG1S",
106 OPERATION_DESCRIBE:@"strip put",
107 STRIP_INSERTION_STATUS:@2,
108 }];
109 }
110
111 } DisposeBGBloodBlock:^{
112
113 [self sendEventWithName:BG1S_EVENT_NOTIFY body:@{
114 BG1S_ACTION:ACTION_GET_BLOOD,
115 BG1S_KEY_MAC:mac,
116 BG1S_TYPE:@"BG1S",
117 OPERATION_DESCRIBE:@"get blood"
118 }];
119
120 } DisposeBGResultBlock:^(NSDictionary *result) {
121
122
123 [self sendEventWithName:BG1S_EVENT_NOTIFY body:@{
124 BG1S_ACTION:ACTION_MEASURE_RESULT,
125 BG1S_KEY_MAC:mac,
126 BG1S_TYPE:@"BG1S",
127 MEASURE_RESULT:[result valueForKey:@"Result"],
128 MEASURE_MODE:[result valueForKey:@"TestState"]
129 }];
130
131 } DisposeBGErrorBlock:^(BG1SDeviceError error) {
132
133 [self sendBG1SErrorCode:error mac:mac];
134
135 }];
136
137
138 }
139
140}
141
142//getFunction
143RCT_EXPORT_METHOD(getFunction:(nonnull NSString *)mac){
144 if ([self getDeviceWithMac:mac]!=nil) {
145
146
147 [[self getDeviceWithMac:mac] commandFunction:^(NSDictionary *functionDict) {
148
149
150 [self sendEventWithName:BG1S_EVENT_NOTIFY body:@{
151 BG1S_ACTION:ACTION_CODE_ANALYSIS,
152 BG1S_KEY_MAC:mac,
153 BG1S_TYPE:@"BG1S",
154 INFO_BATTERY_BG1S:[functionDict valueForKey:@"Battary"],
155 INFO_VERSION_CODE_BLOOD_BG1S:[functionDict valueForKey:@"CodeVersion"],
156 INFO_VERSION_CODE_CTL_BG1S:[functionDict valueForKey:@"DcodeVersion"],
157
158 }];
159
160 } DisposeBGErrorBlock:^(BG1SDeviceError error) {
161
162
163 [self sendBG1SErrorCode:error mac:mac];
164
165 }];
166
167
168 }
169}
170
171//断开连接
172RCT_EXPORT_METHOD(disconnect:(nonnull NSString *)mac){
173
174 if ([self getDeviceWithMac:mac]!=nil) {
175
176 [[self getDeviceWithMac:mac] commandDisconnectDevice];
177 }
178
179}
180
181-(void)sendBG1SErrorCode:(BG1SDeviceError)errorID mac:(NSString*)mac{
182
183 NSString *errorMassage = [NSString string];
184 switch (errorID) {
185 case 0:
186 errorMassage = @"BG1SDeviceError0";
187 break;
188 case 1:
189 errorMassage = @"BG1SError_LowBattery";
190 break;
191 case 2:
192 errorMassage = @"BG1SError_ReferenceUnstable";
193 break;
194 case 3:
195 errorMassage = @"BG1SError_BadStrip";
196 break;
197 case 4:
198 errorMassage = @"BG1SError_BadEEPROM";
199 break;
200 case 5:
201 errorMassage = @"BG1SError_LowAmbientTemperature";
202 break;
203 case 6:
204 errorMassage = @"BG1SError_HighAmbientTemperature";
205 break;
206 case 7:
207 errorMassage = @"BG1SError_BleedEarly";
208 break;
209 case 8:
210 errorMassage = @"BG1SError_Other";
211 break;
212
213
214 default:
215 break;
216 }
217
218 NSDictionary *deviceInfo = @{BG1S_KEY_MAC:mac,BG1S_ACTION:ACTION_ERROR_BG1S,ERROR_NUM_BG1S:[NSNumber numberWithInt:errorID],ERROR_DESCRIPTION_BG1S:errorMassage};
219 [self sendEventWithName:BG1S_EVENT_NOTIFY body:deviceInfo];
220
221
222}
223
224@end