diff --git a/Core/Inc/yunhorn_sts_sensors.h b/Core/Inc/yunhorn_sts_sensors.h index a7b7c44..8e6e786 100644 --- a/Core/Inc/yunhorn_sts_sensors.h +++ b/Core/Inc/yunhorn_sts_sensors.h @@ -182,7 +182,6 @@ typedef struct STS_OO_SensorStatusDataTypeDef uint16_t occupancy_duration; // sensor 3, motion detection duration uint32_t fall_laydown_duration; // sensor 3, fall down not rise up duration uint32_t no_movement_duration; - uint32_t unconcious_duration; uint8_t occupancy_over_stay_state; // uint8_t battery_Pct; /* % of battery two digits, 88% (00-99)% */ uint8_t dutycycletimelevel; /* level=0,255 */ diff --git a/Core/Src/yunhorn_sts_process.c b/Core/Src/yunhorn_sts_process.c index 7019cb8..1d32d4f 100644 --- a/Core/Src/yunhorn_sts_process.c +++ b/Core/Src/yunhorn_sts_process.c @@ -63,8 +63,9 @@ extern volatile sts_cfg_nvm_t sts_cfg_nvm; extern volatile uint8_t sts_fall_detection_acc_threshold, sts_fall_detection_depth_threshold, sts_occupancy_overtime_threshold_in_10min; extern volatile uint8_t sts_fall_rising_detected_result_changed_flag; extern volatile uint8_t last_sts_fall_rising_detected_result; -extern volatile uint8_t sts_unconscious_state; -extern volatile uint16_t sts_unconscious_threshold, sts_unconscious_duration; + + +extern volatile uint16_t sts_motionless_duration_threshold_in_min; extern volatile uint8_t sts_emergency_button_pushed, sts_rss_2nd_result,sts_tof_result, sts_status_color, sts_lamp_bar_color, sts_service_mask; extern volatile distance_measure_cfg_t distance_cfg; extern uint8_t sts_fall_rising_detected_result; @@ -727,33 +728,46 @@ void STS_PRESENCE_SENSOR_Prepare_Send_Data(STS_OO_SensorStatusDataTypeDef *senso if (sts_rss_result == STS_RESULT_MOTION) { - sensor_data->rss_presence_distance = (uint16_t)(sts_presence_rss_distance)&0xFFFF; + sensor_data->rss_presence_distance = (uint16_t)(sts_presence_rss_distance)&0xFFFF; sensor_data->rss_presence_score = (uint16_t)(sts_presence_rss_score)&0xFFFF; // uint8_t sts_unconscious_state; // uint16_t sts_unconscious_threshold, sts_unconscious_threshold_duration; } else { - sensor_data->rss_presence_distance = 0x0; + sensor_data->rss_presence_distance = 0x0; sensor_data->rss_presence_score = 0x0; } - sensor_data->unconscious_state=(sts_fall_rising_detected_result == STS_PRESENCE_UNCONSCIOUS)? 1:0; - sensor_data->over_stay_state = sts_o7_sensorData.over_stay_state; - sensor_data->over_stay_duration = sts_o7_sensorData.event_sensor1_duration; // no_movement or unconcious duration + sensor_data->unconscious_state = (sts_fall_rising_detected_result == STS_PRESENCE_UNCONSCIOUS)? 1:0; sensor_data->unconscious_duration = sts_o7_sensorData.event_sensor3_unconcious_duration; sensor_data->no_movement_duration = sts_o7_sensorData.event_sensor3_no_movement_duration; - if (sensor_data->over_stay_state !=0) + if (sensor_data->unconscious_state !=0) { - APP_LOG(TS_OFF,VLEVEL_L,"\r\n ... Over Stay Duration = %u Sec [Threshold: %u Seconds]\r\n", sensor_data->over_stay_duration, sts_occupancy_overtime_threshold_in_10min*60); + APP_LOG(TS_OFF,VLEVEL_L,"\r\n ... Unconscious or No Movement Duration = %u Sec [Threshold: %u Seconds]\r\n", + sensor_data->unconscious_duration, sts_motionless_duration_threshold_in_min*60); } + + // Over stay, long stay duration and state + sensor_data->over_stay_state = sts_o7_sensorData.over_stay_state; + sensor_data->over_stay_duration = sts_o7_sensorData.event_sensor1_duration; + if (sensor_data->over_stay_state !=0) + { + APP_LOG(TS_OFF,VLEVEL_L,"\r\n ... Over Stay Duration = %u Sec [Threshold: %u Seconds]\r\n", + sensor_data->over_stay_duration, + sts_occupancy_overtime_threshold_in_10min*60); + } + + // Fall detection and duration, confirmation duration sensor_data->fall_state = sts_fall_rising_detected_result; if (sts_fall_rising_detected_result == STS_PRESENCE_FALL) { - APP_LOG(TS_OFF, VLEVEL_M, "\r\n......FALL RISING DETECTION RESULT: %25s \r\n",(char*)sts_presence_fall_detection_message[sts_fall_rising_detected_result] ); + APP_LOG(TS_OFF, VLEVEL_M, "\r\n......FALL RISING DETECTION RESULT: %25s \r\n", + (char*)sts_presence_fall_detection_message[sts_fall_rising_detected_result] ); sensor_data->fall_speed = (uint8_t)sts_fall_rising_pattern_factor1; sensor_data->fall_gravity = (uint8_t)sts_roc_acc_standard_variance; + } else { sensor_data->fall_speed = 0; sensor_data->fall_gravity = 0; @@ -765,8 +779,8 @@ void STS_PRESENCE_SENSOR_Prepare_Send_Data(STS_OO_SensorStatusDataTypeDef *senso if ((sts_occupancy_overtime_threshold_in_10min != 0) && (event_start_time !=0)) { if (sts_occupancy_overtime_state == 1U) { - sts_status_color = STS_RED_BLUE; - sts_lamp_bar_color = STS_RED_BLUE; + sts_status_color = STS_RED_BLUE; + sts_lamp_bar_color = STS_RED_BLUE; } //STS_Lamp_Bar_Refresh(); } @@ -1177,9 +1191,9 @@ void OnSensor3BStateChanged(void) case STS_PRESENCE_UNCONSCIOUS: sts_o7_sensorData.event_sensor3_no_movement_start_time = sensor_event_time.Seconds; sts_o7_sensorData.event_sensor3_unconcious_start_time = sensor_event_time.Seconds; - sts_o7_sensorData.event_sensor3_unconcious_duration = 0; - sts_o7_sensorData.event_sensor3_no_movement_duration = 0; - sts_o7_sensorData.fall_laydown_duration = 0; + //sts_o7_sensorData.event_sensor3_unconcious_duration = 0; + //sts_o7_sensorData.event_sensor3_no_movement_duration = 0; + //sts_o7_sensorData.fall_laydown_duration = 0; break; default: diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 10895f0..d6321b7 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -62,7 +62,10 @@ extern volatile uint8_t sts_lamp_bar_flashing_color; volatile uint8_t last_sts_lamp_bar_color=STS_DARK; extern volatile uint8_t sts_rss_result; extern volatile uint8_t sts_rss_result_changed_flag, sts_hall1_changed_flag, sts_hall2_changed_flag, sts_reed_hall_changed_flag; -volatile uint8_t sts_fall_detection_acc_threshold = 10, sts_fall_detection_depth_threshold=20, sts_fall_confirm_threshold_in_10sec=1, sts_occupancy_overtime_threshold_in_10min=2; +volatile uint8_t sts_fall_detection_acc_threshold = 10, + sts_fall_detection_depth_threshold=20, + sts_fall_confirm_threshold_in_10sec=1, + sts_occupancy_overtime_threshold_in_10min=2; volatile uint8_t sts_unconscious_or_motionless_level_threshold=6; //6*128 volatile uint8_t sts_motionless_duration_threshold_in_min=1; // test mode, 1 min, normal 10 min. long occupation 30 min volatile uint16_t sts_unconscious_level_threshold=600; @@ -1177,7 +1180,10 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context) sts_o7_sensorData.over_stay_state = 1; sts_o7_sensorData.over_stay_duration = sts_o7_sensorData.event_sensor1_duration; over_threshold = TRUE; - APP_LOG(TS_OFF, VLEVEL_L, "\r\nSensor 1 Over Stay State=%d, Duration= %d Sec, Threshold =%u \r\n", sts_o7_sensorData.over_stay_state,(sts_o7_sensorData.over_stay_duration),(sts_occupancy_overtime_threshold_in_10min*60) ); + APP_LOG(TS_OFF, VLEVEL_L, "\r\nSensor 1 Over Stay State=%d, Duration= %d Sec, Threshold =%u \r\n", + sts_o7_sensorData.over_stay_state, + (sts_o7_sensorData.over_stay_duration), + (sts_occupancy_overtime_threshold_in_10min*60) ); sts_lamp_bar_color = STS_RED_DARK; //sts_lamp_bar_flashing_color = 0x20; //volatile uint8_t sts_lamp_bar_color = STS_GREEN; //puColor @@ -1214,7 +1220,7 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context) { sts_o7_sensorData.event_sensor3_motion_duration = current_time.Seconds - sts_o7_sensorData.event_sensor3_motion_start_time; //if (sts_o7_sensorData.event_sensor3_motion_duration > sts_occupancy_overtime_threshold_in_10min*600) - if (sts_o7_sensorData.event_sensor3_motion_duration > sts_occupancy_overtime_threshold_in_10min) //for debug + if (sts_o7_sensorData.event_sensor3_motion_duration > sts_occupancy_overtime_threshold_in_10min*60) //for debug { sts_o7_sensorData.occupancy_over_stay_state = 1; sts_o7_sensorData.occupancy_duration =sts_o7_sensorData.event_sensor3_motion_duration; @@ -1263,6 +1269,13 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context) sts_o7_sensorData.fall_state = sts_fall_rising_detected_result; sts_o7_sensorData.event_sensor3_no_movement_duration = current_time.Seconds - sts_o7_sensorData.event_sensor3_no_movement_start_time; sts_o7_sensorData.event_sensor3_unconcious_duration = current_time.Seconds - sts_o7_sensorData.event_sensor3_unconcious_start_time; + // sts_motionless_duration_threshold_in_min + if ((sts_o7_sensorData.event_sensor3_no_movement_duration > sts_cfg_nvm.motionless_duration_threshold_in_min*60)|| + (sts_o7_sensorData.unconscious_duration > sts_cfg_nvm.motionless_duration_threshold_in_min*60)) + { + sts_o7_sensorData.unconscious_state = 1; + over_threshold = TRUE; + } break; } @@ -1274,8 +1287,9 @@ static void OnYunhornSTSDurationCheckTimerEvent(void *context) if (over_threshold == TRUE) { sensor_data_ready = 1; - + sts_lamp_bar_color = sts_lamp_bar_flashing_color; SendTxData(); + over_threshold = FALSE; } }