From 3ed5130aebfea242721bb08255128fa24706b6a8 Mon Sep 17 00:00:00 2001 From: YunHorn Technology Date: Tue, 13 Aug 2024 19:46:52 +0800 Subject: [PATCH] *** stable *** for P110/P113/P114/P115-(motion mode) --- LoRaWAN/App/lora_app.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 31e7428..8de30b1 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -488,7 +488,7 @@ static LmHandlerParams_t LmHandlerParams = /** * @brief Type of Event to generate application Tx */ -static TxEventType_t EventType = TX_ON_TIMER; //TX_ON_TIMER;//TX_ON_EVENT; +static TxEventType_t EventType = TX_ON_EVENT; //TX_ON_TIMER; //TX_ON_TIMER; /** * @brief Timer to handle the application Tx @@ -648,8 +648,6 @@ void LoRaWAN_Init(void) /* USER CODE BEGIN LoRaWAN_Init_2 */ UTIL_TIMER_Start(&JoinLedTimer); - - /* USER CODE END LoRaWAN_Init_2 */ LmHandlerJoin(ActivationType, ForceRejoin); @@ -689,11 +687,11 @@ void LoRaWAN_Init(void) //UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer); UTIL_TIMER_Create(&YunhornSTSHeartBeatTimer, YUNHORN_STS_HEART_BEAT_CHECK_TIME, UTIL_TIMER_PERIODIC, OnYunhornSTSHeartBeatTimerEvent, NULL); - //UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer); + UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer); UTIL_TIMER_Start(&STSLampBarColorTimer); - UTIL_TIMER_Start(&STSDurationCheckTimer); + //UTIL_TIMER_Start(&STSDurationCheckTimer); #else UTIL_TIMER_Create(&YunhornSTSSamplingCheckTimer, YUNHORN_STS_SAMPLING_CHECK_TIME, UTIL_TIMER_PERIODIC, OnYunhornSTSSamplingCheckTimerEvent, NULL); @@ -1106,7 +1104,7 @@ static void SendTxData(void) } } - if (EventType == TX_ON_TIMER) + if ((EventType == TX_ON_TIMER)||((EventType == TX_ON_EVENT)&&(nextTxIn >0))) { UTIL_TIMER_Stop(&TxTimer); UTIL_TIMER_SetPeriod(&TxTimer, MAX(nextTxIn, TxPeriodicity)); @@ -1759,6 +1757,7 @@ static void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity) /* USER CODE BEGIN OnTxPeriodicityChanged_1 */ /* USER CODE END OnTxPeriodicityChanged_1 */ +#if 0 HeartBeatPeriodicity = periodicity; if (HeartBeatPeriodicity == 0) @@ -1766,15 +1765,15 @@ static void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity) /* Revert to application default periodicity */ HeartBeatPeriodicity = 10*APP_TX_DUTYCYCLE; } - +#endif /* Update timer periodicity */ UTIL_TIMER_Stop(&YunhornSTSHeartBeatTimer); - UTIL_TIMER_SetPeriod(&YunhornSTSHeartBeatTimer, HeartBeatPeriodicity); + UTIL_TIMER_SetPeriod(&YunhornSTSHeartBeatTimer, periodicity); UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer); /* USER CODE BEGIN OnTxPeriodicityChanged_2 */ - APP_LOG(TS_OFF, VLEVEL_H,"**************** HeartBeatPeriodicity = %u (sec)\r\n", HeartBeatPeriodicity/1000 ); + APP_LOG(TS_OFF, VLEVEL_H,"**************** HeartBeatPeriodicity = %u (sec)\r\n", periodicity/1000 ); /* USER CODE END OnTxPeriodicityChanged_2 */ } @@ -2907,8 +2906,13 @@ void OnRestoreSTSCFGContextProcess(void) HeartBeatPeriodicity = samplingperiodicity*1000; #endif #if defined(STS_O7)|| defined(STS_O6) ||defined(STS_O5) - HeartBeatPeriodicity = periodicity; - OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity); + if (STS_LoRa_WAN_Joined !=0) { + HeartBeatPeriodicity = periodicity; + OnYunhornSTSHeartBeatPeriodicityChanged(HeartBeatPeriodicity); + } else { + OnYunhornSTSHeartBeatPeriodicityChanged(APP_TX_DUTYCYCLE); + } + OnYunhornSTSSamplingPeriodicityChanged(sampling); // in m-sec unit #endif @@ -3030,7 +3034,7 @@ void STS_SENSOR_Function_Test_Process(void) uint32_t STS_Get_Date_Time_Stamp(void) { - struct tm localtime; + struct tm localtime={0}; SysTime_t UnixEpoch = SysTimeGet(); UnixEpoch.Seconds -= 18; /*removing leap seconds*/