|
L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
|
#include "main.h"#include "mysensors.h"#include "mysensors_base.h"#include "i2c.h"#include "utils/utils.h"#include "utils/mydefs.h"#include "stm32_timer.h"#include "stm32_seq.h"#include "adc_if.h"#include "CayenneLpp.h"#include <stdio.h>#include <string.h>#include <inttypes.h>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 () |
| |
| sens_ProcessDef_t | sensors_Work () |
| |
| void | sensors_Init (I2C_HandleTypeDef *hi2c) |
| Initialization of all sensors, must be called before for store of hi2c handler. | |
| void | sensors_Retiming () |
| stop and start of sensor timer for next measure | |
| 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, SysTime_t *prevMeasureTime) |
| collecting sensor data into CayenneLppGetBuffer buffer for sending them via LoRaWan, the methods works with _bck_XXXXX sensor data, not with real. The measure time is added only if time distance is bigger than 1min: | |
| 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 | |
| SysTime_t | sensors_GetTimeFromBlock (const mems_DataBlock_t *data) |
| getting the SysTime_t from block data of memory | |
Variables | |
| static const sens_GrpTiming_t | _groupTiming [] |
| definition of sensors group | |
| static const sens_processing_t | _sensors [] |
| struct { | |
| I2C_HandleTypeDef * Hi2c | |
| sens_ProcessDef_t ProcessDef | |
| int8_t GroupInxTiming: 4 | |
| sleeper_t ProcessDelay | |
| uint8_t GroupReadCount | |
| UTIL_TIMER_Object_t SensorTimerReading | |
| uint8_t SensorSeqID: 4 | |
| uint8_t MylorawanSeqID: 4 | |
| SysTime_t MeasureTime | |
| } | _ |
| anonymous global struct for current sensor data flow | |
| static char | _sensBuffer [1024] = {} |
| static int | _i2cOnOff = 1 |
| enum 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.
|
static |
Definition at line 142 of file mysensors.c.
References _groupTiming.
Referenced by sensors_NextGroup().
|
static |
Definition at line 146 of file mysensors.c.
References _sensors.
Referenced by sensors_Init(), sensors_NextGroup(), sensors_OnOff(), sensors_Read(), and sensors_Service().
| void i2c_OnOff | ( | uint8_t | onOff | ) |
possible to I2C turn on/off - cumulative
Definition at line 190 of file mysensors.c.
References _i2cOnOff, MX_I2C2_DeInit(), MX_I2C2_Init(), Power3v3_Off(), and Power3v3_On().
Referenced by main(), nfc_FactoryReset(), nfc_ReadMeasureNFC(), nfc_ReadSystemParams(), nfc_WriteMeasureData(), nfc_WriteMeasureNFC(), nfc_WriteSystemParams(), and sensors_Work().
|
static |
Definition at line 159 of file mysensors.c.
References _sensBuffer.
Referenced by sensors_CayennelFromBckData(), and sensors_Read().
|
static |
Definition at line 169 of file mysensors.c.
References _sensBuffer.
Referenced by sensors_Read().
|
static |
Definition at line 154 of file mysensors.c.
References _sensBuffer.
Referenced by sensors_CayennelFromBckData(), and sensors_Read().
|
static |
Definition at line 174 of file mysensors.c.
References _sensBuffer, and writeLogNL().
Referenced by sensors_CayennelFromBckData(), and sensors_Read().
| uint8_t * sensors_CayennelFromBckData | ( | uint8_t * | sizeOut, |
| SysTime_t * | prevMeasureTime ) |
collecting sensor data into CayenneLppGetBuffer buffer for sending them via LoRaWan, the methods works with _bck_XXXXX sensor data, not with real.
The measure time is added only if time distance is bigger than 1min:
| sizeOut | - the size(bytes) in buffer, the size is max 254, uint8_t is enough |
| prevMeasureTime | the previous measure time, 0 or NULL - is not specified, no time is added |
Definition at line 488 of file mysensors.c.
References _, _batPercLevel, _bck_bar_bmp585Data, _bck_tmphm_sht45Data, _memsMainBlock, CayenneLppAddBarometricPressure(), CayenneLppAddBatteryPerc(), CayenneLppAddConcentration(), CayenneLppAddLuminosity(), CayenneLppAddParticulateMatter_1_0(), CayenneLppAddParticulateMatter_2_5(), CayenneLppAddRelativeHumidity(), CayenneLppAddTemperature(), CayenneLppAddTimeMeasureABS(), CayenneLppAddTimeMeasureMIN16(), CayenneLppAddTimeMeasureMIN8(), CayenneLppGetBuffer(), CayenneLppGetSize(), CayenneLppReset(), mems_WriteMainBlock(), PRIf_02, PRIf_02D, sensBuffer_Add(), sensBuffer_Reset(), sensBuffer_Send(), and SYSTEMPARAMS_BATTIMESEND.
Referenced by myloraWan_PrepareSendingBuffer().
| void sensors_CopyToBck | ( | ) |
The copying data from current sensors buffer to backUp - _bck_XXXXX.
Definition at line 463 of file mysensors.c.
References _bar_bmp585Data, _bck_bar_bmp585Data, _bck_tmphm_sht45Data, and _tmphm_sht45Data.
Referenced by myloraWan_MeasureFinish().
| SysTime_t sensors_GetTimeFromBlock | ( | const mems_DataBlock_t * | data | ) |
getting the SysTime_t from block data of memory
| the | time of measure - UNIX time |
Definition at line 683 of file mysensors.c.
References mems_DataBlock_t::Data.
Referenced by myLoraWan_LastDataSend(), and myloraWan_MeasureFinish().
| void sensors_Init | ( | I2C_HandleTypeDef * | hi2c | ) |
Initialization of all sensors, must be called before for store of hi2c handler.
| hi2c |
Definition at line 413 of file mysensors.c.
References _, _sensors, getCount_Sensors(), SENS_GRP_ALL, sensors_OnOff(), systemParams_IsSensorAvaiable(), and writeLog().
Referenced by main(), and sensors_Work().
|
static |
Move to next used group in _sensors[].
Definition at line 271 of file mysensors.c.
References _, _groupTiming, _sensors, getCount_GroupTiming(), and getCount_Sensors().
Referenced by sensors_Start(), and sensors_Work().
|
static |
On/Off sensors according to group.
| grp | - specified group, if SENS_GRP_LAST - all sensors |
Definition at line 216 of file mysensors.c.
References _, _sensors, getCount_Sensors(), SENS_GRP_ALL, systemParams_IsSensorAvaiable(), and writeLog().
Referenced by sensors_Init(), and sensors_Work().
|
static |
reading sensor one by one in specified group
| grp | specified group, if SENS_GRP_LAST - all sensors |
Definition at line 245 of file mysensors.c.
References _, _sensors, _tryInit, getCount_Sensors(), SENS_GRP_ALL, sensBuffer_Add(), sensBuffer_Get(), sensBuffer_Reset(), sensBuffer_Send(), and systemParams_IsSensorAvaiable().
Referenced by sensors_Work().
| 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
| size | of total read from data block, 0 - if is other than expected data |
Definition at line 646 of file mysensors.c.
References _, _bck_bar_bmp585Data, _bck_tmphm_sht45Data, mems_DataBlock_t::Data, MEMS_DATATYPE_SENSOR, and mems_DataBlock_t::Type.
Referenced by myloraWan_PrepareSendingBuffer().
| void sensors_Retiming | ( | ) |
stop and start of sensor timer for next measure
Definition at line 438 of file mysensors.c.
References _, _systemParams, and tasksensors_OnTimeout().
Referenced by main(), and tasksensors_Work().
|
static |
Definition at line 284 of file mysensors.c.
References _, _sensors, getCount_Sensors(), and systemParams_IsSensorAvaiable().
Referenced by sensors_Work().
| void sensors_Start | ( | ) |
Definition at line 333 of file mysensors.c.
References _, SENS_BEGIN, sensors_NextGroup(), and sleeper_SetSleepMS().
Referenced by tasksensors_OnTimeout().
| sens_ProcessDef_t sensors_Work | ( | ) |
Definition at line 342 of file mysensors.c.
References _, _groupTiming, 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().
| 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 604 of file mysensors.c.
References _, _bck_bar_bmp585Data, _bck_tmphm_sht45Data, 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().
| 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 454 of file mysensors.c.
References _, tasksensors_OnTimeout(), and tasksensors_Work().
Referenced by main().
|
static |
Definition at line 322 of file mysensors.c.
References _, _systemParams, CFG_SEQ_Prio_0, and sensors_Start().
Referenced by sensors_Retiming(), and sensorsSeq_Init().
|
static |
task sensor sequencer
Definition at line 301 of file mysensors.c.
References _, CFG_SEQ_Prio_0, SENS_DATAREADY, SENS_DONE, sensors_Retiming(), and sensors_Work().
Referenced by sensorsSeq_Init().
| struct { ... } _ |
anonymous global struct for current sensor data flow
|
static |
definition of sensors group
Definition at line 84 of file mysensors.c.
Referenced by getCount_GroupTiming(), sensors_NextGroup(), and sensors_Work().
|
static |
Definition at line 189 of file mysensors.c.
Referenced by i2c_OnOff().
|
static |
Definition at line 152 of file mysensors.c.
Referenced by sensBuffer_Add(), sensBuffer_Get(), sensBuffer_Reset(), and sensBuffer_Send().
|
static |
Definition at line 94 of file mysensors.c.
Referenced by getCount_Sensors(), sensors_Init(), sensors_NextGroup(), sensors_OnOff(), sensors_Read(), and sensors_Service().
| int8_t GroupInxTiming |
index of current group process - max 7 groups, can be negative
Definition at line 129 of file mysensors.c.
| uint8_t GroupReadCount |
counter or reading for group -> sens_GrpTiming_t.MaxReadCount
Definition at line 131 of file mysensors.c.
| I2C_HandleTypeDef* Hi2c |
current I2C handler
Definition at line 127 of file mysensors.c.
| SysTime_t MeasureTime |
time when measure was done
Definition at line 138 of file mysensors.c.
| uint8_t MylorawanSeqID |
bit sequencer for mylorawan - the measure is finished, data processing send
Definition at line 136 of file mysensors.c.
| sens_ProcessDef_t ProcessDef |
process reading sensor data, sensor Reading sequence must start via sensors_Start
Definition at line 128 of file mysensors.c.
| sleeper_t ProcessDelay |
global process timing -> _groupTiming
Definition at line 130 of file mysensors.c.
| uint8_t SensorSeqID |
bit sequencer for sensor reading CFG_SEQ_Task_Sensors - max 4 bit, CFG_SEQ_Task_Sensors
Definition at line 135 of file mysensors.c.
| UTIL_TIMER_Object_t SensorTimerReading |
semsor timer reading
Definition at line 134 of file mysensors.c.