|
L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
|
#include "mysensors_base.h"#include "mysensors.h"#include "main.h"#include "se-identity.h"#include "lora_app.h"#include "sys_app.h"#include "utils/mydefs.h"#include "utils/utils.h"Go to the source code of this file.
Macros | |
| #define | SYS_REF(i, f) |
| #define | SYS_WR(inst, member) |
| #define | SYS_WR_ARR(inst, member, len) |
| #define | SYS_WR_STR(inst, member) |
| #define | SYS_WR_TIME(inst, member) |
Functions | |
| static int8_t | systemParamsRef_Get (uint8_t inx) |
| |
| static void | OnTimerToOff (void *) |
| |
| static void | getDevEuiFromHardware (uint8_t *devEui) |
| uint8_t * | systemParams_getAppDevEUI () |
| Return a pointer to the DevEUI stored in _systemParams. The DevEUI is auto-generated from the chip UID during initialisation and is read-only from the phone app's perspective. | |
| uint8_t * | systemParams_getAppEUI () |
| Return a pointer to the AppEUI (JoinEUI) stored in _systemParams. Used by the LoRaWAN stack during the OTAA join procedure. | |
| uint8_t * | systemParams_getAppKey () |
| Return a pointer to the AppKey stored in _systemParams. Used by the LoRaWAN stack to derive session keys during OTAA join. | |
| void | systemParams_SetCRCSystemParams () |
| Recalculate and store the CRC in _systemParams.Crc. Call this after modifying any field of _systemParams before writing the structure to the NFC EEPROM. | |
| uint8_t | systemParams_CheckCRC (const systemParams_t *par) |
| Verify the CRC field of a systemParams_t structure. | |
| void | sensorsBase_Init () |
| Initialization of base sensor data structure. | |
| void | sensorsBase_StartTimerToOff () |
| start timer to off the function is called from PWR_EnterStopMode - timer is started | |
| void | sensorsBase_StopTimerToOff () |
| stop timer to off the function is called from PWR_ExitStopMode - the timer value is checked and the PWR_ExitStopMode was invoked from this times, system goes to OFF mode setModeDevice(MODEDEVICE_OFF) | |
| void | systemParams_Correction () |
| Clamp all RW fields of _systemParams to their valid ranges, called after loading parameters from NFC to ensure no out-of-range values are used (e.g. port numbers, timeouts, data rates). The DEVEui cannot be changed - problem of rewrite of DEVUi accross devices. | |
| uint8_t | systemParams_IsSensorAvaiable (systemParams_Sensors_t sensorType) |
| Check whether a particular sensor is enabled in _systemParams.AvailableSensors. | |
| uint8_t | systemParams_CorrectSystemTime () |
| setting/correction of the system time from _systemParams.MqttTime, if contains valid UNIX time(low uint32_t). MCU is reading MqttTime from NFC and compares with current system time - SysTimeGet The system time is changed(SysTimeSet) if is less that time in _systemParams.MqttTime | |
| void | systemParams_SetFromPart (const uint8_t *buffer, uint8_t bufSize) |
| The setting of systemParams_t from server dowlink. The buffer contains the combination for setting of value . | |
| void | sensorsBase_MeasureNFCInit () |
| the default initialization of _measureNFC struct | |
| void | sensorsBase_SetCRCMeasureNFC () |
| Recalculate and store the CRC in _measureNFC.Crc. Call this after modifying any field of _measureNFC before writing the structure to the NFC EEPROM. | |
| uint8_t | sensorsBase_CheckCRCMeasureNFC () |
| Verify the CRC field of a _measureNFC structure. | |
| static void | _systemParams_unixToDateTime (uint64_t t, uint16_t *year, uint8_t *month, uint8_t *day, uint8_t *hour, uint8_t *min, uint8_t *sec) |
| Convert a Unix UTC timestamp (seconds since 1970-01-01 00:00:00) to broken-down calendar fields. | |
| void | systemParams_Log (const char *info) |
| Log the current _systemParams fields to the UART debug output. | |
Variables | |
| systemParams_t | _systemParams |
| systemParams_t | _systemParamsBck = {} |
| systemParamsRef_t | _systemParamRef [] |
| |
| int8_t | _tryInit = 1 |
| measureNFC_t | _measureNFC = {} |
| uint8_t | _batPercLevel = 0 |
| static UTIL_TIMER_Object_t | _timerToOff = {} |
| static uint32_t | _timerTick = 0 |
| #define SYS_REF | ( | i, | |
| f ) |
Definition at line 92 of file mysensors_base.c.
| #define SYS_WR | ( | inst, | |
| member ) |
Definition at line 396 of file mysensors_base.c.
Referenced by systemParams_Log().
| #define SYS_WR_ARR | ( | inst, | |
| member, | |||
| len ) |
Definition at line 403 of file mysensors_base.c.
Referenced by systemParams_Log().
| #define SYS_WR_STR | ( | inst, | |
| member ) |
Definition at line 416 of file mysensors_base.c.
Referenced by systemParams_Log().
| #define SYS_WR_TIME | ( | inst, | |
| member ) |
Definition at line 423 of file mysensors_base.c.
Referenced by systemParams_Log().
|
static |
Convert a Unix UTC timestamp (seconds since 1970-01-01 00:00:00) to broken-down calendar fields.
Uses Howard Hinnant's pure-integer civil-from-days Gregorian algorithm (no libc time functions required), correct for any 64-bit Unix timestamp including leap years and century / 400-year boundaries.
| t | Seconds since the Unix epoch (UTC). |
| year | Output: full calendar year (e.g. 2026). |
| month | Output: month 1–12. |
| day | Output: day-of-month 1–31. |
| hour | Output: hours 0–23. |
| min | Output: minutes 0–59. |
| sec | Output: seconds 0–59. |
Definition at line 460 of file mysensors_base.c.
|
static |
Definition at line 165 of file mysensors_base.c.
References calculateCrc(), SYSTEM_APP_DevEUI0, SYSTEM_APP_DevEUI1, and SYSTEM_APP_DevEUI2.
Referenced by systemParams_Correction(), and systemParams_getAppDevEUI().
|
static |
Definition at line 161 of file mysensors_base.c.
Referenced by sensorsBase_StartTimerToOff().
| uint8_t sensorsBase_CheckCRCMeasureNFC | ( | ) |
Verify the CRC field of a _measureNFC structure.
| 1 | – CRC is valid (structure is intact). |
| 0 | – CRC mismatch (structure is corrupt or uninitialised). |
Definition at line 377 of file mysensors_base.c.
References _measureNFC, calculateCrc(), CLAMP, and sensorsBase_SetCRCMeasureNFC().
Referenced by nfc_Init(), and nfc_WriteMeasureData().
| void sensorsBase_Init | ( | ) |
Initialization of base sensor data structure.
Definition at line 225 of file mysensors_base.c.
References Error_Handler(), MEASUEREDATANFC_EEPROMSIZE, MEASUREDATANFC_ADDR, sensorsBase_MeasureNFCInit(), systemParams_getAppDevEUI(), systemParams_SetCRCSystemParams(), SZ_MEASURENFC, SZ_SYSTEMPARAMS, and writeLog().
Referenced by main().
| void sensorsBase_MeasureNFCInit | ( | ) |
the default initialization of _measureNFC struct
Definition at line 362 of file mysensors_base.c.
References _measureNFC, MEASUEREDATANFC_EEPROMSIZE, MEASUREDATANFC_ADDR, and sensorsBase_SetCRCMeasureNFC().
Referenced by nfc_Init(), nfc_WriteMeasureData(), and sensorsBase_Init().
| void sensorsBase_SetCRCMeasureNFC | ( | ) |
Recalculate and store the CRC in _measureNFC.Crc.
Call this after modifying any field of _measureNFC before writing the structure to the NFC EEPROM.
Definition at line 372 of file mysensors_base.c.
References _measureNFC, and calculateCrc().
Referenced by nfc_WriteMeasureNFC(), sensorsBase_CheckCRCMeasureNFC(), and sensorsBase_MeasureNFCInit().
| void sensorsBase_StartTimerToOff | ( | ) |
start timer to off the function is called from PWR_EnterStopMode - timer is started
Definition at line 270 of file mysensors_base.c.
References _timerTick, _timerToOff, HAL_GetTick(), OnTimerToOff(), and SYSTEMPARAMS_MINTIME2OFF.
Referenced by PWR_EnterStopMode().
| void sensorsBase_StopTimerToOff | ( | ) |
stop timer to off the function is called from PWR_ExitStopMode - the timer value is checked and the PWR_ExitStopMode was invoked from this times, system goes to OFF mode setModeDevice(MODEDEVICE_OFF)
Definition at line 278 of file mysensors_base.c.
References _timerTick, _timerToOff, HAL_GetTick(), MODEDEVICE_OFF, setModeDevice(), and SYSTEMPARAMS_MINTIME2OFF.
Referenced by PWR_ExitStopMode().
| uint8_t systemParams_CheckCRC | ( | const systemParams_t * | par | ) |
Verify the CRC field of a systemParams_t structure.
| par | Pointer to the systemParams_t to check. |
| 1 | – CRC is valid (structure is intact). |
| 0 | – CRC mismatch (structure is corrupt or uninitialised). |
Definition at line 219 of file mysensors_base.c.
References calculateCrc(), and systemParams_t::Crc.
Referenced by nfc_ReadSystemParamsToBck(), and OnLoRaWANRxData().
| void systemParams_Correction | ( | ) |
Clamp all RW fields of _systemParams to their valid ranges, called after loading parameters from NFC to ensure no out-of-range values are used (e.g. port numbers, timeouts, data rates).
The DEVEui cannot be changed - problem of rewrite of DEVUi accross devices.
Definition at line 290 of file mysensors_base.c.
References _systemParams, CLAMP, GetDevAddr(), getDevEuiFromHardware(), SYSTEMPARAMS_MAXSENSORTIME, and SYSTEMPARAMS_MINSENSORTIME.
Referenced by nfc_Init().
| uint8_t systemParams_CorrectSystemTime | ( | ) |
setting/correction of the system time from _systemParams.MqttTime, if contains valid UNIX time(low uint32_t). MCU is reading MqttTime from NFC and compares with current system time - SysTimeGet The system time is changed(SysTimeSet) if is less that time in _systemParams.MqttTime
| 0 | - no changes |
| 1 | - the system time has been update |
| 2 | - the _systemParams.MqttTime |
Definition at line 310 of file mysensors_base.c.
References _systemParams.
Referenced by main(), and OnTimeSynchronized().
| uint8_t * systemParams_getAppDevEUI | ( | ) |
Return a pointer to the DevEUI stored in _systemParams. The DevEUI is auto-generated from the chip UID during initialisation and is read-only from the phone app's perspective.
Definition at line 189 of file mysensors_base.c.
References _systemParams, GetDevAddr(), and getDevEuiFromHardware().
Referenced by LoRaWAN_Init(), and sensorsBase_Init().
| uint8_t * systemParams_getAppEUI | ( | ) |
Return a pointer to the AppEUI (JoinEUI) stored in _systemParams. Used by the LoRaWAN stack during the OTAA join procedure.
Definition at line 203 of file mysensors_base.c.
References _systemParams.
Referenced by LoRaWAN_Init().
| uint8_t * systemParams_getAppKey | ( | ) |
Return a pointer to the AppKey stored in _systemParams. Used by the LoRaWAN stack to derive session keys during OTAA join.
Definition at line 208 of file mysensors_base.c.
References _systemParams.
Referenced by LoRaWAN_Init().
| uint8_t systemParams_IsSensorAvaiable | ( | systemParams_Sensors_t | sensorType | ) |
Check whether a particular sensor is enabled in _systemParams.AvailableSensors.
| sensorType | One of the systemParams_Sensors_t bitmask values. |
| 1 | – sensor is marked as available and should be polled. |
| 0 | – sensor is disabled in the configuration. |
Definition at line 305 of file mysensors_base.c.
References _systemParams.
Referenced by sensors_Init(), sensors_OnOff(), sensors_Read(), and sensors_Service().
| void systemParams_Log | ( | const char * | info | ) |
Log the current _systemParams fields to the UART debug output.
| info | Optional prefix string printed before the dump (e.g. "LOAD" or "SAVE"). |
Definition at line 489 of file mysensors_base.c.
References _measureNFC, _systemParamRef, _systemParams, COUNT_OF, SYS_WR, SYS_WR_ARR, SYS_WR_STR, SYS_WR_TIME, and writeLog().
Referenced by main().
| void systemParams_SetCRCSystemParams | ( | ) |
Recalculate and store the CRC in _systemParams.Crc. Call this after modifying any field of _systemParams before writing the structure to the NFC EEPROM.
Definition at line 214 of file mysensors_base.c.
References _systemParams, and calculateCrc().
Referenced by nfc_WriteSystemParams(), OnLoRaWANRxData(), sensorsBase_Init(), and systemParams_SetFromPart().
| void systemParams_SetFromPart | ( | const uint8_t * | buffer, |
| uint8_t | bufSize ) |
The setting of systemParams_t from server dowlink. The buffer contains the combination for setting of value
.
Definition at line 329 of file mysensors_base.c.
References _systemParamRef, _systemParams, systemParams_SetCRCSystemParams(), systemParamsRef_Get(), and writeLog().
Referenced by OnLoRaWANRxData().
|
static |
| index | into _systemParamRef where is found inx param |
| -1 | - in case, if specified index not exist |
Definition at line 148 of file mysensors_base.c.
References _systemParamRef, and COUNT_OF.
Referenced by systemParams_SetFromPart().
| uint8_t _batPercLevel = 0 |
level of battery percentage on start
Definition at line 136 of file mysensors_base.c.
Referenced by main(), and sensors_CayennelFromBckData().
| measureNFC_t _measureNFC = {} |
Global measure NFC block for saving of measure data
Definition at line 135 of file mysensors_base.c.
Referenced by nfc_ReadMeasureNFC(), nfc_WriteMeasureData(), nfc_WriteMeasureNFC(), sensorsBase_CheckCRCMeasureNFC(), sensorsBase_MeasureNFCInit(), sensorsBase_SetCRCMeasureNFC(), and systemParams_Log().
| systemParamsRef_t _systemParamRef[] |
Definition at line 98 of file mysensors_base.c.
Referenced by systemParams_Log(), systemParams_SetFromPart(), and systemParamsRef_Get().
| systemParams_t _systemParams |
Global system parameters read from / written to the NFC tag EEPROM
Definition at line 21 of file mysensors_base.c.
Referenced by bar_bmp585_Read(), checkResetRestart(), main(), mems_ReadFromSystemParams(), mems_WriteToSystemParams(), myLoraWan_LastDataSend(), myloraWan_MeasureFinish(), myLoraWan_ResetDataDefault(), nfc_Init(), nfc_ReadSystemParams(), nfc_WriteSystemParams(), OnLoRaWanConnected(), OnLoRaWANRxData(), sensors_Retiming(), systemParams_Correction(), systemParams_CorrectSystemTime(), systemParams_getAppDevEUI(), systemParams_getAppEUI(), systemParams_getAppKey(), systemParams_IsSensorAvaiable(), systemParams_Log(), systemParams_SetCRCSystemParams(), systemParams_SetFromPart(), systemParams_SetLoRaWanParams(), and tasksensors_OnTimeout().
| systemParams_t _systemParamsBck = {} |
Global system parameters backup buffer for NFC reading and and for sending via downlink to server
Definition at line 85 of file mysensors_base.c.
Referenced by nfc_Init(), nfc_ReadSystemParams(), nfc_ReadSystemParamsToBck(), and OnLoRaWANRxData().
|
static |
Definition at line 141 of file mysensors_base.c.
Referenced by sensorsBase_StartTimerToOff(), and sensorsBase_StopTimerToOff().
|
static |
Definition at line 140 of file mysensors_base.c.
Referenced by sensorsBase_StartTimerToOff(), and sensorsBase_StopTimerToOff().
| int8_t _tryInit = 1 |
Flag used by xxx_Is() calls; when set to 1, the Is function attempts to (re-)initialize the sensor
Definition at line 134 of file mysensors_base.c.
Referenced by nfc_FactoryReset(), nfc_ReadMeasureNFC(), nfc_ReadSystemParams(), nfc_ReadSystemParamsToBck(), nfc_WriteMeasureData(), nfc_WriteMeasureNFC(), nfc_WriteSystemParams(), and sensors_Read().