|
L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
|
#include "mylora_process.h"#include "main.h"#include "rtc.h"#include "mysensors.h"#include "mysensors_base.h"#include "sys_app.h"#include "stm32_seq.h"#include "lora_app.h"#include "mymems.h"#include "CayenneLpp.h"#include "LoRaMac.h"#include "nfc.h"#include "i2c.h"#include "adc_if.h"#include <stdio.h>Go to the source code of this file.
Macros | |
| #define | MAX_NOACKREPEATCOUNT 3 |
Functions | |
| static void | myLoraWan_ResetDataDefault () |
| static uint8_t | myLoRaWAN_GetMaxPayloadSize (void) |
| Get the maximum application payload size for the current data rate. Returns 0 if the query fails or channel is not available. | |
| static void | myLoraWan_Reconnect () |
| Reconnect to LoRa gateway. In case is measure data are queued, the myloraWan_MeasureFinish is called via sequencer to process current measure data. | |
| static void | myLoraWan_StartReconnect () |
| StartReconnect - processing of myLoraWan_Reconnect via sequencer in case ConnectedCount is not falled on 0. | |
| static LmHandlerErrorStatus_t | LoRaWAN_SendConfirmedData (uint8_t *data, uint8_t dataSize, uint8_t port) |
| Send confirmed data to LoRaWAN network. | |
| static uint8_t | myloraWan_PrepareSendingBuffer (const mems_DataBlock_t *data, uint8_t reset, uint8_t maxSize, SysTime_t prevMeasureTime) |
| the preparing _currentSendingDataBuffer/_currentSendingDataSz from CayennelLpp to send data to LoRaWan gateway | |
| static void | myloraWan_MeasureFinish () |
| the measure has been finished, sensor data save to memory or local buffer(in case if no memory is exist or is not storing set) | |
| static void | myLoraWan_LastDataSend () |
| take data from LIFO - last data and send. Cannot be nested only if is LoRa connected | |
| void | OnLoRaWanConnected (void) |
| Called after LoRaWAN successfully connects to the server. | |
| void | OnTimeSynchronized (void) |
| Called after date/time has been synchronized from LoRaWAN. | |
| void | OnLoRaWANRxData (LmHandlerAppData_t *appData, LmHandlerRxParams_t *params) |
| Handle received downlink data from LoRaWAN server. | |
| void | OnLoRaWANTxData (LmHandlerTxParams_t *params) |
| Handle transmission event callback. | |
| void | myloraWan_Init (uint8_t myloraWanAppBit) |
| initialization of myloraWan process, sequencer | |
Variables | |
| struct { | |
| uint8_t MyloraWanAppBit:4 | |
| uint8_t ConnectedCount:5 | |
| uint8_t NoAckRepeatCount:4 | |
| uint8_t IsDataSending:1 | |
| uint8_t IsMeasureQueued:1 | |
| uint8_t IsConnected:1 | |
| uint8_t CurrentSendingDataBuffer [256] | |
| uint8_t CurrentSendingDataSz | |
| int8_t FromEndInx:5 | |
| uint8_t AckFromServer:1 | |
| loraWanPort_t LoraWanPort | |
| uint16_t DataSendSz | |
| uint16_t DataSendInx | |
| const uint8_t * DataSendBuffer | |
| } | _ = {} |
| anonymous global struct for saving of current mylorawan data flow | |
| #define MAX_NOACKREPEATCOUNT 3 |
Definition at line 24 of file mylora_process.c.
Referenced by OnLoRaWanConnected(), and OnLoRaWANTxData().
|
static |
Send confirmed data to LoRaWAN network.
This function sends data that requires acknowledgment from the server. The server must respond with a downlink acknowledgment. This is useful for critical data that must be verified as received.
| data | Pointer to the data buffer to send |
| dataSize | Size of the data in bytes (max 242 bytes) |
| port | LoRaWAN application port (typically 2) |
Definition at line 118 of file mylora_process.c.
References _, and writeLog().
Referenced by myLoraWan_LastDataSend().
|
static |
Get the maximum application payload size for the current data rate. Returns 0 if the query fails or channel is not available.
Definition at line 60 of file mylora_process.c.
Referenced by myLoraWan_LastDataSend().
| void myloraWan_Init | ( | uint8_t | myloraWanAppBit | ) |
initialization of myloraWan process, sequencer
| myloraWanAppBit | the bit for sequencer - this value, +2 |
Definition at line 646 of file mylora_process.c.
References _, myLoraWan_LastDataSend(), myloraWan_MeasureFinish(), and myLoraWan_Reconnect().
Referenced by main().
|
static |
take data from LIFO - last data and send. Cannot be nested only if is LoRa connected
Definition at line 278 of file mylora_process.c.
References _, _memsMainBlock, _systemParams, CayenneLppMaxBuffer(), CFG_SEQ_Prio_0, LoRaWAN_SendConfirmedData(), mems_GetLastData(), myLoRaWAN_GetMaxPayloadSize(), myloraWan_PrepareSendingBuffer(), sensors_GetTimeFromBlock(), SYS_GetBatteryLevel(), SYSTEMPARAMS_BATTMINWORK, and writeLog().
Referenced by myloraWan_Init().
|
static |
the measure has been finished, sensor data save to memory or local buffer(in case if no memory is exist or is not storing set)
the task myLoraWan_LastDataSend is started for start of sending data LIFO direction
Definition at line 203 of file mylora_process.c.
References _, _memsMainBlock, _systemParams, CFG_SEQ_Prio_0, measureDataNFC_t::Data, hi2c2, mems_AddData(), MEMS_DATATYPE_SENSOR, mems_InicBuffer(), myloraWan_PrepareSendingBuffer(), nfc_WriteMeasureData(), sensors_CopyToBck(), sensors_GetTimeFromBlock(), sensors_WriteFromBckToDataBlock(), measureDataNFC_t::UTCMeasureTime, and writeLog().
Referenced by myloraWan_Init().
|
static |
the preparing _currentSendingDataBuffer/_currentSendingDataSz from CayennelLpp to send data to LoRaWan gateway
| data | - memory data block, sensors measured values |
| reset | - the sending buffer is reset or not(adding for _systemParams.SendInOnePacket == 1) |
| maxSize | - the max size of payload for current datarate, 0 - no buffer is checked |
| prevMeasureTime | - the time of previous block or 0, if time is unknown or is 1st |
| 1 | - data stored in _currentSendingDataBuffer for send |
| 0 | - not stored, the maximum buffer has been reached |
Definition at line 177 of file mylora_process.c.
References _, sensors_CayennelFromBckData(), and sensors_ReadToBckFromDataBlock().
Referenced by myLoraWan_LastDataSend(), and myloraWan_MeasureFinish().
|
static |
Reconnect to LoRa gateway. In case is measure data are queued, the myloraWan_MeasureFinish is called via sequencer to process current measure data.
Definition at line 71 of file mylora_process.c.
References _, CFG_SEQ_Prio_0, LORAWAN_DEFAULT_ACTIVATION_TYPE, and writeLog().
Referenced by myloraWan_Init().
|
static |
Definition at line 49 of file mylora_process.c.
References _, and _systemParams.
Referenced by OnLoRaWanConnected(), and OnLoRaWANTxData().
|
static |
StartReconnect - processing of myLoraWan_Reconnect via sequencer in case ConnectedCount is not falled on 0.
Definition at line 92 of file mylora_process.c.
References _, CFG_SEQ_Prio_0, and writeLog().
Referenced by OnLoRaWANTxData().
| void OnLoRaWanConnected | ( | void | ) |
Called after LoRaWAN successfully connects to the server.
This function is called when the LoRaWAN join process completes successfully. It performs time synchronization with the LoRaWAN server by requesting the device time, which updates the RTC with the server's time.
Definition at line 416 of file mylora_process.c.
References _, _systemParams, CFG_SEQ_Prio_0, MAX_NOACKREPEATCOUNT, myLoraWan_ResetDataDefault(), and writeLog().
Referenced by OnJoinRequest().
| void OnLoRaWANRxData | ( | LmHandlerAppData_t * | appData, |
| LmHandlerRxParams_t * | params ) |
Handle received downlink data from LoRaWAN server.
This callback function is triggered when the device receives data from the LoRaWAN server. This can be a response to a confirmed uplink or an application-level downlink message.
| appData | Received application data including buffer and port |
| params | Receive parameters including RSSI, SNR, and downlink counter |
Definition at line 477 of file mylora_process.c.
References _, _systemParams, _systemParamsBck, CFG_SEQ_Prio_0, LORAWANPORT_CONFIG_GET, LORAWANPORT_CONFIG_GET_LAST, LORAWANPORT_CONFIG_SET_PART, mems_RemoveLastData(), systemParams_CheckCRC(), systemParams_SetCRCSystemParams(), systemParams_SetFromPart(), and writeLog().
Referenced by OnRxData().
| void OnLoRaWANTxData | ( | LmHandlerTxParams_t * | params | ) |
Handle transmission event callback.
This callback is triggered after a transmission attempt, whether successful or not. It provides information about whether an ACK was received for confirmed messages.
| params | Transmission parameters including status and ACK received flag |
Definition at line 597 of file mylora_process.c.
References _, CFG_SEQ_Prio_0, MAX_NOACKREPEATCOUNT, myLoraWan_ResetDataDefault(), myLoraWan_StartReconnect(), and writeLog().
Referenced by OnTxData().
| void OnTimeSynchronized | ( | void | ) |
Called after date/time has been synchronized from LoRaWAN.
This function is called when the device receives a time synchronization response (DeviceTimeAns) from the LoRaWAN server. The RTC has already been updated with the server's time when this function is called.
Add your custom code here to perform actions after time synchronization, such as updating time-dependent schedules, logging the sync event, or triggering time-based operations.
Definition at line 452 of file mylora_process.c.
References systemParams_CorrectSystemTime(), and writeLog().
Referenced by OnSysTimeUpdate().
| struct { ... } _ |
anonymous global struct for saving of current mylorawan data flow
| uint8_t AckFromServer |
the ACK from server came, data can be processed
Definition at line 41 of file mylora_process.c.
| uint8_t ConnectedCount |
the connection counter for repeating reconnect after NoAckRepeatCount falled on 0 - max 32, _systemParams.LoRaRepeatTryConnect
Definition at line 33 of file mylora_process.c.
| uint8_t CurrentSendingDataBuffer[256] |
buffer for sending data - max 222, with reserve
Definition at line 38 of file mylora_process.c.
| uint8_t CurrentSendingDataSz |
the count of data in buffer
Definition at line 39 of file mylora_process.c.
| const uint8_t* DataSendBuffer |
pointer to data for send - if not null, this buffer is processed
Definition at line 46 of file mylora_process.c.
| uint16_t DataSendInx |
the index into DataSendBuffer from the context is copying
Definition at line 45 of file mylora_process.c.
| uint16_t DataSendSz |
the size of buffer to send, the last buffer is send with port LoraWanPort+1
Definition at line 44 of file mylora_process.c.
| int8_t FromEndInx |
the index from end of memory to send data in case if _systemParams.SendInOnePacket - more data in one pack
Definition at line 40 of file mylora_process.c.
| uint8_t IsConnected |
the connection to gateway is ON/OFF
Definition at line 37 of file mylora_process.c.
| uint8_t IsDataSending |
data is in process of sending, the memory is blocked, until IsDataSending is ON
Definition at line 35 of file mylora_process.c.
| uint8_t IsMeasureQueued |
the measure has been finished, but _IsDataSending is ON and memory is blocked, so current measurement is queued
Definition at line 36 of file mylora_process.c.
| loraWanPort_t LoraWanPort |
the port for data sending
Definition at line 42 of file mylora_process.c.
| uint8_t MyloraWanAppBit |
Sequencer bits, CFG_SEQ_Task_MyLora, CFG_SEQ_Task_MyLoraReconect, CFG_SEQ_Task_MyLoraResend - !!! max 4 bits !!!
Definition at line 32 of file mylora_process.c.
| uint8_t NoAckRepeatCount |
the count of repeating to resend data in case if no ACK comes from gateway - max 16 - default
Definition at line 34 of file mylora_process.c.