diff --git a/STM32CubeIDE/Release/WLE5CC_NODE_STS.elf b/STM32CubeIDE/Release/WLE5CC_NODE_STS.elf index d6cdfe9..812681e 100644 Binary files a/STM32CubeIDE/Release/WLE5CC_NODE_STS.elf and b/STM32CubeIDE/Release/WLE5CC_NODE_STS.elf differ diff --git a/STS/Core/Inc/yunhorn_sts_prd_conf.h b/STS/Core/Inc/yunhorn_sts_prd_conf.h index be73bb6..59ecd04 100644 --- a/STS/Core/Inc/yunhorn_sts_prd_conf.h +++ b/STS/Core/Inc/yunhorn_sts_prd_conf.h @@ -369,7 +369,9 @@ enum sts_lamp_color { */ #define STS_CONFIG_NVM_BASE_ADDRESS FLASH_USER_START_ADDR -#define STS_CONFIG_NVM_CONFIG_SIZE FLASH_USER_CONFIG_SIZE +#define STS_CONFIG_NVM_CONFIG_SIZE FLASH_USER_CONFIG_SIZE +#define STS_SENSOR_DATA_NVM_BASE_ADDRESS ((void *) 0x0803F000U) // Last 4kB of flash +#define STS_SENSOR_DATA_NVM_SIZE ((void *) 0x000007FFU) //0x400=1KB=1024 /*---------------------------------------------------------------------------*/ /* LoRaWAN NVM configuration */ /*---------------------------------------------------------------------------*/ diff --git a/STS/Core/Inc/yunhorn_sts_sensors.h b/STS/Core/Inc/yunhorn_sts_sensors.h index 4fa99cb..8dc2ce4 100644 --- a/STS/Core/Inc/yunhorn_sts_sensors.h +++ b/STS/Core/Inc/yunhorn_sts_sensors.h @@ -238,7 +238,9 @@ void OnStoreSTSCFGContextRequest(void); /** * @brief Read config from flash */ -void OnRestoreSTSCFGContextRequest(uint8_t *cfg_in_nvm); +void OnRestoreSTSCFGContextRequest(void *cfg_in_nvm); + +void OnRestoreSTSLOGContextRequest(void *log_in_nvm); void STS_REBOOT_CONFIG_Init(void); diff --git a/STS/Core/Src/yunhorn_sts_process.c b/STS/Core/Src/yunhorn_sts_process.c index 392b9a9..1a8c6ba 100644 --- a/STS/Core/Src/yunhorn_sts_process.c +++ b/STS/Core/Src/yunhorn_sts_process.c @@ -47,8 +47,10 @@ #if defined(STS_P2)||defined(STS_T6) #include "app_tof.h" #include "app_tof_peoplecount.h" +extern volatile sts_people_count_sensor_data_t *sts_people_count_sensor_data; extern volatile uint8_t sts_door_jam_profile; extern volatile uint8_t sts_tof_presence_state_changed; +extern volatile sts_ppc_cfg_type_t ppc_cfg[]; #elif defined(L8) #include "app_tof.h" #endif @@ -71,6 +73,11 @@ volatile sts_cfg_nvm_t sts_cfg_nvm = { 0x00, //sts_ioc_mask 0x20, //32 bytes, below start of p[0] 20 BYTES AND 12 BYTES FALL DOWN CFG { // below 20 bytes +#ifdef STS_P2 + 0x0,0x8,0x10,0x0,0x3,0x8,0x21,0x1,0xaf,0xe7, //current work config profile short + 0x1,0x8,0x10,0x0,0x3,0x8,0x21,0x1,0xaf,0xe7, //current work config profile long, after measured distance + // change the max distance, min distance, SPAD, front center and back center, etc. +#else 0x08, //start_m [8]*0.1 meter =0.8 0x19, //lenght_m 0x19=[25]*0.1=2.5f meter 0x0F, //threshold 0X0F=[15]*0.1=1.5f @@ -91,6 +98,7 @@ volatile sts_cfg_nvm_t sts_cfg_nvm = { 0x00, //reserve --P[17] 0x00, //reserve --P[18] 0x00, //reserve --P[19] +#endif }, // above 20 bytes 0x00, //reserve2 0x00, //reserve3 @@ -137,7 +145,7 @@ extern volatile int sts_tof_distance_data[MAX_TOF_COUNT]; volatile sts_tof_range_data_t sts_range_sensor_data={0x0,0x0,0x0}; #endif #if defined(STS_P2)||defined(STS_T6) -volatile uint8_t sts_door_jam_profile = 0; +volatile uint8_t sts_door_jam_profile = DOOR_JAM_2400; #endif #ifdef STS_R4 volatile uint8_t sts_soap_level_state=0; @@ -647,6 +655,22 @@ void USER_APP_Parse_CMD_P(uint8_t *parse_buffer, uint8_t parse_buffer_size) break; case 12: break; + case 13: + for (uint8_t i=0; i<10; i++) { + sts_cfg_nvm.p[i] = (uint8_t)parse_buffer[CFG_CMD4+i]; + } + + ppc_cfg[parse_buffer[CFG_CMD4]].distance_array_size = (uint8_t)parse_buffer[CFG_CMD4+1]; + ppc_cfg[parse_buffer[CFG_CMD4]].max_distance = (uint8_t)parse_buffer[CFG_CMD4+2]; + ppc_cfg[parse_buffer[CFG_CMD4]].min_distance = (uint8_t)parse_buffer[CFG_CMD4+3]; + ppc_cfg[parse_buffer[CFG_CMD4]].dist_threshold = (uint8_t)parse_buffer[CFG_CMD4+4]; + ppc_cfg[parse_buffer[CFG_CMD4]].rows_of_SPADS = (uint8_t)parse_buffer[CFG_CMD4+5]; + ppc_cfg[parse_buffer[CFG_CMD4]].timing_budget = (uint8_t)parse_buffer[CFG_CMD4+6]; + ppc_cfg[parse_buffer[CFG_CMD4]].distance_mode = (uint8_t)parse_buffer[CFG_CMD4+7]; + ppc_cfg[parse_buffer[CFG_CMD4]].front_zone_center = (uint8_t)parse_buffer[CFG_CMD4+8]; + ppc_cfg[parse_buffer[CFG_CMD4]].back_zone_center = (uint8_t)parse_buffer[CFG_CMD4+9]; + break; + default: break; } @@ -1084,6 +1108,7 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s break; case 'M': /* "YZM": Mask level */ i = 0; + outbuf[i++] = (uint8_t)'Y'; outbuf[i++] = (uint8_t)'M'; outbuf[i++] = (uint8_t)sts_service_mask; outbuf[i++] = (uint8_t)sts_work_mode; @@ -1169,6 +1194,17 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf); break; + case 'M': + uint8_t log_in_nvm[YUNHORN_STS_MAX_NVM_CFG_SIZE]={0x0}; + OnRestoreSTSLOGContextRequest((void*)&log_in_nvm); + i=0; + outbuf[0] = 0x4D; // 'M' for MEM IN FLASH + UTIL_MEM_cpy_8(outbuf+1, log_in_nvm,32); + i=33; + STS_SENSOR_Upload_Message(YUNHORN_STS_USER_APP_CTRL_REPLY_PORT, i, (uint8_t *)outbuf); + + break; + default: break; } @@ -1252,8 +1288,12 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s APP_LOG(TS_OFF,VLEVEL_M, "\nSTS Tx Periodicty changed to %u sec\n\r", STS_TxPeriod_sec); #ifdef STS_R4 OnYunhornSTSTxPeriodicityChanged(STS_TxPeriod_sec*1000); -#elif defined(STS_R1D)||defined(STS_R1)||defined(STS_R5)||defined(STS_P2)||defined(STS_O6T)||defined(STS_R2)||defined(STS_R3)||defined(STS_R6)||defined(STS_O5)||defined(STS_M1) +#elif defined(STS_R1D)||defined(STS_R1)||defined(STS_R5)||defined(STS_O6T)||defined(STS_R2)||defined(STS_R3)||defined(STS_R6)||defined(STS_O5)||defined(STS_M1) OnYunhornSTSTxPeriodicityChanged(STS_TxPeriod_sec*1000); +#elif defined(STS_P2) + OnYunhornSTSTxPeriodicityChanged(STS_TxPeriod_sec*1000); + sts_people_count_sensor_data->Count_Period = (uint8_t)((tlv_buf[CFG_CMD3]-0x30)*10+ (tlv_buf[CFG_CMD4]-0x30)); + sts_people_count_sensor_data->Count_Period_Unit = (uint8_t)tlv_buf[CFG_CMD5]; #elif defined(STS_O6)||defined(STS_O7) OnYunhornSTSHeartBeatPeriodicityChanged(periodicity_length); #endif @@ -1551,7 +1591,7 @@ void OnStoreSTSCFGContextRequest(void) /* USER CODE END OnStoreContextRequest_Last */ } -void OnRestoreSTSCFGContextRequest(uint8_t *cfg_in_nvm) +void OnRestoreSTSCFGContextRequest(void *cfg_in_nvm) { /* USER CODE BEGIN OnRestoreSTSCFGContextRequest_1 */ @@ -1562,6 +1602,16 @@ void OnRestoreSTSCFGContextRequest(uint8_t *cfg_in_nvm) /* USER CODE END OnRestoreSTSCFGContextRequest_Last */ } +void OnRestoreSTSLOGContextRequest(void *log_in_nvm) +{ + /* USER CODE BEGIN OnRestoreSTSCFGContextRequest_1 */ + + /* USER CODE END OnRestoreSTSCFGContextRequest_1 */ + UTIL_MEM_cpy_8((void*)log_in_nvm, (void *)STS_SENSOR_DATA_NVM_BASE_ADDRESS, YUNHORN_STS_MAX_NVM_CFG_SIZE); + /* USER CODE BEGIN OnRestoreSTSCFGContextRequest_Last */ + + /* USER CODE END OnRestoreSTSCFGContextRequest_Last */ +} void STS_REBOOT_CONFIG_Init(void) { @@ -1672,6 +1722,8 @@ void OnRestoreSTSCFGContextProcess(void) #ifdef STS_P2 STS_TxPeriod_sec = periodicity; STS_HeartBeatTimerPeriod_sec = sampling_heartbeat_periodicity; + sts_people_count_sensor_data->Count_Period = sts_cfg_nvm.periodicity; + sts_people_count_sensor_data->Count_Period_Unit = sts_cfg_nvm.unit; #endif @@ -1795,21 +1847,22 @@ void STS_SENSOR_Function_Test_Process(void) if ((sts_sensor_install_height >= 1500)&&(sts_sensor_install_height<=4000)) { - sts_door_jam_profile = DOOR_JAM_2000; // DOOR_JAM_2000: assume door_jame less 2000mm + sts_door_jam_profile = DOOR_JAM_1600; // assume door_jame less 1600mm profile =1 - if (sts_sensor_install_height >= 2000) - sts_door_jam_profile ++; //DOOR_JAM_2400 + if (sts_sensor_install_height >= 1600) + sts_door_jam_profile ++; //DOOR_JAM_2400, profile =2 if (sts_sensor_install_height >= 2400) - sts_door_jam_profile ++; //DOOR_JAM_3000 + sts_door_jam_profile ++; //DOOR_JAM_3000, profile =3 if (sts_sensor_install_height >= 3000) - sts_door_jam_profile ++; //DOOR_JAM_3500 + sts_door_jam_profile ++; //DOOR_JAM_3500, profile = 4 if (sts_sensor_install_height >= 3500) - sts_door_jam_profile ++; //DOOR_JAM_4000 + sts_door_jam_profile ++; //DOOR_JAM_4000, profile = 5 APP_LOG(TS_OFF, VLEVEL_M, "\r\nDOOR JAM PROFILE=%d \r\n", sts_door_jam_profile); } + #endif #ifdef YUNHORN_STS_O6_ENABLED tstbuf[i++] = (uint8_t)20; //length of following data diff --git a/STS/TOF/App/app_tof_peoplecount.c b/STS/TOF/App/app_tof_peoplecount.c index f4df1e1..b51bd60 100644 --- a/STS/TOF/App/app_tof_peoplecount.c +++ b/STS/TOF/App/app_tof_peoplecount.c @@ -5,6 +5,8 @@ /* USER CODE BEGIN Includes */ #include "yunhorn_sts_sensors.h" #include "app_tof_peoplecount.h" +#include "flash_if.h" +#include "stm32_mem.h" #ifdef STS_P2 #include "VL53L1X_API.h" #include "VL53l1X_calibration.h" @@ -19,22 +21,19 @@ extern I2C_HandleTypeDef hi2c2; volatile sts_people_count_sensor_data_t sts_people_count_sensor_data={0,0,0,2,'M',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}; extern volatile uint32_t STS_TOFScanPeriod_sec, STS_TxPeriod_sec, STS_HeartBeatTimerPeriod_sec; extern volatile sts_cfg_nvm_t sts_cfg_nvm; +extern volatile uint8_t nvm_store_value[]; volatile uint8_t sts_tof_presence_state=0, sts_tof_presence_state_changed=0; /* TIMING_BUDGET, in ms possible values [15, 20, 50, 100, 200, 500] */ /* DISTANCE_THRESHOLD = MAX - ASSUME_CHILD_HEIGHT(800mm) */ +// door jam profile volatile sts_ppc_cfg_type_t ppc_cfg[6] = { - {DOOR_JAM_2000, 8, 2000,0,1600,8,33,DISTANCE_MODE_SHORT,175,247}, - {DOOR_JAM_2000, 8, 2000,0,1600,8,33,DISTANCE_MODE_SHORT,175,247}, - {DOOR_JAM_2400, 10, 2400,0,1600,8,33,DISTANCE_MODE_LONG,175,231}, -/* - {DOOR_JAM_2000, 16, 2000,0, 1200,16, tbms_33,DISTANCE_MODE_LONG,199,199}, - {DOOR_JAM_2400, 10, 2400,0, 1600,8, tbms_50,DISTANCE_MODE_LONG,175,231}, - {DOOR_JAM_3000, 10, 3000,0, 2200,8,tbms_100,DISTANCE_MODE_LONG,175,231}, - {DOOR_JAM_3500, 10, 3500,0, 2700,8,tbms_100,DISTANCE_MODE_LONG,175,231}, - {DOOR_JAM_4000, 10, 4000,0, 3200,8,tbms_200,DISTANCE_MODE_LONG,175,231}, - {DOOR_SIDE_1600, 8, 1600,0, 300,8, tbms_33,DISTANCE_MODE_SHORT,175,231}, -*/ + {DOOR_SIDE_1300,10, 1300,0, 1200,8,33, DISTANCE_MODE_SHORT,175,231}, + {DOOR_JAM_1600, 10, 1600,0, 1300,8,33, DISTANCE_MODE_SHORT,175,231}, + {DOOR_JAM_2400, 10, 2400,0, 1600,8,33, DISTANCE_MODE_LONG,175,231}, + {DOOR_JAM_3000, 10, 3000,0, 2200,8,100,DISTANCE_MODE_LONG,175,231}, + {DOOR_JAM_3500, 10, 3500,0, 2700,8,100,DISTANCE_MODE_LONG,175,231}, + {DOOR_JAM_4000, 10, 4000,0, 3200,8,200,DISTANCE_MODE_LONG,175,231}, }; volatile sts_zone_center_by_rows_of_spads_t zone_center[4]={ {4, 151, 247}, @@ -50,8 +49,8 @@ volatile uint8_t sts_distance_mode = DOOR_JAM_2400; //DOOR_JAM_2400; //sts_door_ #endif #if (defined(STS_P2)) volatile uint8_t sts_people_count_number_changed = 0; -static uint32_t cnt_today=0, cnt_week=0; -static uint8_t last_year=0, this_year=0,last_month=0, this_month=0,last_week=0, this_week=0,last_day=0, this_day=0; +static uint32_t cnt_today=0, cnt_day=0, cnt_week=0, cnt_month=0, cnt_year=0; +//static uint8_t last_year=0, this_year=0,last_month=0, this_month=0,last_week=0, this_week=0,last_day=0, this_day=0; #endif uint16_t dev=0x52; extern uint16_t sensor_id; @@ -60,7 +59,8 @@ volatile int IntCount; #define isInterrupt 1 /* If isInterrupt = 1 then device working in interrupt mode, else device working in polling mode */ /* USER CODE END PV */ static int PplCounter; -static int center[2] = {FRONT_ZONE_CENTER,BACK_ZONE_CENTER}; //{ppc_cfg[sts_distance_mode].front_zone_center, ppc_cfg[sts_distance_mode].back_zone_center}; /* these are the spad center of the 2 4*16 zones */ +static int center[2] = {FRONT_ZONE_CENTER,BACK_ZONE_CENTER}; + static int Zone = 0; static int PathTrack[] = {0,0,0,0}; static int PathTrackFillingSize = 1; // init this to 1 as we start from state where nobody is any of the zones @@ -265,14 +265,14 @@ int ProcessPeopleCountingData(int16_t Distance, uint8_t zone, uint8_t RangeStatu int AnEventHasOccured = 0; // Add just picked distance to the table of the corresponding zone - if (DistancesTableSize[zone] < ppc_cfg[sts_distance_mode].distance_array_size) { + if (DistancesTableSize[zone] < ppc_cfg[sts_door_jam_profile].distance_array_size) { Distances[zone][DistancesTableSize[zone]] = Distance; DistancesTableSize[zone] ++; } else { - for (i=1; iSOMEONE IN"); @@ -429,8 +429,8 @@ void STS_people_count_sensor_Read(sts_people_count_sensor_data_t *sts_p2_sensor_ 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_people_count_sensor_data.Count_Period; - sts_p2_sensor_data->Count_Period_Unit = sts_people_count_sensor_data.Count_Period_Unit; + 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 // if not end of day --- @@ -506,40 +506,80 @@ void STS_people_count_sensor_Read(sts_people_count_sensor_data_t *sts_p2_sensor_ sts_people_count_sensor_data.Walk_Around_People_Count = 0; } - if (cnt_today ==0) + //if (cnt_today ==0) { // new day, then check week/month/year, not check every time // reset counter at end of day TODO XXX - if (last_day != this_day) { - cnt_today = 0; - + cnt_day ++; + if (cnt_day >=7) { + cnt_day = 0; sts_people_count_sensor_data.Sum_Day_Walk_In_People_Count = 0; sts_people_count_sensor_data.Sum_Day_Walk_Out_People_Count = 0; sts_people_count_sensor_data.Sum_Day_Walk_Around_People_Count = 0; - } - if (cnt_week) - // reset counter at end of week TODO XXX - if (last_week != this_week) { + cnt_week++; + if (cnt_week >= 4 ) { + cnt_week =0; + sts_people_count_sensor_data.Sum_Week_Walk_In_People_Count = 0; + sts_people_count_sensor_data.Sum_Week_Walk_Out_People_Count = 0; + sts_people_count_sensor_data.Sum_Week_Walk_Around_People_Count = 0; - sts_people_count_sensor_data.Sum_Week_Walk_In_People_Count = 0; - sts_people_count_sensor_data.Sum_Week_Walk_Out_People_Count = 0; - sts_people_count_sensor_data.Sum_Week_Walk_Around_People_Count = 0; + cnt_month++; + if (cnt_month >=12) { + cnt_month =0; + + sts_people_count_sensor_data.Sum_Month_Walk_In_People_Count = 0; + sts_people_count_sensor_data.Sum_Month_Walk_Out_People_Count = 0; + sts_people_count_sensor_data.Sum_Month_Walk_Around_People_Count = 0; + + cnt_year++; + sts_people_count_sensor_data.Sum_Year_Walk_In_People_Count = 0; + sts_people_count_sensor_data.Sum_Year_Walk_Out_People_Count = 0; + sts_people_count_sensor_data.Sum_Year_Walk_Around_People_Count = 0; + } + } } - // reset counter at end of month TODO XXX - if (last_month != this_month) { + uint16_t sts_p2_data_to_nvm[32] ={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_people_count_sensor_data.Sum_Month_Walk_In_People_Count = 0; - sts_people_count_sensor_data.Sum_Month_Walk_Out_People_Count = 0; - sts_people_count_sensor_data.Sum_Month_Walk_Around_People_Count = 0; - } + 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; - if (last_year != this_year) { + 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++] = 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++] = 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++] = 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