Skip to content

File syn_at_parser.c

FileList > proto > syn_at_parser.c

Go to the source code of this file

Implementation of stream-oriented AT command parser.

  • #include "syn_at_parser.h"
  • #include <ctype.h>
  • #include <stdlib.h>
  • #include <string.h>

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.

Public Static Functions

Type Name
const char * find_param_start (const char * line, size_t param_idx)
bool starts_with (const char * str, const char * prefix)

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.

Public Static Functions Documentation

function find_param_start

static const char * find_param_start (
    const char * line,
    size_t param_idx
) 

function starts_with

static bool starts_with (
    const char * str,
    const char * prefix
) 


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