drivers: gnss: Add GNSS dump to log feature
This commit adds dumping of GNSS data and satellites to the log if CONFIG_GNSS_DUMP_TO_LOG is selected Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
This commit is contained in:
parent
2a81c22489
commit
03d2671ddd
2 changed files with 63 additions and 0 deletions
|
|
@ -20,6 +20,22 @@ config GNSS_DUMP
|
||||||
help
|
help
|
||||||
Enable GNSS dump library
|
Enable GNSS dump library
|
||||||
|
|
||||||
|
config GNSS_DUMP_TO_LOG
|
||||||
|
bool "Dump GNSS events to log"
|
||||||
|
select GNSS_DUMP
|
||||||
|
help
|
||||||
|
Enable GNSS dump to log.
|
||||||
|
|
||||||
|
if GNSS_DUMP_TO_LOG
|
||||||
|
|
||||||
|
config GNSS_DUMP_TO_LOG_BUF_SIZE
|
||||||
|
int "GNSS log dump buffer size"
|
||||||
|
default 128
|
||||||
|
help
|
||||||
|
Size of GNSS log dump buffer
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
module = GNSS
|
module = GNSS
|
||||||
module-str = gnss
|
module-str = gnss
|
||||||
source "subsys/logging/Kconfig.template.log_config"
|
source "subsys/logging/Kconfig.template.log_config"
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,14 @@
|
||||||
|
|
||||||
#include "gnss_dump.h"
|
#include "gnss_dump.h"
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
|
#include <zephyr/logging/log.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#if CONFIG_GNSS_DUMP_TO_LOG
|
||||||
|
static char dump_buf[CONFIG_GNSS_DUMP_TO_LOG_BUF_SIZE];
|
||||||
|
#endif /* CONFIG_GNSS_DUMP_TO_LOG */
|
||||||
|
|
||||||
static const char *gnss_fix_status_to_str(enum gnss_fix_status fix_status)
|
static const char *gnss_fix_status_to_str(enum gnss_fix_status fix_status)
|
||||||
{
|
{
|
||||||
switch (fix_status) {
|
switch (fix_status) {
|
||||||
|
|
@ -132,3 +138,44 @@ int gnss_dump_satellite(char *str, uint16_t strsize, const struct gnss_satellite
|
||||||
return (strsize < ret) ? -ENOMEM : 0;
|
return (strsize < ret) ? -ENOMEM : 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if CONFIG_GNSS_DUMP_TO_LOG
|
||||||
|
static void gnss_dump_data_to_log(const struct device *dev, const struct gnss_data *data)
|
||||||
|
{
|
||||||
|
if (gnss_dump_info(dump_buf, sizeof(dump_buf), &data->info) < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_PRINTK("%s: %s\r\n", dev->name, dump_buf);
|
||||||
|
|
||||||
|
if (gnss_dump_nav_data(dump_buf, sizeof(dump_buf), &data->nav_data) < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_PRINTK("%s: %s\r\n", dev->name, dump_buf);
|
||||||
|
|
||||||
|
if (gnss_dump_time(dump_buf, sizeof(dump_buf), &data->utc) < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_PRINTK("%s: %s\r\n", dev->name, dump_buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
GNSS_DATA_CALLBACK_DEFINE(NULL, gnss_dump_data_to_log);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_GNSS_DUMP_TO_LOG) && defined(CONFIG_GNSS_SATELLITES)
|
||||||
|
static void gnss_dump_satellites_to_log(const struct device *dev,
|
||||||
|
const struct gnss_satellite *satellites, uint16_t size)
|
||||||
|
{
|
||||||
|
for (uint16_t i = 0; i < size; i++) {
|
||||||
|
if (gnss_dump_satellite(dump_buf, sizeof(dump_buf), &satellites[i]) < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_PRINTK("%s: %s\r\n", dev->name, dump_buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GNSS_SATELLITES_CALLBACK_DEFINE(NULL, gnss_dump_satellites_to_log);
|
||||||
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue