Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions drivers/gnss/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,24 @@ module = GNSS_UBX_MODEM
module-str = u-blox GNSS
source "subsys/logging/Kconfig.template.log_config"

config GNSS_U_BLOX_LARGE_MESSAGES
bool
help
Configure defaults for large messages. Intended for supporting optional
messages like NAV-PVT.

config GNSS_U_BLOX_PIPE_SIZE
int "UBX modem pipe size"
range 128 2048
default 1024 if GNSS_U_BLOX_LARGE_MESSAGES
default 512
help
Maximum number of bytes that can be stored in the pipe buffer.

config GNSS_U_BLOX_MAX_MSG_SIZE
int "UBX modem pipe size"
range 128 512
default 512 if GNSS_U_BLOX_LARGE_MESSAGES
default 256
help
Maximum size of a UBX message that driver can handle.
Expand Down
3 changes: 2 additions & 1 deletion samples/task_runner/gnss/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ CONFIG_INFUSE_WATCHDOG=y

CONFIG_ASSERT=y
CONFIG_GNSS=y
CONFIG_GNSS_U_BLOX_NO_API_COMPAT=y

CONFIG_TASK_RUNNER=y
CONFIG_TASK_RUNNER_AUTO_ITERATE=y
CONFIG_TASK_RUNNER_TASK_GNSS=y
CONFIG_TASK_RUNNER_TASK_BATTERY=y
CONFIG_TASK_RUNNER_TASK_TDF_LOGGER=y

CONFIG_TASK_RUNNER_GNSS_SATELLITE_INFO=y
1 change: 1 addition & 0 deletions samples/task_runner/gnss/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ tests:
sample.task_runner.gnss:
tags: app
integration_platforms:
- thingy91x/nrf9151/ns
- tauro/nrf9151/ns
sample.task_runner.gnss.api_compat:
tags: app
Expand Down
4 changes: 4 additions & 0 deletions subsys/task_runner/tasks/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ config TASK_RUNNER_TASK_GNSS_STACK_SIZE
default 4096 if COVERAGE
default 2048

config TASK_RUNNER_GNSS_SATELLITE_INFO
bool "Display satellite information while running fixes"
imply GNSS_U_BLOX_LARGE_MESSAGES

config TASK_RUNNER_GNSS_MINIMUM_ACCURACY_M
int "Accuracies worse than this threshold are reported as (-181,-91)"
default 100000
Expand Down
19 changes: 18 additions & 1 deletion subsys/task_runner/tasks/task_gnss_nrf9x.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ static bool handle_pvt_frame(const struct task_gnss_args *args)
struct tdf_nrf9x_gnss_pvt tdf;
uint32_t runtime = k_uptime_seconds() - state.task_start;
bool valid_time, valid_hacc, valid_pdop;
bool info = k_uptime_seconds() % 30 == 0;
int rc;

/* Get data */
Expand All @@ -223,7 +224,7 @@ static bool handle_pvt_frame(const struct task_gnss_args *args)
}

