diff --git a/Core/Inc/main.h b/Core/Inc/main.h index e8c2fa6..94e7d42 100644 --- a/Core/Inc/main.h +++ b/Core/Inc/main.h @@ -107,8 +107,9 @@ void Error_Handler(void); #define MEMS_RESET_Pin GPIO_PIN_4 #define MEMS_RESET_GPIO_Port GPIOB -#define PME_ON HAL_GPIO_WritePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin, GPIO_PIN_SET ) -#define PME_OFF HAL_GPIO_WritePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin, GPIO_PIN_RESET ) +#define PME_ON HAL_GPIO_WritePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin, GPIO_PIN_SET ) +#define PME_OFF HAL_GPIO_WritePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin, GPIO_PIN_RESET ) +#define PME_TOGGLE HAL_GPIO_TogglePin(MEMS_POWER_GPIO_Port, MEMS_POWER_Pin) diff --git a/Core/Inc/utilities_def.h b/Core/Inc/utilities_def.h index bcf7700..75968c2 100644 --- a/Core/Inc/utilities_def.h +++ b/Core/Inc/utilities_def.h @@ -29,7 +29,7 @@ extern "C" { /* Includes ------------------------------------------------------------------*/ #include /* USER CODE BEGIN Includes */ - +#include "yunhorn_sts_prd_conf.h" /* USER CODE END Includes */ /* Exported types ------------------------------------------------------------*/ @@ -80,6 +80,31 @@ typedef enum CFG_SEQ_Task_LoRaStoreContextEvent, CFG_SEQ_Task_LoRaStopJoinEvent, /* USER CODE BEGIN CFG_SEQ_Task_Id_t */ + CFG_SEQ_Task_YunhornSTSEventRFAC, /* RFAC */ + +#ifdef STS_O6 + CFG_SEQ_Task_YunhornSTSEventP1, /* REEDSWITCH, IO */ + CFG_SEQ_Task_YunhornSTSEventP2, /* MOTION */ + CFG_SEQ_Task_YunhornSTSEventP3, /* LAMP BAR LED */ +#endif +#ifdef STS_R1 + CFG_SEQ_Task_YunhornSTSEventP4, /* TOF RANGE */ +#endif +#ifdef STS_P2 + CFG_SEQ_Task_YunhornSTSEventP5, /* TOF IN-OUT */ +#endif +#ifdef STS_R4 + CFG_SEQ_Task_YunhornSTSEventP6, /* SOAP LEVEL */ +#endif +#ifdef STS_E2 + CFG_SEQ_Task_YunhornSTSEventP7, /* IAQ */ +#endif +#ifdef STS_M1 + CFG_SEQ_Task_YunhornSTSEventP8, /* ETR, PULSE COUNT */ +#endif +#ifdef MODBUS_RS485 + STS_YunhornSTSEventPIORS485_Process, /* RS485 MODBUS RTU */ +#endif /* USER CODE END CFG_SEQ_Task_Id_t */ CFG_SEQ_Task_NBR diff --git a/LoRaWAN/App/lora_app.c b/LoRaWAN/App/lora_app.c index c8af269..3b9f290 100644 --- a/LoRaWAN/App/lora_app.c +++ b/LoRaWAN/App/lora_app.c @@ -45,6 +45,8 @@ /* External variables ---------------------------------------------------------*/ /* USER CODE BEGIN EV */ uint8_t outbuf[128]={0x0}; +extern volatile uint8_t *sts_ac_code; +extern volatile uint32_t rfac_timer; /* USER CODE END EV */ /* Private typedef -----------------------------------------------------------*/ @@ -237,6 +239,45 @@ static void OnRxTimerLedEvent(void *context); */ static void OnJoinTimerLedEvent(void *context); +/** + * @brief STS Lamp Bar timer callback function + * @param context ptr of Lamp Bar LED context + */ +static void OnYunhornSTSLampBarColorTimerEvent(void *context); + +/** + * @brief SYS occupancy, door lock, motion duration check timer callback function + * @param context ptr of duration check context + */ +static void OnYunhornSTSDurationCheckTimerEvent(void *context); + +/** + * @brief Yunhorn STS Occupancy RSS WakeUP timer callback function + * @param context ptr of STS RSS WakeUp context + */ + +static void OnYunhornSTSOORSSWakeUpTimerEvent(void *context); + +/** + * @brief Yunhorn STS Heart beat timer callback function + * @param context ptr of context + */ + +static void OnYunhornSTSHeartBeatTimerEvent(void *context); + + +/** + * @brief Yunhorn STS Heart Beat Periodicity Chagne function + * @param duration of periodicty in ms (1/1000 sec) + */ +static void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity); + +/** + * @brief Yunhorn STS AC Code handle Process + * @param void + */ +static void STS_YUNHORN_RFAC_HANDLE_PROCESS(void); + /* USER CODE END PFP */ /* Private variables ---------------------------------------------------------*/ @@ -305,6 +346,7 @@ static UTIL_TIMER_Object_t TxTimer; */ static UTIL_TIMER_Object_t WakeUpScanTimer; +static UTIL_TIMER_Object_t YunhornSTSHeartBeatTimer; /** * @brief Tx Timer period @@ -1107,3 +1149,126 @@ static void OnRestoreContextRequest(void *nvm, uint32_t nvm_size) /* USER CODE END OnRestoreContextRequest_Last */ } +/** + * @brief Yunhorn STS Occupancy RSS WakeUP timer callback function, act as sampling process + * @param context ptr of STS RSS WakeUp context + */ +static void OnYunhornSTSOORSSWakeUpTimerEvent(void *context) +{ +#if 0 + if ((sts_work_mode == STS_RSS_MODE)||(sts_work_mode == STS_DUAL_MODE)||(sts_work_mode == STS_UNI_MODE)) + { + UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventP2), CFG_SEQ_Prio_0); + + if ((sts_rss_result_changed_flag == 1) || (sts_fall_rising_detected_result_changed_flag == 1)) + { + //SendTxData(); + sts_rss_result_changed_flag = 0; + sts_fall_rising_detected_result_changed_flag = 0; + + UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0); + //if ((last_sts_rss_result ==STS_RESULT_NO_MOTION)&& (sts_rss_result==STS_RESULT_MOTION)) + { + //OnSensor3StateChanged(); + } + } + + } + + UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer); +#endif +} + +/** + * @brief Yunhorn STS Sensor Heart Beat Timer callback function + * @param context ptr of STS Sampling Check context + */ +static void OnYunhornSTSHeartBeatTimerEvent(void *context) +{ + //heart_beat_timer = 1; + //UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_LoRaSendOnTxTimerOrButtonEvent), CFG_SEQ_Prio_0); + AppData.Port = YUNHORN_STS_P2_LORA_APP_HTBT_PORT; + AppData.BufferSize = 2; + AppData.Buffer[0]=0x80; + AppData.Buffer[1]=0x63; //TODO XXX change to battery level % + + LmHandlerErrorStatus_t status = LmHandlerSend(&AppData, LmHandlerParams.IsTxConfirmed, false); + if(LORAMAC_HANDLER_SUCCESS == status) APP_LOG(TS_OFF, VLEVEL_L, "\nHeart-beat Sent out \r\n"); + + 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 ++; + } + UTIL_SEQ_SetTask((1 << CFG_SEQ_Task_YunhornSTSEventRFAC), CFG_SEQ_Prio_0); + } + UTIL_TIMER_Start(&YunhornSTSHeartBeatTimer); +} + +/** + * @brief Yunhorn STS Sensor Live Heart Beat Periodicity/interval Change callback function + * @param context ptr of STS Live Heart Beat context + * YL x x x + * */ + +static void OnYunhornSTSHeartBeatPeriodicityChanged(uint32_t periodicity) +{ + /* USER CODE BEGIN OnTxPeriodicityChanged_1 */ + + /* USER CODE END OnTxPeriodicityChanged_1 */ + + if (periodicity == 0) + { + /* Revert to application default periodicity */ + periodicity = 10*APP_TX_DUTYCYCLE; //10*10 000 ms + } + + /* Update timer periodicity */ + + UTIL_TIMER_Stop(&YunhornSTSHeartBeatTimer); + 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", periodicity/1000 ); + /* USER CODE END OnTxPeriodicityChanged_2 */ +} + +/** + * @brief Yunhorn STS Sensor Sampling Periodicity/interval Change callback function + * @param context ptr of STS RSS WakeUp context + */ + +static void OnYunhornSTSSamplingPeriodicityChanged(uint32_t periodicity) +{ + /* USER CODE BEGIN OnTxPeriodicityChanged_1 */ + + /* USER CODE END OnTxPeriodicityChanged_1 */ + + if (periodicity == 0) + { + /* Revert to application default periodicity */ + periodicity = APP_TX_DUTYCYCLE; + } + + /* Update timer periodicity */ + +#if defined(STS_O6)||defined(STS_O7) + UTIL_TIMER_Stop(&YunhornSTSRSSWakeUpTimer); + UTIL_TIMER_SetPeriod(&YunhornSTSRSSWakeUpTimer, periodicity); + UTIL_TIMER_Start(&YunhornSTSRSSWakeUpTimer); + APP_LOG(TS_OFF, VLEVEL_M,"**************** Sampling Timer Periodicity = %u (sec)\r\n", (SamplingPeriodicity/1000) ); +#else +#ifdef STS_E2 + UTIL_TIMER_Stop(&YunhornSTSSamplingCheckTimer); + UTIL_TIMER_SetPeriod(&YunhornSTSSamplingCheckTimer, periodicity); + UTIL_TIMER_Start(&YunhornSTSSamplingCheckTimer); + APP_LOG(TS_OFF, VLEVEL_M,"**************** SamplingPeriodicity = %u (sec)\r\n", (SamplingPeriodicity/1000) ); +#endif +#endif + + /* USER CODE BEGIN OnTxPeriodicityChanged_2 */ + + /* USER CODE END OnTxPeriodicityChanged_2 */ +} diff --git a/STM32CubeIDE/.cproject b/STM32CubeIDE/.cproject index 9930938..7f171cb 100644 --- a/STM32CubeIDE/.cproject +++ b/STM32CubeIDE/.cproject @@ -14,7 +14,7 @@ - +