diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 306d5f5..9f0507f 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -906,7 +906,11 @@ static void SendTxData(void) #ifdef VL53LX #ifdef STS_P2 - STS_people_count_sensor_Read(&sts_p2_sensor_data); + if (IsClockSynched == true) + { + STS_people_count_sensor_Read(&sts_p2_sensor_data); + } + #elif defined(STS_T6) STS_tof_presence_detection_sensor_Read(&sts_t6_sensor_data); #endif @@ -1109,11 +1113,13 @@ static void SendTxData(void) AppData.BufferSize = i; //&(~sts_service_mask); #ifdef CLOCK_SYNC - if( IsClockSynched == false ) + + if (false == IsClockSynched) { status = LmhpClockSyncAppTimeReq( ); if (LORAMAC_HANDLER_SUCCESS == status) { + APP_LOG(TS_OFF, VLEVEL_L, "\r\n---- Clock Sync ---- good \r\n"); OnSysTimeUpdate(); } } diff --git a/LoRaWAN/Target/lorawan_conf.h b/LoRaWAN/Target/lorawan_conf.h index 1706743..443d818 100644 --- a/LoRaWAN/Target/lorawan_conf.h +++ b/LoRaWAN/Target/lorawan_conf.h @@ -69,7 +69,7 @@ extern "C" { * - Firmware Management Protocol (Package ID: 4, Default Port: 203) * The Certification Protocol is also defined as a mandatory package (Package ID: 0, Default Port: 224) */ -#define LORAWAN_DATA_DISTRIB_MGT 0 +#define LORAWAN_DATA_DISTRIB_MGT 1 /*! * @brief LoRaWAN packages version diff --git a/STM32CubeIDE/Release/STS_P2_2025JAN16_debug.elf b/STM32CubeIDE/Release/STS_P2_2025JAN16_debug.elf new file mode 100644 index 0000000..bd17d1e Binary files /dev/null and b/STM32CubeIDE/Release/STS_P2_2025JAN16_debug.elf differ diff --git a/STM32CubeIDE/Release/WLE5CC_NODE_STS.elf b/STM32CubeIDE/Release/WLE5CC_NODE_STS.elf index 95dfc03..bd17d1e 100644 Binary files a/STM32CubeIDE/Release/WLE5CC_NODE_STS.elf and b/STM32CubeIDE/Release/WLE5CC_NODE_STS.elf differ diff --git a/STS/Core/Src/yunhorn_sts_process.c b/STS/Core/Src/yunhorn_sts_process.c index 270f928..d86e29a 100644 --- a/STS/Core/Src/yunhorn_sts_process.c +++ b/STS/Core/Src/yunhorn_sts_process.c @@ -2088,7 +2088,7 @@ void OnYunhornSTSOORSSWakeUpTimerEvent(void *context) #if 0 void OnYunhornSTSHeartBeatTimerEvent(void *context) { -#if 0 +#if 1 uint8_t appDataPort, appBufferSize, appDataBuffer[32]; appDataPort = YUNHORN_STS_P2_LORA_APP_HTBT_PORT; appBufferSize = 2; diff --git a/STS/TOF/App/app_tof_peoplecount.c b/STS/TOF/App/app_tof_peoplecount.c index 5544acb..3bc5d1d 100644 --- a/STS/TOF/App/app_tof_peoplecount.c +++ b/STS/TOF/App/app_tof_peoplecount.c @@ -25,9 +25,9 @@ extern volatile sts_cfg_nvm_t sts_cfg_nvm; extern volatile uint8_t nvm_store_value[]; extern volatile struct tm sts_localtime; volatile uint8_t sts_tof_presence_state=0, sts_tof_presence_state_changed=0, sts_tof_presence_distance_dm=0, sts_pir_state=0; -volatile int sts_localtime_day, sts_localtime_week, sts_localtime_month, sts_localtime_year, sts_localtime_day; +volatile int sts_localtime_day, sts_localtime_week, sts_localtime_month, sts_localtime_year; extern volatile uint8_t sts_lamp_bar_color, sts_color_occupy_vacant; - +static uint8_t sum_count_changed = 0; #define STS_COLOR_DEFAULT_VACANT (sts_color_occupy_vacant&0x0f) #define STS_COLOR_DEFAULT_OCCUPY ((sts_color_occupy_vacant>>4)&0x0f) @@ -469,15 +469,21 @@ void STS_tof_presence_detection_sensor_Read(sts_tof_presence_detection_sensor_da void STS_people_count_sensor_Read(sts_people_count_sensor_data_t *sts_p2_sensor_data) { + APP_LOG(TS_OFF, VLEVEL_L, "\n (1) In=%04d Out=%04d Around=%04d Day_in=%04d Day_out=%04d Day_around=%04d\n", + sts_people_count_sensor_data.Walk_In_People_Count,sts_people_count_sensor_data.Walk_Out_People_Count,sts_people_count_sensor_data.Walk_Around_People_Count, + sts_people_count_sensor_data.Sum_Day_Walk_In_People_Count,sts_people_count_sensor_data.Sum_Day_Walk_Out_People_Count,sts_people_count_sensor_data.Sum_Day_Walk_Around_People_Count); + sts_p2_sensor_data->Count_Valid = sts_people_count_sensor_data.Count_Valid; + sum_count_changed = ((sts_people_count_sensor_data.Walk_In_People_Count + sts_people_count_sensor_data.Walk_Out_People_Count + sts_people_count_sensor_data.Walk_Around_People_Count)==0)? 0:1; + sts_p2_sensor_data->Walk_In_People_Count = sts_people_count_sensor_data.Walk_In_People_Count; sts_p2_sensor_data->Walk_Out_People_Count = sts_people_count_sensor_data.Walk_Out_People_Count; sts_p2_sensor_data->Walk_Around_People_Count = sts_people_count_sensor_data.Walk_Around_People_Count; sts_p2_sensor_data->Count_Period = sts_cfg_nvm.periodicity; //sts_people_count_sensor_data.Count_Period; sts_p2_sensor_data->Count_Period_Unit = sts_cfg_nvm.unit; //sts_people_count_sensor_data.Count_Period_Unit; - // Sum Day counting + // Sum Day counting // if not end of day --- sts_people_count_sensor_data.Sum_Day_Walk_In_People_Count += sts_people_count_sensor_data.Walk_In_People_Count; sts_people_count_sensor_data.Sum_Day_Walk_Out_People_Count += sts_people_count_sensor_data.Walk_Out_People_Count; @@ -487,6 +493,13 @@ void STS_people_count_sensor_Read(sts_people_count_sensor_data_t *sts_p2_sensor_ sts_p2_sensor_data->Sum_Day_Walk_Out_People_Count = sts_people_count_sensor_data.Sum_Day_Walk_Out_People_Count; sts_p2_sensor_data->Sum_Day_Walk_Around_People_Count = sts_people_count_sensor_data.Sum_Day_Walk_Around_People_Count; + if (sum_count_changed) + { + APP_LOG(TS_OFF, VLEVEL_L, "\n (3) In=%04d Out=%04d Around=%04d Day_in=%04d Day_out=%04d Day_around=%04d\n", + sts_people_count_sensor_data.Walk_In_People_Count,sts_people_count_sensor_data.Walk_Out_People_Count,sts_people_count_sensor_data.Walk_Around_People_Count, + sts_people_count_sensor_data.Sum_Day_Walk_In_People_Count,sts_people_count_sensor_data.Sum_Day_Walk_Out_People_Count,sts_people_count_sensor_data.Sum_Day_Walk_Around_People_Count); + + STS_Get_Date_Time_Stamp(); // else reset day counter if (sts_localtime.tm_mday != sts_localtime_day) @@ -592,47 +605,84 @@ void STS_people_count_sensor_Read(sts_people_count_sensor_data_t *sts_p2_sensor_ } } - uint16_t sts_p2_data_to_nvm[32] ={0x0}, pp =0; + uint8_t sts_p2_data_to_nvm[64] ={0x0}, pp =0; // OnRestoreSTSLOGContextRequest((void*)sts_p2_data_to_nvm); // TODO XXX, better read the data in flash and then add up today's data // TODO XXX - sts_p2_data_to_nvm[pp++] = sts_people_count_sensor_data.Sum_Day_Walk_In_People_Count; - sts_p2_data_to_nvm[pp++] = sts_people_count_sensor_data.Sum_Day_Walk_Out_People_Count; - sts_p2_data_to_nvm[pp++] = sts_people_count_sensor_data.Sum_Day_Walk_Around_People_Count; + sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Day_Walk_In_People_Count<<8; + sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Day_Walk_In_People_Count&0xff; - sts_p2_data_to_nvm[pp++] = sts_people_count_sensor_data.Sum_Week_Walk_In_People_Count; - sts_p2_data_to_nvm[pp++] = sts_people_count_sensor_data.Sum_Week_Walk_Out_People_Count; - sts_p2_data_to_nvm[pp++] = sts_people_count_sensor_data.Sum_Week_Walk_Around_People_Count; + sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Day_Walk_Out_People_Count<<8; + sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Day_Walk_Out_People_Count; - sts_p2_data_to_nvm[pp++] = sts_people_count_sensor_data.Sum_Month_Walk_In_People_Count; - sts_p2_data_to_nvm[pp++] = sts_people_count_sensor_data.Sum_Month_Walk_Out_People_Count; - sts_p2_data_to_nvm[pp++] = sts_people_count_sensor_data.Sum_Month_Walk_Around_People_Count; + sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Day_Walk_Around_People_Count<<8; + sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Day_Walk_Around_People_Count; + sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Week_Walk_In_People_Count<<8; + sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Week_Walk_In_People_Count; - sts_p2_data_to_nvm[pp++] = sts_people_count_sensor_data.Sum_Year_Walk_In_People_Count; - sts_p2_data_to_nvm[pp++] = sts_people_count_sensor_data.Sum_Year_Walk_Out_People_Count; - sts_p2_data_to_nvm[pp++] = sts_people_count_sensor_data.Sum_Year_Walk_Around_People_Count; + sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Week_Walk_Out_People_Count<<8; + sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Week_Walk_Out_People_Count; - sts_p2_data_to_nvm[pp++] = sts_people_count_sensor_data.Sum_LifeCycle_Walk_In_People_Count; - sts_p2_data_to_nvm[pp++] = sts_people_count_sensor_data.Sum_LifeCycle_Walk_Out_People_Count; - sts_p2_data_to_nvm[pp++] = sts_people_count_sensor_data.Sum_LifeCycle_Walk_Around_People_Count; -/* - APP_LOG(TS_OFF, VLEVEL_M, "\n-----------------------------------------------\n"); - APP_LOG(TS_OFF, VLEVEL_M, "\n00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15\n"); - for (uint8_t i=0; i