16#include "common/SerialModemBase.h"
21static constexpr uint32_t MLR_DEFAULT_BAUDRATE = 19200;
26enum class MLR_Modem_Response
50using MLR_Modem_Error = ModemError;
55enum class MLR_ModemMode : uint8_t
66enum class MLR_ModemSpreadFactor : uint8_t
77enum class MLR_ModemParserState
118 MLR_Modem_Event(ModemError err, MLR_Modem_Response t, int32_t val,
const uint8_t *p, uint16_t l)
139 MLR_Modem_Error
begin(Stream &pUart, MLR_Modem_AsyncCallback pCallback =
nullptr);
148 MLR_Modem_Error
SetChannel(uint8_t channel,
bool saveValue);
156 MLR_Modem_Error
GetChannel(uint8_t *pChannel);
165 MLR_Modem_Error
SetMode(MLR_ModemMode mode,
bool saveValue);
173 MLR_Modem_Error
GetMode(MLR_ModemMode *pMode);
182 MLR_Modem_Error
SetSpreadFactor(MLR_ModemSpreadFactor sf,
bool saveValue);
233 MLR_Modem_Error
SetGroupID(uint8_t gi,
bool saveValue);
249 MLR_Modem_Error
GetUserID(uint16_t *pUserID);
314 MLR_Modem_Error
SetBaudRate(uint32_t baudRate,
bool saveValue);
324 MLR_Modem_Error
SendRawCommand(
const char *command,
char *responseBuffer,
size_t bufferSize, uint32_t timeoutMs = 500);
342 MLR_Modem_Error
TransmitData(
const uint8_t *pMsg, uint8_t len);
387 MLR_Modem_Error
GetPacket(
const uint8_t **ppData, uint8_t *len);
423 ModemParseResult
parse()
override;
430 ModemParseResult m_HandleReadStart();
431 ModemParseResult m_HandleReadCmdFirstLetter();
432 ModemParseResult m_HandleReadCmdSecondLetter();
433 ModemParseResult m_HandleReadCmdParam();
434 ModemParseResult m_HandleRadioDrSize();
435 ModemParseResult m_HandleRadioDrPayload();
436 ModemParseResult m_HandleReadCmdUntilCR();
437 ModemParseResult m_HandleReadCmdUntilLF();
440 void dispatchAsyncEvent(ModemError error, MLR_Modem_Response responseType, int32_t value = 0,
const uint8_t *pPayload =
nullptr, uint16_t len = 0);
444 ModemError m_HandleMessageHexByte(uint8_t *pValue, uint32_t responseLen,
const char *responsePrefix);
446 ModemError m_HandleMessageHexWord(uint16_t *pValue, uint32_t responseLen,
const char *responsePrefix);
449 ModemError m_HandleMessage_RS(int16_t *pRssi);
451 ModemError m_HandleMessage_RA(int16_t *pRssi);
454 ModemError m_HandleMessage_SN(uint32_t *pSerialNumber);
456 ModemError m_HandleMessage_IZ();
459 MLR_Modem_Response m_asyncExpectedResponse;
460 MLR_ModemParserState m_parserState;
463 bool m_drMessagePresent;
464 uint8_t m_drMessageLen;
465 uint8_t m_drMessage[300];
468 bool m_irMessagePresent;
471 MLR_ModemMode m_mode;
472 MLR_Modem_AsyncCallback m_pCallback;
Main class for interfacing with the MLR Modem.
Definition: MLR_Modem.h:131
void onCommandComplete(ModemError result) override
Optional hook called when a queued command finishes.
Definition: MLR_Modem.cpp:460
void DeletePacket()
Deletes the currently stored received packet.
Definition: MLR_Modem.h:404
MLR_Modem_Error SetGroupID(uint8_t gi, bool saveValue)
Sets the Group ID.
Definition: MLR_Modem.cpp:198
const char * getLogPrefix() const override
Definition: MLR_Modem.h:426
MLR_Modem_Error GetRssiLastRx(int16_t *pRssi)
Gets the RSSI (Received Signal Strength) of the last successfully received packet.
Definition: MLR_Modem.cpp:225
MLR_Modem_Error GetEquipmentID(uint8_t *pEI)
Gets the Equipment ID (self ID).
Definition: MLR_Modem.cpp:183
MLR_Modem_Error SetSpreadFactor(MLR_ModemSpreadFactor sf, bool saveValue)
Sets the LoRa spreading factor.
Definition: MLR_Modem.cpp:163
MLR_Modem_Error SetCarrierSenseRssiOutput(uint8_t ciValue, bool saveValue)
Sets the Carrier Sense RSSI Output setting.
Definition: MLR_Modem.cpp:259
ModemParseResult parse() override
Main parser state machine step. Must use readByte() and update _rxBuffer / _rxIndex.
Definition: MLR_Modem.cpp:503
void Work()
Main processing loop for the driver. This function must be called regularly (e.g.,...
Definition: MLR_Modem.h:419
MLR_Modem_Error SetMode(MLR_ModemMode mode, bool saveValue)
Sets the wireless communication mode (e.g., FSK or LoRa).
Definition: MLR_Modem.cpp:142
MLR_Modem_Error TransmitData(const uint8_t *pMsg, uint8_t len)
Transmits data over the wireless link.
Definition: MLR_Modem.cpp:341
MLR_Modem_Error GetCarrierSenseRssiOutput(uint8_t *pCiValue)
Gets the Carrier Sense RSSI Output setting.
Definition: MLR_Modem.cpp:264
MLR_Modem_Error GetRssiCurrentChannelAsync()
Asynchronously requests the current RSSI of the configured channel. The result will be delivered via ...
Definition: MLR_Modem.cpp:398
MLR_Modem_Error SetEquipmentID(uint8_t ei, bool saveValue)
Sets the Equipment ID (self ID).
Definition: MLR_Modem.cpp:178
void SetAsyncCallback(MLR_Modem_AsyncCallback pCallback)
Sets the asynchronous callback function.
Definition: MLR_Modem.h:393
MLR_Modem_Error GetChannel(uint8_t *pChannel)
Gets the current frequency channel.
Definition: MLR_Modem.cpp:137
MLR_Modem_Error SendRawCommand(const char *command, char *responseBuffer, size_t bufferSize, uint32_t timeoutMs=500)
Sends a raw command string and waits synchronously for a response.
Definition: MLR_Modem.cpp:325
MLR_Modem_Error GetMode(MLR_ModemMode *pMode)
Gets the current wireless communication mode.
Definition: MLR_Modem.cpp:158
MLR_Modem_Error SendRawCommandAsync(const char *command, uint32_t timeoutMs=500)
Sends a raw command string asynchronously. The response will be delivered via the AsyncCallback as ML...
Definition: MLR_Modem.cpp:330
MLR_Modem_Error GetUserID(uint16_t *pUserID)
Gets the User ID.
Definition: MLR_Modem.cpp:208
MLR_Modem_Error begin(Stream &pUart, MLR_Modem_AsyncCallback pCallback=nullptr)
Initializes the modem driver.
Definition: MLR_Modem.cpp:103
MLR_Modem_Error SetDestinationID(uint8_t di, bool saveValue)
Sets the Destination ID.
Definition: MLR_Modem.cpp:188
MLR_Modem_Error GetRssiCurrentChannel(int16_t *pRssi)
Gets the current RSSI (noise floor) of the configured channel.
Definition: MLR_Modem.cpp:242
MLR_Modem_Error GetDestinationID(uint8_t *pDI)
Gets the Destination ID.
Definition: MLR_Modem.cpp:193
MLR_Modem_Error SoftReset()
Performs a software reset of the modem.
Definition: MLR_Modem.cpp:320
MLR_Modem_Error SetChannel(uint8_t channel, bool saveValue)
Sets the frequency channel.
Definition: MLR_Modem.cpp:128
MLR_Modem_Error GetBaudRate(uint8_t *pBaudRate)
Gets the UART Baud Rate setting.
Definition: MLR_Modem.cpp:299
MLR_Modem_Error TransmitDataAsync(const uint8_t *pMsg, uint8_t len)
Transmits data over the wireless link asynchronously. The result will be delivered via the AsyncCallb...
Definition: MLR_Modem.cpp:385
void onRxDataReceived() override
Definition: MLR_Modem.cpp:435
MLR_Modem_Error FactoryReset()
Resets the modem to factory settings.
Definition: MLR_Modem.cpp:286
MLR_Modem_Error SetBaudRate(uint32_t baudRate, bool saveValue)
Sets the UART Baud Rate.
Definition: MLR_Modem.cpp:304
MLR_Modem_Error GetSerialNumberAsync()
Asynchronously requests the modem's serial number. The result will be delivered via the AsyncCallback...
Definition: MLR_Modem.cpp:410
bool HasPacket()
Checks if a new radio packet has been received.
Definition: MLR_Modem.h:399
MLR_Modem_Error GetSpreadFactor(MLR_ModemSpreadFactor *pSf)
Gets the current LoRa spreading factor.
Definition: MLR_Modem.cpp:173
MLR_Modem_Error GetGroupID(uint8_t *pGI)
Gets the Group ID.
Definition: MLR_Modem.cpp:203
MLR_Modem_Error GetSerialNumber(uint32_t *pSn)
Gets the modem's serial number.
Definition: MLR_Modem.cpp:269
MLR_Modem_Error GetPacket(const uint8_t **ppData, uint8_t *len)
Retrieves the last received packet.
Definition: MLR_Modem.cpp:422
Base class handling low-level serial I/O, debugging, and async transaction logic.
Definition: SerialModemBase.h:92
void update()
Main processing loop. Must be called frequently. Handles command queue, transmission,...
Definition: SerialModemBase.cpp:50
Represents an event from the modem.
Definition: MLR_Modem.h:98
MLR_Modem_Event()
Definition: MLR_Modem.h:107
MLR_Modem_Event(ModemError err, MLR_Modem_Response t)
Definition: MLR_Modem.h:110
MLR_Modem_Event(ModemError err, MLR_Modem_Response t, int32_t val, const uint8_t *p, uint16_t l)
Definition: MLR_Modem.h:118
const uint8_t * pPayload
Pointer to payload data (e.g., for DataReceived)
Definition: MLR_Modem.h:102
MLR_Modem_Event(ModemError err, MLR_Modem_Response t, int32_t val)
Definition: MLR_Modem.h:114
int32_t value
Numerical value associated with the response.
Definition: MLR_Modem.h:101
uint16_t payloadLen
Length of payload data.
Definition: MLR_Modem.h:103
MLR_Modem_Error error
Error code.
Definition: MLR_Modem.h:99
MLR_Modem_Response type
Type of response.
Definition: MLR_Modem.h:100