diff options
Diffstat (limited to 'libs/ihealth-sdk/ios/ReactNativeIOSLibrary/PO3Module.m')
| -rw-r--r-- | libs/ihealth-sdk/ios/ReactNativeIOSLibrary/PO3Module.m | 260 |
1 files changed, 260 insertions, 0 deletions
diff --git a/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/PO3Module.m b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/PO3Module.m new file mode 100644 index 0000000..6c1ddec --- /dev/null +++ b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/PO3Module.m | |||
| @@ -0,0 +1,260 @@ | |||
| 1 | // | ||
| 2 | // PO3Module.m | ||
| 3 | // ReactNativeIOSLibrary | ||
| 4 | // | ||
| 5 | // Created by daiqingquan on 2016/12/4. | ||
| 6 | // Copyright © 2016年 daiqingquan. All rights reserved. | ||
| 7 | // | ||
| 8 | |||
| 9 | #import "PO3Module.h" | ||
| 10 | #import "PO3.h" | ||
| 11 | #import "PO3Controller.h" | ||
| 12 | #import "POProfileModule.h" | ||
| 13 | #import "ManageDeviceController.h" | ||
| 14 | |||
| 15 | @implementation PO3Module{ | ||
| 16 | |||
| 17 | |||
| 18 | NSMutableDictionary*resultDic; | ||
| 19 | |||
| 20 | } | ||
| 21 | |||
| 22 | #define EVENT_NOTIFY @"event_notify_po3" | ||
| 23 | |||
| 24 | |||
| 25 | RCT_EXPORT_MODULE() | ||
| 26 | - (NSArray<NSString *> *)supportedEvents { | ||
| 27 | return @[@"event_notify", @"event_scan_device", @"event_scan_finish", | ||
| 28 | @"event_device_connected", @"event_device_connect_failed", | ||
| 29 | @"event_device_disconnect", @"event_authenticate_result", | ||
| 30 | @"event_notify_ts28b", @"event_notify_bg1", | ||
| 31 | @"action_connect_result_for_bg1"]; | ||
| 32 | } | ||
| 33 | |||
| 34 | |||
| 35 | |||
| 36 | #pragma mark | ||
| 37 | #pragma mark - constantsToExport | ||
| 38 | - (NSDictionary *)constantsToExport | ||
| 39 | { | ||
| 40 | return @{ @"Event_Notify": EVENT_NOTIFY }; | ||
| 41 | |||
| 42 | } | ||
| 43 | |||
| 44 | + (BOOL)requiresMainQueueSetup | ||
| 45 | { | ||
| 46 | return YES; | ||
| 47 | } | ||
| 48 | #pragma mark | ||
| 49 | #pragma mark - Init | ||
| 50 | -(id)init | ||
| 51 | { | ||
| 52 | if (self=[super init]) | ||
| 53 | { | ||
| 54 | |||
| 55 | |||
| 56 | } | ||
| 57 | return self; | ||
| 58 | } | ||
| 59 | |||
| 60 | -(PO3*)getPO3WithMac:(NSString*)mac{ | ||
| 61 | |||
| 62 | PO3Controller *controller = [PO3Controller shareIHPO3Controller]; | ||
| 63 | NSArray *poDeviceArray = [controller getAllCurrentPO3Instace]; | ||
| 64 | |||
| 65 | for(PO3 *tempPO3 in poDeviceArray){ | ||
| 66 | if([mac isEqualToString:tempPO3.serialNumber]){ | ||
| 67 | |||
| 68 | return tempPO3; | ||
| 69 | break; | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | return nil; | ||
| 74 | } | ||
| 75 | |||
| 76 | #pragma mark | ||
| 77 | #pragma mark - Method | ||
| 78 | |||
| 79 | RCT_EXPORT_METHOD(getAllConnectedDevices){ | ||
| 80 | |||
| 81 | |||
| 82 | NSArray*po3array= [[PO3Controller shareIHPO3Controller] getAllCurrentPO3Instace]; | ||
| 83 | |||
| 84 | NSMutableArray*deviceMacArray=[NSMutableArray array]; | ||
| 85 | |||
| 86 | for (int i=0; i<[po3array count]; i++) { | ||
| 87 | |||
| 88 | PO3*po3=[po3array objectAtIndex:i]; | ||
| 89 | |||
| 90 | [deviceMacArray addObject:po3.serialNumber]; | ||
| 91 | |||
| 92 | } | ||
| 93 | |||
| 94 | NSDictionary* deviceInfo = @{@"action":@"ACTION_GET_ALL_CONNECTED_DEVICES",@"devices":deviceMacArray}; | ||
| 95 | |||
| 96 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 97 | |||
| 98 | |||
| 99 | } | ||
| 100 | |||
| 101 | |||
| 102 | |||
| 103 | RCT_EXPORT_METHOD(getBattery:(nonnull NSString *)mac){ | ||
| 104 | |||
| 105 | if ([self getPO3WithMac:mac]!=nil) { | ||
| 106 | |||
| 107 | [[self getPO3WithMac:mac] commandPO3SyncTime:^(BOOL resetSuc) { | ||
| 108 | |||
| 109 | } withErrorBlock:^(PO3ErrorID errorID) { | ||
| 110 | |||
| 111 | }]; | ||
| 112 | |||
| 113 | [[self getPO3WithMac:mac] commandPO3GetDeviceBattery:^(NSNumber *battery) { | ||
| 114 | |||
| 115 | NSDictionary* deviceInfo = @{POACTION:@"ACTION_BATTERY_PO",PO_BATTERY:battery}; | ||
| 116 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 117 | |||
| 118 | } withErrorBlock:^(PO3ErrorID errorID) { | ||
| 119 | |||
| 120 | }]; | ||
| 121 | }else{ | ||
| 122 | |||
| 123 | NSDictionary* deviceInfo = @{POACTION:@"ACTION_ERROR_PO",@"error_po":@"disconnect"}; | ||
| 124 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 125 | |||
| 126 | } | ||
| 127 | |||
| 128 | |||
| 129 | } | ||
| 130 | |||
| 131 | |||
| 132 | RCT_EXPORT_METHOD(startMeasure:(nonnull NSString *)mac){ | ||
| 133 | |||
| 134 | |||
| 135 | if ([self getPO3WithMac:mac]!=nil) { | ||
| 136 | |||
| 137 | [[self getPO3WithMac:mac] commandPO3StartMeasure:^(BOOL resetSuc) { | ||
| 138 | |||
| 139 | } withMeasureData:^(NSDictionary *measureDataDic) { | ||
| 140 | |||
| 141 | 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"]}; | ||
| 142 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 143 | |||
| 144 | resultDic=[[NSMutableDictionary alloc] initWithDictionary:deviceInfo]; | ||
| 145 | |||
| 146 | } withFinishMeasure:^(BOOL finishData) { | ||
| 147 | |||
| 148 | [resultDic setValue:@"ACTION_RESULTDATA_PO" forKey:POACTION]; | ||
| 149 | |||
| 150 | [self sendEventWithName:EVENT_NOTIFY body:resultDic]; | ||
| 151 | |||
| 152 | } withErrorBlock:^(PO3ErrorID errorID) { | ||
| 153 | |||
| 154 | }]; | ||
| 155 | |||
| 156 | }else{ | ||
| 157 | |||
| 158 | NSDictionary* deviceInfo = @{@"action":@"ACTION_ERROR_PO",@"error_po":@"disconnect"}; | ||
| 159 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 160 | |||
| 161 | } | ||
| 162 | |||
| 163 | } | ||
| 164 | |||
| 165 | RCT_EXPORT_METHOD(getHistoryData:(nonnull NSString *)mac){ | ||
| 166 | |||
| 167 | |||
| 168 | |||
| 169 | if ([self getPO3WithMac:mac]!=nil) { | ||
| 170 | |||
| 171 | |||
| 172 | [[self getPO3WithMac:mac] commandPO3SyncTime:^(BOOL resetSuc) { | ||
| 173 | |||
| 174 | } withErrorBlock:^(PO3ErrorID errorID) { | ||
| 175 | |||
| 176 | }]; | ||
| 177 | |||
| 178 | NSMutableArray *resultArray = [[NSMutableArray alloc]init]; | ||
| 179 | |||
| 180 | [[self getPO3WithMac:mac] commandPO3OfflineDataCount:^(NSNumber *dataCount) { | ||
| 181 | |||
| 182 | if(dataCount.intValue == 0){ | ||
| 183 | NSDictionary *dic = @{POACTION:@"ACTION_NO_OFFLINEDATA_PO"}; | ||
| 184 | [self sendEventWithName:EVENT_NOTIFY body:dic]; | ||
| 185 | } | ||
| 186 | |||
| 187 | } withOfflineData:^(NSDictionary *OfflineData) { | ||
| 188 | |||
| 189 | |||
| 190 | NSDateFormatter *dateFormat = nil; | ||
| 191 | |||
| 192 | if (dateFormat == nil) { | ||
| 193 | dateFormat = [[NSDateFormatter alloc] init]; | ||
| 194 | [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//设定时间格式,这里可以设置成自己需要的格式 | ||
| 195 | } | ||
| 196 | |||
| 197 | NSString *locationString=[dateFormat stringFromDate:[OfflineData valueForKey:@"date"]]; | ||
| 198 | |||
| 199 | |||
| 200 | NSDictionary* deviceInfo = @{ | ||
| 201 | POACTION:@"ACTION_OFFLINEDATA_PO", | ||
| 202 | @"measureDate":locationString, | ||
| 203 | @"dataID":[OfflineData valueForKey:@"dataID"], | ||
| 204 | @"pulseWave":[OfflineData valueForKey:@"wave"], | ||
| 205 | @"heartrate":[OfflineData valueForKey:@"bpm"], | ||
| 206 | @"bloodoxygen":[OfflineData valueForKey:@"spo2"]}; | ||
| 207 | |||
| 208 | |||
| 209 | [resultArray addObject:deviceInfo]; | ||
| 210 | |||
| 211 | |||
| 212 | |||
| 213 | } withOfflineWaveData:^(NSDictionary *offlineWaveDataDic) { | ||
| 214 | |||
| 215 | } withFinishMeasure:^(BOOL resetSuc) { | ||
| 216 | |||
| 217 | NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:resultArray,@"offLineData",@"ACTION_OFFLINEDATA_PO",POACTION, nil]; | ||
| 218 | [self sendEventWithName:EVENT_NOTIFY body:dic]; | ||
| 219 | |||
| 220 | |||
| 221 | } withErrorBlock:^(PO3ErrorID errorID) { | ||
| 222 | |||
| 223 | }]; | ||
| 224 | |||
| 225 | }else{ | ||
| 226 | |||
| 227 | |||
| 228 | |||
| 229 | } | ||
| 230 | |||
| 231 | |||
| 232 | |||
| 233 | |||
| 234 | } | ||
| 235 | |||
| 236 | |||
| 237 | RCT_EXPORT_METHOD(disconnect:(nonnull NSString *)mac){ | ||
| 238 | |||
| 239 | |||
| 240 | |||
| 241 | |||
| 242 | if ([self getPO3WithMac:mac]!=nil) { | ||
| 243 | |||
| 244 | [[ManageDeviceController commandGetInstance] commandDisconnectSelectDevice:[self getPO3WithMac:mac].currentUUID]; | ||
| 245 | |||
| 246 | }else{ | ||
| 247 | |||
| 248 | |||
| 249 | |||
| 250 | } | ||
| 251 | |||
| 252 | |||
| 253 | |||
| 254 | } | ||
| 255 | |||
| 256 | |||
| 257 | |||
| 258 | |||
| 259 | |||
| 260 | @end | ||
