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:
parent
b4c8d47536
commit
b98769ea41
|
@ -3,7 +3,10 @@
|
||||||
|
|
||||||
CONFIG_GNSS=y
|
CONFIG_GNSS=y
|
||||||
CONFIG_GNSS_SATELLITES=y
|
CONFIG_GNSS_SATELLITES=y
|
||||||
|
|
||||||
CONFIG_LOG=y
|
CONFIG_LOG=y
|
||||||
CONFIG_LOG_BUFFER_SIZE=8192
|
CONFIG_LOG_BUFFER_SIZE=8192
|
||||||
CONFIG_GNSS_DUMP_TO_LOG=y
|
CONFIG_GNSS_DUMP_TO_LOG=y
|
||||||
|
CONFIG_GNSS_DUMP_TO_LOG_BUF_SIZE=1024
|
||||||
CONFIG_GNSS_LOG_LEVEL_DBG=y
|
CONFIG_GNSS_LOG_LEVEL_DBG=y
|
||||||
|
CONFIG_MODEM_MODULES_LOG_LEVEL_DBG=y
|
||||||
|
|
|
@ -7,25 +7,34 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <zephyr/device.h>
|
#include <zephyr/device.h>
|
||||||
#include <zephyr/drivers/gnss.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)
|
static void gnss_data_cb(const struct device *dev, const struct gnss_data *data)
|
||||||
{
|
{
|
||||||
if (data->info.fix_status != GNSS_FIX_STATUS_NO_FIX) {
|
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(GNSS_MODEM, gnss_data_cb);
|
||||||
GNSS_DATA_CALLBACK_DEFINE(DEVICE_DT_GET(DT_ALIAS(gnss)), gnss_data_cb);
|
|
||||||
|
|
||||||
#if CONFIG_GNSS_SATELLITES
|
#if CONFIG_GNSS_SATELLITES
|
||||||
static void gnss_satellites_cb(const struct device *dev, const struct gnss_satellite *satellites,
|
static void gnss_satellites_cb(const struct device *dev, const struct gnss_satellite *satellites,
|
||||||
uint16_t size)
|
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
|
#endif
|
||||||
|
GNSS_SATELLITES_CALLBACK_DEFINE(GNSS_MODEM, gnss_satellites_cb);
|
||||||
GNSS_SATELLITES_CALLBACK_DEFINE(DEVICE_DT_GET(DT_ALIAS(gnss)), gnss_satellites_cb);
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue