Skip to content

File syn_at_parser.h

FileList > proto > syn_at_parser.h

Go to the source code of this file

Zero-allocation, stream-oriented AT command parser for cellular & serial modems. More...

  • #include "../common/syn_defs.h"
  • #include "../pt/syn_pt.h"
  • #include "../util/syn_stream.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>

Classes

Type Name
struct SYN_AtParser
AT Command Parser context.

Public Types

Type Name
enum SYN_AtRespType
Decoded AT response types.

Public Functions

Type Name
SYN_AtRespType syn_at_parser_feed_char (SYN_AtParser * parser, char c)
Feed a single byte into the AT parser.
SYN_AtRespType syn_at_parser_feed_stream (SYN_AtParser * parser, SYN_Stream * stream)
Feed available bytes from a SYN_Stream into the AT parser.
int syn_at_parser_get_cme_error (const SYN_AtParser * parser)
Get the parsed error code for SYN_AT_RESP_CME_ERROR.
const char * syn_at_parser_get_line (const SYN_AtParser * parser)
Get the current accumulated response line string.
bool syn_at_parser_get_param_int (const char * line, size_t param_idx, int * out_val)
Helper: Extract an integer parameter from a comma-delimited AT response line.
bool syn_at_parser_get_param_str (const char * line, size_t param_idx, char * out_buf, size_t max_len)
Helper: Extract a string parameter from a comma-delimited AT response line.
SYN_Status syn_at_parser_init (SYN_AtParser * parser, char * buf, size_t buf_size)
Initialize an AT command parser.
void syn_at_parser_reset (SYN_AtParser * parser)
Reset internal parser state.

Detailed Description

Lightweight, non-blocking line and prompt parser for modems (SIM800, Quectel, ESP-AT, etc.). Feeds from SYN_Stream or raw byte feeds, handles \r line framing, prompt '>' detection, CME ERROR decoding, URC filtering, and parameter extraction without dynamic memory allocation.

** **

static char line_buf[128];
static SYN_AtParser parser;
syn_at_parser_init(&parser, line_buf, sizeof(line_buf));

// In protothread or main loop:
SYN_AtRespType resp = syn_at_parser_feed_stream(&parser, &uart_rx_stream);
if (resp == SYN_AT_RESP_OK) {
    // Command succeeded
} else if (resp == SYN_AT_RESP_PROMPT) {
    // Modem sent '>' prompt, ready for data
}

Public Types Documentation

enum SYN_AtRespType

Decoded AT response types.

enum SYN_AtRespType {
    SYN_AT_RESP_NONE = 0,
    SYN_AT_RESP_OK,
    SYN_AT_RESP_ERROR,
    SYN_AT_RESP_CME_ERROR,
    SYN_AT_RESP_PROMPT,
    SYN_AT_RESP_LINE,
    SYN_AT_RESP_URC
};


Public Functions Documentation

function syn_at_parser_feed_char

Feed a single byte into the AT parser.

SYN_AtRespType syn_at_parser_feed_char (
    SYN_AtParser * parser,
    char c
) 

Processes a single character. Returns response type if a complete line (\r ) or prompt ('>') has been parsed.

Parameters:

  • parser Parser instance.
  • c Byte to process.

Returns:

Decoded response type, or SYN_AT_RESP_NONE if line incomplete.


function syn_at_parser_feed_stream

Feed available bytes from a SYN_Stream into the AT parser.

SYN_AtRespType syn_at_parser_feed_stream (
    SYN_AtParser * parser,
    SYN_Stream * stream
) 

Reads bytes non-blockingly from the stream until a complete response line/prompt is parsed or the stream is empty.

Parameters:

  • parser Parser instance.
  • stream Pointer to input stream.

Returns:

Decoded response type, or SYN_AT_RESP_NONE if line incomplete.


function syn_at_parser_get_cme_error

Get the parsed error code for SYN_AT_RESP_CME_ERROR.

int syn_at_parser_get_cme_error (
    const SYN_AtParser * parser
) 

Parameters:

  • parser Parser instance.

Returns:

Numerical CME/CMS error code, or -1 if unavailable.


function syn_at_parser_get_line

Get the current accumulated response line string.

const char * syn_at_parser_get_line (
    const SYN_AtParser * parser
) 

Parameters:

  • parser Parser instance.

Returns:

Null-terminated line string.


function syn_at_parser_get_param_int

Helper: Extract an integer parameter from a comma-delimited AT response line.

bool syn_at_parser_get_param_int (
    const char * line,
    size_t param_idx,
    int * out_val
) 

Example line: "+CSQ: 20,0" -> param 0 is 20, param 1 is 0.

Parameters:

  • line Response text line.
  • param_idx 0-based parameter index.
  • out_val [out] Extracted integer value.

Returns:

true if parameter was found and successfully parsed.


function syn_at_parser_get_param_str

Helper: Extract a string parameter from a comma-delimited AT response line.

bool syn_at_parser_get_param_str (
    const char * line,
    size_t param_idx,
    char * out_buf,
    size_t max_len
) 

Handles quoted strings (e.g. "+CPIN: \"READY\"") and strips quotes.

Parameters:

  • line Response text line.
  • param_idx 0-based parameter index.
  • out_buf Destination buffer.
  • max_len Destination capacity.

Returns:

true if parameter was found and extracted.


function syn_at_parser_init

Initialize an AT command parser.

SYN_Status syn_at_parser_init (
    SYN_AtParser * parser,
    char * buf,
    size_t buf_size
) 

Parameters:

  • parser Parser instance.
  • buf Caller-owned buffer for line accumulation.
  • buf_size Capacity of buffer in bytes.

Returns:

SYN_OK on success, or SYN_ERR_INVALID_PARAM.


function syn_at_parser_reset

Reset internal parser state.

void syn_at_parser_reset (
    SYN_AtParser * parser
) 

Clears accumulated line buffer and last decoded response.

Parameters:

  • parser Parser instance.


The documentation for this class was generated from the following file src/syntropic/proto/syn_at_parser.h