huawei: minor refactor in GPS enabling/disabling logic

This commit is contained in:
Aleksander Morgado
2020-06-28 11:38:48 +02:00
parent 538ed3f24e
commit bbfc10d7c5

View File

@@ -3875,7 +3875,7 @@ location_load_capabilities (MMIfaceModemLocation *self,
typedef struct { typedef struct {
MMModemLocationSource source; MMModemLocationSource source;
int idx; guint idx;
} LocationGatheringContext; } LocationGatheringContext;
/******************************/ /******************************/
@@ -3903,8 +3903,7 @@ gps_disabled_ready (MMBaseModem *self,
mm_base_modem_at_command_full_finish (self, res, &error); mm_base_modem_at_command_full_finish (self, res, &error);
/* Only use the GPS port in NMEA/RAW setups */ /* Only use the GPS port in NMEA/RAW setups */
if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW)) {
MM_MODEM_LOCATION_SOURCE_GPS_RAW)) {
/* Even if we get an error here, we try to close the GPS port */ /* Even if we get an error here, we try to close the GPS port */
gps_port = mm_base_modem_peek_port_gps (self); gps_port = mm_base_modem_peek_port_gps (self);
if (gps_port) if (gps_port)
@@ -3968,6 +3967,13 @@ disable_location_gathering (MMIfaceModemLocation *_self,
/*****************************************************************************/ /*****************************************************************************/
/* Enable location gathering (Location interface) */ /* Enable location gathering (Location interface) */
static const gchar *gps_startup[] = {
"^WPDOM=0",
"^WPDST=1",
"^WPDFR=65535,30",
"^WPDGP",
};
static gboolean static gboolean
enable_location_gathering_finish (MMIfaceModemLocation *self, enable_location_gathering_finish (MMIfaceModemLocation *self,
GAsyncResult *res, GAsyncResult *res,
@@ -3976,42 +3982,40 @@ enable_location_gathering_finish (MMIfaceModemLocation *self,
return g_task_propagate_boolean (G_TASK (res), error); return g_task_propagate_boolean (G_TASK (res), error);
} }
static const gchar *gps_startup[] = { static void run_gps_startup (GTask *task);
"^WPDOM=0",
"^WPDST=1",
"^WPDFR=65535,30",
"^WPDGP",
NULL
};
static void static void
gps_enabled_ready (MMBaseModem *self, gps_startup_command_ready (MMBaseModem *self,
GAsyncResult *res, GAsyncResult *res,
GTask *task) GTask *task)
{ {
LocationGatheringContext *ctx;
GError *error = NULL; GError *error = NULL;
MMPortSerialGps *gps_port;
ctx = g_task_get_task_data (task); if (!mm_base_modem_at_command_finish (self, res, &error)) {
if (!mm_base_modem_at_command_full_finish (self, res, &error)) {
ctx->idx = 0;
g_task_return_error (task, error); g_task_return_error (task, error);
g_object_unref (task); g_object_unref (task);
return; return;
} }
/* ctx->idx++; make sure ctx->idx is a valid command */ /* continue with next command */
if (gps_startup[ctx->idx++] && gps_startup[ctx->idx]) { run_gps_startup (task);
mm_base_modem_at_command_full (MM_BASE_MODEM (self), }
mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)),
gps_startup[ctx->idx], static void
run_gps_startup (GTask *task)
{
MMBroadbandModemHuawei *self;
LocationGatheringContext *ctx;
self = g_task_get_source_object (task);
ctx = g_task_get_task_data (task);
if (ctx->idx < G_N_ELEMENTS (gps_startup)) {
mm_base_modem_at_command (MM_BASE_MODEM (self),
gps_startup[ctx->idx++],
3, 3,
FALSE, FALSE,
FALSE, /* raw */ (GAsyncReadyCallback)gps_startup_command_ready,
NULL, /* cancellable */
(GAsyncReadyCallback)gps_enabled_ready,
task); task);
return; return;
} }
@@ -4019,7 +4023,10 @@ gps_enabled_ready (MMBaseModem *self,
/* Only use the GPS port in NMEA/RAW setups */ /* Only use the GPS port in NMEA/RAW setups */
if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA |
MM_MODEM_LOCATION_SOURCE_GPS_RAW)) { MM_MODEM_LOCATION_SOURCE_GPS_RAW)) {
gps_port = mm_base_modem_peek_port_gps (self); GError *error = NULL;
MMPortSerialGps *gps_port;
gps_port = mm_base_modem_peek_port_gps (MM_BASE_MODEM (self));
if (!gps_port || if (!gps_port ||
!mm_port_serial_open (MM_PORT_SERIAL (gps_port), &error)) { !mm_port_serial_open (MM_PORT_SERIAL (gps_port), &error)) {
if (error) if (error)
@@ -4070,15 +4077,7 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *_self,
} }
if (start_gps) { if (start_gps) {
mm_base_modem_at_command_full (MM_BASE_MODEM (self), run_gps_startup (task);
mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)),
gps_startup[ctx->idx],
3,
FALSE,
FALSE, /* raw */
NULL, /* cancellable */
(GAsyncReadyCallback)gps_enabled_ready,
task);
return; return;
} }