This repository has been archived by the owner on Dec 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
R24dvd_new.h
1277 lines (1193 loc) · 47.5 KB
/
R24dvd_new.h
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
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "esphome.h"
static const char *const TAG = "R24dvd";
#define FRAME_BUF_MAX_SIZE 128
#define PRODUCT_BUF_MAX_SIZE 32
#define FRAME_HEADER1_VALUE 0x53
#define FRAME_HEADER2_VALUE 0x59
#define FRAME_TAIL1_VALUE 0x54
#define FRAME_TAIL2_VALUE 0x43
#define FRAME_CONTROL_WORD_INDEX 2
#define FRAME_COMMAND_WORD_INDEX 3
#define FRAME_DATA_INDEX 6
enum
{
FRAME_IDLE,
FRAME_HEADER2,
FRAME_CTL_WORLD,
FRAME_CMD_WORLD,
FRAME_DATA_LEN_H,
FRAME_DATA_LEN_L,
FRAME_DATA_BYTES,
FRAME_DATA_CRC,
FRAME_TAIL1,
FRAME_TAIL2,
};
enum
{
STANDARD_FUNCTION_QUERY_PRODUCT_MODE = 0,
STANDARD_FUNCTION_QUERY_PRODUCT_ID,
STANDARD_FUNCTION_QUERY_FIRMWARE_VERDION,
STANDARD_FUNCTION_QUERY_HARDWARE_MODE,
// STANDARD_FUNCTION_QUERY_PROTOCOL_TYPE,
STANDARD_FUNCTION_QUERY_HUMAN_STATUS,
STANDARD_FUNCTION_QUERY_SCENE_MODE,
STANDARD_FUNCTION_QUERY_SENSITIVITY,
STANDARD_FUNCTION_QUERY_RADAR_INIT_STATUS,
STANDARD_FUNCTION_QUERY_MOV_TARGET_DETECTION_MAX_DISTANCE,
STANDARD_FUNCTION_QUERY_STATIC_TARGET_DETECTION_MAX_DISTANCE,
STANDARD_FUNCTION_QUERY_UNMANNED_TIME,
STANDARD_FUNCTION_QUERY_RADAR_OUITPUT_INFORMATION_SWITCH,
STANDARD_FUNCTION_MAX,
CUSTOM_FUNCTION_QUERY_RADAR_OUITPUT_INFORMATION_SWITCH,
// CUSTOM_FUNCTION_QUERY_SPATIAL_STATIC_VALUE,
// CUSTOM_FUNCTION_QUERY_SPATIAL_MOTION_AMPLITUDE,
CUSTOM_FUNCTION_QUERY_PRESENCE_OF_DETECTION_RANGE,
// CUSTOM_FUNCTION_QUERY_DISTANCE_OF_MOVING_OBJECT,
// CUSTOM_FUNCTION_QUERY_TARGET_MOVEMENT_SPEED,
CUSTOM_FUNCTION_QUERY_JUDGMENT_THRESHOLD_EXISTS,
CUSTOM_FUNCTION_QUERY_MOTION_AMPLITUDE_TRIGGER_THRESHOLD,
CUSTOM_FUNCTION_QUERY_PRESENCE_OF_PERCEPTION_BOUNDARY,
CUSTOM_FUNCTION_QUERY_MOTION_TRIGGER_BOUNDARY,
CUSTOM_FUNCTION_QUERY_MOTION_TRIGGER_TIME,
CUSTOM_FUNCTION_QUERY_MOVEMENT_TO_REST_TIME,
CUSTOM_FUNCTION_QUERY_TIME_OF_ENTER_UNMANNED,
CUSTOM_FUNCTION_MAX,
};
enum
{
OUTPUT_SWITCH_INIT,
OUTPUT_SWTICH_ON,
OUTPUT_SWTICH_OFF,
};
static char s_heartbeat_str[2][20] = {"0", "1"};
static char s_scene_str[5][20] = {"0", "1", "2", "3", "4"};
static char s_someoneExists_str[2][20] = {"0", "1"};
static char s_motion_status_str[3][20] = {"none", "0", "1"};
static char s_keep_away_str[3][20] = {"none", "0", "1"};
static char s_unmanned_time_str[9][20] = {"none", "10s", "30s", "1min", "2min", "5min", "10min", "30min", "1hour"};
static char s_motion_trig_boundary_str[10][5] = {"0.5m", "1.0m", "1.5m", "2.0m", "2.5m", "3.0m", "3.5m", "4.0m", "4.5m", "5.0m"};
static char s_presence_of_perception_boundary_str[10][5] = {"0.5m", "1.0m", "1.5m", "2.0m", "2.5m", "3.0m", "3.5m", "4.0m", "4.5m", "5.0m"};
static char s_presence_of_detection_range_str[7][10] = {"none", "0.5m", "1.0m", "1.5m", "2.0m", "2.5m", "3.0m"};
static uint8_t s_output_info_switch_flag = OUTPUT_SWITCH_INIT;
static uint8_t sg_recv_data_state = FRAME_IDLE;
static uint8_t sg_frame_len = 0;
static uint8_t sg_data_len = 0;
static uint8_t sg_frame_buf[FRAME_BUF_MAX_SIZE] = {0};
static uint8_t sg_frame_prase_buf[FRAME_BUF_MAX_SIZE] = {0};
static bool sg_init_flag = false;
static int sg_start_query_data = -1;
static int sg_start_query_data_max = -1;
static uint8_t sg_movementSigns_bak;
static uint32_t sg_motion_trigger_time_bak;
static uint32_t sg_move_to_rest_time_bak;
static uint32_t sg_enter_unmanned_time_bak;
static uint8_t sg_spatial_static_value_bak;
static uint8_t sg_static_distance_bak;
static uint8_t sg_spatial_motion_value_bak;
static uint8_t sg_motion_distance_bak;
static uint8_t sg_motion_speed_bak;
static uint8_t sg_heartbeat_flag = 255;
static uint8_t s_power_on_status = 0;
static uint8_t get_frame_crc_sum(uint8_t *data, int len)
{
unsigned int crc_sum = 0;
for (int i = 0; i < len - 3; i++)
{
crc_sum += data[i];
}
return crc_sum & 0xff;
}
static int get_frame_check_status(uint8_t *data, int len)
{
uint8_t crc_sum = get_frame_crc_sum(data, len);
uint8_t verified = data[len - 3];
return (verified == crc_sum) ? 1 : 0;
}
static void show_frame_data(uint8_t *data, int len)
{
printf("[%s] FRAME: %d, ", __FUNCTION__, len);
for (int i = 0; i < len; i++)
{
printf("%02X ", data[i] & 0xff);
}
printf("\r\n");
}
class MyCustomTextSensor : public PollingComponent, public TextSensor
{
public:
// constructor
MyCustomTextSensor() : PollingComponent(8000) {}
float get_setup_priority() const override { return esphome::setup_priority::LATE; }
TextSensor *Heartbeat = new TextSensor();
void setup() override
{
s_power_on_status = 0;
}
void update() override
{
if (!sg_init_flag)
return;
if (sg_init_flag && (255 != sg_heartbeat_flag))
{
this->Heartbeat->publish_state(s_heartbeat_str[sg_heartbeat_flag]);
sg_heartbeat_flag = 0;
}
if (s_power_on_status < 4)
{
if (s_output_info_switch_flag == OUTPUT_SWITCH_INIT)
{
sg_start_query_data = CUSTOM_FUNCTION_QUERY_RADAR_OUITPUT_INFORMATION_SWITCH;
sg_start_query_data_max = CUSTOM_FUNCTION_MAX;
}
else if (s_output_info_switch_flag == OUTPUT_SWTICH_OFF)
{
sg_start_query_data = STANDARD_FUNCTION_QUERY_PRODUCT_MODE;
sg_start_query_data_max = STANDARD_FUNCTION_MAX;
}
else if (s_output_info_switch_flag == OUTPUT_SWTICH_ON)
{
sg_start_query_data = CUSTOM_FUNCTION_QUERY_RADAR_OUITPUT_INFORMATION_SWITCH;
sg_start_query_data_max = CUSTOM_FUNCTION_MAX;
}
s_power_on_status++;
}
else
{
sg_start_query_data = STANDARD_FUNCTION_QUERY_PRODUCT_MODE;
sg_start_query_data_max = STANDARD_FUNCTION_QUERY_HARDWARE_MODE;
}
}
};
class UartReadLineSensor : public Component, public UARTDevice, public Sensor
{
private:
char c_product_mode[PRODUCT_BUF_MAX_SIZE + 1];
char c_product_id[PRODUCT_BUF_MAX_SIZE + 1];
char c_hardware_model[PRODUCT_BUF_MAX_SIZE + 1];
char c_firmware_version[PRODUCT_BUF_MAX_SIZE + 1];
public:
UartReadLineSensor(UARTComponent *parent) : UARTDevice(parent) {}
float get_setup_priority() const override { return esphome::setup_priority::LATE; }
Sensor *movementSigns = new Sensor();
Sensor *inited = new Sensor();
void setup();
void loop();
void send_query(uint8_t *query, size_t string_length);
void get_init_finial(void);
void get_heartbeat_packet(void);
void get_product_mode(void);
void get_product_id(void);
void get_hardware_model(void);
void get_firmware_version(void);
void get_protocol_type(void);
void get_human_status(void);
void get_scene_mode(void);
void get_sensitivity(void);
void get_radar_init_status(void);
void get_unmanned_time(void);
void get_movingTargetDetectionMaxDistance(void);
void get_staticTargetDetectionMaxDistance(void);
void get_radar_output_information_switch(void);
void get_spatial_static_value(void);
void get_spatial_motion_amplitude(void);
void get_presence_of_detection_range(void);
void get_distance_of_moving_object(void);
void get_target_movement_speed(void);
void get_judgment_threshold_exists(void);
void get_motion_amplitude_trigger_threshold(void);
void get_presence_of_perception_boundary(void);
void get_motion_trigger_boundary(void);
void get_motion_trigger_time(void);
void get_movement_to_rest_time(void);
void get_time_of_enter_unmanned(void);
void R24_split_data_frame(uint8_t value);
void R24_frame_parse_work_status(uint8_t *data);
void R24_frame_parse_human_information(uint8_t *data);
void R24_frame_parse_detection_range(uint8_t *data);
void R24_frame_parse_product_Information(uint8_t *data);
void R24_frame_parse_open_underlying_information(uint8_t *data);
void R24_parse_data_frame(uint8_t *data, uint8_t len);
};
void UartReadLineSensor::setup()
{
ESP_LOGCONFIG(TAG, "uart_settings is 115200");
this->check_uart_settings(115200);
sg_init_flag = true;
memset(this->c_product_mode, 0, PRODUCT_BUF_MAX_SIZE);
memset(this->c_product_id, 0, PRODUCT_BUF_MAX_SIZE);
memset(this->c_firmware_version, 0, PRODUCT_BUF_MAX_SIZE);
memset(this->c_hardware_model, 0, PRODUCT_BUF_MAX_SIZE);
}
void UartReadLineSensor::loop()
{
uint8_t byte;
while (this->available())
{
this->read_byte(&byte);
this->R24_split_data_frame(byte);
}
if (!s_output_info_switch_flag && sg_start_query_data == CUSTOM_FUNCTION_QUERY_RADAR_OUITPUT_INFORMATION_SWITCH)
{
this->get_radar_output_information_switch();
sg_start_query_data++;
}
if ((s_output_info_switch_flag == OUTPUT_SWTICH_OFF) && (sg_start_query_data <= sg_start_query_data_max) && (sg_start_query_data >= STANDARD_FUNCTION_QUERY_PRODUCT_MODE))
{
switch (sg_start_query_data)
{
case STANDARD_FUNCTION_QUERY_PRODUCT_MODE:
if (strlen(this->c_product_mode) > 0)
{
id(product_mode).publish_state(this->c_product_mode);
}
else
{
this->get_product_mode();
}
break;
case STANDARD_FUNCTION_QUERY_PRODUCT_ID:
if (strlen(this->c_product_id) > 0)
{
id(product_id).publish_state(this->c_product_id);
}
else
{
this->get_product_id();
}
break;
case STANDARD_FUNCTION_QUERY_FIRMWARE_VERDION:
if (strlen(this->c_firmware_version) > 0)
{
id(firmware_version).publish_state(this->c_firmware_version);
}
else
{
this->get_firmware_version();
}
break;
case STANDARD_FUNCTION_QUERY_HARDWARE_MODE:
if (strlen(this->c_hardware_model) > 0)
{
id(hardware_model).publish_state(this->c_hardware_model);
}
else
{
this->get_hardware_model();
}
break;
case STANDARD_FUNCTION_QUERY_HUMAN_STATUS:
this->get_human_status();
break;
case STANDARD_FUNCTION_QUERY_SCENE_MODE:
this->get_scene_mode();
break;
case STANDARD_FUNCTION_QUERY_SENSITIVITY:
this->get_sensitivity();
break;
case STANDARD_FUNCTION_QUERY_RADAR_INIT_STATUS:
this->get_radar_init_status();
break;
case STANDARD_FUNCTION_QUERY_MOV_TARGET_DETECTION_MAX_DISTANCE:
this->get_movingTargetDetectionMaxDistance();
break;
case STANDARD_FUNCTION_QUERY_STATIC_TARGET_DETECTION_MAX_DISTANCE:
this->get_staticTargetDetectionMaxDistance();
break;
case STANDARD_FUNCTION_QUERY_UNMANNED_TIME:
this->get_unmanned_time();
break;
case STANDARD_FUNCTION_QUERY_RADAR_OUITPUT_INFORMATION_SWITCH:
this->get_radar_output_information_switch();
break;
case STANDARD_FUNCTION_MAX:
this->get_heartbeat_packet();
break;
default:
break;
}
sg_start_query_data++;
}
if ((s_output_info_switch_flag == OUTPUT_SWTICH_ON) && (sg_start_query_data <= sg_start_query_data_max) && (sg_start_query_data >= CUSTOM_FUNCTION_QUERY_RADAR_OUITPUT_INFORMATION_SWITCH))
{
switch (sg_start_query_data)
{
case CUSTOM_FUNCTION_QUERY_RADAR_OUITPUT_INFORMATION_SWITCH:
this->get_radar_output_information_switch();
break;
// case CUSTOM_FUNCTION_QUERY_SPATIAL_STATIC_VALUE:
// this->get_spatial_static_value();
// break;
// case CUSTOM_FUNCTION_QUERY_SPATIAL_MOTION_AMPLITUDE:
// this->get_spatial_motion_amplitude();
// break;
case CUSTOM_FUNCTION_QUERY_PRESENCE_OF_DETECTION_RANGE:
this->get_presence_of_detection_range();
break;
// case CUSTOM_FUNCTION_QUERY_DISTANCE_OF_MOVING_OBJECT:
// this->get_distance_of_moving_object();
// break;
// case CUSTOM_FUNCTION_QUERY_TARGET_MOVEMENT_SPEED:
// this->get_target_movement_speed();
// break;
case CUSTOM_FUNCTION_QUERY_JUDGMENT_THRESHOLD_EXISTS:
this->get_judgment_threshold_exists();
break;
case CUSTOM_FUNCTION_QUERY_MOTION_AMPLITUDE_TRIGGER_THRESHOLD:
this->get_motion_amplitude_trigger_threshold();
break;
case CUSTOM_FUNCTION_QUERY_PRESENCE_OF_PERCEPTION_BOUNDARY:
this->get_presence_of_perception_boundary();
break;
case CUSTOM_FUNCTION_QUERY_MOTION_TRIGGER_BOUNDARY:
this->get_motion_trigger_boundary();
break;
case CUSTOM_FUNCTION_QUERY_MOTION_TRIGGER_TIME:
this->get_motion_trigger_time();
break;
case CUSTOM_FUNCTION_QUERY_MOVEMENT_TO_REST_TIME:
this->get_movement_to_rest_time();
break;
case CUSTOM_FUNCTION_QUERY_TIME_OF_ENTER_UNMANNED:
this->get_time_of_enter_unmanned();
break;
case CUSTOM_FUNCTION_MAX:
this->get_heartbeat_packet();
break;
default:
break;
}
sg_start_query_data++;
}
}
void UartReadLineSensor::send_query(uint8_t *query, size_t string_length)
{
int i;
for (i = 0; i < string_length; i++)
{
write(query[i]);
}
show_frame_data(query, i);
}
void UartReadLineSensor::get_heartbeat_packet(void)
{
uint8_t send_data_len = 10;
uint8_t send_data[10] = {0x53, 0x59, 0x01, 0x01, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_init_finial(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x05, 0x81, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_product_mode(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x02, 0xA1, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_product_id(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x02, 0xA2, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_hardware_model(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x02, 0xA3, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_firmware_version(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x02, 0xA4, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_protocol_type(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x02, 0xA5, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_human_status(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x80, 0x81, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_scene_mode(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x05, 0x87, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_sensitivity(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x05, 0x88, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_radar_init_status(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x05, 0x81, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_movingTargetDetectionMaxDistance(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x07, 0x81, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_staticTargetDetectionMaxDistance(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x07, 0x84, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_unmanned_time(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x80, 0x8a, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_radar_output_information_switch(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x08, 0x80, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_spatial_static_value(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x08, 0x81, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_spatial_motion_amplitude(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x08, 0x82, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_presence_of_detection_range(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x08, 0x83, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_distance_of_moving_object(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x08, 0x84, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_target_movement_speed(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x08, 0x85, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_judgment_threshold_exists(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x08, 0x88, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_motion_amplitude_trigger_threshold(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x08, 0x89, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_presence_of_perception_boundary(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x08, 0x8a, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_motion_trigger_boundary(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x08, 0x8b, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_motion_trigger_time(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x08, 0x8c, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_movement_to_rest_time(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x08, 0x8d, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::get_time_of_enter_unmanned(void)
{
unsigned char send_data_len = 10;
unsigned char send_data[10] = {0x53, 0x59, 0x08, 0x8e, 0x00, 0x01, 0x0F, 0x00, 0x54, 0x43};
send_data[FRAME_DATA_INDEX + 1] = get_frame_crc_sum(send_data, send_data_len);
this->send_query(send_data, send_data_len);
}
void UartReadLineSensor::R24_split_data_frame(uint8_t value)
{
switch (sg_recv_data_state)
{
case FRAME_IDLE:
if (FRAME_HEADER1_VALUE == value)
{
sg_recv_data_state = FRAME_HEADER2;
}
break;
case FRAME_HEADER2:
if (FRAME_HEADER2_VALUE == value)
{
sg_frame_buf[0] = FRAME_HEADER1_VALUE;
sg_frame_buf[1] = FRAME_HEADER2_VALUE;
sg_recv_data_state = FRAME_CTL_WORLD;
}
else
{
sg_recv_data_state = FRAME_IDLE;
ESP_LOGD(TAG, "FRAME_IDLE ERROR value:%x", value);
}
break;
case FRAME_CTL_WORLD:
sg_frame_buf[2] = value;
sg_recv_data_state = FRAME_CMD_WORLD;
break;
case FRAME_CMD_WORLD:
sg_frame_buf[3] = value;
sg_recv_data_state = FRAME_DATA_LEN_H;
break;
case FRAME_DATA_LEN_H:
if (value <= 4)
{
sg_data_len = value * 256;
sg_frame_buf[4] = value;
sg_recv_data_state = FRAME_DATA_LEN_L;
}
else
{
sg_data_len = 0;
sg_recv_data_state = FRAME_IDLE;
ESP_LOGD(TAG, "FRAME_DATA_LEN_H ERROR value:%x", value);
}
break;
case FRAME_DATA_LEN_L:
sg_data_len += value;
if (sg_data_len > 32)
{
ESP_LOGD(TAG, "len=%d, FRAME_DATA_LEN_L ERROR value:%x", sg_data_len, value);
sg_data_len = 0;
sg_recv_data_state = FRAME_IDLE;
}
else
{
sg_frame_buf[5] = value;
sg_frame_len = 6;
sg_recv_data_state = FRAME_DATA_BYTES;
}
break;
case FRAME_DATA_BYTES:
sg_data_len -= 1;
sg_frame_buf[sg_frame_len++] = value;
if (sg_data_len <= 0)
{
sg_recv_data_state = FRAME_DATA_CRC;
}
break;
case FRAME_DATA_CRC:
sg_frame_buf[sg_frame_len++] = value;
sg_recv_data_state = FRAME_TAIL1;
break;
case FRAME_TAIL1:
if (FRAME_TAIL1_VALUE == value)
{
sg_recv_data_state = FRAME_TAIL2;
}
else
{
sg_recv_data_state = FRAME_IDLE;
sg_frame_len = 0;
sg_data_len = 0;
ESP_LOGD(TAG, "FRAME_TAIL1 ERROR value:%x", value);
}
break;
case FRAME_TAIL2:
if (FRAME_TAIL2_VALUE == value)
{
sg_frame_buf[sg_frame_len++] = FRAME_TAIL1_VALUE;
sg_frame_buf[sg_frame_len++] = FRAME_TAIL2_VALUE;
memcpy(sg_frame_prase_buf, sg_frame_buf, sg_frame_len);
if (get_frame_check_status(sg_frame_prase_buf, sg_frame_len))
{
// show_frame_data(sg_frame_prase_buf, sg_frame_len);
this->R24_parse_data_frame(sg_frame_prase_buf, sg_frame_len);
}
else
{
ESP_LOGD(TAG, "frame check failer!");
}
}
else
{
ESP_LOGD(TAG, "FRAME_TAIL2 ERROR value:%x", value);
}
memset(sg_frame_prase_buf, 0, FRAME_BUF_MAX_SIZE);
memset(sg_frame_buf, 0, FRAME_BUF_MAX_SIZE);
sg_frame_len = 0;
sg_data_len = 0;
sg_recv_data_state = FRAME_IDLE;
break;
default:
sg_recv_data_state = FRAME_IDLE;
}
}
void UartReadLineSensor::R24_frame_parse_work_status(uint8_t *data)
{
if (data[FRAME_COMMAND_WORD_INDEX] == 0x01)
{
this->inited->publish_state(data[FRAME_DATA_INDEX]);
ESP_LOGD(TAG, "Report: radar init status 0x%02X", data[FRAME_DATA_INDEX]);
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x07)
{
if (id(scene_mode).has_index(data[FRAME_DATA_INDEX] - 1))
{
id(scene_mode).publish_state(s_scene_str[data[FRAME_DATA_INDEX] - 1]);
}
else
{
ESP_LOGD(TAG, "Select has index offset %d Error", data[FRAME_DATA_INDEX]);
}
ESP_LOGD(TAG, "Reply: set scene_mode 0x%02X", data[FRAME_DATA_INDEX]);
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x08)
{
// 1-3
id(sensitivity).publish_state(data[FRAME_DATA_INDEX]);
ESP_LOGD(TAG, "Reply: set sensitivity 0x%02X", data[FRAME_DATA_INDEX]);
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x09)
{
// 1-4
id(custom_mode_settings).publish_state(data[FRAME_DATA_INDEX]);
ESP_LOGD(TAG, "Reply: set custom_mode_settings 0x%02X", data[FRAME_DATA_INDEX]);
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x81)
{
this->inited->publish_state(data[FRAME_DATA_INDEX]);
ESP_LOGD(TAG, "Reply: get radar init status 0x%02X", data[FRAME_DATA_INDEX]);
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x87)
{
if (id(scene_mode).has_index(data[FRAME_DATA_INDEX] - 1))
{
id(scene_mode).publish_state(s_scene_str[data[FRAME_DATA_INDEX] - 1]);
}
else
{
ESP_LOGD(TAG, "Select has index offset %d Error", data[FRAME_DATA_INDEX]);
}
ESP_LOGD(TAG, "Reply: get scene_mode 0x%02X", data[FRAME_DATA_INDEX]);
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x88)
{
id(sensitivity).publish_state(data[FRAME_DATA_INDEX]);
ESP_LOGD(TAG, "Reply: get sensitivity 0x%02X", data[FRAME_DATA_INDEX]);
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x89)
{
// 1-4
id(custom_mode_settings).publish_state(data[FRAME_DATA_INDEX]);
ESP_LOGD(TAG, "Reply: get custom_mode_settings 0x%02X", data[FRAME_DATA_INDEX]);
}
else
{
ESP_LOGD(TAG, "[%s] No found COMMAND_WORD(%02X) in Frame", __FUNCTION__, data[FRAME_COMMAND_WORD_INDEX]);
}
}
void UartReadLineSensor::R24_frame_parse_human_information(uint8_t *data)
{
if (data[FRAME_COMMAND_WORD_INDEX] == 0x01)
{
id(someoneExists).publish_state(s_someoneExists_str[data[FRAME_DATA_INDEX]]);
ESP_LOGD(TAG, "Report: someoneExists %d", data[FRAME_DATA_INDEX]);
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x02)
{
if (data[FRAME_DATA_INDEX] < 3 && data[FRAME_DATA_INDEX] >= 0)
{
id(motion_status).publish_state(s_motion_status_str[data[FRAME_DATA_INDEX]]);
}
ESP_LOGD(TAG, "Report: motion_status %d", data[FRAME_DATA_INDEX]);
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x03)
{
if (sg_movementSigns_bak != data[FRAME_DATA_INDEX])
{
this->movementSigns->publish_state(data[FRAME_DATA_INDEX]);
sg_movementSigns_bak = data[FRAME_DATA_INDEX];
}
ESP_LOGD(TAG, "Report: movementSigns %d", data[FRAME_DATA_INDEX]);
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x0A)
{
// none:0x00 1s:0x01 30s:0x02 1min:0x03 2min:0x04 5min:0x05 10min:0x06 30min:0x07 1hour:0x08
if (data[FRAME_DATA_INDEX] < 9 && data[FRAME_DATA_INDEX] >= 0)
{
id(unmanned_time).publish_state(s_unmanned_time_str[data[FRAME_DATA_INDEX]]);
}
ESP_LOGD(TAG, "Reply: set enter unmanned time %d", data[FRAME_DATA_INDEX]);
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x0B)
{
// none:0x00 close_to:0x01 far_away:0x02
if (data[FRAME_DATA_INDEX] < 3 && data[FRAME_DATA_INDEX] >= 0)
{
id(keep_away).publish_state(s_keep_away_str[data[FRAME_DATA_INDEX]]);
}
ESP_LOGD(TAG, "Report: moving direction %d", data[FRAME_DATA_INDEX]);
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x81)
{
id(someoneExists).publish_state(s_someoneExists_str[data[FRAME_DATA_INDEX]]);
ESP_LOGD(TAG, "Reply: get someoneExists %d", data[FRAME_DATA_INDEX]);
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x82)
{
if (data[FRAME_DATA_INDEX] < 3 && data[FRAME_DATA_INDEX] >= 0)
{
id(motion_status).publish_state(s_motion_status_str[data[FRAME_DATA_INDEX]]);
}
ESP_LOGD(TAG, "Reply: get motion_status %d", data[FRAME_DATA_INDEX]);
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x83)
{
if (sg_movementSigns_bak != data[FRAME_DATA_INDEX])
{
this->movementSigns->publish_state(data[FRAME_DATA_INDEX]);
sg_movementSigns_bak = data[FRAME_DATA_INDEX];
}
ESP_LOGD(TAG, "Reply: get movementSigns %d", data[FRAME_DATA_INDEX]);
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x8A)
{
// none:0x00 1s:0x01 30s:0x02 1min:0x03 2min:0x04 5min:0x05 10min:0x06 30min:0x07 1hour:0x08
if (data[FRAME_DATA_INDEX] < 9 && data[FRAME_DATA_INDEX] >= 0)
{
id(unmanned_time).publish_state(s_unmanned_time_str[data[FRAME_DATA_INDEX]]);
}
ESP_LOGD(TAG, "Report: get enter unmanned time %d", data[FRAME_DATA_INDEX]);
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x8B)
{
// none:0x00 close_to:0x01 far_away:0x02
if (data[FRAME_DATA_INDEX] < 3 && data[FRAME_DATA_INDEX] >= 0)
{
id(keep_away).publish_state(s_keep_away_str[data[FRAME_DATA_INDEX]]);
}
ESP_LOGD(TAG, "Reply: get moving direction %d", data[FRAME_DATA_INDEX]);
}
else
{
ESP_LOGD(TAG, "[%s] No found COMMAND_WORD(%02X) in Frame", __FUNCTION__, data[FRAME_COMMAND_WORD_INDEX]);
}
}
void UartReadLineSensor::R24_frame_parse_detection_range(uint8_t *data)
{
if (data[FRAME_COMMAND_WORD_INDEX] == 0x01)
{
id(moving_target_detection_max_distance).publish_state(data[FRAME_DATA_INDEX] * 256 + data[FRAME_DATA_INDEX + 1]);
ESP_LOGD(TAG, "Reply: set movingTargetDetectionMaxDistance %d", data[FRAME_DATA_INDEX] * 256 + data[FRAME_DATA_INDEX + 1]);
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x04)
{
id(static_target_detection_max_distance).publish_state(data[FRAME_DATA_INDEX] * 256 + data[FRAME_DATA_INDEX + 1]);
ESP_LOGD(TAG, "Reply: set staticTargetDetectionMaxDistance %d", data[FRAME_DATA_INDEX] * 256 + data[FRAME_DATA_INDEX + 1]);
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x81)
{
id(moving_target_detection_max_distance).publish_state(data[FRAME_DATA_INDEX] * 256 + data[FRAME_DATA_INDEX + 1]);
ESP_LOGD(TAG, "Reply: get movingTargetDetectionMaxDistance %d", data[FRAME_DATA_INDEX] * 256 + data[FRAME_DATA_INDEX + 1]);
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x84)
{
id(static_target_detection_max_distance).publish_state(data[FRAME_DATA_INDEX] * 256 + data[FRAME_DATA_INDEX + 1]);
ESP_LOGD(TAG, "Reply: get staticTargetDetectionMaxDistance %d", data[FRAME_DATA_INDEX] * 256 + data[FRAME_DATA_INDEX + 1]);
}
else
{
ESP_LOGD(TAG, "[%s] No found COMMAND_WORD(%02X) in Frame", __FUNCTION__, data[FRAME_COMMAND_WORD_INDEX]);
}
}
void UartReadLineSensor::R24_frame_parse_product_Information(uint8_t *data)
{
uint8_t product_len = 0;
if (data[FRAME_COMMAND_WORD_INDEX] == 0xA1)
{
product_len = data[FRAME_COMMAND_WORD_INDEX + 1] * 256 + data[FRAME_COMMAND_WORD_INDEX + 2];
if (product_len < PRODUCT_BUF_MAX_SIZE)
{
memset(this->c_product_mode, 0, PRODUCT_BUF_MAX_SIZE);
memcpy(this->c_product_mode, &data[FRAME_DATA_INDEX], product_len);
ESP_LOGD(TAG, "Reply: get product_mode :%s", this->c_product_mode);
id(product_mode).publish_state(this->c_product_mode);
}
else
{
ESP_LOGD(TAG, "Reply: get product_mode length too long!");
}
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0xA2)
{
product_len = data[FRAME_COMMAND_WORD_INDEX + 1] * 256 + data[FRAME_COMMAND_WORD_INDEX + 2];
if (product_len < PRODUCT_BUF_MAX_SIZE)
{
memset(this->c_product_id, 0, PRODUCT_BUF_MAX_SIZE);
memcpy(this->c_product_id, &data[FRAME_DATA_INDEX], product_len);
id(product_id).publish_state(this->c_product_id);
ESP_LOGD(TAG, "Reply: get productId :%s", this->c_product_id);
}
else
{
ESP_LOGD(TAG, "Reply: get productId length too long!");
}
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0xA3)
{
product_len = data[FRAME_COMMAND_WORD_INDEX + 1] * 256 + data[FRAME_COMMAND_WORD_INDEX + 2];
if (product_len < PRODUCT_BUF_MAX_SIZE)
{
memset(this->c_hardware_model, 0, PRODUCT_BUF_MAX_SIZE);
memcpy(this->c_hardware_model, &data[FRAME_DATA_INDEX], product_len);
id(hardware_model).publish_state(this->c_hardware_model);
ESP_LOGD(TAG, "Reply: get hardware_model :%s", this->c_hardware_model);
}
else
{
ESP_LOGD(TAG, "Reply: get hardwareModel length too long!");
}
}
else if (data[FRAME_COMMAND_WORD_INDEX] == 0xA4)
{
product_len = data[FRAME_COMMAND_WORD_INDEX + 1] * 256 + data[FRAME_COMMAND_WORD_INDEX + 2];
if (product_len < PRODUCT_BUF_MAX_SIZE)
{
memset(this->c_firmware_version, 0, PRODUCT_BUF_MAX_SIZE);
memcpy(this->c_firmware_version, &data[FRAME_DATA_INDEX], product_len);
id(firmware_version).publish_state(this->c_firmware_version);
ESP_LOGD(TAG, "Reply: get firmware_version :%s", this->c_firmware_version);
}
else
{
ESP_LOGD(TAG, "Reply: get firmwareVersion length too long!");
}
}
}
void UartReadLineSensor::R24_frame_parse_open_underlying_information(uint8_t *data)
{
if (data[FRAME_COMMAND_WORD_INDEX] == 0x00)
{
id(output_info_switch).publish_state(data[FRAME_DATA_INDEX]);
if (data[FRAME_DATA_INDEX])
{
s_output_info_switch_flag = OUTPUT_SWTICH_ON;