L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
mysensors.c File Reference
#include "main.h"
#include "mysensors.h"
#include "mysensors_base.h"
#include "i2c.h"
#include "utils/utils.h"
#include "stm32_timer.h"
#include "stm32_seq.h"
#include "sys_app.h"
#include "adc_if.h"
#include "CayenneLpp.h"
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
Include dependency graph for mysensors.c:

Go to the source code of this file.

Data Structures

struct  sens_GrpTiming_t
 the definition for group of sensor sens_ReadingGrp_t the number of readings and timeout for reading data from sensors More...
struct  sens_processing_t
 sensor definition - interface More...

Enumerations

enum  sens_ReadingGrp_t {
  SENS_GRP_0 = 0 , SENS_GRP_1 , SENS_GRP_2 , SENS_GRP_3 ,
  SENS_GRP_ALL
}
 sensor groups for reading - the sensors in one group are read together This is necessary to processing of the similar sensors together as tempHum, ambient, barometer etc. depends on their consumption every sensor's group has it own count of measuring, timeout between measure At the end of measure, maybe any sensors need to service, therefor is called method NeedService, which returns 1 - sensor is servicing 0 - not, or service has been finished More...

Functions

static int getCount_GroupTiming ()
static int getCount_Sensors ()
static void sensBuffer_Reset ()
static void sensBuffer_Add (const char *format,...)
static char * sensBuffer_Get ()
static void sensBuffer_Send ()
void i2c_OnOff (uint8_t onOff)
 possible to I2C turn on/off - cumulative
static int sensors_OnOff (sens_ReadingGrp_t grp, int onOff)
 On/Off sensors according to group.
static void sensors_Read (sens_ReadingGrp_t grp)
 reading sensor one by one in specified group
static uint8_t sensors_NextGroup ()
 Move to next used group in _sensors[].
static uint8_t sensors_Service ()
static void tasksensors_Work ()
 task sensor sequencer
static void tasksensors_OnTimeout ()
void sensors_Start ()
 
  • non squncer processing start of reading - prepare of internal state machine

sens_ProcessDef_t sensors_Work ()
 
  • no sequncer processing reading data from sensor according to group specification

void sensors_Init (I2C_HandleTypeDef *hi2c)
 Initialization of all sensors, must be called before for store of hi2c handler.
void sensors_Retiming ()
 the System goes to OFF mode - retiming of timer sensor reading
void sensorsSeq_Init (uint32_t sensortAppBit, uint32_t mylorawanAppBit)
 task sequencer initialization for sensors reading
void sensors_CopyToBck ()
 The copying data from current sensors buffer to backUp - _bck_XXXXX.
uint8_t * sensors_CayennelFromBckData (uint8_t *sizeOut)
 collecting sensor data into CayenneLppGetBuffer buffer for sending them via LoRa the methods works with _bck_XXXXX senzor, not with real
void sensors_WriteFromBckToDataBlock (mems_DataBlock_t *data)
 filling the data block from sensor data - store to memory the methods works with _bck_XXXXX senzor, not with real at the begin is writte the timeout of sensor measuring in minutes * 100
uint8_t sensors_ReadToBckFromDataBlock (const mems_DataBlock_t *data)
 reading from memory block and filling specified sensor from memory - ready for sensors_CayennelData the methods works with _bck_XXXXX senzor, not with real

Variables

static const sens_GrpTiming_t _groupTiming []
 definition of sensors group
static const sens_processing_t _sensors []
static I2C_HandleTypeDef * _hi2c = NULL
static sens_ProcessDef_t _processDef = SENS_DONE
static int _groupInxTiming = 0
static sleeper_t _processDelay = {}
static int _groupReadCount = 0
static UTIL_TIMER_Object_t _sensorTimerReading = {}
static uint32_t _sensorSeqID = 0
static uint32_t _mylorawanSeqID = 0
static uint16_t _sensorMeasureTime = 0
static char _sensBuffer [1024] = {}
static int _i2cOnOff = 1

