30 .SensSendInOnePacket = 0,
37#if defined(SENSOR_BAR_BMP585) || defined(SENSOR_BAR_ILS22QS)
40#if defined(SENSOR_AMB_TSL2591)
43#if defined(SENSOR_SCD41)
46#if defined(SENSOR_SPS30)
51 .MemsStoreSensorData = 1,
52 .MemsMaxSensorData = 0,
53 .MemsCurrentCountSensorData = 0,
57 .LoRaRepeatTryConnect = 2,
65 .HWBatteryLevelStatus = 0,
79 .IntBatTimeSendUNIX = 0,
90#define SYS_REF(i,f) {.Inx = i, .Size = sizeof(_systemParams.f), .Addr = ((uint8_t*)&_systemParams.f - (uint8_t*)&_systemParams), .Name = #f}
92#define SYS_REF(i,f) {.Inx = i, .Size = sizeof(_systemParams.f), .Addr = ((uint8_t*)&_systemParams.f - (uint8_t*)&_systemParams)}
102 SYS_REF(2, SensTimeoutMeasure),
104 SYS_REF(4, SensSendInOnePacket),
107 SYS_REF(7, MemsStoreSensorData),
109 SYS_REF(9, MemsCurrentCountSensorData),
111 SYS_REF(11, LoRaRepeatTryConnect),
112 SYS_REF(12, LoRaAdaptiveDataRate),
117 SYS_REF(17, HWBatteryLevelStatus),
128 SYS_REF(28, IntBatTimeSendUNIX),
150 int8_t retInx = -1, i;
174 uint32_t uid0 = HAL_GetUIDw0();
175 uint32_t uid2 = HAL_GetUIDw2();
176 uint32_t unique = uid0 ^ uid2;
178 devEui[3] = (uint8_t)(unique >> 24);
179 devEui[4] = (uint8_t)(unique >> 16);
180 devEui[5] = (uint8_t)(unique >> 8);
181 devEui[6] = (uint8_t)(unique);
191 const uint8_t def[8] =
192 { 0, 0, 0, 0, 0, 0, 0, 0 };
221 uint8_t crc =
calculateCrc((uint8_t*)par,
sizeof(*par) -
sizeof(par->
Crc));
222 return crc == par->
Crc;
259 if (eepromDataSize > 255)
261 writeLog(
"The NFC EEPROM size:%d is too big for BYTE(uint8_t) handling in measureNFC_t", eepromDataSize);
313 SysTime_t sysTime = SysTimeGet(), mqttTime = {.Seconds =
_systemParams.MqttTime & 0xFFFFFFFF, .SubSeconds = 0};
315 if (mqttTime.Seconds >= sysTime.Seconds)
317 SysTimeSet(mqttTime);
332 while (buffer != NULL && bufSize)
335 uint8_t inx = *(buffer + pos);
336 const uint8_t *data = buffer + pos + 1;
341 writeLog(
"systemParams_SetFromPart: Incorrect INX:%d on position in buffer:%d", (
int)inx, (
int)pos);
348 writeLog(
"systemParams_SetFromPart: few bytes in buffer. Position:%d, required:%d, in buffer:%d", (
int)pos, (
int)
_systemParamRef[inxRef].Size, (
int)bufSize);
396#define SYS_WR(inst, member) \
397 writeLog("%03u(%02X) " #member ":%d(%02X)", \
398 (unsigned)((uint8_t*)&((inst).member) - (uint8_t*)&(inst)), \
399 (unsigned)((uint8_t*)&((inst).member) - (uint8_t*)&(inst)), \
400 (int)((inst).member),(int)((inst).member))
403#define SYS_WR_ARR(inst, member, len) \
405 unsigned _off = (unsigned)((uint8_t*)&((inst).member) - (uint8_t*)&(inst)); \
406 char _buf[3*(len)]; \
407 for (unsigned _i = 0; _i < (unsigned)(len); _i++) { \
408 _buf[_i*3+0] = "0123456789ABCDEF"[((inst).member[_i] >> 4) & 0xF]; \
409 _buf[_i*3+1] = "0123456789ABCDEF"[ (inst).member[_i] & 0xF]; \
410 _buf[_i*3+2] = (_i < (unsigned)(len)-1) ? ':' : '\0'; \
412 writeLog("%03u(%02X) " #member ":%s", _off, _off, _buf); \
416#define SYS_WR_STR(inst, member) \
417 writeLog("%03u(%02X) " #member ":%s", \
418 (unsigned)((uint8_t*)&((inst).member) - (uint8_t*)&(inst)), \
419 (unsigned)((uint8_t*)&((inst).member) - (uint8_t*)&(inst)), \
423#define SYS_WR_TIME(inst, member) \
425 unsigned _off = (unsigned)((uint8_t*)&((inst).member) - (uint8_t*)&(inst)); \
426 uint64_t _t = (uint64_t)((inst).member); \
427 uint32_t _thi = (uint32_t)((_t >> 32) & 0xFFFFFFFFUL); \
428 uint32_t _tlo = (uint32_t)(_t & 0xFFFFFFFFUL); \
430 writeLog("%03u(%02X) " #member ":%lu%08lu(%08lX%08lX) (not set)", \
431 _off, _off, 0UL, 0UL, 0UL, 0UL); \
433 uint16_t _yr; uint8_t _mo, _dy, _hh, _mm, _ss; \
434 _systemParams_unixToDateTime(_t, &_yr, &_mo, &_dy, &_hh, &_mm, &_ss); \
435 writeLog("%03u(%02X) " #member ":%lu%08lu(%08lX%08lX) %04u-%02u-%02u %02u:%02u:%02u UTC", \
437 (unsigned long)_thi, (unsigned long)_tlo, \
438 (unsigned long)_thi, (unsigned long)_tlo, \
439 (unsigned)_yr, (unsigned)_mo, (unsigned)_dy, \
440 (unsigned)_hh, (unsigned)_mm, (unsigned)_ss); \
461 uint16_t *year, uint8_t *month, uint8_t *day,
462 uint8_t *hour, uint8_t *min, uint8_t *sec)
464 *sec = (uint8_t)(t % 60u);
466 *min = (uint8_t)(t % 60u);
468 *hour = (uint8_t)(t % 24u);
472 uint32_t z = (uint32_t)t + 719468u;
473 uint32_t era = z / 146097u;
474 uint32_t doe = z - era * 146097u;
475 uint32_t yoe = (doe - doe/1460u + doe/36524u - doe/146096u) / 365u;
476 uint32_t y = yoe + era * 400u;
477 uint32_t doy = doe - (365u * yoe + yoe/4u - yoe/100u);
478 uint32_t mp = (5u * doy + 2u) / 153u;
479 uint32_t d = doy - (153u * mp + 2u) / 5u + 1u;
480 uint32_t m = mp + (mp < 10u ? 3u : -9u);
481 y += (m <= 2u ? 1u : 0u);
491 writeLog(
"=========== systemParams_Log %s =============", info);
532 writeLog(
"================ NFC measure info ========");
540 writeLog(
"======_systemParamRef only for Tamas =======");
546 writeLog(
"==========================================");
#define SENSOR_SHT45
Enable SHT45 temperature and humidity sensor driver.
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)
This function is executed in case of error occurrence.
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...
#define COUNT_OF(array)
the macro for getting items count array
static void OnTimerToOff(void *)
Dummy function - the timer need empty dummy, cannot be NULL
systemParamsRef_t _systemParamRef[]
the definition of _systemParams and struct position and sizes
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 sensorsBase_SetCRCMeasureNFC()
Recalculate and store the CRC in _measureNFC.Crc. Call this after modifying any field of _measureNFC ...
uint8_t systemParams_CorrectSystemTime()
setting/correction of the system time from _systemParams.MqttTime, if contains valid UNIX time(low ui...
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_getAppEUI()
Return a pointer to the AppEUI (JoinEUI) stored in _systemParams. Used by the LoRaWAN stack during th...
void sensorsBase_MeasureNFCInit()
the default initialization of _measureNFC struct
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...
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...
uint8_t sensorsBase_CheckCRCMeasureNFC()
Verify the CRC field of a _measureNFC structure.
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)
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.
#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_TIME(inst, member)
#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.
static int8_t systemParamsRef_Get(uint8_t inx)
find the index of field
#define SYSTEMPARAMS_APPVER00
Application firmware minor version number (plain integer).
#define SYSTEMPARAMS_MINSENSORTIME
Minimum allowed sensor measurement interval in milliseconds (30 seconds).
#define MEASUEREDATANFC_EEPROMSIZE
the maximum size EEPROM.
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_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 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).
systemParams_t _systemParamsBck
#define SZ_MEASURENFC
The last 50 records of payload (CayeneeLPP) are store in NFC for debuging. These data can be received...
#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 MEASUREDATANFC_ADDR
The address, on which is the begin of measured data in NFC. The address is modulo 4,...
#define SYSTEMPARAMS_MAXSENSORTIME
Maximum allowed sensor measurement interval in milliseconds (18 hour).
@ LORAWANPORT_DATA_DEFAULT
Secure Element identity and keys.
#define FORMAT32_KEY(...)
block of one measure data in CayennelLPP payload format The Data field contains the same payload as i...
the control block of NFC on address MEASUREDATANFC_ADDR where are stored the last measure data The EE...
System configuration parameters – persisted in NFC EEPROM at address 0. The structure contains all mo...
The references to systemParams_t for change values from server via downlink. The server sends via dow...
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)
uint8_t calculateCrc(uint8_t *data, uint8_t len)
Calculate a CRC-8 checksum (Sensirion polynomial) over a byte buffer. Used to validate sensor I2C res...