L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
mysensors_base.c
Go to the documentation of this file.
1/*
2 * mysensors_base.c
3 *
4 * Created on: 29. 1. 2026
5 * Author: Milan
6 */
7
8#include "mysensors_base.h"
9#include "mysensors.h"
10#include "main.h"
11#include "se-identity.h"
12#include "lora_app.h"
13#include "sys_app.h"
14#include "utils/mydefs.h"
15#include "utils/utils.h"
16
17
18
19
20
22 .Sign = SYSTEMPARAMS_SIGN, // only sign check
23 .AppVersion = {SYSTEMPARAMS_APPVER00, SYSTEMPARAMS_APPVER01}, // application version, SYSTEMPARAMS_APPVER01 - validity
24#ifdef DEBUG
25 .SensTimeoutMeasure = SYSTEMPARAMS_MINSENSORTIME, // 30sec, sensorsSeq_Init
26#else
27 .SensTimeoutMeasure = SYSTEMPARAMS_DEFAULTSENSORTIME, // 10min, sensorsSeq_Init
28#endif
29 .SensAltitude = SYSTEMPARAMS_DEFAULTALTITUDE, // bar_bmp585_Read, bar_ils22qs_Read, scd41_Init
30 .SensSendInOnePacket = 0,
31 .SensPollSensors = (SYSPARAM_TEMP_HUM | SYSPARAM_BAR), // bit mask of sensors
32
33 .SensExistSensors =
34#if defined(SENSOR_SHT45)
36#endif
37#if defined(SENSOR_BAR_BMP585) || defined(SENSOR_BAR_ILS22QS)
39#endif
40#if defined(SENSOR_AMB_TSL2591)
42#endif
43#if defined(SENSOR_SCD41)
45#endif
46#if defined(SENSOR_SPS30)
48#endif
49 0,
50
51 .MemsStoreSensorData = 1, // myloraWan_MeasureFinish
52 .MemsMaxSensorData = 0, // mems_WriteToSystemParams, will be updated later, according to memory chip
53 .MemsCurrentCountSensorData = 0, // mems_WriteToSystemParams, will be updated later, according to memory chip
54
55
56 .LoRaPort = LORAWANPORT_DATA_DEFAULT, // myLoraWan_LastDataSend
57 .LoRaRepeatTryConnect = 2, // OnLoRaWanConnected
58 .LoRaAdaptiveDataRate = LORAWAN_ADR_STATE, // systemParams_SetLoRaWanParams
59 .LoRaDataRate = LORAWAN_DEFAULT_DATA_RATE, // systemParams_SetLoRaWanParams
60 .LoRaTxPower = LORAWAN_DEFAULT_TX_POWER, // systemParams_SetLoRaWanParams
61 .LoRaClass = LORAWAN_DEFAULT_CLASS, // systemParams_SetLoRaWanParams
62 .LoRaRegion = ACTIVE_REGION, // systemParams_SetLoRaWanParams
63
64
65 .HWBatteryLevelStatus = 0, // mems_WriteToSystemParams, will be updated later
66 .HWBatteryMV = 0, // mems_WriteToSystemParams, will be updated later, according to memory chip
67 .HWDevEUI = {}, // default 0, will be updated in getAppDevEUI
68 .HWAppEUI = FORMAT32_KEY(SYSTEM_APP_EUI), // LoRaWAN_Init
69 .HWAppKEY = FORMAT_KEY(SYSTEM_APP_KEY), // LoRaWAN_Init, app KEY
70 .HWDevADDR = 0, // will be updated in getAppDevEUI
71
72 .DevRestart = 0, // the device need to be restarted
73 .DevReset = 0, // factory reset
74 .DevOnOff = 0, // in main() - start/stop measuring
75
76 .MqttConfirm = 0,
77 .MqttTime = 0,
78
79 .IntBatTimeSendUNIX = 0,
80 .Dummy = {},//
81 .Crc = 0 //
82 };
83
84
85systemParams_t _systemParamsBck = {}; // helper - bckUp buffer for NFC reading and for sending via downlink to server
86
87
88// helper -
89#ifdef DEBUG
90#define SYS_REF(i,f) {.Inx = i, .Size = sizeof(_systemParams.f), .Addr = ((uint8_t*)&_systemParams.f - (uint8_t*)&_systemParams), .Name = #f}
91#else
92#define SYS_REF(i,f) {.Inx = i, .Size = sizeof(_systemParams.f), .Addr = ((uint8_t*)&_systemParams.f - (uint8_t*)&_systemParams)}
93#endif
94
95/**
96 * @brief - the definition of _systemParams and struct position and sizes
97 */
99 {
100 SYS_REF(0, Sign),
101 SYS_REF(1, AppVersion),
102 SYS_REF(2, SensTimeoutMeasure),
103 SYS_REF(3, SensAltitude),
104 SYS_REF(4, SensSendInOnePacket),
105 SYS_REF(5, SensPollSensors),
106 SYS_REF(6, SensExistSensors),
107 SYS_REF(7, MemsStoreSensorData),
108 SYS_REF(8, MemsMaxSensorData),
109 SYS_REF(9, MemsCurrentCountSensorData),
110 SYS_REF(10, LoRaPort),
111 SYS_REF(11, LoRaRepeatTryConnect),
112 SYS_REF(12, LoRaAdaptiveDataRate),
113 SYS_REF(13, LoRaDataRate),
114 SYS_REF(14, LoRaTxPower),
115 SYS_REF(15, LoRaClass),
116 SYS_REF(16, LoRaRegion),
117 SYS_REF(17, HWBatteryLevelStatus),
118 SYS_REF(18, HWBatteryMV),
119 SYS_REF(19, HWDevEUI),
120 SYS_REF(20, HWAppEUI),
121 SYS_REF(21, HWAppKEY),
122 SYS_REF(22, HWDevADDR),
123 SYS_REF(23, DevRestart),
124 SYS_REF(24, DevReset),
125 SYS_REF(25, DevOnOff),
126 SYS_REF(26, MqttConfirm),
127 SYS_REF(27, MqttTime),
128 SYS_REF(28, IntBatTimeSendUNIX),
129 SYS_REF(29, Dummy),
130 SYS_REF(30, Crc)
131 };
132
133
134int8_t _tryInit = 1; // xxx_Is - try init for ensure....
136uint8_t _batPercLevel = 0; /**< level of battery percentage on start */
137
138
139
140static UTIL_TIMER_Object_t _timerToOff = {}; // timer to activate of OFF Mode
141static uint32_t _timerTick = 0; // timer tick
142
143/**
144 * @brief - find the index of field
145 * @retval index into _systemParamRef where is found inx param
146 * @retval -1 - in case, if specified index not exist
147 */
148static int8_t systemParamsRef_Get(uint8_t inx)
149{
150 int8_t retInx = -1, i;
151
152 for (i = 0; i < COUNT_OF(_systemParamRef) && retInx < 0; ++i)
153 if (_systemParamRef[i].Inx == inx)
154 retInx = i;
155 return retInx;
156}
157
158/**
159 * @brief - Dummy function - the timer need empty dummy, cannot be NULL
160 */
161static void OnTimerToOff(void*)
162{
163}
164
165static void getDevEuiFromHardware(uint8_t *devEui)
166{
167 // --- Prefix: your HW/FW identity (3 bytes) ---
168 // Bit 1 of byte[0] set = locally administered (not IEEE-registered)
169 devEui[0] = SYSTEM_APP_DevEUI0; // 0x45; // 0x46 = locally-administered variant of 0x44, or use 0x45 for private network
170 devEui[1] = SYSTEM_APP_DevEUI1; // 0x87;
171 devEui[2] = SYSTEM_APP_DevEUI2; // 0xF2;
172
173 // --- Unique part: 4 bytes derived from STM32 96-bit UID ---
174 uint32_t uid0 = HAL_GetUIDw0();
175 uint32_t uid2 = HAL_GetUIDw2();
176 uint32_t unique = uid0 ^ uid2; // XOR for better mixing
177
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);
182
183 // --- Checksum: CRC-8 over bytes [0..6] ---
184 devEui[7] = calculateCrc(devEui, 7);
185}
186
187///////////////////////////////////// public //////////////////////////////////
188
190{
191 const uint8_t def[8] =
192 { 0, 0, 0, 0, 0, 0, 0, 0 };
193
194 if (memcmp(_systemParams.HWDevEUI, def, MIN(sizeof(_systemParams.HWDevEUI), sizeof(def))) == 0)
196
197 if (_systemParams.HWDevADDR == 0)
198 GetDevAddr(&_systemParams.HWDevADDR);
199
200 return _systemParams.HWDevEUI;
201}
202
204{
205 return _systemParams.HWAppEUI;
206}
207
209{
210 return _systemParams.HWAppKEY;
211}
212
213
215{
216 _systemParams.Crc = calculateCrc((uint8_t*)&_systemParams, sizeof(_systemParams) - sizeof(_systemParams.Crc));
217}
218
220{
221 uint8_t crc = calculateCrc((uint8_t*)par, sizeof(*par) - sizeof(par->Crc));
222 return crc == par->Crc;
223}
224
226{
227 if (SZ_SYSTEMPARAMS != sizeof(systemParams_t))
228 {
229 writeLog("The sizeof systemParams_t:%d, expected:%d", sizeof(systemParams_t), SZ_SYSTEMPARAMS);
231 }
232
233 if (SZ_MEASURENFC != sizeof(measureNFC_t))
234 {
235 writeLog("The sizeof measureNFC_t:%d, expected:%d", sizeof(measureNFC_t), SZ_MEASURENFC);
237 }
238
239 if (sizeof(measureNFC_t) % 4)
240 {
241 writeLog("The sizeof measureNFC_t:%d is not on boundary 4!", sizeof(measureNFC_t));
243 }
244 if (sizeof(measureDataNFC_t) % 4)
245 {
246 writeLog("The sizeof measureDataNFC_t:%d is not on boundary 4!", sizeof(measureDataNFC_t));
248
249 }
250
252 {
253 writeLog("The sizeof systemParams_t:%d overwrite data measure address:%d", SZ_SYSTEMPARAMS, MEASUREDATANFC_ADDR);
255 }
256
257 // the chec the size of EEPROM a byte address possible
258 int eepromDataSize = MEASUEREDATANFC_EEPROMSIZE / sizeof(measureDataNFC_t);
259 if (eepromDataSize > 255)
260 {
261 writeLog("The NFC EEPROM size:%d is too big for BYTE(uint8_t) handling in measureNFC_t", eepromDataSize);
263 }
264
266 systemParams_getAppDevEUI(); // set default setting
267 sensorsBase_MeasureNFCInit(); // set default setting
268}
269
271{
272 if (_timerToOff.ReloadValue == 0)
273 UTIL_TIMER_Create(&_timerToOff, SYSTEMPARAMS_MINTIME2OFF, UTIL_TIMER_ONESHOT, OnTimerToOff, NULL);
274 UTIL_TIMER_Start(&_timerToOff);
276}
277
279{
280 uint32_t curTick = HAL_GetTick() - _timerTick;
281 UTIL_TIMER_Stop(&_timerToOff);
282
283 if (curTick >= SYSTEMPARAMS_MINTIME2OFF)
284 {
285 //sensors_Retiming();
286 setModeDevice(MODEDEVICE_OFF); // MCU is ready go to OFF mode
287 }
288}
289
291{
292 _systemParams.SensTimeoutMeasure = CLAMP(_systemParams.SensTimeoutMeasure, SYSTEMPARAMS_MINSENSORTIME, SYSTEMPARAMS_MAXSENSORTIME); // max 1h
293 _systemParams.LoRaRepeatTryConnect = CLAMP(_systemParams.LoRaRepeatTryConnect, 0, 32);
294 _systemParams.LoRaDataRate = CLAMP(_systemParams.LoRaDataRate, DR_0, DR_5);
295 _systemParams.LoRaTxPower = CLAMP(_systemParams.LoRaTxPower, TX_POWER_0, TX_POWER_7);
296 _systemParams.LoRaClass = CLAMP(_systemParams.LoRaClass, (uint8_t)CLASS_A, (uint8_t)CLASS_C);
297 _systemParams.LoRaRegion = CLAMP(_systemParams.LoRaRegion, 0, 9);
298 _systemParams.MqttTime &= 0xFFFFFFFF;
299
300 // these values ​​cannot be modified
302 GetDevAddr(&_systemParams.HWDevADDR);
303}
304
306{
307 return (_systemParams.SensPollSensors & sensorType) != 0;
308}
309
311{
312 uint8_t ret = 0;
313 SysTime_t sysTime = SysTimeGet(), mqttTime = {.Seconds = _systemParams.MqttTime & 0xFFFFFFFF, .SubSeconds = 0};
314
315 if (mqttTime.Seconds >= sysTime.Seconds) // the system time is lower, is updated
316 {
317 SysTimeSet(mqttTime);
318 ret = 1; // system time has been changed, system Time is incorrect
319 }
320 else
321 {
322 _systemParams.MqttTime = sysTime.Seconds;
323 ret = 2; // mqtt time has been changed
324 }
325 return ret;
326}
327
328
329void systemParams_SetFromPart(const uint8_t* buffer, uint8_t bufSize)
330{
331 uint8_t pos = 0;
332 while (buffer != NULL && bufSize)
333 {
334 // 1. read index
335 uint8_t inx = *(buffer + pos); // index of field in _systemParams
336 const uint8_t *data = buffer + pos + 1; // data for field
337 int8_t inxRef = systemParamsRef_Get(inx); // trying to fine the address and size for specified inx
338
339 if (inxRef < 0)
340 {
341 writeLog("systemParams_SetFromPart: Incorrect INX:%d on position in buffer:%d", (int)inx, (int)pos);
342 break;
343 }
344
345 // 2. minimum size of rest must be .Size + 1(byte of Inx)
346 if (bufSize < _systemParamRef[inxRef].Size + 1)
347 {
348 writeLog("systemParams_SetFromPart: few bytes in buffer. Position:%d, required:%d, in buffer:%d", (int)pos, (int)_systemParamRef[inxRef].Size, (int)bufSize);
349 break;
350 }
351
352 // copy data to _systemParam struct
353 memcpy((uint8_t*)&_systemParams + _systemParamRef[inxRef].Addr, data, _systemParamRef[inxRef].Size);
354 pos += (1 + _systemParamRef[inxRef].Size); // next position
355 bufSize -= (1 + _systemParamRef[inxRef].Size); // decrement size
356 writeLog("systemParams_SetFromPart: write on _systemParams, Addr:%d, Size:%d", (int) _systemParamRef[inxRef].Addr, _systemParamRef[inxRef].Size);
357 }
359}
360
361
363{
364 _measureNFC.Count = 0;
365 _measureNFC.MaxCount = (MEASUEREDATANFC_EEPROMSIZE - MEASUREDATANFC_ADDR - sizeof(measureNFC_t)) / sizeof(measureDataNFC_t); // byte border
366 _measureNFC.Inx = 0;
367 _measureNFC.Size = sizeof(measureDataNFC_t);
368 memset(_measureNFC.Dummy, 0, sizeof(_measureNFC.Dummy));
370}
371
373{
374 _measureNFC.Crc = calculateCrc((uint8_t*)&_measureNFC, sizeof(_measureNFC) - sizeof(_measureNFC.Crc));
375}
376
378{
379 uint8_t crc = calculateCrc((uint8_t*)&_measureNFC, sizeof(_measureNFC) - sizeof(_measureNFC.Crc));
380 uint8_t isOK = (crc == _measureNFC.Crc);
381
382 if (isOK)
383 {
384 // 1. check the count - correction
385 _measureNFC.Count = CLAMP(_measureNFC.Count, 0, _measureNFC.MaxCount);
386 // 2. check the INX - correcton
387 _measureNFC.Inx = CLAMP(_measureNFC.Inx, 0, _measureNFC.Count);
389 // 3. the checking of size - not correction possible
390 isOK = (_measureNFC.Size == sizeof(measureDataNFC_t));
391 }
392 return isOK;
393}
394
395#ifdef WRITELOG
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))
401
402// Byte array as AA:BB:CC:... — length passed explicitly
403#define SYS_WR_ARR(inst, member, len) \
404 do { \
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'; \
411 } \
412 writeLog("%03u(%02X) " #member ":%s", _off, _off, _buf); \
413 } while(0)
414
415// String field (char array)
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)), \
420 (inst).member)
421
422// uint64_t Unix timestamp field — logs offset, raw value (dec hi:lo and hex hi:lo) and human-readable UTC date/time
423#define SYS_WR_TIME(inst, member) \
424 do { \
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); \
429 if (_t == 0ULL) { \
430 writeLog("%03u(%02X) " #member ":%lu%08lu(%08lX%08lX) (not set)", \
431 _off, _off, 0UL, 0UL, 0UL, 0UL); \
432 } else { \
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", \
436 _off, _off, \
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); \
441 } \
442 } while(0)
443
444/**
445 * @brief Convert a Unix UTC timestamp (seconds since 1970-01-01 00:00:00) to
446 * broken-down calendar fields.
447 *
448 * Uses Howard Hinnant's pure-integer civil-from-days Gregorian algorithm
449 * (no libc time functions required), correct for any 64-bit Unix timestamp
450 * including leap years and century / 400-year boundaries.
451 *
452 * @param t Seconds since the Unix epoch (UTC).
453 * @param year Output: full calendar year (e.g. 2026).
454 * @param month Output: month 1–12.
455 * @param day Output: day-of-month 1–31.
456 * @param hour Output: hours 0–23.
457 * @param min Output: minutes 0–59.
458 * @param sec Output: seconds 0–59.
459 */
460static void _systemParams_unixToDateTime(uint64_t t,
461 uint16_t *year, uint8_t *month, uint8_t *day,
462 uint8_t *hour, uint8_t *min, uint8_t *sec)
463{
464 *sec = (uint8_t)(t % 60u);
465 t /= 60u;
466 *min = (uint8_t)(t % 60u);
467 t /= 60u;
468 *hour = (uint8_t)(t % 24u);
469 t /= 24u;
470
471 // Shift epoch from 1970-01-01 to 0000-03-01 for the era-based Gregorian algorithm
472 uint32_t z = (uint32_t)t + 719468u;
473 uint32_t era = z / 146097u;
474 uint32_t doe = z - era * 146097u; /* [0, 146096] */
475 uint32_t yoe = (doe - doe/1460u + doe/36524u - doe/146096u) / 365u; /* [0, 399] */
476 uint32_t y = yoe + era * 400u;
477 uint32_t doy = doe - (365u * yoe + yoe/4u - yoe/100u); /* [0, 365] */
478 uint32_t mp = (5u * doy + 2u) / 153u; /* [0, 11] */
479 uint32_t d = doy - (153u * mp + 2u) / 5u + 1u; /* [1, 31] */
480 uint32_t m = mp + (mp < 10u ? 3u : -9u); /* [1, 12] */
481 y += (m <= 2u ? 1u : 0u);
482
483 *year = (uint16_t)y;
484 *month = (uint8_t)m;
485 *day = (uint8_t)d;
486}
487
488
489void systemParams_Log(const char* info)
490{
491 writeLog("=========== systemParams_Log %s =============", info);
493 SYS_WR_ARR (_systemParams, AppVersion, 2);
494
495 SYS_WR (_systemParams, SensTimeoutMeasure);
496 SYS_WR (_systemParams, SensAltitude);
497 SYS_WR (_systemParams, SensSendInOnePacket);
498 SYS_WR (_systemParams, SensPollSensors);
499 SYS_WR (_systemParams, SensExistSensors);
500
501 SYS_WR (_systemParams, MemsStoreSensorData);
502 SYS_WR (_systemParams, MemsMaxSensorData);
503 SYS_WR (_systemParams, MemsCurrentCountSensorData);
504
505 //SYS_WR (_systemParams, LoRaPort);
506 SYS_WR (_systemParams, LoRaRepeatTryConnect);
507 SYS_WR (_systemParams, LoRaAdaptiveDataRate);
508 SYS_WR (_systemParams, LoRaDataRate);
509 SYS_WR (_systemParams, LoRaTxPower);
510 SYS_WR (_systemParams, LoRaClass);
511 SYS_WR (_systemParams, LoRaRegion);
512
513
514 SYS_WR (_systemParams, HWBatteryLevelStatus);
515 SYS_WR (_systemParams, HWBatteryMV);
516 SYS_WR_ARR (_systemParams, HWDevEUI, 8);
517 SYS_WR_ARR (_systemParams, HWAppEUI, 8);
518 SYS_WR_ARR (_systemParams, HWAppKEY, 16);
519 SYS_WR (_systemParams, HWDevADDR);
520
521 SYS_WR (_systemParams, DevRestart);
522 SYS_WR (_systemParams, DevReset);
523 SYS_WR (_systemParams, DevOnOff);
524
525 SYS_WR (_systemParams, MqttConfirm);
526 SYS_WR_TIME(_systemParams, MqttTime);
527
528 SYS_WR_TIME(_systemParams, IntBatTimeSendUNIX);
529
530 SYS_WR (_systemParams, Crc);
531
532 writeLog("================ NFC measure info ========");
533 SYS_WR(_measureNFC, Count);
534 SYS_WR(_measureNFC, MaxCount);
535 SYS_WR(_measureNFC, Size);
536 SYS_WR(_measureNFC, Inx);
537 SYS_WR(_measureNFC, Crc);
538
539#ifdef DEBUG
540 writeLog("======_systemParamRef only for Tamas =======");
541 for(int i = 0; i < COUNT_OF(_systemParamRef); ++i)
542 {
543 writeLog("Inx:%02d Size:%02d Addr:%02d Name:%s", (int)_systemParamRef[i].Inx, (int)_systemParamRef[i].Size, (int)_systemParamRef[i].Addr, _systemParamRef[i].Name);
544 }
545#endif
546 writeLog("==========================================");
547
548}
549#endif
#define SENSOR_SHT45
Enable SHT45 temperature and humidity sensor driver.
Header of application of the LRWAN Middleware.
#define LORAWAN_ADR_STATE
Definition lora_app.h:82
#define ACTIVE_REGION
Definition lora_app.h:42
#define LORAWAN_DEFAULT_DATA_RATE
Definition lora_app.h:88
#define LORAWAN_DEFAULT_CLASS
Definition lora_app.h:71
#define LORAWAN_DEFAULT_TX_POWER
Definition lora_app.h:95
: 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.
Definition main.c:589
@ MODEDEVICE_OFF
Definition main.h:60
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:105
void setModeDevice(modeDevice_t mod)
set new device mode
Definition main.c:167
#define CLAMP(val, minVal, maxVal)
Clamp val to the closed interval [minVal, maxVal]. All three arguments are evaluated exactly once via...
Definition mydefs.h:50
#define COUNT_OF(array)
the macro for getting items count array
Definition mydefs.h:70
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
#define SYS_REF(i, f)
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....
@ SYSPARAM_CO2
@ SYSPARAM_BAR
@ SYSPARAM_PARTICULAR
@ SYSPARAM_AMBIENT
@ SYSPARAM_TEMP_HUM
#define SYSTEM_APP_EUI
Default LoRaWAN JoinEUI / AppEUI (8 bytes, all zeros – overridden via NFC).
uint8_t _batPercLevel
#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...
int8_t _tryInit
#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,...
measureNFC_t _measureNFC
#define SYSTEMPARAMS_MAXSENSORTIME
Maximum allowed sensor measurement interval in milliseconds (18 hour).
@ LORAWANPORT_DATA_DEFAULT
Secure Element identity and keys.
#define FORMAT_KEY(...)
#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)
Definition sys_app.c:337
Function prototypes for sys_app.c file.
void GetDevAddr(uint32_t *devAddr)
callback to get the board 32 bits unique ID (LSB)
Definition sys_app.c:239
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...
Definition utils.c:13