diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index 439e1b5..ff9e86b 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -471,22 +471,22 @@ void LoRaWAN_Init(void) /* Init Info table used by LmHandler*/ LoraInfo_Init(); - APP_LOG(TS_OFF, VLEVEL_M, "\n start 1\n"); + /* Init the Lora Stack*/ LmHandlerInit(&LmHandlerCallbacks, APP_VERSION); LmHandlerConfigure(&LmHandlerParams); - APP_LOG(TS_OFF, VLEVEL_M, "\n start 2\n"); + /* USER CODE BEGIN LoRaWAN_Init_2 */ UTIL_TIMER_Start(&JoinLedTimer); /* USER CODE END LoRaWAN_Init_2 */ - APP_LOG(TS_OFF, VLEVEL_M, "\n start 3\n"); + LmHandlerJoin(ActivationType, ForceRejoin); - APP_LOG(TS_OFF, VLEVEL_M, "\n start 3 FORCE JOIN\n"); + if (EventType == TX_ON_TIMER) { - APP_LOG(TS_OFF, VLEVEL_M, "\n start 4\n"); + /* send every time timer elapses */ UTIL_TIMER_Create(&TxTimer, TxPeriodicity, UTIL_TIMER_ONESHOT, OnTxTimerEvent, NULL); UTIL_TIMER_Start(&TxTimer); @@ -494,7 +494,7 @@ void LoRaWAN_Init(void) else { /* USER CODE BEGIN LoRaWAN_Init_3 */ - APP_LOG(TS_OFF, VLEVEL_M, "\n start 5\n"); + /* 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_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); /* USER CODE END LoRaWAN_Init_Last */ @@ -1217,6 +1217,26 @@ static void OnYunhornSTSOORSSWakeUpTimerEvent(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); } diff --git a/STS/Core/Src/yunhorn_sts_process.c b/STS/Core/Src/yunhorn_sts_process.c index 8c37e44..24a3182 100644 --- a/STS/Core/Src/yunhorn_sts_process.c +++ b/STS/Core/Src/yunhorn_sts_process.c @@ -105,7 +105,7 @@ volatile uint8_t sts_work_mode=4; volatile uint32_t rfac_timer=0; volatile uint16_t sts_sensor_install_height=3000; 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}; extern volatile hmac_result_t hmac_result; extern uint16_t sensor_id; @@ -1706,6 +1706,7 @@ void OnYunhornSTSOORSSWakeUpTimerEvent(void *context) */ void OnYunhornSTSHeartBeatTimerEvent(void *context) { +#if 0 uint8_t appDataPort, appBufferSize, appDataBuffer[32]; appDataPort = YUNHORN_STS_P2_LORA_APP_HTBT_PORT; appBufferSize = 2; @@ -1724,6 +1725,7 @@ void OnYunhornSTSHeartBeatTimerEvent(void *context) UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventRFAC), CFG_SEQ_Prio_0); } UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer); +#endif } /**