| 1 |
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* qmicli -- Command line interface to control QMI devices |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation, either version 2 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
* |
| 18 |
* Copyright (C) 2018 Thomas Weißschuh <[email protected]> |
| 19 |
* Copyright (C) 2018 Aleksander Morgado <[email protected]> |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "config.h" |
| 23 |
|
| 24 |
#include <stdio.h> |
| 25 |
#include <stdlib.h> |
| 26 |
#include <locale.h> |
| 27 |
#include <math.h> |
| 28 |
#include <string.h> |
| 29 |
|
| 30 |
#include <glib.h> |
| 31 |
#include <gio/gio.h> |
| 32 |
|
| 33 |
#include <libqmi-glib.h> |
| 34 |
|
| 35 |
#include "qmicli.h" |
| 36 |
#include "qmicli-helpers.h" |
| 37 |
|
| 38 |
#if defined HAVE_QMI_SERVICE_LOC |
| 39 |
|
| 40 |
#undef VALIDATE_MASK_NONE |
| 41 |
#define VALIDATE_MASK_NONE(str) (str ? str : "none") |
| 42 |
|
| 43 |
/* Context */ |
| 44 |
|
| 45 |
typedef enum { |
| 46 |
MONITORING_STEP_FIRST, |
| 47 |
MONITORING_STEP_REGISTER_EVENTS, |
| 48 |
MONITORING_STEP_SETUP_TIMEOUT, |
| 49 |
MONITORING_STEP_ONGOING, |
| 50 |
} MonitoringStep; |
| 51 |
|
| 52 |
typedef struct { |
| 53 |
QmiDevice *device; |
| 54 |
QmiClientLoc *client; |
| 55 |
GCancellable *cancellable; |
| 56 |
guint timeout_id; |
| 57 |
MonitoringStep monitoring_step; |
| 58 |
guint position_report_indication_id; |
| 59 |
guint nmea_indication_id; |
| 60 |
guint gnss_sv_info_indication_id; |
| 61 |
guint delete_assistance_data_indication_id; |
| 62 |
guint get_nmea_types_indication_id; |
| 63 |
guint set_nmea_types_indication_id; |
| 64 |
guint get_operation_mode_indication_id; |
| 65 |
guint set_operation_mode_indication_id; |
| 66 |
guint get_engine_lock_indication_id; |
| 67 |
guint set_engine_lock_indication_id; |
| 68 |
guint inject_position_indication_id; |
| 69 |
guint inject_time_indication_id; |
| 70 |
guint get_predicted_orbits_data_source_indication_id; |
| 71 |
guint get_predicted_orbits_data_validity_indication_id; |
| 72 |
} Context; |
| 73 |
static Context *ctx; |
| 74 |
|
| 75 |
/* Options */ |
| 76 |
static gint session_id; |
| 77 |
static gboolean start_flag; |
| 78 |
static gboolean stop_flag; |
| 79 |
static gboolean get_position_report_flag; |
| 80 |
static gboolean get_gnss_sv_info_flag; |
| 81 |
static gint timeout; |
| 82 |
static gboolean follow_position_report_flag; |
| 83 |
static gboolean follow_gnss_sv_info_flag; |
| 84 |
static gboolean follow_nmea_flag; |
| 85 |
static gboolean delete_assistance_data_flag; |
| 86 |
static gboolean get_nmea_types_flag; |
| 87 |
static gchar *set_nmea_types_str; |
| 88 |
static gboolean get_operation_mode_flag; |
| 89 |
static gchar *set_operation_mode_str; |
| 90 |
static gboolean get_engine_lock_flag; |
| 91 |
static gchar *set_engine_lock_str; |
| 92 |
static gdouble inject_position_latitude = NAN; |
| 93 |
static gdouble inject_position_longitude = NAN; |
| 94 |
static gboolean inject_time_flag; |
| 95 |
static gboolean get_predicted_orbits_data_source_flag; |
| 96 |
static gboolean get_predicted_orbits_data_validity_flag; |
| 97 |
static gboolean noop_flag; |
| 98 |
|
| 99 |
#define DEFAULT_LOC_TIMEOUT_SECS 30 |
| 100 |
|
| 101 |
static GOptionEntry entries[] = { |
| 102 |
#if defined HAVE_QMI_MESSAGE_LOC_START || defined HAVE_QMI_MESSAGE_LOC_STOP |
| 103 |
{ |
| 104 |
"loc-session-id", 0, 0, G_OPTION_ARG_INT, &session_id, |
| 105 |
"Session ID for the LOC session", |
| 106 |
"[ID]", |
| 107 |
}, |
| 108 |
#endif |
| 109 |
#if defined HAVE_QMI_MESSAGE_LOC_START |
| 110 |
{ |
| 111 |
"loc-start", 0, 0, G_OPTION_ARG_NONE, &start_flag, |
| 112 |
"Start location gathering", |
| 113 |
NULL, |
| 114 |
}, |
| 115 |
#endif |
| 116 |
#if defined HAVE_QMI_MESSAGE_LOC_STOP |
| 117 |
{ |
| 118 |
"loc-stop", 0, 0, G_OPTION_ARG_NONE, &stop_flag, |
| 119 |
"Stop location gathering", |
| 120 |
NULL, |
| 121 |
}, |
| 122 |
#endif |
| 123 |
#if defined HAVE_QMI_INDICATION_LOC_POSITION_REPORT && defined HAVE_QMI_MESSAGE_LOC_REGISTER_EVENTS |
| 124 |
{ |
| 125 |
"loc-get-position-report", 0, 0, G_OPTION_ARG_NONE, &get_position_report_flag, |
| 126 |
"Get position reported by the location module", |
| 127 |
NULL, |
| 128 |
}, |
| 129 |
#endif |
| 130 |
#if defined HAVE_QMI_INDICATION_LOC_GNSS_SV_INFO && defined HAVE_QMI_MESSAGE_LOC_REGISTER_EVENTS |
| 131 |
{ |
| 132 |
"loc-get-gnss-sv-info", 0, 0, G_OPTION_ARG_NONE, &get_gnss_sv_info_flag, |
| 133 |
"Show GNSS space vehicle info", |
| 134 |
NULL, |
| 135 |
}, |
| 136 |
#endif |
| 137 |
#if (defined HAVE_QMI_INDICATION_LOC_POSITION_REPORT || defined HAVE_QMI_INDICATION_LOC_GNSS_SV_INFO) && \ |
| 138 |
defined HAVE_QMI_MESSAGE_LOC_REGISTER_EVENTS |
| 139 |
{ |
| 140 |
"loc-timeout", 0, 0, G_OPTION_ARG_INT, &timeout, |
| 141 |
"Maximum time to wait for information in `--loc-get-position-report' and `--loc-get-gnss-sv-info' (default 30s)", |
| 142 |
"[SECS]", |
| 143 |
}, |
| 144 |
#endif |
| 145 |
#if defined HAVE_QMI_INDICATION_LOC_POSITION_REPORT && defined HAVE_QMI_MESSAGE_LOC_REGISTER_EVENTS |
| 146 |
{ |
| 147 |
"loc-follow-position-report", 0, 0, G_OPTION_ARG_NONE, &follow_position_report_flag, |
| 148 |
"Follow all position updates reported by the location module indefinitely", |
| 149 |
NULL, |
| 150 |
}, |
| 151 |
#endif |
| 152 |
#if defined HAVE_QMI_INDICATION_LOC_GNSS_SV_INFO && defined HAVE_QMI_MESSAGE_LOC_REGISTER_EVENTS |
| 153 |
{ |
| 154 |
"loc-follow-gnss-sv-info", 0, 0, G_OPTION_ARG_NONE, &follow_gnss_sv_info_flag, |
| 155 |
"Follow all GNSS space vehicle info updates reported by the location module indefinitely", |
| 156 |
NULL, |
| 157 |
}, |
| 158 |
#endif |
| 159 |
#if defined HAVE_QMI_INDICATION_LOC_NMEA && defined HAVE_QMI_MESSAGE_LOC_REGISTER_EVENTS |
| 160 |
{ |
| 161 |
"loc-follow-nmea", 0, 0, G_OPTION_ARG_NONE, &follow_nmea_flag, |
| 162 |
"Follow all NMEA trace updates reported by the location module indefinitely", |
| 163 |
NULL, |
| 164 |
}, |
| 165 |
#endif |
| 166 |
#if defined HAVE_QMI_MESSAGE_LOC_DELETE_ASSISTANCE_DATA |
| 167 |
{ |
| 168 |
"loc-delete-assistance-data", 0, 0, G_OPTION_ARG_NONE, &delete_assistance_data_flag, |
| 169 |
"Delete positioning assistance data", |
| 170 |
NULL, |
| 171 |
}, |
| 172 |
#endif |
| 173 |
#if defined HAVE_QMI_MESSAGE_LOC_GET_NMEA_TYPES |
| 174 |
{ "loc-get-nmea-types", 0, 0, G_OPTION_ARG_NONE, &get_nmea_types_flag, |
| 175 |
"Get list of enabled NMEA traces", |
| 176 |
NULL |
| 177 |
}, |
| 178 |
#endif |
| 179 |
#if defined HAVE_QMI_MESSAGE_LOC_SET_NMEA_TYPES |
| 180 |
{ "loc-set-nmea-types", 0, 0, G_OPTION_ARG_STRING, &set_nmea_types_str, |
| 181 |
"Set list of enabled NMEA traces", |
| 182 |
"[type1|type2|type3...]" |
| 183 |
}, |
| 184 |
#endif |
| 185 |
#if defined HAVE_QMI_MESSAGE_LOC_GET_OPERATION_MODE |
| 186 |
{ "loc-get-operation-mode", 0, 0, G_OPTION_ARG_NONE, &get_operation_mode_flag, |
| 187 |
"Get operation mode", |
| 188 |
NULL |
| 189 |
}, |
| 190 |
#endif |
| 191 |
#if defined HAVE_QMI_MESSAGE_LOC_SET_OPERATION_MODE |
| 192 |
{ "loc-set-operation-mode", 0, 0, G_OPTION_ARG_STRING, &set_operation_mode_str, |
| 193 |
"Set operation mode", |
| 194 |
"[default|msb|msa|standalone|cellid|wwan]" |
| 195 |
}, |
| 196 |
#endif |
| 197 |
#if defined HAVE_QMI_MESSAGE_LOC_GET_ENGINE_LOCK |
| 198 |
{ "loc-get-engine-lock", 0, 0, G_OPTION_ARG_NONE, &get_engine_lock_flag, |
| 199 |
"Get engine lock status", |
| 200 |
NULL |
| 201 |
}, |
| 202 |
#endif |
| 203 |
#if defined HAVE_QMI_MESSAGE_LOC_SET_ENGINE_LOCK |
| 204 |
{ "loc-set-engine-lock", 0, 0, G_OPTION_ARG_STRING, &set_engine_lock_str, |
| 205 |
"Set engine lock status", |
| 206 |
"[none|mi|mt|all]" |
| 207 |
}, |
| 208 |
#endif |
| 209 |
#if defined HAVE_QMI_MESSAGE_LOC_INJECT_POSITION |
| 210 |
{ "loc-inject-position-latitude", 0, 0, G_OPTION_ARG_DOUBLE, &inject_position_latitude, |
| 211 |
"Inject latitude into GNSS engine", |
| 212 |
"-90.0 to 90.0. Positive values indicate northern latitude." |
| 213 |
}, |
| 214 |
{ "loc-inject-position-longitude", 0, 0, G_OPTION_ARG_DOUBLE, &inject_position_longitude, |
| 215 |
"Inject longitude into GNSS engine", |
| 216 |
"-180.0 to 180.0. Positive values indicate eastern longitude." |
| 217 |
}, |
| 218 |
#endif |
| 219 |
#if defined HAVE_QMI_MESSAGE_LOC_INJECT_UTC_TIME |
| 220 |
{ "loc-inject-time", 0, 0, G_OPTION_ARG_NONE, &inject_time_flag, |
| 221 |
"Inject UTC time into GNSS engine", |
| 222 |
NULL |
| 223 |
}, |
| 224 |
#endif |
| 225 |
#if defined HAVE_QMI_MESSAGE_LOC_GET_PREDICTED_ORBITS_DATA_SOURCE |
| 226 |
{ "loc-get-predicted-orbits-data-source", 0, 0, G_OPTION_ARG_NONE, &get_predicted_orbits_data_source_flag, |
| 227 |
"Get predicted orbits data source", |
| 228 |
NULL |
| 229 |
}, |
| 230 |
#endif |
| 231 |
#if defined HAVE_QMI_MESSAGE_LOC_GET_PREDICTED_ORBITS_DATA_VALIDITY |
| 232 |
{ "loc-get-predicted-orbits-data-validity", 0, 0, G_OPTION_ARG_NONE, &get_predicted_orbits_data_validity_flag, |
| 233 |
"Get predicted orbits data validity information", |
| 234 |
NULL |
| 235 |
}, |
| 236 |
#endif |
| 237 |
{ "loc-noop", 0, 0, G_OPTION_ARG_NONE, &noop_flag, |
| 238 |
"Just allocate or release a LOC client. Use with `--client-no-release-cid' and/or `--client-cid'", |
| 239 |
NULL |
| 240 |
}, |
| 241 |
{ NULL, 0, 0, 0, NULL, NULL, NULL } |
| 242 |
}; |
| 243 |
|
| 244 |
GOptionGroup * |
| 245 |
qmicli_loc_get_option_group (void) |
| 246 |
{ |
| 247 |
GOptionGroup *group; |
| 248 |
|
| 249 |
group = g_option_group_new ("loc", |
| 250 |
"LOC options:", |
| 251 |
"Show location options", NULL, NULL); |
| 252 |
g_option_group_add_entries (group, entries); |
| 253 |
|
| 254 |
return group; |
| 255 |
} |
| 256 |
|
| 257 |
gboolean |
| 258 |
qmicli_loc_options_enabled (void) |
| 259 |
{ |
| 260 |
static guint n_actions = 0; |
| 261 |
static gboolean checked = FALSE; |
| 262 |
gboolean follow_action; |
| 263 |
|
| 264 |
if (checked) |
| 265 |
return !!n_actions; |
| 266 |
|
| 267 |
/* Let's define the following actions: |
| 268 |
* - Start location engine |
| 269 |
* - Stop location engine |
| 270 |
* - Show current position (oneshot). |
| 271 |
* - Show current satellite info (oneshot). |
| 272 |
* - Follow updates indefinitely, including either position, satellite info or NMEA traces. |
| 273 |
* - Other single-request operations. |
| 274 |
*/ |
| 275 |
follow_action = !!(follow_position_report_flag + follow_gnss_sv_info_flag + follow_nmea_flag); |
| 276 |
n_actions = (start_flag + |
| 277 |
stop_flag + |
| 278 |
get_position_report_flag + |
| 279 |
get_gnss_sv_info_flag + |
| 280 |
follow_action + |
| 281 |
delete_assistance_data_flag + |
| 282 |
get_nmea_types_flag + |
| 283 |
!!set_nmea_types_str + |
| 284 |
get_operation_mode_flag + |
| 285 |
!!set_operation_mode_str + |
| 286 |
get_engine_lock_flag + |
| 287 |
!!set_engine_lock_str + |
| 288 |
(!isnan (inject_position_latitude) || !isnan (inject_position_longitude)) + |
| 289 |
inject_time_flag + |
| 290 |
get_predicted_orbits_data_source_flag + |
| 291 |
get_predicted_orbits_data_validity_flag + |
| 292 |
noop_flag); |
| 293 |
|
| 294 |
if (n_actions > 1) { |
| 295 |
g_printerr ("error: too many LOC actions requested\n"); |
| 296 |
exit (EXIT_FAILURE); |
| 297 |
} |
| 298 |
|
| 299 |
if (session_id < 0 || session_id > G_MAXUINT8) { |
| 300 |
g_printerr ("error: invalid session ID: %d [0,%u]\n", session_id, G_MAXUINT8); |
| 301 |
exit (EXIT_FAILURE); |
| 302 |
} |
| 303 |
|
| 304 |
if (timeout < 0) { |
| 305 |
g_printerr ("error: invalid timeout: %d", timeout); |
| 306 |
exit (EXIT_FAILURE); |
| 307 |
} |
| 308 |
|
| 309 |
if (timeout > 0 && !(get_position_report_flag || get_gnss_sv_info_flag)) { |
| 310 |
g_printerr ("error: `--loc-timeout' is only applicable with `--loc-get-position-report' or `--loc-get-gnss-sv-info'\n"); |
| 311 |
exit (EXIT_FAILURE); |
| 312 |
} |
| 313 |
|
| 314 |
/* Actions that require receiving QMI indication messages must specify that |
| 315 |
* indications are expected. */ |
| 316 |
if (get_position_report_flag || |
| 317 |
get_gnss_sv_info_flag || |
| 318 |
follow_action || |
| 319 |
delete_assistance_data_flag || |
| 320 |
get_nmea_types_flag || |
| 321 |
set_nmea_types_str || |
| 322 |
get_operation_mode_flag || |
| 323 |
set_operation_mode_str || |
| 324 |
get_engine_lock_flag || |
| 325 |
set_engine_lock_str || |
| 326 |
!isnan (inject_position_latitude) || |
| 327 |
!isnan (inject_position_longitude) || |
| 328 |
inject_time_flag || |
| 329 |
get_predicted_orbits_data_source_flag || |
| 330 |
get_predicted_orbits_data_validity_flag) |
| 331 |
qmicli_expect_indications (); |
| 332 |
|
| 333 |
checked = TRUE; |
| 334 |
return !!n_actions; |
| 335 |
} |
| 336 |
|
| 337 |
static void |
| 338 |
context_free (Context *context) |
| 339 |
{ |
| 340 |
if (!context) |
| 341 |
return; |
| 342 |
|
| 343 |
if (context->timeout_id) |
| 344 |
g_source_remove (context->timeout_id); |
| 345 |
|
| 346 |
if (context->position_report_indication_id) |
| 347 |
g_signal_handler_disconnect (context->client, context->position_report_indication_id); |
| 348 |
|
| 349 |
if (context->gnss_sv_info_indication_id) |
| 350 |
g_signal_handler_disconnect (context->client, context->gnss_sv_info_indication_id); |
| 351 |
|
| 352 |
if (context->nmea_indication_id) |
| 353 |
g_signal_handler_disconnect (context->client, context->nmea_indication_id); |
| 354 |
|
| 355 |
if (context->delete_assistance_data_indication_id) |
| 356 |
g_signal_handler_disconnect (context->client, context->delete_assistance_data_indication_id); |
| 357 |
|
| 358 |
if (context->get_nmea_types_indication_id) |
| 359 |
g_signal_handler_disconnect (context->client, context->get_nmea_types_indication_id); |
| 360 |
|
| 361 |
if (context->set_nmea_types_indication_id) |
| 362 |
g_signal_handler_disconnect (context->client, context->set_nmea_types_indication_id); |
| 363 |
|
| 364 |
if (context->get_operation_mode_indication_id) |
| 365 |
g_signal_handler_disconnect (context->client, context->get_operation_mode_indication_id); |
| 366 |
|
| 367 |
if (context->set_operation_mode_indication_id) |
| 368 |
g_signal_handler_disconnect (context->client, context->set_operation_mode_indication_id); |
| 369 |
|
| 370 |
if (context->get_engine_lock_indication_id) |
| 371 |
g_signal_handler_disconnect (context->client, context->get_engine_lock_indication_id); |
| 372 |
|
| 373 |
if (context->set_engine_lock_indication_id) |
| 374 |
g_signal_handler_disconnect (context->client, context->set_engine_lock_indication_id); |
| 375 |
|
| 376 |
if (context->inject_position_indication_id) |
| 377 |
g_signal_handler_disconnect (context->client, context->inject_position_indication_id); |
| 378 |
|
| 379 |
if (context->inject_time_indication_id) |
| 380 |
g_signal_handler_disconnect (context->client, context->inject_time_indication_id); |
| 381 |
|
| 382 |
if (context->get_predicted_orbits_data_source_indication_id) |
| 383 |
g_signal_handler_disconnect (context->client, context->get_predicted_orbits_data_source_indication_id); |
| 384 |
|
| 385 |
if (context->get_predicted_orbits_data_validity_indication_id) |
| 386 |
g_signal_handler_disconnect (context->client, context->get_predicted_orbits_data_validity_indication_id); |
| 387 |
|
| 388 |
g_clear_object (&context->cancellable); |
| 389 |
g_clear_object (&context->client); |
| 390 |
g_clear_object (&context->device); |
| 391 |
g_slice_free (Context, context); |
| 392 |
} |
| 393 |
|
| 394 |
static void |
| 395 |
operation_shutdown (gboolean operation_status) |
| 396 |
{ |
| 397 |
context_free (ctx); |
| 398 |
qmicli_async_operation_done (operation_status, FALSE); |
| 399 |
} |
| 400 |
|
| 401 |
#if (defined HAVE_QMI_INDICATION_LOC_POSITION_REPORT || \ |
| 402 |
defined HAVE_QMI_INDICATION_LOC_GNSS_SV_INFO || \ |
| 403 |
defined HAVE_QMI_INDICATION_LOC_NMEA) && \ |
| 404 |
defined HAVE_QMI_MESSAGE_LOC_REGISTER_EVENTS |
| 405 |
|
| 406 |
static void monitoring_step_run (void); |
| 407 |
|
| 408 |
static gboolean |
| 409 |
monitoring_timed_out (void) |
| 410 |
{ |
| 411 |
ctx->timeout_id = 0; |
| 412 |
g_printerr ("error: operation failed: timeout\n"); |
| 413 |
operation_shutdown (FALSE); |
| 414 |
return G_SOURCE_REMOVE; |
| 415 |
} |
| 416 |
|
| 417 |
static void |
| 418 |
monitoring_cancelled (GCancellable *cancellable) |
| 419 |
{ |
| 420 |
/* For GET operations, this is a failure */ |
| 421 |
if (get_position_report_flag || get_gnss_sv_info_flag) { |
| 422 |
g_printerr ("error: operation failed: cancelled\n"); |
| 423 |
operation_shutdown (FALSE); |
| 424 |
return; |
| 425 |
} |
| 426 |
|
| 427 |
/* For FOLLOW operations, silently exit */ |
| 428 |
if (follow_position_report_flag || follow_gnss_sv_info_flag || follow_nmea_flag) { |
| 429 |
operation_shutdown (TRUE); |
| 430 |
return; |
| 431 |
} |
| 432 |
|
| 433 |
g_assert_not_reached (); |
| 434 |
} |
| 435 |
|
| 436 |
#endif /* HAVE_QMI_INDICATION_LOC_POSITION_REPORT |
| 437 |
* HAVE_QMI_INDICATION_LOC_GNSS_SV_INFO |
| 438 |
* HAVE_QMI_INDICATION_LOC_NMEA */ |
| 439 |
|
| 440 |
#if defined HAVE_QMI_INDICATION_LOC_NMEA && defined HAVE_QMI_MESSAGE_LOC_REGISTER_EVENTS |
| 441 |
|
| 442 |
static void |
| 443 |
nmea_received (QmiClientLoc *client, |
| 444 |
QmiIndicationLocNmeaOutput *output) |
| 445 |
{ |
| 446 |
const gchar *nmea = NULL; |
| 447 |
|
| 448 |
qmi_indication_loc_nmea_output_get_nmea_string (output, &nmea, NULL); |
| 449 |
if (nmea) |
| 450 |
/* Note: NMEA traces already have an EOL */ |
| 451 |
g_print ("%s", nmea); |
| 452 |
} |
| 453 |
|
| 454 |
#endif /* HAVE_QMI_INDICATION_LOC_NMEA */ |
| 455 |
|
| 456 |
#if defined HAVE_QMI_INDICATION_LOC_GNSS_SV_INFO && defined HAVE_QMI_MESSAGE_LOC_REGISTER_EVENTS |
| 457 |
|
| 458 |
static void |
| 459 |
gnss_sv_info_received (QmiClientLoc *client, |
| 460 |
QmiIndicationLocGnssSvInfoOutput *output) |
| 461 |
{ |
| 462 |
GArray *satellite_infos = NULL; |
| 463 |
guint i, num_satellite_infos; |
| 464 |
gboolean altitude_assumed; |
| 465 |
|
| 466 |
if (qmi_indication_loc_gnss_sv_info_output_get_altitude_assumed (output, &altitude_assumed, NULL)) |
| 467 |
g_print ("[gnss sv info] Altitude assumed: %s\n", altitude_assumed ? "yes" : "no"); |
| 468 |
else |
| 469 |
g_print ("[gnss sv info] Altitude assumed: n/a\n"); |
| 470 |
|
| 471 |
qmi_indication_loc_gnss_sv_info_output_get_list (output, &satellite_infos, NULL); |
| 472 |
|
| 473 |
num_satellite_infos = satellite_infos ? satellite_infos->len : 0; |
| 474 |
g_print ("[gnss sv info] %d satellites detected:\n", num_satellite_infos); |
| 475 |
for (i = 0; i < num_satellite_infos; i++) { |
| 476 |
QmiIndicationLocGnssSvInfoOutputListElement *element; |
| 477 |
|
| 478 |
element = &g_array_index (satellite_infos, QmiIndicationLocGnssSvInfoOutputListElement, i); |
| 479 |
g_print (" [satellite #%u]\n", i); |
| 480 |
g_print (" system: %s\n", (element->valid_information & QMI_LOC_SATELLITE_VALID_INFORMATION_SYSTEM) ? qmi_loc_system_get_string (element->system) : "n/a"); |
| 481 |
if (element->valid_information & QMI_LOC_SATELLITE_VALID_INFORMATION_GNSS_SATELLITE_ID) |
| 482 |
g_print (" satellite id: %u\n", element->gnss_satellite_id); |
| 483 |
else |
| 484 |
g_print (" satellite id: n/a\n"); |
| 485 |
g_print (" health status: %s\n", (element->valid_information & QMI_LOC_SATELLITE_VALID_INFORMATION_HEALTH_STATUS) ? qmi_loc_health_status_get_string (element->health_status) : "n/a"); |
| 486 |
g_print (" satellite status: %s\n", (element->valid_information & QMI_LOC_SATELLITE_VALID_INFORMATION_PROCESS_STATUS) ? qmi_loc_satellite_status_get_string (element->satellite_status) : "n/a"); |
| 487 |
g_print (" navigation data: %s\n", (element->valid_information & QMI_LOC_SATELLITE_VALID_INFORMATION_SATELLITE_INFO_MASK) ? qmi_loc_navigation_data_get_string (element->navigation_data) : "n/a"); |
| 488 |
|
| 489 |
if (element->valid_information & QMI_LOC_SATELLITE_VALID_INFORMATION_ELEVATION) |
| 490 |
g_print (" elevation: %lf\n", (gdouble)element->elevation_degrees); |
| 491 |
else |
| 492 |
g_print (" elevation: n/a\n"); |
| 493 |
|
| 494 |
if (element->valid_information & QMI_LOC_SATELLITE_VALID_INFORMATION_AZIMUTH) |
| 495 |
g_print (" azimuth: %lf\n", (gdouble)element->azimuth_degrees); |
| 496 |
else |
| 497 |
g_print (" azimuth: n/a\n"); |
| 498 |
|
| 499 |
if (element->valid_information & QMI_LOC_SATELLITE_VALID_INFORMATION_SIGNAL_TO_NOISE_RATIO) |
| 500 |
g_print (" SNR: %lf\n", (gdouble)element->signal_to_noise_ratio_bhz); |
| 501 |
else |
| 502 |
g_print (" SNR: n/a\n"); |
| 503 |
} |
| 504 |
|
| 505 |
/* Terminate GET request */ |
| 506 |
if (get_gnss_sv_info_flag) |
| 507 |
operation_shutdown (TRUE); |
| 508 |
} |
| 509 |
|
| 510 |
#endif /* HAVE_QMI_INDICATION_LOC_GNSS_SV_INFO */ |
| 511 |
|
| 512 |
#if defined HAVE_QMI_INDICATION_LOC_POSITION_REPORT && defined HAVE_QMI_MESSAGE_LOC_REGISTER_EVENTS |
| 513 |
|
| 514 |
static void |
| 515 |
position_report_received (QmiClientLoc *client, |
| 516 |
QmiIndicationLocPositionReportOutput *output) |
| 517 |
{ |
| 518 |
QmiLocSessionStatus status; |
| 519 |
|
| 520 |
qmi_indication_loc_position_report_output_get_session_status (output, &status, NULL); |
| 521 |
g_print ("[position report] status: %s\n", qmi_loc_session_status_get_string (status)); |
| 522 |
|
| 523 |
if (status == QMI_LOC_SESSION_STATUS_SUCCESS || status == QMI_LOC_SESSION_STATUS_IN_PROGRESS) { |
| 524 |
gdouble auxd; |
| 525 |
gfloat auxf; |
| 526 |
guint8 aux8; |
| 527 |
guint32 aux32; |
| 528 |
guint64 aux64; |
| 529 |
QmiLocReliability reliability; |
| 530 |
QmiLocTechnologyUsed technology; |
| 531 |
QmiLocTimeSource time_source; |
| 532 |
QmiLocSensorDataUsage sensor_data_usage; |
| 533 |
gfloat pdop; |
| 534 |
gfloat hdop; |
| 535 |
gfloat vdop; |
| 536 |
guint16 gps_weeks; |
| 537 |
guint32 gps_time_of_week_milliseconds; |
| 538 |
gboolean auxb; |
| 539 |
GArray *array; |
| 540 |
|
| 541 |
if (qmi_indication_loc_position_report_output_get_latitude (output, &auxd, NULL)) |
| 542 |
g_print (" latitude: %lf degrees\n", auxd); |
| 543 |
else |
| 544 |
g_print (" latitude: n/a\n"); |
| 545 |
|
| 546 |
if (qmi_indication_loc_position_report_output_get_longitude (output, &auxd, NULL)) |
| 547 |
g_print (" longitude: %lf degrees\n", auxd); |
| 548 |
else |
| 549 |
g_print (" longitude: n/a\n"); |
| 550 |
|
| 551 |
if (qmi_indication_loc_position_report_output_get_horizontal_uncertainty_circular (output, &auxf, NULL)) |
| 552 |
g_print (" circular horizontal position uncertainty: %lf meters\n", (gdouble)auxf); |
| 553 |
else |
| 554 |
g_print (" circular horizontal position uncertainty: n/a\n"); |
| 555 |
|
| 556 |
if (qmi_indication_loc_position_report_output_get_horizontal_uncertainty_elliptical_minor (output, &auxf, NULL)) |
| 557 |
g_print (" horizontal elliptical uncertainty (semi-minor axis): %lf meters\n", (gdouble)auxf); |
| 558 |
else |
| 559 |
g_print (" horizontal elliptical uncertainty (semi-minor axis): n/a\n"); |
| 560 |
|
| 561 |
if (qmi_indication_loc_position_report_output_get_horizontal_uncertainty_elliptical_major (output, &auxf, NULL)) |
| 562 |
g_print (" horizontal elliptical uncertainty (semi-major axis): %lf meters\n", (gdouble)auxf); |
| 563 |
else |
| 564 |
g_print (" horizontal elliptical uncertainty (semi-major axis): n/a\n"); |
| 565 |
|
| 566 |
if (qmi_indication_loc_position_report_output_get_horizontal_uncertainty_elliptical_azimuth (output, &auxf, NULL)) |
| 567 |
g_print (" horizontal elliptical uncertainty azimuth: %lf meters\n", (gdouble)auxf); |
| 568 |
else |
| 569 |
g_print (" horizontal elliptical uncertainty azimuth: n/a\n"); |
| 570 |
|
| 571 |
if (qmi_indication_loc_position_report_output_get_horizontal_confidence (output, &aux8, NULL)) |
| 572 |
g_print (" horizontal confidence: %u%%\n", aux8); |
| 573 |
else |
| 574 |
g_print (" horizontal confidence: n/a\n"); |
| 575 |
|
| 576 |
if (qmi_indication_loc_position_report_output_get_horizontal_reliability (output, &reliability, NULL)) |
| 577 |
g_print (" horizontal reliability: %s\n", qmi_loc_reliability_get_string (reliability)); |
| 578 |
else |
| 579 |
g_print (" horizontal reliability: n/a\n"); |
| 580 |
|
| 581 |
if (qmi_indication_loc_position_report_output_get_horizontal_speed (output, &auxf, NULL)) |
| 582 |
g_print (" horizontal speed: %lf m/s\n", (gdouble)auxf); |
| 583 |
else |
| 584 |
g_print (" horizontal speed: n/a\n"); |
| 585 |
|
| 586 |
if (qmi_indication_loc_position_report_output_get_speed_uncertainty (output, &auxf, NULL)) |
| 587 |
g_print (" speed uncertainty: %lf m/s\n", (gdouble)auxf); |
| 588 |
else |
| 589 |
g_print (" speed uncertainty: n/a\n"); |
| 590 |
|
| 591 |
if (qmi_indication_loc_position_report_output_get_altitude_from_ellipsoid (output, &auxf, NULL)) |
| 592 |
g_print (" altitude w.r.t. ellipsoid: %lf meters\n", (gdouble)auxf); |
| 593 |
else |
| 594 |
g_print (" altitude w.r.t. ellipsoid: n/a\n"); |
| 595 |
|
| 596 |
if (qmi_indication_loc_position_report_output_get_altitude_from_sealevel (output, &auxf, NULL)) |
| 597 |
g_print (" altitude w.r.t. mean sea level: %lf meters\n", (gdouble)auxf); |
| 598 |
else |
| 599 |
g_print (" altitude w.r.t. mean sea level: n/a\n"); |
| 600 |
|
| 601 |
if (qmi_indication_loc_position_report_output_get_vertical_uncertainty (output, &auxf, NULL)) |
| 602 |
g_print (" vertical uncertainty: %lf meters\n", (gdouble)auxf); |
| 603 |
else |
| 604 |
g_print (" vertical uncertainty: n/a\n"); |
| 605 |
|
| 606 |
if (qmi_indication_loc_position_report_output_get_vertical_confidence (output, &aux8, NULL)) |
| 607 |
g_print (" vertical confidence: %u%%\n", aux8); |
| 608 |
else |
| 609 |
g_print (" vertical confidence: n/a\n"); |
| 610 |
|
| 611 |
if (qmi_indication_loc_position_report_output_get_vertical_reliability (output, &reliability, NULL)) |
| 612 |
g_print (" vertical reliability: %s\n", qmi_loc_reliability_get_string (reliability)); |
| 613 |
else |
| 614 |
g_print (" vertical reliability: n/a\n"); |
| 615 |
|
| 616 |
if (qmi_indication_loc_position_report_output_get_vertical_speed (output, &auxf, NULL)) |
| 617 |
g_print (" vertical speed: %lf m/s\n", (gdouble)auxf); |
| 618 |
else |
| 619 |
g_print (" vertical speed: n/a\n"); |
| 620 |
|
| 621 |
if (qmi_indication_loc_position_report_output_get_heading (output, &auxf, NULL)) |
| 622 |
g_print (" heading: %lf degrees\n", (gdouble)auxf); |
| 623 |
else |
| 624 |
g_print (" heading: n/a\n"); |
| 625 |
|
| 626 |
if (qmi_indication_loc_position_report_output_get_heading_uncertainty (output, &auxf, NULL)) |
| 627 |
g_print (" heading uncertainty: %lf meters\n", (gdouble)auxf); |
| 628 |
else |
| 629 |
g_print (" heading uncertainty: n/a\n"); |
| 630 |
|
| 631 |
if (qmi_indication_loc_position_report_output_get_magnetic_deviation (output, &auxf, NULL)) |
| 632 |
g_print (" magnetic deviation: %lf degrees\n", (gdouble)auxf); |
| 633 |
else |
| 634 |
g_print (" magnetic deviation: n/a\n"); |
| 635 |
|
| 636 |
if (qmi_indication_loc_position_report_output_get_technology_used (output, &technology, NULL)) { |
| 637 |
g_autofree gchar *technology_str = NULL; |
| 638 |
|
| 639 |
technology_str = qmi_loc_technology_used_build_string_from_mask (technology); |
| 640 |
g_print (" technology: %s\n", VALIDATE_MASK_NONE (technology_str)); |
| 641 |
} else |
| 642 |
g_print (" technology: n/a\n"); |
| 643 |
|
| 644 |
if (qmi_indication_loc_position_report_output_get_dop (output, &pdop, &hdop, &vdop, NULL)) { |
| 645 |
g_print (" position DOP: %lf\n", (gdouble)pdop); |
| 646 |
g_print (" horizontal DOP: %lf\n", (gdouble)hdop); |
| 647 |
g_print (" vertical DOP: %lf\n", (gdouble)vdop); |
| 648 |
} else { |
| 649 |
g_print (" position DOP: n/a\n"); |
| 650 |
g_print (" horizontal DOP: n/a\n"); |
| 651 |
g_print (" vertical DOP: n/a\n"); |
| 652 |
} |
| 653 |
|
| 654 |
if (qmi_indication_loc_position_report_output_get_utc_timestamp (output, &aux64, NULL)) |
| 655 |
g_print (" UTC timestamp: %" G_GUINT64_FORMAT " ms\n", aux64); |
| 656 |
else |
| 657 |
g_print (" UTC timestamp: n/a\n"); |
| 658 |
|
| 659 |
if (qmi_indication_loc_position_report_output_get_leap_seconds (output, &aux8, NULL)) |
| 660 |
g_print (" Leap seconds: %u\n", aux8); |
| 661 |
else |
| 662 |
g_print (" Leap seconds: n/a\n"); |
| 663 |
|
| 664 |
if (qmi_indication_loc_position_report_output_get_gps_date_time (output, &gps_weeks, &gps_time_of_week_milliseconds, NULL)) |
| 665 |
g_print (" GPS time: %u weeks and %ums\n", gps_weeks, gps_time_of_week_milliseconds); |
| 666 |
else |
| 667 |
g_print (" GPS time: n/a\n"); |
| 668 |
|
| 669 |
if (qmi_indication_loc_position_report_output_get_time_uncertainty (output, &auxf, NULL)) |
| 670 |
g_print (" time uncertainty: %lf ms\n", (gdouble)auxf); |
| 671 |
else |
| 672 |
g_print (" time uncertainty: n/a\n"); |
| 673 |
|
| 674 |
if (qmi_indication_loc_position_report_output_get_time_source (output, &time_source, NULL)) |
| 675 |
g_print (" time source: %s\n", qmi_loc_time_source_get_string (time_source)); |
| 676 |
else |
| 677 |
g_print (" time source: n/a\n"); |
| 678 |
|
| 679 |
if (qmi_indication_loc_position_report_output_get_sensor_data_usage (output, &sensor_data_usage, NULL)) { |
| 680 |
g_autofree gchar *sensor_data_usage_str = NULL; |
| 681 |
|
| 682 |
sensor_data_usage_str = qmi_loc_sensor_data_usage_build_string_from_mask (sensor_data_usage); |
| 683 |
g_print (" sensor data usage: %s\n", VALIDATE_MASK_NONE (sensor_data_usage_str)); |
| 684 |
} else |
| 685 |
g_print (" sensor data usage: n/a\n"); |
| 686 |
|
| 687 |
if (qmi_indication_loc_position_report_output_get_session_fix_count (output, &aux32, NULL)) |
| 688 |
g_print (" Fix count: %u\n", aux32); |
| 689 |
else |
| 690 |
g_print (" Fix count: n/a\n"); |
| 691 |
|
| 692 |
if (qmi_indication_loc_position_report_output_get_satellites_used (output, &array, NULL)) { |
| 693 |
guint i; |
| 694 |
|
| 695 |
g_print (" Satellites used: "); |
| 696 |
for (i = 0; i < array->len; i++) { |
| 697 |
guint16 sv_id; |
| 698 |
|
| 699 |
/* |
| 700 |
* - For GPS: 1 to 32 |
| 701 |
* - For SBAS: 33 to 64 |
| 702 |
* - For GLONASS: 65 to 96 |
| 703 |
* - For QZSS: 193 to 197 |
| 704 |
* - For BDS: 201 to 237 |
| 705 |
*/ |
| 706 |
sv_id = g_array_index (array, guint16, i); |
| 707 |
g_print ("%u%s", sv_id, i == array->len - 1 ? "" : ","); |
| 708 |
} |
| 709 |
g_print ("\n"); |
| 710 |
} else |
| 711 |
g_print (" Satellites used: n/a\n"); |
| 712 |
|
| 713 |
if (qmi_indication_loc_position_report_output_get_altitude_assumed (output, &auxb, NULL)) |
| 714 |
g_print (" Altitude assumed: %s\n", auxb ? "yes" : "no"); |
| 715 |
else |
| 716 |
g_print (" Altitude assumed: n/a\n"); |
| 717 |
|
| 718 |
/* Terminate GET request */ |
| 719 |
if (get_position_report_flag) |
| 720 |
operation_shutdown (TRUE); |
| 721 |
|
| 722 |
return; |
| 723 |
} |
| 724 |
|
| 725 |
/* Otherwise, treat as error */ |
| 726 |
g_printerr ("[position report] error: %s\n", qmi_loc_session_status_get_string (status)); |
| 727 |
if (get_position_report_flag) |
| 728 |
operation_shutdown (FALSE); |
| 729 |
} |
| 730 |
|
| 731 |
#endif /* HAVE_QMI_INDICATION_LOC_POSITION_REPORT */ |
| 732 |
|
| 733 |
#if (defined HAVE_QMI_INDICATION_LOC_POSITION_REPORT || \ |
| 734 |
defined HAVE_QMI_INDICATION_LOC_GNSS_SV_INFO || \ |
| 735 |
defined HAVE_QMI_INDICATION_LOC_NMEA) && \ |
| 736 |
defined HAVE_QMI_MESSAGE_LOC_REGISTER_EVENTS |
| 737 |
|
| 738 |
static void |
| 739 |
monitoring_step_ongoing (void) |
| 740 |
{ |
| 741 |
#if defined HAVE_QMI_INDICATION_LOC_POSITION_REPORT |
| 742 |
if (get_position_report_flag || follow_position_report_flag) |
| 743 |
ctx->position_report_indication_id = g_signal_connect (ctx->client, |
| 744 |
"position-report", |
| 745 |
G_CALLBACK (position_report_received), |
| 746 |
NULL); |
| 747 |
#endif |
| 748 |
|
| 749 |
#if defined HAVE_QMI_INDICATION_LOC_GNSS_SV_INFO |
| 750 |
if (get_gnss_sv_info_flag || follow_gnss_sv_info_flag) |
| 751 |
ctx->gnss_sv_info_indication_id = g_signal_connect (ctx->client, |
| 752 |
"gnss-sv-info", |
| 753 |
G_CALLBACK (gnss_sv_info_received), |
| 754 |
NULL); |
| 755 |
#endif |
| 756 |
|
| 757 |
#if defined HAVE_QMI_INDICATION_LOC_NMEA |
| 758 |
if (follow_nmea_flag) |
| 759 |
ctx->nmea_indication_id = g_signal_connect (ctx->client, |
| 760 |
"nmea", |
| 761 |
G_CALLBACK (nmea_received), |
| 762 |
NULL); |
| 763 |
#endif |
| 764 |
|
| 765 |
g_assert (ctx->position_report_indication_id || |
| 766 |
ctx->gnss_sv_info_indication_id || |
| 767 |
ctx->nmea_indication_id); |
| 768 |
} |
| 769 |
|
| 770 |
static void |
| 771 |
monitoring_step_setup_timeout (void) |
| 772 |
{ |
| 773 |
/* User can use Ctrl+C to cancel the monitoring at any time */ |
| 774 |
g_cancellable_connect (ctx->cancellable, |
| 775 |
G_CALLBACK (monitoring_cancelled), |
| 776 |
NULL, |
| 777 |
NULL); |
| 778 |
|
| 779 |
/* For non-follow requests, we also setup a timeout */ |
| 780 |
if (get_position_report_flag || get_gnss_sv_info_flag) |
| 781 |
ctx->timeout_id = g_timeout_add_seconds (timeout > 0 ? timeout : DEFAULT_LOC_TIMEOUT_SECS, |
| 782 |
(GSourceFunc) monitoring_timed_out, |
| 783 |
NULL); |
| 784 |
|
| 785 |
/* Go on */ |
| 786 |
ctx->monitoring_step++; |
| 787 |
monitoring_step_run (); |
| 788 |
} |
| 789 |
|
| 790 |
static void |
| 791 |
register_events_ready (QmiClientLoc *client, |
| 792 |
GAsyncResult *res) |
| 793 |
{ |
| 794 |
QmiMessageLocRegisterEventsOutput *output; |
| 795 |
GError *error = NULL; |
| 796 |
|
| 797 |
output = qmi_client_loc_register_events_finish (client, res, &error); |
| 798 |
if (!output) { |
| 799 |
g_printerr ("error: operation failed: %s\n", error->message); |
| 800 |
g_error_free (error); |
| 801 |
operation_shutdown (FALSE); |
| 802 |
return; |
| 803 |
} |
| 804 |
|
| 805 |
if (!qmi_message_loc_register_events_output_get_result (output, &error)) { |
| 806 |
g_printerr ("error: could not register location tracking events: %s\n", error->message); |
| 807 |
qmi_message_loc_register_events_output_unref (output); |
| 808 |
g_error_free (error); |
| 809 |
operation_shutdown (FALSE); |
| 810 |
return; |
| 811 |
} |
| 812 |
|
| 813 |
g_debug ("Registered location tracking events..."); |
| 814 |
|
| 815 |
/* Go on */ |
| 816 |
ctx->monitoring_step++; |
| 817 |
monitoring_step_run (); |
| 818 |
|
| 819 |
qmi_message_loc_register_events_output_unref (output); |
| 820 |
} |
| 821 |
|
| 822 |
static void |
| 823 |
monitoring_step_register_events (void) |
| 824 |
{ |
| 825 |
QmiMessageLocRegisterEventsInput *re_input; |
| 826 |
QmiLocEventRegistrationFlag indication_mask = 0; |
| 827 |
|
| 828 |
/* Configure events to enable */ |
| 829 |
|
| 830 |
if (get_position_report_flag || follow_position_report_flag) |
| 831 |
indication_mask |= QMI_LOC_EVENT_REGISTRATION_FLAG_POSITION_REPORT; |
| 832 |
|
| 833 |
if (get_gnss_sv_info_flag || follow_gnss_sv_info_flag) |
| 834 |
indication_mask |= QMI_LOC_EVENT_REGISTRATION_FLAG_GNSS_SATELLITE_INFO; |
| 835 |
|
| 836 |
if (follow_nmea_flag) |
| 837 |
indication_mask |= QMI_LOC_EVENT_REGISTRATION_FLAG_NMEA; |
| 838 |
|
| 839 |
g_assert (indication_mask); |
| 840 |
|
| 841 |
re_input = qmi_message_loc_register_events_input_new (); |
| 842 |
qmi_message_loc_register_events_input_set_event_registration_mask ( |
| 843 |
re_input, indication_mask, NULL); |
| 844 |
qmi_client_loc_register_events (ctx->client, |
| 845 |
re_input, |
| 846 |
10, |
| 847 |
ctx->cancellable, |
| 848 |
(GAsyncReadyCallback) register_events_ready, |
| 849 |
NULL); |
| 850 |
qmi_message_loc_register_events_input_unref (re_input); |
| 851 |
} |
| 852 |
|
| 853 |
static void |
| 854 |
monitoring_step_run (void) |
| 855 |
{ |
| 856 |
switch (ctx->monitoring_step) { |
| 857 |
case MONITORING_STEP_FIRST: |
| 858 |
ctx->monitoring_step++; |
| 859 |
/* fall through */ |
| 860 |
|
| 861 |
case MONITORING_STEP_REGISTER_EVENTS: |
| 862 |
monitoring_step_register_events (); |
| 863 |
return; |
| 864 |
|
| 865 |
case MONITORING_STEP_SETUP_TIMEOUT: |
| 866 |
monitoring_step_setup_timeout (); |
| 867 |
return; |
| 868 |
|
| 869 |
case MONITORING_STEP_ONGOING: |
| 870 |
monitoring_step_ongoing (); |
| 871 |
return; |
| 872 |
|
| 873 |
default: |
| 874 |
g_assert_not_reached(); |
| 875 |
} |
| 876 |
} |
| 877 |
|
| 878 |
#endif /* HAVE_QMI_INDICATION_LOC_POSITION_REPORT |
| 879 |
* HAVE_QMI_INDICATION_LOC_GNSS_SV_INFO |
| 880 |
* HAVE_QMI_INDICATION_LOC_NMEA */ |
| 881 |
|
| 882 |
#if defined HAVE_QMI_MESSAGE_LOC_DELETE_ASSISTANCE_DATA |
| 883 |
|
| 884 |
static gboolean |
| 885 |
delete_assistance_data_timed_out (void) |
| 886 |
{ |
| 887 |
ctx->timeout_id = 0; |
| 888 |
g_printerr ("error: operation failed: timeout\n"); |
| 889 |
operation_shutdown (FALSE); |
| 890 |
return G_SOURCE_REMOVE; |
| 891 |
} |
| 892 |
|
| 893 |
static void |
| 894 |
delete_assistance_data_received (QmiClientLoc *client, |
| 895 |
QmiIndicationLocDeleteAssistanceDataOutput *output) |
| 896 |
{ |
| 897 |
QmiLocIndicationStatus status; |
| 898 |
GError *error = NULL; |
| 899 |
|
| 900 |
if (!qmi_indication_loc_delete_assistance_data_output_get_indication_status (output, &status, &error)) { |
| 901 |
g_printerr ("error: couldn't delete assistance data: %s\n", error->message); |
| 902 |
g_error_free (error); |
| 903 |
operation_shutdown (FALSE); |
| 904 |
return; |
| 905 |
} |
| 906 |
|
| 907 |
g_print ("Successfully deleted assistance data\n"); |
| 908 |
operation_shutdown (TRUE); |
| 909 |
} |
| 910 |
|
| 911 |
static void |
| 912 |
delete_assistance_data_ready (QmiClientLoc *client, |
| 913 |
GAsyncResult *res) |
| 914 |
{ |
| 915 |
QmiMessageLocDeleteAssistanceDataOutput *output; |
| 916 |
GError *error = NULL; |
| 917 |
|
| 918 |
output = qmi_client_loc_delete_assistance_data_finish (client, res, &error); |
| 919 |
if (!output) { |
| 920 |
g_printerr ("error: operation failed: %s\n", error->message); |
| 921 |
g_error_free (error); |
| 922 |
operation_shutdown (FALSE); |
| 923 |
return; |
| 924 |
} |
| 925 |
|
| 926 |
if (!qmi_message_loc_delete_assistance_data_output_get_result (output, &error)) { |
| 927 |
g_printerr ("error: could not delete assistance data: %s\n", error->message); |
| 928 |
qmi_message_loc_delete_assistance_data_output_unref (output); |
| 929 |
g_error_free (error); |
| 930 |
operation_shutdown (FALSE); |
| 931 |
return; |
| 932 |
} |
| 933 |
qmi_message_loc_delete_assistance_data_output_unref (output); |
| 934 |
} |
| 935 |
|
| 936 |
#endif /* HAVE_QMI_MESSAGE_LOC_DELETE_ASSISTANCE_DATA */ |
| 937 |
|
| 938 |
#if defined HAVE_QMI_MESSAGE_LOC_GET_NMEA_TYPES |
| 939 |
|
| 940 |
static gboolean |
| 941 |
get_nmea_types_timed_out (void) |
| 942 |
{ |
| 943 |
ctx->timeout_id = 0; |
| 944 |
g_printerr ("error: operation failed: timeout\n"); |
| 945 |
operation_shutdown (FALSE); |
| 946 |
return G_SOURCE_REMOVE; |
| 947 |
} |
| 948 |
|
| 949 |
static void |
| 950 |
get_nmea_types_received (QmiClientLoc *client, |
| 951 |
QmiIndicationLocGetNmeaTypesOutput *output) |
| 952 |
{ |
| 953 |
QmiLocIndicationStatus status; |
| 954 |
QmiLocNmeaType nmea_types_mask; |
| 955 |
g_autoptr(GError) error = NULL; |
| 956 |
g_autofree gchar *nmea_types_str = NULL; |
| 957 |
|
| 958 |
if (!qmi_indication_loc_get_nmea_types_output_get_indication_status (output, &status, &error)) { |
| 959 |
g_printerr ("error: couldn't get NMEA types: %s\n", error->message); |
| 960 |
operation_shutdown (FALSE); |
| 961 |
return; |
| 962 |
} |
| 963 |
|
| 964 |
if (!qmi_indication_loc_get_nmea_types_output_get_nmea_types (output, &nmea_types_mask, NULL)) { |
| 965 |
g_printerr ("error: couldn't get NMEA types: missing\n"); |
| 966 |
operation_shutdown (FALSE); |
| 967 |
return; |
| 968 |
} |
| 969 |
|
| 970 |
nmea_types_str = qmi_loc_nmea_type_build_string_from_mask (nmea_types_mask); |
| 971 |
g_print ("Successfully retrieved NMEA types: %s\n", VALIDATE_MASK_NONE (nmea_types_str)); |
| 972 |
operation_shutdown (TRUE); |
| 973 |
} |
| 974 |
|
| 975 |
static void |
| 976 |
get_nmea_types_ready (QmiClientLoc *client, |
| 977 |
GAsyncResult *res) |
| 978 |
{ |
| 979 |
g_autoptr(QmiMessageLocGetNmeaTypesOutput) output = NULL; |
| 980 |
g_autoptr(GError) error = NULL; |
| 981 |
|
| 982 |
output = qmi_client_loc_get_nmea_types_finish (client, res, &error); |
| 983 |
if (!output) { |
| 984 |
g_printerr ("error: operation failed: %s\n", error->message); |
| 985 |
operation_shutdown (FALSE); |
| 986 |
return; |
| 987 |
} |
| 988 |
|
| 989 |
if (!qmi_message_loc_get_nmea_types_output_get_result (output, &error)) { |
| 990 |
g_printerr ("error: could not get NMEA types: %s\n", error->message); |
| 991 |
operation_shutdown (FALSE); |
| 992 |
return; |
| 993 |
} |
| 994 |
} |
| 995 |
|
| 996 |
#endif /* HAVE_QMI_MESSAGE_LOC_GET_NMEA_TYPES */ |
| 997 |
|
| 998 |
#if defined HAVE_QMI_MESSAGE_LOC_SET_NMEA_TYPES |
| 999 |
|
| 1000 |
static gboolean |
| 1001 |
set_nmea_types_timed_out (void) |
| 1002 |
{ |
| 1003 |
ctx->timeout_id = 0; |
| 1004 |
g_printerr ("error: operation failed: timeout\n"); |
| 1005 |
operation_shutdown (FALSE); |
| 1006 |
return G_SOURCE_REMOVE; |
| 1007 |
} |
| 1008 |
|
| 1009 |
static void |
| 1010 |
set_nmea_types_received (QmiClientLoc *client, |
| 1011 |
QmiIndicationLocSetNmeaTypesOutput *output) |
| 1012 |
{ |
| 1013 |
QmiLocIndicationStatus status; |
| 1014 |
g_autoptr(GError) error = NULL; |
| 1015 |
|
| 1016 |
if (!qmi_indication_loc_set_nmea_types_output_get_indication_status (output, &status, &error)) { |
| 1017 |
g_printerr ("error: couldn't set NMEA types: %s\n", error->message); |
| 1018 |
operation_shutdown (FALSE); |
| 1019 |
return; |
| 1020 |
} |
| 1021 |
|
| 1022 |
g_print ("Successfully set NMEA types\n"); |
| 1023 |
operation_shutdown (TRUE); |
| 1024 |
} |
| 1025 |
|
| 1026 |
static void |
| 1027 |
set_nmea_types_ready (QmiClientLoc *client, |
| 1028 |
GAsyncResult *res) |
| 1029 |
{ |
| 1030 |
g_autoptr(QmiMessageLocSetNmeaTypesOutput) output = NULL; |
| 1031 |
g_autoptr(GError) error = NULL; |
| 1032 |
|
| 1033 |
output = qmi_client_loc_set_nmea_types_finish (client, res, &error); |
| 1034 |
if (!output) { |
| 1035 |
g_printerr ("error: operation failed: %s\n", error->message); |
| 1036 |
operation_shutdown (FALSE); |
| 1037 |
return; |
| 1038 |
} |
| 1039 |
|
| 1040 |
if (!qmi_message_loc_set_nmea_types_output_get_result (output, &error)) { |
| 1041 |
g_printerr ("error: could not set NMEA types: %s\n", error->message); |
| 1042 |
operation_shutdown (FALSE); |
| 1043 |
return; |
| 1044 |
} |
| 1045 |
} |
| 1046 |
|
| 1047 |
static QmiMessageLocSetNmeaTypesInput * |
| 1048 |
set_nmea_types_input_create (const gchar *str) |
| 1049 |
{ |
| 1050 |
g_autoptr(QmiMessageLocSetNmeaTypesInput) input = NULL; |
| 1051 |
g_autoptr(GError) error = NULL; |
| 1052 |
QmiLocNmeaType nmea_type_mask; |
| 1053 |
|
| 1054 |
if (!qmicli_read_loc_nmea_type_from_string (str, &nmea_type_mask)) { |
| 1055 |
g_printerr ("error: couldn't parse input string as NMEA types: '%s'\n", str); |
| 1056 |
return NULL; |
| 1057 |
} |
| 1058 |
|
| 1059 |
input = qmi_message_loc_set_nmea_types_input_new (); |
| 1060 |
if (!qmi_message_loc_set_nmea_types_input_set_nmea_types (input, nmea_type_mask, &error)) { |
| 1061 |
g_printerr ("error: couldn't create input data bundle: '%s'\n", error->message); |
| 1062 |
return NULL; |
| 1063 |
} |
| 1064 |
|
| 1065 |
return g_steal_pointer (&input); |
| 1066 |
} |
| 1067 |
|
| 1068 |
#endif /* HAVE_QMI_MESSAGE_LOC_SET_NMEA_TYPES */ |
| 1069 |
|
| 1070 |
#if defined HAVE_QMI_MESSAGE_LOC_GET_OPERATION_MODE |
| 1071 |
|
| 1072 |
static gboolean |
| 1073 |
get_operation_mode_timed_out (void) |
| 1074 |
{ |
| 1075 |
ctx->timeout_id = 0; |
| 1076 |
g_printerr ("error: operation failed: timeout\n"); |
| 1077 |
operation_shutdown (FALSE); |
| 1078 |
return G_SOURCE_REMOVE; |
| 1079 |
} |
| 1080 |
|
| 1081 |
static void |
| 1082 |
get_operation_mode_received (QmiClientLoc *client, |
| 1083 |
QmiIndicationLocGetOperationModeOutput *output) |
| 1084 |
{ |
| 1085 |
QmiLocIndicationStatus status; |
| 1086 |
QmiLocOperationMode operation_mode; |
| 1087 |
g_autoptr(GError) error = NULL; |
| 1088 |
|
| 1089 |
if (!qmi_indication_loc_get_operation_mode_output_get_indication_status (output, &status, &error)) { |
| 1090 |
g_printerr ("error: couldn't get operation mode %s\n", error->message); |
| 1091 |
operation_shutdown (FALSE); |
| 1092 |
return; |
| 1093 |
} |
| 1094 |
|
| 1095 |
if (!qmi_indication_loc_get_operation_mode_output_get_operation_mode (output, &operation_mode, NULL)) { |
| 1096 |
g_printerr ("error: couldn't get operation mode: missing\n"); |
| 1097 |
operation_shutdown (FALSE); |
| 1098 |
return; |
| 1099 |
} |
| 1100 |
|
| 1101 |
g_print ("Successfully retrieved operation mode: %s\n", qmi_loc_operation_mode_get_string (operation_mode)); |
| 1102 |
operation_shutdown (TRUE); |
| 1103 |
} |
| 1104 |
|
| 1105 |
static void |
| 1106 |
get_operation_mode_ready (QmiClientLoc *client, |
| 1107 |
GAsyncResult *res) |
| 1108 |
{ |
| 1109 |
g_autoptr(QmiMessageLocGetOperationModeOutput) output = NULL; |
| 1110 |
g_autoptr(GError) error = NULL; |
| 1111 |
|
| 1112 |
output = qmi_client_loc_get_operation_mode_finish (client, res, &error); |
| 1113 |
if (!output) { |
| 1114 |
g_printerr ("error: operation failed: %s\n", error->message); |
| 1115 |
operation_shutdown (FALSE); |
| 1116 |
return; |
| 1117 |
} |
| 1118 |
|
| 1119 |
if (!qmi_message_loc_get_operation_mode_output_get_result (output, &error)) { |
| 1120 |
g_printerr ("error: could not get operation mode: %s\n", error->message); |
| 1121 |
operation_shutdown (FALSE); |
| 1122 |
return; |
| 1123 |
} |
| 1124 |
} |
| 1125 |
#endif /* HAVE_QMI_MESSAGE_LOC_GET_OPERATION_MODE */ |
| 1126 |
|
| 1127 |
#if defined HAVE_QMI_MESSAGE_LOC_SET_OPERATION_MODE |
| 1128 |
|
| 1129 |
static gboolean |
| 1130 |
set_operation_mode_timed_out (void) |
| 1131 |
{ |
| 1132 |
ctx->timeout_id = 0; |
| 1133 |
g_printerr ("error: operation failed: timeout\n"); |
| 1134 |
operation_shutdown (FALSE); |
| 1135 |
return G_SOURCE_REMOVE; |
| 1136 |
} |
| 1137 |
|
| 1138 |
static void |
| 1139 |
set_operation_mode_received (QmiClientLoc *client, |
| 1140 |
QmiIndicationLocSetOperationModeOutput *output) |
| 1141 |
{ |
| 1142 |
QmiLocIndicationStatus status; |
| 1143 |
g_autoptr(GError) error = NULL; |
| 1144 |
|
| 1145 |
if (!qmi_indication_loc_set_operation_mode_output_get_indication_status (output, &status, &error)) { |
| 1146 |
g_printerr ("error: couldn't set operation mode: %s\n", error->message); |
| 1147 |
operation_shutdown (FALSE); |
| 1148 |
return; |
| 1149 |
} |
| 1150 |
|
| 1151 |
g_print ("Successfully set operation mode\n"); |
| 1152 |
operation_shutdown (TRUE); |
| 1153 |
} |
| 1154 |
|
| 1155 |
static void |
| 1156 |
set_operation_mode_ready (QmiClientLoc *client, |
| 1157 |
GAsyncResult *res) |
| 1158 |
{ |
| 1159 |
g_autoptr(QmiMessageLocSetOperationModeOutput) output = NULL; |
| 1160 |
g_autoptr(GError) error = NULL; |
| 1161 |
|
| 1162 |
output = qmi_client_loc_set_operation_mode_finish (client, res, &error); |
| 1163 |
if (!output) { |
| 1164 |
g_printerr ("error: operation failed: %s\n", error->message); |
| 1165 |
operation_shutdown (FALSE); |
| 1166 |
return; |
| 1167 |
} |
| 1168 |
|
| 1169 |
if (!qmi_message_loc_set_operation_mode_output_get_result (output, &error)) { |
| 1170 |
g_printerr ("error: could not set operation mode: %s\n", error->message); |
| 1171 |
operation_shutdown (FALSE); |
| 1172 |
return; |
| 1173 |
} |
| 1174 |
} |
| 1175 |
|
| 1176 |
static QmiMessageLocSetOperationModeInput * |
| 1177 |
set_operation_mode_input_create (const gchar *str) |
| 1178 |
{ |
| 1179 |
g_autoptr(QmiMessageLocSetOperationModeInput) input = NULL; |
| 1180 |
g_autoptr(GError) error = NULL; |
| 1181 |
QmiLocOperationMode operation_mode; |
| 1182 |
|
| 1183 |
if (!qmicli_read_loc_operation_mode_from_string (str, &operation_mode)) |
| 1184 |
return NULL; |
| 1185 |
|
| 1186 |
input = qmi_message_loc_set_operation_mode_input_new (); |
| 1187 |
if (!qmi_message_loc_set_operation_mode_input_set_operation_mode (input, operation_mode, &error)) { |
| 1188 |
g_printerr ("error: couldn't create input data bundle: '%s'\n", error->message); |
| 1189 |
return NULL; |
| 1190 |
} |
| 1191 |
|
| 1192 |
return g_steal_pointer (&input); |
| 1193 |
} |
| 1194 |
|
| 1195 |
#endif /* HAVE_QMI_MESSAGE_LOC_SET_OPERATION_MODE */ |
| 1196 |
|
| 1197 |
#if defined HAVE_QMI_MESSAGE_LOC_GET_ENGINE_LOCK |
| 1198 |
|
| 1199 |
static gboolean |
| 1200 |
get_engine_lock_timed_out (void) |
| 1201 |
{ |
| 1202 |
ctx->timeout_id = 0; |
| 1203 |
g_printerr ("error: operation failed: timeout\n"); |
| 1204 |
operation_shutdown (FALSE); |
| 1205 |
return G_SOURCE_REMOVE; |
| 1206 |
} |
| 1207 |
|
| 1208 |
static void |
| 1209 |
get_engine_lock_received (QmiClientLoc *client, |
| 1210 |
QmiIndicationLocGetEngineLockOutput *output) |
| 1211 |
{ |
| 1212 |
QmiLocIndicationStatus status; |
| 1213 |
QmiLocLockType type; |
| 1214 |
g_autoptr(GError) error = NULL; |
| 1215 |
|
| 1216 |
if (!qmi_indication_loc_get_engine_lock_output_get_indication_status (output, &status, &error)) { |
| 1217 |
g_printerr ("error: couldn't get engine lock %s\n", error->message); |
| 1218 |
operation_shutdown (FALSE); |
| 1219 |
return; |
| 1220 |
} |
| 1221 |
|
| 1222 |
if (!qmi_indication_loc_get_engine_lock_output_get_lock_type (output, &type, NULL)) { |
| 1223 |
g_printerr ("error: couldn't get engine lock: missing\n"); |
| 1224 |
operation_shutdown (FALSE); |
| 1225 |
return; |
| 1226 |
} |
| 1227 |
|
| 1228 |
g_print ("Successfully retrieved engine lock: %s\n", qmi_loc_lock_type_get_string (type)); |
| 1229 |
operation_shutdown (TRUE); |
| 1230 |
} |
| 1231 |
|
| 1232 |
static void |
| 1233 |
get_engine_lock_ready (QmiClientLoc *client, |
| 1234 |
GAsyncResult *res) |
| 1235 |
{ |
| 1236 |
g_autoptr(QmiMessageLocGetEngineLockOutput) output = NULL; |
| 1237 |
g_autoptr(GError) error = NULL; |
| 1238 |
|
| 1239 |
output = qmi_client_loc_get_engine_lock_finish (client, res, &error); |
| 1240 |
if (!output) { |
| 1241 |
g_printerr ("error: operation failed: %s\n", error->message); |
| 1242 |
operation_shutdown (FALSE); |
| 1243 |
return; |
| 1244 |
} |
| 1245 |
|
| 1246 |
if (!qmi_message_loc_get_engine_lock_output_get_result (output, &error)) { |
| 1247 |
g_printerr ("error: could not get engine lock: %s\n", error->message); |
| 1248 |
operation_shutdown (FALSE); |
| 1249 |
return; |
| 1250 |
} |
| 1251 |
} |
| 1252 |
#endif /* HAVE_QMI_MESSAGE_LOC_GET_ENGINE_LOCK */ |
| 1253 |
|
| 1254 |
#if defined HAVE_QMI_MESSAGE_LOC_SET_ENGINE_LOCK |
| 1255 |
|
| 1256 |
static gboolean |
| 1257 |
set_engine_lock_timed_out (void) |
| 1258 |
{ |
| 1259 |
ctx->timeout_id = 0; |
| 1260 |
g_printerr ("error: operation failed: timeout\n"); |
| 1261 |
operation_shutdown (FALSE); |
| 1262 |
return G_SOURCE_REMOVE; |
| 1263 |
} |
| 1264 |
|
| 1265 |
static void |
| 1266 |
set_engine_lock_received (QmiClientLoc *client, |
| 1267 |
QmiIndicationLocSetEngineLockOutput *output) |
| 1268 |
{ |
| 1269 |
QmiLocIndicationStatus status; |
| 1270 |
g_autoptr(GError) error = NULL; |
| 1271 |
|
| 1272 |
if (!qmi_indication_loc_set_engine_lock_output_get_indication_status (output, &status, &error)) { |
| 1273 |
g_printerr ("error: couldn't set engine lock: %s\n", error->message); |
| 1274 |
operation_shutdown (FALSE); |
| 1275 |
return; |
| 1276 |
} |
| 1277 |
|
| 1278 |
g_print ("Successfully set engine lock\n"); |
| 1279 |
operation_shutdown (TRUE); |
| 1280 |
} |
| 1281 |
|
| 1282 |
static void |
| 1283 |
set_engine_lock_ready (QmiClientLoc *client, |
| 1284 |
GAsyncResult *res) |
| 1285 |
{ |
| 1286 |
g_autoptr(QmiMessageLocSetEngineLockOutput) output = NULL; |
| 1287 |
g_autoptr(GError) error = NULL; |
| 1288 |
|
| 1289 |
output = qmi_client_loc_set_engine_lock_finish (client, res, &error); |
| 1290 |
if (!output) { |
| 1291 |
g_printerr ("error: operation failed: %s\n", error->message); |
| 1292 |
operation_shutdown (FALSE); |
| 1293 |
return; |
| 1294 |
} |
| 1295 |
|
| 1296 |
if (!qmi_message_loc_set_engine_lock_output_get_result (output, &error)) { |
| 1297 |
g_printerr ("error: could not set engine lock: %s\n", error->message); |
| 1298 |
operation_shutdown (FALSE); |
| 1299 |
return; |
| 1300 |
} |
| 1301 |
} |
| 1302 |
|
| 1303 |
static QmiMessageLocSetEngineLockInput * |
| 1304 |
set_engine_lock_input_create (const gchar *str) |
| 1305 |
{ |
| 1306 |
g_autoptr(QmiMessageLocSetEngineLockInput) input = NULL; |
| 1307 |
g_autoptr(GError) error = NULL; |
| 1308 |
QmiLocLockType type; |
| 1309 |
|
| 1310 |
if (!qmicli_read_loc_lock_type_from_string (str, &type)) |
| 1311 |
return NULL; |
| 1312 |
|
| 1313 |
input = qmi_message_loc_set_engine_lock_input_new (); |
| 1314 |
if (!qmi_message_loc_set_engine_lock_input_set_lock_type (input, type, &error)) { |
| 1315 |
g_printerr ("error: couldn't create input data bundle: '%s'\n", error->message); |
| 1316 |
return NULL; |
| 1317 |
} |
| 1318 |
|
| 1319 |
return g_steal_pointer (&input); |
| 1320 |
} |
| 1321 |
|
| 1322 |
#endif /* HAVE_QMI_MESSAGE_LOC_SET_ENGINE_LOCK */ |
| 1323 |
|
| 1324 |
#if defined HAVE_QMI_MESSAGE_LOC_STOP |
| 1325 |
|
| 1326 |
static void |
| 1327 |
stop_ready (QmiClientLoc *client, |
| 1328 |
GAsyncResult *res) |
| 1329 |
{ |
| 1330 |
QmiMessageLocStopOutput *output; |
| 1331 |
GError *error = NULL; |
| 1332 |
|
| 1333 |
output = qmi_client_loc_stop_finish (client, res, &error); |
| 1334 |
if (!output) { |
| 1335 |
g_printerr ("error: operation failed: %s\n", error->message); |
| 1336 |
g_error_free (error); |
| 1337 |
operation_shutdown (FALSE); |
| 1338 |
return; |
| 1339 |
} |
| 1340 |
|
| 1341 |
if (!qmi_message_loc_stop_output_get_result (output, &error)) { |
| 1342 |
g_printerr ("error: could not stop location tracking: %s\n", error->message); |
| 1343 |
qmi_message_loc_stop_output_unref (output); |
| 1344 |
g_error_free (error); |
| 1345 |
operation_shutdown (FALSE); |
| 1346 |
return; |
| 1347 |
} |
| 1348 |
|
| 1349 |
g_print ("[%s] Successfully stopped location tracking (session id %u)\n", |
| 1350 |
qmi_device_get_path_display (ctx->device), session_id); |
| 1351 |
|
| 1352 |
qmi_message_loc_stop_output_unref (output); |
| 1353 |
operation_shutdown (TRUE); |
| 1354 |
} |
| 1355 |
|
| 1356 |
#endif /* HAVE_QMI_MESSAGE_LOC_STOP */ |
| 1357 |
|
| 1358 |
#if defined HAVE_QMI_MESSAGE_LOC_START |
| 1359 |
|
| 1360 |
static void |
| 1361 |
start_ready (QmiClientLoc *client, |
| 1362 |
GAsyncResult *res) |
| 1363 |
{ |
| 1364 |
QmiMessageLocStartOutput *output; |
| 1365 |
GError *error = NULL; |
| 1366 |
|
| 1367 |
output = qmi_client_loc_start_finish (client, res, &error); |
| 1368 |
if (!output) { |
| 1369 |
g_printerr ("error: operation failed: %s\n", error->message); |
| 1370 |
g_error_free (error); |
| 1371 |
operation_shutdown (FALSE); |
| 1372 |
return; |
| 1373 |
} |
| 1374 |
|
| 1375 |
if (!qmi_message_loc_start_output_get_result (output, &error)) { |
| 1376 |
g_printerr ("error: could not start location tracking: %s\n", error->message); |
| 1377 |
qmi_message_loc_start_output_unref (output); |
| 1378 |
g_error_free (error); |
| 1379 |
operation_shutdown (FALSE); |
| 1380 |
return; |
| 1381 |
} |
| 1382 |
|
| 1383 |
g_print ("[%s] Successfully started location tracking (session id %u)\n", |
| 1384 |
qmi_device_get_path_display (ctx->device), session_id); |
| 1385 |
|
| 1386 |
qmi_message_loc_start_output_unref (output); |
| 1387 |
operation_shutdown (TRUE); |
| 1388 |
} |
| 1389 |
|
| 1390 |
#endif /* HAVE_QMI_MESSAGE_LOC_START */ |
| 1391 |
|
| 1392 |
#if defined HAVE_QMI_MESSAGE_LOC_INJECT_POSITION |
| 1393 |
static void |
| 1394 |
inject_position_received (QmiClientLoc *client, |
| 1395 |
QmiIndicationLocInjectPositionOutput *output) |
| 1396 |
{ |
| 1397 |
QmiLocIndicationStatus status; |
| 1398 |
g_autoptr(GError) error = NULL; |
| 1399 |
|
| 1400 |
if (!qmi_indication_loc_inject_position_output_get_indication_status (output, &status, &error)) { |
| 1401 |
g_printerr ("error: couldn't inject position %s\n", error->message); |
| 1402 |
operation_shutdown (FALSE); |
| 1403 |
return; |
| 1404 |
} |
| 1405 |
|
| 1406 |
g_print ("Successfully inject position\n"); |
| 1407 |
operation_shutdown (TRUE); |
| 1408 |
} |
| 1409 |
|
| 1410 |
|
| 1411 |
static gboolean |
| 1412 |
inject_position_timed_out (void) |
| 1413 |
{ |
| 1414 |
ctx->timeout_id = 0; |
| 1415 |
g_printerr ("error: inject position operation failed: timeout\n"); |
| 1416 |
operation_shutdown (FALSE); |
| 1417 |
return G_SOURCE_REMOVE; |
| 1418 |
} |
| 1419 |
|
| 1420 |
|
| 1421 |
static void |
| 1422 |
inject_position_ready (QmiClientLoc *client, |
| 1423 |
GAsyncResult *res) |
| 1424 |
{ |
| 1425 |
g_autoptr(QmiMessageLocInjectPositionOutput) output = NULL; |
| 1426 |
g_autoptr(GError) error = NULL; |
| 1427 |
|
| 1428 |
output = qmi_client_loc_inject_position_finish (client, res, &error); |
| 1429 |
if (!output) { |
| 1430 |
g_printerr ("error: operation failed: %s\n", error->message); |
| 1431 |
operation_shutdown (FALSE); |
| 1432 |
return; |
| 1433 |
} |
| 1434 |
|
| 1435 |
if (!qmi_message_loc_inject_position_output_get_result (output, &error)) { |
| 1436 |
g_printerr ("error: could not inject position: %s\n", error->message); |
| 1437 |
operation_shutdown (FALSE); |
| 1438 |
return; |
| 1439 |
} |
| 1440 |
} |
| 1441 |
|
| 1442 |
static void |
| 1443 |
inject_position_create (void) |
| 1444 |
{ |
| 1445 |
g_autoptr(QmiMessageLocInjectPositionInput) input = NULL; |
| 1446 |
GError *error = NULL; |
| 1447 |
guint64 utc_ms = 0; |
| 1448 |
|
| 1449 |
input = qmi_message_loc_inject_position_input_new (); |
| 1450 |
if (!input) { |
| 1451 |
operation_shutdown (FALSE); |
| 1452 |
return; |
| 1453 |
} |
| 1454 |
|
| 1455 |
qmi_message_loc_inject_position_input_set_latitude (input, inject_position_latitude, &error); |
| 1456 |
qmi_message_loc_inject_position_input_set_longitude (input, inject_position_longitude, &error); |
| 1457 |
qmi_message_loc_inject_position_input_set_position_source (input, QMI_LOC_POSITION_SOURCE_OTHER, &error); |
| 1458 |
|
| 1459 |
// it's not recommended to advertise accuracy better than 1000 meters to the modem |
| 1460 |
qmi_message_loc_inject_position_input_set_horizontal_uncertainty_circular (input, 1000, &error); |
| 1461 |
qmi_message_loc_inject_position_input_set_horizontal_confidence (input, 68, &error); |
| 1462 |
|
| 1463 |
utc_ms = g_get_real_time () / 1000; |
| 1464 |
qmi_message_loc_inject_position_input_set_utc_timestamp (input, utc_ms, &error); |
| 1465 |
|
| 1466 |
/* Wait for response asynchronously */ |
| 1467 |
ctx->timeout_id = g_timeout_add_seconds (timeout > 0 ? timeout : DEFAULT_LOC_TIMEOUT_SECS, |
| 1468 |
(GSourceFunc) inject_position_timed_out, |
| 1469 |
NULL); |
| 1470 |
|
| 1471 |
ctx->inject_position_indication_id = g_signal_connect (ctx->client, |
| 1472 |
"inject-position", |
| 1473 |
G_CALLBACK (inject_position_received), |
| 1474 |
NULL); |
| 1475 |
|
| 1476 |
qmi_client_loc_inject_position (ctx->client, |
| 1477 |
input, |
| 1478 |
10, |
| 1479 |
ctx->cancellable, |
| 1480 |
(GAsyncReadyCallback) inject_position_ready, |
| 1481 |
NULL); |
| 1482 |
} |
| 1483 |
#endif /* HAVE_QMI_MESSAGE_LOC_INJECT_POSITION */ |
| 1484 |
|
| 1485 |
#if defined HAVE_QMI_MESSAGE_LOC_INJECT_UTC_TIME |
| 1486 |
|
| 1487 |
static gboolean |
| 1488 |
inject_time_timed_out (void) |
| 1489 |
{ |
| 1490 |
ctx->timeout_id = 0; |
| 1491 |
g_printerr ("error: operation failed: timeout\n"); |
| 1492 |
operation_shutdown (FALSE); |
| 1493 |
return G_SOURCE_REMOVE; |
| 1494 |
} |
| 1495 |
|
| 1496 |
static void |
| 1497 |
inject_time_received (QmiClientLoc *client, |
| 1498 |
QmiIndicationLocInjectUtcTimeOutput *output) |
| 1499 |
{ |
| 1500 |
QmiLocIndicationStatus status; |
| 1501 |
g_autoptr(GError) error = NULL; |
| 1502 |
|
| 1503 |
if (!qmi_indication_loc_inject_utc_time_output_get_indication_status (output, &status, &error)) { |
| 1504 |
g_printerr ("error: couldn't inject time %s\n", error->message); |
| 1505 |
operation_shutdown (FALSE); |
| 1506 |
return; |
| 1507 |
} |
| 1508 |
|
| 1509 |
g_print ("Successfully injected time\n"); |
| 1510 |
operation_shutdown (TRUE); |
| 1511 |
} |
| 1512 |
|
| 1513 |
static void |
| 1514 |
inject_time_ready (QmiClientLoc *client, |
| 1515 |
GAsyncResult *res) |
| 1516 |
{ |
| 1517 |
g_autoptr(QmiMessageLocInjectUtcTimeOutput) output = NULL; |
| 1518 |
g_autoptr(GError) error = NULL; |
| 1519 |
|
| 1520 |
output = qmi_client_loc_inject_utc_time_finish (client, res, &error); |
| 1521 |
if (!output) { |
| 1522 |
g_printerr ("error: operation failed: %s\n", error->message); |
| 1523 |
operation_shutdown (FALSE); |
| 1524 |
return; |
| 1525 |
} |
| 1526 |
|
| 1527 |
if (!qmi_message_loc_inject_utc_time_output_get_result (output, &error)) { |
| 1528 |
g_printerr ("error: could not inject time: %s\n", error->message); |
| 1529 |
operation_shutdown (FALSE); |
| 1530 |
return; |
| 1531 |
} |
| 1532 |
} |
| 1533 |
|
| 1534 |
static void |
| 1535 |
inject_time_create (void) |
| 1536 |
{ |
| 1537 |
g_autoptr(QmiMessageLocInjectUtcTimeInput) input = NULL; |
| 1538 |
GError *error = NULL; |
| 1539 |
guint64 utc_ms = 0; |
| 1540 |
|
| 1541 |
input = qmi_message_loc_inject_utc_time_input_new (); |
| 1542 |
if (!input) { |
| 1543 |
operation_shutdown (FALSE); |
| 1544 |
return; |
| 1545 |
} |
| 1546 |
|
| 1547 |
utc_ms = g_get_real_time () / 1000; |
| 1548 |
qmi_message_loc_inject_utc_time_input_set_utc_time (input, utc_ms, &error); |
| 1549 |
qmi_message_loc_inject_utc_time_input_set_time_uncertainty (input, 1000, &error); |
| 1550 |
qmi_message_loc_inject_utc_time_input_set_time_source (input, QMI_LOC_INJECTED_TIME_SOURCE_UNKNOWN, &error); |
| 1551 |
|
| 1552 |
/* Wait for response asynchronously */ |
| 1553 |
ctx->timeout_id = g_timeout_add_seconds (timeout > 0 ? timeout : DEFAULT_LOC_TIMEOUT_SECS, |
| 1554 |
(GSourceFunc) inject_time_timed_out, |
| 1555 |
NULL); |
| 1556 |
|
| 1557 |
ctx->inject_time_indication_id = g_signal_connect (ctx->client, |
| 1558 |
"inject-utc-time", |
| 1559 |
G_CALLBACK (inject_time_received), |
| 1560 |
NULL); |
| 1561 |
|
| 1562 |
qmi_client_loc_inject_utc_time (ctx->client, |
| 1563 |
input, |
| 1564 |
10, |
| 1565 |
ctx->cancellable, |
| 1566 |
(GAsyncReadyCallback) inject_time_ready, |
| 1567 |
NULL); |
| 1568 |
} |
| 1569 |
#endif /* HAVE_QMI_MESSAGE_LOC_INJECT_UTC_TIME */ |
| 1570 |
|
| 1571 |
#if defined HAVE_QMI_MESSAGE_LOC_GET_PREDICTED_ORBITS_DATA_SOURCE |
| 1572 |
|
| 1573 |
static gboolean |
| 1574 |
get_predicted_orbits_data_source_timed_out (void) |
| 1575 |
{ |
| 1576 |
ctx->timeout_id = 0; |
| 1577 |
g_printerr ("error: operation failed: timeout\n"); |
| 1578 |
operation_shutdown (FALSE); |
| 1579 |
return G_SOURCE_REMOVE; |
| 1580 |
} |
| 1581 |
|
| 1582 |
static void |
| 1583 |
get_predicted_orbits_data_source_received (QmiClientLoc *client, |
| 1584 |
QmiIndicationLocGetPredictedOrbitsDataSourceOutput *output) |
| 1585 |
{ |
| 1586 |
QmiLocIndicationStatus status; |
| 1587 |
g_autoptr(GError) error = NULL; |
| 1588 |
GArray *servers = NULL; |
| 1589 |
guint32 max_file_size = 0; |
| 1590 |
guint32 max_part_size = 0; |
| 1591 |
guint i; |
| 1592 |
|
| 1593 |
if (!qmi_indication_loc_get_predicted_orbits_data_source_output_get_indication_status (output, &status, &error)) { |
| 1594 |
g_printerr ("error: couldn't get predicted orbits data source: %s\n", error->message); |
| 1595 |
operation_shutdown (FALSE); |
| 1596 |
return; |
| 1597 |
} |
| 1598 |
|
| 1599 |
g_print ("[%s] Predicted orbits data source received:\n", |
| 1600 |
qmi_device_get_path_display (ctx->device)); |
| 1601 |
|
| 1602 |
if (qmi_indication_loc_get_predicted_orbits_data_source_output_get_allowed_sizes ( |
| 1603 |
output, |
| 1604 |
&max_file_size, |
| 1605 |
&max_part_size, |
| 1606 |
NULL)) { |
| 1607 |
g_print ( |
| 1608 |
"\t Allowed max file size: '%u'\n" |
| 1609 |
"\t Allowed max part size: '%u'\n", |
| 1610 |
max_file_size, |
| 1611 |
max_part_size); |
| 1612 |
} |
| 1613 |
|
| 1614 |
if (!qmi_indication_loc_get_predicted_orbits_data_source_output_get_server_list ( |
| 1615 |
output, |
| 1616 |
&servers, |
| 1617 |
&error)) { |
| 1618 |
g_printerr ("error: couldn't get predicted orbits data source server list: %s\n", error->message); |
| 1619 |
operation_shutdown (FALSE); |
| 1620 |
return; |
| 1621 |
} |
| 1622 |
|
| 1623 |
for (i = 0; i < servers->len; i++) |
| 1624 |
g_print ("\t Server %u: '%s'\n", i + 1, g_array_index (servers, const gchar *, i)); |
| 1625 |
|
| 1626 |
g_print ("\nSuccessfully retrieved predicted orbits data source\n"); |
| 1627 |
operation_shutdown (TRUE); |
| 1628 |
} |
| 1629 |
|
| 1630 |
static void |
| 1631 |
get_predicted_orbits_data_source_ready (QmiClientLoc *client, |
| 1632 |
GAsyncResult *res) |
| 1633 |
{ |
| 1634 |
g_autoptr(QmiMessageLocGetPredictedOrbitsDataSourceOutput) output = NULL; |
| 1635 |
g_autoptr(GError) error = NULL; |
| 1636 |
|
| 1637 |
output = qmi_client_loc_get_predicted_orbits_data_source_finish (client, res, &error); |
| 1638 |
if (!output) { |
| 1639 |
g_printerr ("error: operation failed: %s\n", error->message); |
| 1640 |
operation_shutdown (FALSE); |
| 1641 |
return; |
| 1642 |
} |
| 1643 |
|
| 1644 |
if (!qmi_message_loc_get_predicted_orbits_data_source_output_get_result (output, &error)) { |
| 1645 |
g_printerr ("error: could not get predicted orbits data source: %s\n", error->message); |
| 1646 |
operation_shutdown (FALSE); |
| 1647 |
return; |
| 1648 |
} |
| 1649 |
} |
| 1650 |
#endif /* HAVE_QMI_MESSAGE_LOC_GET_PREDICTED_ORBITS_DATA_SOURCE */ |
| 1651 |
|
| 1652 |
#if defined HAVE_QMI_MESSAGE_LOC_GET_PREDICTED_ORBITS_DATA_VALIDITY |
| 1653 |
static gboolean |
| 1654 |
get_predicted_orbits_data_validity_timed_out (void) |
| 1655 |
{ |
| 1656 |
ctx->timeout_id = 0; |
| 1657 |
g_printerr ("error: operation failed: timeout\n"); |
| 1658 |
operation_shutdown (FALSE); |
| 1659 |
return G_SOURCE_REMOVE; |
| 1660 |
} |
| 1661 |
|
| 1662 |
static void |
| 1663 |
get_predicted_orbits_data_validity_received (QmiClientLoc *client, |
| 1664 |
QmiIndicationLocGetPredictedOrbitsDataValidityOutput *output) |
| 1665 |
{ |
| 1666 |
QmiLocIndicationStatus status; |
| 1667 |
guint64 start_utc_timestamp; |
| 1668 |
guint16 duration_hours; |
| 1669 |
gchar *dt_str; |
| 1670 |
GDateTime *dt; |
| 1671 |
g_autoptr(GError) error = NULL; |
| 1672 |
|
| 1673 |
if (!qmi_indication_loc_get_predicted_orbits_data_validity_output_get_indication_status (output, &status, &error)) { |
| 1674 |
g_printerr ("error: couldn't get predicted orbits validity %s\n", error->message); |
| 1675 |
operation_shutdown (FALSE); |
| 1676 |
return; |
| 1677 |
} |
| 1678 |
|
| 1679 |
if (!qmi_indication_loc_get_predicted_orbits_data_validity_output_get_validity_info (output, &start_utc_timestamp, &duration_hours, &error)) { |
| 1680 |
g_printerr ("error: couldn't get predicted orbits validity information: missing\n"); |
| 1681 |
operation_shutdown (FALSE); |
| 1682 |
return; |
| 1683 |
} |
| 1684 |
|
| 1685 |
dt = g_date_time_new_from_unix_utc (start_utc_timestamp); |
| 1686 |
dt_str = g_date_time_format_iso8601 (dt); |
| 1687 |
g_date_time_unref (dt); |
| 1688 |
g_print ("Successfully retrieved validity info: %s, valid for %d hours\n", dt_str, duration_hours); |
| 1689 |
g_free (dt_str); |
| 1690 |
operation_shutdown (TRUE); |
| 1691 |
} |
| 1692 |
|
| 1693 |
static void |
| 1694 |
get_predicted_orbits_data_validity_ready (QmiClientLoc *client, |
| 1695 |
GAsyncResult *res) |
| 1696 |
{ |
| 1697 |
g_autoptr(QmiMessageLocGetPredictedOrbitsDataValidityOutput) output = NULL; |
| 1698 |
g_autoptr(GError) error = NULL; |
| 1699 |
|
| 1700 |
output = qmi_client_loc_get_predicted_orbits_data_validity_finish (client, res, &error); |
| 1701 |
if (!output) { |
| 1702 |
g_printerr ("error: operation failed: %s\n", error->message); |
| 1703 |
operation_shutdown (FALSE); |
| 1704 |
return; |
| 1705 |
} |
| 1706 |
|
| 1707 |
if (!qmi_message_loc_get_predicted_orbits_data_validity_output_get_result (output, &error)) { |
| 1708 |
g_printerr ("error: could not get predicted orbits data validity status: %s\n", error->message); |
| 1709 |
operation_shutdown (FALSE); |
| 1710 |
return; |
| 1711 |
} |
| 1712 |
} |
| 1713 |
|
| 1714 |
static void |
| 1715 |
get_predicted_orbits_data_validity_create (void) |
| 1716 |
{ |
| 1717 |
/* Wait for response asynchronously */ |
| 1718 |
ctx->timeout_id = g_timeout_add_seconds (timeout > 0 ? timeout : DEFAULT_LOC_TIMEOUT_SECS, |
| 1719 |
(GSourceFunc) get_predicted_orbits_data_validity_timed_out, |
| 1720 |
NULL); |
| 1721 |
|
| 1722 |
ctx->get_predicted_orbits_data_validity_indication_id = g_signal_connect (ctx->client, |
| 1723 |
"get-predicted-orbits-data-validity", |
| 1724 |
G_CALLBACK (get_predicted_orbits_data_validity_received), |
| 1725 |
NULL); |
| 1726 |
|
| 1727 |
qmi_client_loc_get_predicted_orbits_data_validity (ctx->client, |
| 1728 |
NULL, |
| 1729 |
10, |
| 1730 |
ctx->cancellable, |
| 1731 |
(GAsyncReadyCallback) get_predicted_orbits_data_validity_ready, |
| 1732 |
NULL); |
| 1733 |
} |
| 1734 |
#endif /* HAVE_QMI_MESSAGE_LOC_GET_PREDICTED_ORBITS_DATA_VALIDITY */ |
| 1735 |
|
| 1736 |
static gboolean |
| 1737 |
noop_cb (gpointer unused) |
| 1738 |
{ |
| 1739 |
operation_shutdown (TRUE); |
| 1740 |
return G_SOURCE_REMOVE; |
| 1741 |
} |
| 1742 |
|
| 1743 |
void |
| 1744 |
qmicli_loc_run (QmiDevice *device, |
| 1745 |
QmiClientLoc *client, |
| 1746 |
GCancellable *cancellable) |
| 1747 |
{ |
| 1748 |
/* Initialize context */ |
| 1749 |
ctx = g_slice_new0 (Context); |
| 1750 |
ctx->device = g_object_ref (device); |
| 1751 |
ctx->client = g_object_ref (client); |
| 1752 |
ctx->cancellable = g_object_ref (cancellable); |
| 1753 |
|
| 1754 |
#if defined HAVE_QMI_MESSAGE_LOC_START |
| 1755 |
if (start_flag) { |
| 1756 |
QmiMessageLocStartInput *input; |
| 1757 |
|
| 1758 |
input = qmi_message_loc_start_input_new (); |
| 1759 |
qmi_message_loc_start_input_set_session_id (input, (guint8) session_id, NULL); |
| 1760 |
qmi_message_loc_start_input_set_intermediate_report_state (input, QMI_LOC_INTERMEDIATE_REPORT_STATE_ENABLE, NULL); |
| 1761 |
qmi_message_loc_start_input_set_minimum_interval_between_position_reports (input, 1000, NULL); |
| 1762 |
qmi_message_loc_start_input_set_fix_recurrence_type (input, QMI_LOC_FIX_RECURRENCE_TYPE_REQUEST_PERIODIC_FIXES, NULL); |
| 1763 |
qmi_client_loc_start (ctx->client, |
| 1764 |
input, |
| 1765 |
10, |
| 1766 |
ctx->cancellable, |
| 1767 |
(GAsyncReadyCallback) start_ready, |
| 1768 |
NULL); |
| 1769 |
qmi_message_loc_start_input_unref (input); |
| 1770 |
return; |
| 1771 |
} |
| 1772 |
#endif |
| 1773 |
|
| 1774 |
#if defined HAVE_QMI_MESSAGE_LOC_STOP |
| 1775 |
if (stop_flag) { |
| 1776 |
QmiMessageLocStopInput *input; |
| 1777 |
|
| 1778 |
input = qmi_message_loc_stop_input_new (); |
| 1779 |
qmi_message_loc_stop_input_set_session_id (input, (guint8) session_id, NULL); |
| 1780 |
qmi_client_loc_stop (ctx->client, |
| 1781 |
input, |
| 1782 |
10, |
| 1783 |
ctx->cancellable, |
| 1784 |
(GAsyncReadyCallback) stop_ready, |
| 1785 |
NULL); |
| 1786 |
qmi_message_loc_stop_input_unref (input); |
| 1787 |
return; |
| 1788 |
} |
| 1789 |
#endif |
| 1790 |
|
| 1791 |
#if defined HAVE_QMI_MESSAGE_LOC_DELETE_ASSISTANCE_DATA |
| 1792 |
if (delete_assistance_data_flag) { |
| 1793 |
QmiMessageLocDeleteAssistanceDataInput *input; |
| 1794 |
|
| 1795 |
input = qmi_message_loc_delete_assistance_data_input_new (); |
| 1796 |
qmi_message_loc_delete_assistance_data_input_set_delete_all (input, TRUE, NULL); |
| 1797 |
|
| 1798 |
/* Wait for response asynchronously */ |
| 1799 |
ctx->timeout_id = g_timeout_add_seconds (timeout > 0 ? timeout : DEFAULT_LOC_TIMEOUT_SECS, |
| 1800 |
(GSourceFunc) delete_assistance_data_timed_out, |
| 1801 |
NULL); |
| 1802 |
|
| 1803 |
ctx->delete_assistance_data_indication_id = g_signal_connect (ctx->client, |
| 1804 |
"delete-assistance-data", |
| 1805 |
G_CALLBACK (delete_assistance_data_received), |
| 1806 |
NULL); |
| 1807 |
|
| 1808 |
qmi_client_loc_delete_assistance_data (ctx->client, |
| 1809 |
input, |
| 1810 |
10, |
| 1811 |
ctx->cancellable, |
| 1812 |
(GAsyncReadyCallback) delete_assistance_data_ready, |
| 1813 |
NULL); |
| 1814 |
qmi_message_loc_delete_assistance_data_input_unref (input); |
| 1815 |
return; |
| 1816 |
} |
| 1817 |
#endif |
| 1818 |
|
| 1819 |
#if defined HAVE_QMI_MESSAGE_LOC_GET_NMEA_TYPES |
| 1820 |
if (get_nmea_types_flag) { |
| 1821 |
/* Wait for response asynchronously */ |
| 1822 |
ctx->timeout_id = g_timeout_add_seconds (timeout > 0 ? timeout : DEFAULT_LOC_TIMEOUT_SECS, |
| 1823 |
(GSourceFunc) get_nmea_types_timed_out, |
| 1824 |
NULL); |
| 1825 |
|
| 1826 |
ctx->get_nmea_types_indication_id = g_signal_connect (ctx->client, |
| 1827 |
"get-nmea-types", |
| 1828 |
G_CALLBACK (get_nmea_types_received), |
| 1829 |
NULL); |
| 1830 |
qmi_client_loc_get_nmea_types (ctx->client, |
| 1831 |
NULL, |
| 1832 |
10, |
| 1833 |
ctx->cancellable, |
| 1834 |
(GAsyncReadyCallback) get_nmea_types_ready, |
| 1835 |
NULL); |
| 1836 |
return; |
| 1837 |
} |
| 1838 |
#endif |
| 1839 |
|
| 1840 |
#if defined HAVE_QMI_MESSAGE_LOC_SET_NMEA_TYPES |
| 1841 |
if (set_nmea_types_str) { |
| 1842 |
g_autoptr(QmiMessageLocSetNmeaTypesInput) input = NULL; |
| 1843 |
|
| 1844 |
g_debug ("Asynchronously setting APN type..."); |
| 1845 |
input = set_nmea_types_input_create (set_nmea_types_str); |
| 1846 |
if (!input) { |
| 1847 |
operation_shutdown (FALSE); |
| 1848 |
return; |
| 1849 |
} |
| 1850 |
|
| 1851 |
/* Wait for response asynchronously */ |
| 1852 |
ctx->timeout_id = g_timeout_add_seconds (timeout > 0 ? timeout : DEFAULT_LOC_TIMEOUT_SECS, |
| 1853 |
(GSourceFunc) set_nmea_types_timed_out, |
| 1854 |
NULL); |
| 1855 |
|
| 1856 |
ctx->set_nmea_types_indication_id = g_signal_connect (ctx->client, |
| 1857 |
"set-nmea-types", |
| 1858 |
G_CALLBACK (set_nmea_types_received), |
| 1859 |
NULL); |
| 1860 |
qmi_client_loc_set_nmea_types (ctx->client, |
| 1861 |
input, |
| 1862 |
10, |
| 1863 |
ctx->cancellable, |
| 1864 |
(GAsyncReadyCallback)set_nmea_types_ready, |
| 1865 |
NULL); |
| 1866 |
return; |
| 1867 |
} |
| 1868 |
#endif |
| 1869 |
|
| 1870 |
#if defined HAVE_QMI_MESSAGE_LOC_GET_OPERATION_MODE |
| 1871 |
if (get_operation_mode_flag) { |
| 1872 |
/* Wait for response asynchronously */ |
| 1873 |
ctx->timeout_id = g_timeout_add_seconds (timeout > 0 ? timeout : DEFAULT_LOC_TIMEOUT_SECS, |
| 1874 |
(GSourceFunc) get_operation_mode_timed_out, |
| 1875 |
NULL); |
| 1876 |
|
| 1877 |
ctx->get_operation_mode_indication_id = g_signal_connect (ctx->client, |
| 1878 |
"get-operation-mode", |
| 1879 |
G_CALLBACK (get_operation_mode_received), |
| 1880 |
NULL); |
| 1881 |
qmi_client_loc_get_operation_mode (ctx->client, |
| 1882 |
NULL, |
| 1883 |
10, |
| 1884 |
ctx->cancellable, |
| 1885 |
(GAsyncReadyCallback) get_operation_mode_ready, |
| 1886 |
NULL); |
| 1887 |
return; |
| 1888 |
} |
| 1889 |
#endif |
| 1890 |
|
| 1891 |
#if defined HAVE_QMI_MESSAGE_LOC_SET_OPERATION_MODE |
| 1892 |
if (set_operation_mode_str) { |
| 1893 |
g_autoptr(QmiMessageLocSetOperationModeInput) input = NULL; |
| 1894 |
|
| 1895 |
g_debug ("Asynchronously setting operation mode..."); |
| 1896 |
input = set_operation_mode_input_create (set_operation_mode_str); |
| 1897 |
if (!input) { |
| 1898 |
operation_shutdown (FALSE); |
| 1899 |
return; |
| 1900 |
} |
| 1901 |
|
| 1902 |
/* Wait for response asynchronously */ |
| 1903 |
ctx->timeout_id = g_timeout_add_seconds (timeout > 0 ? timeout : DEFAULT_LOC_TIMEOUT_SECS, |
| 1904 |
(GSourceFunc) set_operation_mode_timed_out, |
| 1905 |
NULL); |
| 1906 |
|
| 1907 |
ctx->set_operation_mode_indication_id = g_signal_connect (ctx->client, |
| 1908 |
"set-operation-mode", |
| 1909 |
G_CALLBACK (set_operation_mode_received), |
| 1910 |
NULL); |
| 1911 |
qmi_client_loc_set_operation_mode (ctx->client, |
| 1912 |
input, |
| 1913 |
10, |
| 1914 |
ctx->cancellable, |
| 1915 |
(GAsyncReadyCallback)set_operation_mode_ready, |
| 1916 |
NULL); |
| 1917 |
return; |
| 1918 |
} |
| 1919 |
#endif |
| 1920 |
|
| 1921 |
#if defined HAVE_QMI_MESSAGE_LOC_GET_ENGINE_LOCK |
| 1922 |
if (get_engine_lock_flag) { |
| 1923 |
/* Wait for response asynchronously */ |
| 1924 |
ctx->timeout_id = g_timeout_add_seconds (timeout > 0 ? timeout : DEFAULT_LOC_TIMEOUT_SECS, |
| 1925 |
(GSourceFunc) get_engine_lock_timed_out, |
| 1926 |
NULL); |
| 1927 |
|
| 1928 |
ctx->get_engine_lock_indication_id = g_signal_connect (ctx->client, |
| 1929 |
"get-engine-lock", |
| 1930 |
G_CALLBACK (get_engine_lock_received), |
| 1931 |
NULL); |
| 1932 |
qmi_client_loc_get_engine_lock (ctx->client, |
| 1933 |
NULL, |
| 1934 |
10, |
| 1935 |
ctx->cancellable, |
| 1936 |
(GAsyncReadyCallback) get_engine_lock_ready, |
| 1937 |
NULL); |
| 1938 |
return; |
| 1939 |
} |
| 1940 |
#endif |
| 1941 |
|
| 1942 |
#if defined HAVE_QMI_MESSAGE_LOC_SET_ENGINE_LOCK |
| 1943 |
if (set_engine_lock_str) { |
| 1944 |
g_autoptr(QmiMessageLocSetEngineLockInput) input = NULL; |
| 1945 |
|
| 1946 |
g_debug ("Asynchronously setting engine lock..."); |
| 1947 |
input = set_engine_lock_input_create (set_engine_lock_str); |
| 1948 |
if (!input) { |
| 1949 |
operation_shutdown (FALSE); |
| 1950 |
return; |
| 1951 |
} |
| 1952 |
|
| 1953 |
/* Wait for response asynchronously */ |
| 1954 |
ctx->timeout_id = g_timeout_add_seconds (timeout > 0 ? timeout : DEFAULT_LOC_TIMEOUT_SECS, |
| 1955 |
(GSourceFunc) set_engine_lock_timed_out, |
| 1956 |
NULL); |
| 1957 |
|
| 1958 |
ctx->set_engine_lock_indication_id = g_signal_connect (ctx->client, |
| 1959 |
"set-engine-lock", |
| 1960 |
G_CALLBACK (set_engine_lock_received), |
| 1961 |
NULL); |
| 1962 |
qmi_client_loc_set_engine_lock (ctx->client, |
| 1963 |
input, |
| 1964 |
10, |
| 1965 |
ctx->cancellable, |
| 1966 |
(GAsyncReadyCallback)set_engine_lock_ready, |
| 1967 |
NULL); |
| 1968 |
return; |
| 1969 |
} |
| 1970 |
#endif |
| 1971 |
|
| 1972 |
#if (defined HAVE_QMI_INDICATION_LOC_POSITION_REPORT || \ |
| 1973 |
defined HAVE_QMI_INDICATION_LOC_GNSS_SV_INFO || \ |
| 1974 |
defined HAVE_QMI_INDICATION_LOC_NMEA) && \ |
| 1975 |
defined HAVE_QMI_MESSAGE_LOC_REGISTER_EVENTS |
| 1976 |
if (get_position_report_flag || get_gnss_sv_info_flag || follow_position_report_flag || follow_gnss_sv_info_flag || follow_nmea_flag) { |
| 1977 |
/* All the remaining actions require monitoring */ |
| 1978 |
ctx->monitoring_step = MONITORING_STEP_FIRST; |
| 1979 |
monitoring_step_run (); |
| 1980 |
return; |
| 1981 |
} |
| 1982 |
#endif |
| 1983 |
|
| 1984 |
#if defined HAVE_QMI_MESSAGE_LOC_INJECT_POSITION |
| 1985 |
if (!isnan (inject_position_latitude) || |
| 1986 |
!isnan (inject_position_longitude)) { |
| 1987 |
|
| 1988 |
if (isnan(inject_position_latitude) || |
| 1989 |
isnan(inject_position_longitude) || |
| 1990 |
(inject_position_latitude < -90) || |
| 1991 |
(inject_position_latitude > 90) || |
| 1992 |
(inject_position_longitude < -180) || |
| 1993 |
(inject_position_longitude > 180)) { |
| 1994 |
g_printerr ("error: correct values for both latitude and longitude has to be set.\n" |
| 1995 |
"`--loc-inject-position-latitude [-90.0 .. 90.0] --loc-inject-position-longitude [-180.0 .. 180.0]'\n"); |
| 1996 |
exit (EXIT_FAILURE); |
| 1997 |
} |
| 1998 |
g_debug ("Asynchronously inject position..."); |
| 1999 |
inject_position_create (); |
| 2000 |
return; |
| 2001 |
} |
| 2002 |
#endif |
| 2003 |
#if defined HAVE_QMI_MESSAGE_LOC_INJECT_UTC_TIME |
| 2004 |
if (inject_time_flag) { |
| 2005 |
g_debug ("Asynchronously inject time..."); |
| 2006 |
inject_time_create (); |
| 2007 |
return; |
| 2008 |
} |
| 2009 |
#endif |
| 2010 |
|
| 2011 |
#if defined HAVE_QMI_MESSAGE_LOC_GET_PREDICTED_ORBITS_DATA_SOURCE |
| 2012 |
if (get_predicted_orbits_data_source_flag) { |
| 2013 |
/* Wait for response asynchronously */ |
| 2014 |
ctx->timeout_id = g_timeout_add_seconds (timeout > 0 ? timeout : DEFAULT_LOC_TIMEOUT_SECS, |
| 2015 |
(GSourceFunc) get_predicted_orbits_data_source_timed_out, |
| 2016 |
NULL); |
| 2017 |
|
| 2018 |
ctx->get_predicted_orbits_data_source_indication_id = g_signal_connect (ctx->client, |
| 2019 |
"get-predicted-orbits-data-source", |
| 2020 |
G_CALLBACK (get_predicted_orbits_data_source_received), |
| 2021 |
NULL); |
| 2022 |
qmi_client_loc_get_predicted_orbits_data_source (ctx->client, |
| 2023 |
NULL, |
| 2024 |
10, |
| 2025 |
ctx->cancellable, |
| 2026 |
(GAsyncReadyCallback) get_predicted_orbits_data_source_ready, |
| 2027 |
ctx); |
| 2028 |
return; |
| 2029 |
} |
| 2030 |
#endif |
| 2031 |
|
| 2032 |
#if defined HAVE_QMI_MESSAGE_LOC_GET_PREDICTED_ORBITS_DATA_VALIDITY |
| 2033 |
if (get_predicted_orbits_data_validity_flag) { |
| 2034 |
g_debug ("Asynchronously request predicted orbits data validity info..."); |
| 2035 |
get_predicted_orbits_data_validity_create (); |
| 2036 |
return; |
| 2037 |
} |
| 2038 |
#endif |
| 2039 |
/* Just client allocate/release? */ |
| 2040 |
if (noop_flag) { |
| 2041 |
g_idle_add (noop_cb, NULL); |
| 2042 |
return; |
| 2043 |
} |
| 2044 |
|
| 2045 |
g_warn_if_reached (); |
| 2046 |
} |
| 2047 |
|
| 2048 |
#endif /* HAVE_QMI_SERVICE_LOC */ |