L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
mysensors_base.c File Reference
#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 dependency graph for mysensors_base.c:

Go to the source code of this file.

Macros

#define SYS_WR(inst, member)
#define SYS_WR_ARR(inst, member, len)
#define SYS_WR_STR(inst, member)

Functions

static void OnTimerToOff (void *)
 
  • Dummy function - the timer need empty dummy, cannot be NULL

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.
uint8_t systemParams_CalculateCrc (uint8_t *data, uint8_t len)
 Calculate a CRC-8 checksum (Sensirion polynomial) over a byte buffer. Used to validate sensor I2C response packets as well as the CRC field of systemParams_t.
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).
uint8_t systemParams_IsSensorAvaiable (systemParams_Sensors_t sensorType)
 Check whether a particular sensor is enabled in _systemParams.AvailableSensors.
void systemParams_Log (const char *info)
 Log the current _systemParams fields to the UART debug output.

Variables

systemParams_t _systemParams
int8_t _tryInit = 1
static UTIL_TIMER_Object_t _timerToOff = {}
static uint32_t _timerTick = 0

Macro Definition Documentation

◆ SYS_WR

#define SYS_WR ( inst,
member )
Value:
writeLog("%03u(%02X) " #member ":%d(%02X)", \
(unsigned)((uint8_t*)&((inst).member) - (uint8_t*)&(inst)), \
(unsigned)((uint8_t*)&((inst).member) - (uint8_t*)&(inst)), \
(int)((inst).member),(int)((inst).member))
void writeLog(const char *format,...)
Format and send a log message over UART (printf-style). Available only when WRITELOG is defined; comp...
Definition main.c:97

Definition at line 244 of file mysensors_base.c.

Referenced by systemParams_Log().

◆ SYS_WR_ARR

#define SYS_WR_ARR ( inst,
member,
len )
Value:
do { \
unsigned _off = (unsigned)((uint8_t*)&((inst).member) - (uint8_t*)&(inst)); \
char _buf[3*(len)]; \
for (unsigned _i = 0; _i < (unsigned)(len); _i++) { \
_buf[_i*3+0] = "0123456789ABCDEF"[((inst).member[_i] >> 4) & 0xF]; \
_buf[_i*3+1] = "0123456789ABCDEF"[ (inst).member[_i] & 0xF]; \
_buf[_i*3+2] = (_i < (unsigned)(len)-1) ? ':' : '\0'; \
} \
writeLog("%03u(%02X) " #member ":%s", _off, _off, _buf); \
} while(0)

Definition at line 251 of file mysensors_base.c.

Referenced by systemParams_Log().

◆ SYS_WR_STR

#define SYS_WR_STR ( inst,
member )
Value:
writeLog("%03u(%02X) " #member ":%s", \
(unsigned)((uint8_t*)&((inst).member) - (uint8_t*)&(inst)), \
(unsigned)((uint8_t*)&((inst).member) - (uint8_t*)&(inst)), \
(inst).member)

Definition at line 264 of file mysensors_base.c.

Referenced by systemParams_Log().

Function Documentation

◆ getDevEuiFromHardware()

void getDevEuiFromHardware ( uint8_t * devEui)
static

Definition at line 117 of file mysensors_base.c.

References SYSTEM_APP_DevEUI0, SYSTEM_APP_DevEUI1, SYSTEM_APP_DevEUI2, and systemParams_CalculateCrc().

Referenced by systemParams_getAppDevEUI().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnTimerToOff()

void OnTimerToOff ( void * )
static

  • Dummy function - the timer need empty dummy, cannot be NULL

Definition at line 69 of file mysensors_base.c.

Referenced by sensorsBase_StartTimerToOff().

Here is the caller graph for this function:

◆ sensorsBase_Init()

void sensorsBase_Init ( )

Initialization of base sensor data structure.

Definition at line 195 of file mysensors_base.c.

References Error_Handler(), systemParams_getAppDevEUI(), systemParams_SetCRCSystemParams(), SZ_SYSTEMPARAMS, and writeLog().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sensorsBase_StartTimerToOff()

void sensorsBase_StartTimerToOff ( )

start timer to off the function is called from PWR_EnterStopMode - timer is started

Definition at line 206 of file mysensors_base.c.

References _timerTick, _timerToOff, HAL_GetTick(), OnTimerToOff(), and SYSTEMPARAMS_MINTIME2OFF.

Referenced by PWR_EnterStopMode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sensorsBase_StopTimerToOff()

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 214 of file mysensors_base.c.

References _timerTick, _timerToOff, HAL_GetTick(), MODEDEVICE_OFF, sensors_Retiming(), setModeDevice(), and SYSTEMPARAMS_MINTIME2OFF.

Referenced by PWR_ExitStopMode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ systemParams_CalculateCrc()

