diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 3f95890..2cfa67f 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -541,7 +541,7 @@ void LoRaWAN_Init(void) #if defined(STS_P2)||defined(STS_T6)||defined(L8) - // UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP5), UTIL_SEQ_RFU, STS_YunhornSTSEventP5_Process); + UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP5), UTIL_SEQ_RFU, STS_YunhornSTSEventP5_Process); #endif @@ -561,7 +561,7 @@ void LoRaWAN_Init(void) UTIL_TIMER_Start(&STSLampBarColorTimer); #elif defined(STS_P2) - UTIL_TIMER_Create(&YunhornSTSWakeUpScanTimer, STS_TOFScanPeriod_msec, UTIL_TIMER_PERIODIC, (void*)STS_TOF_VL53LX_PeopleCounting_Process_Start, NULL); + UTIL_TIMER_Create(&YunhornSTSWakeUpScanTimer, 2*STS_TOFScanPeriod_msec, UTIL_TIMER_PERIODIC, (void*)STS_TOF_VL53LX_PeopleCounting_Process_Start, NULL); UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer); #endif @@ -1034,7 +1034,7 @@ static void SendTxData(void) #ifdef STS_P2 #ifdef VL53LX // VL53L1X - AppData.Buffer[i++] = (uint8_t) 15; //sum of below + AppData.Buffer[i++] = (uint8_t) 6; //sum of below AppData.Buffer[i++] = (uint8_t)((sts_p2_sensor_data.Walk_In_People_Count>>8) & 0xFF); AppData.Buffer[i++] = (uint8_t)(sts_p2_sensor_data.Walk_In_People_Count & 0xFF); @@ -1044,6 +1044,7 @@ static void SendTxData(void) AppData.Buffer[i++] = (uint8_t)((sts_p2_sensor_data.Walk_Around_People_Count>>8) & 0xFF); AppData.Buffer[i++] = (uint8_t)(sts_p2_sensor_data.Walk_Around_People_Count & 0xFF); #endif // VL53L1X +#if 0 #ifdef VL53LX // VL53L1X AppData.Buffer[i++] = (uint8_t)((sts_p2_sensor_data.Count_Period) & 0xFF); AppData.Buffer[i++] = (uint8_t)((sts_p2_sensor_data.Count_Period_Unit) & 0xFF); @@ -1059,7 +1060,7 @@ static void SendTxData(void) AppData.Buffer[i++] = (uint8_t)(sts_p2_sensor_data.Count_Valid & 0xFF); #endif // VL53L1X - +#endif #endif //STS_P2 #if defined(STS_T6) @@ -1228,9 +1229,10 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams) } AppData.Port = 1; AppData.BufferSize = 16; - UTIL_MEM_cpy_8((uint8_t*)AppData.Buffer, (uint8_t *)"YUNHORN168", 10); - UTIL_MEM_cpy_8((uint8_t*)AppData.Buffer+10, (uint8_t *)(uint8_t*)YUNHORN_STS_PRD_STRING, sizeof(YUNHORN_STS_PRD_STRING)); - AppData.BufferSize = sizeof(YUNHORN_STS_PRD_STRING)+10; + // UTIL_MEM_cpy_8((uint8_t*)AppData.Buffer, (uint8_t *)"YUNHORN168", 10); + // UTIL_MEM_cpy_8((uint8_t*)AppData.Buffer+10, (uint8_t *)(uint8_t*)YUNHORN_STS_PRD_STRING, sizeof(YUNHORN_STS_PRD_STRING)); + UTIL_MEM_cpy_8((uint8_t*)AppData.Buffer, (uint8_t*)YUNHORN_STS_PRD_STRING, sizeof(YUNHORN_STS_PRD_STRING)); + AppData.BufferSize = sizeof(YUNHORN_STS_PRD_STRING); LmHandlerParams.IsTxConfirmed = true; LmHandlerErrorStatus_t status = LmHandlerSend(&AppData, LmHandlerParams.IsTxConfirmed, false); if (status ==LORAMAC_HANDLER_SUCCESS ) LmHandlerParams.IsTxConfirmed = false; diff --git a/STM32CubeIDE/Release/WLE5CC_NODE_STS.elf b/STM32CubeIDE/Release/WLE5CC_NODE_STS.elf index 9fe4dd0..c606595 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_sensors.h b/STS/Core/Inc/yunhorn_sts_sensors.h index 11605e3..ab663b0 100644 --- a/STS/Core/Inc/yunhorn_sts_sensors.h +++ b/STS/Core/Inc/yunhorn_sts_sensors.h @@ -291,7 +291,10 @@ void STS_SENSOR_Function_Test_Process(void); int STS_SENSOR_Distance_Test_Process(void); void STS_PRESENCE_SENSOR_Function_Test_Process(uint8_t *self_test_result, uint8_t count); void STS_PRESENCE_SENSOR_Distance_Measure_Process(void); -void ppc_cfg_parameter_update(void); + +void ppc_cfg_parameter_update(void); // STS_T6 +void sts_p2_ppc_cfg_parameter_update(void); // STS_P2 + /* USER CODE BEGIN Private defines */ /* In this example TIM2 input clock (TIM2CLK) is set to APB1 clock (PCLK1), diff --git a/STS/Core/Src/yunhorn_sts_process.c b/STS/Core/Src/yunhorn_sts_process.c index 2d4509d..270f928 100644 --- a/STS/Core/Src/yunhorn_sts_process.c +++ b/STS/Core/Src/yunhorn_sts_process.c @@ -685,20 +685,26 @@ 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]; - } + case 15: + if ((parse_buffer[CFG_CMD4]=='P') && ((parse_buffer[CFG_CMD5]-0x30)<=6)) // P 1 1 'P' + { + for (uint8_t i=0; i<10; i++) { + sts_cfg_nvm.p[i] = (uint8_t)(parse_buffer[CFG_CMD5+i]-0x30); + } + // P 1 1 P 6 DistArraySize MaxDist MinDist ThreDist ROWSPADS TimeBudget + // p 1 1 p 6 8 40(x10cm) 10(x10cm) 16(x10cm) 8 3/5/10/20/50(x10ms) - 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]; + ppc_cfg[parse_buffer[CFG_CMD5]-0x30].distance_array_size = (uint8_t)(parse_buffer[CFG_CMD5+1]-0x30); + ppc_cfg[parse_buffer[CFG_CMD5]-0x30].max_distance = (uint8_t)((parse_buffer[CFG_CMD5+2]-0x30)*10 + (parse_buffer[CFG_CMD5+3]-0x30)); + ppc_cfg[parse_buffer[CFG_CMD5]-0x30].min_distance = (uint8_t)((parse_buffer[CFG_CMD5+4]-0x30)*10 + (parse_buffer[CFG_CMD5+5]-0x30)); + ppc_cfg[parse_buffer[CFG_CMD5]-0x30].dist_threshold = (uint8_t)((parse_buffer[CFG_CMD5+6]-0x30)*10 + (parse_buffer[CFG_CMD5+7]-0x30)); + ppc_cfg[parse_buffer[CFG_CMD5]-0x30].rows_of_SPADS = (uint8_t)(parse_buffer[CFG_CMD5+8]-0x30); + ppc_cfg[parse_buffer[CFG_CMD5]-0x30].timing_budget = (uint8_t)((parse_buffer[CFG_CMD5+9]-0x30)*100 + (parse_buffer[CFG_CMD5+10]-0x30)*10); + + APP_LOG(TS_OFF, VLEVEL_L, "\r\nDistArray=%d Max=%d, Min=%d Threshold=%d SPADS=%d TimingBudget=%d \r\n", + ppc_cfg[DOOR_JAM_NOW].distance_array_size, ppc_cfg[DOOR_JAM_NOW].max_distance, ppc_cfg[DOOR_JAM_NOW].min_distance, ppc_cfg[DOOR_JAM_NOW].dist_threshold, + ppc_cfg[DOOR_JAM_NOW].rows_of_SPADS, ppc_cfg[DOOR_JAM_NOW].timing_budget); + } break; default: @@ -1097,6 +1103,7 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s case 'S': /* "YZS": Self Function Testing */ STS_SENSOR_Function_Test_Process(); + #if defined(STS_T6) ppc_cfg_parameter_update(); sts_cfg_nvm.sensor_install_height_in_10cm = sts_sensor_install_height/100; //in 10 cm, say 4500mm=450cm=45 dm @@ -1104,6 +1111,13 @@ void USER_APP_AUTO_RESPONDER_Parse(uint8_t *parse_buffer, uint8_t parse_buffer_s APP_LOG(TS_OFF, VLEVEL_M, "\n STS CFG NVM -> SENSOR INSTALL HEIGHT STORED = %d dm(10cm)\n", sts_cfg_nvm.sensor_install_height_in_10cm); OnStoreSTSCFGContextRequest(); +#elif defined(STS_P2) + sts_p2_ppc_cfg_parameter_update(); + sts_cfg_nvm.sensor_install_height_in_10cm = sts_sensor_install_height/100; //in 10 cm, say 4500mm=450cm=45 dm + sts_cfg_nvm.sts_door_jam_profile = sts_door_jam_profile; + APP_LOG(TS_OFF, VLEVEL_M, "\n STS CFG NVM -> SENSOR INSTALL HEIGHT STORED = %d dm(10cm)\n", sts_cfg_nvm.sensor_install_height_in_10cm); + OnStoreSTSCFGContextRequest(); + #endif break; @@ -1889,6 +1903,26 @@ void ppc_cfg_parameter_update(void) APP_LOG(TS_OFF, VLEVEL_M, "\r\n Door Jam profile updated to %d with Max/Min/Threshold=%d:%d:%d \r\n", sts_door_jam_profile, ppc_cfg[DOOR_JAM_NOW].max_distance,ppc_cfg[DOOR_JAM_NOW].min_distance, ppc_cfg[DOOR_JAM_NOW].dist_threshold); } + +#ifdef STS_P2 +void sts_p2_ppc_cfg_parameter_update(void) +{ + ppc_cfg[DOOR_JAM_NOW].profile_name = DOOR_JAM_NOW; + ppc_cfg[DOOR_JAM_NOW].distance_array_size = 8; + ppc_cfg[DOOR_JAM_NOW].max_distance = sts_sensor_install_height; + ppc_cfg[DOOR_JAM_NOW].min_distance = MAX((sts_sensor_install_height*0.2), 200); // 200 mm for toilet seat height + ppc_cfg[DOOR_JAM_NOW].dist_threshold = MAX((sts_sensor_install_height - 500),sts_sensor_install_height*0.8); + ppc_cfg[DOOR_JAM_NOW].rows_of_SPADS = ROWS_OF_SPADS; + ppc_cfg[DOOR_JAM_NOW].timing_budget = 100; // TIMING_BUDGET, in ms possible values [15, 20, 33, 50, 100, 200, 500] + ppc_cfg[DOOR_JAM_NOW].distance_mode = 2; /* 1=short, 2=long, DISTANCE_MODE */ + ppc_cfg[DOOR_JAM_NOW].front_zone_center = FRONT_ZONE_CENTER; + ppc_cfg[DOOR_JAM_NOW].back_zone_center = BACK_ZONE_CENTER; + sts_door_jam_profile = DOOR_JAM_NOW; + + APP_LOG(TS_OFF, VLEVEL_M, "\r\n STS_P2 Door Jam profile updated to %d with Max/Min/Threshold=%d:%d:%d \r\n", + sts_door_jam_profile, ppc_cfg[DOOR_JAM_NOW].max_distance,ppc_cfg[DOOR_JAM_NOW].min_distance, ppc_cfg[DOOR_JAM_NOW].dist_threshold); +} +#endif void STS_SENSOR_MEMS_Get_ID(uint16_t *devID) { #ifdef VL53LX diff --git a/STS/TOF/App/app_tof_peoplecount.c b/STS/TOF/App/app_tof_peoplecount.c index 991e890..04cf701 100644 --- a/STS/TOF/App/app_tof_peoplecount.c +++ b/STS/TOF/App/app_tof_peoplecount.c @@ -299,7 +299,7 @@ int ProcessPeopleCountingData(int16_t Distance, uint8_t zone, uint8_t RangeStatu MinDistance = Distances[zone][i]; } } - //APP_LOG(TS_OFF, VLEVEL_M, "\r\n MinDistance & dist_threshold ---%d %d", MinDistance,ppc_cfg[sts_distance_mode].dist_threshold); + // APP_LOG(TS_OFF, VLEVEL_M, "\r\n Distance=%d Min. & threshold ---%d %d", Distance, MinDistance,ppc_cfg[sts_distance_mode].dist_threshold); if (MinDistance < ppc_cfg[sts_door_jam_profile].dist_threshold) { // Someone is in ! CurrentZoneStatus = SOMEONE; @@ -376,7 +376,7 @@ int ProcessPeopleCountingData(int16_t Distance, uint8_t zone, uint8_t RangeStatu // reset the table filling size in case an entry or exit just found DistancesTableSize[0] = 0; DistancesTableSize[1] = 0; - APP_LOG(TS_OFF, VLEVEL_L,"Walk In, People Count=%d\n", PeopleCount); + APP_LOG(TS_OFF, VLEVEL_L,"Walk In, People Count=%d Head/Min =%d Range=%d\n", PeopleCount, MinDistance, Distance); sts_people_count_sensor_data.Walk_In_People_Count ++; sts_people_count_number_changed = 1; LED_RED_OFF; @@ -394,13 +394,12 @@ int ProcessPeopleCountingData(int16_t Distance, uint8_t zone, uint8_t RangeStatu // reset the table filling size in case an entry or exit just found DistancesTableSize[0] = 0; DistancesTableSize[1] = 0; - APP_LOG(TS_OFF, VLEVEL_L,"Walk Out, People Count=%d\n", PeopleCount); + APP_LOG(TS_OFF, VLEVEL_L,"Walk Out, People Count=%d Head/Min =%d Range=%d\n", PeopleCount, MinDistance, Distance); sts_people_count_sensor_data.Walk_Out_People_Count ++; //LED1_ON; //TODO XXX, CHANGE TO (LED_IN_OFF && LED_OUT_ON); //LED1_TOGGLE; - + LED_GREEN_OFF; LED_RED_ON; - LED_GREEN_OFF; HAL_Delay(50); LED_RED_OFF; sts_people_count_number_changed = 1; @@ -409,18 +408,18 @@ int ProcessPeopleCountingData(int16_t Distance, uint8_t zone, uint8_t RangeStatu DistancesTableSize[0] = 0; DistancesTableSize[1] = 0; - APP_LOG(TS_OFF, VLEVEL_L,"Walk Around ie. Wrong path\n"); + APP_LOG(TS_OFF, VLEVEL_L,"Walk Around ie. Wrong path, Head Distance=%d \n", MinDistance); sts_people_count_sensor_data.Walk_Around_People_Count ++; LED_RED_ON; LED_GREEN_ON; - HAL_Delay(50); + HAL_Delay(30); LED_GREEN_OFF; LED_RED_OFF; - HAL_Delay(50); + HAL_Delay(30); LED_RED_ON; LED_GREEN_ON; - HAL_Delay(50); + HAL_Delay(30); LED_GREEN_OFF; LED_RED_OFF; } @@ -645,24 +644,24 @@ void STS_TOF_VL53LX_PeopleCounting_Process_Init(void) uint16_t log_in_nvm[32]; 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[2]; - sts_people_count_sensor_data.Sum_Day_Walk_Around_People_Count = (uint16_t)log_in_nvm[4]; + 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]; - sts_people_count_sensor_data.Sum_Week_Walk_In_People_Count = (uint16_t)log_in_nvm[6]; - sts_people_count_sensor_data.Sum_Week_Walk_Out_People_Count = (uint16_t)log_in_nvm[8]; - sts_people_count_sensor_data.Sum_Week_Walk_Around_People_Count = (uint16_t)log_in_nvm[10]; + 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_Month_Walk_In_People_Count = (uint16_t)log_in_nvm[12]; - sts_people_count_sensor_data.Sum_Month_Walk_Out_People_Count = (uint16_t)log_in_nvm[14]; - sts_people_count_sensor_data.Sum_Month_Walk_Around_People_Count = (uint16_t)log_in_nvm[16]; + 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_Year_Walk_In_People_Count = (uint16_t)log_in_nvm[18]; - sts_people_count_sensor_data.Sum_Year_Walk_Out_People_Count = (uint16_t)log_in_nvm[20]; - sts_people_count_sensor_data.Sum_Year_Walk_Around_People_Count = (uint16_t)log_in_nvm[22]; + 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_LifeCycle_Walk_In_People_Count = (uint16_t)log_in_nvm[24]; - sts_people_count_sensor_data.Sum_LifeCycle_Walk_Out_People_Count = (uint16_t)log_in_nvm[26]; - sts_people_count_sensor_data.Sum_LifeCycle_Walk_Around_People_Count = (uint16_t)log_in_nvm[28]; + 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]; } @@ -937,7 +936,7 @@ int sts_tof_vl53lx_peoplecount_init(void) wordData = 0; while (sensorState == 0) { status = VL53L1X_BootState(dev, &sensorState); - HAL_Delay(2); + HAL_Delay(1); wordData ++; if (wordData > 8000) { APP_LOG(TS_OFF, VLEVEL_L,"\n\n ***Failed to boot Chip***\n\n\n"); @@ -1035,6 +1034,7 @@ int sts_tof_vl53lx_peoplecount_start(void) Distance = ppc_cfg[sts_door_jam_profile].max_distance; //MAX_DISTANCE; #endif // inject the new ranged distance in the people counting algorithm + //APP_LOG(TS_OFF, VLEVEL_L,"%d,%d,%d\n", Zone, Distance, Signal); PplCounter = ProcessPeopleCountingData(Distance, Zone, RangeStatus); //printf("\nPplCounter =%d \n\r", PplCounter); //sprintf(DisplayStr, "%4d", PplCounter); // only use for special EVK with display