diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index e71810a..7902ef8 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -570,7 +570,7 @@ static void SendTxData(void) uint8_t batteryLevel = GetBatteryLevel(); sensor_t sensor_data; UTIL_TIMER_Time_t nextTxIn = 0; - sts_people_count_sensor_data_t sts_p2_sensor_data; + sts_people_count_sensor_data_t sts_p2_sensor_data={0x0}; if (LmHandlerIsBusy() == false) { @@ -667,6 +667,8 @@ static void SendTxData(void) AppData.Buffer[i++] = (uint8_t)((sts_p2_sensor_data.Sum_Day_Walk_Around_People_Count>>8) & 0xFF); AppData.Buffer[i++] = (uint8_t)(sts_p2_sensor_data.Sum_Day_Walk_Around_People_Count & 0xFF); + + AppData.Buffer[i++] = (uint8_t)(sts_p2_sensor_data.Count_Valid & 0xFF); #endif AppData.BufferSize = i; #endif /* CAYENNE_LPP */ @@ -787,8 +789,8 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams) AppData.Buffer[0]=0x38; AppData.Buffer[1]=0x38; LmHandlerParams.IsTxConfirmed = true; - int status = LmHandlerSend(&AppData, LmHandlerParams.IsTxConfirmed, false); - LmHandlerParams.IsTxConfirmed = false; + LmHandlerErrorStatus_t status = LmHandlerSend(&AppData, LmHandlerParams.IsTxConfirmed, false); + if (status ==LORAMAC_HANDLER_SUCCESS ) LmHandlerParams.IsTxConfirmed = false; } else { diff --git a/STS/TOF/App/app_tof_peoplecount.c b/STS/TOF/App/app_tof_peoplecount.c index 39bb543..552f859 100644 --- a/STS/TOF/App/app_tof_peoplecount.c +++ b/STS/TOF/App/app_tof_peoplecount.c @@ -13,7 +13,7 @@ /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ 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}; +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}; volatile sts_ppc_cfg_type_t ppc_cfg[3] = { {DOOR_JAM_2000, 8, 2000,0,1600,8,33,DISTANCE_MODE_SHORT,175,247}, @@ -224,6 +224,12 @@ int ProcessPeopleCountingData(int16_t Distance, uint8_t zone, uint8_t RangeStatu void STS_people_count_sensor_Read(sts_people_count_sensor_data_t *sts_p2_sensor_data) { + if (0 == sts_people_count_sensor_data.Count_Valid) + { + sts_p2_sensor_data->Count_Valid = sts_people_count_sensor_data.Count_Valid; + return; + } + 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; @@ -317,6 +323,7 @@ void STS_TOF_VL53LX_PeopleCounting_Process_Start(void* context) //APP_LOG(TS_OFF, VLEVEL_M,"############### TOF VL53LX_ PEOPLE COUNTING SUB-PROCESS \r\n"); { status = sts_tof_vl53lx_peoplecount_start(); + sts_people_count_sensor_data.Count_Valid = (status ==0)? 1:0; //APP_LOG(TS_OFF, VLEVEL_M,"############### SUB-PROCESS running .... \r\n"); } @@ -359,8 +366,13 @@ int sts_tof_vl53lx_peoplecount_init(void) while (sensorState == 0) { status = VL53L1X_BootState(dev, &sensorState); HAL_Delay(2); + wordData ++; + if (wordData > 8000) { + APP_LOG(TS_OFF, VLEVEL_L,"\n\n ***Failed to boot Chip***\n\n\n"); + return status; + } } - APP_LOG(TS_OFF, VLEVEL_L,"Chip booted\n"); + APP_LOG(TS_OFF, VLEVEL_L,"\nChip booted\n\n"); /* Initialize and configure the device according to people counting need */ status = VL53L1X_SensorInit(dev); @@ -386,7 +398,7 @@ int sts_tof_vl53lx_peoplecount_init(void) int sts_tof_vl53lx_peoplecount_start(void) { //uint8_t byteData, sensorState=0; - //uint16_t wordData; + uint16_t wordData=0; uint16_t Distance, Signal; uint8_t RangeStatus; uint8_t dataReady; @@ -397,6 +409,8 @@ int sts_tof_vl53lx_peoplecount_start(void) while (dataReady == 0) { status = VL53L1X_CheckForDataReady(dev, &dataReady); HAL_Delay(1); + wordData++; + if (wordData > 30) return -1; // 50 ms timer, so make this 60% to fail back } dataReady = 0; status += VL53L1X_GetRangeStatus(dev, &RangeStatus); diff --git a/STS/TOF/App/app_tof_peoplecount.h b/STS/TOF/App/app_tof_peoplecount.h index 7ddf790..fd7f49a 100644 --- a/STS/TOF/App/app_tof_peoplecount.h +++ b/STS/TOF/App/app_tof_peoplecount.h @@ -133,6 +133,8 @@ uint32_t Sum_LifeCycle_Walk_Out_People_Count; uint32_t Sum_LifeCycle_Walk_Around_People_Count; + uint8_t Count_Valid; + } sts_people_count_sensor_data_t; void STS_TOF_VL53LX_PeopleCounting_Process_Init(void);