Enumeration Type Documentation

◆ sens_ReadingGrp_t

sensor groups for reading - the sensors in one group are read together This is necessary to processing of the similar sensors together as tempHum, ambient, barometer etc. depends on their consumption every sensor's group has it own count of measuring, timeout between measure At the end of measure, maybe any sensors need to service, therefor is called method NeedService, which returns 1 - sensor is servicing 0 - not, or service has been finished

Enumerator
SENS_GRP_0 
SENS_GRP_1 
SENS_GRP_2 
SENS_GRP_3 
SENS_GRP_ALL 

Definition at line 42 of file mysensors.c.

Function Documentation

◆ getCount_GroupTiming()

int getCount_GroupTiming ( )
static

Definition at line 136 of file mysensors.c.

References _groupTiming.

Referenced by sensors_NextGroup().

Here is the caller graph for this function:

◆ getCount_Sensors()

int getCount_Sensors ( )
static

Definition at line 140 of file mysensors.c.

References _sensors.

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

Here is the caller graph for this function:

◆ i2c_OnOff()

void i2c_OnOff ( uint8_t onOff)

possible to I2C turn on/off - cumulative

Definition at line 184 of file mysensors.c.

References _i2cOnOff, MX_I2C2_DeInit(), and MX_I2C2_Init().

Referenced by main(), nfc_FactoryReset(), nfc_ReadSystemParams(), nfc_WriteSystemParams(), and sensors_Work().

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

◆ sensBuffer_Add()

void sensBuffer_Add ( const char * format,
... )
static

Definition at line 153 of file mysensors.c.

References _sensBuffer.

Referenced by sensors_Read().

Here is the caller graph for this function:

◆ sensBuffer_Get()

char * sensBuffer_Get ( )
static

Definition at line 163 of file mysensors.c.

References _sensBuffer.

Referenced by sensors_Read().

Here is the caller graph for this function:

◆ sensBuffer_Reset()

void sensBuffer_Reset ( )
static

Definition at line 148 of file mysensors.c.

References _sensBuffer.

Referenced by sensors_Read().

Here is the caller graph for this function:

◆ sensBuffer_Send()

void sensBuffer_Send ( )
static

Definition at line 168 of file mysensors.c.

References _sensBuffer, and writeLogNL().

Referenced by sensors_Read().

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

◆ sensors_CayennelFromBckData()

uint8_t * sensors_CayennelFromBckData ( uint8_t * sizeOut)

collecting sensor data into CayenneLppGetBuffer buffer for sending them via LoRa the methods works with _bck_XXXXX senzor, not with real

Parameters
sizeOut- the size(bytes) in buffer, the size is max 254, uint8_t is enough
Return values
addressof buffer or null, if no data

Definition at line 469 of file mysensors.c.

References _bck_amb_tsl2591Data, _bck_bar_bmp585Data, _bck_bar_ils22qsData, _bck_scd41Data, _bck_sps30Data, _bck_tmphm_sht45Data, _sensorMeasureTime, CayenneLppAddBarometricPressure(), CayenneLppAddConcentration(), CayenneLppAddLuminosity(), CayenneLppAddMeasureInterval(), CayenneLppAddParticulateMatter_1_0(), CayenneLppAddParticulateMatter_2_5(), CayenneLppAddRelativeHumidity(), CayenneLppAddTemperature(), CayenneLppAddVoltage(), CayenneLppGetBuffer(), CayenneLppGetSize(), CayenneLppReset(), and GetBatteryLevel().

Referenced by myloraWan_PrepareSendingBuffer().

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

◆ sensors_CopyToBck()

void sensors_CopyToBck ( )

The copying data from current sensors buffer to backUp - _bck_XXXXX.

Definition at line 447 of file mysensors.c.

References _amb_tsl2591Data, _bar_bmp585Data, _bar_ils22qsData, _bck_amb_tsl2591Data, _bck_bar_bmp585Data, _bck_bar_ils22qsData, _bck_scd41Data, _bck_sps30Data, _bck_tmphm_sht45Data, _scd41Data, _sps30Data, and _tmphm_sht45Data.

