From b2c4ee3eb816d9d38d4277f91941be5a41d43f00 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Thu, 2 Nov 2023 12:20:44 +0800 Subject: [PATCH] revised for ROCTEC R5, TxPeriodicty to 10 sec, reduced TOF change detection logic --- Core/Inc/yunhorn_sts_prd_conf.h | 4 ++-- LoRaWAN/App/lora_app.c | 33 ++++++++++++++++++--------------- TOF/App/app_tof.c | 4 ++++ TOF/App/app_tof_vl53l0x_range.c | 4 ++-- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Core/Inc/yunhorn_sts_prd_conf.h b/Core/Inc/yunhorn_sts_prd_conf.h index 34bf021..a073508 100644 --- a/Core/Inc/yunhorn_sts_prd_conf.h +++ b/Core/Inc/yunhorn_sts_prd_conf.h @@ -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 diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 66257d9..ef3cebf 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -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') { diff --git a/TOF/App/app_tof.c b/TOF/App/app_tof.c index ace19d9..cbd931f 100644 --- a/TOF/App/app_tof.c +++ b/TOF/App/app_tof.c @@ -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; } diff --git a/TOF/App/app_tof_vl53l0x_range.c b/TOF/App/app_tof_vl53l0x_range.c index fe1ee66..cf060a9 100644 --- a/TOF/App/app_tof_vl53l0x_range.c +++ b/TOF/App/app_tof_vl53l0x_range.c @@ -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; }