quectel,shared: port GPS enabling to use AT sequence
This commit is contained in:
@@ -320,21 +320,17 @@ mm_shared_quectel_location_load_capabilities (MMIfaceModemLocation *_self,
|
|||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Enable location gathering (Location interface) */
|
/* Enable location gathering (Location interface) */
|
||||||
|
|
||||||
static const gchar *gps_startup[] = {
|
/* NOTES:
|
||||||
/* NOTES:
|
* 1) "+QGPSCFG=\"nmeasrc\",1" will be necessary for getting location data
|
||||||
* 1) "+QGPSCFG=\"nmeasrc\",1" will be necessary for getting location data
|
* without the nmea port.
|
||||||
* without the nmea port.
|
* 2) may be necessary to set "+QGPSCFG=\"gpsnmeatype\".
|
||||||
* 2) may be necessary to set "+QGPSCFG=\"gpsnmeatype\".
|
*/
|
||||||
*/
|
static const MMBaseModemAtCommand gps_startup[] = {
|
||||||
"+QGPSCFG=\"outport\",\"usbnmea\"",
|
{ "+QGPSCFG=\"outport\",\"usbnmea\"", 3, FALSE, mm_base_modem_response_processor_no_result_continue },
|
||||||
"+QGPS=1",
|
{ "+QGPS=1", 3, FALSE, mm_base_modem_response_processor_no_result_continue },
|
||||||
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
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,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
@@ -343,48 +339,25 @@ 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 run_gps_startup (GTask *task);
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gps_startup_command_ready (MMBaseModem *self,
|
gps_startup_ready (MMBaseModem *self,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
GTask *task)
|
GTask *task)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
MMModemLocationSource source;
|
||||||
|
GError *error = NULL;
|
||||||
|
|
||||||
if (!mm_base_modem_at_command_full_finish (self, res, &error)) {
|
mm_base_modem_at_sequence_finish (self, res, NULL, &error);
|
||||||
|
if (error) {
|
||||||
g_task_return_error (task, error);
|
g_task_return_error (task, error);
|
||||||
g_object_unref (task);
|
g_object_unref (task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* continue with next command */
|
source = GPOINTER_TO_UINT (g_task_get_task_data (task));
|
||||||
run_gps_startup (task);
|
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
|
||||||
FALSE,
|
|
||||||
(GAsyncReadyCallback)gps_startup_command_ready,
|
|
||||||
task);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if the nmea/raw gps port exists and is available */
|
/* Check if the nmea/raw gps port exists and is available */
|
||||||
if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW)) {
|
if (source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA | MM_MODEM_LOCATION_SOURCE_GPS_RAW)) {
|
||||||
GError *error = NULL;
|
|
||||||
MMPortSerialGps *gps_port;
|
MMPortSerialGps *gps_port;
|
||||||
|
|
||||||
gps_port = mm_base_modem_peek_port_gps (MM_BASE_MODEM (self));
|
gps_port = mm_base_modem_peek_port_gps (MM_BASE_MODEM (self));
|
||||||
@@ -425,10 +398,9 @@ mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self,
|
|||||||
GAsyncReadyCallback callback,
|
GAsyncReadyCallback callback,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
LocationGatheringContext *ctx;
|
GTask *task;
|
||||||
GTask *task;
|
Private *priv;
|
||||||
Private *priv;
|
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);
|
||||||
@@ -436,6 +408,7 @@ mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self,
|
|||||||
g_assert (priv->iface_modem_location_parent->enable_location_gathering_finish);
|
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);
|
||||||
|
g_task_set_task_data (task, GUINT_TO_POINTER (source), NULL);
|
||||||
|
|
||||||
/* Check if the source is provided by the parent */
|
/* Check if the source is provided by the parent */
|
||||||
if (!(priv->provided_sources & source)) {
|
if (!(priv->provided_sources & source)) {
|
||||||
@@ -447,26 +420,28 @@ mm_shared_quectel_enable_location_gathering (MMIfaceModemLocation *self,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = g_new0 (LocationGatheringContext, 1);
|
/* Only start GPS engine if not done already */
|
||||||
ctx->source = source;
|
start_gps = ((source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA |
|
||||||
g_task_set_task_data (task, ctx, g_free);
|
MM_MODEM_LOCATION_SOURCE_GPS_RAW |
|
||||||
|
MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) &&
|
||||||
|
!(priv->enabled_sources & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA |
|
||||||
|
MM_MODEM_LOCATION_SOURCE_GPS_RAW |
|
||||||
|
MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)));
|
||||||
|
|
||||||
/* RAW, NMEA and UNMANAGED are all enabled in the same way */
|
priv->enabled_sources |= source;
|
||||||
if (ctx->source & (MM_MODEM_LOCATION_SOURCE_GPS_NMEA |
|
|
||||||
MM_MODEM_LOCATION_SOURCE_GPS_RAW |
|
|
||||||
MM_MODEM_LOCATION_SOURCE_GPS_UNMANAGED)) {
|
|
||||||
if (priv->enabled_sources == MM_MODEM_LOCATION_SOURCE_NONE)
|
|
||||||
start_gps = TRUE;
|
|
||||||
|
|
||||||
priv->enabled_sources |= ctx->source;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (start_gps) {
|
if (start_gps) {
|
||||||
run_gps_startup (task);
|
mm_base_modem_at_sequence (
|
||||||
|
MM_BASE_MODEM (self),
|
||||||
|
gps_startup,
|
||||||
|
NULL, /* response_processor_context */
|
||||||
|
NULL, /* response_processor_context_free */
|
||||||
|
(GAsyncReadyCallback)gps_startup_ready,
|
||||||
|
task);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For any other location (e.g. 3GPP), or if the GPS is already running just return */
|
/* If the GPS is already running just return */
|
||||||
g_task_return_boolean (task, TRUE);
|
g_task_return_boolean (task, TRUE);
|
||||||
g_object_unref (task);
|
g_object_unref (task);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user