summaryrefslogtreecommitdiff
path: root/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS2SModule.m
diff options
context:
space:
mode:
authorhc <haocheng.xie@respiree.com>2026-04-13 15:17:52 +0800
committerhc <haocheng.xie@respiree.com>2026-04-13 15:17:52 +0800
commitd6d9a09d505d11148599a95a5be3e1351edbe0ac (patch)
treea5f5891983d1ff207e99f683a5e151519cef4980 /libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS2SModule.m
parente4fb9966e762852bf17f21c8406501d42fae0b61 (diff)
Local iHealth SDK, device detail screen, iOS event fixes
Diffstat (limited to 'libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS2SModule.m')
-rw-r--r--libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS2SModule.m1052
1 files changed, 1052 insertions, 0 deletions
diff --git a/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS2SModule.m b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS2SModule.m
new file mode 100644
index 0000000..c048ca8
--- /dev/null
+++ b/libs/ihealth-sdk/ios/ReactNativeIOSLibrary/HS2SModule.m
@@ -0,0 +1,1052 @@
1//
2// HS2Module.m
3// ReactNativeIOSLibrary
4//
5// Created by jing on 2018/11/26.
6// Copyright © 2018年 daiqingquan. All rights reserved.
7//
8
9#import "HS2SModule.h"
10#import "HS2SProfileModule.h"
11#import "HSMacroFile.h"
12#import "HS2SController.h"
13#import "HS2S.h"
14#import "iHealthDeviceManagerModule.h"
15#import "ManageDeviceController.h"
16
17#define EVENT_NOTIFY @"HS2S.MODULE.NOTIFY"
18#define kMAC_KEY @"mac"
19#define kACTION_KEY @"action"
20#define kTYPE_KEY @"type"
21
22#define kTYPE_HS2S @"HS2S"
23
24@implementation HS2SModule
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#pragma mark-init
37
38-(NSDictionary *)constantsToExport{
39 return @{
40 @"Event_Notify" : EVENT_NOTIFY
41 };
42}
43
44+ (BOOL)requiresMainQueueSetup
45{
46 return YES;
47}
48
49-(HS2S *)getHS2SWithMac:(NSString *)mac{
50 HS2SController *controller = [HS2SController shareIHHS2SController];
51 NSArray *hs2sDeviceArray = [controller getAllCurrentHS2SInstace];
52 for (HS2S *tempHS2S in hs2sDeviceArray) {
53 if ([mac isEqualToString:tempHS2S.serialNumber]){
54 return tempHS2S;
55 break;
56 }
57 }
58 return nil;
59}
60
61#pragma mark
62#pragma mark - Method
63
64
65#pragma mark-获取连接设备
66RCT_EXPORT_METHOD(getAllConnectedDevices){
67
68
69 NSArray*hs2sarray= [[HS2SController shareIHHS2SController] getAllCurrentHS2SInstace];
70
71 NSMutableArray*deviceMacArray=[NSMutableArray array];
72
73 for (int i=0; i<[hs2sarray count]; i++) {
74
75 HS2S*hs2s=[hs2sarray objectAtIndex:i];
76
77 [deviceMacArray addObject:hs2s.serialNumber];
78
79 }
80
81 NSDictionary* deviceInfo = @{kACTION_KEY:ACTION_GET_ALL_CONNECTED_DEVICES,@"devices":deviceMacArray};
82 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
83
84
85}
86
87RCT_EXPORT_METHOD(getDeviceInfo:(nonnull NSString*)mac){
88 if ([self getHS2SWithMac:mac] != nil) {
89
90 [[self getHS2SWithMac:mac] commandGetHS2SDeviceInfo:^(NSDictionary *deviceInfo) {
91
92
93 NSDictionary* deviceInfoDic = @{kMAC_KEY:mac,
94 kTYPE_KEY:kTYPE_HS2S,
95 kACTION_KEY:ACTION_GET_HS2S_DEVICE_INFO,
96 HS2S_DEVICE_BATTERY:[deviceInfo valueForKey:@"Battary"],
97 HS2S_DEVICE_UNIT:[deviceInfo valueForKey:@"Unit"],
98 HS2S_DEVICE_USER_COUNT:[deviceInfo valueForKey:@"UserCount"]
99 };
100 [self sendEventWithName:EVENT_NOTIFY body:deviceInfoDic];
101
102 } DiaposeErrorBlock:^(HS2SDeviceError errorID) {
103
104 [self sendHS2SErrorCode:errorID mac:mac];
105 }];
106
107 }
108}
109
110RCT_EXPORT_METHOD(getBattery:(nonnull NSString*)mac){
111 if ([self getHS2SWithMac:mac] != nil) {
112
113 [[self getHS2SWithMac:mac]commandGetHS2SBattery:^(NSNumber *battary) {
114
115 NSDictionary *deviceInfo = @{kMAC_KEY:mac,kTYPE_KEY:kTYPE_HS2S,kACTION_KEY:ACTION_BATTARY_HS,BATTERY_HS:battary};
116
117 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
118
119
120 } DiaposeErrorBlock:^(HS2SDeviceError errorID) {
121
122 [self sendHS2SErrorCode:errorID mac:mac];
123
124 }];
125
126 }
127}
128RCT_EXPORT_METHOD(setUnit:(nonnull NSString*)mac :(nonnull NSNumber*)unit){
129
130
131 if ([self getHS2SWithMac:mac] != nil) {
132
133 HSUnit tempUnit;
134
135 switch ([unit intValue]) {
136 case 1:
137 tempUnit=HSUnit_Kg;
138 break;
139 case 2:
140 tempUnit=HSUnit_LB;
141 break;
142 case 3:
143 tempUnit=HSUnit_ST;
144 break;
145 default:
146 tempUnit=HSUnit_Kg;
147 break;
148 }
149
150
151 __weak typeof(self) weakSelf = self;
152
153 [[self getHS2SWithMac:mac] commandSetHS2SUnit:tempUnit result:^(BOOL result) {
154
155 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
156
157 kMAC_KEY:mac,
158
159 kTYPE_KEY:kTYPE_HS2S,
160
161 kACTION_KEY:ACTION_SET_HS2S_UNIT,
162
163 HS2S_SET_RESULT:[NSNumber numberWithBool:result]
164
165 }];
166
167 } DisposeErrorBlock:^(HS2SDeviceError errorID) {
168
169 [self sendHS2SErrorCode:errorID mac:mac];
170
171 }];
172
173 }
174
175}
176
177RCT_EXPORT_METHOD(getUserInfo:(nonnull NSString*)mac){
178
179 if ([self getHS2SWithMac:mac] != nil) {
180
181 __weak typeof(self) weakSelf = self;
182
183 [[self getHS2SWithMac:mac]commandGetHS2SUserInfo:^(NSDictionary *userInfo) {
184
185
186 NSMutableArray*tempUserArray=[userInfo valueForKey:@"UserInfo"];
187
188 NSMutableArray*resultArray=[NSMutableArray array];
189
190
191 if (tempUserArray>0) {
192
193 for (int i=0; i<tempUserArray.count; i++) {
194
195 NSMutableDictionary*tempDic=[tempUserArray objectAtIndex:i];
196
197 NSMutableDictionary*resultDic=[NSMutableDictionary dictionary];
198
199 [resultDic setValue:[tempDic valueForKey:@"UserInfo_Fitness"] forKey:HS2S_BODYBUILDING];
200
201 [resultDic setValue:[tempDic valueForKey:@"UserInfo_ImpedanceMark"] forKey:HS2S_IMPEDANCE];
202
203 [resultDic setValue:[tempDic valueForKey:@"UserInfo_Height"] forKey:HS2S_HEIGHT];
204
205 [resultDic setValue:[tempDic valueForKey:@"UserInfo_Age"] forKey:HS2S_AGE];
206
207 [resultDic setValue:[tempDic valueForKey:@"UserInfo_SEX"] forKey:HS2S_GENDER];
208
209 [resultDic setValue:[tempDic valueForKey:@"UserInfo_Weight"] forKey:HS2S_WEIGTH];
210
211
212 [resultDic setValue:[tempDic valueForKey:@"UserInfo_CreatTS"] forKey:HS2S_CREATE_TIME];
213
214
215 NSString * userIDstr =[[NSString alloc] initWithData:[tempDic valueForKey:@"UserInfo_ID"] encoding:NSUTF8StringEncoding];
216
217 [resultDic setValue:userIDstr forKey:HS2S_USER_ID];
218
219 [resultArray addObject:resultDic];
220
221 }
222 }
223
224
225
226
227 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
228
229 kMAC_KEY:mac,
230
231 kTYPE_KEY:kTYPE_HS2S,
232
233 kACTION_KEY:ACTION_GET_HS2S_USER_INFO,
234
235 HS2S_USER_INFO_COUNT:[userInfo valueForKey:@"UserCount"],
236
237 HS2S_USER_INFO_ARRAY:resultArray
238 }];
239
240 } DiaposeErrorBlock:^(HS2SDeviceError errorID) {
241
242 [self sendHS2SErrorCode:errorID mac:mac];
243
244 }];
245
246 }
247}
248
249RCT_EXPORT_METHOD(updateUserInfo:(nonnull NSString*)mac :(nonnull NSString*)userID :(nonnull NSNumber*)createTS :(nonnull NSNumber*)weight :(nonnull NSNumber*)age :(nonnull NSNumber*)height :(nonnull NSNumber*)sex :(nonnull NSNumber*)impedanceMark :(nonnull NSNumber*)fitnessMark){
250
251 if ([self getHS2SWithMac:mac] != nil) {
252
253
254 HealthUser*user=[HealthUser new];
255
256
257 NSData *data =[userID dataUsingEncoding:NSUTF8StringEncoding];
258
259 user.hs2SUserID=data;
260
261 user.createTS=[createTS integerValue];
262
263 user.weight=weight;
264
265 user.age=age;
266
267 user.height=height;
268
269 if ([sex integerValue]==0) {
270
271 user.sex=UserSex_Female;
272
273 }else{
274
275 user.sex=UserSex_Male;
276 }
277
278 if ([impedanceMark integerValue]==0) {
279
280 user.impedanceMark=HS2SImpedanceMark_NO;
281
282 }else{
283
284 user.impedanceMark=HS2SImpedanceMark_YES;
285 }
286
287 if ([fitnessMark integerValue]==0) {
288
289 user.fitnessMark=HS2SFitnessMark_NO;
290
291 }else{
292
293 user.fitnessMark=HS2SFitnessMark_YES;
294 }
295
296 __weak typeof(self) weakSelf = self;
297
298 [[self getHS2SWithMac:mac] commandUpdateHS2SUserInfoWithUser:user result:^(BOOL result) {
299
300
301 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
302
303 kMAC_KEY:mac,
304
305 kTYPE_KEY:kTYPE_HS2S,
306
307 kACTION_KEY:ACTION_UPDATE_HS2S_USER_INFO,
308
309 HS2S_SET_RESULT:[NSNumber numberWithBool:result]
310
311 }];
312
313
314 } DiaposeErrorBlock:^(HS2SDeviceError errorID) {
315
316 [self sendHS2SErrorCode:errorID mac:mac];
317 }];
318
319 }
320
321}
322
323RCT_EXPORT_METHOD(deleteUser:(nonnull NSString*)mac :(nonnull NSString*)userID){
324
325
326 NSData *userIDData =[userID dataUsingEncoding:NSUTF8StringEncoding];
327
328
329 __weak typeof(self) weakSelf = self;
330
331 if ([self getHS2SWithMac:mac] != nil) {
332
333 [[self getHS2SWithMac:mac]commandDeleteHS2SUserWithUserID:userIDData result:^(BOOL result) {
334
335 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
336
337 kMAC_KEY:mac,
338
339 kTYPE_KEY:kTYPE_HS2S,
340
341 kACTION_KEY:ACTION_DELETE_HS2S_USER,
342
343 HS2S_SET_RESULT:[NSNumber numberWithBool:result]
344
345 }];
346
347 } DiaposeErrorBlock:^(HS2SDeviceError errorID) {
348
349 [self sendHS2SErrorCode:errorID mac:mac];
350 }];
351
352 }
353}
354
355RCT_EXPORT_METHOD(getMemoryDataCount:(nonnull NSString*)mac :(nonnull NSString*)userID){
356
357
358 NSData *userIDData =[userID dataUsingEncoding:NSUTF8StringEncoding];
359
360 __weak typeof(self) weakSelf = self;
361
362 if ([self getHS2SWithMac:mac] != nil) {
363
364 [[self getHS2SWithMac:mac]commandGetHS2SMemoryDataCountWithUserID:userIDData memoryCount:^(NSNumber *count) {
365
366 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
367
368 kMAC_KEY:mac,
369
370 kTYPE_KEY:kTYPE_HS2S,
371
372 kACTION_KEY:ACTION_GET_HS2S_MEMORY_COUNT,
373
374 MEMORY_COUNT:count
375
376 }];
377
378 } DiaposeErrorBlock:^(HS2SDeviceError errorID) {
379
380 [self sendHS2SErrorCode:errorID mac:mac];
381 }];
382
383 }
384}
385
386RCT_EXPORT_METHOD(getMemoryData:(nonnull NSString*)mac :(nonnull NSString*)userID){
387
388
389 NSData *userIDData =[userID dataUsingEncoding:NSUTF8StringEncoding];
390
391 __weak typeof(self) weakSelf = self;
392
393 if ([self getHS2SWithMac:mac] != nil) {
394
395 [[self getHS2SWithMac:mac]commandGetHS2SMemoryDataWithUserID:userIDData memoryData:^(NSArray *data) {
396
397
398
399 NSMutableArray*resultArray=[NSMutableArray array];
400
401
402 if (data>0) {
403
404 for (int i=0; i<data.count; i++) {
405
406 NSMutableDictionary*tempDic=[data objectAtIndex:i];
407
408 NSMutableDictionary*resultDic=[NSMutableDictionary dictionary];
409
410 [resultDic setValue:[tempDic valueForKey:@"UserInfo_Fitness"] forKey:HS2S_BODYBUILDING];
411
412 [resultDic setValue:[tempDic valueForKey:@"UserInfo_ImpedanceMark"] forKey:HS2S_IMPEDANCE];
413
414 [resultDic setValue:[tempDic valueForKey:@"UserInfo_Height"] forKey:HS2S_HEIGHT];
415
416 [resultDic setValue:[tempDic valueForKey:@"UserInfo_Age"] forKey:HS2S_AGE];
417
418 [resultDic setValue:[tempDic valueForKey:@"UserInfo_SEX"] forKey:HS2S_GENDER];
419
420// [resultDic setValue:[tempDic valueForKey:@"UserInfo_Weight"] forKey:HS2S_WEIGTH];
421
422 [resultDic setValue:[tempDic valueForKey:@"HS2SWeigthResult"] forKey:HS2S_WEIGTH];
423
424 NSDate *tempDate =[tempDic valueForKey:@"HS2SMeasureTS"];
425
426
427 NSDateFormatter *mydateFormatter = [[NSDateFormatter alloc] init];
428
429
430 [mydateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
431
432
433 NSString *dateStr = [mydateFormatter stringFromDate:tempDate];
434
435 [resultDic setValue:dateStr forKey:HS2S_MEASURE_TIME];
436
437 [resultDic setValue:[tempDic valueForKey:@"HS2SBodyWeightFlag"] forKey:HS2S_INSTRUCTION_TYPE];
438
439 if ([[tempDic valueForKey:@"HS2SBodyWeightFlag"] intValue]==1) {
440
441
442 [resultDic setValue:[tempDic valueForKey:@"HS2SFatWeight"] forKey:HS2S_FAT_WEIGHT];
443
444 [resultDic setValue:[tempDic valueForKey:@"HS2SFatControl"] forKey:HS2S_FAT_CONTROL];
445
446 [resultDic setValue:[tempDic valueForKey:@"HS2SWeightControl"] forKey:HS2S_WEIGHT_CONTROL];
447
448 [resultDic setValue:[tempDic valueForKey:@"HS2SStandardWeight"] forKey:HS2S_STANDARD_WEIGHT];
449
450 [resultDic setValue:[tempDic valueForKey:@"HS2SSkeletalMuscle"] forKey:HS2S_STANDARD_WEIGHT];
451
452 [resultDic setValue:[tempDic valueForKey:@"HS2SBodyWaterPercentAge"] forKey:HS2S_BODY_WATER_RATE];
453
454 [resultDic setValue:[tempDic valueForKey:@"HS2SMuscle"] forKey:HS2S_MUSCLE_MASS];
455
456 [resultDic setValue:[tempDic valueForKey:@"HS2SMuscleControl"] forKey:HS2S_MUSCLE_CONTROL];
457
458 [resultDic setValue:[tempDic valueForKey:@"HS2SProteinPercentAge"] forKey:HS2S_PHYSICAL_AGE];
459
460 [resultDic setValue:[tempDic valueForKey:@"HS2SVFR"] forKey:HS2S_VISCERAL_FAT_GRADE];
461
462 [resultDic setValue:[tempDic valueForKey:@"HS2SResultBodyFatPercentAge"] forKey:HS2S_BODY_FIT_PERCENTAGE];
463
464 [resultDic setValue:[tempDic valueForKey:@"HS2SBoneMineral"] forKey:HS2S_BONE_SALT_CONTENT];
465
466
467 }
468
469 [resultArray addObject:resultDic];
470
471 }
472 }
473
474
475
476 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
477
478 kMAC_KEY:mac,
479
480 kTYPE_KEY:kTYPE_HS2S,
481
482 kACTION_KEY:ACTION_GET_HS2S_MEMORY_DATA,
483
484 MEMORY_DATA:resultArray
485
486 }];
487
488 } DiaposeErrorBlock:^(HS2SDeviceError errorID) {
489
490 [self sendHS2SErrorCode:errorID mac:mac];
491
492 }];
493
494 }
495}
496
497RCT_EXPORT_METHOD(deleteMemoryData:(nonnull NSString*)mac :(nonnull NSString*)userID){
498
499
500 NSData *userIDData =[userID dataUsingEncoding:NSUTF8StringEncoding];
501
502 __weak typeof(self) weakSelf = self;
503
504 if ([self getHS2SWithMac:mac] != nil) {
505
506 [[self getHS2SWithMac:mac]commandDeleteHS2SMemoryDataWithUserID:userIDData result:^(BOOL result) {
507
508 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
509
510 kMAC_KEY:mac,
511
512 kTYPE_KEY:kTYPE_HS2S,
513
514 kACTION_KEY:ACTION_DELETE_HS2S_MEMORY_DATA,
515
516 HS2S_SET_RESULT:[NSNumber numberWithBool:result]
517
518 }];
519
520 } DiaposeErrorBlock:^(HS2SDeviceError errorID) {
521
522 [self sendHS2SErrorCode:errorID mac:mac];
523
524 }];
525
526 }
527}
528
529RCT_EXPORT_METHOD(getAnonymousMemoryDataCount:(nonnull NSString*)mac){
530
531 __weak typeof(self) weakSelf = self;
532
533 if ([self getHS2SWithMac:mac] != nil) {
534
535 [[self getHS2SWithMac:mac]commandGetHS2SAnonymousMemoryDataCount:^(NSNumber *count) {
536
537 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
538
539 kMAC_KEY:mac,
540
541 kTYPE_KEY:kTYPE_HS2S,
542
543 kACTION_KEY:ACTION_GET_HS2S_ANONYMOUS_MEMORY_COUNT,
544
545 MEMORY_COUNT:count
546
547 }];
548
549 } DiaposeErrorBlock:^(HS2SDeviceError errorID) {
550
551 [self sendHS2SErrorCode:errorID mac:mac];
552
553 }];
554
555 }
556}
557
558RCT_EXPORT_METHOD(getAnonymousMemoryData:(nonnull NSString*)mac){
559
560
561 __weak typeof(self) weakSelf = self;
562
563
564 if ([self getHS2SWithMac:mac] != nil) {
565
566 [[self getHS2SWithMac:mac]commandGetHS2SAnonymousMemoryData:^(NSArray *data) {
567
568
569 NSMutableArray*resultArray=[NSMutableArray array];
570
571
572 if (data>0) {
573
574 for (int i=0; i<data.count; i++) {
575
576 NSMutableDictionary*tempDic=[data objectAtIndex:i];
577
578 NSMutableDictionary*resultDic=[NSMutableDictionary dictionary];
579
580
581 NSDate *tempDate =[tempDic valueForKey:@"HS2SMeasureTS"];
582
583 NSDateFormatter *mydateFormatter = [[NSDateFormatter alloc] init];
584
585 [mydateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
586
587 NSString *dateStr = [mydateFormatter stringFromDate:tempDate];
588
589 [resultDic setValue:[tempDic valueForKey:@"HS2SWeigthResult"] forKey:HS2S_WEIGTH];
590
591 [resultDic setValue:dateStr forKey:HS2S_MEASURE_TIME];
592
593 [resultArray addObject:resultDic];
594
595 }
596 }
597
598
599 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
600
601 kMAC_KEY:mac,
602
603 kTYPE_KEY:kTYPE_HS2S,
604
605 kACTION_KEY:ACTION_GET_HS2S_ANONYMOUS_MEMORY_DATA,
606
607 MEMORY_DATA:resultArray
608
609 }];
610
611 } DiaposeErrorBlock:^(HS2SDeviceError errorID) {
612
613 [self sendHS2SErrorCode:errorID mac:mac];
614
615 }];
616
617 }
618}
619
620RCT_EXPORT_METHOD(deleteAnonymousMemoryData:(nonnull NSString*)mac){
621
622 __weak typeof(self) weakSelf = self;
623
624
625 if ([self getHS2SWithMac:mac] != nil) {
626
627 [[self getHS2SWithMac:mac]commandDeleteHS2SAnonymousMemoryData:^(BOOL result) {
628
629 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
630
631 kMAC_KEY:mac,
632
633 kTYPE_KEY:kTYPE_HS2S,
634
635 kACTION_KEY:ACTION_DELETE_HS2S_ANONYMOUS_MEMORY_DATA,
636
637 HS2S_SET_RESULT:[NSNumber numberWithBool:result]
638
639 }];
640
641 } DiaposeErrorBlock:^(HS2SDeviceError errorID) {
642
643 [self sendHS2SErrorCode:errorID mac:mac];
644
645 }];
646
647 }
648}
649
650RCT_EXPORT_METHOD(measure:(nonnull NSString*)mac :(nonnull NSNumber*)userType :(nonnull NSString*)userID :(nonnull NSNumber*)createTS :(nonnull NSNumber*)weight :(nonnull NSNumber*)age :(nonnull NSNumber*)height :(nonnull NSNumber*)sex :(nonnull NSNumber*)impedanceMark :(nonnull NSNumber*)fitnessMark){
651
652
653 if ([self getHS2SWithMac:mac] != nil) {
654
655
656 HealthUser*user=[HealthUser new];
657
658
659 if ([userType integerValue]==0) {
660
661 user.userType=UserType_Guest;
662
663 }else{
664
665 user.userType=UserType_Normal;
666 }
667
668
669 NSData *data =[userID dataUsingEncoding:NSUTF8StringEncoding];
670
671
672 user.hs2SUserID=data;
673
674 user.createTS=[createTS integerValue];
675
676 user.weight=weight;
677
678 user.age=age;
679
680 user.height=height;
681
682 if ([sex integerValue]==0) {
683
684 user.sex=UserSex_Female;
685
686 }else{
687
688 user.sex=UserSex_Male;
689 }
690
691 if ([impedanceMark integerValue]==0) {
692
693 user.impedanceMark=HS2SImpedanceMark_NO;
694
695 }else{
696
697 user.impedanceMark=HS2SImpedanceMark_YES;
698 }
699
700 if ([fitnessMark integerValue]==0) {
701
702 user.fitnessMark=HS2SFitnessMark_NO;
703
704 }else{
705
706 user.fitnessMark=HS2SFitnessMark_YES;
707 }
708
709
710 [[self getHS2SWithMac:mac]commandStartHS2SMeasureWithUser:user weight:^(NSNumber *unStableWeight) {
711
712 NSDictionary *deviceInfo = @{kMAC_KEY:mac,kTYPE_KEY:kTYPE_HS2S,kACTION_KEY:ACTION_HS2S_ONLINE_DATA,HS2S_WEIGTH:unStableWeight};
713 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
714
715 } stableWeight:^(NSNumber *stableWeight) {
716
717 NSDictionary *deviceInfo =@{kMAC_KEY:mac,kTYPE_KEY:kTYPE_HS2S,kACTION_KEY:ACTION_HS2S_ONLINE_RESULT,HS2S_WEIGTH:stableWeight };
718
719 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
720
721 } weightAndBodyInfo:^(NSDictionary *weightAndBodyInfoDic) {
722
723 NSMutableDictionary*resultDic=[NSMutableDictionary dictionary];
724
725 [resultDic setValue:[weightAndBodyInfoDic valueForKey:@"UserInfo_Fitness"] forKey:HS2S_BODYBUILDING];
726
727 [resultDic setValue:[weightAndBodyInfoDic valueForKey:@"UserInfo_ImpedanceMark"] forKey:HS2S_IMPEDANCE];
728
729 [resultDic setValue:[weightAndBodyInfoDic valueForKey:@"UserInfo_Height"] forKey:HS2S_HEIGHT];
730
731 [resultDic setValue:[weightAndBodyInfoDic valueForKey:@"UserInfo_Age"] forKey:HS2S_AGE];
732
733 [resultDic setValue:[weightAndBodyInfoDic valueForKey:@"UserInfo_SEX"] forKey:HS2S_GENDER];
734
735 [resultDic setValue:[weightAndBodyInfoDic valueForKey:@"HS2SWeigthResult"] forKey:HS2S_WEIGTH];
736
737 NSDate *tempDate =[weightAndBodyInfoDic valueForKey:@"HS2SMeasureTS"];
738
739
740 NSDateFormatter *mydateFormatter = [[NSDateFormatter alloc] init];
741
742 [mydateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
743
744 NSString *dateStr = [mydateFormatter stringFromDate:tempDate];
745
746
747 [resultDic setValue:dateStr forKey:HS2S_MEASURE_TIME];
748
749 [resultDic setValue:[weightAndBodyInfoDic valueForKey:@"HS2SBodyWeightFlag"] forKey:HS2S_INSTRUCTION_TYPE];
750
751 if ([[weightAndBodyInfoDic valueForKey:@"HS2SBodyWeightFlag"] intValue]==1) {
752
753
754 [resultDic setValue:[weightAndBodyInfoDic valueForKey:@"HS2SFatWeight"] forKey:HS2S_FAT_WEIGHT];
755
756 [resultDic setValue:[weightAndBodyInfoDic valueForKey:@"HS2SFatControl"] forKey:HS2S_FAT_CONTROL];
757
758 [resultDic setValue:[weightAndBodyInfoDic valueForKey:@"HS2SWeightControl"] forKey:HS2S_WEIGHT_CONTROL];
759
760 [resultDic setValue:[weightAndBodyInfoDic valueForKey:@"HS2SStandardWeight"] forKey:HS2S_STANDARD_WEIGHT];
761
762 [resultDic setValue:[weightAndBodyInfoDic valueForKey:@"HS2SSkeletalMuscle"] forKey:HS2S_STANDARD_WEIGHT];
763
764 [resultDic setValue:[weightAndBodyInfoDic valueForKey:@"HS2SBodyWaterPercentAge"] forKey:HS2S_BODY_WATER_RATE];
765
766 [resultDic setValue:[weightAndBodyInfoDic valueForKey:@"HS2SMuscle"] forKey:HS2S_MUSCLE_MASS];
767
768 [resultDic setValue:[weightAndBodyInfoDic valueForKey:@"HS2SMuscleControl"] forKey:HS2S_MUSCLE_CONTROL];
769
770 [resultDic setValue:[weightAndBodyInfoDic valueForKey:@"HS2SProteinPercentAge"] forKey:HS2S_PHYSICAL_AGE];
771
772 [resultDic setValue:[weightAndBodyInfoDic valueForKey:@"HS2SVFR"] forKey:HS2S_VISCERAL_FAT_GRADE];
773
774 [resultDic setValue:[weightAndBodyInfoDic valueForKey:@"HS2SResultBodyFatPercentAge"] forKey:HS2S_BODY_FIT_PERCENTAGE];
775
776 [resultDic setValue:[weightAndBodyInfoDic valueForKey:@"HS2SBoneMineral"] forKey:HS2S_BONE_SALT_CONTENT];
777
778
779 }
780
781
782 NSDictionary *deviceInfo =@{kMAC_KEY:mac,kTYPE_KEY:kTYPE_HS2S,kACTION_KEY:ACTION_HS2S_BODYFAT_RESULT,HS2S_DATA_BODY_FAT_RESULT:resultDic };
783
784 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
785
786
787 } disposeHS2SMeasureFinish:^{
788
789 NSDictionary *deviceInfo =@{kMAC_KEY:mac,kTYPE_KEY:kTYPE_HS2S,kACTION_KEY:ACTION_HS2S_MEASURE_FINISH};
790
791 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
792
793 } DiaposeErrorBlock:^(HS2SDeviceError errorID) {
794
795 [self sendHS2SErrorCode:errorID mac:mac];
796
797 }];
798
799 }
800}
801
802
803RCT_EXPORT_METHOD(resetDevice:(nonnull NSString*)mac){
804
805
806 __weak typeof(self) weakSelf = self;
807
808
809 if ([self getHS2SWithMac:mac] != nil) {
810
811 [[self getHS2SWithMac:mac]commandResetHS2SDevice:^(BOOL result) {
812
813 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
814
815 kMAC_KEY:mac,
816
817 kTYPE_KEY:kTYPE_HS2S,
818
819 kACTION_KEY:ACTION_HS2S_RESET_DEVICE,
820
821 HS2S_SET_RESULT:[NSNumber numberWithBool:result]
822
823 }];
824
825 } DiaposeErrorBlock:^(HS2SDeviceError errorID) {
826
827 [self sendHS2SErrorCode:errorID mac:mac];
828
829 }];
830
831 }
832}
833
834//RCT_EXPORT_METHOD(broadCastTypeDevice:(nonnull NSString*)mac){
835//
836//
837// __weak typeof(self) weakSelf = self;
838//
839//
840// if ([self getHS2SWithMac:mac] != nil) {
841//
842// [[self getHS2SWithMac:mac]commandBroadCastTypeHS2SDevice:^(BOOL result) {
843//
844// [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
845//
846// kMAC_KEY:mac,
847//
848// kTYPE_KEY:kTYPE_HS2S,
849//
850// kACTION_KEY:ACTION_BroadCastType_DEVICE,
851//
852// HS2S_SET_RESULT:[NSNumber numberWithBool:result]
853//
854// }];
855//
856// } DiaposeErrorBlock:^(HS2SDeviceError errorID) {
857//
858// [self sendHS2SErrorCode:errorID mac:mac];
859//
860// }];
861//
862// }
863//}
864
865
866RCT_EXPORT_METHOD(setDeviceLightUp:(nonnull NSString*)mac){
867
868
869 __weak typeof(self) weakSelf = self;
870
871
872 if ([self getHS2SWithMac:mac] != nil) {
873
874
875 [[self getHS2SWithMac:mac] commandSetHS2SDeviceLightUp:^(BOOL result) {
876 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
877
878 kMAC_KEY:mac,
879
880 kTYPE_KEY:kTYPE_HS2S,
881
882 kACTION_KEY:ACTION_HS2S_LightUp_DEVICE,
883
884 HS2S_SET_RESULT:[NSNumber numberWithBool:result]
885
886 }];
887 } DiaposeErrorBlock:^(HS2SDeviceError errorID) {
888
889 [self sendHS2SErrorCode:errorID mac:mac];
890
891 }];
892
893
894 }
895}
896
897
898RCT_EXPORT_METHOD(enterHS2SHeartRateMeasurementMode:(nonnull NSString*)mac){
899
900
901 __weak typeof(self) weakSelf = self;
902
903
904 if ([self getHS2SWithMac:mac] != nil) {
905
906
907 [[self getHS2SWithMac:mac] commandEnterHS2SHeartRateMeasurementMode:^(NSDictionary *heartResultDic) {
908
909 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
910
911 kMAC_KEY:mac,
912
913 kTYPE_KEY:kTYPE_HS2S,
914
915 kACTION_KEY:ACTION_HS2S_MEASURE_HEARTRATE,
916
917 HS2S_MEASURE_HEARTRATE_RESULT:heartResultDic
918
919 }];
920
921 } measurementStatus:^(NSNumber *measurementStatus) {
922
923
924 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
925
926 kMAC_KEY:mac,
927
928 kTYPE_KEY:kTYPE_HS2S,
929
930 kACTION_KEY:ACTION_HS2S_MEASURE_HEARTRATE_DEVICE_STATUS,
931
932 HS2S_DEVICE_STATUS:measurementStatus
933
934 }];
935
936 } DiaposeErrorBlock:^(HS2SDeviceError errorID) {
937
938 [self sendHS2SErrorCode:errorID mac:mac];
939
940 }];
941
942
943 }
944}
945
946
947RCT_EXPORT_METHOD(exitHS2SHeartRateMeasurementMode:(nonnull NSString*)mac){
948
949
950 __weak typeof(self) weakSelf = self;
951
952
953 if ([self getHS2SWithMac:mac] != nil) {
954
955
956 [[self getHS2SWithMac:mac] commandExitHS2SHeartRateMeasurementMode:^(BOOL result) {
957
958
959 [weakSelf sendEventWithName:EVENT_NOTIFY body:@{
960
961 kMAC_KEY:mac,
962
963 kTYPE_KEY:kTYPE_HS2S,
964
965 kACTION_KEY:ACTION_HS2S_EXIT_MEASURE_HEARTRATE_STATUS,
966
967 HS2S_SET_RESULT:[NSNumber numberWithBool:result]
968
969 }];
970
971 } DiaposeErrorBlock:^(HS2SDeviceError errorID) {
972
973
974 [self sendHS2SErrorCode:errorID mac:mac];
975
976 }];
977
978
979 }
980}
981
982
983
984
985-(void)sendHS2SErrorCode:(HS2SDeviceError)errorID mac:(NSString*)mac{
986
987
988 NSString *errorMassage = [NSString string];
989 switch (errorID) {
990 case 0:
991 errorMassage = @"HS2SDeviceError_CommunicationTimeout";
992 break;
993 case 1:
994 errorMassage = @"HS2SDeviceError_ReceivedCommandError";
995 break;
996 case 2:
997 errorMassage = @"HS2SDeviceError_InputParameterError";
998 break;
999 case 3:
1000 errorMassage = @"HS2SDeviceError_MoreThanMaxNumbersOfUser";
1001 break;
1002 case 4:
1003 errorMassage = @"HS2SDeviceError_WriteFlashError";
1004 break;
1005 case 5:
1006 errorMassage = @"HS2SDeviceError_UserNotExist";
1007 break;
1008 case 6:
1009 errorMassage = @"HS2SDeviceError_StartMeasureError";
1010 break;
1011 case 7:
1012 errorMassage = @"HS2SDeviceError_MeasureTimeout";
1013 break;
1014 case 8:
1015 errorMassage = @"HS2SDeviceError_MeasureOverweight";
1016 break;
1017
1018 case 9:
1019 errorMassage = @"HS2SDeviceError_Disconnect";
1020 break;
1021 case 10:
1022 errorMassage = @"HS2SDeviceError_Unsupported";
1023 break;
1024
1025 default:
1026 break;
1027 }
1028
1029 NSDictionary *deviceInfo = @{kMAC_KEY:mac,kACTION_KEY:ACTION_ERROR_HS,ERROR_NUM_HS:errorMassage};
1030 [self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
1031
1032
1033}
1034
1035RCT_EXPORT_METHOD(disconnect:(nonnull NSString*)mac){
1036 if ([self getHS2SWithMac:mac] != nil){
1037
1038 [[self getHS2SWithMac:mac]commandDisconnectDevice];
1039 NSLog(@"End device connnect!");
1040
1041 }else{
1042
1043 }
1044}
1045
1046
1047- (void)sendEventWithAction:(NSString*)actionName keyString:(NSString*)key valueString:(id)value{
1048 [self sendEventWithName:EVENT_NOTIFY body:@{kACTION_KEY:actionName,key:value}];
1049}
1050
1051@end
1052