/* Periodically print fix state */
if (k_uptime_seconds() % 30 == 0) {
if (info) {
LOG_INF("NAV-PVT: Lat: %9d Lon: %9d Height: %6d", tdf.lat, tdf.lon, tdf.height);
LOG_INF(" HAcc: %u mm VAcc: %u mm pDOP: %d NumSV: %d", tdf.h_acc, tdf.v_acc,
tdf.p_dop / 100, tdf.num_sv);
Expand All @@ -232,6 +233,22 @@ static bool handle_pvt_frame(const struct task_gnss_args *args)
LOG_DBG(" HAcc: %u mm VAcc: %u mm pDOP: %d NumSV: %d", tdf.h_acc, tdf.v_acc,
tdf.p_dop / 100, tdf.num_sv);
}
#ifdef CONFIG_TASK_RUNNER_GNSS_SATELLITE_INFO
for (int i = 0; i < NRF_MODEM_GNSS_MAX_SATELLITES; i++) {
uint8_t used = !!(frame.sv[i].flags & NRF_MODEM_GNSS_SV_FLAG_USED_IN_FIX);

if (frame.sv[i].sv == 0) {
continue;
}
if (info) {
LOG_INF("\tID: %3d CNo: %3d dB/Hz Used: %d", frame.sv[i].sv,
frame.sv[i].cn0, used);
} else {
LOG_DBG("\tID: %3d CNo: %3d dB/Hz Used: %d", frame.sv[i].sv,
frame.sv[i].cn0, used);
}
}
#endif /* CONFIG_TASK_RUNNER_GNSS_SATELLITE_INFO */

if (run_target == TASK_GNSS_FLAGS_RUN_FOREVER) {
/* If running perpetually, log each output */
Expand Down
62 changes: 62 additions & 0 deletions subsys/task_runner/tasks/task_gnss_ubx.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ struct gnss_run_state {
struct ubx_modem_data *modem;
const struct task_schedule *schedule;
struct ubx_message_handler_ctx timegps;
#ifdef CONFIG_TASK_RUNNER_GNSS_SATELLITE_INFO
struct ubx_message_handler_ctx nav_sat;
#endif /* CONFIG_TASK_RUNNER_GNSS_SATELLITE_INFO */
struct ubx_msg_nav_pvt latest_pvt;
struct ubx_msg_nav_pvt best_fix;
struct ubx_msg_nav_timegps latest_timegps;
Expand Down Expand Up @@ -275,6 +278,31 @@ static bool nav_pvt_handle(struct gnss_run_state *state, const struct task_gnss_
return false;
}

#ifdef CONFIG_TASK_RUNNER_GNSS_SATELLITE_INFO
static int nav_sat_cb(uint8_t message_class, uint8_t message_id, const void *payload,
size_t payload_len, void *user_data)
{
const struct ubx_msg_nav_sat *sat = payload;
bool info = k_uptime_seconds() % 30 == 0;

for (int i = 0; i < sat->num_svs; i++) {
uint8_t quality = sat->svs[i].flags & UBX_MSG_NAV_SAT_FLAGS_QUALITY_IND_MASK;
uint8_t used = !!(sat->svs[i].flags & UBX_MSG_NAV_SAT_FLAGS_SV_USED);

if (info) {
LOG_INF("\tGNSS: %d ID: %3d CNo: %3d dB/Hz Qual: %d Used: %d",
sat->svs[i].gnss_id, sat->svs[i].sv_id, sat->svs[i].cno, quality,
used);
} else {
LOG_DBG("\tGNSS: %d ID: %3d CNo: %3d dB/Hz Qual: %d Used: %d",
sat->svs[i].gnss_id, sat->svs[i].sv_id, sat->svs[i].cno, quality,
used);
}
}
return 0;
}
#endif /* CONFIG_TASK_RUNNER_GNSS_SATELLITE_INFO */

void gnss_task_fn(const struct task_schedule *schedule, struct k_poll_signal *terminate,
void *gnss_dev)
{
Expand Down Expand Up @@ -349,6 +377,10 @@ void gnss_task_fn(const struct task_schedule *schedule, struct k_poll_signal *te
UBX_MSG_CFG_VALSET_LAYERS_RAM | UBX_MSG_CFG_VALSET_LAYERS_BBR);
/* Core location message */
UBX_CFG_VALUE_APPEND(&cfg_buf, UBX_CFG_KEY_MSGOUT_UBX_NAV_PVT_I2C, 1);
#ifdef CONFIG_TASK_RUNNER_GNSS_SATELLITE_INFO
/* Satellite information message */
UBX_CFG_VALUE_APPEND(&cfg_buf, UBX_CFG_KEY_MSGOUT_UBX_NAV_SAT_I2C, 1);
#endif /* CONFIG_TASK_RUNNER_GNSS_SATELLITE_INFO */
/* Power mode configuration */
if (args->flags & TASK_GNSS_FLAGS_PERFORMANCE_MODE) {
/* Normal mode tracking (default values) */
Expand Down Expand Up @@ -400,11 +432,38 @@ void gnss_task_fn(const struct task_schedule *schedule, struct k_poll_signal *te
if (rc < 0) {
LOG_WRN("Failed to configure NAV-PVT rate");
}

#ifdef CONFIG_TASK_RUNNER_GNSS_SATELLITE_INFO
const struct ubx_msg_cfg_msg cfg_msg_sat = {
.msg_class = UBX_MSG_CLASS_NAV,
.msg_id = UBX_MSG_ID_NAV_SAT,
.rate = 1,
};

ubx_msg_simple(&msg_buf, UBX_MSG_CLASS_CFG, UBX_MSG_ID_CFG_RATE, &cfg_msg_sat,
sizeof(cfg_msg_sat));
rc = ubx_modem_send_sync_acked(run_state.modem, &msg_buf, K_MSEC(250));
if (rc < 0) {
LOG_WRN("Failed to configure navigation rate");
}
#endif /* CONFIG_TASK_RUNNER_GNSS_SATELLITE_INFO */
#endif /* CONFIG_GNSS_UBX_M8 */

/* Subscribe to NAV-PVT message */
ubx_modem_msg_subscribe(run_state.modem, &pvt_handler_ctx);

#ifdef CONFIG_TASK_RUNNER_GNSS_SATELLITE_INFO
struct ubx_message_handler_ctx sat_handler_ctx = {
.message_class = UBX_MSG_CLASS_NAV,
.message_id = UBX_MSG_ID_NAV_SAT,
.message_cb = nav_sat_cb,
.user_data = NULL,
};

/* Subscribe to NAV-SAT message */
ubx_modem_msg_subscribe(run_state.modem, &sat_handler_ctx);
#endif /* CONFIG_TASK_RUNNER_GNSS_SATELLITE_INFO */

/* Block until runner requests termination (all work happens in NAV-PVT callback) */
struct k_poll_event events[] = {
K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL, K_POLL_MODE_NOTIFY_ONLY, terminate),
Expand Down Expand Up @@ -466,6 +525,9 @@ void gnss_task_fn(const struct task_schedule *schedule, struct k_poll_signal *te

/* Cleanup message subscription */
ubx_modem_msg_unsubscribe(run_state.modem, &pvt_handler_ctx);
#ifdef CONFIG_TASK_RUNNER_GNSS_SATELLITE_INFO
ubx_modem_msg_unsubscribe(run_state.modem, &sat_handler_ctx);
#endif /* CONFIG_TASK_RUNNER_GNSS_SATELLITE_INFO */

/* Release power requirement */
rc = pm_device_runtime_put(gnss);
Expand Down