summaryrefslogtreecommitdiff
path: root/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP7SModule.m
diff options
context:
space:
mode:
Diffstat (limited to 'libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP7SModule.m')
-rwxr-xr-xlibs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP7SModule.m284
1 files changed, 284 insertions, 0 deletions
diff --git a/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP7SModule.m b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP7SModule.m
new file mode 100755
index 0000000..95986bc
--- /dev/null
+++ b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP7SModule.m
@@ -0,0 +1,284 @@
1//
2// BP7SModule.m
3// ReactNativeIOSLibrary
4//
5// Created by Liu Yanbo on 2016/12/05.
6// Copyright © 2016年 Liu Yanbo. All rights reserved.
7//
8
9#import "BP7SModule.h"
10#import "BPProfileModule.h"
11#import "BPMacroFile.h"
12#import "BP7SController.h"
13#import "BP7S.h"
14#import "iHealthDeviceManagerModule.h"
15#import "ScanDeviceController.h"
16#import "ConnectDeviceController.h"
17#define EVENT_NOTIFY @"BP7S.MODULE.NOTIFY"
18
19@implementation BP7SModule
20RCT_EXPORT_MODULE()
21- (NSArray<NSString *> *)supportedEvents {
22 return @[@"event_notify", @"event_scan_device", @"event_scan_finish",
23 @"event_device_connected", @"event_device_connect_failed",
24 @"event_device_disconnect", @"event_authenticate_result",
25 @"event_notify_ts28b", @"event_notify_bg1",
26 @"action_connect_result_for_bg1"];
27}
28
29
30- (NSDictionary *)constantsToExport
31{
32 return @{
33 @"Event_Notify":EVENT_NOTIFY,
34
35 };
36}
37
38+ (BOOL)requiresMainQueueSetup
39{
40 return YES;
41}
42-(BP7S*)getDeviceWithMac:(NSString*)mac{
43
44 BP7SController *controller = [BP7SController shareBP7SController];
45 NSArray *bpDeviceArray = [controller getAllCurrentBP7SInstace];
46
47 for(BP7S *tempDevice in bpDeviceArray){
48 if([mac isEqualToString:tempDevice.serialNumber]){
49
50 return tempDevice;
51 }
52 }
53
54 return nil;
55}
56
57#pragma mark-获取连接设备
58RCT_EXPORT_METHOD(getAllConnectedDevices){
59
60
61 NSArray*bp7Sarray= [[BP7SController shareBP7SController] getAllCurrentBP7SInstace];
62
63 NSMutableArray*deviceMacArray=[NSMutableArray array];
64
65 for (int i=0; i<[bp7Sarray count]; i++) {
66
67 BP7S*bp7s=[bp7Sarray objectAtIndex:i];
68
69 [deviceMacArray addObject:bp7s.serialNumber];
70
71 }
72
73 NSDictionary* deviceInfo = @{@"action":@"ACTION_GET_ALL_CONNECTED_DEVICES",@"devices":deviceMacArray};
74
75 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
76
77
78}
79
80
81
82#pragma mark - Method
83
84RCT_EXPORT_METHOD(getFunctionInfo:(nonnull NSString *)mac){
85
86 if ([self getDeviceWithMac:mac]!=nil) {
87
88
89 [[self getDeviceWithMac:mac] commandFunction:^(NSDictionary *dic) {
90
91 NSDictionary* response = @{
92 kACTION:kACTION_FUNCTION_INFORMATION_BP,
93 kFUNCTION_IS_UPAIR_MEASURE:dic[@"upAirMeasureFlg"],
94 kFUNCTION_IS_ARM_MEASURE:dic[@"armMeasureFlg"],
95 kFUNCTION_HAVE_ANGLE_SENSOR:dic[@"haveAngleSensor"],
96 kFUNCTION_HAVE_OFFLINE:dic[@"haveOffline"],
97 kFUNCTION_HAVE_ANGLE_SETTING:dic[@"haveAngleSet"],
98 kFUNCTION_IS_MULTI_UPLOAD:dic[@"mutableUpload"],
99 kFUNCTION_HAVE_SELF_UPDATE:dic[@"selfUpdate"],
100 kFUNCTION_HAVE_HSD:dic[@"haveHSD"]
101 };
102 [BPProfileModule sendEventToEmitter:self eventNotify:EVENT_NOTIFY WithDict:response];
103 } errorBlock:^(BPDeviceError error) {
104 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:error];
105 }];
106 }else{
107 NSLog(@"error %d",BPDidDisconnect);
108 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
109 }
110
111
112}
113
114//getOffLineNum
115RCT_EXPORT_METHOD(getOffLineNum:(nonnull NSString *)mac){
116
117 if ([self getDeviceWithMac:mac]!=nil) {
118
119 [[self getDeviceWithMac:mac] commandTransferMemoryTotalCount:^(NSNumber *count) {
120 NSDictionary* response = @{
121 kACTION:kACTION_HISTORICAL_NUM_BP,
122 kHISTORICAL_NUM_BP:count,
123 };
124 [BPProfileModule sendEventToEmitter:self eventNotify:EVENT_NOTIFY WithDict:response];
125 } errorBlock:^(BPDeviceError error) {
126 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:error];
127 }];
128 }else{
129 NSLog(@"error %d",BPDidDisconnect);
130 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
131 }
132
133
134}
135
136//getOffLineData
137RCT_EXPORT_METHOD(getOffLineData:(nonnull NSString *)mac){
138
139 if ([self getDeviceWithMac:mac]!=nil) {
140 [[self getDeviceWithMac:mac] commandTransferMemoryDataWithTotalCount:^(NSNumber *count) {
141 if (count.integerValue == 0) {
142 NSDictionary* response = @{
143 kACTION:kACTION_HISTORICAL_DATA_BP,
144 };
145 [BPProfileModule sendEventToEmitter:self eventNotify:EVENT_NOTIFY WithDict:response];
146 }
147 } progress:^(NSNumber *progress) {
148 NSLog(@"pregress %@",progress);
149 } dataArray:^(NSArray *array) {
150 NSLog(@"dataArray %@",array);
151 NSMutableArray* historyDataArray = [NSMutableArray array];
152 for (NSDictionary* dataDict in array) {
153 if ([dataDict isKindOfClass:[NSDictionary class]]) {
154 NSDate *tempDate = [dataDict objectForKey:@"time"];
155
156 //将时间格式转化成字符串,适配plugin和react native
157 NSDateFormatter *mydateFormatter = [[NSDateFormatter alloc] init];
158 [mydateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
159 NSString *dateStr = [mydateFormatter stringFromDate:tempDate];
160 NSDictionary* historyDataDict = @{
161 kMEASUREMENT_DATE_BP:dateStr,
162 kHIGH_BLOOD_PRESSURE_BP:dataDict[@"sys"],
163 kLOW_BLOOD_PRESSURE_BP:dataDict[@"dia"],
164 kPULSE_BP:dataDict[@"heartRate"],
165 kMEASUREMENT_AHR_BP:dataDict[@"irregular"],
166 kMEASUREMENT_HSD_BP:dataDict[@"hsdValue"],
167 kMEASUREMENT_STRAT_ANGLE_BP: dataDict[@"startAngle"],
168 kMEASUREMENT_ANGLE_CHANGE_BP:dataDict[@"measureAngleChange"],
169 kMEASUREMENT_HAND_BP:dataDict[@"chooseHand"],
170 kDATAID:dataDict[@"dataID"]
171 };
172 [historyDataArray addObject:historyDataDict];
173 }
174 }
175 if (historyDataArray.count > 0) {
176 NSDictionary* response = @{
177 kACTION:kACTION_HISTORICAL_DATA_BP,
178 kHISTORICAL_DATA_BP:[historyDataArray copy]
179 };
180 [BPProfileModule sendEventToEmitter:self eventNotify:EVENT_NOTIFY WithDict:response];
181 }
182 } errorBlock:^(BPDeviceError error) {
183 NSLog(@"error %d",error);
184 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:error];
185 }];
186
187 }else{
188 NSLog(@"error %d",BPDidDisconnect);
189 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
190 }
191
192
193}
194//getBattery
195RCT_EXPORT_METHOD(getBattery:(nonnull NSString *)mac){
196
197 if ([self getDeviceWithMac:mac]!=nil) {
198 [[self getDeviceWithMac:mac] commandEnergy:^(NSNumber *energyValue) {
199 NSLog(@"energyValue %@",energyValue);
200 NSDictionary* response = @{
201 kACTION:kACTION_BATTERY_BP,
202 kBATTERY_BP:energyValue,
203 };
204 [BPProfileModule sendEventToEmitter:self eventNotify:EVENT_NOTIFY WithDict:response];
205 } errorBlock:^(BPDeviceError error) {
206 NSLog(@"error %d",error);
207 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:error];
208 }];
209 }else{
210 NSLog(@"error %d",BPDidDisconnect);
211 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
212 }
213
214
215}
216//setUnit
217RCT_EXPORT_METHOD(setUnit:(nonnull NSString *)mac unit:(nonnull NSNumber*)unit){
218
219 if ([unit integerValue] > 1 || [unit integerValue] < 0) {
220 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPInputParameterError];
221 return;
222 }
223
224 if ([self getDeviceWithMac:mac]!=nil) {
225 [[self getDeviceWithMac:mac] commandSetUnit:[unit integerValue] > 0 ? @"kPa" : @"mmHg" disposeSetReslut:^{
226 NSLog(@"set unit success");
227 NSDictionary* response = @{
228 kACTION:kACTION_SET_UNIT_SUCCESS_BP,
229 };
230 [BPProfileModule sendEventToEmitter:self eventNotify:EVENT_NOTIFY WithDict:response];
231 } errorBlock:^(BPDeviceError error) {
232 NSLog(@"error %d",error);
233 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:error];
234 }];
235 }else{
236 NSLog(@"error %d",BPDidDisconnect);
237 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
238 }
239
240
241}
242//angleSet
243RCT_EXPORT_METHOD(angleSet:(nonnull NSString *)mac hl:(nonnull NSNumber*)hl ll:(nonnull NSNumber*)ll hr:(nonnull NSNumber*)hr lr:(nonnull NSNumber*)lr){
244
245 if ([self getDeviceWithMac:mac]!=nil) {
246 NSDictionary* dict = @{
247 @"highAngleForLeft":hl,
248 @"lowAngleForLeft":ll,
249 @"highAngleForRight":hr,
250 @"lowAngleForRight":lr
251 };
252
253 [[self getDeviceWithMac:mac] commandSetAngle:dict disposeSetReslut:^{
254 NSDictionary* response = @{
255 kACTION:kACTION_SET_ANGLE_SUCCESS_BP,
256 };
257 [BPProfileModule sendEventToEmitter:self eventNotify:EVENT_NOTIFY WithDict:response];
258 } errorBlock:^(BPDeviceError error) {
259 NSLog(@"error %d",error);
260 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:error];
261 }];
262 }else{
263 NSLog(@"error %d",BPDidDisconnect);
264 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
265 }
266
267
268}
269
270RCT_EXPORT_METHOD(disconnect:(nonnull NSString *)mac){
271
272 if ([self getDeviceWithMac:mac]!=nil) {
273 [[self getDeviceWithMac:mac] commandDisconnectDevice];
274 }else{
275 NSLog(@"error %d",BPDidDisconnect);
276 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
277 }
278
279
280}
281
282
283
284@end