diff --git a/Core/Inc/sys_conf.h b/Core/Inc/sys_conf.h index 891bd1a..3611754 100644 --- a/Core/Inc/sys_conf.h +++ b/Core/Inc/sys_conf.h @@ -47,12 +47,12 @@ extern "C" { /** * @brief Verbose level for all trace logs */ -#define VERBOSE_LEVEL VLEVEL_H +#define VERBOSE_LEVEL VLEVEL_M /** * @brief Enable trace logs */ -#define APP_LOG_ENABLED 0 +#define APP_LOG_ENABLED 1 /** * @brief Activate monitoring (probes) of some internal RF signals for debug purpose diff --git a/Core/Inc/yunhorn_sts_prd_conf.h b/Core/Inc/yunhorn_sts_prd_conf.h index 252bc81..519d72d 100644 --- a/Core/Inc/yunhorn_sts_prd_conf.h +++ b/Core/Inc/yunhorn_sts_prd_conf.h @@ -211,9 +211,10 @@ #endif /* YUNHORN_STS_R0_ENABLED */ #ifdef YUNHORN_STS_M7_ENABLED +#include "yunhorn_sts_motion_sensor.h" #define MajorVer 23U -#define MinorVer 02U -#define SubMinorVer 23U +#define MinorVer 10U +#define SubMinorVer 14U #define FirmwareVersion 3U #define STS_NVM_CFG_SIZE 32U #define STS_CFG_PCFG_SIZE 28U @@ -225,7 +226,7 @@ #define YUNHORN_STS_M7_CFG_CMD_SIZE 9U #define YUNHORN_STS_MAX_NVM_CFG_SIZE 64U #define YUNHORN_STS_AC_CODE_SIZE 20U - #include "yunhorn_sts_motion_sensor.h" + #define YUNHORN_STS_M7_LORA_APP_DATA_PORT 20U #define YUNHORN_STS_M7_LORA_APP_HTBT_PORT 21U #define YUNHORN_STS_M7_USER_APP_CTRL_PORT 2U diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index aed9bee..752931f 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -411,7 +411,7 @@ void LoRaWAN_Init(void) /* USER CODE END LoRaWAN_Init_LV */ /* USER CODE BEGIN LoRaWAN_Init_1 */ - APP_LOG(TS_OFF, VLEVEL_H, "\r\n\n\n##### YUNHORN_STS_FW:%d SWV%d HWV:%d MTM:%d.%d R:%d.%d.%d####\r\n\n\n", + APP_LOG(TS_OFF, VLEVEL_M, "\r\n\n\n##### YUNHORN_STS_FW:%d SWV%d HWV:%d MTM:%d.%d R:%d.%d.%d####\r\n\n\n", FirmwareVersion, sts_version, sts_hardware_ver, sts_mtmcode1,sts_mtmcode2, MajorVer, MinorVer, SubMinorVer); /* Get LoRaWAN APP version*/ APP_LOG(TS_OFF, VLEVEL_M, "APPLICATION_VERSION: V%X.%X.%X\r\n", @@ -490,15 +490,16 @@ void LoRaWAN_Init(void) } /* USER CODE BEGIN LoRaWAN_Init_Last */ - STS_REBOOT_CONFIG_Init(); - UTIL_TIMER_Create(&YunhornSTSHeartBeatTimer, HeartBeatPeriodicity, UTIL_TIMER_ONESHOT, OnYunhornSTSHeartBeatTimerEvent, NULL); - UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventRFAC), UTIL_SEQ_RFU, STS_YunhornSTSEventRFAC_Process); + UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP1), UTIL_SEQ_RFU, STS_MOTION_SENSOR_WakeUp_Process); UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventP2), UTIL_SEQ_RFU, STS_SENSOR_Function_Test_Process); + UTIL_SEQ_RegTask((1 << CFG_SEQ_Task_YunhornSTSEventRFAC), UTIL_SEQ_RFU, STS_YunhornSTSEventRFAC_Process); - - UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer); + STS_REBOOT_CONFIG_Init(); + + //UTIL_TIMER_Create(&YunhornSTSHeartBeatTimer, HeartBeatPeriodicity, UTIL_TIMER_ONESHOT, OnYunhornSTSHeartBeatTimerEvent, NULL); + //UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer); /* USER CODE END LoRaWAN_Init_Last */ @@ -1089,8 +1090,6 @@ static void SendTxData(void) STS_M7_SensorDataTypeDef m7_data; UTIL_TIMER_Time_t nextTxIn = 0; - //if (LmHandlerIsBusy() == false) - { uint32_t i = 0; //EnvSensors_Read(&sensor_data); @@ -1103,9 +1102,10 @@ static void SendTxData(void) if (heart_beat_timer != 0U) { heart_beat_timer = 0U; - AppData.Port = sts_sendhtbtport; //LORAWAN_USER_APP_PORT; + AppData.Port = LORAWAN_USER_HTBT_PORT; //LORAWAN_USER_APP_PORT; AppData.Buffer[i++] = (uint8_t)(99*batteryLevel/254); //#01 - } else + } + if (sensor_data_ready !=0U) { sensor_data_ready = 0U; AppData.Buffer[i++] = (uint8_t)(0xFF & sts_mtmcode1); //mtmcode1; //#01 @@ -1148,8 +1148,8 @@ static void SendTxData(void) UTIL_TIMER_Stop(&JoinLedTimer); HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET); /* LED_RED */ } - //if (i>1) - //{ + if (i>1) + { status = LmHandlerSend(&AppData, LmHandlerParams.IsTxConfirmed, false); if (LORAMAC_HANDLER_SUCCESS == status) { @@ -1163,9 +1163,7 @@ static void SendTxData(void) APP_LOG(TS_ON, VLEVEL_H, "Next Tx in : ~%d second(s)\r\n", (nextTxIn / 1000)); } } - //} - - } // if (LmHandlerIsBusy() == false) + } if (EventType == TX_ON_TIMER) { @@ -1630,17 +1628,22 @@ void STS_REBOOT_CONFIG_Init(void) void OnRestoreSTSCFGContextProcess(void) { - uint32_t periodicity = (sts_cfg_nvm.periodicity); //TxPeriodicty interval + uint32_t periodicity_length = (sts_cfg_nvm.periodicity); //TxPeriodicty interval if ((char)sts_cfg_nvm.unit =='M') { - periodicity *= 60; + periodicity_length *= 60; } else if ((char) sts_cfg_nvm.unit =='H') { - periodicity *= 3600; + periodicity_length *= 3600; } else if ((char) sts_cfg_nvm.unit =='S') { - periodicity *= 1; + periodicity_length *= 1; } - periodicity = (periodicity > 10)? periodicity : 10; // in seconds unit - TxPeriodicity= periodicity*1000; // to ms - OnTxPeriodicityChanged(TxPeriodicity); // in msec unit + periodicity_length = (periodicity_length > 10)? periodicity_length : 10; // in seconds unit + + if (sts_lorawan_joined) + { + OnTxPeriodicityChanged(periodicity_length*1000); // in msec unit + } else { + OnTxPeriodicityChanged(TxPeriodicity); // 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/LoRaWAN/App/lora_app.h b/LoRaWAN/App/lora_app.h index 0cdb252..4969b8f 100644 --- a/LoRaWAN/App/lora_app.h +++ b/LoRaWAN/App/lora_app.h @@ -55,9 +55,10 @@ extern "C" { * LoRaWAN User application port * @note do not use 224. It is reserved for certification */ -#define LORAWAN_USER_APP_PORT sts_senddataport -#define LORAWAN_USER_APP_CTRL_PORT sts_appctrlport -#define LORAWAN_USER_APP_CTRL_REPLY_PORT sts_appctrl_reply_port +#define LORAWAN_USER_APP_PORT 20 +#define LORAWAN_USER_HTBT_PORT 21 +#define LORAWAN_USER_APP_CTRL_PORT 2 +#define LORAWAN_USER_APP_CTRL_REPLY_PORT 1 /*! * LoRaWAN Switch class application port * @note do not use 224. It is reserved for certification