8 namespace seeed_mr24hpc1 {
10 static const char *
const TAG =
"seeed_mr24hpc1";
15 ESP_LOGCONFIG(TAG,
"MR24HPC1:");
16 #ifdef USE_TEXT_SENSOR 17 LOG_TEXT_SENSOR(
" ",
"Heartbeat Text Sensor", this->heartbeat_state_text_sensor_);
18 LOG_TEXT_SENSOR(
" ",
"Product Model Text Sensor", this->product_model_text_sensor_);
19 LOG_TEXT_SENSOR(
" ",
"Product ID Text Sensor", this->product_id_text_sensor_);
20 LOG_TEXT_SENSOR(
" ",
"Hardware Model Text Sensor", this->hardware_model_text_sensor_);
21 LOG_TEXT_SENSOR(
" ",
"Firware Verison Text Sensor", this->firware_version_text_sensor_);
22 LOG_TEXT_SENSOR(
" ",
"Keep Away Text Sensor", this->keep_away_text_sensor_);
23 LOG_TEXT_SENSOR(
" ",
"Motion Status Text Sensor", this->motion_status_text_sensor_);
24 LOG_TEXT_SENSOR(
" ",
"Custom Mode End Text Sensor", this->custom_mode_end_text_sensor_);
26 #ifdef USE_BINARY_SENSOR 27 LOG_BINARY_SENSOR(
" ",
"Has Target Binary Sensor", this->has_target_binary_sensor_);
30 LOG_SENSOR(
" ",
"Custom Presence Of Detection Sensor", this->custom_presence_of_detection_sensor_);
31 LOG_SENSOR(
" ",
"Movement Signs Sensor", this->movement_signs_sensor_);
32 LOG_SENSOR(
" ",
"Custom Motion Distance Sensor", this->custom_motion_distance_sensor_);
33 LOG_SENSOR(
" ",
"Custom Spatial Static Sensor", this->custom_spatial_static_value_sensor_);
34 LOG_SENSOR(
" ",
"Custom Spatial Motion Sensor", this->custom_spatial_motion_value_sensor_);
35 LOG_SENSOR(
" ",
"Custom Motion Speed Sensor", this->custom_motion_speed_sensor_);
36 LOG_SENSOR(
" ",
"Custom Mode Num Sensor", this->custom_mode_num_sensor_);
39 LOG_SWITCH(
" ",
"Underly Open Function Switch", this->underlying_open_function_switch_);
42 LOG_BUTTON(
" ",
"Restart Button", this->restart_button_);
43 LOG_BUTTON(
" ",
"Custom Set End Button", this->custom_set_end_button_);
46 LOG_SELECT(
" ",
"Scene Mode Select", this->scene_mode_select_);
47 LOG_SELECT(
" ",
"Unman Time Select", this->unman_time_select_);
48 LOG_SELECT(
" ",
"Existence Boundary Select", this->existence_boundary_select_);
49 LOG_SELECT(
" ",
"Motion Boundary Select", this->motion_boundary_select_);
52 LOG_NUMBER(
" ",
"Sensitivity Number", this->sensitivity_number_);
53 LOG_NUMBER(
" ",
"Custom Mode Number", this->custom_mode_number_);
54 LOG_NUMBER(
" ",
"Existence Threshold Number", this->existence_threshold_number_);
55 LOG_NUMBER(
" ",
"Motion Threshold Number", this->motion_threshold_number_);
56 LOG_NUMBER(
" ",
"Motion Trigger Time Number", this->motion_trigger_number_);
57 LOG_NUMBER(
" ",
"Motion To Rest Time Number", this->motion_to_rest_number_);
58 LOG_NUMBER(
" ",
"Custom Unman Time Number", this->custom_unman_time_number_);
64 ESP_LOGCONFIG(TAG,
"Setting up MR24HPC1...");
67 if (this->custom_mode_number_ !=
nullptr) {
68 this->custom_mode_number_->publish_state(0);
70 if (this->custom_mode_num_sensor_ !=
nullptr) {
71 this->custom_mode_num_sensor_->publish_state(0);
73 if (this->custom_mode_end_text_sensor_ !=
nullptr) {
74 this->custom_mode_end_text_sensor_->publish_state(
"Not in custom mode");
77 this->poll_time_base_func_check_ =
true;
78 this->check_dev_inf_sign_ =
true;
80 this->sg_data_len_ = 0;
81 this->sg_frame_len_ = 0;
85 memset(this->c_product_mode_, 0, PRODUCT_BUF_MAX_SIZE);
86 memset(this->c_product_id_, 0, PRODUCT_BUF_MAX_SIZE);
87 memset(this->c_firmware_version_, 0, PRODUCT_BUF_MAX_SIZE);
88 memset(this->c_hardware_model_, 0, PRODUCT_BUF_MAX_SIZE);
89 memset(this->sg_frame_prase_buf_, 0, FRAME_BUF_MAX_SIZE);
90 memset(this->sg_frame_buf_, 0, FRAME_BUF_MAX_SIZE);
93 ESP_LOGCONFIG(TAG,
"Set up MR24HPC1 complete");
97 void MR24HPC1Component::update_() {
99 this->poll_time_base_func_check_ =
true;
109 this->r24_split_data_frame_(byte);
124 if (this->poll_time_base_func_check_) {
125 switch (this->sg_start_query_data_) {
128 this->sg_start_query_data_++;
132 this->sg_start_query_data_++;
138 this->sg_start_query_data_++;
144 this->sg_start_query_data_++;
145 this->check_dev_inf_sign_ =
false;
149 this->sg_start_query_data_++;
153 this->sg_start_query_data_++;
157 this->sg_start_query_data_++;
161 this->sg_start_query_data_++;
165 this->sg_start_query_data_++;
169 this->sg_start_query_data_++;
173 this->sg_start_query_data_++;
177 this->sg_start_query_data_++;
181 this->sg_start_query_data_++;
185 this->sg_start_query_data_++;
189 this->sg_start_query_data_++;
193 this->sg_start_query_data_++;
197 this->sg_start_query_data_++;
201 this->sg_start_query_data_++;
205 this->sg_start_query_data_++;
209 this->sg_start_query_data_++;
211 this->poll_time_base_func_check_ =
false;
216 this->sg_start_query_data_++;
220 this->sg_start_query_data_++;
224 this->sg_start_query_data_++;
228 this->sg_start_query_data_++;
232 this->sg_start_query_data_++;
236 this->sg_start_query_data_++;
237 this->poll_time_base_func_check_ =
false;
246 static uint8_t get_frame_crc_sum(
const uint8_t *data,
int len) {
247 unsigned int crc_sum = 0;
248 for (
int i = 0; i < len - 3; i++) {
251 return crc_sum & 0xff;
255 static int get_frame_check_status(uint8_t *data,
int len) {
256 uint8_t crc_sum = get_frame_crc_sum(data, len);
257 uint8_t verified = data[len - 3];
258 return (verified == crc_sum) ? 1 : 0;
262 void MR24HPC1Component::r24_split_data_frame_(uint8_t value) {
263 switch (this->sg_recv_data_state_) {
265 if (FRAME_HEADER1_VALUE == value) {
270 if (FRAME_HEADER2_VALUE == value) {
271 this->sg_frame_buf_[0] = FRAME_HEADER1_VALUE;
272 this->sg_frame_buf_[1] = FRAME_HEADER2_VALUE;
276 ESP_LOGD(TAG,
"FRAME_IDLE ERROR value:%x", value);
280 this->sg_frame_buf_[2] = value;
284 this->sg_frame_buf_[3] = value;
289 this->sg_data_len_ = value * 256;
290 this->sg_frame_buf_[4] = value;
293 this->sg_data_len_ = 0;
295 ESP_LOGD(TAG,
"FRAME_DATA_LEN_H ERROR value:%x", value);
299 this->sg_data_len_ += value;
300 if (this->sg_data_len_ > 32) {
301 ESP_LOGD(TAG,
"len=%d, FRAME_DATA_LEN_L ERROR value:%x", this->sg_data_len_, value);
302 this->sg_data_len_ = 0;
305 this->sg_frame_buf_[5] = value;
306 this->sg_frame_len_ = 6;
311 this->sg_data_len_ -= 1;
312 this->sg_frame_buf_[this->sg_frame_len_++] = value;
313 if (this->sg_data_len_ <= 0) {
318 this->sg_frame_buf_[this->sg_frame_len_++] = value;
322 if (FRAME_TAIL1_VALUE == value) {
326 this->sg_frame_len_ = 0;
327 this->sg_data_len_ = 0;
328 ESP_LOGD(TAG,
"FRAME_TAIL1 ERROR value:%x", value);
332 if (FRAME_TAIL2_VALUE == value) {
333 this->sg_frame_buf_[this->sg_frame_len_++] = FRAME_TAIL1_VALUE;
334 this->sg_frame_buf_[this->sg_frame_len_++] = FRAME_TAIL2_VALUE;
335 memcpy(this->sg_frame_prase_buf_, this->sg_frame_buf_, this->sg_frame_len_);
336 if (get_frame_check_status(this->sg_frame_prase_buf_, this->sg_frame_len_)) {
337 this->r24_parse_data_frame_(this->sg_frame_prase_buf_, this->sg_frame_len_);
339 ESP_LOGD(TAG,
"frame check failer!");
342 ESP_LOGD(TAG,
"FRAME_TAIL2 ERROR value:%x", value);
344 memset(this->sg_frame_prase_buf_, 0, FRAME_BUF_MAX_SIZE);
345 memset(this->sg_frame_buf_, 0, FRAME_BUF_MAX_SIZE);
346 this->sg_frame_len_ = 0;
347 this->sg_data_len_ = 0;
356 void MR24HPC1Component::r24_frame_parse_product_information_(uint8_t *data) {
357 uint16_t product_len =
encode_uint16(data[FRAME_COMMAND_WORD_INDEX + 1], data[FRAME_COMMAND_WORD_INDEX + 2]);
358 if (data[FRAME_COMMAND_WORD_INDEX] == COMMAND_PRODUCT_MODE) {
359 if ((this->product_model_text_sensor_ !=
nullptr) && (product_len < PRODUCT_BUF_MAX_SIZE)) {
360 memset(this->c_product_mode_, 0, PRODUCT_BUF_MAX_SIZE);
361 memcpy(this->c_product_mode_, &data[FRAME_DATA_INDEX], product_len);
362 this->product_model_text_sensor_->publish_state(this->c_product_mode_);
364 ESP_LOGD(TAG,
"Reply: get product_mode error!");
366 }
else if (data[FRAME_COMMAND_WORD_INDEX] == COMMAND_PRODUCT_ID) {
367 if ((this->product_id_text_sensor_ !=
nullptr) && (product_len < PRODUCT_BUF_MAX_SIZE)) {
368 memset(this->c_product_id_, 0, PRODUCT_BUF_MAX_SIZE);
369 memcpy(this->c_product_id_, &data[FRAME_DATA_INDEX], product_len);
370 this->product_id_text_sensor_->publish_state(this->c_product_id_);
372 ESP_LOGD(TAG,
"Reply: get productId error!");
374 }
else if (data[FRAME_COMMAND_WORD_INDEX] == COMMAND_HARDWARE_MODEL) {
375 if ((this->hardware_model_text_sensor_ !=
nullptr) && (product_len < PRODUCT_BUF_MAX_SIZE)) {
376 memset(this->c_hardware_model_, 0, PRODUCT_BUF_MAX_SIZE);
377 memcpy(this->c_hardware_model_, &data[FRAME_DATA_INDEX], product_len);
378 this->hardware_model_text_sensor_->publish_state(this->c_hardware_model_);
379 ESP_LOGD(TAG,
"Reply: get hardware_model :%s", this->c_hardware_model_);
381 ESP_LOGD(TAG,
"Reply: get hardwareModel error!");
383 }
else if (data[FRAME_COMMAND_WORD_INDEX] == COMMAND_FIRMWARE_VERSION) {
384 if ((this->firware_version_text_sensor_ !=
nullptr) && (product_len < PRODUCT_BUF_MAX_SIZE)) {
385 memset(this->c_firmware_version_, 0, PRODUCT_BUF_MAX_SIZE);
386 memcpy(this->c_firmware_version_, &data[FRAME_DATA_INDEX], product_len);
387 this->firware_version_text_sensor_->publish_state(this->c_firmware_version_);
389 ESP_LOGD(TAG,
"Reply: get firmwareVersion error!");
395 void MR24HPC1Component::r24_frame_parse_open_underlying_information_(uint8_t *data) {
396 if (data[FRAME_COMMAND_WORD_INDEX] == 0x00) {
397 if (this->underlying_open_function_switch_ !=
nullptr) {
398 this->underlying_open_function_switch_->publish_state(
399 data[FRAME_DATA_INDEX]);
401 if (data[FRAME_DATA_INDEX]) {
406 }
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x01) {
407 if (this->custom_spatial_static_value_sensor_ !=
nullptr) {
408 this->custom_spatial_static_value_sensor_->publish_state(data[FRAME_DATA_INDEX]);
410 if (this->custom_presence_of_detection_sensor_ !=
nullptr) {
411 this->custom_presence_of_detection_sensor_->publish_state(data[FRAME_DATA_INDEX + 1] * 0.5f);
413 if (this->custom_spatial_motion_value_sensor_ !=
nullptr) {
414 this->custom_spatial_motion_value_sensor_->publish_state(data[FRAME_DATA_INDEX + 2]);
416 if (this->custom_motion_distance_sensor_ !=
nullptr) {
417 this->custom_motion_distance_sensor_->publish_state(data[FRAME_DATA_INDEX + 3] * 0.5f);
419 if (this->custom_motion_speed_sensor_ !=
nullptr) {
420 this->custom_motion_speed_sensor_->publish_state((data[FRAME_DATA_INDEX + 4] - 10) * 0.5f);
422 }
else if ((data[FRAME_COMMAND_WORD_INDEX] == 0x06) || (data[FRAME_COMMAND_WORD_INDEX] == 0x86)) {
424 if ((this->keep_away_text_sensor_ !=
nullptr) && (data[FRAME_DATA_INDEX] < 3)) {
425 this->keep_away_text_sensor_->publish_state(S_KEEP_AWAY_STR[data[FRAME_DATA_INDEX]]);
427 }
else if ((this->movement_signs_sensor_ !=
nullptr) &&
428 ((data[FRAME_COMMAND_WORD_INDEX] == 0x07) || (data[FRAME_COMMAND_WORD_INDEX] == 0x87))) {
429 this->movement_signs_sensor_->publish_state(data[FRAME_DATA_INDEX]);
430 }
else if ((this->existence_threshold_number_ !=
nullptr) &&
431 ((data[FRAME_COMMAND_WORD_INDEX] == 0x08) || (data[FRAME_COMMAND_WORD_INDEX] == 0x88))) {
432 this->existence_threshold_number_->publish_state(data[FRAME_DATA_INDEX]);
433 }
else if ((this->motion_threshold_number_ !=
nullptr) &&
434 ((data[FRAME_COMMAND_WORD_INDEX] == 0x09) || (data[FRAME_COMMAND_WORD_INDEX] == 0x89))) {
435 this->motion_threshold_number_->publish_state(data[FRAME_DATA_INDEX]);
436 }
else if ((this->existence_boundary_select_ !=
nullptr) &&
437 ((data[FRAME_COMMAND_WORD_INDEX] == 0x0a) || (data[FRAME_COMMAND_WORD_INDEX] == 0x8a))) {
438 if (this->existence_boundary_select_->has_index(data[FRAME_DATA_INDEX] - 1)) {
439 this->existence_boundary_select_->publish_state(S_BOUNDARY_STR[data[FRAME_DATA_INDEX] - 1]);
441 }
else if ((this->motion_boundary_select_ !=
nullptr) &&
442 ((data[FRAME_COMMAND_WORD_INDEX] == 0x0b) || (data[FRAME_COMMAND_WORD_INDEX] == 0x8b))) {
443 if (this->motion_boundary_select_->has_index(data[FRAME_DATA_INDEX] - 1)) {
444 this->motion_boundary_select_->publish_state(S_BOUNDARY_STR[data[FRAME_DATA_INDEX] - 1]);
446 }
else if ((this->motion_trigger_number_ !=
nullptr) &&
447 ((data[FRAME_COMMAND_WORD_INDEX] == 0x0c) || (data[FRAME_COMMAND_WORD_INDEX] == 0x8c))) {
448 uint32_t motion_trigger_time =
encode_uint32(data[FRAME_DATA_INDEX], data[FRAME_DATA_INDEX + 1],
449 data[FRAME_DATA_INDEX + 2], data[FRAME_DATA_INDEX + 3]);
450 this->motion_trigger_number_->publish_state(motion_trigger_time);
451 }
else if ((this->motion_to_rest_number_ !=
nullptr) &&
452 ((data[FRAME_COMMAND_WORD_INDEX] == 0x0d) || (data[FRAME_COMMAND_WORD_INDEX] == 0x8d))) {
453 uint32_t move_to_rest_time =
encode_uint32(data[FRAME_DATA_INDEX], data[FRAME_DATA_INDEX + 1],
454 data[FRAME_DATA_INDEX + 2], data[FRAME_DATA_INDEX + 3]);
455 this->motion_to_rest_number_->publish_state(move_to_rest_time);
456 }
else if ((this->custom_unman_time_number_ !=
nullptr) &&
457 ((data[FRAME_COMMAND_WORD_INDEX] == 0x0e) || (data[FRAME_COMMAND_WORD_INDEX] == 0x8e))) {
458 uint32_t enter_unmanned_time =
encode_uint32(data[FRAME_DATA_INDEX], data[FRAME_DATA_INDEX + 1],
459 data[FRAME_DATA_INDEX + 2], data[FRAME_DATA_INDEX + 3]);
460 float custom_unmanned_time = enter_unmanned_time / 1000.0;
461 this->custom_unman_time_number_->publish_state(custom_unmanned_time);
462 }
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x80) {
463 if (data[FRAME_DATA_INDEX]) {
468 if (this->underlying_open_function_switch_ !=
nullptr) {
469 this->underlying_open_function_switch_->publish_state(data[FRAME_DATA_INDEX]);
471 }
else if ((this->custom_spatial_static_value_sensor_ !=
nullptr) && (data[FRAME_COMMAND_WORD_INDEX] == 0x81)) {
472 this->custom_spatial_static_value_sensor_->publish_state(data[FRAME_DATA_INDEX]);
473 }
else if ((this->custom_spatial_motion_value_sensor_ !=
nullptr) && (data[FRAME_COMMAND_WORD_INDEX] == 0x82)) {
474 this->custom_spatial_motion_value_sensor_->publish_state(data[FRAME_DATA_INDEX]);
475 }
else if ((this->custom_presence_of_detection_sensor_ !=
nullptr) && (data[FRAME_COMMAND_WORD_INDEX] == 0x83)) {
476 this->custom_presence_of_detection_sensor_->publish_state(
477 S_PRESENCE_OF_DETECTION_RANGE_STR[data[FRAME_DATA_INDEX]]);
478 }
else if ((this->custom_motion_distance_sensor_ !=
nullptr) && (data[FRAME_COMMAND_WORD_INDEX] == 0x84)) {
479 this->custom_motion_distance_sensor_->publish_state(data[FRAME_DATA_INDEX] * 0.5f);
480 }
else if ((this->custom_motion_speed_sensor_ !=
nullptr) && (data[FRAME_COMMAND_WORD_INDEX] == 0x85)) {
481 this->custom_motion_speed_sensor_->publish_state((data[FRAME_DATA_INDEX] - 10) * 0.5f);
485 void MR24HPC1Component::r24_parse_data_frame_(uint8_t *data, uint8_t len) {
486 switch (data[FRAME_CONTROL_WORD_INDEX]) {
488 if ((this->heartbeat_state_text_sensor_ !=
nullptr) && (data[FRAME_COMMAND_WORD_INDEX] == 0x01)) {
489 this->heartbeat_state_text_sensor_->publish_state(
"Equipment Normal");
490 }
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x02) {
491 ESP_LOGD(TAG,
"Reply: query restart packet");
492 }
else if (this->heartbeat_state_text_sensor_ !=
nullptr) {
493 this->heartbeat_state_text_sensor_->publish_state(
"Equipment Abnormal");
497 this->r24_frame_parse_product_information_(data);
500 this->r24_frame_parse_work_status_(data);
503 this->r24_frame_parse_open_underlying_information_(data);
506 this->r24_frame_parse_human_information_(data);
509 ESP_LOGD(TAG,
"control word:0x%02X not found", data[FRAME_CONTROL_WORD_INDEX]);
514 void MR24HPC1Component::r24_frame_parse_work_status_(uint8_t *data) {
515 if (data[FRAME_COMMAND_WORD_INDEX] == 0x01) {
516 ESP_LOGD(TAG,
"Reply: get radar init status 0x%02X", data[FRAME_DATA_INDEX]);
517 }
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x07) {
518 if ((this->scene_mode_select_ !=
nullptr) && (this->scene_mode_select_->has_index(data[FRAME_DATA_INDEX]))) {
519 this->scene_mode_select_->publish_state(S_SCENE_STR[data[FRAME_DATA_INDEX]]);
521 ESP_LOGD(TAG,
"Select has index offset %d Error", data[FRAME_DATA_INDEX]);
523 }
else if ((this->sensitivity_number_ !=
nullptr) &&
524 ((data[FRAME_COMMAND_WORD_INDEX] == 0x08) || (data[FRAME_COMMAND_WORD_INDEX] == 0x88))) {
526 this->sensitivity_number_->publish_state(data[FRAME_DATA_INDEX]);
527 }
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x09) {
529 if (this->custom_mode_num_sensor_ !=
nullptr) {
530 this->custom_mode_num_sensor_->publish_state(data[FRAME_DATA_INDEX]);
532 if (this->custom_mode_number_ !=
nullptr) {
533 this->custom_mode_number_->publish_state(0);
535 if (this->custom_mode_end_text_sensor_ !=
nullptr) {
536 this->custom_mode_end_text_sensor_->publish_state(
"Setup in progress...");
538 }
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x81) {
539 ESP_LOGD(TAG,
"Reply: get radar init status 0x%02X", data[FRAME_DATA_INDEX]);
540 }
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x87) {
541 if ((this->scene_mode_select_ !=
nullptr) && (this->scene_mode_select_->has_index(data[FRAME_DATA_INDEX]))) {
542 this->scene_mode_select_->publish_state(S_SCENE_STR[data[FRAME_DATA_INDEX]]);
544 ESP_LOGD(TAG,
"Select has index offset %d Error", data[FRAME_DATA_INDEX]);
546 }
else if ((this->custom_mode_end_text_sensor_ !=
nullptr) && (data[FRAME_COMMAND_WORD_INDEX] == 0x0A)) {
547 this->custom_mode_end_text_sensor_->publish_state(
"Set Success!");
548 }
else if (data[FRAME_COMMAND_WORD_INDEX] == 0x89) {
549 if (data[FRAME_DATA_INDEX] == 0) {
550 if (this->custom_mode_end_text_sensor_ !=
nullptr) {
551 this->custom_mode_end_text_sensor_->publish_state(
"Not in custom mode");
553 if (this->custom_mode_number_ !=
nullptr) {
554 this->custom_mode_number_->publish_state(0);
556 if (this->custom_mode_num_sensor_ !=
nullptr) {
557 this->custom_mode_num_sensor_->publish_state(data[FRAME_DATA_INDEX]);
560 if (this->custom_mode_num_sensor_ !=
nullptr) {
561 this->custom_mode_num_sensor_->publish_state(data[FRAME_DATA_INDEX]);
565 ESP_LOGD(TAG,
"[%s] No found COMMAND_WORD(%02X) in Frame", __FUNCTION__, data[FRAME_COMMAND_WORD_INDEX]);
569 void MR24HPC1Component::r24_frame_parse_human_information_(uint8_t *data) {
570 if ((this->has_target_binary_sensor_ !=
nullptr) &&
571 ((data[FRAME_COMMAND_WORD_INDEX] == 0x01) || (data[FRAME_COMMAND_WORD_INDEX] == 0x81))) {
572 this->has_target_binary_sensor_->publish_state(S_SOMEONE_EXISTS_STR[data[FRAME_DATA_INDEX]]);
573 }
else if ((this->motion_status_text_sensor_ !=
nullptr) &&
574 ((data[FRAME_COMMAND_WORD_INDEX] == 0x02) || (data[FRAME_COMMAND_WORD_INDEX] == 0x82))) {
575 if (data[FRAME_DATA_INDEX] < 3) {
576 this->motion_status_text_sensor_->publish_state(S_MOTION_STATUS_STR[data[FRAME_DATA_INDEX]]);
578 }
else if ((this->movement_signs_sensor_ !=
nullptr) &&
579 ((data[FRAME_COMMAND_WORD_INDEX] == 0x03) || (data[FRAME_COMMAND_WORD_INDEX] == 0x83))) {
580 this->movement_signs_sensor_->publish_state(data[FRAME_DATA_INDEX]);
581 }
else if ((this->unman_time_select_ !=
nullptr) &&
582 ((data[FRAME_COMMAND_WORD_INDEX] == 0x0A) || (data[FRAME_COMMAND_WORD_INDEX] == 0x8A))) {
584 if (data[FRAME_DATA_INDEX] < 9) {
585 this->unman_time_select_->publish_state(S_UNMANNED_TIME_STR[data[FRAME_DATA_INDEX]]);
587 }
else if ((this->keep_away_text_sensor_ !=
nullptr) &&
588 ((data[FRAME_COMMAND_WORD_INDEX] == 0x0B) || (data[FRAME_COMMAND_WORD_INDEX] == 0x8B))) {
590 if (data[FRAME_DATA_INDEX] < 3) {
591 this->keep_away_text_sensor_->publish_state(S_KEEP_AWAY_STR[data[FRAME_DATA_INDEX]]);
594 ESP_LOGD(TAG,
"[%s] No found COMMAND_WORD(%02X) in Frame", __FUNCTION__, data[FRAME_COMMAND_WORD_INDEX]);
599 void MR24HPC1Component::send_query_(
const uint8_t *query,
size_t string_length) {
608 this->send_query_(GET_RADAR_OUTPUT_INFORMATION_SWITCH,
sizeof(GET_RADAR_OUTPUT_INFORMATION_SWITCH));
622 this->send_query_(GET_FIRMWARE_VERSION,
sizeof(GET_FIRMWARE_VERSION));
628 this->send_query_(GET_HUMAN_MOTION_INFORMATION,
sizeof(GET_HUMAN_MOTION_INFORMATION));
632 this->send_query_(GET_BODY_MOTION_PARAMETERS,
sizeof(GET_BODY_MOTION_PARAMETERS));
646 this->send_query_(GET_EXISTENCE_BOUNDARY,
sizeof(GET_EXISTENCE_BOUNDARY));
652 this->send_query_(GET_SPATIAL_STATIC_VALUE,
sizeof(GET_SPATIAL_STATIC_VALUE));
656 this->send_query_(GET_SPATIAL_MOTION_VALUE,
sizeof(GET_SPATIAL_MOTION_VALUE));
660 this->send_query_(GET_DISTANCE_OF_STATIC_OBJECT,
sizeof(GET_DISTANCE_OF_STATIC_OBJECT));
664 this->send_query_(GET_DISTANCE_OF_MOVING_OBJECT,
sizeof(GET_DISTANCE_OF_MOVING_OBJECT));
668 this->send_query_(GET_TARGET_MOVEMENT_SPEED,
sizeof(GET_TARGET_MOVEMENT_SPEED));
672 this->send_query_(GET_EXISTENCE_THRESHOLD,
sizeof(GET_EXISTENCE_THRESHOLD));
676 this->send_query_(GET_MOTION_THRESHOLD,
sizeof(GET_MOTION_THRESHOLD));
680 this->send_query_(GET_MOTION_TRIGGER_TIME,
sizeof(GET_MOTION_TRIGGER_TIME));
684 this->send_query_(GET_MOTION_TO_REST_TIME,
sizeof(GET_MOTION_TO_REST_TIME));
688 this->send_query_(GET_CUSTOM_UNMAN_TIME,
sizeof(GET_CUSTOM_UNMAN_TIME));
695 this->send_query_(UNDERLYING_SWITCH_ON,
sizeof(UNDERLYING_SWITCH_ON));
697 this->send_query_(UNDERLYING_SWITCH_OFF,
sizeof(UNDERLYING_SWITCH_OFF));
699 if (this->keep_away_text_sensor_ !=
nullptr) {
700 this->keep_away_text_sensor_->publish_state(
"");
702 if (this->motion_status_text_sensor_ !=
nullptr) {
703 this->motion_status_text_sensor_->publish_state(
"");
705 if (this->custom_spatial_static_value_sensor_ !=
nullptr) {
706 this->custom_spatial_static_value_sensor_->publish_state(NAN);
708 if (this->custom_spatial_motion_value_sensor_ !=
nullptr) {
709 this->custom_spatial_motion_value_sensor_->publish_state(NAN);
711 if (this->custom_motion_distance_sensor_ !=
nullptr) {
712 this->custom_motion_distance_sensor_->publish_state(NAN);
714 if (this->custom_presence_of_detection_sensor_ !=
nullptr) {
715 this->custom_presence_of_detection_sensor_->publish_state(NAN);
717 if (this->custom_motion_speed_sensor_ !=
nullptr) {
718 this->custom_motion_speed_sensor_->publish_state(NAN);
723 uint8_t send_data_len = 10;
724 uint8_t send_data[10] = {0x53, 0x59, 0x05, 0x07, 0x00, 0x01, value, 0x00, 0x54, 0x43};
725 send_data[7] = get_frame_crc_sum(send_data, send_data_len);
726 this->send_query_(send_data, send_data_len);
727 if (this->custom_mode_number_ !=
nullptr) {
728 this->custom_mode_number_->publish_state(0);
730 if (this->custom_mode_num_sensor_ !=
nullptr) {
731 this->custom_mode_num_sensor_->publish_state(0);
748 uint8_t send_data_len = 10;
749 uint8_t send_data[10] = {0x53, 0x59, 0x05, 0x08, 0x00, 0x01, value, 0x00, 0x54, 0x43};
750 send_data[7] = get_frame_crc_sum(send_data, send_data_len);
751 this->send_query_(send_data, send_data_len);
757 this->send_query_(SET_RESTART,
sizeof(SET_RESTART));
758 this->check_dev_inf_sign_ =
true;
762 uint8_t send_data_len = 10;
763 uint8_t send_data[10] = {0x53, 0x59, 0x80, 0x0a, 0x00, 0x01, value, 0x00, 0x54, 0x43};
764 send_data[7] = get_frame_crc_sum(send_data, send_data_len);
765 this->send_query_(send_data, send_data_len);
772 if (this->custom_mode_number_ !=
nullptr) {
773 this->custom_mode_number_->publish_state(0);
777 uint8_t send_data_len = 10;
778 uint8_t send_data[10] = {0x53, 0x59, 0x05, 0x09, 0x00, 0x01,
mode, 0x00, 0x54, 0x43};
779 send_data[7] = get_frame_crc_sum(send_data, send_data_len);
780 this->send_query_(send_data, send_data_len);
794 uint8_t send_data_len = 10;
795 uint8_t send_data[10] = {0x53, 0x59, 0x05, 0x0a, 0x00, 0x01, 0x0F, 0xCB, 0x54, 0x43};
796 this->send_query_(send_data, send_data_len);
797 if (this->custom_mode_number_ !=
nullptr) {
798 this->custom_mode_number_->publish_state(0);
813 if ((this->custom_mode_num_sensor_ !=
nullptr) && (this->custom_mode_num_sensor_->state == 0))
815 uint8_t send_data_len = 10;
816 uint8_t send_data[10] = {0x53, 0x59, 0x08, 0x0A, 0x00, 0x01, (uint8_t) (value + 1), 0x00, 0x54, 0x43};
817 send_data[7] = get_frame_crc_sum(send_data, send_data_len);
818 this->send_query_(send_data, send_data_len);
823 if ((this->custom_mode_num_sensor_ !=
nullptr) && (this->custom_mode_num_sensor_->state == 0))
825 uint8_t send_data_len = 10;
826 uint8_t send_data[10] = {0x53, 0x59, 0x08, 0x0B, 0x00, 0x01, (uint8_t) (value + 1), 0x00, 0x54, 0x43};
827 send_data[7] = get_frame_crc_sum(send_data, send_data_len);
828 this->send_query_(send_data, send_data_len);
833 if ((this->custom_mode_num_sensor_ !=
nullptr) && (this->custom_mode_num_sensor_->state == 0))
835 uint8_t send_data_len = 10;
836 uint8_t send_data[10] = {0x53, 0x59, 0x08, 0x08, 0x00, 0x01, value, 0x00, 0x54, 0x43};
837 send_data[7] = get_frame_crc_sum(send_data, send_data_len);
838 this->send_query_(send_data, send_data_len);
843 if ((this->custom_mode_num_sensor_ !=
nullptr) && (this->custom_mode_num_sensor_->state == 0))
845 uint8_t send_data_len = 10;
846 uint8_t send_data[10] = {0x53, 0x59, 0x08, 0x09, 0x00, 0x01, value, 0x00, 0x54, 0x43};
847 send_data[7] = get_frame_crc_sum(send_data, send_data_len);
848 this->send_query_(send_data, send_data_len);
853 if ((this->custom_mode_num_sensor_ !=
nullptr) && (this->custom_mode_num_sensor_->state == 0))
855 uint8_t send_data_len = 13;
856 uint8_t send_data[13] = {0x53, 0x59, 0x08, 0x0C, 0x00, 0x04, 0x00, 0x00, 0x00, value, 0x00, 0x54, 0x43};
857 send_data[10] = get_frame_crc_sum(send_data, send_data_len);
858 this->send_query_(send_data, send_data_len);
863 if ((this->custom_mode_num_sensor_ !=
nullptr) && (this->custom_mode_num_sensor_->state == 0))
865 uint8_t h8_num = (value >> 8) & 0xff;
866 uint8_t l8_num = value & 0xff;
867 uint8_t send_data_len = 13;
868 uint8_t send_data[13] = {0x53, 0x59, 0x08, 0x0D, 0x00, 0x04, 0x00, 0x00, h8_num, l8_num, 0x00, 0x54, 0x43};
869 send_data[10] = get_frame_crc_sum(send_data, send_data_len);
870 this->send_query_(send_data, send_data_len);
875 if ((this->custom_mode_num_sensor_ !=
nullptr) && (this->custom_mode_num_sensor_->state == 0))
877 uint32_t value_ms = value * 1000;
878 uint8_t h24_num = (value_ms >> 24) & 0xff;
879 uint8_t h16_num = (value_ms >> 16) & 0xff;
880 uint8_t h8_num = (value_ms >> 8) & 0xff;
881 uint8_t l8_num = value_ms & 0xff;
882 uint8_t send_data_len = 13;
883 uint8_t send_data[13] = {0x53, 0x59, 0x08, 0x0E, 0x00, 0x04, h24_num, h16_num, h8_num, l8_num, 0x00, 0x54, 0x43};
884 send_data[10] = get_frame_crc_sum(send_data, send_data_len);
885 this->send_query_(send_data, send_data_len);
void get_spatial_motion_value()
void set_custom_mode(uint8_t mode)
void set_interval(const std::string &name, uint32_t interval, std::function< void()> &&f)
Set an interval function with a unique name.
void write_array(const uint8_t *data, size_t len)
void get_motion_trigger_time()
void get_target_movement_speed()
void get_human_motion_info()
void set_existence_boundary(uint8_t value)
void get_heartbeat_packet()
constexpr uint32_t encode_uint32(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
Encode a 32-bit value given four bytes in most to least significant byte order.
void get_existence_threshold()
void get_distance_of_static_object()
void set_motion_threshold(uint8_t value)
void get_existence_boundary()
void set_sensitivity(uint8_t value)
void get_motion_boundary()
void set_custom_end_mode()
void get_custom_unman_time()
void check_uart_settings(uint32_t baud_rate, uint8_t stop_bits=1, UARTParityOptions parity=UART_CONFIG_PARITY_NONE, uint8_t data_bits=8)
Check that the configuration of the UART bus matches the provided values and otherwise print a warnin...
bool read_byte(uint8_t *data)
void get_hardware_model()
void set_motion_boundary(uint8_t value)
BedjetMode mode
BedJet operating mode.
constexpr uint16_t encode_uint16(uint8_t msb, uint8_t lsb)
Encode a 16-bit value given the most and least significant byte.
void set_unman_time(uint8_t value)
void dump_config() override
void get_spatial_static_value()
void set_motion_trigger_time(uint8_t value)
void set_motion_to_rest_time(uint16_t value)
void set_existence_threshold(uint8_t value)
void set_custom_unman_time(uint16_t value)
void get_radar_output_information_switch()
void get_motion_to_rest_time()
Implementation of SPI Controller mode.
void get_distance_of_moving_object()
void get_motion_threshold()
void set_underlying_open_function(bool enable)
void set_scene_mode(uint8_t value)
void get_firmware_version()
void get_body_motion_params()