fix sum day/week/month issue

This commit is contained in:
Yunhorn 2025-01-16 17:37:05 +08:00
parent c62c958937
commit 4ce585595b
6 changed files with 132 additions and 49 deletions

View File

@ -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();
}
}

View File

@ -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

Binary file not shown.

View File

@ -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;

View File

@ -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<YUNHORN_STS_MAX_NVM_CFG_SIZE; i++)
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Week_Walk_Around_People_Count<<8;
sts_p2_data_to_nvm[pp++] = (uint8_t)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_Month_Walk_In_People_Count<<8;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Month_Walk_In_People_Count;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Month_Walk_Out_People_Count<<8;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Month_Walk_Out_People_Count;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Month_Walk_Around_People_Count<<8;
sts_p2_data_to_nvm[pp++] = (uint8_t)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_Year_Walk_In_People_Count<<8;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Year_Walk_In_People_Count;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Year_Walk_Out_People_Count<<8;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Year_Walk_Out_People_Count;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Year_Walk_Around_People_Count<<8;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_Year_Walk_Around_People_Count;
// below int32 4 bytes data
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_LifeCycle_Walk_In_People_Count<<24;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_LifeCycle_Walk_In_People_Count<<16;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_LifeCycle_Walk_In_People_Count<<8;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_LifeCycle_Walk_In_People_Count;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_LifeCycle_Walk_Out_People_Count<<24;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_LifeCycle_Walk_Out_People_Count<<16;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_LifeCycle_Walk_Out_People_Count<<8;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_LifeCycle_Walk_Out_People_Count;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_LifeCycle_Walk_Around_People_Count<<24;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_LifeCycle_Walk_Around_People_Count<<16;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_LifeCycle_Walk_Around_People_Count<<8;
sts_p2_data_to_nvm[pp++] = (uint8_t)sts_people_count_sensor_data.Sum_LifeCycle_Walk_Around_People_Count;
APP_LOG(TS_OFF, VLEVEL_L, "\n (5) 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);
APP_LOG(TS_OFF, VLEVEL_L, "\n-----------------------------------------------\n");
APP_LOG(TS_OFF, VLEVEL_L, "\n----------- FLASH TO NVM DATA -----------------\n");
APP_LOG(TS_OFF, VLEVEL_L, "\n00 01 02 03 04 05 06 07\n");
for (uint8_t i=0; i< 64; i++)
{
if (i%8==0) APP_LOG(TS_OFF, VLEVEL_M, "\n");
APP_LOG(TS_OFF, VLEVEL_M, "%04X ", sts_p2_data_to_nvm[i]);
if ( i%8 == 0) APP_LOG(TS_OFF, VLEVEL_M, "\r\n");
APP_LOG(TS_OFF, VLEVEL_L, "%02x ", (uint8_t)sts_p2_data_to_nvm[i]);
}
APP_LOG(TS_OFF, VLEVEL_M, "\n\r");
APP_LOG(TS_OFF, VLEVEL_M, "\n###############################################\n\r");
*/
APP_LOG(TS_OFF, VLEVEL_L, "\n\r");
APP_LOG(TS_OFF, VLEVEL_L, "\n###############################################\n\r");
if (FLASH_IF_Erase(STS_SENSOR_DATA_NVM_BASE_ADDRESS, FLASH_PAGE_SIZE) == FLASH_IF_OK)
{
FLASH_IF_Write(STS_SENSOR_DATA_NVM_BASE_ADDRESS, (const void *)sts_p2_data_to_nvm, 64);
}
}
}
// reset counter at end of year TODO XXX
@ -648,30 +698,54 @@ void STS_TOF_VL53LX_PeopleCounting_Process_Init(void)
{
APP_LOG(TS_OFF, VLEVEL_L,"\n\n# YUNHORN STS-P2 PEOPLE COUNTING PROCESS #\r\n");
sts_tof_vl53lx_peoplecount_init();
sts_people_count_sensor_data.Count_Period = sts_cfg_nvm.periodicity;
sts_people_count_sensor_data.Count_Period_Unit = sts_cfg_nvm.unit;
uint16_t log_in_nvm[32];
STS_Get_Date_Time_Stamp();
sts_localtime_day = sts_localtime.tm_mday;
sts_localtime_week = sts_localtime.tm_wday;
sts_localtime_month = sts_localtime.tm_mon;
sts_localtime_year = sts_localtime.tm_year;
uint8_t log_in_nvm[64]={0x0};
OnRestoreSTSLOGContextRequest(log_in_nvm);
sts_people_count_sensor_data.Sum_Day_Walk_In_People_Count = (uint16_t)log_in_nvm[0];
sts_people_count_sensor_data.Sum_Day_Walk_Out_People_Count = (uint16_t)log_in_nvm[1];
sts_people_count_sensor_data.Sum_Day_Walk_Around_People_Count = (uint16_t)log_in_nvm[2];
if ((log_in_nvm[0]==0xff)&&(log_in_nvm[1]==0xff)) {
for (uint8_t i =0; i< 64; i++)
log_in_nvm[i] = 0x0;
} else
{
sts_people_count_sensor_data.Sum_Day_Walk_In_People_Count = (uint16_t)((log_in_nvm[0]<<8) | log_in_nvm[1]);
sts_people_count_sensor_data.Sum_Day_Walk_Out_People_Count = (uint16_t)((log_in_nvm[2]<<8) | log_in_nvm[3]);
sts_people_count_sensor_data.Sum_Day_Walk_Around_People_Count = (uint16_t)((log_in_nvm[4]<<8) | log_in_nvm[5]);
sts_people_count_sensor_data.Sum_Week_Walk_In_People_Count = (uint16_t)log_in_nvm[3];
sts_people_count_sensor_data.Sum_Week_Walk_Out_People_Count = (uint16_t)log_in_nvm[4];
sts_people_count_sensor_data.Sum_Week_Walk_Around_People_Count = (uint16_t)log_in_nvm[5];
sts_people_count_sensor_data.Sum_Week_Walk_In_People_Count = (uint16_t)((log_in_nvm[6]<<8) | log_in_nvm[7]);
sts_people_count_sensor_data.Sum_Week_Walk_Out_People_Count = (uint16_t)((log_in_nvm[8]<<8) | log_in_nvm[9]);
sts_people_count_sensor_data.Sum_Week_Walk_Around_People_Count = (uint16_t)((log_in_nvm[10]<<8) | log_in_nvm[11]);
sts_people_count_sensor_data.Sum_Month_Walk_In_People_Count = (uint16_t)log_in_nvm[6];
sts_people_count_sensor_data.Sum_Month_Walk_Out_People_Count = (uint16_t)log_in_nvm[7];
sts_people_count_sensor_data.Sum_Month_Walk_Around_People_Count = (uint16_t)log_in_nvm[8];
sts_people_count_sensor_data.Sum_Month_Walk_In_People_Count = (uint16_t)((log_in_nvm[12]<<8) | log_in_nvm[13]);
sts_people_count_sensor_data.Sum_Month_Walk_Out_People_Count = (uint16_t)((log_in_nvm[14]<<8) | log_in_nvm[15]);
sts_people_count_sensor_data.Sum_Month_Walk_Around_People_Count = (uint16_t)((log_in_nvm[16]<<8) | log_in_nvm[17]);
sts_people_count_sensor_data.Sum_Year_Walk_In_People_Count = (uint16_t)log_in_nvm[9];
sts_people_count_sensor_data.Sum_Year_Walk_Out_People_Count = (uint16_t)log_in_nvm[10];
sts_people_count_sensor_data.Sum_Year_Walk_Around_People_Count = (uint16_t)log_in_nvm[11];
sts_people_count_sensor_data.Sum_Year_Walk_In_People_Count = (uint16_t)((log_in_nvm[18]<<8) | log_in_nvm[19]);
sts_people_count_sensor_data.Sum_Year_Walk_Out_People_Count = (uint16_t)((log_in_nvm[20]<<8) | log_in_nvm[21]);
sts_people_count_sensor_data.Sum_Year_Walk_Around_People_Count = (uint16_t)((log_in_nvm[22]<<8) | log_in_nvm[23]);
sts_people_count_sensor_data.Sum_LifeCycle_Walk_In_People_Count = (uint16_t)log_in_nvm[12];
sts_people_count_sensor_data.Sum_LifeCycle_Walk_Out_People_Count = (uint16_t)log_in_nvm[13];
sts_people_count_sensor_data.Sum_LifeCycle_Walk_Around_People_Count = (uint16_t)log_in_nvm[14];
sts_people_count_sensor_data.Sum_LifeCycle_Walk_In_People_Count = (uint32_t)((log_in_nvm[24]<<24) | log_in_nvm[25]<<16 | log_in_nvm[26]<<8 | log_in_nvm[27]);
sts_people_count_sensor_data.Sum_LifeCycle_Walk_Out_People_Count = (uint32_t)((log_in_nvm[28]<<28) | log_in_nvm[29]<<16 | log_in_nvm[30]<<8 | log_in_nvm[31]);
sts_people_count_sensor_data.Sum_LifeCycle_Walk_Around_People_Count = (uint32_t)((log_in_nvm[32]<<24) | log_in_nvm[33]<<16 | log_in_nvm[34]<<8 | log_in_nvm[35]);
}
APP_LOG(TS_OFF, VLEVEL_L, "\r\n ************* Restore sum data from NVM *********** \r\n");
for (uint8_t i=0; i<64; i++)
{
if (i%8==0) APP_LOG(TS_OFF, VLEVEL_L, "\n");
APP_LOG(TS_OFF, VLEVEL_L, "|0x%02x ", (uint8_t)log_in_nvm[i]);
}
}
void STS_TOF_VL53LX_PeopleCounting_Process_Start(void)
@ -689,7 +763,9 @@ void STS_TOF_VL53LX_PeopleCounting_Process_Start(void)
{
sts_people_count_sensor_data.Count_Valid = 0;
//APP_LOG(TS_OFF, VLEVEL_M,"# Counting time out... \r\n");
} else {
}
#if 0
else {
// add up counting value since begin of day till now
sts_people_count_sensor_data.Sum_Day_Walk_In_People_Count += sts_people_count_sensor_data.Walk_In_People_Count;
@ -697,6 +773,7 @@ void STS_TOF_VL53LX_PeopleCounting_Process_Start(void)
sts_people_count_sensor_data.Sum_Day_Walk_Around_People_Count += sts_people_count_sensor_data.Walk_Around_People_Count;
}
#endif
}
}