wip good send tx, heart -beat, before reboot config

This commit is contained in:
Yunhorn 2024-09-19 10:55:02 +08:00
parent 36f82d08c2
commit 1e3c7505fc
2 changed files with 30 additions and 8 deletions

View File

@ -471,22 +471,22 @@ void LoRaWAN_Init(void)
/* Init Info table used by LmHandler*/ /* Init Info table used by LmHandler*/
LoraInfo_Init(); LoraInfo_Init();
APP_LOG(TS_OFF, VLEVEL_M, "\n start 1\n");
/* Init the Lora Stack*/ /* Init the Lora Stack*/
LmHandlerInit(&LmHandlerCallbacks, APP_VERSION); LmHandlerInit(&LmHandlerCallbacks, APP_VERSION);
LmHandlerConfigure(&LmHandlerParams); LmHandlerConfigure(&LmHandlerParams);
APP_LOG(TS_OFF, VLEVEL_M, "\n start 2\n");
/* USER CODE BEGIN LoRaWAN_Init_2 */ /* USER CODE BEGIN LoRaWAN_Init_2 */
UTIL_TIMER_Start(&JoinLedTimer); UTIL_TIMER_Start(&JoinLedTimer);
/* USER CODE END LoRaWAN_Init_2 */ /* USER CODE END LoRaWAN_Init_2 */
APP_LOG(TS_OFF, VLEVEL_M, "\n start 3\n");
LmHandlerJoin(ActivationType, ForceRejoin); LmHandlerJoin(ActivationType, ForceRejoin);
APP_LOG(TS_OFF, VLEVEL_M, "\n start 3 FORCE JOIN\n");
if (EventType == TX_ON_TIMER) if (EventType == TX_ON_TIMER)
{ {
APP_LOG(TS_OFF, VLEVEL_M, "\n start 4\n");
/* send every time timer elapses */ /* send every time timer elapses */
UTIL_TIMER_Create(&TxTimer, TxPeriodicity, UTIL_TIMER_ONESHOT, OnTxTimerEvent, NULL); UTIL_TIMER_Create(&TxTimer, TxPeriodicity, UTIL_TIMER_ONESHOT, OnTxTimerEvent, NULL);
UTIL_TIMER_Start(&TxTimer); UTIL_TIMER_Start(&TxTimer);
@ -494,7 +494,7 @@ void LoRaWAN_Init(void)
else else
{ {
/* USER CODE BEGIN LoRaWAN_Init_3 */ /* USER CODE BEGIN LoRaWAN_Init_3 */
APP_LOG(TS_OFF, VLEVEL_M, "\n start 5\n");
/* USER CODE END LoRaWAN_Init_3 */ /* USER CODE END LoRaWAN_Init_3 */
} }
@ -516,7 +516,7 @@ void LoRaWAN_Init(void)
UTIL_TIMER_Create(&YunhornSTSWakeUpScanTimer, STS_TOFScanPeriod_msec, UTIL_TIMER_PERIODIC, (void*)OnYunhornSTSWakeUpScanTimerEvent, NULL); UTIL_TIMER_Create(&YunhornSTSWakeUpScanTimer, STS_TOFScanPeriod_msec, UTIL_TIMER_PERIODIC, (void*)OnYunhornSTSWakeUpScanTimerEvent, NULL);
UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer); UTIL_TIMER_Start(&YunhornSTSWakeUpScanTimer);
UTIL_TIMER_Create(&YunhornSTSHeartBeatTimer, STS_HeartBeatTimerPeriod_sec, UTIL_TIMER_PERIODIC, OnYunhornSTSHeartBeatTimerEvent, NULL); UTIL_TIMER_Create(&YunhornSTSHeartBeatTimer, 1000*STS_HeartBeatTimerPeriod_sec, UTIL_TIMER_PERIODIC, OnYunhornSTSHeartBeatTimerEvent, NULL);
UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer); UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer);
/* USER CODE END LoRaWAN_Init_Last */ /* USER CODE END LoRaWAN_Init_Last */
@ -1217,6 +1217,26 @@ static void OnYunhornSTSOORSSWakeUpTimerEvent(void *context)
static void OnYunhornSTSHeartBeatTimerEvent(void *context) static void OnYunhornSTSHeartBeatTimerEvent(void *context)
{ {
// UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventRFAC), CFG_SEQ_Prio_0);
uint8_t appDataPort, appBufferSize, appDataBuffer[32];
appDataPort = YUNHORN_STS_P2_LORA_APP_HTBT_PORT;
appBufferSize = 2;
appDataBuffer[0]=0x80;
appDataBuffer[1]=0x63; //TODO XXX change to battery level %
STS_SENSOR_Upload_Message(appDataPort, appBufferSize, (uint8_t*)appDataBuffer);
if ((sts_ac_code[0]==0x0) && (sts_ac_code[19]==0x0)) /* simple validation of non-empty ac code */
{
/* RFAC Challenge */
if (rfac_timer < (STS_BURN_IN_RFAC+3)) {
rfac_timer ++;
}
//STS_YunhornSTSEventRFAC_Process();
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventRFAC), CFG_SEQ_Prio_0);
}
UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer);
} }

View File

@ -105,7 +105,7 @@ volatile uint8_t sts_work_mode=4;
volatile uint32_t rfac_timer=0; volatile uint32_t rfac_timer=0;
volatile uint16_t sts_sensor_install_height=3000; volatile uint16_t sts_sensor_install_height=3000;
volatile uint8_t sensor_data_ready=0; volatile uint8_t sensor_data_ready=0;
volatile uint32_t STS_TOFScanPeriod_msec=50, STS_TxPeriod_sec=10, STS_HeartBeatTimerPeriod_sec=120; volatile uint32_t STS_TOFScanPeriod_msec=50, STS_TxPeriod_sec=10, STS_HeartBeatTimerPeriod_sec=60;
static uint8_t outbuf[128]={0x0}; static uint8_t outbuf[128]={0x0};
extern volatile hmac_result_t hmac_result; extern volatile hmac_result_t hmac_result;
extern uint16_t sensor_id; extern uint16_t sensor_id;
@ -1706,6 +1706,7 @@ void OnYunhornSTSOORSSWakeUpTimerEvent(void *context)
*/ */
void OnYunhornSTSHeartBeatTimerEvent(void *context) void OnYunhornSTSHeartBeatTimerEvent(void *context)
{ {
#if 0
uint8_t appDataPort, appBufferSize, appDataBuffer[32]; uint8_t appDataPort, appBufferSize, appDataBuffer[32];
appDataPort = YUNHORN_STS_P2_LORA_APP_HTBT_PORT; appDataPort = YUNHORN_STS_P2_LORA_APP_HTBT_PORT;
appBufferSize = 2; appBufferSize = 2;
@ -1724,6 +1725,7 @@ void OnYunhornSTSHeartBeatTimerEvent(void *context)
UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventRFAC), CFG_SEQ_Prio_0); UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventRFAC), CFG_SEQ_Prio_0);
} }
UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer); UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer);
#endif
} }
/** /**