Referenced by myloraWan_MeasureFinish().

Here is the caller graph for this function:

◆ sensors_Init()

void sensors_Init ( I2C_HandleTypeDef * hi2c)

Initialization of all sensors, must be called before for store of hi2c handler.

Parameters
hi2c

Definition at line 399 of file mysensors.c.

References _hi2c, _sensors, getCount_Sensors(), SENS_GRP_ALL, sensors_OnOff(), systemParams_IsSensorAvaiable(), and writeLog().

Referenced by main(), and sensors_Work().

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

◆ sensors_NextGroup()

uint8_t sensors_NextGroup ( )
static

Move to next used group in _sensors[].

Definition at line 259 of file mysensors.c.

References _groupInxTiming, _groupTiming, _sensors, getCount_GroupTiming(), and getCount_Sensors().

Referenced by sensors_Start(), and sensors_Work().

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

◆ sensors_OnOff()

int sensors_OnOff ( sens_ReadingGrp_t grp,
int onOff )
static

On/Off sensors according to group.

Parameters
grp- specified group, if SENS_GRP_LAST - all sensors
Returns
number of sensors started from group

Definition at line 204 of file mysensors.c.

References _hi2c, _sensors, getCount_Sensors(), SENS_GRP_ALL, systemParams_IsSensorAvaiable(), and writeLog().

Referenced by sensors_Init(), and sensors_Work().

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

◆ sensors_Read()

void sensors_Read ( sens_ReadingGrp_t grp)
static

reading sensor one by one in specified group

Parameters
grpspecified group, if SENS_GRP_LAST - all sensors

Definition at line 233 of file mysensors.c.

References _hi2c, _sensors, _tryInit, getCount_Sensors(), SENS_GRP_ALL, sensBuffer_Add(), sensBuffer_Get(), sensBuffer_Reset(), sensBuffer_Send(), and systemParams_IsSensorAvaiable().

Referenced by sensors_Work().

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

◆ sensors_ReadToBckFromDataBlock()

uint8_t sensors_ReadToBckFromDataBlock ( const mems_DataBlock_t * data)

reading from memory block and filling specified sensor from memory - ready for sensors_CayennelData the methods works with _bck_XXXXX senzor, not with real

Return values
sizeof total read from data block, 0 - if is other than expected data

Definition at line 575 of file mysensors.c.

References _bck_amb_tsl2591Data, _bck_bar_bmp585Data, _bck_bar_ils22qsData, _bck_scd41Data, _bck_sps30Data, _bck_tmphm_sht45Data, _sensorMeasureTime, mems_DataBlock_t::Data, MEMS_DATATYPE_SENSOR, and mems_DataBlock_t::Type.

Referenced by myloraWan_PrepareSendingBuffer().

Here is the caller graph for this function:

◆ sensors_Retiming()

void sensors_Retiming ( )

the System goes to OFF mode - retiming of timer sensor reading

Definition at line 424 of file mysensors.c.

References _sensorTimerReading, and _systemParams.

Referenced by sensorsBase_StopTimerToOff().

Here is the caller graph for this function:

◆ sensors_Service()

uint8_t sensors_Service ( )
static

Definition at line 272 of file mysensors.c.

References _hi2c, _sensors, getCount_Sensors(), and systemParams_IsSensorAvaiable().

Referenced by sensors_Work().

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

◆ sensors_Start()

void sensors_Start ( )

  • non squncer processing start of reading - prepare of internal state machine

Definition at line 319 of file mysensors.c.

References _groupInxTiming, _groupReadCount, _processDef, _processDelay, SENS_BEGIN, sensors_NextGroup(), and sleeper_SetSleepMS().

Referenced by tasksensors_OnTimeout().

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

◆ sensors_Work()

sens_ProcessDef_t sensors_Work ( )

  • no sequncer processing reading data from sensor according to group specification

