26#include "stm32_timer.h"
70 HAL_StatusTypeDef (*
Init)(I2C_HandleTypeDef *hi2c);
71 int8_t (*
Is)(I2C_HandleTypeDef *hi2c, int8_t tryInit);
72 HAL_StatusTypeDef (*
On)(I2C_HandleTypeDef *hi2c);
73 HAL_StatusTypeDef (*
Off)(I2C_HandleTypeDef *hi2c);
74 HAL_StatusTypeDef (*
Read)(I2C_HandleTypeDef *hi2c);
75 int8_t (*
Service)(I2C_HandleTypeDef *hi2c);
100#ifdef SENSOR_BAR_ILS22QS
101 {
_groupTiming[0], bar_ils22qs_Init, bar_ils22qs_Is, bar_ils22qs_On, bar_ils22qs_Off, bar_ils22qs_Read, NULL,
102 bar_ils22qs_LogData,
SYSPARAM_BAR,
"barometer ILS22 sensor" },
104#ifdef SENSOR_AMB_TSL2591
105 {
_groupTiming[0], amb_tsl2591_Init, amb_tsl2591_Is, amb_tsl2591_On, amb_tsl2591_Off, amb_tsl2591_Read, NULL,
108#ifdef SENSOR_BAR_BMP585
113 {
_groupTiming[1], scd41_Init, scd41_Is, scd41_On, scd41_Off, scd41_Read, NULL,
117 {
_groupTiming[2], sps30_Init, sps30_Is, sps30_On, sps30_Off, sps30_Read, sps30_Service,
162 va_start(argList, format);
183#define sensBuffer_Reset()
184#define sensBuffer_Add(format, ...)
185#define sensBuffer_Get() NULL
186#define sensBuffer_Send()
220 writeLog(
"Sensors:%s", (onOff ?
"On" :
"Off"));
221 for (i = 0; i < count; i++)
247 HAL_StatusTypeDef status;
252 for (i = 0; i < count; i++)
259 if (status == HAL_OK)
276 for (i = 0; i < count; i++)
287 uint8_t underService = 0;
289 for (i = 0; i < count; i++)
336 _.GroupInxTiming = -1;
338 _.GroupReadCount = 0;
346 switch (
_.ProcessDef)
359 _.GroupReadCount = 0;
368 _.ProcessDelay.SleepMS = 0;
379 if (
_.GroupReadCount >=
_groupTiming[
_.GroupInxTiming].MaxReadCount)
382 _.ProcessDelay.SleepMS = 0;
387 _.ProcessDelay.SleepMS = 0;
415 HAL_StatusTypeDef status;
422 for (i = 0; i < count; i++)
429 writeLog(
"%d. %s Init %s.", i, ((
_sensors[i].Name != NULL) ?
_sensors[i].Name :
"sensor"), ((status == HAL_OK) ?
"OK" :
"failed"));
433 writeLog(
"%d. sensor: Init is NULL", i);
443 if (
_.SensorTimerReading.ReloadValue == 0)
445 UTIL_TIMER_Stop(&
_.SensorTimerReading);
446 UTIL_TIMER_Start(&
_.SensorTimerReading);
456 _.SensorSeqID = sensortAppBit;
457 _.MylorawanSeqID = mylorawanAppBit;
468#ifdef SENSOR_AMB_TSL2591
469 _bck_amb_tsl2591Data = _amb_tsl2591Data;
471#ifdef SENSOR_BAR_ILS22QS
472 _bck_bar_ils22qsData = _bar_ils22qsData;
474#ifdef SENSOR_BAR_BMP585
478 _bck_scd41Data = _scd41Data;
481 _bck_sps30Data = _sps30Data;
490 uint8_t sz, channel = 1;
491 SysTime_t currentTime = SysTimeGet();
493 uint8_t isTempHum = 0;
510#ifdef SENSOR_AMB_TSL2591
511 if (_bck_amb_tsl2591Data.IsDataValid)
517#ifdef SENSOR_BAR_ILS22QS
518 if (_bck_bar_ils22qsData.IsDataValid)
525#ifdef SENSOR_BAR_BMP585
534 if (_bck_scd41Data.IsDataValid)
546 if (_bck_sps30Data.IsDataValid)
567 if (prevMeasureTime != NULL && prevMeasureTime->Seconds > 0)
569 uint32_t timeToBuff = (
_.MeasureTime.Seconds >= prevMeasureTime->Seconds) ?
570 _.MeasureTime.Seconds - prevMeasureTime->Seconds :
571 prevMeasureTime->Seconds -
_.MeasureTime.Seconds;
576 if (timeToBuff <= 255)
582 if (timeToBuff <= 65535)
609 _.MeasureTime = SysTimeGet();
610 memcpy(data->
Data + off, &
_.MeasureTime,
sizeof(
_.MeasureTime));
611 off +=
sizeof(
_.MeasureTime);
617#ifdef SENSOR_AMB_TSL2591
618 memcpy(data->
Data + off, &_bck_amb_tsl2591Data,
sizeof(_bck_amb_tsl2591Data));
619 off +=
sizeof(_bck_amb_tsl2591Data);
621#ifdef SENSOR_BAR_ILS22QS
622 memcpy(data->
Data + off, &_bck_bar_ils22qsData,
sizeof(_bck_bar_ils22qsData));
623 off +=
sizeof(_bck_bar_ils22qsData);
625#ifdef SENSOR_BAR_BMP585
630 memcpy(data->
Data + off, &_bck_scd41Data,
sizeof(_bck_scd41Data));
631 off +=
sizeof(_bck_scd41Data);
634 memcpy(data->
Data + off, &_bck_sps30Data,
sizeof(_bck_sps30Data));
635 off +=
sizeof(_bck_sps30Data);
643 data->
Size = (uint8_t)off;
652 memcpy(&
_.MeasureTime, data->
Data + off,
sizeof(
_.MeasureTime));
653 off +=
sizeof(
_.MeasureTime);
659#ifdef SENSOR_AMB_TSL2591
660 memcpy(&_bck_amb_tsl2591Data, data->
Data + off,
sizeof(_bck_amb_tsl2591Data));
661 off +=
sizeof(_bck_amb_tsl2591Data);
663#ifdef SENSOR_BAR_ILS22QS
664 memcpy(&_bck_bar_ils22qsData, data->
Data + off,
sizeof(_bck_bar_ils22qsData));
665 off +=
sizeof(_bck_bar_ils22qsData);
667#ifdef SENSOR_BAR_BMP585
672 memcpy(&_bck_scd41Data, data->
Data + off,
sizeof(_bck_scd41Data));
673 off +=
sizeof(_bck_scd41Data);
676 memcpy(&_bck_sps30Data, data->
Data + off,
sizeof(_bck_sps30Data));
677 off +=
sizeof(_bck_sps30Data);
687 memcpy(&ss, data->
Data,
sizeof(ss));
uint8_t CayenneLppAddTemperature(uint8_t channel, float celsius)
uint8_t CayenneLppAddBatteryPerc(uint8_t channel, uint8_t perc)
Add battery percent of voltage data to the buffer (1B).
uint8_t * CayenneLppGetBuffer(void)
uint8_t CayenneLppAddConcentration(uint8_t channel, uint16_t ppm)
Add CO2 concentration data to the buffer.
uint8_t CayenneLppAddLuminosity(uint8_t channel, uint16_t lux)
uint8_t CayenneLppAddBarometricPressure(uint8_t channel, float hpa)
uint8_t CayenneLppAddTimeMeasureABS(uint8_t channel, uint32_t timeMeasure)
Add UTC time of measure to the buffer.
void CayenneLppReset(void)
uint8_t CayenneLppAddTimeMeasureMIN16(uint8_t channel, uint16_t timeOffsetMin16)
Add the relative time of measuring - offset from previous measured data less than 65535 minutes (abou...
uint8_t CayenneLppAddParticulateMatter_1_0(uint8_t channel, float concentration_1_0)
Add particulate matter of 1mm concentration data to the buffer.
uint8_t CayenneLppAddParticulateMatter_2_5(uint8_t channel, float concentration_2_5)
Add particulate matter 2.5mm concentration data to the buffer.
uint8_t CayenneLppAddRelativeHumidity(uint8_t channel, float rh)
uint8_t CayenneLppGetSize(void)
uint8_t CayenneLppAddTimeMeasureMIN8(uint8_t channel, uint8_t timeOffsetMin8)
Add the relative time of measuring - offset from previous measured data less than 255 minutes The tim...
Implements the Cayenne Low Power Protocol.
Header for ADC interface configuration.
HAL_StatusTypeDef bar_bmp585_On(I2C_HandleTypeDef *hi2c)
Turn on sensor - wakeup the sensor and start to processing of pressure measure.
HAL_StatusTypeDef bar_bmp585_Off(I2C_HandleTypeDef *hi2c)
Turn off sensor - stop measure and put sensor in very deep sleep mode.
HAL_StatusTypeDef bar_bmp585_Read(I2C_HandleTypeDef *hi2c)
Read value from sensor, pressure and temperature. Sensor must be turned on before.
void bar_bmp585_LogData(char *buf)
Log data to buffer.
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...
bar_bmp585_t _bar_bmp585Data
Live measurement data from the BMP585 sensor; updated by bar_bmp585_Read().
bar_bmp585_t _bck_bar_bmp585Data
Snapshot copy of the last completed BMP585 measurement; used for LoRaWAN transmission.
int8_t bar_bmp585_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit)
Check if sensor is present.
This file contains all the function prototypes for the i2c.c file.
void MX_I2C2_DeInit(void)
Deinitialise the I2C2 peripheral to reduce current consumption in low-power mode. Call before enterin...
static struct @042147022327042232212126043022001043033342036075 _
: 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 Power3v3_On()
Cumulative turn the all peripheries to ON state - pull-up the _3V3_Enb_Pin pin.
void togle_LedOff(int off)
togle led
void writeLogNL(const char *buf)
Send a pre-formatted C string to the UART log followed by a newline.
void Power3v3_Off()
Cumulative turn the all peripheries to OFF state - pull-down the _3V3_Enb_Pin pin.
#define PRIf_02D(fData)
Expands to integer and fractional arguments for use with PRIf_02. Splits a float/double into the inte...
#define PRIf_02
printf format string for printing a float/double as integer with 2 decimal places....
mems_MainBlock_t _memsMainBlock
Global instance of the main flash control block; loaded by mems_ReadMainBlock().
HAL_StatusTypeDef mems_WriteMainBlock()
writing the main block on flash. The main block is stored on address 0
static int getCount_GroupTiming()
sens_ReadingGrp_t
sensor groups for reading - the sensors in one group are read together This is necessary to processin...
static uint8_t sensors_NextGroup()
Move to next used group in _sensors[].
void sensors_Init(I2C_HandleTypeDef *hi2c)
Initialization of all sensors, must be called before for store of hi2c handler.
uint8_t * sensors_CayennelFromBckData(uint8_t *sizeOut, SysTime_t *prevMeasureTime)
collecting sensor data into CayenneLppGetBuffer buffer for sending them via LoRaWan,...
void sensors_WriteFromBckToDataBlock(mems_DataBlock_t *data)
filling the data block from sensor data - store to memory the methods works with _bck_XXXXX senzor,...
sens_ProcessDef_t sensors_Work()
no sequncer processing reading data from sensor according to group specification
void sensorsSeq_Init(uint32_t sensortAppBit, uint32_t mylorawanAppBit)
task sequencer initialization for sensors reading
void sensors_Start()
non squncer processing start of reading - prepare of internal state machine
UTIL_TIMER_Object_t SensorTimerReading
static void tasksensors_Work()
task sensor sequencer
void sensors_Retiming()
stop and start of sensor timer for next measure
static void sensBuffer_Add(const char *format,...)
static void sensBuffer_Reset()
static const sens_GrpTiming_t _groupTiming[]
definition of sensors group
static void sensBuffer_Send()
static char _sensBuffer[1024]
static char * sensBuffer_Get()
static void sensors_Read(sens_ReadingGrp_t grp)
reading sensor one by one in specified group
SysTime_t sensors_GetTimeFromBlock(const mems_DataBlock_t *data)
getting the SysTime_t from block data of memory
static int getCount_Sensors()
static void tasksensors_OnTimeout()
void i2c_OnOff(uint8_t onOff)
possible to I2C turn on/off - cumulative
static const sens_processing_t _sensors[]
static uint8_t sensors_Service()
void sensors_CopyToBck()
The copying data from current sensors buffer to backUp - _bck_XXXXX.
sens_ProcessDef_t ProcessDef
uint8_t sensors_ReadToBckFromDataBlock(const mems_DataBlock_t *data)
reading from memory block and filling specified sensor from memory - ready for sensors_CayennelData t...
static int sensors_OnOff(sens_ReadingGrp_t grp, int onOff)
On/Off sensors according to group.
sens_ProcessDef_t
State machine states for the sensor reading process.
systemParams_t _systemParams
systemParams_Sensors_t
Bitmask of sensor modules that are enabled / available for data collection. Used in systemParams_t....
#define SENSORS_DATASIZE
Total size in bytes of one packed sensor data record. Computed as the sum of all enabled sensor struc...
#define SYSTEMPARAMS_BATTIMESEND
The time, in seconds, the battery level sending interval - 12h.
uint8_t systemParams_IsSensorAvaiable(systemParams_Sensors_t sensorType)
Check whether a particular sensor is enabled in _systemParams.AvailableSensors.
Sensor data record stored as one element in the flash circular queue.
uint8_t Data[(sizeof(SysTime_t)+sizeof(tmphm_sht45_t)+0+0+sizeof(bar_bmp585_t)+0+0)]
the definition for group of sensor sens_ReadingGrp_t the number of readings and timeout for reading d...
sensor definition - interface
int8_t(* Is)(I2C_HandleTypeDef *hi2c, int8_t tryInit)
HAL_StatusTypeDef(* Read)(I2C_HandleTypeDef *hi2c)
systemParams_Sensors_t Type
int8_t(* Service)(I2C_HandleTypeDef *hi2c)
sens_GrpTiming_t GroupTiming
HAL_StatusTypeDef(* Off)(I2C_HandleTypeDef *hi2c)
HAL_StatusTypeDef(* Init)(I2C_HandleTypeDef *hi2c)
HAL_StatusTypeDef(* On)(I2C_HandleTypeDef *hi2c)
void(* LogData)(char *buf)
Non-blocking timer utility – similar to HAL_Delay but without CPU blocking.
HAL_StatusTypeDef tmphm_sht45_On(I2C_HandleTypeDef *hi2c)
Zapnutie sensora dummy.
HAL_StatusTypeDef tmphm_sht45_Init(I2C_HandleTypeDef *hi2c)
initialization, check if sensor is present or not. Checks main (0x44) and alternative address (0x45) ...
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
tmphm_sht45_t _bck_tmphm_sht45Data
Snapshot copy of the last completed SHT45 measurement; used for LoRaWAN transmission.
HAL_StatusTypeDef tmphm_sht45_Off(I2C_HandleTypeDef *hi2c)
turn off sensor - dummy
tmphm_sht45_t _tmphm_sht45Data
Live measurement data from the SHT45 sensor; updated by tmphm_sht45_Read().
int8_t tmphm_sht45_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit)
check if tempHum sensor is present
void sleeper_SetSleepMS(sleeper_t *v, uint32_t sleepMS)
Change the sleep duration and restart the timer from now.
void sleeper_Next(sleeper_t *v)
Restart the timer so the next period begins from now. InicTime is updated to the current HAL tick.
int sleeper_IsElapsed(const sleeper_t *v)
Check whether the configured time interval has elapsed.