Base class handling low-level serial I/O, debugging, and async transaction logic. More...
#include <SerialModemBase.h>
Public Member Functions | |
| 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 | |
| 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. | |
Static Protected Member Functions | |
| 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 | |
| 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 | |
| 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 |
Base class handling low-level serial I/O, debugging, and async transaction logic.
| SerialModemBase::SerialModemBase | ( | ) |
|
virtualdefault |
|
staticprotected |
|
inlinestaticprotected |
|
staticprotected |
|
inlinestaticprotected |
|
protected |
|
protected |
Enqueues a command for processing. Non-blocking.
|
protected |
Enqueues a data transmission command with payload.
|
protected |
|
protected |
Helper to get a boolean value (ON/OF).
| cmd | Command string (e.g., "@RR"). |
| pValue | Output pointer for the value. |
| respPrefix | Expected response prefix. |
|
protected |
Helper to get a 1-byte value.
| cmd | Command string (e.g., "@CH"). |
| pValue | Output pointer for the value. |
| respPrefix | Expected response prefix. |
| respLen | Total length of expected response. |
|
inline |
Gets the result of the last processed command.
|
protectedpure virtual |
Implemented in MLR_Modem.
| uint8_t SerialModemBase::getQueueCount | ( | ) | const |
Gets the number of commands currently in the queue.
|
inline |
Accessor for the shared RX buffer.
|
inline |
|
protected |
Sets the UART stream to use for modem communication.
| stream | Reference to the serial stream. |
| bool SerialModemBase::isIdle | ( | ) | const |
Checks if the internal engine is currently idle (no command processing).
|
inline |
Checks if the last processed command has finished. Useful for implementing synchronous wrappers.
| bool SerialModemBase::isQueueEmpty | ( | ) | const |
Checks if the command queue is empty.
| bool SerialModemBase::isQueueFull | ( | ) | const |
Checks if the command queue is full.
|
protected |
|
inlineprotectedvirtual |
Optional hook called when a queued command finishes.
Reimplemented in MLR_Modem.
|
protectedpure virtual |
Implemented in MLR_Modem.
|
protectedpure virtual |
Main parser state machine step. Must use readByte() and update _rxBuffer / _rxIndex.
Implemented in MLR_Modem.
|
staticprotected |
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |
Sends a raw command string and fills the provided buffer with the response.
| command | Command string. |
| responseBuffer | Output buffer. |
| bufferSize | Size of output buffer. |
| timeoutMs | Timeout. |
|
protected |
Helper to set a boolean value (ON/OF).
| baseCmd | Base command string (e.g., "@RR"). Appends "ON" or "OF". |
| enabled | True for ON, False for OFF. |
| save | Whether to save to NVM (/W). |
| respPrefix | Expected response prefix (e.g., "*RR="). |
|
protected |
Helper to set a 1-byte value (e.g., @CH0E) and verify the response.
| cmd | Command string (e.g., "@CH"). |
| value | The byte value to set. |
| save | Whether to save to NVM (/W). |
| respPrefix | Expected response prefix (e.g., "*CH="). |
| respLen | Total length of expected response. |
| void SerialModemBase::setDebugStream | ( | Stream * | debugStream | ) |
Initializes the debug stream.
| debugStream | Pointer to the Stream for debug output (can be nullptr). |
|
protected |
|
protected |
| void SerialModemBase::update | ( | ) |
Main processing loop. Must be called frequently. Handles command queue, transmission, and response parsing.
|
protected |
Helper to wait for the current command to finish (Pseudo-blocking). Calls update() internally.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
staticconstexprprotected |