L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
mysensors.h
Go to the documentation of this file.
1/*
2 * mysensors.h
3 *
4 * Created on: 6. 1. 2026
5 * Author: Milan
6 *
7 * helpers for standard HAL fncs
8 * The sensors reading data.
9 */
10
11#ifndef INC_MYSENSORS_H_
12#define INC_MYSENSORS_H_
13
14#include "stm32wlxx_hal.h"
15#include "mymems.h"
16
17/**
18 * @brief State machine states for the sensor reading process.
19 *
20 * The state machine is driven either by the sequencer (timer-based) or
21 * by direct polling via sensors_Start() / sensors_Work(). It progresses
22 * sequentially through the states; completion is signalled when SENS_DONE
23 * is returned.
24 */
25typedef enum
26{
27 SENS_BEGIN = 0, /**< Entry state: I2C is initialised and the sequence is prepared */
28 SENS_INIT, /**< Sensor initialisation: each active sensor is (re-)initialised if not already */
29 SENS_START, /**< Sensors powered on (xxx_On() called for the current group) */
30 SENS_READ, /**< Data read issued (xxx_Read() called for the current group) */
31 SENS_STOP, /**< Sensors powered off (xxx_Off() called for the current group) */
32 SENS_DATAREADY, /**< All sensor data collected; ready for post-processing or LoRa uplink */
33 SENS_SERVICE, /**< Service actions executed (e.g. SPS30 fan cleaning); data may be unavailable */
34 SENS_END, /**< Sequence complete: I2C is de-initialised for power saving */
35 SENS_DONE /**< Final state: caller may read sensor data and schedule the next cycle */
37
38
39/**
40 * @brief Initialization of all sensors, must be called before for store of hi2c handler
41 * @param hi2c
42 */
43void sensors_Init(I2C_HandleTypeDef* hi2c);
44
45/**
46 * @brief the sensors sequencer initialization and set the process in sequencer
47 * - create task
48 * - create timer
49 * - process data
50 * - fire event CFG_SEQ_Task_MyLoraSend - data are ready for loraWan processing
51
52 * @param sensortAppBit - bit for task
53 * @param mylorawanAppBit - bit for event firing
54 */
55void sensorsSeq_Init(uint32_t sensortAppBit, uint32_t mylorawanAppBit);
56
57/**
58 * @brief The copying data from current sensors buffer to backUp - _bck_XXXXX
59 */
61
62/**
63 * @brief collecting sensor data into CayenneLppGetBuffer buffer for sending them via LoRaWan, the methods works with _bck_XXXXX sensor data, not with real. \n
64 * The measure time is added only if time distance is bigger than 1min:
65 * @par
66 * - UNIX - absolute time, if distance between times is bigger than 65353 minutes(45.5days), CayenneLppAddTimeMeasureABS
67 * @par
68 * - relative, minutes 16 - max 65535 is distance is bigger than 255 minutes (4.25h), CayenneLppAddTimeMeasureMIN16
69 * @par
70 * - relative, minute 8 - max 255, if distance between measured data is less than 255 minutes, CayenneLppAddTimeMeasureMIN16
71 *
72 * @param sizeOut - the size(bytes) in buffer, the size is max 254, uint8_t is enough
73 * @param prevMeasureTime the previous measure time, 0 or NULL - is not specified, no time is added
74 * @return address of buffer or null, if no data
75 */
76uint8_t * sensors_CayennelFromBckData(uint8_t *sizeOut, SysTime_t* prevMeasureTime);
77
78/**
79 * @brief filling the data block from sensor data - store to memory
80 * the methods works with _bck_XXXXX senzor, not with real
81 * at the begin is writte the timeout of sensor measuring in minutes * 100
82 */
84
85/**
86 * @brief reading from memory block and filling specified sensor from memory - ready for sensors_CayennelData
87 * the methods works with _bck_XXXXX senzor, not with real
88 * @retval size of total read from data block, 0 - if is other than expected data
89 */
91
92/**
93 * @brief getting the SysTime_t from block data of memory
94 * @retval the time of measure - UNIX time
95 */
96SysTime_t sensors_GetTimeFromBlock(const mems_DataBlock_t *data);
97
98
99/**
100 * @brief stop and start of sensor timer for next measure
101 */
102void sensors_Retiming();
103
104/**
105 * @brief possible to I2C turn on/off - cumulative
106 */
107void i2c_OnOff(uint8_t onOff);
108
109
110/*
111 * for non sequencer ....
112 * sensors_Start();
113 * if (sensors_Read() == SENS_DONE)
114 * ; finished
115 *
116 */
117
118/**
119 * @brief - non squncer processing
120 * start of reading - prepare of internal state machine
121 */
122void sensors_Start();
123
124/**
125 * @brief - no sequncer processing
126 * reading data from sensor according to group specification
127 * @return SENS_DONE - process of reading finished, otherwise current state of status machine
128 */
130
131
132#endif /* INC_MYSENSORS_H_ */
sens_ProcessDef_t
State machine states for the sensor reading process.
Definition mysensors.h:26
@ SENS_SERVICE
Definition mysensors.h:33
@ SENS_INIT
Definition mysensors.h:28
@ SENS_START
Definition mysensors.h:29
@ SENS_READ
Definition mysensors.h:30
@ SENS_DATAREADY
Definition mysensors.h:32
@ SENS_DONE
Definition mysensors.h:35
@ SENS_STOP
Definition mysensors.h:31
@ SENS_BEGIN
Definition mysensors.h:27
@ SENS_END
Definition mysensors.h:34
void sensors_Init(I2C_HandleTypeDef *hi2c)
Initialization of all sensors, must be called before for store of hi2c handler.
Definition mysensors.c:413
uint8_t * sensors_CayennelFromBckData(uint8_t *sizeOut, SysTime_t *prevMeasureTime)
collecting sensor data into CayenneLppGetBuffer buffer for sending them via LoRaWan,...
Definition mysensors.c:488
void sensors_WriteFromBckToDataBlock(mems_DataBlock_t *data)
filling the data block from sensor data - store to memory the methods works with _bck_XXXXX senzor,...
Definition mysensors.c:604
sens_ProcessDef_t sensors_Work()
no sequncer processing reading data from sensor according to group specification
Definition mysensors.c:342
void sensorsSeq_Init(uint32_t sensortAppBit, uint32_t mylorawanAppBit)
the sensors sequencer initialization and set the process in sequencer
Definition mysensors.c:454
void sensors_Start()
non squncer processing start of reading - prepare of internal state machine
Definition mysensors.c:333
void sensors_Retiming()
stop and start of sensor timer for next measure
Definition mysensors.c:438
SysTime_t sensors_GetTimeFromBlock(const mems_DataBlock_t *data)
getting the SysTime_t from block data of memory
Definition mysensors.c:683
void i2c_OnOff(uint8_t onOff)
possible to I2C turn on/off - cumulative
Definition mysensors.c:190
void sensors_CopyToBck()
The copying data from current sensors buffer to backUp - _bck_XXXXX.
Definition mysensors.c:463
uint8_t sensors_ReadToBckFromDataBlock(const mems_DataBlock_t *data)
reading from memory block and filling specified sensor from memory - ready for sensors_CayennelData t...
Definition mysensors.c:646
Sensor data record stored as one element in the flash circular queue.
Definition mymems.h:82