summaryrefslogtreecommitdiff
path: root/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP5SModule.m
diff options
context:
space:
mode:
Diffstat (limited to 'libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP5SModule.m')
-rw-r--r--libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP5SModule.m426
1 files changed, 426 insertions, 0 deletions
diff --git a/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP5SModule.m b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP5SModule.m
new file mode 100644
index 0000000..332fe67
--- /dev/null
+++ b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP5SModule.m
@@ -0,0 +1,426 @@
1//
2// BP5SModule.m
3// ReactNativeIOSLibrary
4//
5// Created by soso on 2019/4/17.
6// Copyright © 2019 daiqingquan. All rights reserved.
7//
8
9#import "BP5SModule.h"
10
11#import "BPProfileModule.h"
12#import "BPMacroFile.h"
13#import "BP5SController.h"
14#import "BP5S.h"
15#import "iHealthDeviceManagerModule.h"
16
17#import "ScanDeviceController.h"
18#import "ConnectDeviceController.h"
19#define EVENT_NOTIFY @"BP5S.MODULE.NOTIFY"
20
21@interface BP5SModule ()
22@property (nonatomic, assign) BOOL isMeasuring;
23
24@end
25
26
27@implementation BP5SModule
28RCT_EXPORT_MODULE()
29- (NSArray<NSString *> *)supportedEvents {
30 return @[@"event_notify", @"event_scan_device", @"event_scan_finish",
31 @"event_device_connected", @"event_device_connect_failed",
32 @"event_device_disconnect", @"event_authenticate_result",
33 @"event_notify_ts28b", @"event_notify_bg1",
34 @"action_connect_result_for_bg1"];
35}
36
37
38- (NSDictionary *)constantsToExport
39{
40 return @{
41 @"Event_Notify":EVENT_NOTIFY,
42
43 };
44}
45+ (BOOL)requiresMainQueueSetup
46{
47 return YES;
48}
49
50-(BP5S*)getDeviceWithMac:(NSString*)mac{
51
52 BP5SController *controller = [BP5SController sharedController];
53 NSArray *bpDeviceArray = [controller getAllCurrentInstance];
54
55 for(BP5S *tempDevice in bpDeviceArray){
56 if([mac isEqualToString:tempDevice.serialNumber]){
57
58 return tempDevice;
59 }
60 }
61
62 return nil;
63}
64
65
66#pragma mark - Method
67
68
69#pragma mark-获取连接设备
70RCT_EXPORT_METHOD(getAllConnectedDevices){
71
72
73 NSArray *bp5sArray= [[BP5SController sharedController] getAllCurrentInstance];
74
75 NSMutableArray *deviceMacArray = [NSMutableArray array];
76
77 for (int i=0; i<[bp5sArray count]; i++) {
78
79 BP5S *bp5s=[bp5sArray objectAtIndex:i];
80
81 [deviceMacArray addObject:bp5s.serialNumber];
82
83 }
84
85 NSDictionary* deviceInfo = @{@"action":@"ACTION_GET_ALL_CONNECTED_DEVICES",@"devices":deviceMacArray};
86
87 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
88
89}
90
91
92//开始测量
93RCT_EXPORT_METHOD(startMeasure:(nonnull NSString *)mac){
94
95 if ([self getDeviceWithMac:mac]!=nil) {
96 __weak typeof(self) weakSelf = self;
97
98 [[self getDeviceWithMac:mac] commandStartMeasureWithZeroingState:^(BOOL isComplete) {
99 weakSelf.isMeasuring = YES;
100 NSDictionary* response = @{
101 @"mac":mac,
102 kACTION:isComplete ? kACTION_ZOREING_BP : kACTION_ZOREOVER_BP,
103 };
104 [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response];
105 } pressure:^(NSArray *pressureArr) {
106 weakSelf.isMeasuring = YES;
107 NSLog(@"pressure %@",pressureArr);
108 NSDictionary* response = @{
109 @"mac":mac,
110 kACTION:kACTION_ONLINE_PRESSURE_BP,
111 kBLOOD_PRESSURE_BP:pressureArr.firstObject,
112 };
113 [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response];
114 } waveletWithHeartbeat:^(NSArray *waveletArr) {
115 weakSelf.isMeasuring = YES;
116 NSLog(@"xiaoboWithHeart %@",waveletArr);
117 NSDictionary* response = @{
118 @"mac":mac,
119 kACTION:kACTION_ONLINE_PULSEWAVE_BP,
120 kFLAG_HEARTBEAT_BP:@(1),
121 kPULSEWAVE_BP:waveletArr
122 };
123 [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response];
124 } waveletWithoutHeartbeat:^(NSArray *waveletArr) {
125 weakSelf.isMeasuring = YES;
126 NSLog(@"xiaoboNoHeart %@",waveletArr);
127 NSDictionary* response = @{
128 @"mac":mac,
129 kACTION:kACTION_ONLINE_PULSEWAVE_BP,
130 kFLAG_HEARTBEAT_BP:@(0),
131 kPULSEWAVE_BP:waveletArr
132 };
133 [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response];
134 } result:^(NSDictionary *resultDict) {
135 weakSelf.isMeasuring = NO;
136 NSLog(@"result %@",resultDict);
137 NSDictionary* response = @{
138 @"mac":mac,
139 kACTION:kACTION_ONLINE_RESULT_BP,
140 kHIGH_BLOOD_PRESSURE_BP:resultDict[@"sys"],
141 kLOW_BLOOD_PRESSURE_BP:resultDict[@"dia"],
142 kPULSE_BP:resultDict[@"heartRate"],
143 kMEASUREMENT_AHR_BP:resultDict[@"irregular"],
144 kDATAID:resultDict[@"dataID"],
145 };
146 [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response];
147 } errorBlock:^(BPDeviceError error) {
148 weakSelf.isMeasuring = NO;
149 NSLog(@"error %lu",(unsigned long)error);
150 [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error];
151 }];
152
153 }else{
154 self.isMeasuring = NO;
155 NSLog(@"error %lu",(unsigned long)BPDidDisconnect);
156 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
157 }
158}
159
160//停止测量
161RCT_EXPORT_METHOD(stopMeasure:(nonnull NSString *)mac){
162 if (!self.isMeasuring) {
163 NSLog(@"error %d",401);
164 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:401];
165 return;
166 }
167 __weak typeof(self) weakSelf = self;
168 if ([self getDeviceWithMac:mac]!=nil) {
169 [[self getDeviceWithMac:mac] stopBPMeassureSuccessBlock:^{
170
171 weakSelf.isMeasuring = NO;
172 NSDictionary* response = @{
173 @"mac":mac,
174 kACTION:kACTION_INTERRUPTED_BP,
175 };
176 [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response];
177
178 } errorBlock:^(BPDeviceError error) {
179
180 NSLog(@"error %lu",(unsigned long)error);
181 weakSelf.isMeasuring = NO;
182 [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error];
183 }];
184
185
186 }else{
187 weakSelf.isMeasuring = NO;
188 NSLog(@"error %lu",(unsigned long)BPDidDisconnect);
189 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
190 }
191
192
193}
194
195//删除功能
196RCT_EXPORT_METHOD(deleteData:(nonnull NSString *)mac){
197
198 if ([self getDeviceWithMac:mac]!=nil) {
199 __weak typeof(self) weakSelf = self;
200 [[self getDeviceWithMac:mac] commandDeleteDataSuccessBlock:^{
201 NSDictionary* response = @{
202 @"mac":mac,
203 kACTION:kACTION_Delete_BP,
204 };
205 [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response];
206 } errorBlock:^(BPDeviceError error) {
207 NSLog(@"error %lu",(unsigned long)error);
208 [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error];
209 }];
210 }else{
211 NSLog(@"error %lu",(unsigned long)BPDidDisconnect);
212 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
213 }
214}
215
216//设置离线功能
217RCT_EXPORT_METHOD(enbleOffline:(nonnull NSString *)mac mode:(nonnull NSNumber *)mode){
218
219 if ([self getDeviceWithMac:mac]!=nil) {
220 __block BOOL success = YES;
221 __weak typeof(self) weakSelf = self;
222
223 BOOL flag;
224
225 if ([mode boolValue] == YES) {
226 flag = YES;
227 }else{
228 flag = NO;
229 }
230
231 [[self getDeviceWithMac:mac] commandSetOffline:flag success:^{
232
233 if (flag == YES) {
234 NSDictionary* response = @{
235 @"mac":mac,
236 kACTION:kACTION_ENABLE_OFFLINE_BP,
237 };
238 [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response];
239 }else{
240 NSDictionary* response = @{
241 @"mac":mac,
242 kACTION:kACTION_DISENABLE_OFFLINE_BP,
243 };
244 [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response];
245 }
246
247 } error:^(BPDeviceError error) {
248 success = NO;
249 [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error];
250 }];
251 }else{
252 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
253 }
254}
255
256
257//查电量
258RCT_EXPORT_METHOD(getBattery:(nonnull NSString *)mac){
259
260 if ([self getDeviceWithMac:mac]!=nil) {
261 __weak typeof(self) weakSelf = self;
262 [[self getDeviceWithMac:mac] commandEnergy:^(NSNumber *energyValue) {
263 NSDictionary* response = @{
264 @"mac":mac,
265 kACTION:kACTION_BATTERY_BP,
266 kBATTERY_BP:energyValue
267 };
268 [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response];
269 } errorBlock:^(BPDeviceError error) {
270 NSLog(@"error %lu",(unsigned long)error);
271 [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error];
272 }];
273 }else{
274 NSLog(@"error %lu",(unsigned long)BPDidDisconnect);
275 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
276 }
277}
278
279//查数据数量
280RCT_EXPORT_METHOD(getOffLineNum:(nonnull NSString *)mac){
281
282 if ([self getDeviceWithMac:mac]!=nil) {
283 __weak typeof(self) weakSelf = self;
284 [[self getDeviceWithMac:mac]commandTransferMemoryTotalCount:^(NSNumber *num) {
285
286 NSDictionary* response = @{
287 @"mac":mac,
288 kACTION:kACTION_HISTORICAL_NUM_BP,
289 kHISTORICAL_NUM_BP:num
290 };
291 [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response];
292
293 } errorBlock:^(BPDeviceError error) {
294
295 [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error];
296
297 }];
298
299 }else{
300 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
301 }
302}
303
304
305//查离线数据
306RCT_EXPORT_METHOD(getOffLineData:(nonnull NSString *)mac){
307
308 if ([self getDeviceWithMac:mac]!=nil) {
309 __weak typeof(self) weakSelf = self;
310
311 [[self getDeviceWithMac:mac] commandTransferMemoryDataWithTotalCount:^(NSNumber *count) {
312 if ([count integerValue] == 0) {
313 NSDictionary* response = @{@"mac":mac,kACTION:kACTION_HISTORICAL_DATA_BP };
314 [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response];
315 }
316 } progress:^(NSNumber *progress) {
317
318 } dataArray:^(NSArray *array) {
319 NSMutableArray * tempArr = [[NSMutableArray alloc]init];
320
321 for(NSDictionary *history in array)
322 {
323
324 NSNumber *dateNum = [history objectForKey:@"time"];
325
326 NSDate *tempDate = [NSDate dateWithTimeIntervalSince1970:[dateNum integerValue]];
327 //将时间格式转化成字符串,适配plugin和react native
328 NSDateFormatter *mydateFormatter = [[NSDateFormatter alloc] init];
329 [mydateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
330 NSString *dateStr = [mydateFormatter stringFromDate:tempDate];
331
332 NSNumber*bpHSD=[history valueForKey:@"hsdValue"];
333 NSDictionary *dic=[NSDictionary dictionary];
334 if (bpHSD!=nil) {
335 dic = @{
336 @"mac":mac,
337 kMEASUREMENT_DATE_BP: dateStr,
338 kLOW_BLOOD_PRESSURE_BP: [history objectForKey:@"dia"],
339 kHIGH_BLOOD_PRESSURE_BP: [history objectForKey:@"sys"],
340 kMEASUREMENT_AHR_BP: [history objectForKey:@"irregular"],
341 kPULSE_BP: [history objectForKey:@"heartRate"],
342 kDATAID: [history objectForKey:@"dataID"],
343 kMEASUREMENT_HSD_BP: history[@"hsdValue"]
344 };
345 }else{
346
347
348 dic = @{
349 @"mac":mac,
350 kMEASUREMENT_DATE_BP: dateStr,
351 kLOW_BLOOD_PRESSURE_BP: [history objectForKey:@"dia"],
352 kHIGH_BLOOD_PRESSURE_BP: [history objectForKey:@"sys"],
353 kMEASUREMENT_AHR_BP: [history objectForKey:@"irregular"],
354 kPULSE_BP: [history objectForKey:@"heartRate"],
355 kDATAID: [history objectForKey:@"dataID"]
356
357 };
358 }
359 [tempArr addObject:dic];
360 }
361
362 if (tempArr.count > 0) {
363 NSDictionary* response = @{
364 @"mac":mac,
365 kACTION:kACTION_HISTORICAL_DATA_BP,
366 kHISTORICAL_DATA_BP:[tempArr copy]
367 };
368 [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response];
369 }
370
371 } errorBlock:^(BPDeviceError error) {
372 [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error];
373 }];
374
375 }else{
376
377 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
378 }
379
380
381}
382
383//查询功能
384RCT_EXPORT_METHOD(getFunctionInfo:(nonnull NSString *)mac){
385
386 if ([self getDeviceWithMac:mac]!=nil) {
387 __weak typeof(self) weakSelf = self;
388 [[self getDeviceWithMac:mac] commandFunction:^(NSDictionary *dic) {
389
390 NSDictionary* response = @{
391 @"mac":mac,
392 kACTION:kACTION_FUNCTION_INFORMATION_BP,
393 kFUNCTION_IS_UPAIR_MEASURE: [dic objectForKey:@"upAirMeasureFlg"],
394 kFUNCTION_IS_ARM_MEASURE: [dic objectForKey:@"armMeasureFlg"],
395 kFUNCTION_HAVE_ANGLE_SENSOR: [dic objectForKey:@"haveAngleSensor"],
396 kFUNCTION_HAVE_OFFLINE: [dic objectForKey:@"haveOffline"],
397 kFUNCTION_HAVE_HSD: [dic objectForKey:@"haveHSD"],
398 kFUNCTION_IS_MULTI_UPLOAD: [dic objectForKey:@"mutableUpload"],
399 kFUNCTION_HAVE_SELF_UPDATE: [dic objectForKey: @"selfUpdate"]};
400 [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response];
401
402 } errorBlock:^(BPDeviceError error) {
403
404 [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error];
405
406 }];
407 }else{
408
409 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
410 }
411}
412
413//离线数据
414RCT_EXPORT_METHOD(disconnect:(nonnull NSString *)mac){
415
416 if ([self getDeviceWithMac:mac]!=nil) {
417 [[self getDeviceWithMac:mac] commandDisconnectDevice];
418 }else{
419 NSLog(@"error %lu",(unsigned long)BPDidDisconnect);
420 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
421 }
422}
423
424
425
426@end