force running loc-start and loc-follow-nmea

This commit is contained in:
Daniel Barlow 2024-07-23 23:50:01 +01:00
parent be10ba1b8a
commit 9dce5a04e6
2 changed files with 48 additions and 102 deletions

View File

@ -276,6 +276,8 @@ release_client_ready (QmiDevice *dev,
qmi_device_close_async (dev, 10, NULL, (GAsyncReadyCallback) close_ready, NULL);
}
static guint8 saved_cid = QMI_CID_NONE;
void
qmicli_async_operation_done (gboolean reported_operation_status,
gboolean skip_cid_release)
@ -294,8 +296,10 @@ qmicli_async_operation_done (gboolean reported_operation_status,
return;
}
if (skip_cid_release)
if (skip_cid_release) {
g_debug ("Skipped CID release");
saved_cid = qmi_client_get_cid (client);
}
else if (!client_no_release_cid_flag)
flags |= QMI_DEVICE_RELEASE_CLIENT_FLAGS_RELEASE_CID;
else
@ -362,6 +366,10 @@ device_allocate_client (QmiDevice *dev)
cid = (guint8)cid32;
g_debug ("Reusing CID '%u'", cid);
}
if (saved_cid != QMI_CID_NONE) {
cid = saved_cid;
g_debug ("Using saved CID '%u'", cid);
}
/* As soon as we get the QmiDevice, create a client for the requested
* service */
@ -626,17 +634,8 @@ parse_actions (void)
{
guint actions_enabled = 0;
#if defined HAVE_QMI_SERVICE_LOC
if (qmicli_loc_options_enabled ()) {
service = QMI_SERVICE_LOC;
actions_enabled++;
}
#endif
/* No options? */
if (actions_enabled == 0) {
g_printerr ("error: no actions specified\n");
exit (EXIT_FAILURE);
}
qmicli_loc_options_enabled ();
service = QMI_SERVICE_LOC;
/* Go on! */
}
@ -711,28 +710,30 @@ int main (int argc, char **argv)
parse_actions ();
/* Create requirements for async options */
cancellable = g_cancellable_new ();
loop = g_main_loop_new (NULL, FALSE);
for(int i=0; i<2; i++){
/* Create requirements for async options */
cancellable = g_cancellable_new ();
loop = g_main_loop_new (NULL, FALSE);
/* Setup signals */
g_unix_signal_add (SIGINT, (GSourceFunc) signals_handler, NULL);
g_unix_signal_add (SIGHUP, (GSourceFunc) signals_handler, NULL);
g_unix_signal_add (SIGTERM, (GSourceFunc) signals_handler, NULL);
/* Setup signals */
g_unix_signal_add (SIGINT, (GSourceFunc) signals_handler, NULL);
g_unix_signal_add (SIGHUP, (GSourceFunc) signals_handler, NULL);
g_unix_signal_add (SIGTERM, (GSourceFunc) signals_handler, NULL);
/* Launch QmiDevice creation */
if (!make_device (file))
return EXIT_FAILURE;
/* Launch QmiDevice creation */
if (!make_device (file))
return EXIT_FAILURE;
g_main_loop_run (loop);
g_main_loop_run (loop);
if (cancellable)
g_object_unref (cancellable);
if (client)
g_object_unref (client);
if (device)
g_object_unref (device);
g_main_loop_unref (loop);
}
if (cancellable)
g_object_unref (cancellable);
if (client)
g_object_unref (client);
if (device)
g_object_unref (device);
g_main_loop_unref (loop);
g_object_unref (file);
return (operation_status ? EXIT_SUCCESS : EXIT_FAILURE);

View File

