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