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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
|
//
// AM3SModule.m
// ReactNativeIOSLibrary
//
// Created by daiqingquan on 2016/11/23.
// Copyright © 2016年 daiqingquan. All rights reserved.
//
#import "AM3SModule.h"
#import "AMProfileModule.h"
#import "AMMacroFile.h"
#import "AM3SController_V2.h"
#import "AM3S_V2.h"
#define EVENT_NOTIFY @"event_notify_am3s"
@implementation AM3SModule
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"];
}
- (NSDictionary *)constantsToExport
{
return @{
@"Event_Notify": EVENT_NOTIFY
};
}
+ (BOOL)requiresMainQueueSetup
{
return YES;
}
#pragma mark
#pragma mark - Init
-(id)init
{
if (self=[super init])
{
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(DeviceConnectForAM3S:) name:AM3SConnectNoti object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(DeviceDisConnectForAM3S:) name:AM3SDisConnectNoti object:nil];
[AM3SController_V2 shareIHAM3SController];
}
return self;
}
-(AM3S_V2*)getAM3SWithMac:(NSString*)mac{
AM3SController_V2 *controller = [AM3SController_V2 shareIHAM3SController];
NSArray *amDeviceArray = [controller getAllCurrentAM3SInstace];
for(AM3S_V2 *tempAM3S in amDeviceArray){
if([mac isEqualToString:tempAM3S.serialNumber]){
return tempAM3S;
break;
}
}
return nil;
}
#pragma mark
#pragma mark - Notification
#pragma mark - AM3S
-(void)DeviceConnectForAM3S:(NSNotification *)tempNoti{
AM3SController_V2 *controller = [AM3SController_V2 shareIHAM3SController];
NSArray *amDeviceArray = [controller getAllCurrentAM3SInstace];
AM3S_V2 *AMInstance = [amDeviceArray objectAtIndex:0];
}
-(void)DeviceDisConnectForAM3S:(NSNotification *)tempNoti{
AM3SController_V2 *controller = [AM3SController_V2 shareIHAM3SController];
}
#pragma mark - Method
#pragma mark-获取连接设备
RCT_EXPORT_METHOD(getAllConnectedDevices){
NSArray*am3sarray= [[AM3SController_V2 shareIHAM3SController] getAllCurrentAM3SInstace];
NSMutableArray*deviceMacArray=[NSMutableArray array];
for (int i=0; i<[am3sarray count]; i++) {
AM3S_V2*am3s=[am3sarray objectAtIndex:i];
[deviceMacArray addObject:am3s.serialNumber];
}
NSDictionary* deviceInfo = @{@"action":@"ACTION_GET_ALL_CONNECTED_DEVICES",@"devices":deviceMacArray};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}
#pragma mark-恢复出厂
RCT_EXPORT_METHOD(reset:(nonnull NSString *)mac){
if ([self getAM3SWithMac:mac]!=nil) {
[[self getAM3SWithMac:mac] commandAM3SResetDevice:^(BOOL resetSuc) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"reset_am",@"reset":[NSNumber numberWithInteger:resetSuc]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark - 得到用户ID
RCT_EXPORT_METHOD(getUserId:(nonnull NSString *)mac){
if ([self getAM3SWithMac:mac]!=nil) {
[[self getAM3SWithMac:mac] commandAM3SGetDeviceUserID:^(unsigned int userID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"userid_am",@"userid":[NSNumber numberWithInteger:userID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark - 设置用户ID
RCT_EXPORT_METHOD(setUserId:(nonnull NSString *)mac :(nonnull NSNumber *)uesrID){
if ([self getAM3SWithMac:mac]!=nil) {
[[self getAM3SWithMac:mac] commandAM3SSetUserID:uesrID withFinishResult:^(BOOL resetSuc) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"set_userid_success_am"};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark - 同步时间
RCT_EXPORT_METHOD(syncRealTime:(nonnull NSString *)mac){
if ([self getAM3SWithMac:mac]!=nil) {
[[self getAM3SWithMac:mac] commandAM3SSyncTime:^(BOOL resetSuc) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"set_sync_time_success_am"};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark - 设置用户信息
RCT_EXPORT_METHOD(setUserInfo:(nonnull NSString *)mac :(nonnull NSNumber *)age :(nonnull NSNumber *)height :(nonnull NSNumber *)weight :(nonnull NSNumber *)gender :(nonnull NSNumber *)unit :(nonnull NSNumber *)target :(nonnull NSNumber *)activityLevel){
if ([self getAM3SWithMac:mac]!=nil) {
HealthUser *myUser = [[HealthUser alloc]init];
myUser.age = age;
myUser.sex = UserSex_Male;
myUser.height = height;
myUser.weight = weight;
myUser.activityLevel = activityLevel;
NSDictionary *dic = [[NSMutableDictionary alloc]init];
[[self getAM3SWithMac:mac] commandAM3SSetUserInfo:myUser withUnit:unit withActiveGoal:target withSetUserInfoFinishResult:^(BOOL resetSuc) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"set_userinfo_success_am"};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withSetBMR:^(BOOL resetSuc) {
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark - 得到用户信息
RCT_EXPORT_METHOD(getUserInfo:(nonnull NSString *)mac){
if ([self getAM3SWithMac:mac]!=nil) {
[[self getAM3SWithMac:mac] commandAM3SGetUserInfo:^(NSDictionary *userInfo) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"get_userinfo_am",@"age":[userInfo valueForKey:@"Age"],@"step":[userInfo valueForKey:@"Step"],@"height":[userInfo valueForKey:@"Height"],@"gender":[userInfo valueForKey:@"Gender"],@"weight":[userInfo valueForKey:@"Weight"],@"unit":[userInfo valueForKey:@"Unit"],@"target1":[userInfo valueForKey:@"TotalStep1"],@"target2":[userInfo valueForKey:@"TotalStep2"],@"target3":[userInfo valueForKey:@"TotalStep3"]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark - 得到闹钟个数
RCT_EXPORT_METHOD(getAlarmClockNum:(nonnull NSString *)mac){
if ([self getAM3SWithMac:mac]!=nil) {
[[self getAM3SWithMac:mac] commandAM3SGetTotoalAlarmInfo:^(NSMutableArray *totoalAlarmArray) {
NSMutableArray * IDArray = [[NSMutableArray alloc]init];
if (totoalAlarmArray.count > 0){
for (NSDictionary *dic in totoalAlarmArray) {
[IDArray addObject:[dic valueForKey:@"AlarmId"]];
}
}
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"get_alarmnum_am",@"alarmclocknumber":[NSNumber numberWithInt:IDArray.count],@"alarmclocknumberid":IDArray};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark - 得到闹钟信息
RCT_EXPORT_METHOD(getAlarmClockDetail:(nonnull NSString *)mac :(nonnull NSArray *)alarmIDS){
if ([self getAM3SWithMac:mac]!=nil) {
[[self getAM3SWithMac:mac] commandAM3SGetTotoalAlarmInfo:^(NSMutableArray *totoalAlarmArray) {
NSMutableArray * alarmInfoArray = [[NSMutableArray alloc]init];
if (totoalAlarmArray.count > 0){
for (NSDictionary *dic in totoalAlarmArray) {
NSMutableDictionary *alartDic = [[NSMutableDictionary alloc]init];
for (NSNumber * alarmID in alarmIDS) {
NSNumber *deviceAlarmID = [dic valueForKey:@"AlarmId"];
if(deviceAlarmID.intValue == alarmID.intValue){
[alartDic setValue:[dic valueForKey:@"AlarmId"] forKey:@"alarmid"];
NSDate *date = [dic valueForKey:@"Time"];
NSDateFormatter *dateFormater=[[NSDateFormatter alloc]init];
[dateFormater setTimeZone:[NSTimeZone defaultTimeZone]];
[dateFormater setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[dateFormater setDateFormat:@"HH:mm"];
NSString *dateString = [dateFormater stringFromDate:date];
[alartDic setValue:dateString forKey:@"time"];
[alartDic setValue:[dic valueForKey:@"IsRepeat"] forKey:@"repeat"];
NSMutableDictionary * weekDic = [[NSMutableDictionary alloc]init];
[weekDic setValue:[[dic valueForKey:@"Week"] objectAtIndex:0] forKey:@"sun"];
[weekDic setValue:[[dic valueForKey:@"Week"] objectAtIndex:1] forKey:@"mon"];
[weekDic setValue:[[dic valueForKey:@"Week"] objectAtIndex:2] forKey:@"tue"];
[weekDic setValue:[[dic valueForKey:@"Week"] objectAtIndex:3] forKey:@"wed"];
[weekDic setValue:[[dic valueForKey:@"Week"] objectAtIndex:4] forKey:@"thu"];
[weekDic setValue:[[dic valueForKey:@"Week"] objectAtIndex:5] forKey:@"fri"];
[weekDic setValue:[[dic valueForKey:@"Week"] objectAtIndex:6] forKey:@"sat"];
[alartDic setValue:weekDic forKey:@"get_alarm_week"];
[alartDic setValue:[dic valueForKey:@"Switch"] forKey:@"switch"];
[alarmInfoArray addObject:alartDic];
}
}
}
}
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"get_alarminfo_am",@"alarmclockdetail":alarmInfoArray};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark - 设置闹钟信息
RCT_EXPORT_METHOD(setAlarmClock:(nonnull NSString *)mac :(nonnull NSNumber *)alarmID :(nonnull NSNumber *)hour :(nonnull NSNumber *)min :(nonnull NSNumber*)isRepeat :(nonnull NSArray *)weekArray :(nonnull NSNumber *)isOn){
if ([self getAM3SWithMac:mac]!=nil) {
if(alarmID.integerValue < 0 || alarmID.integerValue > 3 ||
hour.integerValue > 23 || hour.integerValue < 0 ||
min.integerValue > 59 || min.integerValue < 0){
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:400]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
return;
}
NSDateFormatter *formater=[[NSDateFormatter alloc]init];
[formater setTimeZone:[NSTimeZone defaultTimeZone]];
[formater setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[formater setDateFormat:@"HH-mm"];
NSString * timeStr = [NSString stringWithFormat:@"%@-%@",hour,min];
NSDate *date = [formater dateFromString:timeStr];
NSDictionary *dic = [[NSDictionary alloc]initWithObjectsAndKeys:alarmID,@"AlarmId",date,@"Time",isRepeat,@"IsRepeat",weekArray,@"Week",isOn,@"Switch", nil];
[[self getAM3SWithMac:mac] commandAM3SSetAlarmDictionary:dic withFinishResult:^(BOOL resetSuc) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"set_alarminfo_success_am"};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark - 删除闹钟信息
RCT_EXPORT_METHOD(deleteAlarmClock:(nonnull NSString *)mac :(nonnull NSNumber *)alarmID){
if ([self getAM3SWithMac:mac]!=nil) {
[[self getAM3SWithMac:mac] commandAM3SDeleteAlarmID:alarmID withFinishResult:^(BOOL resetSuc) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"delete_alarm_success_am"};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark - 查询提醒信息
RCT_EXPORT_METHOD(getActivityRemind:(nonnull NSString *)mac){
if ([self getAM3SWithMac:mac]!=nil) {
[[self getAM3SWithMac:mac] commandAM3SGetReminderInfo:^(NSArray *remindInfo) {
NSDictionary *dic = [remindInfo objectAtIndex:0];
NSDate *date = [dic valueForKey:@"Time"];
NSDateFormatter *dateFormater=[[NSDateFormatter alloc]init];
[dateFormater setTimeZone:[NSTimeZone defaultTimeZone]];
[dateFormater setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[dateFormater setDateFormat:@"HH:mm"];
NSString *dateString = [dateFormater stringFromDate:date];
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"get_activity_remind_am",@"time":dateString,@"switch":[dic valueForKey:@"Switch"]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark - 设置提醒信息
RCT_EXPORT_METHOD(setActivityRemind:(nonnull NSString *)mac :(nonnull NSNumber *)hour :(nonnull NSNumber *)min :(nonnull NSNumber *)isOn){
if ([self getAM3SWithMac:mac]!=nil) {
if(hour.integerValue > 23 || hour.integerValue < 0 ||
min.integerValue > 59 || min.integerValue < 0){
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:400]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
return;
}
NSDateFormatter *formater=[[NSDateFormatter alloc]init];
[formater setTimeZone:[NSTimeZone defaultTimeZone]];
[formater setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
[formater setDateFormat:@"HH-mm"];
NSString * timeStr = [NSString stringWithFormat:@"%@-%@",hour,min];
NSDate *date = [formater dateFromString:timeStr];
NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:date,@"Time",isOn,@"Switch", nil];
[[self getAM3SWithMac:mac] commandAM3SSetReminderDictionary:dic withFinishResult:^(BOOL resetSuc) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"set_activityremind_success_am"};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark - 同步运动
RCT_EXPORT_METHOD(syncActivityData:(nonnull NSString *)mac){
if ([self getAM3SWithMac:mac]!=nil) {
[[self getAM3SWithMac:mac] commandAM3SStartSyncActiveData:^(NSDictionary *startDataDictionary) {
} withActiveHistoryData:^(NSArray *historyDataArray) {
NSMutableArray *lastArray = [[NSMutableArray alloc]init];
for (NSDictionary *dic in historyDataArray) {
NSMutableDictionary * lastDic = [[NSMutableDictionary alloc]init];
NSDateFormatter *dateFormat = nil;
if (dateFormat == nil) {
dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//设定时间格式,这里可以设置成自己需要的格式
}
NSString *locationString=[dateFormat stringFromDate:[dic valueForKey:AMDate]];
[lastDic setValue:locationString forKey:@"time"];
[lastDic setValue:[dic valueForKey:AMStepSize] forKey:@"stepsize"];
[lastDic setValue:[dic valueForKey:AMCalorie] forKey:@"calorie"];
[lastDic setValue:[dic valueForKey:AMStepNum] forKey:@"step"];
[lastDic setValue:[dic valueForKey:@"dataID"] forKey:@"dataID"];
[lastArray addObject:lastDic];
}
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:lastArray forKey:@"activity_each_data"];
NSArray *array = [NSArray arrayWithObjects:dictionary, nil];
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"sync_activity_data_am",@"activity":array};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withActiveFinishTransmission:^{
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark - 同步睡眠
RCT_EXPORT_METHOD(syncSleepData:(nonnull NSString *)mac){
if ([self getAM3SWithMac:mac]!=nil) {
[[self getAM3SWithMac:mac] commandAM3SStartSyncSleepData:^(NSDictionary *startDataDictionary) {
} withSleepHistoryData:^(NSArray *historyDataArray) {
NSMutableArray *lastArray = [[NSMutableArray alloc]init];
for (NSArray *array in historyDataArray) {
for (NSDictionary *dic in array) {
NSMutableDictionary * lastDic = [[NSMutableDictionary alloc]init];
NSDateFormatter *dateFormat = nil;
if (dateFormat == nil) {
dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//设定时间格式,这里可以设置成自己需要的格式
}
NSString *locationString=[dateFormat stringFromDate:[dic valueForKey:AMDate]];
[lastDic setValue:locationString forKey:@"time"]; [lastDic setValue:[dic valueForKey:@"SleepData"] forKey:@"level"];
[lastDic setValue:[dic valueForKey:@"dataID"] forKey:@"dataID"];
[lastArray addObject:lastDic];
}
}
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:lastArray forKey:@"sleep_each_data"];
NSArray *array = [NSArray arrayWithObjects:dictionary, nil];
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"sync_sleep_data_am",@"sleep":array};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withSleepFinishTransmission:^{
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark - 同步阶段性
RCT_EXPORT_METHOD(syncStageReportData:(nonnull NSString *)mac){
if ([self getAM3SWithMac:mac]!=nil) {
[[self getAM3SWithMac:mac] commandAM3SStartSyncStageData:^(NSArray *measureDataArray) {
NSMutableArray *lastArray = [[NSMutableArray alloc]init];
NSPredicate *pre = [NSPredicate predicateWithFormat:@"ReportState == 1"];
NSArray *workoutArray = [measureDataArray filteredArrayUsingPredicate:pre];
if (workoutArray.count != 0)
{
for (NSDictionary *dic in workoutArray) {
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc]init];
[dictionary setValue:@"stage_data_type_workout" forKey:@"type"];
NSDateFormatter *dateFormat = nil;
if (dateFormat == nil) {
dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//设定时间格式,这里可以设置成自己需要的格式
}
NSString *locationString=[dateFormat stringFromDate:[dic valueForKey:Work_outMeasureDate]];
[dictionary setValue:locationString forKey:@"stoptime"];
[dictionary setValue:[dic valueForKey:Work_outTimeNumber] forKey:@"usedtime"];
[dictionary setValue:[dic valueForKey:Work_outStepNumber] forKey:@"stage_data_workout_step"];
[dictionary setValue:[dic valueForKey:Work_outLengthNumber] forKey:@"stage_data_distance"];
[dictionary setValue:[dic valueForKey:Work_outCalories] forKey:@"calorie"];
[dictionary setValue:[dic valueForKey:@"dataID"] forKey:@"dataID"];
[lastArray addObject:dictionary];
}
}
NSPredicate *predicateSleep = [NSPredicate predicateWithFormat:@"ReportState == 2"];
NSArray *sleepArray = [measureDataArray filteredArrayUsingPredicate:predicateSleep];
if (sleepArray.count != 0)
{
for (NSDictionary *dic in sleepArray) {
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc]init];
[dictionary setValue:@"sleep" forKey:@"type"];
NSDateFormatter *dateFormat = nil;
if (dateFormat == nil) {
dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//设定时间格式,这里可以设置成自己需要的格式
}
NSString *locationString=[dateFormat stringFromDate:[dic valueForKey:Sleep_summaryMeasureDate]];
[dictionary setValue:locationString forKey:@"stoptime"];
[dictionary setValue:[dic valueForKey:Sleep_summarySleepTime] forKey:@"usedtime"];
[dictionary setValue:[dic valueForKey:Sleep_summarysleepEfficiency] forKey:@"sleepefficiency"];
[dictionary setValue:[dic valueForKey:Sleep_summarysleepAddMinute] forKey:@"is50min"];
[lastArray addObject:dictionary];
}
}
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"sync_stage_data_am",@"stage_data":lastArray};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withStageDataFinishTransmission:^(BOOL resetSuc) {
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark - 同步阶实时数据
RCT_EXPORT_METHOD(syncRealData:(nonnull NSString *)mac){
if ([self getAM3SWithMac:mac]!=nil) {
[[self getAM3SWithMac:mac] commandAM3SStartSyncCurrentActiveData:^(NSDictionary *activeDictionary) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"sync_real_data_am",@"step":[activeDictionary valueForKey:@"Step"],@"calorie":[activeDictionary valueForKey:@"Calories"],@"totalcalories":[activeDictionary valueForKey:@"TotalCalories"]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark - 查询状态
RCT_EXPORT_METHOD(queryAMState:(nonnull NSString *)mac){
if ([self getAM3SWithMac:mac]!=nil) {
__block NSInteger index;
[[self getAM3SWithMac:mac] commandAM3SGetDeviceStateInfo:^(AM3SQueryState queryState) {
index = queryState;
} withBattery:^(NSNumber *battery) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"query_state_am",@"query_state":[NSNumber numberWithInteger:index],@"battery":battery};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark - 设置BMR
RCT_EXPORT_METHOD(setUserBmr:(nonnull NSString *)mac :(nonnull NSNumber *)bmr){
if ([self getAM3SWithMac:mac]!=nil) {
[[self getAM3SWithMac:mac] commandAM3SSetBMR:bmr withFinishResult:^(BOOL resetSuc) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"set_bmr_success_am"};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark - 随机数
RCT_EXPORT_METHOD(sendRandom:(nonnull NSString *)mac){
if ([self getAM3SWithMac:mac]!=nil) {
[[self getAM3SWithMac:mac] commandAM3SSetRandomNumber:^(NSString *randomNumString) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"get_random_am",@"random":randomNumString};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark - 断开
RCT_EXPORT_METHOD(disconnect:(nonnull NSString *)mac){
if ([self getAM3SWithMac:mac]!=nil) {
[[self getAM3SWithMac:mac] commandAM3SDisconnect:^(BOOL resetSuc) {
NSDictionary* deviceInfo = @{@"mac":mac};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark-设置小时制
RCT_EXPORT_METHOD(setHourMode:(nonnull NSString *)mac :(nonnull NSNumber*)hourMode){
if ([self getAM3SWithMac:mac]!=nil) {
AM3STimeFormatAndNation formatAndNation;
formatAndNation = hourMode.intValue;
[[self getAM3SWithMac:mac]commandAM3SSetTimeFormatAndNation:hourMode.intValue withFinishResult:^(BOOL resetSuc) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"set_hour_mode_success_am"};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark-得到小时制
RCT_EXPORT_METHOD(getHourMode:(nonnull NSString *)mac){
if ([self getAM3SWithMac:mac]!=nil) {
[[self getAM3SWithMac:mac] commandAM3SGetTimeFormatAndNation:^(AM3STimeFormatAndNation timeFormatAndNation) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"get_hour_mode_am",@"hourtype":[NSNumber numberWithInt:timeFormatAndNation]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark-设置图片
RCT_EXPORT_METHOD(setPicture:(nonnull NSString *)mac :(nonnull NSNumber *)index){
if ([self getAM3SWithMac:mac]!=nil) {
if((index.intValue !=0) && (index.intValue !=1)){
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:400]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
return;
}
AM3SPicture piction;
piction = index.intValue;
[[self getAM3SWithMac:mac] commandAM3SSetPicture:piction withFinishResult:^(BOOL resetSuc) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"set_picture_success_am"};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
#pragma mark-得到图片
RCT_EXPORT_METHOD(getPicture:(nonnull NSString *)mac){
if ([self getAM3SWithMac:mac]!=nil) {
[[self getAM3SWithMac:mac] commandAM3SGetPicture:^(AM3SPicture picture) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"get_picture_am",@"get_picture_am":[NSNumber numberWithInt:picture]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
} withErrorBlock:^(AM3SErrorID errorID) {
NSDictionary* deviceInfo = @{@"mac":mac,@"action":@"error_am",@"error":[NSNumber numberWithInteger:errorID]};
[self sendEventWithName:EVENT_NOTIFY body:deviceInfo];
}];
}
}
@end
|