29 .SensSendInOnePacket = 0,
32 .MemsStoreSensorData = 1,
33 .MemsMaxSensorData = 0,
34 .MemsCurrentCountSensorData = 0,
38 .LoRaRepeatTryConnect = 10,
46 .HWBatteryLevelStatus = 0,
126 uint32_t uid0 = HAL_GetUIDw0();
127 uint32_t uid2 = HAL_GetUIDw2();
128 uint32_t unique = uid0 ^ uid2;
130 devEui[3] = (uint8_t)(unique >> 24);
131 devEui[4] = (uint8_t)(unique >> 16);
132 devEui[5] = (uint8_t)(unique >> 8);
133 devEui[6] = (uint8_t)(unique);
142 const uint8_t def[8] =
143 { 0, 0, 0, 0, 0, 0, 0, 0 };
170 for (uint8_t i = 0; i < len; i++)
173 for (uint8_t bit = 8; bit > 0; --bit)
176 crc = (crc << 1) ^ 0x31;
192 return crc == par->
Crc;
240 return (
_systemParams.SensAvailableSensors & sensorType) != 0;
244#define SYS_WR(inst, member) \
245 writeLog("%03u(%02X) " #member ":%d(%02X)", \
246 (unsigned)((uint8_t*)&((inst).member) - (uint8_t*)&(inst)), \
247 (unsigned)((uint8_t*)&((inst).member) - (uint8_t*)&(inst)), \
248 (int)((inst).member),(int)((inst).member))
251#define SYS_WR_ARR(inst, member, len) \
253 unsigned _off = (unsigned)((uint8_t*)&((inst).member) - (uint8_t*)&(inst)); \
254 char _buf[3*(len)]; \
255 for (unsigned _i = 0; _i < (unsigned)(len); _i++) { \
256 _buf[_i*3+0] = "0123456789ABCDEF"[((inst).member[_i] >> 4) & 0xF]; \
257 _buf[_i*3+1] = "0123456789ABCDEF"[ (inst).member[_i] & 0xF]; \
258 _buf[_i*3+2] = (_i < (unsigned)(len)-1) ? ':' : '\0'; \
260 writeLog("%03u(%02X) " #member ":%s", _off, _off, _buf); \
264#define SYS_WR_STR(inst, member) \
265 writeLog("%03u(%02X) " #member ":%s", \
266 (unsigned)((uint8_t*)&((inst).member) - (uint8_t*)&(inst)), \
267 (unsigned)((uint8_t*)&((inst).member) - (uint8_t*)&(inst)), \
273 writeLog(
"=========== systemParams_Log %s =============", info);
307 writeLog(
"==========================================");
Header of application of the LRWAN Middleware.
#define LORAWAN_ADR_STATE
#define LORAWAN_DEFAULT_DATA_RATE
#define LORAWAN_DEFAULT_CLASS
#define LORAWAN_DEFAULT_TX_POWER
: Header for main.c file. This file contains the common defines of the application.
void Error_Handler(void)
Default error handler called by HAL on unrecoverable errors. Disables interrupts and enters an infini...
void writeLog(const char *format,...)
Format and send a log message over UART (printf-style). Available only when WRITELOG is defined; comp...
void setModeDevice(modeDevice_t mod)
set new device mode
#define CLAMP(val, minVal, maxVal)
Clamp val to the closed interval [minVal, maxVal]. All three arguments are evaluated exactly once via...
void sensors_Retiming()
the System goes to OFF mode - retiming of timer sensor reading
static void OnTimerToOff(void *)
Dummy function - the timer need empty dummy, cannot be NULL
void sensorsBase_StartTimerToOff()
start timer to off the function is called from PWR_EnterStopMode - timer is started
static void getDevEuiFromHardware(uint8_t *devEui)
uint8_t * systemParams_getAppKey()
Return a pointer to the AppKey stored in _systemParams. Used by the LoRaWAN stack to derive session k...
void systemParams_SetCRCSystemParams()
Recalculate and store the CRC in _systemParams.Crc. Call this after modifying any field of _systemPar...
static UTIL_TIMER_Object_t _timerToOff
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 res...
uint8_t * systemParams_getAppEUI()
Return a pointer to the AppEUI (JoinEUI) stored in _systemParams. Used by the LoRaWAN stack during th...
uint8_t * systemParams_getAppDevEUI()
Return a pointer to the DevEUI stored in _systemParams. The DevEUI is auto-generated from the chip UI...
void sensorsBase_StopTimerToOff()
stop timer to off the function is called from PWR_ExitStopMode - the timer value is checked and the P...
uint8_t systemParams_CheckCRC(const systemParams_t *par)
Verify the CRC field of a systemParams_t structure.
void systemParams_Log(const char *info)
Log the current _systemParams fields to the UART debug output.
#define SYS_WR_ARR(inst, member, len)
#define SYS_WR(inst, member)
void systemParams_Correction()
Clamp all RW fields of _systemParams to their valid ranges. Called after loading parameters from NFC ...
#define SYS_WR_STR(inst, member)
static uint32_t _timerTick
void sensorsBase_Init()
Initialization of base sensor data structure.
uint8_t systemParams_IsSensorAvaiable(systemParams_Sensors_t sensorType)
Check whether a particular sensor is enabled in _systemParams.AvailableSensors.
#define SYSTEMPARAMS_MAXLORAWANPORT
Maximum valid LoRaWAN application port number (ports 224–255 are reserved).
#define SYSTEMPARAMS_APPVER00
Application firmware minor version number (plain integer).
#define SYSTEMPARAMS_MINSENSORTIME
Minimum allowed sensor measurement interval in milliseconds (30 seconds).
systemParams_t _systemParams
#define SYSTEMPARAMS_DEFAULTALTITUDE
The default sensor altitue.
#define SZ_SYSTEMPARAMS
Total size in bytes of the systemParams_t structure stored on the NFC tag and send via LoRa - the siz...
#define SYSTEMPARAMS_DEFAULTLORAWANPORT
Default LoRaWAN application port used for sensor uplinks.
#define SYSTEMPARAMS_MINTIME2OFF
Minimum idle time in milliseconds before the device enters OFF (standby) mode. Values below ~10 s are...
#define SYSTEM_APP_KEY
Default LoRaWAN AppKey (16 bytes – overridden via NFC before deployment).
systemParams_Sensors_t
Bitmask of sensor modules that are enabled / available for data collection. Used in systemParams_t....
#define SYSTEM_APP_EUI
Default LoRaWAN JoinEUI / AppEUI (8 bytes, all zeros – overridden via NFC).
#define SYSTEMPARAMS_MINLORAWANPORT
Minimum valid LoRaWAN application port number (port 0 is reserved by the stack).
#define SYSTEM_APP_DevEUI0
First byte of the 3-byte OUI prefix used in the auto-generated DevEUI.
#define SYSTEMPARAMS_DEFAULTSENSORTIME
Default sensor measurement interval in milliseconds (10 minutes).
#define SYSTEM_APP_DevEUI1
Second byte of the 3-byte OUI prefix used in the auto-generated DevEUI.
#define SYSTEMPARAMS_SIGN
4-byte ASCII signature stored at offset 0 of systemParams_t to validate data integrity.
#define SYSTEMPARAMS_APPVER01
Application firmware major version number (plain integer) - check of validity struct together with SY...
#define SYSTEM_APP_DevEUI2
Third byte of the 3-byte OUI prefix used in the auto-generated DevEUI.
#define SYSTEMPARAMS_MAXSENSORTIME
Maximum allowed sensor measurement interval in milliseconds (18 hour).
Secure Element identity and keys.
#define FORMAT32_KEY(...)
System configuration parameters – persisted in NFC EEPROM at address 0. The structure contains all mo...
uint32_t HAL_GetTick(void)
Function prototypes for sys_app.c file.
void GetDevAddr(uint32_t *devAddr)
callback to get the board 32 bits unique ID (LSB)