uint8_t systemParams_CalculateCrc ( uint8_t * data,
uint8_t len )

Calculate a CRC-8 checksum (Sensirion polynomial) over a byte buffer. Used to validate sensor I2C response packets as well as the CRC field of systemParams_t.

Parameters
dataPointer to the data buffer.
lenNumber of bytes to include in the calculation.
Returns
Computed CRC-8 byte.

Definition at line 167 of file mysensors_base.c.

Referenced by getDevEuiFromHardware(), scd41_IsDataReady(), scd41_Read(), scd41_WriteWithCRC(), sps30_GetAutoCleanInterval(), sps30_On(), sps30_Read(), sps30_SetAutoCleanInterval(), systemParams_CheckCRC(), and systemParams_SetCRCSystemParams().

Here is the caller graph for this function:

◆ systemParams_CheckCRC()

uint8_t systemParams_CheckCRC ( const systemParams_t * par)

Verify the CRC field of a systemParams_t structure.

Parameters
parPointer to the systemParams_t to check.
Return values
1– CRC is valid (structure is intact).
0– CRC mismatch (structure is corrupt or uninitialised).

Definition at line 189 of file mysensors_base.c.

References systemParams_t::Crc, and systemParams_CalculateCrc().

Referenced by nfc_ReadSystemParamsToBck().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ systemParams_Correction()

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).

Definition at line 226 of file mysensors_base.c.

References _systemParams, CLAMP, SYSTEMPARAMS_MAXLORAWANPORT, SYSTEMPARAMS_MAXSENSORTIME, SYSTEMPARAMS_MINLORAWANPORT, and SYSTEMPARAMS_MINSENSORTIME.

Referenced by nfc_Init().

Here is the caller graph for this function:

◆ systemParams_getAppDevEUI()

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.

Returns
Pointer to the 8-byte DevEUI array inside _systemParams.

Definition at line 140 of file mysensors_base.c.

References _systemParams, GetDevAddr(), and getDevEuiFromHardware().

Referenced by LoRaWAN_Init(), and sensorsBase_Init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ systemParams_getAppEUI()

uint8_t * systemParams_getAppEUI ( )

Return a pointer to the AppEUI (JoinEUI) stored in _systemParams. Used by the LoRaWAN stack during the OTAA join procedure.

Returns
Pointer to the 8-byte AppEUI array inside _systemParams.

Definition at line 154 of file mysensors_base.c.

References _systemParams.

Referenced by LoRaWAN_Init().

Here is the caller graph for this function:

◆ systemParams_getAppKey()

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.

Returns
Pointer to the 16-byte AppKey array inside _systemParams.

Definition at line 159 of file mysensors_base.c.

References _systemParams.

Referenced by LoRaWAN_Init().

Here is the caller graph for this function:

◆ systemParams_IsSensorAvaiable()

uint8_t systemParams_IsSensorAvaiable ( systemParams_Sensors_t sensorType)

Check whether a particular sensor is enabled in _systemParams.AvailableSensors.

Parameters
sensorTypeOne of the systemParams_Sensors_t bitmask values.
Return values
1– sensor is marked as available and should be polled.
0– sensor is disabled in the configuration.

Definition at line 238 of file mysensors_base.c.

References _systemParams.

Referenced by sensors_Init(), sensors_OnOff(), sensors_Read(), and sensors_Service().

Here is the caller graph for this function:

◆ systemParams_Log()

void systemParams_Log ( const char * info)

Log the current _systemParams fields to the UART debug output.

Parameters
infoOptional prefix string printed before the dump (e.g. "LOAD" or "SAVE").

Definition at line 271 of file mysensors_base.c.

References _systemParams, SYS_WR, SYS_WR_ARR, SYS_WR_STR, and writeLog().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ systemParams_SetCRCSystemParams()

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 184 of file mysensors_base.c.

References _systemParams, and systemParams_CalculateCrc().

Referenced by nfc_WriteSystemParams(), and sensorsBase_Init().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ _systemParams

◆ _timerTick

uint32_t _timerTick = 0
static

Definition at line 64 of file mysensors_base.c.

Referenced by sensorsBase_StartTimerToOff(), and sensorsBase_StopTimerToOff().

◆ _timerToOff

UTIL_TIMER_Object_t _timerToOff = {}
static

Definition at line 63 of file mysensors_base.c.

Referenced by sensorsBase_StartTimerToOff(), and sensorsBase_StopTimerToOff().

◆ _tryInit

int8_t _tryInit = 1

Flag used by xxx_Is() calls; when set to 1, the Is function attempts to (re-)initialise the sensor

Definition at line 60 of file mysensors_base.c.

Referenced by nfc_FactoryReset(), nfc_ReadSystemParams(), nfc_ReadSystemParamsToBck(), nfc_WriteSystemParams(), and sensors_Read().