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
|
//
// PO3Module.m
// ReactNativeIOSLibrary
//
// Created by daiqingquan on 2016/12/4.
// Copyright © 2016年 daiqingquan. All rights reserved.
//
#import "PO3Module.h"
#import "PO3.h"
#import "PO3Controller.h"
#import "POProfileModule.h"
#import "ManageDeviceController.h"
@implementation PO3Module{
NSMutableDictionary*resultDic;
}
#define EVENT_NOTIFY @"event_notify_po3"
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"];
}
#pragma mark
#pragma mark - constantsToExport
- (NSDictionary *)constantsToExport
{
return @{ @"Event_Notify": EVENT_NOTIFY };
}
+ (BOOL)requiresMainQueueSetup
{
return YES;
}
#pragma mark
#pragma mark - Init
-(id)init
{
if (self=[super init])
{
}
return self;
}
-(PO3*)getPO3WithMac:(NSString*)mac{
PO3Controller *controller = [PO3Controller shareIHPO3Controller];
NSArray *poDeviceArray = [controller getAllCurrentPO3Instace];
for(PO3 *tempPO3 in poDeviceArray){
if([mac isEqualToString:tempPO3.serialNumber]){
return tempPO3;
break;
}
}
return nil;
}
#pragma mark
#pragma mark - Method
RCT_EXPORT_METHOD(getAllConnectedDevices){
NSArray*po3array= [[PO3Controller shareIHPO3Controller] getAllCurrentPO3Instace];
NSMutableArray*deviceMacArray=[NSMutableArray array];
for (int i=0; i<[po3array count]; i++) {
PO3*po3=[po3array objectAtIndex:i];
[deviceMacArray addObject:po3.serialNumber];
}
NSDictionary* deviceInfo = @{@"action":@"ACTION_GET_ALL_CONNECTED_DEVICES",@"devices":deviceMacArray};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}
RCT_EXPORT_METHOD(getBattery:(nonnull NSString *)mac){
if ([self getPO3WithMac:mac]!=nil) {
[[self getPO3WithMac:mac] commandPO3SyncTime:^(BOOL resetSuc) {
} withErrorBlock:^(PO3ErrorID errorID) {
}];
[[self getPO3WithMac:mac] commandPO3GetDeviceBattery:^(NSNumber *battery) {
NSDictionary* deviceInfo = @{POACTION:@"ACTION_BATTERY_PO",PO_BATTERY:battery};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(PO3ErrorID errorID) {
}];
}else{
NSDictionary* deviceInfo = @{POACTION:@"ACTION_ERROR_PO",@"error_po":@"disconnect"};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}
}
RCT_EXPORT_METHOD(startMeasure:(nonnull NSString *)mac){
if ([self getPO3WithMac:mac]!=nil) {
[[self getPO3WithMac:mac] commandPO3StartMeasure:^(BOOL resetSuc) {
} withMeasureData:^(NSDictionary *measureDataDic) {
NSDictionary* deviceInfo = @{@"action":@"ACTION_LIVEDA_PO",@"pulseWave":[measureDataDic valueForKey:@"wave"],@"dataID":[measureDataDic valueForKey:@"dataID"],@"pi":[measureDataDic valueForKey:@"PI"],@"pulsestrength":[measureDataDic valueForKey:@"height"],@"bloodoxygen":[measureDataDic valueForKey:@"spo2"],@"heartrate":[measureDataDic valueForKey:@"bpm"]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
resultDic=[[NSMutableDictionary alloc] initWithDictionary:deviceInfo];
} withFinishMeasure:^(BOOL finishData) {
[resultDic setValue:@"ACTION_RESULTDATA_PO" forKey:POACTION];
[self sendEventWithName:EVENT_NOTIFY body:resultDic];
} withErrorBlock:^(PO3ErrorID errorID) {
}];
}else{
NSDictionary* deviceInfo = @{@"action":@"ACTION_ERROR_PO",@"error_po":@"disconnect"};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}
}
RCT_EXPORT_METHOD(getHistoryData:(nonnull NSString *)mac){
if ([self getPO3WithMac:mac]!=nil) {
[[self getPO3WithMac:mac] commandPO3SyncTime:^(BOOL resetSuc) {
} withErrorBlock:^(PO3ErrorID errorID) {
}];
NSMutableArray *resultArray = [[NSMutableArray alloc]init];
[[self getPO3WithMac:mac] commandPO3OfflineDataCount:^(NSNumber *dataCount) {
if(dataCount.intValue == 0){
NSDictionary *dic = @{POACTION:@"ACTION_NO_OFFLINEDATA_PO"};
[self sendEventWithName:EVENT_NOTIFY body:dic];
}
} withOfflineData:^(NSDictionary *OfflineData) {
NSDateFormatter *dateFormat = nil;
if (dateFormat == nil) {
dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//设定时间格式,这里可以设置成自己需要的格式
}
NSString *locationString=[dateFormat stringFromDate:[OfflineData valueForKey:@"date"]];
NSDictionary* deviceInfo = @{
POACTION:@"ACTION_OFFLINEDATA_PO",
@"measureDate":locationString,
@"dataID":[OfflineData valueForKey:@"dataID"],
@"pulseWave":[OfflineData valueForKey:@"wave"],
@"heartrate":[OfflineData valueForKey:@"bpm"],
@"bloodoxygen":[OfflineData valueForKey:@"spo2"]};
[resultArray addObject:deviceInfo];
} withOfflineWaveData:^(NSDictionary *offlineWaveDataDic) {
} withFinishMeasure:^(BOOL resetSuc) {
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:resultArray,@"offLineData",@"ACTION_OFFLINEDATA_PO",POACTION, nil];
[self sendEventWithName:EVENT_NOTIFY body:dic];
} withErrorBlock:^(PO3ErrorID errorID) {
}];
}else{
}
}
RCT_EXPORT_METHOD(disconnect:(nonnull NSString *)mac){
if ([self getPO3WithMac:mac]!=nil) {
[[ManageDeviceController commandGetInstance] commandDisconnectSelectDevice:[self getPO3WithMac:mac].currentUUID];
}else{
}
}
@end
|