From 24f9309d6ecd559d24c54391fadef76cdbde1097 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 16 May 2025 11:19:59 -0500 Subject: serial-parsers,port-serial-at: move echo removal into serial parser Mainly because we need somewhere to stash the call end regex, and it's silly to have a 3rd instance of that in MMPortSerialAt when we already have one in the serial parsers that MMPortSerialAt relies on pretty heavily. Signed-off-by: Dan Williams --- src/mm-port-serial-at.c | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) (limited to 'src/mm-port-serial-at.c') diff --git a/src/mm-port-serial-at.c b/src/mm-port-serial-at.c index 90c0af70..ca2cc540 100644 --- a/src/mm-port-serial-at.c +++ b/src/mm-port-serial-at.c @@ -42,6 +42,7 @@ enum { struct _MMPortSerialAtPrivate { /* Response parser data */ MMPortSerialAtResponseParserFn response_parser_fn; + MMPortSerialAtRemoveEchoFn remove_echo_fn; gpointer response_parser_user_data; GDestroyNotify response_parser_notify; @@ -61,6 +62,7 @@ struct _MMPortSerialAtPrivate { void mm_port_serial_at_set_response_parser (MMPortSerialAt *self, MMPortSerialAtResponseParserFn fn, + MMPortSerialAtRemoveEchoFn echo_fn, gpointer user_data, GDestroyNotify notify) { @@ -70,30 +72,11 @@ mm_port_serial_at_set_response_parser (MMPortSerialAt *self, self->priv->response_parser_notify (self->priv->response_parser_user_data); self->priv->response_parser_fn = fn; + self->priv->remove_echo_fn = echo_fn; self->priv->response_parser_user_data = user_data; self->priv->response_parser_notify = notify; } -void -mm_port_serial_at_remove_echo (GByteArray *response) -{ - guint i; - - if (response->len <= 2) - return; - - for (i = 0; i < (response->len - 1); i++) { - /* If there is any content before the first - * , assume it's echo or garbage, and skip it */ - if (response->data[i] == '\r' && response->data[i + 1] == '\n') { - if (i > 0) - g_byte_array_remove_range (response, 0, i); - /* else, good, we're already started with */ - break; - } - } -} - static MMPortSerialResponseType parse_response (MMPortSerial *port, GByteArray *response, @@ -109,7 +92,7 @@ parse_response (MMPortSerial *port, /* Remove echo */ if (self->priv->remove_echo) - mm_port_serial_at_remove_echo (response); + self->priv->remove_echo_fn (self->priv->response_parser_user_data, response); /* If there's no response to receive, we're done; e.g. if we only got * unsolicited messages */ @@ -243,7 +226,7 @@ parse_unsolicited (MMPortSerial *port, GByteArray *response) /* Remove echo */ if (self->priv->remove_echo) - mm_port_serial_at_remove_echo (response); + self->priv->remove_echo_fn (self->priv->response_parser_user_data, response); for (iter = self->priv->unsolicited_msg_handlers; iter; iter = iter->next) { MMAtUnsolicitedMsgHandler *handler = (MMAtUnsolicitedMsgHandler *) iter->data; -- cgit v1.2.3-70-g09d2