summaryrefslogtreecommitdiff
path: root/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP550BTModule.m
diff options
context:
space:
mode:
Diffstat (limited to 'libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP550BTModule.m')
-rwxr-xr-xlibs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP550BTModule.m318
1 files changed, 318 insertions, 0 deletions
diff --git a/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP550BTModule.m b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP550BTModule.m
new file mode 100755
index 0000000..e8976be
--- /dev/null
+++ b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP550BTModule.m
@@ -0,0 +1,318 @@
1//
2// BP550BTModule.m
3// ReactNativeIOSLibrary
4//
5// Created by daiqingquan on 2016/11/23.
6// Copyright © 2016年 daiqingquan. All rights reserved.
7//
8
9#import "BP550BTModule.h"
10#import "KN550BT.h"
11#import "KN550BTController.h"
12#import "BPProfileModule.h"
13#import "iHealthDeviceManagerModule.h"
14#import "ScanDeviceController.h"
15#import "ConnectDeviceController.h"
16#define EVENT_NOTIFY @"event_notify_bp550bt"
17
18@implementation BP550BTModule
19
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+ (BOOL)requiresMainQueueSetup
38{
39 return YES;
40}
41#pragma mark
42#pragma mark - Init
43-(id)init
44{
45 if (self=[super init])
46 {
47
48// [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(DeviceConnectForKN550BT:) name:KN550BTConnectNoti object:nil];
49// [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(DeviceDisConnectForKN550BT:) name:KN550BTDisConnectNoti object:nil];
50
51 [KN550BTController shareKN550BTController];
52
53 }
54 return self;
55}
56
57
58-(KN550BT*)getDeviceWithMac:(NSString*)mac{
59
60 KN550BTController *controller = [KN550BTController shareKN550BTController];
61 NSArray *bpDeviceArray = [controller getAllCurrentKN550BTInstace];
62
63 for(KN550BT *tempDevice in bpDeviceArray){
64 if([mac isEqualToString:tempDevice.serialNumber]){
65
66// tempDevice.reactNativeFlg = @YES;
67 return tempDevice;
68 }
69 }
70
71 return nil;
72}
73
74
75//-(void)DeviceConnectForKN550BT:(NSNotification *)tempNoti{
76// KN550BTController *controller = [KN550BTController shareKN550BTController];
77// NSArray *BPDeviceArray = [controller getAllCurrentKN550BTInstace];
78//
79// KN550BT *bpInstance = [BPDeviceArray objectAtIndex:0];
80// NSString *mac = bpInstance.currentUUID;
81// NSDictionary *IDPSDic = [tempNoti userInfo];
82//
83// NSDictionary* deviceInfo = @{
84// kACTION:@"kn550bt_connected_bg",@"idps":IDPSDic };
85// [BPProfileModule sendEventToEmitter:self eventNotify:EVENT_NOTIFY WithDict:response];
86//
87//}
88//
89//-(void)DeviceDisConnectForKN550BT:(NSNotification *)tempNoti{
90//
91// NSDictionary *IDPSDic = [tempNoti userInfo];
92// NSString *mac = [IDPSDic objectForKey:@"SerialNumber"];
93//
94// NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"kn550bt_disconnected_bg",@"idps":IDPSDic};
95// [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
96//
97//}
98
99
100#pragma mark-获取连接设备
101RCT_EXPORT_METHOD(getAllConnectedDevices){
102
103
104 NSArray*bp550array= [[KN550BTController shareKN550BTController] getAllCurrentKN550BTInstace];
105
106 NSMutableArray*deviceMacArray=[NSMutableArray array];
107
108 for (int i=0; i<[bp550array count]; i++) {
109
110 KN550BT*kn550bt=[bp550array objectAtIndex:i];
111
112 [deviceMacArray addObject:kn550bt.serialNumber];
113
114 }
115
116 NSDictionary* deviceInfo = @{@"action":@"ACTION_GET_ALL_CONNECTED_DEVICES",@"devices":deviceMacArray};
117
118 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
119
120
121}
122
123
124
125
126#pragma mark - Method
127
128RCT_EXPORT_METHOD(getFunctionInfo:(nonnull NSString *)mac){
129
130 if ([self getDeviceWithMac:mac]!=nil) {
131 __weak typeof(self) weakSelf = self;
132 [[self getDeviceWithMac:mac] commandFunction:^(NSDictionary *dic) {
133
134 NSDictionary* response = @{
135 kACTION:kACTION_FUNCTION_INFORMATION_BP,
136 kFUNCTION_IS_UPAIR_MEASURE: [dic objectForKey:@"upAirMeasureFlg"],
137 kFUNCTION_IS_ARM_MEASURE: [dic objectForKey:@"armMeasureFlg"],
138 kFUNCTION_HAVE_ANGLE_SENSOR: [dic objectForKey:@"haveAngleSensor"],
139 kFUNCTION_HAVE_OFFLINE: [dic objectForKey:@"haveOffline"],
140 kFUNCTION_HAVE_HSD: [dic objectForKey:@"haveHSD"],
141 kFUNCTION_HAVE_ANGLE_SETTING: [dic objectForKey:@"haveAngleSet"],
142 kFUNCTION_IS_MULTI_UPLOAD: [dic objectForKey:@"mutableUpload"],
143 kFUNCTION_HAVE_SELF_UPDATE: [dic objectForKey: @"selfUpdate"],
144 kType:@"KN550",
145 kMAC:mac
146 };
147 [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response];
148
149 } errorBlock:^(BPDeviceError error) {
150
151 [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error];
152
153 }];
154 }else{
155
156 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
157
158 }
159
160
161}
162
163RCT_EXPORT_METHOD(getBattery:(nonnull NSString *)mac){
164
165 if ([self getDeviceWithMac:mac]!=nil) {
166 __weak typeof(self) weakSelf = self;
167 [[self getDeviceWithMac:mac] commandEnergy:^(NSNumber *energyValue) {
168
169 NSDictionary* response = @{
170 kACTION:kACTION_BATTERY_BP,
171 kBATTERY_BP:energyValue,
172 kType:@"KN550",
173 kMAC:mac
174 };
175 [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response];
176 NSLog(@"%@",response);
177
178 } errorBlock:^(BPDeviceError error) {
179
180 [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error];
181
182 }];
183
184 }else{
185
186 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
187 }
188
189
190}
191
192RCT_EXPORT_METHOD(getOffLineNum:(nonnull NSString *)mac){
193
194 if ([self getDeviceWithMac:mac]!=nil) {
195 __weak typeof(self) weakSelf = self;
196 [[self getDeviceWithMac:mac]commandTransferMemoryTotalCount:^(NSNumber *num) {
197
198 NSDictionary* response = @{
199 kACTION:kACTION_HISTORICAL_NUM_BP,
200 kHISTORICAL_NUM_BP:num,
201 kType:@"KN550",
202 kMAC:mac
203 };
204 [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response];
205
206 } errorBlock:^(BPDeviceError error) {
207
208 [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error];
209
210 }];
211
212 }else{
213 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
214
215 }
216
217
218}
219
220RCT_EXPORT_METHOD(getOffLineData:(nonnull NSString *)mac){
221
222 if ([self getDeviceWithMac:mac]!=nil) {
223 __weak typeof(self) weakSelf = self;
224
225 [[self getDeviceWithMac:mac] commandTransferMemoryDataWithTotalCount:^(NSNumber *count) {
226 if ([count integerValue] == 0) {
227 NSDictionary* response = @{kACTION:kACTION_HISTORICAL_DATA_BP };
228 [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response];
229 }
230 } progress:^(NSNumber *progress) {
231
232 } dataArray:^(NSArray *array) {
233 NSMutableArray * tempArr = [[NSMutableArray alloc]init];
234
235 for(NSDictionary *history in array)
236 {
237 NSDate *tempDate = [history objectForKey:@"time"];
238
239 //将时间格式转化成字符串,适配plugin和react native【
240 NSDateFormatter *mydateFormatter = [[NSDateFormatter alloc] init];
241 [mydateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
242 NSString *dateStr = [mydateFormatter stringFromDate:tempDate];
243
244 NSNumber*bpHSD=[history valueForKey:@"hsdValue"];
245 NSDictionary *dic=[NSDictionary dictionary];
246 if (bpHSD!=nil) {
247 dic = @{
248 kMEASUREMENT_DATE_BP: dateStr,
249 kLOW_BLOOD_PRESSURE_BP: [history objectForKey:@"dia"],
250 kHIGH_BLOOD_PRESSURE_BP: [history objectForKey:@"sys"],
251 kMEASUREMENT_AHR_BP: [history objectForKey:@"irregular"],
252 kPULSE_BP: [history objectForKey:@"heartRate"],
253 kDATAID: [history objectForKey:@"dataID"],
254 kMEASUREMENT_HSD_BP: history[@"hsdValue"],
255 kType:@"KN550",
256 kMAC:mac
257 };
258 }else{
259
260
261 dic = @{
262 kMEASUREMENT_DATE_BP: dateStr,
263 kLOW_BLOOD_PRESSURE_BP: [history objectForKey:@"dia"],
264 kHIGH_BLOOD_PRESSURE_BP: [history objectForKey:@"sys"],
265 kMEASUREMENT_AHR_BP: [history objectForKey:@"irregular"],
266 kPULSE_BP: [history objectForKey:@"heartRate"],
267 kDATAID: [history objectForKey:@"dataID"],
268 kType:@"KN550",
269 kMAC:mac
270
271 };
272 }
273
274
275
276 [tempArr addObject:dic];
277
278 }
279
280 if (tempArr.count > 0) {
281 NSDictionary* response = @{
282 kACTION:kACTION_HISTORICAL_DATA_BP,
283 kHISTORICAL_DATA_BP:[tempArr copy],
284 kType:@"KN550",
285 kMAC:mac
286 };
287 [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response];
288 }
289
290 } errorBlock:^(BPDeviceError error) {
291 [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error];
292 }];
293
294 }else{
295
296 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
297 }
298
299
300}
301
302RCT_EXPORT_METHOD(disconnect:(nonnull NSString *)mac){
303
304 if ([self getDeviceWithMac:mac]!=nil) {
305
306 [[self getDeviceWithMac:mac] commandDisconnectDevice];
307
308 }else{
309
310 [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect];
311
312 }
313
314
315}
316
317
318@end