Generic AT response parser for OK / ERROR to be used in plugins?
Aleksander Morgado
aleksander at aleksander.es
Sat Jan 7 11:52:10 UTC 2017
On Sat, Jan 7, 2017 at 10:16 AM, Schroer, Jens Peter
<jens.schroer at scypho.com> wrote:
> I am currently trying to add support for the U-Blox Sara U270 to the ublox
> branch.
> For that I need to run some AT commands on the modem.
> Some of them just return the common generic OK / ERROR.
> So instead of me reinventing the wheel I was wondering if there is a generic
> AT response parser in the code base, that I can reuse?
> I found the mm_serial_parser_v1_parse but I was not able to find a piece of
> code that helped me to apply it to my scenario (but would not be surprised
> if I missed such a case).
>
> I would be very thankful for suggestions or pointers at where to look.
mm_base_modem_at_command() is what you need, that already includes the
generic AT command parser. You'll get an error reported if "ERROR" is
received, and you'll get no error and an EMPTY string if "OK" is
received.
E.g.:
mm_base_modem_at_command (self, "+SOMETHING", 3, FALSE,
(GAsyncReadyCallback) something_ready, NULL);
Then:
static void
something_ready (MMBaseModem *self,
GAsyncResult *res,
gpointer unused)
{
const gchar *response;
GError *error = NULL;
response = mm_base_modem_at_command_finish (self, res, &error);
if (!response) {
mm_dbg ("An error was received: %s", error->message);
g_error_free (error);
} else
mm_dbg ("response received: '%s'", response);
}
The GError you get is already built from the actual AT response error
received. If the command succeeds instead, you'll get returned by
mm_base_modem_at_command_finish() the string response that happened
before the "OK" (so if you just get OK, you get an empty string).
--
Aleksander
https://aleksander.es
More information about the ModemManager-devel
mailing list