Return values
SENS_DONE- process of reading finished, otherwise current state of status machine

Definition at line 328 of file mysensors.c.

References _groupInxTiming, _groupReadCount, _groupTiming, _processDef, _processDelay, i2c_OnOff(), SENS_BEGIN, SENS_DATAREADY, SENS_DONE, SENS_END, SENS_INIT, SENS_READ, SENS_SERVICE, SENS_START, SENS_STOP, sensors_Init(), sensors_NextGroup(), sensors_OnOff(), sensors_Read(), sensors_Service(), sleeper_IsElapsed(), sleeper_Next(), sleeper_SetSleepMS(), and togle_LedOff().

Referenced by tasksensors_Work().

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

◆ sensors_WriteFromBckToDataBlock()

void sensors_WriteFromBckToDataBlock ( mems_DataBlock_t * data)

filling the data block from sensor data - store to memory the methods works with _bck_XXXXX senzor, not with real at the begin is writte the timeout of sensor measuring in minutes * 100

Definition at line 530 of file mysensors.c.

References _bck_amb_tsl2591Data, _bck_bar_bmp585Data, _bck_bar_ils22qsData, _bck_scd41Data, _bck_sps30Data, _bck_tmphm_sht45Data, _sensorMeasureTime, _systemParams, mems_DataBlock_t::Data, Error_Handler(), MEMS_DATATYPE_SENSOR, SENSORS_DATASIZE, mems_DataBlock_t::Size, mems_DataBlock_t::Type, and writeLog().

Referenced by myloraWan_MeasureFinish().

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

◆ sensorsSeq_Init()

void sensorsSeq_Init ( uint32_t sensortAppBit,
uint32_t mylorawanAppBit )

task sequencer initialization for sensors reading

the sensors sequencer initialization and set the process in sequencer

Definition at line 436 of file mysensors.c.

References _mylorawanSeqID, _sensorSeqID, _sensorTimerReading, _systemParams, tasksensors_OnTimeout(), and tasksensors_Work().

Referenced by main().

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

◆ tasksensors_OnTimeout()

void tasksensors_OnTimeout ( )
static

Definition at line 308 of file mysensors.c.

References _sensorSeqID, _systemParams, CFG_SEQ_Prio_0, and sensors_Start().

Referenced by sensorsSeq_Init().

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

◆ tasksensors_Work()

void tasksensors_Work ( )
static

task sensor sequencer

Definition at line 289 of file mysensors.c.

References _mylorawanSeqID, _sensorSeqID, _sensorTimerReading, CFG_SEQ_Prio_0, SENS_DATAREADY, SENS_DONE, and sensors_Work().

Referenced by sensorsSeq_Init().

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

Variable Documentation

◆ _groupInxTiming

int _groupInxTiming = 0
static

Definition at line 126 of file mysensors.c.

Referenced by sensors_NextGroup(), sensors_Start(), and sensors_Work().

◆ _groupReadCount

int _groupReadCount = 0
static

Definition at line 128 of file mysensors.c.

Referenced by sensors_Start(), and sensors_Work().

◆ _groupTiming

const sens_GrpTiming_t _groupTiming[]
static
Initial value:
=
{
{ SENS_GRP_0, 5, 500 },
{ SENS_GRP_1, 3, 5100 },
{ SENS_GRP_2, 5, 1100 },
}
@ SENS_GRP_1
Definition mysensors.c:45
@ SENS_GRP_2
Definition mysensors.c:46
@ SENS_GRP_0
Definition mysensors.c:44

definition of sensors group

Definition at line 84 of file mysensors.c.

Referenced by getCount_GroupTiming(), sensors_NextGroup(), and sensors_Work().

◆ _hi2c

I2C_HandleTypeDef* _hi2c = NULL
static

Definition at line 122 of file mysensors.c.

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

◆ _i2cOnOff

int _i2cOnOff = 1
static

Definition at line 183 of file mysensors.c.

Referenced by i2c_OnOff().

◆ _mylorawanSeqID

