ublox: new 'AT+UUSBCONF?' response parser
This commit is contained in:
@@ -167,6 +167,7 @@ Makefile.in
|
||||
/plugins/test-modem-helpers-mbm*
|
||||
/plugins/test-modem-helpers-telit*
|
||||
/plugins/test-modem-helpers-thuraya*
|
||||
/plugins/test-modem-helpers-ublox*
|
||||
/plugins/test-service-*
|
||||
|
||||
/test/lsudev
|
||||
|
||||
@@ -855,6 +855,25 @@ test_udev_rules_LDADD = \
|
||||
# plugin: u-blox
|
||||
################################################################################
|
||||
|
||||
noinst_LTLIBRARIES += libhelpers-ublox.la
|
||||
libhelpers_ublox_la_SOURCES = \
|
||||
ublox/mm-modem-helpers-ublox.c \
|
||||
ublox/mm-modem-helpers-ublox.h \
|
||||
$(NULL)
|
||||
|
||||
noinst_PROGRAMS += test-modem-helpers-ublox
|
||||
test_modem_helpers_ublox_SOURCES = \
|
||||
ublox/tests/test-modem-helpers-ublox.c \
|
||||
$(NULL)
|
||||
test_modem_helpers_ublox_CPPFLAGS = \
|
||||
-I$(top_srcdir)/plugins/ublox \
|
||||
$(NULL)
|
||||
test_modem_helpers_ublox_LDADD = \
|
||||
$(builddir)/libhelpers-ublox.la \
|
||||
$(top_builddir)/src/libhelpers.la \
|
||||
$(top_builddir)/libmm-glib/libmm-glib.la \
|
||||
$(NULL)
|
||||
|
||||
pkglib_LTLIBRARIES += libmm-plugin-ublox.la
|
||||
libmm_plugin_ublox_la_SOURCES = \
|
||||
ublox/mm-plugin-ublox.c \
|
||||
@@ -864,6 +883,7 @@ libmm_plugin_ublox_la_SOURCES = \
|
||||
$(NULL)
|
||||
libmm_plugin_ublox_la_CPPFLAGS = $(PLUGIN_COMMON_COMPILER_FLAGS)
|
||||
libmm_plugin_ublox_la_LDFLAGS = $(PLUGIN_COMMON_LINKER_FLAGS)
|
||||
libmm_plugin_ublox_la_LIBADD = $(builddir)/libhelpers-ublox.la
|
||||
|
||||
################################################################################
|
||||
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details:
|
||||
*
|
||||
* Copyright (C) 2016 Aleksander Morgado <aleksander@aleksander.es>
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mm-modem-helpers.h"
|
||||
#include "mm-modem-helpers-ublox.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* UUSBCONF? response parser */
|
||||
|
||||
gboolean
|
||||
mm_ublox_parse_uusbconf_response (const gchar *response,
|
||||
MMUbloxUsbProfile *out_profile,
|
||||
GError **error)
|
||||
{
|
||||
GRegex *r;
|
||||
GMatchInfo *match_info;
|
||||
GError *inner_error = NULL;
|
||||
MMUbloxUsbProfile profile = MM_UBLOX_USB_PROFILE_UNKNOWN;
|
||||
|
||||
g_assert (out_profile != NULL);
|
||||
|
||||
/* Response may be e.g.:
|
||||
* +UUSBCONF: 3,"RNDIS",,"0x1146"
|
||||
* +UUSBCONF: 2,"ECM",,"0x1143"
|
||||
* +UUSBCONF: 0,"",,"0x1141"
|
||||
*
|
||||
* Note: we don't rely on the PID; assuming future new modules will
|
||||
* have a different PID but they may keep the profile names.
|
||||
*/
|
||||
r = g_regex_new ("\\+UUSBCONF: (\\d+),([^,]*),([^,]*),([^,]*)(?:\\r\\n)?", 0, 0, NULL);
|
||||
g_assert (r != NULL);
|
||||
|
||||
g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error);
|
||||
if (!inner_error && g_match_info_matches (match_info)) {
|
||||
gchar *profile_name;
|
||||
|
||||
profile_name = mm_get_string_unquoted_from_match_info (match_info, 2);
|
||||
if (profile_name && profile_name[0]) {
|
||||
if (g_str_equal (profile_name, "RNDIS"))
|
||||
profile = MM_UBLOX_USB_PROFILE_RNDIS;
|
||||
else if (g_str_equal (profile_name, "ECM"))
|
||||
profile = MM_UBLOX_USB_PROFILE_ECM;
|
||||
else
|
||||
inner_error = g_error_new (MM_CORE_ERROR, MM_CORE_ERROR_UNSUPPORTED,
|
||||
"Unknown USB profile: '%s'", profile_name);
|
||||
} else
|
||||
profile = MM_UBLOX_USB_PROFILE_BACK_COMPATIBLE;
|
||||
g_free (profile_name);
|
||||
}
|
||||
|
||||
if (match_info)
|
||||
g_match_info_free (match_info);
|
||||
g_regex_unref (r);
|
||||
|
||||
if (inner_error) {
|
||||
g_propagate_error (error, inner_error);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (profile == MM_UBLOX_USB_PROFILE_UNKNOWN) {
|
||||
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||
"Couldn't parse profile response");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*out_profile = profile;
|
||||
return TRUE;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details:
|
||||
*
|
||||
* Copyright (C) 2016 Aleksander Morgado <aleksander@aleksander.es>
|
||||
*/
|
||||
|
||||
#ifndef MM_MODEM_HELPERS_UBLOX_H
|
||||
#define MM_MODEM_HELPERS_UBLOX_H
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
/*****************************************************************************/
|
||||
/* UUSBCONF? response parser */
|
||||
|
||||
typedef enum {
|
||||
MM_UBLOX_USB_PROFILE_UNKNOWN,
|
||||
MM_UBLOX_USB_PROFILE_RNDIS,
|
||||
MM_UBLOX_USB_PROFILE_ECM,
|
||||
MM_UBLOX_USB_PROFILE_BACK_COMPATIBLE,
|
||||
} MMUbloxUsbProfile;
|
||||
|
||||
gboolean mm_ublox_parse_uusbconf_response (const gchar *response,
|
||||
MMUbloxUsbProfile *out_profile,
|
||||
GError **error);
|
||||
|
||||
#endif /* MM_MODEM_HELPERS_UBLOX_H */
|
||||
@@ -0,0 +1,101 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details:
|
||||
*
|
||||
* Copyright (C) 2016 Aleksander Morgado <aleksander@aleksander.es>
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <locale.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <ModemManager.h>
|
||||
#define _LIBMM_INSIDE_MM
|
||||
#include <libmm-glib.h>
|
||||
|
||||
#include "mm-log.h"
|
||||
#include "mm-modem-helpers.h"
|
||||
#include "mm-modem-helpers-ublox.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Test UUSBCONF? responses */
|
||||
|
||||
typedef struct {
|
||||
const gchar *str;
|
||||
MMUbloxUsbProfile profile;
|
||||
} UusbconfResponseTest;
|
||||
|
||||
static const UusbconfResponseTest uusbconf_response_tests[] = {
|
||||
{
|
||||
.str = "+UUSBCONF: 3,\"RNDIS\",,\"0x1146\"\r\n",
|
||||
.profile = MM_UBLOX_USB_PROFILE_RNDIS
|
||||
},
|
||||
{
|
||||
.str = "+UUSBCONF: 2,\"ECM\",,\"0x1143\"\r\n",
|
||||
.profile = MM_UBLOX_USB_PROFILE_ECM
|
||||
},
|
||||
{
|
||||
.str = "+UUSBCONF: 0,\"\",,\"0x1141\"\r\n",
|
||||
.profile = MM_UBLOX_USB_PROFILE_BACK_COMPATIBLE
|
||||
},
|
||||
};
|
||||
|
||||
static void
|
||||
test_uusbconf_response (void)
|
||||
{
|
||||
guint i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (uusbconf_response_tests); i++) {
|
||||
MMUbloxUsbProfile profile = MM_UBLOX_USB_PROFILE_UNKNOWN;
|
||||
GError *error = NULL;
|
||||
gboolean success;
|
||||
|
||||
success = mm_ublox_parse_uusbconf_response (uusbconf_response_tests[i].str, &profile, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (success);
|
||||
g_assert_cmpuint (uusbconf_response_tests[i].profile, ==, profile);
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void
|
||||
_mm_log (const char *loc,
|
||||
const char *func,
|
||||
guint32 level,
|
||||
const char *fmt,
|
||||
...)
|
||||
{
|
||||
#if defined ENABLE_TEST_MESSAGE_TRACES
|
||||
/* Dummy log function */
|
||||
va_list args;
|
||||
gchar *msg;
|
||||
|
||||
va_start (args, fmt);
|
||||
msg = g_strdup_vprintf (fmt, args);
|
||||
va_end (args);
|
||||
g_print ("%s\n", msg);
|
||||
g_free (msg);
|
||||
#endif
|
||||
}
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
setlocale (LC_ALL, "");
|
||||
|
||||
g_type_init ();
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/MM/ublox/uusbconf/response", test_uusbconf_response);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
Reference in New Issue
Block a user