diff options
Diffstat (limited to 'libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP3LModule.m')
| -rwxr-xr-x | libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP3LModule.m | 226 |
1 files changed, 226 insertions, 0 deletions
diff --git a/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP3LModule.m b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP3LModule.m new file mode 100755 index 0000000..05adb0c --- /dev/null +++ b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/BP3LModule.m | |||
| @@ -0,0 +1,226 @@ | |||
| 1 | // | ||
| 2 | // BP3LModule.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 "BP3LModule.h" | ||
| 10 | #import "BPProfileModule.h" | ||
| 11 | #import "BPMacroFile.h" | ||
| 12 | #import "BP3LController.h" | ||
| 13 | #import "BP3L.h" | ||
| 14 | #import "iHealthDeviceManagerModule.h" | ||
| 15 | |||
| 16 | #import "ScanDeviceController.h" | ||
| 17 | #import "ConnectDeviceController.h" | ||
| 18 | #define EVENT_NOTIFY @"BP3L.MODULE.NOTIFY" | ||
| 19 | |||
| 20 | @interface BP3LModule () | ||
| 21 | @property (nonatomic, assign) BOOL isMeasuring; | ||
| 22 | |||
| 23 | @end | ||
| 24 | |||
| 25 | @implementation BP3LModule | ||
| 26 | RCT_EXPORT_MODULE() | ||
| 27 | - (NSArray<NSString *> *)supportedEvents { | ||
| 28 | return @[@"event_notify", @"event_scan_device", @"event_scan_finish", | ||
| 29 | @"event_device_connected", @"event_device_connect_failed", | ||
| 30 | @"event_device_disconnect", @"event_authenticate_result", | ||
| 31 | @"event_notify_ts28b", @"event_notify_bg1", | ||
| 32 | @"action_connect_result_for_bg1"]; | ||
| 33 | } | ||
| 34 | |||
| 35 | |||
| 36 | - (NSDictionary *)constantsToExport | ||
| 37 | { | ||
| 38 | return @{ | ||
| 39 | @"Event_Notify":EVENT_NOTIFY, | ||
| 40 | |||
| 41 | }; | ||
| 42 | } | ||
| 43 | + (BOOL)requiresMainQueueSetup | ||
| 44 | { | ||
| 45 | return YES; | ||
| 46 | } | ||
| 47 | |||
| 48 | -(BP3L*)getDeviceWithMac:(NSString*)mac{ | ||
| 49 | |||
| 50 | BP3LController *controller = [BP3LController shareBP3LController]; | ||
| 51 | NSArray *bpDeviceArray = [controller getAllCurrentBP3LInstace]; | ||
| 52 | |||
| 53 | for(BP3L *tempDevice in bpDeviceArray){ | ||
| 54 | if([mac isEqualToString:tempDevice.serialNumber]){ | ||
| 55 | |||
| 56 | return tempDevice; | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | return nil; | ||
| 61 | } | ||
| 62 | |||
| 63 | |||
| 64 | #pragma mark - Method | ||
| 65 | |||
| 66 | |||
| 67 | #pragma mark-获取连接设备 | ||
| 68 | RCT_EXPORT_METHOD(getAllConnectedDevices){ | ||
| 69 | |||
| 70 | |||
| 71 | NSArray*bp3larray= [[BP3LController shareBP3LController] getAllCurrentBP3LInstace]; | ||
| 72 | |||
| 73 | NSMutableArray*deviceMacArray=[NSMutableArray array]; | ||
| 74 | |||
| 75 | for (int i=0; i<[bp3larray count]; i++) { | ||
| 76 | |||
| 77 | BP3L*bp3l=[bp3larray objectAtIndex:i]; | ||
| 78 | |||
| 79 | [deviceMacArray addObject:bp3l.serialNumber]; | ||
| 80 | |||
| 81 | } | ||
| 82 | |||
| 83 | NSDictionary* deviceInfo = @{@"action":@"ACTION_GET_ALL_CONNECTED_DEVICES",@"devices":deviceMacArray}; | ||
| 84 | |||
| 85 | [self sendEventWithName:EVENT_NOTIFY body:deviceInfo]; | ||
| 86 | |||
| 87 | |||
| 88 | } | ||
| 89 | |||
| 90 | |||
| 91 | |||
| 92 | |||
| 93 | RCT_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 | kACTION:isComplete ? kACTION_ZOREING_BP : kACTION_ZOREOVER_BP, | ||
| 102 | }; | ||
| 103 | [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 104 | } pressure:^(NSArray *pressureArr) { | ||
| 105 | weakSelf.isMeasuring = YES; | ||
| 106 | NSLog(@"pressure %@",pressureArr); | ||
| 107 | NSDictionary* response = @{ | ||
| 108 | kACTION:kACTION_ONLINE_PRESSURE_BP, | ||
| 109 | kBLOOD_PRESSURE_BP:pressureArr.firstObject, | ||
| 110 | }; | ||
| 111 | [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 112 | } waveletWithHeartbeat:^(NSArray *waveletArr) { | ||
| 113 | weakSelf.isMeasuring = YES; | ||
| 114 | NSLog(@"xiaoboWithHeart %@",waveletArr); | ||
| 115 | NSDictionary* response = @{ | ||
| 116 | kACTION:kACTION_ONLINE_PULSEWAVE_BP, | ||
| 117 | kFLAG_HEARTBEAT_BP:@(1), | ||
| 118 | kPULSEWAVE_BP:waveletArr | ||
| 119 | }; | ||
| 120 | [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 121 | } waveletWithoutHeartbeat:^(NSArray *waveletArr) { | ||
| 122 | weakSelf.isMeasuring = YES; | ||
| 123 | NSLog(@"xiaoboNoHeart %@",waveletArr); | ||
| 124 | NSDictionary* response = @{ | ||
| 125 | kACTION:kACTION_ONLINE_PULSEWAVE_BP, | ||
| 126 | kFLAG_HEARTBEAT_BP:@(0), | ||
| 127 | kPULSEWAVE_BP:waveletArr | ||
| 128 | }; | ||
| 129 | [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 130 | } result:^(NSDictionary *resultDict) { | ||
| 131 | weakSelf.isMeasuring = NO; | ||
| 132 | NSLog(@"result %@",resultDict); | ||
| 133 | NSDictionary* response = @{ | ||
| 134 | kACTION:kACTION_ONLINE_RESULT_BP, | ||
| 135 | kHIGH_BLOOD_PRESSURE_BP:resultDict[@"sys"], | ||
| 136 | kLOW_BLOOD_PRESSURE_BP:resultDict[@"dia"], | ||
| 137 | kPULSE_BP:resultDict[@"heartRate"], | ||
| 138 | kMEASUREMENT_AHR_BP:resultDict[@"irregular"], | ||
| 139 | kDATAID:resultDict[@"dataID"], | ||
| 140 | }; | ||
| 141 | [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 142 | } errorBlock:^(BPDeviceError error) { | ||
| 143 | weakSelf.isMeasuring = NO; | ||
| 144 | NSLog(@"error %d",error); | ||
| 145 | [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error]; | ||
| 146 | }]; | ||
| 147 | |||
| 148 | }else{ | ||
| 149 | self.isMeasuring = NO; | ||
| 150 | NSLog(@"error %d",BPDidDisconnect); | ||
| 151 | [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect]; | ||
| 152 | } | ||
| 153 | |||
| 154 | |||
| 155 | } | ||
| 156 | |||
| 157 | |||
| 158 | RCT_EXPORT_METHOD(stopMeasure:(nonnull NSString *)mac){ | ||
| 159 | if (!self.isMeasuring) { | ||
| 160 | NSLog(@"error %d",401); | ||
| 161 | [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:401]; | ||
| 162 | return; | ||
| 163 | } | ||
| 164 | __weak typeof(self) weakSelf = self; | ||
| 165 | if ([self getDeviceWithMac:mac]!=nil) { | ||
| 166 | [[self getDeviceWithMac:mac] stopBPMeassureSuccessBlock:^{ | ||
| 167 | |||
| 168 | weakSelf.isMeasuring = NO; | ||
| 169 | NSDictionary* response = @{ | ||
| 170 | kACTION:kACTION_INTERRUPTED_BP, | ||
| 171 | }; | ||
| 172 | [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 173 | |||
| 174 | } errorBlock:^(BPDeviceError error) { | ||
| 175 | |||
| 176 | NSLog(@"error %d",error); | ||
| 177 | weakSelf.isMeasuring = NO; | ||
| 178 | [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error]; | ||
| 179 | }]; | ||
| 180 | |||
| 181 | |||
| 182 | }else{ | ||
| 183 | weakSelf.isMeasuring = NO; | ||
| 184 | NSLog(@"error %d",BPDidDisconnect); | ||
| 185 | [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect]; | ||
| 186 | } | ||
| 187 | |||
| 188 | |||
| 189 | } | ||
| 190 | |||
| 191 | RCT_EXPORT_METHOD(getBattery:(nonnull NSString *)mac){ | ||
| 192 | |||
| 193 | if ([self getDeviceWithMac:mac]!=nil) { | ||
| 194 | __weak typeof(self) weakSelf = self; | ||
| 195 | [[self getDeviceWithMac:mac] commandEnergy:^(NSNumber *energyValue) { | ||
| 196 | NSDictionary* response = @{ | ||
| 197 | kACTION:kACTION_BATTERY_BP, | ||
| 198 | kBATTERY_BP:energyValue | ||
| 199 | }; | ||
| 200 | [BPProfileModule sendEventToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithDict:response]; | ||
| 201 | } errorBlock:^(BPDeviceError error) { | ||
| 202 | NSLog(@"error %d",error); | ||
| 203 | [BPProfileModule sendErrorToEmitter:weakSelf eventNotify:EVENT_NOTIFY WithCode:error]; | ||
| 204 | }]; | ||
| 205 | }else{ | ||
| 206 | NSLog(@"error %d",BPDidDisconnect); | ||
| 207 | [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect]; | ||
| 208 | } | ||
| 209 | |||
| 210 | |||
| 211 | } | ||
| 212 | |||
| 213 | RCT_EXPORT_METHOD(disconnect:(nonnull NSString *)mac){ | ||
| 214 | |||
| 215 | if ([self getDeviceWithMac:mac]!=nil) { | ||
| 216 | [[self getDeviceWithMac:mac] commandDisconnectDevice]; | ||
| 217 | }else{ | ||
| 218 | NSLog(@"error %d",BPDidDisconnect); | ||
| 219 | [BPProfileModule sendErrorToEmitter:self eventNotify:EVENT_NOTIFY WithCode:BPDidDisconnect]; | ||
| 220 | } | ||
| 221 | |||
| 222 | |||
| 223 | } | ||
| 224 | |||
| 225 | |||
| 226 | @end | ||
