samples: gnss: improve logging

Report more information and do not use `dev->name` so that what the
sample prints looks less similar to the GNSS dump logs.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
This commit is contained in:
Tomi Fontanilles 2024-04-22 17:54:40 +03:00 committed by Anas Nashif
parent b4c8d47536
commit b98769ea41
2 changed files with 18 additions and 6 deletions

View file

@ -3,7 +3,10 @@
CONFIG_GNSS=y
CONFIG_GNSS_SATELLITES=y
CONFIG_LOG=y
CONFIG_LOG_BUFFER_SIZE=8192
CONFIG_GNSS_DUMP_TO_LOG=y
CONFIG_GNSS_DUMP_TO_LOG_BUF_SIZE=1024
CONFIG_GNSS_LOG_LEVEL_DBG=y
CONFIG_MODEM_MODULES_LOG_LEVEL_DBG=y

View file

@ -7,25 +7,34 @@
#include <stdio.h>
#include <zephyr/device.h>
#include <zephyr/drivers/gnss.h>
#include <zephyr/logging/log.h>
#define GNSS_MODEM DEVICE_DT_GET(DT_ALIAS(gnss))
LOG_MODULE_REGISTER(gnss_sample, CONFIG_GNSS_LOG_LEVEL);
static void gnss_data_cb(const struct device *dev, const struct gnss_data *data)
{
if (data->info.fix_status != GNSS_FIX_STATUS_NO_FIX) {
printf("%s has fix!\r\n", dev->name);
printf("Got a fix!\n");
}
}
GNSS_DATA_CALLBACK_DEFINE(DEVICE_DT_GET(DT_ALIAS(gnss)), gnss_data_cb);
GNSS_DATA_CALLBACK_DEFINE(GNSS_MODEM, gnss_data_cb);
#if CONFIG_GNSS_SATELLITES
static void gnss_satellites_cb(const struct device *dev, const struct gnss_satellite *satellites,
uint16_t size)
{
printf("%s reported %u satellites!\r\n", dev->name, size);
unsigned int tracked_count = 0;
for (unsigned int i = 0; i != size; ++i) {
tracked_count += satellites[i].is_tracked;
}
printf("%u satellite%s reported (of which %u tracked)!\n",
size, size > 1 ? "s" : "", tracked_count);
}
#endif
GNSS_SATELLITES_CALLBACK_DEFINE(DEVICE_DT_GET(DT_ALIAS(gnss)), gnss_satellites_cb);
GNSS_SATELLITES_CALLBACK_DEFINE(GNSS_MODEM, gnss_satellites_cb);
int main(void)
{