Main class for interfacing with the MLR Modem. More...
#include <MLR_Modem.h>
Public Member Functions | |
| MLR_Modem_Error | begin (Stream &pUart, MLR_Modem_AsyncCallback pCallback=nullptr) |
| Initializes the modem driver. | |
| MLR_Modem_Error | SetChannel (uint8_t channel, bool saveValue) |
| Sets the frequency channel. | |
| MLR_Modem_Error | GetChannel (uint8_t *pChannel) |
| Gets the current frequency channel. | |
| MLR_Modem_Error | SetMode (MLR_ModemMode mode, bool saveValue) |
| Sets the wireless communication mode (e.g., FSK or LoRa). | |
| MLR_Modem_Error | GetMode (MLR_ModemMode *pMode) |
| Gets the current wireless communication mode. | |
| MLR_Modem_Error | SetSpreadFactor (MLR_ModemSpreadFactor sf, bool saveValue) |
| Sets the LoRa spreading factor. | |
| MLR_Modem_Error | GetSpreadFactor (MLR_ModemSpreadFactor *pSf) |
| Gets the current LoRa spreading factor. | |
| MLR_Modem_Error | SetEquipmentID (uint8_t ei, bool saveValue) |
| Sets the Equipment ID (self ID). | |
| MLR_Modem_Error | GetEquipmentID (uint8_t *pEI) |
| Gets the Equipment ID (self ID). | |
| MLR_Modem_Error | SetDestinationID (uint8_t di, bool saveValue) |
| Sets the Destination ID. | |
| MLR_Modem_Error | GetDestinationID (uint8_t *pDI) |
| Gets the Destination ID. | |
| MLR_Modem_Error | SetGroupID (uint8_t gi, bool saveValue) |
| Sets the Group ID. | |
| MLR_Modem_Error | GetGroupID (uint8_t *pGI) |
| Gets the Group ID. | |
| MLR_Modem_Error | GetUserID (uint16_t *pUserID) |
| Gets the User ID. | |
| MLR_Modem_Error | GetRssiLastRx (int16_t *pRssi) |
| Gets the RSSI (Received Signal Strength) of the last successfully received packet. | |
| MLR_Modem_Error | GetRssiCurrentChannel (int16_t *pRssi) |
| Gets the current RSSI (noise floor) of the configured channel. | |
| MLR_Modem_Error | SetCarrierSenseRssiOutput (uint8_t ciValue, bool saveValue) |
| Sets the Carrier Sense RSSI Output setting. | |
| MLR_Modem_Error | GetCarrierSenseRssiOutput (uint8_t *pCiValue) |
| Gets the Carrier Sense RSSI Output setting. | |
| MLR_Modem_Error | GetSerialNumber (uint32_t *pSn) |
| Gets the modem's serial number. | |
| MLR_Modem_Error | FactoryReset () |
| Resets the modem to factory settings. | |
| MLR_Modem_Error | GetBaudRate (uint8_t *pBaudRate) |
| Gets the UART Baud Rate setting. | |
| MLR_Modem_Error | SetBaudRate (uint32_t baudRate, bool saveValue) |
| Sets the UART Baud Rate. | |
| 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. | |
| 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 MLR_Modem_Response::GenericResponse. | |
| MLR_Modem_Error | TransmitData (const uint8_t *pMsg, uint8_t len) |
| Transmits data over the wireless link. | |
| 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 AsyncCallback as MLR_Modem_Response::MLR_Modem_DtIr. | |
| MLR_Modem_Error | GetRssiCurrentChannelAsync () |
| Asynchronously requests the current RSSI of the configured channel. The result will be delivered via the AsyncCallback. | |
| MLR_Modem_Error | GetSerialNumberAsync () |
| Asynchronously requests the modem's serial number. The result will be delivered via the AsyncCallback. | |
| MLR_Modem_Error | GetPacket (const uint8_t **ppData, uint8_t *len) |
| Retrieves the last received packet. | |
| void | SetAsyncCallback (MLR_Modem_AsyncCallback pCallback) |
| Sets the asynchronous callback function. | |
| bool | HasPacket () |
| Checks if a new radio packet has been received. | |
| void | DeletePacket () |
| Deletes the currently stored received packet. | |
| MLR_Modem_Error | SoftReset () |
| Performs a software reset of the modem. | |
| void | Work () |
| Main processing loop for the driver. This function must be called regularly (e.g., in the Arduino loop()) to parse incoming serial data from the modem. Now calls SerialModemBase::update() internally. | |
Public Member Functions inherited from SerialModemBase | |
| SerialModemBase () | |
| virtual | ~SerialModemBase ()=default |
| void | setDebugStream (Stream *debugStream) |
| Initializes the debug stream. | |
| void | update () |
| Main processing loop. Must be called frequently. Handles command queue, transmission, and response parsing. | |
| bool | isIdle () const |
| Checks if the internal engine is currently idle (no command processing). | |
| bool | isLastCommandComplete () const |
| Checks if the last processed command has finished. Useful for implementing synchronous wrappers. | |
| ModemError | getLastCommandResult () const |
| Gets the result of the last processed command. | |
| const uint8_t * | getRxBuffer () const |
| Accessor for the shared RX buffer. | |
| uint16_t | getRxIndex () const |
| bool | isQueueFull () const |
| Checks if the command queue is full. | |
| bool | isQueueEmpty () const |
| Checks if the command queue is empty. | |
| uint8_t | getQueueCount () const |
| Gets the number of commands currently in the queue. | |
Protected Member Functions | |
| ModemParseResult | parse () override |
| Main parser state machine step. Must use readByte() and update _rxBuffer / _rxIndex. | |
| void | onRxDataReceived () override |
| void | onCommandComplete (ModemError result) override |
| Optional hook called when a queued command finishes. | |
| const char * | getLogPrefix () const override |
Protected Member Functions inherited from SerialModemBase | |
| void | initSerial (Stream &stream) |
| Sets the UART stream to use for modem communication. | |
| ModemError | enqueueCommand (const char *cmd, CommandType type, uint32_t timeoutMs=1000) |
| Enqueues a command for processing. Non-blocking. | |
| ModemError | enqueueTxCommand (const char *cmdHeader, const uint8_t *payload, uint8_t len, const char *suffix=nullptr, uint32_t timeoutMs=2000) |
| Enqueues a data transmission command with payload. | |
| ModemError | setByteValue (const char *cmd, uint8_t value, bool save, const char *respPrefix, size_t respLen) |
| Helper to set a 1-byte value (e.g., @CH0E) and verify the response. | |
| ModemError | getByteValue (const char *cmd, uint8_t *pValue, const char *respPrefix, size_t respLen) |
| Helper to get a 1-byte value. | |
| ModemError | setBoolValue (const char *baseCmd, bool enabled, bool save, const char *respPrefix) |
| Helper to set a boolean value (ON/OF). | |
| ModemError | getBoolValue (const char *cmd, bool *pValue, const char *respPrefix) |
| Helper to get a boolean value (ON/OF). | |
| ModemError | sendRawCommand (const char *command, char *responseBuffer, size_t bufferSize, uint32_t timeoutMs) |
| Sends a raw command string and fills the provided buffer with the response. | |
| ModemError | waitForSyncComplete (uint32_t timeoutMs) |
| Helper to wait for the current command to finish (Pseudo-blocking). Calls update() internally. | |
| void | writeString (const char *str, bool printPrefix=true) |
| void | writeData (const uint8_t *data, size_t len) |
| int | readByte () |
| void | unreadByte (uint8_t c) |
| void | clearUnreadByte () |
| void | flushGarbage (char keepChar=' *') |
| void | startTimeout (uint32_t ms) |
| bool | isTimeout () |
| ModemError | parseResponseHex (const uint8_t *buffer, size_t length, const char *prefix, uint8_t hexDigits, uint32_t *pResult) |
| ModemError | parseResponseDec (const uint8_t *buffer, size_t length, const char *prefix, const char *suffix, size_t suffixLen, int32_t *pResult) |
| virtual ModemParseResult | parse ()=0 |
| Main parser state machine step. Must use readByte() and update _rxBuffer / _rxIndex. | |
| virtual void | onRxDataReceived ()=0 |
| virtual const char * | getLogPrefix () const =0 |
| virtual void | onCommandComplete (ModemError result) |
| Optional hook called when a queued command finishes. | |
Additional Inherited Members | |
Static Protected Member Functions inherited from SerialModemBase | |
| static bool | parseHex (const uint8_t *pData, size_t len, uint32_t *pResult) |
| static bool | parseDec (const uint8_t *pData, size_t len, uint32_t *pResult) |
| static char * | appendStr (char *dest, const char *src, const char *destEnd) |
| static char * | appendHex2 (char *dest, uint8_t val, const char *destEnd) |
| template<size_t N> | |
| static char * | appendStr (char(&destBuf)[N], char *currentPtr, const char *src) |
| template<size_t N> | |
| static char * | appendHex2 (char(&destBuf)[N], char *currentPtr, uint8_t val) |
Protected Attributes inherited from SerialModemBase | |
| Stream * | _uart = nullptr |
| Stream * | _debugStream = nullptr |
| uint8_t | _rxBuffer [RX_BUFFER_SIZE] |
| uint16_t | _rxIndex = 0 |
| int16_t | _oneByteBuf = -1 |
| bool | _debugRxNewLine = true |
Static Protected Attributes inherited from SerialModemBase | |
| static constexpr char | CD_WRITE_OK_RESPONSE [] = "*WR=PS" |
| static constexpr size_t | CD_WRITE_OK_RESPONSE_LEN = 6 |
| static constexpr char | CD_VAL_ON [] = "ON" |
| static constexpr char | CD_VAL_OFF [] = "OF" |
| static constexpr char | CD_CMD_WRITE_SUFFIX [] = "/W" |
| static constexpr size_t | RX_BUFFER_SIZE = 300 |
Main class for interfacing with the MLR Modem.
| MLR_Modem_Error MLR_Modem::begin | ( | Stream & | pUart, |
| MLR_Modem_AsyncCallback | pCallback = nullptr |
||
| ) |
Initializes the modem driver.
| pUart | The Serial port connected to the modem. |
| pCallback | The function to call for async responses and received data. |
|
inline |
Deletes the currently stored received packet.
| MLR_Modem_Error MLR_Modem::FactoryReset | ( | ) |
Resets the modem to factory settings.
| MLR_Modem_Error MLR_Modem::GetBaudRate | ( | uint8_t * | pBaudRate | ) |
Gets the UART Baud Rate setting.
| pBaudRate | Pointer to store the current baud rate code (e.g., '19' for 19200). |
| MLR_Modem_Error MLR_Modem::GetCarrierSenseRssiOutput | ( | uint8_t * | pCiValue | ) |
Gets the Carrier Sense RSSI Output setting.
| pCiValue | Pointer to store the current setting ('00' = OFF, '01' = ON). |
| MLR_Modem_Error MLR_Modem::GetChannel | ( | uint8_t * | pChannel | ) |
Gets the current frequency channel.
| pChannel | Pointer to store the current channel (0x07 - 0x2E). |
| MLR_Modem_Error MLR_Modem::GetDestinationID | ( | uint8_t * | pDI | ) |
Gets the Destination ID.
| pDI | Pointer to store the current Destination ID (0x00 - 0xFF). |
| MLR_Modem_Error MLR_Modem::GetEquipmentID | ( | uint8_t * | pEI | ) |
Gets the Equipment ID (self ID).
| pEI | Pointer to store the current Equipment ID (0x00 - 0xFF). |
| MLR_Modem_Error MLR_Modem::GetGroupID | ( | uint8_t * | pGI | ) |
Gets the Group ID.
| pGI | Pointer to store the current Group ID (0x00 - 0xFF). |
|
inlineoverrideprotectedvirtual |
Implements SerialModemBase.
| MLR_Modem_Error MLR_Modem::GetMode | ( | MLR_ModemMode * | pMode | ) |
Gets the current wireless communication mode.
| pMode | Pointer to store the current mode. |
| MLR_Modem_Error MLR_Modem::GetPacket | ( | const uint8_t ** | ppData, |
| uint8_t * | len | ||
| ) |
Retrieves the last received packet.
| ppData | Pointer to a const uint8_t* that will be set to the packet data. |
*ppData will point to an internal library buffer. This pointer is only valid until the next call to Work() or DeletePacket(). If you need to access the data later, you must copy it to your own buffer. | len | Pointer to a uint8_t that will be set to the packet length. |
| MLR_Modem_Error MLR_Modem::GetRssiCurrentChannel | ( | int16_t * | pRssi | ) |
Gets the current RSSI (noise floor) of the configured channel.
| pRssi | Pointer to store the RSSI value in dBm. |
| MLR_Modem_Error MLR_Modem::GetRssiCurrentChannelAsync | ( | ) |
Asynchronously requests the current RSSI of the configured channel. The result will be delivered via the AsyncCallback.
| MLR_Modem_Error MLR_Modem::GetRssiLastRx | ( | int16_t * | pRssi | ) |
Gets the RSSI (Received Signal Strength) of the last successfully received packet.
| pRssi | Pointer to store the RSSI value in dBm. |
| MLR_Modem_Error MLR_Modem::GetSerialNumber | ( | uint32_t * | pSn | ) |
Gets the modem's serial number.
| pSn | Pointer to store the serial number. |
| MLR_Modem_Error MLR_Modem::GetSerialNumberAsync | ( | ) |
Asynchronously requests the modem's serial number. The result will be delivered via the AsyncCallback.
| MLR_Modem_Error MLR_Modem::GetSpreadFactor | ( | MLR_ModemSpreadFactor * | pSf | ) |
Gets the current LoRa spreading factor.
| pSf | Pointer to store the current spreading factor. |
| MLR_Modem_Error MLR_Modem::GetUserID | ( | uint16_t * | pUserID | ) |
Gets the User ID.
| pUserID | Pointer to store the current User ID (0x0000 - 0xFFFF). |
|
inline |
Checks if a new radio packet has been received.
|
overrideprotectedvirtual |
Optional hook called when a queued command finishes.
Reimplemented from SerialModemBase.
|
overrideprotectedvirtual |
Implements SerialModemBase.
|
overrideprotectedvirtual |
Main parser state machine step. Must use readByte() and update _rxBuffer / _rxIndex.
Implements SerialModemBase.
| MLR_Modem_Error MLR_Modem::SendRawCommand | ( | const char * | command, |
| char * | responseBuffer, | ||
| size_t | bufferSize, | ||
| uint32_t | timeoutMs = 500 |
||
| ) |
Sends a raw command string and waits synchronously for a response.
| command | The null-terminated command string (e.g., "@FV\r\n"). |
| responseBuffer | Buffer to store the raw response line (excluding CRLF). |
| bufferSize | Size of the responseBuffer. |
| timeoutMs | Timeout in milliseconds to wait for the response. |
| MLR_Modem_Error MLR_Modem::SendRawCommandAsync | ( | const char * | command, |
| uint32_t | timeoutMs = 500 |
||
| ) |
Sends a raw command string asynchronously. The response will be delivered via the AsyncCallback as MLR_Modem_Response::GenericResponse.
| command | The null-terminated command string (e.g., "@FV\r\n"). |
| timeoutMs | Timeout in milliseconds to wait for the response. |
|
inline |
Sets the asynchronous callback function.
| pCallback | The callback function. If set to nullptr, no callback will take place. |
| MLR_Modem_Error MLR_Modem::SetBaudRate | ( | uint32_t | baudRate, |
| bool | saveValue | ||
| ) |
Sets the UART Baud Rate.
| baudRate | The baud rate to set (e.g., 9600, 19200). |
| saveValue | If true, saves the setting to non-volatile memory (/W option). |
| MLR_Modem_Error MLR_Modem::SetCarrierSenseRssiOutput | ( | uint8_t | ciValue, |
| bool | saveValue | ||
| ) |
Sets the Carrier Sense RSSI Output setting.
| ciValue | The setting to set ('00' = OFF, '01' = ON). |
| saveValue | If true, saves the setting to non-volatile memory (/W option). |
| MLR_Modem_Error MLR_Modem::SetChannel | ( | uint8_t | channel, |
| bool | saveValue | ||
| ) |
Sets the frequency channel.
| channel | The channel to set (0x07 - 0x2E). |
| saveValue | If true, saves the setting to non-volatile memory (/W option). |
| MLR_Modem_Error MLR_Modem::SetDestinationID | ( | uint8_t | di, |
| bool | saveValue | ||
| ) |
Sets the Destination ID.
| di | The Destination ID to set (0x00 - 0xFF). (0x00 is broadcast) |
| saveValue | If true, saves the setting to non-volatile memory (/W option). |
| MLR_Modem_Error MLR_Modem::SetEquipmentID | ( | uint8_t | ei, |
| bool | saveValue | ||
| ) |
Sets the Equipment ID (self ID).
| ei | The Equipment ID to set (0x00 - 0xFF). |
| saveValue | If true, saves the setting to non-volatile memory (/W option). |
| MLR_Modem_Error MLR_Modem::SetGroupID | ( | uint8_t | gi, |
| bool | saveValue | ||
| ) |
Sets the Group ID.
| gi | The Group ID to set (0x00 - 0xFF). |
| saveValue | If true, saves the setting to non-volatile memory (/W option). |
| MLR_Modem_Error MLR_Modem::SetMode | ( | MLR_ModemMode | mode, |
| bool | saveValue | ||
| ) |
Sets the wireless communication mode (e.g., FSK or LoRa).
| mode | The mode to set (e.g., LoRaCmd). |
| saveValue | If true, saves the setting to non-volatile memory (/W option). |
| MLR_Modem_Error MLR_Modem::SetSpreadFactor | ( | MLR_ModemSpreadFactor | sf, |
| bool | saveValue | ||
| ) |
Sets the LoRa spreading factor.
| sf | The spreading factor to set. |
| saveValue | If true, saves the setting to non-volatile memory (/W option). |
| MLR_Modem_Error MLR_Modem::SoftReset | ( | ) |
Performs a software reset of the modem.
| MLR_Modem_Error MLR_Modem::TransmitData | ( | const uint8_t * | pMsg, |
| uint8_t | len | ||
| ) |
Transmits data over the wireless link.
| pMsg | Pointer to the data payload to send. |
| len | Length of the data payload (0-255 bytes). |
| MLR_Modem_Error MLR_Modem::TransmitDataAsync | ( | const uint8_t * | pMsg, |
| uint8_t | len | ||
| ) |
Transmits data over the wireless link asynchronously. The result will be delivered via the AsyncCallback as MLR_Modem_Response::MLR_Modem_DtIr.
| pMsg | Pointer to the data payload to send. |
| len | Length of the data payload (0-255 bytes). |
|
inline |
Main processing loop for the driver. This function must be called regularly (e.g., in the Arduino loop()) to parse incoming serial data from the modem. Now calls SerialModemBase::update() internally.