diff --git a/Core/Src/sts_lamp_bar.c b/Core/Src/sts_lamp_bar.c index 42b6e26..72c5dde 100644 --- a/Core/Src/sts_lamp_bar.c +++ b/Core/Src/sts_lamp_bar.c @@ -285,7 +285,8 @@ void STS_Combined_Status_Processing(void) sts_status_color = STS_RED_BLUE; } } - break; + break; + case STS_UNI_MODE: //FOR STS-O7 if ((sts_rss_result == STS_RESULT_NO_MOTION) && (sts_reed_hall_1_result == STS_Status_Door_Open )&& (sts_reed_hall_2_result == STS_Status_SOS_Release )) { @@ -294,7 +295,10 @@ void STS_Combined_Status_Processing(void) } else if ((sts_rss_result == STS_RESULT_MOTION) || (sts_reed_hall_1_result == STS_Status_Door_Close )||(sts_reed_hall_2_result == STS_Status_SOS_Pushdown )) { sts_status_color = STS_RED; - switch(sts_fall_rising_detected_result) { + } + + switch(sts_fall_rising_detected_result) + { case STS_PRESENCE_LAYDOWN: sts_lamp_bar_color = STS_YELLOW; sts_status_color = STS_YELLOW; @@ -302,18 +306,23 @@ void STS_Combined_Status_Processing(void) case STS_PRESENCE_FALL: //RED_BLUE FLASH sts_lamp_bar_color = STS_RED_BLUE; sts_status_color = STS_RED_BLUE; - break; + break; case STS_PRESENCE_RISING: //NORMAL OCCUPANCY STATUS sts_lamp_bar_color = STS_RED; sts_status_color = STS_RED; - break; - } - if (sts_reed_hall_2_result == STS_Status_SOS_Pushdown ) - { - sts_status_color = STS_RED_BLUE; - } - } - break; + break; + default: + sts_lamp_bar_color = STS_RED; + sts_status_color = STS_RED; + break; + } + + if (sts_reed_hall_2_result == STS_Status_SOS_Pushdown ) + { + sts_status_color = STS_RED_BLUE; + } + + break; case STS_REMOTE_REED_RSS_MODE: if ((sts_rss_result == STS_RESULT_NO_MOTION) && (sts_reed_hall_result == STS_Status_Door_Open )) diff --git a/Core/Src/yunhorn_sts_presence_rss.c b/Core/Src/yunhorn_sts_presence_rss.c index 3fd9ae7..ecd3b8e 100644 --- a/Core/Src/yunhorn_sts_presence_rss.c +++ b/Core/Src/yunhorn_sts_presence_rss.c @@ -88,7 +88,7 @@ extern volatile uint8_t sts_fall_detection_acc_threshold, sts_fall_detection_depth_threshold, sts_occupancy_overtime_threshold; volatile uint8_t sts_unconcious_state=0; volatile uint16_t sts_unconcious_threshold=1280, sts_unconcious_duration=0; -extern volatile uint8_t sts_rss_result, sts_rss_config_updated_flag; +extern volatile uint8_t sts_rss_result, sts_rss_config_updated_flag, last_sts_rss_result; extern volatile float sts_distance_rss_distance; volatile float sts_presence_rss_distance, sts_presence_rss_score; volatile STS_OO_RSS_SensorTuneDataTypeDef sts_presence_rss_config; @@ -413,7 +413,8 @@ int sts_presence_rss_fall_rise_detection(void) APP_LOG(TS_OFF, VLEVEL_H,"First Half Presence Detection, Motion Count = %u \r\n", (int)motion_count); #endif // ******** Second Half detection of fall down and rise up - +if (sts_presence_fall_detection == 1) +{ set_default_fall_rise_configuration(presence_configuration); if (!acc_detector_presence_reconfigure(&handle, presence_configuration)) @@ -472,10 +473,19 @@ int sts_presence_rss_fall_rise_detection(void) //APP_LOG(TS_OFF, VLEVEL_L,"Second Half, Fall Rise Detection, Motion Count = %u \r\n", (int)motion_count); APP_LOG(TS_OFF, VLEVEL_H,"Fall Rise Detection, Motion Count = %u \r\n", (int)motion_count); - +} sts_rss_result = (average_result > 1)? 1: 0; + if ((last_sts_rss_result ==STS_RESULT_NO_MOTION)&& (sts_rss_result==STS_RESULT_MOTION)) + { + OnSensor3StateChanged(); + } - OnSensor3StateChanged(); + /* TODO XXXX 2024-06-06 + * + * if (sts_rss_fall_rising_detected_result) + * + * + */ APP_LOG(TS_OFF, VLEVEL_H,"Average Motion Result = %u OUTPUT RSS RESULT=%u \r\n", (int)average_result, sts_rss_result); for (k=0; k<10; k++) { @@ -620,6 +630,7 @@ void STS_YunhornCheckStandardDeviation(void) (int)(sts_fall_detection_depth_threshold), (int)(sts_fall_rising_pattern_factor2)); #endif + // *********** detection suggestion if (standard_variance_presence_score <= MIN(DEFAULT_UNCONCIOUS_THRESHOLD, sts_unconcious_threshold)) { sts_fall_rising_detected_result = STS_PRESENCE_STAYSTILL; } diff --git a/Core/Src/yunhorn_sts_process.c b/Core/Src/yunhorn_sts_process.c index d7b6103..0bd0e1b 100644 --- a/Core/Src/yunhorn_sts_process.c +++ b/Core/Src/yunhorn_sts_process.c @@ -104,7 +104,7 @@ volatile uint8_t sts_rss_result_changed_flag = 0; volatile uint8_t sts_rss_result = STS_RESULT_NO_MOTION; volatile uint8_t sts_rss_2nd_result = STS_RESULT_NO_MOTION; //2nd RSS sensor status volatile uint8_t sts_tof_result = STS_RESULT_NO_MOTION; -volatile uint8_t last_sts_rss_result=0; +volatile uint8_t last_sts_rss_result=STS_RESULT_NO_MOTION; //extern volatile uint8_t last_sts_reed_hall_result; extern volatile uint8_t last_lamp_bar_color; @@ -847,7 +847,7 @@ void OnSensor1StateChanged(void) if (sts_hall1_read==STS_Status_Door_Close) { sts_o7_sensorData.event_sensor1_start_time = sensor_event_time.Seconds; - sts_o7_sensorData.event_sensor1_duration = sensor_event_time.Seconds- sts_o7_sensorData.event_sensor1_start_time; + sts_o7_sensorData.event_sensor1_duration = 0; } } @@ -857,7 +857,7 @@ void OnSensor2StateChanged(void) if (sts_hall2_read==STS_Status_SOS_Pushdown) { sts_o7_sensorData.event_sensor2_start_time = sensor_event_time.Seconds; - sts_o7_sensorData.event_sensor2_duration = sensor_event_time.Seconds- sts_o7_sensorData.event_sensor2_start_time; + sts_o7_sensorData.event_sensor2_duration = 0; } } @@ -867,7 +867,7 @@ void OnSensor3StateChanged(void) if (sts_rss_result == STS_RESULT_MOTION) { sts_o7_sensorData.event_sensor3_start_time = sensor_event_time.Seconds; - sts_o7_sensorData.event_sensor3_duration = sensor_event_time.Seconds- sts_o7_sensorData.event_sensor3_start_time; + sts_o7_sensorData.event_sensor3_duration = 0; } } diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 337eb49..b6aaaf8 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -449,7 +449,7 @@ static LmHandlerParams_t LmHandlerParams = /** * @brief Type of Event to generate application Tx */ -static TxEventType_t EventType = TX_ON_TIMER; +static TxEventType_t EventType = TX_ON_EVENT; /** * @brief Timer to handle the application Tx @@ -1077,22 +1077,30 @@ static void OnYunhornSTSLampBarColorTimerEvent(void *context) static void OnYunhornSTSDurationCheckTimerEvent(void *context) { - SysTime_t sensor_event_time = SysTimeGetMcuTime(); + SysTime_t current_time = SysTimeGetMcuTime(); if (sts_hall1_read==STS_Status_Door_Close) - sts_o7_sensorData.event_sensor1_duration = sensor_event_time.Seconds - sts_o7_sensorData.event_sensor1_start_time; + sts_o7_sensorData.event_sensor1_duration = current_time.Seconds - sts_o7_sensorData.event_sensor1_start_time; if (sts_o7_sensorData.event_sensor1_duration > sts_occupancy_overtime_threshold) { sts_o7_sensorData.over_stay_state = 1; - sts_o7_sensorData.over_stay_duration =sts_o7_sensorData.event_sensor1_duration; + sts_o7_sensorData.over_stay_duration = sts_o7_sensorData.event_sensor1_duration; } + // to be defiend later for SOS threshold TODO XXXX if (sts_hall2_read==STS_Status_SOS_Pushdown) - sts_o7_sensorData.event_sensor2_duration = sensor_event_time.Seconds - sts_o7_sensorData.event_sensor2_start_time; + sts_o7_sensorData.event_sensor2_duration = current_time.Seconds - sts_o7_sensorData.event_sensor2_start_time; + if (sts_o7_sensorData.event_sensor2_duration > sts_occupancy_overtime_threshold) + { + sts_o7_sensorData.over_stay_state = 1; + sts_o7_sensorData.over_stay_duration = sts_o7_sensorData.event_sensor2_duration; + } + // to be defiend later for SOS threshold TODO XXXX + if (sts_rss_result==STS_RESULT_MOTION) - sts_o7_sensorData.event_sensor3_duration = sensor_event_time.Seconds - sts_o7_sensorData.event_sensor3_start_time; + sts_o7_sensorData.event_sensor3_duration = current_time.Seconds - sts_o7_sensorData.event_sensor3_start_time; if (sts_o7_sensorData.event_sensor3_duration > sts_occupancy_overtime_threshold) { sts_o7_sensorData.occupancy_over_stay_state = 1; @@ -1286,7 +1294,7 @@ static void OnTxPeriodicityChanged(uint32_t periodicity) UTIL_TIMER_SetPeriod(&TxTimer, TxPeriodicity); UTIL_TIMER_Start(&TxTimer); /* USER CODE BEGIN OnTxPeriodicityChanged_2 */ - APP_LOG(TS_OFF, VLEVEL_L,"**************** TxPeriodicity = %u (sec)\r\n", (TxPeriodicity/1000) ); + APP_LOG(TS_OFF, VLEVEL_M,"**************** TxPeriodicity = %u (sec)\r\n", (TxPeriodicity/1000) ); /* USER CODE END OnTxPeriodicityChanged_2 */ } @@ -1510,7 +1518,7 @@ static void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity) UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer); /* USER CODE BEGIN OnTxPeriodicityChanged_2 */ - APP_LOG(TS_OFF, VLEVEL_H,"**************** HeartBeatPeriodicity Changed to: %u (ms)\r\n", HeartBeatPeriodicity ); + APP_LOG(TS_OFF, VLEVEL_M,"**************** HeartBeatPeriodicity Changed to: %u (ms)\r\n", HeartBeatPeriodicity ); /* USER CODE END OnTxPeriodicityChanged_2 */ } @@ -2484,7 +2492,7 @@ void OnRestoreSTSCFGContextProcess(void) periodicity *= 1; } periodicity = (periodicity > 10)? periodicity : 10; // in seconds unit - TxPeriodicity= periodicity*1000; // to ms + //TxPeriodicity= periodicity*1000; // to ms //OnTxPeriodicityChanged(TxPeriodicity); // in msec unit uint32_t sampling = (sts_cfg_nvm.sampling); @@ -2503,13 +2511,14 @@ void OnRestoreSTSCFGContextProcess(void) OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity); } else { - OnTxPeriodicityChanged(TxPeriodicity); // in msec unit + //OnTxPeriodicityChanged(TxPeriodicity); // in msec unit //Heart-beat or Sampling interval #ifdef STS_E0 samplingperiodicity = (samplingperiodicity > 0)? samplingperiodicity : 1; // in seconds unit HeartBeatPeriodicity = samplingperiodicity*1000; #endif #if defined(STS_O7)|| defined(STS_O6) ||defined(STS_O5) + OnYunhornSTSHeartBeatPeriodicityChanged(periodicity*1000); OnYunhornSTSSamplingPeriodicityChanged(sampling); // in m-sec unit #endif