@ -59,7 +59,7 @@ static Context *ctx;
/* Options */
static gint session_id;
static gboolean start_flag;
static gboolean start_flag = 1;
static gboolean stop_flag;
static gint timeout;
static gboolean follow_nmea_flag;
@ -68,27 +68,6 @@ static gboolean noop_flag;
#define DEFAULT_LOC_TIMEOUT_SECS 30
static GOptionEntry entries[] = {
#if defined HAVE_QMI_MESSAGE_LOC_START
{
"loc-start", 0, 0, G_OPTION_ARG_NONE, &start_flag,
"Start location gathering",
NULL,
},
#endif
#if defined HAVE_QMI_MESSAGE_LOC_STOP
{
"loc-stop", 0, 0, G_OPTION_ARG_NONE, &stop_flag,
"Stop location gathering",
NULL,
},
#endif
#if defined HAVE_QMI_INDICATION_LOC_NMEA && defined HAVE_QMI_MESSAGE_LOC_REGISTER_EVENTS
{
"loc-follow-nmea", 0, 0, G_OPTION_ARG_NONE, &follow_nmea_flag,
"Follow all NMEA trace updates reported by the location module indefinitely",
NULL,
},
#endif
{ NULL, 0, 0, 0, NULL, NULL, NULL }
};
@ -108,50 +87,10 @@ qmicli_loc_get_option_group (void)
gboolean
qmicli_loc_options_enabled (void)
{
static guint n_actions = 0;
static gboolean checked = FALSE;
gboolean follow_action;
if (checked)
return !!n_actions;
/* Let's define the following actions:
* - Start location engine
* - Stop location engine
* - Show current position (oneshot).
* - Show current satellite info (oneshot).
* - Follow updates indefinitely, including either position, satellite info or NMEA traces.
* - Other single-request operations.
*/
follow_action = !!(follow_nmea_flag);
n_actions = (start_flag +
stop_flag +
follow_action +
noop_flag);
if (n_actions > 1) {
g_printerr ("error: too many LOC actions requested\n");
exit (EXIT_FAILURE);
}
if (session_id < 0 || session_id > G_MAXUINT8) {
g_printerr ("error: invalid session ID: %d [0,%u]\n", session_id, G_MAXUINT8);
exit (EXIT_FAILURE);
}
if (timeout < 0) {
g_printerr ("error: invalid timeout: %d", timeout);
exit (EXIT_FAILURE);
}
/* Actions that require receiving QMI indication messages must specify that
* indications are expected. */
if (follow_action)
qmicli_expect_indications ();
checked = TRUE;
return !!n_actions;
start_flag = !0;
follow_nmea_flag = 0;
g_debug("enabled %u %u", start_flag, follow_nmea_flag);
return start_flag;
}
static void
@ -412,7 +351,8 @@ start_ready (QmiClientLoc *client,
qmi_device_get_path_display (ctx->device), session_id);
qmi_message_loc_start_output_unref (output);
operation_shutdown (TRUE);
context_free (ctx);
qmicli_async_operation_done (TRUE, TRUE);
}
#endif /* HAVE_QMI_MESSAGE_LOC_START */
@ -435,6 +375,9 @@ qmicli_loc_run (QmiDevice *device,
ctx->client = g_object_ref (client);
ctx->cancellable = g_object_ref (cancellable);
g_debug("qmicli_loc_run start_flag %u stop-flag %u follow_nmea_flag %u",
start_flag, stop_flag, follow_nmea_flag);
#if defined HAVE_QMI_MESSAGE_LOC_START
if (start_flag) {
QmiMessageLocStartInput *input;
@ -451,6 +394,10 @@ qmicli_loc_run (QmiDevice *device,
(GAsyncReadyCallback) start_ready,
NULL);
qmi_message_loc_start_input_unref (input);
start_flag = 0;
follow_nmea_flag = 1;
g_debug("qmicli_loc_run returning, start_flag %u stop-flag %u follow_nmea_flag %u",
start_flag, stop_flag, follow_nmea_flag);
return;
}
#endif
@ -472,17 +419,15 @@ qmicli_loc_run (QmiDevice *device,
}
#endif
#if (defined HAVE_QMI_INDICATION_LOC_POSITION_REPORT || \
defined HAVE_QMI_INDICATION_LOC_GNSS_SV_INFO || \
defined HAVE_QMI_INDICATION_LOC_NMEA) && \
defined HAVE_QMI_MESSAGE_LOC_REGISTER_EVENTS
if (follow_nmea_flag) {
qmicli_expect_indications ();
/* All the remaining actions require monitoring */
ctx->monitoring_step = MONITORING_STEP_FIRST;
monitoring_step_run ();
g_debug("qmicli_loc_run returning, start_flag %u stop-flag %u follow_nmea_flag %u",
start_flag, stop_flag, follow_nmea_flag);
return;
}
#endif
/* Just client allocate/release? */
if (noop_flag) {