quectel,shared: skip QGPS? check after enabling/disabling failures
If any enabling/disabling command fails, we consider the operation failed, regardless of the QGPS status. This is because e.g. enabling involves more operations than just QGPS=1, and so we should treat a failure in the command sequence as a failure in the whole operation.
This commit is contained in:
@@ -205,45 +205,6 @@ mm_shared_quectel_setup_sim_hot_swap (MMIfaceModem *self,
|
|||||||
g_object_unref (task);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/* Location State Variables */
|
|
||||||
|
|
||||||
static const gchar *gps_startup[] = {
|
|
||||||
/* NOTES:
|
|
||||||
* 1) "+QGPSCFG=\"nmeasrc\",1" will be necessary for getting location data
|
|
||||||
* without the nmea port.
|
|
||||||
* 2) may be necessary to set "+QGPSCFG=\"gpsnmeatype\".
|
|
||||||
*/
|
|
||||||
"+QGPSCFG=\"outport\",\"usbnmea\"",
|
|
||||||
"+QGPS=1",
|
|
||||||
};
|
|
||||||
|
|
||||||
static const int qgps_nmea_port_sources = (
|
|
||||||
MM_MODEM_LOCATION_SOURCE_GPS_RAW | MM_MODEM_LOCATION_SOURCE_GPS_NMEA);
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
MMModemLocationSource source;
|
|
||||||
unsigned long idx;
|
|
||||||
GError *command_error;
|
|
||||||
} LocationGatheringContext;
|
|
||||||
|
|
||||||
static void
|
|
||||||
location_gathering_context_free (LocationGatheringContext *ctx)
|
|
||||||
{
|
|
||||||
g_clear_error (&ctx->command_error);
|
|
||||||
g_slice_free (LocationGatheringContext, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
static LocationGatheringContext *
|
|
||||||
location_gathering_context_new (MMModemLocationSource source)
|
|
||||||
{
|
|
||||||
LocationGatheringContext *ctx;
|
|
||||||
|
|
||||||
ctx = g_slice_new0 (LocationGatheringContext);
|
|
||||||
ctx->source = source;
|
|
||||||
return ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Location capabilities loading (Location interface) */
|
/* Location capabilities loading (Location interface) */
|
||||||
|
|
||||||
@@ -357,10 +318,22 @@ mm_shared_quectel_location_load_capabilities (MMIfaceModemLocation *_self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Functions used to Enable Location */
|
/* Enable location gathering (Location interface) */
|
||||||
|
|
||||||
static void qgps_enable_loop (MMBaseModem *self,
|
static const gchar *gps_startup[] = {
|
||||||
GTask *task);
|
/* NOTES:
|
||||||
|
* 1) "+QGPSCFG=\"nmeasrc\",1" will be necessary for getting location data
|
||||||
|
* without the nmea port.
|
||||||
|
* 2) may be necessary to set "+QGPSCFG=\"gpsnmeatype\".
|
||||||
|
*/
|
||||||
|
"+QGPSCFG=\"outport\",\"usbnmea\"",
|
||||||
|
"+QGPS=1",
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
MMModemLocationSource source;
|
||||||
|
guint idx;
|
||||||
|
} LocationGatheringContext;
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mm_shared_quectel_enable_location_gathering_finish (MMIfaceModemLocation *self,
|
mm_shared_quectel_enable_location_gathering_finish (MMIfaceModemLocation *self,
|
||||||
@@ -370,86 +343,51 @@ mm_shared_quectel_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 void
|
static void run_gps_startup (GTask *task);
|
||||||
qgps_check_enabled_ready (MMBaseModem *self,
|
|
||||||
GAsyncResult *res,
|
|
||||||
GTask *task)
|
|
||||||
{
|
|
||||||
const gchar *response;
|
|
||||||
GError *error = NULL;
|
|
||||||
LocationGatheringContext *ctx;
|
|
||||||
|
|
||||||
ctx = g_task_get_task_data (task);
|
|
||||||
|
|
||||||
response = mm_base_modem_at_command_finish (self, res, &error);
|
|
||||||
|
|
||||||
if (!response)
|
|
||||||
g_task_return_error (task, error);
|
|
||||||
else if (!g_str_equal (mm_strip_tag (response, "+QGPS:"), "1"))
|
|
||||||
g_task_return_error (task, ctx->command_error);
|
|
||||||
else {
|
|
||||||
qgps_enable_loop (self, task);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
g_object_unref (task);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
qgps_enable_command_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;
|
|
||||||
|
|
||||||
ctx = g_task_get_task_data (task);
|
if (!mm_base_modem_at_command_full_finish (self, res, &error)) {
|
||||||
|
g_task_return_error (task, error);
|
||||||
if (!mm_base_modem_at_command_full_finish (self, res, &error))
|
g_object_unref (task);
|
||||||
ctx->command_error = error;
|
|
||||||
|
|
||||||
qgps_enable_loop (self, task);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
qgps_enable_loop (MMBaseModem *self,
|
|
||||||
GTask *task)
|
|
||||||
{
|
|
||||||
MMPortSerialGps *gps_port;
|
|
||||||
LocationGatheringContext *ctx;
|
|
||||||
GError *error = NULL;
|
|
||||||
|
|
||||||
ctx = g_task_get_task_data (task);
|
|
||||||
|
|
||||||
/* If there are more commands run them, then return */
|
|
||||||
if (ctx->idx < G_N_ELEMENTS (gps_startup)) {
|
|
||||||
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)qgps_enable_command_ready,
|
|
||||||
task);
|
|
||||||
ctx->idx++;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->command_error != NULL) {
|
/* continue with next command */
|
||||||
mm_base_modem_at_command (self,
|
run_gps_startup (task);
|
||||||
"+QGPS?",
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
run_gps_startup (GTask *task)
|
||||||
|
{
|
||||||
|
MMSharedQuectel *self;
|
||||||
|
LocationGatheringContext *ctx;
|
||||||
|
|
||||||
|
self = g_task_get_source_object (task);
|
||||||
|
ctx = g_task_get_task_data (task);
|
||||||
|
|
||||||
|
/* If there are more commands run them */
|
||||||
|
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,
|
||||||
(GAsyncReadyCallback)qgps_check_enabled_ready,
|
(GAsyncReadyCallback)gps_startup_command_ready,
|
||||||
task);
|
task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Last run Only: Check if the nmea/raw gps port
|
/* Check if the nmea/raw gps port exists and is available */
|
||||||
* exists and is available Otherwise throw an error */
|
if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW)) {
|
||||||
if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA |
|
GError *error = NULL;
|
||||||
MM_MODEM_LOCATION_SOURCE_GPS_RAW)) {
|
MMPortSerialGps *gps_port;
|
||||||
gps_port = mm_base_modem_peek_port_gps (self);
|
|
||||||
|
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 (!gps_port || !mm_port_serial_open (MM_PORT_SERIAL (gps_port), &error)) {
|
||||||
if (error)
|
if (error)
|
||||||
g_task_return_error (task, error);
|
g_task_return_error (task, error);
|
||||||
@@ -462,7 +400,6 @@ qgps_enable_loop (MMBaseModem *self,
|
|||||||
g_task_return_boolean (task, TRUE);
|
g_task_return_boolean (task, TRUE);
|
||||||
} else
|
} else
|
||||||
g_task_return_boolean (task, TRUE);
|
g_task_return_boolean (task, TRUE);
|
||||||
|
|
||||||
g_object_unref (task);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,12 +408,10 @@ parent_enable_location_gathering_ready (MMIfaceModemLocation *self,
|
|||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GTask *task)
|
GTask *task)
|
||||||
{
|
{
|
||||||
GError *error;
|
GError *error = NULL;
|
||||||
Private *priv;
|
Private *priv;
|
||||||
|
|
||||||
priv = get_private (MM_SHARED_QUECTEL (self));
|
priv = get_private (MM_SHARED_QUECTEL (self));
|
||||||
|
|
||||||
g_assert (priv->iface_modem_location_parent);
|
|
||||||
if (!priv->iface_modem_location_parent->enable_location_gathering_finish (self, res, &error))
|
if (!priv->iface_modem_location_parent->enable_location_gathering_finish (self, res, &error))
|
||||||
g_task_return_error (task, error);
|
g_task_return_error (task, error);
|
||||||
else
|
else
|
||||||
@@ -496,30 +431,27 @@ mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self,
|
|||||||
gboolean start_gps = FALSE;
|
gboolean start_gps = FALSE;
|
||||||
|
|
||||||
priv = get_private (MM_SHARED_QUECTEL (self));
|
priv = get_private (MM_SHARED_QUECTEL (self));
|
||||||
|
g_assert (priv->iface_modem_location_parent);
|
||||||
|
g_assert (priv->iface_modem_location_parent->enable_location_gathering);
|
||||||
|
g_assert (priv->iface_modem_location_parent->enable_location_gathering_finish);
|
||||||
|
|
||||||
task = g_task_new (self, NULL, callback, user_data);
|
task = g_task_new (self, NULL, callback, user_data);
|
||||||
|
|
||||||
/* If the parent can enable the modem let it */
|
/* Check if the source is provided by the parent */
|
||||||
if (!(priv->provided_sources& source)) {
|
if (!(priv->provided_sources & source)) {
|
||||||
if (priv->iface_modem_location_parent->enable_location_gathering &&
|
priv->iface_modem_location_parent->enable_location_gathering (
|
||||||
priv->iface_modem_location_parent->enable_location_gathering_finish) {
|
self,
|
||||||
g_task_set_task_data (task, GUINT_TO_POINTER (source), NULL);
|
source,
|
||||||
priv->iface_modem_location_parent->enable_location_gathering (
|
(GAsyncReadyCallback)parent_enable_location_gathering_ready,
|
||||||
self,
|
task);
|
||||||
source,
|
|
||||||
(GAsyncReadyCallback)parent_enable_location_gathering_ready,
|
|
||||||
task);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_task_return_boolean (task, TRUE);
|
|
||||||
g_object_unref (task);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = location_gathering_context_new (source);
|
ctx = g_new0 (LocationGatheringContext, 1);
|
||||||
g_task_set_task_data (task, ctx, (GDestroyNotify) location_gathering_context_free);
|
ctx->source = source;
|
||||||
|
g_task_set_task_data (task, ctx, g_free);
|
||||||
|
|
||||||
/* NMEA and UNMANAGED are both enabled in the same way */
|
/* RAW, NMEA and UNMANAGED are all enabled in the same way */
|
||||||
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 |
|
||||||
MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) {
|
MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) {
|
||||||
@@ -530,7 +462,7 @@ mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (start_gps) {
|
if (start_gps) {
|
||||||
qgps_enable_loop (MM_BASE_MODEM (self), task);
|
run_gps_startup (task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -540,7 +472,7 @@ mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Functions used to Disable Location */
|
/* Disable location gathering (Location interface) */
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
mm_shared_quectel_disable_location_gathering_finish (MMIfaceModemLocation *self,
|
mm_shared_quectel_disable_location_gathering_finish (MMIfaceModemLocation *self,
|
||||||
@@ -550,34 +482,6 @@ mm_shared_quectel_disable_location_gathering_finish (MMIfaceModemLocation *self
|
|||||||
return g_task_propagate_boolean (G_TASK (res), error);
|
return g_task_propagate_boolean (G_TASK (res), error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
qgps_check_disabled_ready (MMBaseModem *self,
|
|
||||||
GAsyncResult *res,
|
|
||||||
GTask *task)
|
|
||||||
{
|
|
||||||
const gchar *response;
|
|
||||||
GError *error = NULL;
|
|
||||||
|
|
||||||
/* Something is very wrong if we can't query the
|
|
||||||
* state of gps while we're disabling the gps */
|
|
||||||
// TODO: could it make sense to report success?
|
|
||||||
// if the modem won't tell us what the state of the gps is,
|
|
||||||
// and modem manager should prbably treat it as disabled right?
|
|
||||||
response = mm_base_modem_at_command_finish (self, res, &error);
|
|
||||||
if (!response) {
|
|
||||||
g_assert_not_reached ();
|
|
||||||
g_task_return_error (task, error);
|
|
||||||
} else if (!g_str_equal (mm_strip_tag (response, "+QGPS:"), "0"))
|
|
||||||
g_task_return_new_error (task,
|
|
||||||
MM_CORE_ERROR,
|
|
||||||
MM_CORE_ERROR_FAILED,
|
|
||||||
"Modem did not turn off");
|
|
||||||
else
|
|
||||||
g_task_return_boolean (task, TRUE);
|
|
||||||
|
|
||||||
g_object_unref (task);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
qgps_end_ready (MMBaseModem *self,
|
qgps_end_ready (MMBaseModem *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
@@ -585,17 +489,10 @@ qgps_end_ready (MMBaseModem *self,
|
|||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
if (!mm_base_modem_at_command_full_finish (self, res, &error)) {
|
if (!mm_base_modem_at_command_finish (self, res, &error))
|
||||||
mm_base_modem_at_command (self,
|
g_task_return_error (task, error);
|
||||||
"+QGPS?",
|
else
|
||||||
3,
|
g_task_return_boolean (task, TRUE);
|
||||||
FALSE,
|
|
||||||
(GAsyncReadyCallback)qgps_check_disabled_ready,
|
|
||||||
task);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_task_return_boolean (task, TRUE);
|
|
||||||
g_object_unref (task);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -608,8 +505,6 @@ disable_location_gathering_parent_ready (MMIfaceModemLocation *self,
|
|||||||
Private *priv;
|
Private *priv;
|
||||||
|
|
||||||
priv = get_private (MM_SHARED_QUECTEL (self));
|
priv = get_private (MM_SHARED_QUECTEL (self));
|
||||||
|
|
||||||
g_assert (priv->iface_modem_location_parent);
|
|
||||||
if (!priv->iface_modem_location_parent->disable_location_gathering_finish (self, res, &error))
|
if (!priv->iface_modem_location_parent->disable_location_gathering_finish (self, res, &error))
|
||||||
g_task_return_error (task, error);
|
g_task_return_error (task, error);
|
||||||
else
|
else
|
||||||
@@ -623,31 +518,30 @@ mm_shared_quectel_disable_location_gathering (MMIfaceModemLocation *self,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GTask *task;
|
GTask *task;
|
||||||
MMPortSerialGps *gps_port;
|
Private *priv;
|
||||||
Private *priv;
|
|
||||||
|
|
||||||
priv = get_private (MM_SHARED_QUECTEL (self));
|
priv = get_private (MM_SHARED_QUECTEL (self));
|
||||||
|
g_assert (priv->iface_modem_location_parent);
|
||||||
|
|
||||||
task = g_task_new (self, NULL, callback, user_data);
|
task = g_task_new (self, NULL, callback, user_data);
|
||||||
priv->enabled_sources &= ~source;
|
priv->enabled_sources &= ~source;
|
||||||
|
|
||||||
/* Pass handling to parent if we don't handle it */
|
/* Pass handling to parent if we don't handle it */
|
||||||
if (!(source & priv->provided_sources) &&
|
if (!(source & priv->provided_sources)) {
|
||||||
priv->iface_modem_location_parent->disable_location_gathering &&
|
/* The step to disable location gathering may not exist */
|
||||||
priv->iface_modem_location_parent->disable_location_gathering_finish) {
|
if (priv->iface_modem_location_parent->disable_location_gathering &&
|
||||||
priv->iface_modem_location_parent->disable_location_gathering (self,
|
priv->iface_modem_location_parent->disable_location_gathering_finish) {
|
||||||
source,
|
priv->iface_modem_location_parent->disable_location_gathering (self,
|
||||||
(GAsyncReadyCallback)disable_location_gathering_parent_ready,
|
source,
|
||||||
task);
|
(GAsyncReadyCallback)disable_location_gathering_parent_ready,
|
||||||
return;
|
task);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Close the nmea port if we don't need it anymore */
|
g_task_return_boolean (task, TRUE);
|
||||||
if (source & qgps_nmea_port_sources &&
|
g_object_unref (task);
|
||||||
!(priv->enabled_sources & qgps_nmea_port_sources)) {
|
return;
|
||||||
gps_port = mm_base_modem_peek_port_gps (MM_BASE_MODEM (self));
|
|
||||||
if (gps_port)
|
|
||||||
mm_port_serial_close (MM_PORT_SERIAL (gps_port));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Turn off gps on the modem if the source uses gps,
|
/* Turn off gps on the modem if the source uses gps,
|
||||||
@@ -655,16 +549,24 @@ mm_shared_quectel_disable_location_gathering (MMIfaceModemLocation *self,
|
|||||||
if ((source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA |
|
if ((source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA |
|
||||||
MM_MODEM_LOCATION_SOURCE_GPS_RAW |
|
MM_MODEM_LOCATION_SOURCE_GPS_RAW |
|
||||||
MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) &&
|
MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) &&
|
||||||
priv->enabled_sources == MM_MODEM_LOCATION_SOURCE_NONE) {
|
!(priv->enabled_sources & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA |
|
||||||
mm_base_modem_at_command_full (MM_BASE_MODEM (self),
|
MM_MODEM_LOCATION_SOURCE_GPS_RAW |
|
||||||
mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)),
|
MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED))) {
|
||||||
"+QGPSEND",
|
/* Close the data port if we don't need it anymore */
|
||||||
3,
|
if (source & (MM_MODEM_LOCATION_SOURCE_GPS_RAW | MM_MODEM_LOCATION_SOURCE_GPS_NMEA)) {
|
||||||
FALSE,
|
MMPortSerialGps *gps_port;
|
||||||
FALSE, /* raw */
|
|
||||||
NULL, /* cancellable */
|
gps_port = mm_base_modem_peek_port_gps (MM_BASE_MODEM (self));
|
||||||
(GAsyncReadyCallback)qgps_end_ready,
|
if (gps_port)
|
||||||
task);
|
mm_port_serial_close (MM_PORT_SERIAL (gps_port));
|
||||||
|
}
|
||||||
|
|
||||||
|
mm_base_modem_at_command (MM_BASE_MODEM (self),
|
||||||
|
"+QGPSEND",
|
||||||
|
3,
|
||||||
|
FALSE,
|
||||||
|
(GAsyncReadyCallback)qgps_end_ready,
|
||||||
|
task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user