From b1de2c6e204586b109edb478d9067951310baf29 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Wed, 14 Aug 2024 14:12:51 +0800 Subject: [PATCH] --revised ...not good after join...x min to resend --- Core/Inc/sys_conf.h | 6 +-- Core/Src/yunhorn_sts_presence_rss.c | 20 +++++----- Core/Src/yunhorn_sts_process.c | 8 ++-- LoRaWAN/App/lora_app.c | 61 ++++++++++------------------- STM32CubeIDE/.cproject | 1 - 5 files changed, 38 insertions(+), 58 deletions(-) diff --git a/Core/Inc/sys_conf.h b/Core/Inc/sys_conf.h index 2661f50..6059cf0 100644 --- a/Core/Inc/sys_conf.h +++ b/Core/Inc/sys_conf.h @@ -50,12 +50,12 @@ extern "C" { * #define VLEVEL_M 2 functional traces * #define VLEVEL_H 3 all traces */ -#define VERBOSE_LEVEL VLEVEL_OFF +#define VERBOSE_LEVEL VLEVEL_M /** * @brief Enable trace logs */ -#define APP_LOG_ENABLED 0 +#define APP_LOG_ENABLED 1 /** * @brief Activate monitoring (probes) of some internal RF signals for debug purpose @@ -78,7 +78,7 @@ extern "C" { * @brief Enable/Disable MCU Debugger pins (dbg serial wires) * @note by HW serial wires are ON by default, need to put them OFF to save power */ -#define DEBUGGER_ENABLED 0 +#define DEBUGGER_ENABLED 1 /** * @brief Disable Low Power mode diff --git a/Core/Src/yunhorn_sts_presence_rss.c b/Core/Src/yunhorn_sts_presence_rss.c index 3cc244d..0d0b184 100644 --- a/Core/Src/yunhorn_sts_presence_rss.c +++ b/Core/Src/yunhorn_sts_presence_rss.c @@ -348,19 +348,19 @@ int sts_presence_rss_fall_rise_detection(void) { case STS_RSS_CONFIG_DEFAULT: set_default_configuration(presence_configuration); - APP_LOG(TS_OFF, VLEVEL_L,"\r\n##### YUNHORN STS *** Default *** cfg applied\n"); + APP_LOG(TS_OFF, VLEVEL_H,"\r\n##### YUNHORN STS *** Default *** cfg applied\n"); break; case STS_RSS_CONFIG_SIMPLE: sts_rss_set_current_configuration_simple(presence_configuration); - APP_LOG(TS_OFF, VLEVEL_L,"\r\n##### YUNHORN STS *** Simple *** cfg applied\n"); + APP_LOG(TS_OFF, VLEVEL_H,"\r\n##### YUNHORN STS *** Simple *** cfg applied\n"); break; case STS_RSS_CONFIG_FULL: sts_rss_set_current_configuration_full(presence_configuration); - APP_LOG(TS_OFF, VLEVEL_L,"\r\n######### YUNHORN STS *** FULL *** cfg applied\n"); + APP_LOG(TS_OFF, VLEVEL_H,"\r\n######### YUNHORN STS *** FULL *** cfg applied\n"); break; case STS_RSS_CONFIG_FALL_DETECTION: set_default_fall_rise_configuration(presence_configuration); - APP_LOG(TS_OFF, VLEVEL_L,"\r\n######### YUNHORN STS *** FALL DETECTION *** cfg applied\n"); + APP_LOG(TS_OFF, VLEVEL_H,"\r\n######### YUNHORN STS *** FALL DETECTION *** cfg applied\n"); break; default: break; @@ -449,7 +449,7 @@ int sts_presence_rss_fall_rise_detection(void) //acc_integration_sleep_ms(1000 / DEFAULT_UPDATE_RATE_PRESENCE); // 15ms, DEFAULT_UPDATE_RATE); //acc_integration_sleep_ms(1); } - APP_LOG(TS_OFF, VLEVEL_M, "\r\n First Half --- Motion Count = %u \r\n", motion_count); + APP_LOG(TS_OFF, VLEVEL_H, "\r\n First Half --- Motion Count = %u \r\n", motion_count); acc_detector_presence_deactivate(handle); @@ -462,7 +462,7 @@ int sts_presence_rss_fall_rise_detection(void) if (!acc_detector_presence_reconfigure(&handle, presence_configuration)) { - APP_LOG(TS_OFF, VLEVEL_M,"Failed to reconfigure detector\n"); + APP_LOG(TS_OFF, VLEVEL_H,"Failed to reconfigure detector\n"); acc_detector_presence_configuration_destroy(&presence_configuration); acc_detector_presence_destroy(&handle); acc_rss_deactivate(); @@ -523,7 +523,7 @@ int sts_presence_rss_fall_rise_detection(void) //acc_integration_sleep_ms(1); } - APP_LOG(TS_OFF, VLEVEL_M, "\r\n Second Half --- Motion Count Sum to = %u \r\n", motion_count); + APP_LOG(TS_OFF, VLEVEL_H, "\r\n Second Half --- Motion Count Sum to = %u \r\n", motion_count); //APP_LOG(TS_OFF, VLEVEL_L,"Second Half, Fall Rise Detection, Motion Count = %u \r\n", (int)motion_count); @@ -535,7 +535,7 @@ int sts_presence_rss_fall_rise_detection(void) // RSS feature 1: Motion, No-motion process sts_rss_result = (average_result > 3)? 1: 0; - APP_LOG(TS_OFF, VLEVEL_M, "\r\n MotionDetect Average result=%u : RSS result -- = %u \r\n", average_result, sts_rss_result); + APP_LOG(TS_OFF, VLEVEL_H, "\r\n MotionDetect Average result=%u : RSS result -- = %u \r\n", average_result, sts_rss_result); if (sts_rss_result) { LED1_ON; @@ -577,8 +577,8 @@ int sts_presence_rss_fall_rise_detection(void) //#ifdef LOG_RSS - APP_LOG(TS_OFF, VLEVEL_L,"\r\nSensor at Ceiling Height: %u mm\r\n",(uint16_t)sts_sensor_install_height); - APP_LOG(TS_OFF, VLEVEL_L,"\r\n|Motion Distance Zone| ##### |Height cm|\r\n"); + APP_LOG(TS_OFF, VLEVEL_H,"\r\nSensor at Ceiling Height: %u mm\r\n",(uint16_t)sts_sensor_install_height); + APP_LOG(TS_OFF, VLEVEL_H,"\r\n|Motion Distance Zone| ##### |Height cm|\r\n"); uint8_t kk = (uint8_t)(sts_sensor_install_height/400+1); #if 0 APP_LOG(TS_OFF, VLEVEL_L,"\r\n|-----------Ceiling-------Sensor---V-----|\r\n"); diff --git a/Core/Src/yunhorn_sts_process.c b/Core/Src/yunhorn_sts_process.c index 0c589d0..60404fc 100644 --- a/Core/Src/yunhorn_sts_process.c +++ b/Core/Src/yunhorn_sts_process.c @@ -270,12 +270,12 @@ void STS_YunhornSTSEventP2_Process(void) sts_presence_rss_fall_rise_detection(); sts_rss_result_changed_flag = (sts_rss_result == last_sts_rss_result)? 0:1; - APP_LOG(TS_OFF, VLEVEL_M, "\r\n STS_RSS Motion Detection changed flag=%u \r\n",sts_rss_result_changed_flag ); + last_sts_rss_result = sts_rss_result; //sts_fall_rising_detected_result_changed_flag = (sts_fall_rising_detected_result == last_sts_fall_rising_detected_result)?0:1; sts_fall_rising_detected_result_changed_flag = (sts_fall_rising_detected_result != last_sts_fall_rising_detected_result)?1:0; - APP_LOG(TS_OFF, VLEVEL_M, "\r\n STS_RSS Fall Detection changed flag FLAG=%u \r\n",sts_fall_rising_detected_result_changed_flag ); + last_sts_fall_rising_detected_result = sts_fall_rising_detected_result; @@ -790,7 +790,7 @@ void STS_PRESENCE_SENSOR_Prepare_Send_Data(STS_OO_SensorStatusDataTypeDef *senso sensor_data->no_movement_duration = sts_o7_sensorData.event_sensor3_no_movement_duration; if (sensor_data->unconscious_state !=0) { - APP_LOG(TS_OFF,VLEVEL_L,"\r\n ... Unconscious or No Movement Duration = %u Sec [Threshold: %u Seconds]\r\n", + APP_LOG(TS_OFF,VLEVEL_M,"\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); } @@ -800,7 +800,7 @@ void STS_PRESENCE_SENSOR_Prepare_Send_Data(STS_OO_SensorStatusDataTypeDef *senso 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", + APP_LOG(TS_OFF,VLEVEL_M,"\r\n ... Over Stay Duration = %u Sec [Threshold: %u Seconds]\r\n", sensor_data->over_stay_duration, sts_occupancy_overtime_threshold_in_10min*60); } diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 8de30b1..f94a5ca 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -488,7 +488,7 @@ static LmHandlerParams_t LmHandlerParams = /** * @brief Type of Event to generate application Tx */ -static TxEventType_t EventType = TX_ON_EVENT; //TX_ON_TIMER; //TX_ON_TIMER; +static TxEventType_t EventType = TX_ON_TIMER; //TX_ON_TIMER; /** * @brief Timer to handle the application Tx @@ -929,8 +929,8 @@ static void SendTxData(void) if (LmHandlerIsBusy() == false) { uint32_t i = 0; - APP_LOG(TS_OFF, VLEVEL_M, "\r\n STS_WORK_MODE = %02x \r\n", sts_work_mode); STS_PRESENCE_SENSOR_Prepare_Send_Data(&sensorData); + if (sts_work_mode == STS_DUAL_MODE) { AppData.Port = (uint8_t)YUNHORN_STS_O6_LORA_APP_DATA_PORT; @@ -1099,12 +1099,16 @@ static void SendTxData(void) nextTxIn = LmHandlerGetDutyCycleWaitTime(); if (nextTxIn > 0) { - APP_LOG(TS_ON, VLEVEL_H, "Next Tx in : ~%d second(s)\r\n", (nextTxIn / 1000)); + APP_LOG(TS_ON, VLEVEL_M, "Next Tx in : ~%d second(s)\r\n", (nextTxIn / 1000)); } } + } else { + + APP_LOG(TS_OFF, VLEVEL_M, "\r\n ######## LmHandlerIsBusy ************** \r\n"); + } - if ((EventType == TX_ON_TIMER)||((EventType == TX_ON_EVENT)&&(nextTxIn >0))) + if ((EventType == TX_ON_TIMER)) //||((EventType == TX_ON_EVENT)&&(nextTxIn >0))) { UTIL_TIMER_Stop(&TxTimer); UTIL_TIMER_SetPeriod(&TxTimer, MAX(nextTxIn, TxPeriodicity)); @@ -1170,44 +1174,19 @@ static void OnYunhornSTSLampBarColorTimerEvent(void *context) luminance_level %= 60; luminance_level = MAX(10,luminance_level); #endif - //if (STSLampBarColorTimer.IsRunning) - { + UTIL_TIMER_Stop(&STSLampBarColorTimer); if (high4==0) { - //if (last_sts_lamp_bar_color != sts_lamp_bar_color) - { - //__disable_irq(); - STS_Lamp_Bar_Set_STS_RGB_Color(sts_lamp_bar_color, luminance_level); - //__enable_irq(); - //STS_WS2812B_Refresh(); - last_sts_lamp_bar_color = sts_lamp_bar_color; - } + STS_Lamp_Bar_Set_STS_RGB_Color(sts_lamp_bar_color, luminance_level); - } else { - if (r_b) - { - //__disable_irq(); - STS_Lamp_Bar_Set_STS_RGB_Color(high4, luminance_level); - //__enable_irq(); - //last_sts_lamp_bar_color = high4; - //STS_WS2812B_Refresh(); - } - else { - //__disable_irq(); - STS_Lamp_Bar_Set_STS_RGB_Color(low4, luminance_level); - //__enable_irq(); - //last_sts_lamp_bar_color = low4; - //STS_WS2812B_Refresh(); - } - - r_b = !r_b; + } else + { + STS_Lamp_Bar_Set_STS_RGB_Color(r_b?high4:low4, luminance_level); + r_b = !r_b; } - UTIL_TIMER_Start(&STSLampBarColorTimer); - } - } static void OnYunhornSTSDurationCheckTimerEvent(void *context) @@ -1443,7 +1422,8 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams) //UTIL_TIMER_Start(&STSDurationCheckTimer); OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity); - UTIL_TIMER_Create(&YunhornSTSRSSWakeUpTimer, YUNHORN_STS_RSS_WAKEUP_CHECK_TIME, UTIL_TIMER_PERIODIC, OnYunhornSTSOORSSWakeUpTimerEvent, NULL); + //UTIL_TIMER_Create(&YunhornSTSRSSWakeUpTimer, YUNHORN_STS_RSS_WAKEUP_CHECK_TIME, UTIL_TIMER_PERIODIC, OnYunhornSTSOORSSWakeUpTimerEvent, NULL); + UTIL_TIMER_Create(&YunhornSTSRSSWakeUpTimer, YUNHORN_STS_RSS_WAKEUP_CHECK_TIME, UTIL_TIMER_ONESHOT, OnYunhornSTSOORSSWakeUpTimerEvent, NULL); UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer); STS_SENSOR_Distance_Test_Process(); @@ -1706,13 +1686,14 @@ static void OnYunhornSTSOORSSWakeUpTimerEvent(void *context) if ((sts_work_mode == STS_RSS_MODE)||(sts_work_mode == STS_DUAL_MODE)||(sts_work_mode == STS_UNI_MODE)) { UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP2), CFG_SEQ_Prio_0); - APP_LOG(TS_OFF,VLEVEL_M,"\r\n Wakeup Timer ======== RSS result changed flag=%d \r\n", sts_rss_result_changed_flag); + if ((sts_rss_result_changed_flag == 1) || (sts_fall_rising_detected_result_changed_flag == 1)) { + SendTxData(); sts_rss_result_changed_flag = 0; sts_fall_rising_detected_result_changed_flag = 0; - APP_LOG(TS_OFF,VLEVEL_M,"\r\n Wakeup Timer ======== Send Tx Result\r\n"); - SendTxData(); + + //UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0); //if ((last_sts_rss_result ==STS_RESULT_NO_MOTION)&& (sts_rss_result==STS_RESULT_MOTION)) { @@ -1722,7 +1703,7 @@ static void OnYunhornSTSOORSSWakeUpTimerEvent(void *context) } - //UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer); + UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer); } diff --git a/STM32CubeIDE/.cproject b/STM32CubeIDE/.cproject index 93edae5..df8e835 100644 --- a/STM32CubeIDE/.cproject +++ b/STM32CubeIDE/.cproject @@ -154,7 +154,6 @@