revised for ROCTEC R5, TxPeriodicty to 10 sec, reduced TOF change

detection logic
This commit is contained in:
Yunhorn 2023-11-02 12:20:44 +08:00
parent fdb7fddf61
commit b2c4ee3eb8
4 changed files with 26 additions and 19 deletions

View File

@ -231,8 +231,8 @@
#define MajorVer 23U
#define MinorVer 10U
#define SubMinorVer 28U
#define MinorVer 11U
#define SubMinorVer 02U
#define FirmwareVersion 3U
#define YUNHORN_STS_MAX_NVM_CFG_SIZE 64U
#define YUNHORN_STS_AC_CODE_SIZE 20U

View File

@ -56,7 +56,7 @@ extern volatile uint8_t sts_soap_level_state;
extern volatile uint8_t ToF_EventDetected;
extern volatile int sts_tof_distance_data[MAX_TOF_COUNT];
volatile uint32_t SamplingPeriodicity = 1000; //unit ms
volatile uint32_t HeartBeatPeriodicity = 60000; //unit ms
volatile uint32_t HeartBeatPeriodicity = 120000; //unit ms
volatile uint8_t STS_LoRa_WAN_Joined = 0;
volatile uint8_t heart_beat_timer =0;
@ -112,7 +112,8 @@ volatile sts_cfg_nvm_t sts_cfg_nvm = {
0x02, //occupancy over time threshold *10 minutes
// ******************* ABOVE 4 bytes
// below 20 bytes AC
{0xFF,0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,0xFF, 0xFF,0xFF,0xFF,0xFF,0xFF}
{0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0, 0x0,0x0,0x0,0x0,0x0}
};
@ -643,9 +644,11 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
} else {
#ifdef LED_ONBOARD
LED_ON;
HAL_Delay(20);
LED_OFF;
#endif
}
#endif
@ -823,7 +826,7 @@ static void SendTxData(void)
AppData.Buffer[i++] = (uint8_t)(r0_data.battery_Pct); //#05
#endif
if (heart_beat_timer != 0)
if (heart_beat_timer != 0U)
{
heart_beat_timer = 0U;
AppData.Port = LORAWAN_USER_HTBT_PORT; //LORAWAN_USER_APP_PORT+1;
@ -832,9 +835,6 @@ static void SendTxData(void)
AppData.Buffer[i++] = (uint8_t)(r0_data.battery_Pct);
#endif
APP_LOG(TS_ON, VLEVEL_H, "\r\n------------ Heart-Beat ------------- \r\n ------------------\r\nDistance0 = %d mm, \r\nDistance1 = %d mm,\r\nDistance2 = %d mm, \r\nVBAT=%d\r\n",
r0_data.distance_mm,r0_data.distance1_mm,r0_data.distance2_mm, r0_data.battery_Pct);
} else if ((upload_message_timer !=0U)||(sensor_data_ready!=0U)) //sensor_data_ready for manual push button-1 trigger)
{
sensor_data_ready =0;
@ -857,9 +857,6 @@ static void SendTxData(void)
AppData.Buffer[i++] = (uint8_t)(r0_data.battery_mV)&0xff; //#13
#endif
APP_LOG(TS_ON, VLEVEL_H, "\r\n------------ Heart-Beat ------------- \r\n ------------------\r\nDistance0 = %d mm, \r\nDistance1 = %d mm,\r\nDistance2 = %d mm, \r\nVBAT=%d\r\n",
r0_data.distance_mm,r0_data.distance1_mm,r0_data.distance2_mm, r0_data.battery_Pct);
}
AppData.BufferSize = (sts_service_mask >1?0:i);
@ -991,8 +988,8 @@ static void OnJoinRequest(LmHandlerJoinParams_t *joinParams)
STS_LoRa_WAN_Joined = (uint8_t) joinParams->Mode;
//STS_REBOOT_CONFIG_Init();
OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity);
OnTxPeriodicityChanged(TxPeriodicity);
//OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity);
//OnTxPeriodicityChanged(TxPeriodicity);
APP_LOG(TS_OFF, VLEVEL_L,"\r\n STS_LoRa_WAN_Joined = %s \r\n", (STS_LoRa_WAN_Joined == 1)?"ABP":"OTAA");
}
else
@ -1426,7 +1423,7 @@ static void OnYunhornSTSHeartBeatTimerEvent(void *context)
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0);
UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer);
if ((STS_LoRa_WAN_Joined ) && (sts_ac_code[0]==0xFF))
if ((STS_LoRa_WAN_Joined ) && (sts_ac_code[0]==0x0))
{
/* RFAC Challenge */
if (rfac_timer < (STS_BURN_IN_RFAC+3)) {
@ -1977,9 +1974,9 @@ void STS_SENSOR_Upload_Message(uint8_t appDataPort, uint8_t appBufferSize, char
void OnStoreSTSCFGContextRequest(void)
{
/* USER CODE BEGIN OnStoreContextRequest_1 */
uint8_t nvm_store_value[YUNHORN_STS_MAX_NVM_CFG_SIZE]={0x0};
uint8_t i=0,j=0,nvm_store_value[YUNHORN_STS_MAX_NVM_CFG_SIZE]={0x0};
#if (defined(YUNHORN_STS_O6_ENABLED) || defined(YUNHORN_STS_R0_ENABLED))
#if (defined(YUNHORN_STS_O6_ENABLED) || defined(YUNHORN_STS_R0_ENABLED) || defined(YUNHORN_STS_R5_ENABLED))
sts_cfg_nvm.length = STS_NVM_CFG_SIZE;
nvm_store_value[i++] = sts_cfg_nvm.mtmcode1;
nvm_store_value[i++] = sts_cfg_nvm.mtmcode2;
@ -2097,7 +2094,13 @@ void OnRestoreSTSCFGContextProcess(void)
}
periodicity = (periodicity > 10)? periodicity : 10; // in seconds unit
TxPeriodicity= periodicity*1000; // to ms
OnTxPeriodicityChanged(TxPeriodicity); // in msec unit
if (sts_ac_code[0] !=0 )
{ // ensure it's not in production yet
OnTxPeriodicityChanged(TxPeriodicity); // in msec unit
} else
{
OnTxPeriodicityChanged(APP_TX_DUTYCYCLE); // in msec unit
}
uint32_t samplingperiodicity = (sts_cfg_nvm.sampling); //Heart-beat or Sampling interval
if ((char)sts_cfg_nvm.s_unit =='M') {

View File

@ -126,9 +126,13 @@ void MX_TOF_Process(void)
}
void STS_R0_SENSOR_Read(STS_R0_SensorDataTypeDef *r0_data)
{
r0_data->distance_mm = sts_tof_distance_data[0];
r0_data->distance1_mm = sts_tof_distance_data[1];
r0_data->distance2_mm = sts_tof_distance_data[2];
#ifdef ROCTEC_R5
r0_data->distance1_mm = sts_tof_distance_data[0]+sts_tof_distance_data[1]+sts_tof_distance_data[2];
#endif
sensor_data_ready = 1;
}

View File

@ -413,8 +413,8 @@ void STS_TOF_VL53L0X_Range_Process(void)
} // nSensorPresent >0
// reset for next ranging
nDevMask = 0;
nSensorPresent = 0;
//nDevMask = 0;
//nSensorPresent = 0;
}