summaryrefslogtreecommitdiff
path: root/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/PO1Module.m
diff options
context:
space:
mode:
Diffstat (limited to 'libs/ihealth-sdk/ios/ReactNativeIOSLibrary/PO1Module.m')
-rw-r--r--libs/ihealth-sdk/ios/ReactNativeIOSLibrary/PO1Module.m167
1 files changed, 167 insertions, 0 deletions
diff --git a/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/PO1Module.m b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/PO1Module.m
new file mode 100644
index 0000000..1fb2b9c
--- /dev/null
+++ b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/PO1Module.m
@@ -0,0 +1,167 @@
1//
2// PO1Module.m
3// ReactNativeIOSLibrary
4//
5// Created by daiqingquan on 2016/12/4.
6// Copyright © 2016年 daiqingquan. All rights reserved.
7//
8
9#import "PO1Module.h"
10#import "PO1.h"
11#import "PO1Controller.h"
12#import "PO1ProfileModule.h"
13
14@implementation PO1Module{
15
16
17 NSMutableDictionary*resultDic;
18
19}
20
21#define EVENT_NOTIFY @"event_notify_po1"
22#define kMAC_KEY @"mac"
23#define kACTION_KEY @"action"
24
25
26RCT_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
37#pragma mark
38#pragma mark - constantsToExport
39- (NSDictionary *)constantsToExport
40{
41 return @{ @"Event_Notify": EVENT_NOTIFY };
42
43}
44
45+ (BOOL)requiresMainQueueSetup
46{
47 return YES;
48}
49#pragma mark
50#pragma mark - Init
51-(id)init
52{
53 if (self=[super init])
54 {
55
56 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(devicePO1Measure:) name:@"PO1NotificationMeasureData" object:nil];
57
58 }
59
60
61 return self;
62}
63
64
65-(void)devicePO1Measure:(NSNotification *)tempNoti{
66
67 NSDictionary*measureDataDic= [tempNoti userInfo];
68
69 NSLog(@"devicePO1Measure:%@",measureDataDic);
70
71 NSDictionary* deviceInfo = @{kACTION_KEY:@"ACTION_BO_MEASUREMENT",@"WAVE":[measureDataDic valueForKey:@"wave"],@"PI":[measureDataDic valueForKey:@"PI"],@"PULSE_FORCE":[measureDataDic valueForKey:@"height"],@"BLOOD_OXYGEN":[measureDataDic valueForKey:@"spo2"],@"PULSE":[measureDataDic valueForKey:@"bpm"]};
72 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
73}
74
75
76-(void)dealloc{
77 [[NSNotificationCenter defaultCenter]removeObserver:self];
78}
79
80-(PO1*)getPO1WithMac:(NSString*)mac{
81
82 PO1Controller *controller = [PO1Controller shareIHPO1Controller];
83 NSArray *poDeviceArray = [controller getAllCurrentPO1Instace];
84
85 for(PO1 *tempPO1 in poDeviceArray){
86 if([mac isEqualToString:tempPO1.serialNumber]){
87
88 return tempPO1;
89 break;
90 }
91 }
92
93 return nil;
94}
95
96#pragma mark
97#pragma mark - Method
98
99RCT_EXPORT_METHOD(getAllConnectedDevices){
100
101
102 NSArray*po1array= [[PO1Controller shareIHPO1Controller] getAllCurrentPO1Instace];
103
104 NSMutableArray*deviceMacArray=[NSMutableArray array];
105
106 for (int i=0; i<[po1array count]; i++) {
107
108 PO1*po1=[po1array objectAtIndex:i];
109
110 [deviceMacArray addObject:po1.serialNumber];
111
112 }
113
114 NSDictionary* deviceInfo = @{kACTION_KEY:@"ACTION_GET_ALL_CONNECTED_DEVICES",@"devices":deviceMacArray};
115
116 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
117
118
119}
120
121
122
123RCT_EXPORT_METHOD(getBattery:(nonnull NSString *)mac){
124
125 if ([self getPO1WithMac:mac]!=nil) {
126
127
128 [[self getPO1WithMac:mac] commandPO1GetDeviceBattery:^(NSNumber *battery) {
129
130 NSDictionary* deviceInfo = @{kACTION_KEY:@"ACTION_GET_BATTERY",@"BATTERY":battery};
131 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
132
133 } withErrorBlock:^(PO1ErrorID errorID) {
134
135 }];
136 }else{
137
138 NSDictionary* deviceInfo = @{kACTION_KEY:@"ACTION_ERROR_PO1",@"ERROR_DESCRIPTION":@"disconnect"};
139 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
140
141 }
142
143
144}
145
146RCT_EXPORT_METHOD(disconnect:(nonnull NSString *)mac){
147
148
149 if ([self getPO1WithMac:mac]!=nil) {
150
151 [[self getPO1WithMac:mac] commandDisconnectDevice];
152
153 }else{
154
155
156
157 }
158
159
160
161}
162
163
164
165
166
167@end