uint32_t _mylorawanSeqID = 0
static

Definition at line 132 of file mysensors.c.

Referenced by sensorsSeq_Init(), and tasksensors_Work().

◆ _processDef

sens_ProcessDef_t _processDef = SENS_DONE
static

Definition at line 125 of file mysensors.c.

Referenced by sensors_Start(), and sensors_Work().

◆ _processDelay

sleeper_t _processDelay = {}
static

Definition at line 127 of file mysensors.c.

Referenced by sensors_Start(), and sensors_Work().

◆ _sensBuffer

char _sensBuffer[1024] = {}
static

Definition at line 146 of file mysensors.c.

Referenced by sensBuffer_Add(), sensBuffer_Get(), sensBuffer_Reset(), and sensBuffer_Send().

◆ _sensorMeasureTime

uint16_t _sensorMeasureTime = 0
static

◆ _sensors

const sens_processing_t _sensors[]
static
Initial value:
=
{
tmphm_sht45_LogData, SYSPARAM_TEMP_HUM, "tempHum sensor" },
bar_ils22qs_LogData, SYSPARAM_BAR, "barometer ILS22 sensor" },
amb_tsl2591_LogData, SYSPARAM_AMBIENT, "ambient sensor" },
bar_bmp585_LogData, SYSPARAM_BAR, "barometer BMP585 sensor" },
scd41_LogData, SYSPARAM_CO2, "scd41 sensor" },
sps30_LogData, SYSPARAM_PARTICULAR, "sps30 sensor" },
}
void amb_tsl2591_LogData(char *buf)
log data to buffer
int8_t amb_tsl2591_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit)
check if light sensor is present
Definition amb_tsl2591.c:35
HAL_StatusTypeDef amb_tsl2591_Read(I2C_HandleTypeDef *hi2c)
read value from sensor, the value is in _ambientData
HAL_StatusTypeDef amb_tsl2591_Off(I2C_HandleTypeDef *hi2c)
turn off sensor
HAL_StatusTypeDef amb_tsl2591_On(I2C_HandleTypeDef *hi2c)
turn on sensor, read value 4x to automatically configure the sensor.
Definition amb_tsl2591.c:57
HAL_StatusTypeDef amb_tsl2591_Init(I2C_HandleTypeDef *hi2c)
initialization of light sensor, and check if sensor is present or not Subsequently the sensor is turn...
HAL_StatusTypeDef bar_bmp585_On(I2C_HandleTypeDef *hi2c)
Turn on sensor - wakeup the sensor and start to processing of pressure measure.
Definition bar_bmp585.c:96
HAL_StatusTypeDef bar_bmp585_Off(I2C_HandleTypeDef *hi2c)
Turn off sensor - stop measure and put sensor in very deep sleep mode.
Definition bar_bmp585.c:112
HAL_StatusTypeDef bar_bmp585_Read(I2C_HandleTypeDef *hi2c)
Read value from sensor, pressure and temperature. Sensor must be turned on before.
Definition bar_bmp585.c:154
void bar_bmp585_LogData(char *buf)
Log data to buffer.
Definition bar_bmp585.c:219
HAL_StatusTypeDef bar_bmp585_Init(I2C_HandleTypeDef *hi2c)
Initialize sensor, check if it really is this sensor. After check the sensor is turned off to save po...
Definition bar_bmp585.c:119
int8_t bar_bmp585_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit)
Check if sensor is present.
Definition bar_bmp585.c:89
int8_t bar_ils22qs_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit)
Check if the ILPS22QS barometric pressure sensor is present on the I2C bus.
Definition bar_ils22qs.c:67
HAL_StatusTypeDef bar_ils22qs_Init(I2C_HandleTypeDef *hi2c)
Initialise the ILPS22QS sensor and verify it is present on the I2C bus. The sensor is put into low-po...
HAL_StatusTypeDef bar_ils22qs_Read(I2C_HandleTypeDef *hi2c)
read value from sensor, pressure and temperature. Sensor must be turned on before
HAL_StatusTypeDef bar_ils22qs_On(I2C_HandleTypeDef *hi2c)
turn on sensor
Definition bar_ils22qs.c:74
void bar_ils22qs_LogData(char *buf)
log data to buffer
HAL_StatusTypeDef bar_ils22qs_Off(I2C_HandleTypeDef *hi2c)
turn off sensor
Definition bar_ils22qs.c:94
static const sens_GrpTiming_t _groupTiming[]
definition of sensors group
Definition mysensors.c:84
@ SYSPARAM_CO2
@ SYSPARAM_BAR
@ SYSPARAM_PARTICULAR
@ SYSPARAM_AMBIENT
@ SYSPARAM_TEMP_HUM
HAL_StatusTypeDef scd41_Off(I2C_HandleTypeDef *hi2c)
stop reading
Definition scd41.c:94
void scd41_LogData(char *buf)
log data to buffer
Definition scd41.c:228
HAL_StatusTypeDef scd41_Init(I2C_HandleTypeDef *hi2c)
initialization of sensor sdc41
Definition scd41.c:99
HAL_StatusTypeDef scd41_Read(I2C_HandleTypeDef *hi2c)
read value from sensor
Definition scd41.c:190
HAL_StatusTypeDef scd41_On(I2C_HandleTypeDef *hi2c)
start reading - turn on sensor, reading mode can be: SCD41_CMD_START_PERIODIC - every 5s - this is pr...
Definition scd41.c:77
int8_t scd41_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit)
check if CO2 sensor is present
Definition scd41.c:70
HAL_StatusTypeDef sps30_Read(I2C_HandleTypeDef *hi2c)
Read data if data is available.
Definition sps30.c:224
void sps30_LogData(char *buf)
log data to buffer
Definition sps30.c:356
HAL_StatusTypeDef sps30_Off(I2C_HandleTypeDef *hi2c)
Turn off laser and fan to stop measurements.
Definition sps30.c:175
int8_t sps30_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit)
check if SPS30 sensor is present
Definition sps30.c:83
int8_t sps30_Service(I2C_HandleTypeDef *hi2c)
the sensor need to be cleaning
Definition sps30.c:367
HAL_StatusTypeDef sps30_Init(I2C_HandleTypeDef *hi2c)
initialization of sensor sps30
Definition sps30.c:90
HAL_StatusTypeDef sps30_On(I2C_HandleTypeDef *hi2c)
Turn on laser and fan to allow measurements.
Definition sps30.c:128
HAL_StatusTypeDef tmphm_sht45_On(I2C_HandleTypeDef *hi2c)
Zapnutie sensora dummy.
Definition tmphm_sht45.c:57
HAL_StatusTypeDef tmphm_sht45_Init(I2C_HandleTypeDef *hi2c)
initialization, check if sensor is present or not. Checks main (0x44) and alternative address (0x45) ...
Definition tmphm_sht45.c:76
HAL_StatusTypeDef tmphm_sht45_Read(I2C_HandleTypeDef *hi2c)
read temperature and humidity from sensor, values are in _tempHumData
void tmphm_sht45_LogData(char *buf)
log data to buffer
HAL_StatusTypeDef tmphm_sht45_Off(I2C_HandleTypeDef *hi2c)
turn off sensor - dummy
Definition tmphm_sht45.c:70
int8_t tmphm_sht45_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit)
check if tempHum sensor is present
Definition tmphm_sht45.c:40

Definition at line 94 of file mysensors.c.

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

◆ _sensorSeqID

uint32_t _sensorSeqID = 0
static

Definition at line 132 of file mysensors.c.

Referenced by sensorsSeq_Init(), tasksensors_OnTimeout(), and tasksensors_Work().

◆ _sensorTimerReading

UTIL_TIMER_Object_t _sensorTimerReading = {}
static

Definition at line 131 of file mysensors.c.

Referenced by sensors_Retiming(), sensorsSeq_Init(), and tasksensors_Work().