drivers: gnss: Add gnss_dump library
This commit adds a library which dumps the contents of the gnss structures gnss_info, navigation_data, gnss_time and gnss_satellite as a string. Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
This commit is contained in:
parent
28f5f2d1ed
commit
2a81c22489
|
@ -3,3 +3,4 @@
|
|||
|
||||
zephyr_library()
|
||||
zephyr_library_sources(gnss_publish.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_GNSS_DUMP gnss_dump.c)
|
||||
|
|
|
@ -14,6 +14,12 @@ config GNSS_SATELLITES
|
|||
help
|
||||
Enable GNSS sattelites callback.
|
||||
|
||||
config GNSS_DUMP
|
||||
bool "GNSS dump support"
|
||||
depends on LOG
|
||||
help
|
||||
Enable GNSS dump library
|
||||
|
||||
module = GNSS
|
||||
module-str = gnss
|
||||
source "subsys/logging/Kconfig.template.log_config"
|
||||
|
|
134
drivers/gnss/gnss_dump.c
Normal file
134
drivers/gnss/gnss_dump.c
Normal file
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Bjarki Arge Andreasen
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include "gnss_dump.h"
|
||||
#include <zephyr/kernel.h>
|
||||
#include <string.h>
|
||||
|
||||
static const char *gnss_fix_status_to_str(enum gnss_fix_status fix_status)
|
||||
{
|
||||
switch (fix_status) {
|
||||
case GNSS_FIX_STATUS_NO_FIX:
|
||||
return "NO_FIX";
|
||||
case GNSS_FIX_STATUS_GNSS_FIX:
|
||||
return "GNSS_FIX";
|
||||
case GNSS_FIX_STATUS_DGNSS_FIX:
|
||||
return "DGNSS_FIX";
|
||||
case GNSS_FIX_STATUS_ESTIMATED_FIX:
|
||||
return "ESTIMATED_FIX";
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
static const char *gnss_fix_quality_to_str(enum gnss_fix_quality fix_quality)
|
||||
{
|
||||
switch (fix_quality) {
|
||||
case GNSS_FIX_QUALITY_INVALID:
|
||||
return "INVALID";
|
||||
case GNSS_FIX_QUALITY_GNSS_SPS:
|
||||
return "GNSS_SPS";
|
||||
case GNSS_FIX_QUALITY_DGNSS:
|
||||
return "DGNSS";
|
||||
case GNSS_FIX_QUALITY_GNSS_PPS:
|
||||
return "GNSS_PPS";
|
||||
case GNSS_FIX_QUALITY_RTK:
|
||||
return "RTK";
|
||||
case GNSS_FIX_QUALITY_FLOAT_RTK:
|
||||
return "FLOAT_RTK";
|
||||
case GNSS_FIX_QUALITY_ESTIMATED:
|
||||
return "ESTIMATED";
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
#if CONFIG_GNSS_SATELLITES
|
||||
static const char *gnss_system_to_str(enum gnss_system system)
|
||||
{
|
||||
switch (system) {
|
||||
case GNSS_SYSTEM_GPS:
|
||||
return "GPS";
|
||||
case GNSS_SYSTEM_GLONASS:
|
||||
return "GLONASS";
|
||||
case GNSS_SYSTEM_GALILEO:
|
||||
return "GALILEO";
|
||||
case GNSS_SYSTEM_BEIDOU:
|
||||
return "BEIDOU";
|
||||
case GNSS_SYSTEM_QZSS:
|
||||
return "QZSS";
|
||||
case GNSS_SYSTEM_IRNSS:
|
||||
return "IRNSS";
|
||||
case GNSS_SYSTEM_SBAS:
|
||||
return "SBAS";
|
||||
case GNSS_SYSTEM_IMES:
|
||||
return "IMES";
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
#endif
|
||||
|
||||
int gnss_dump_info(char *str, uint16_t strsize, const struct gnss_info *info)
|
||||
{
|
||||
int ret;
|
||||
const char *fmt = "gnss_info: {satellites_cnt: %u, hdop: %u.%u, fix_status: %s, "
|
||||
"fix_quality: %s}";
|
||||
|
||||
ret = snprintk(str, strsize, fmt, info->satellites_cnt, info->hdop / 1000,
|
||||
info->hdop % 1000, gnss_fix_status_to_str(info->fix_status),
|
||||
gnss_fix_quality_to_str(info->fix_quality));
|
||||
|
||||
return (strsize < ret) ? -ENOMEM : 0;
|
||||
}
|
||||
|
||||
int gnss_dump_nav_data(char *str, uint16_t strsize, const struct navigation_data *nav_data)
|
||||
{
|
||||
int ret;
|
||||
int32_t altitude_int;
|
||||
int32_t altitude_fraction;
|
||||
const char *fmt = "navigation_data: {latitude: %lli.%lli, longitude : %lli.%lli, "
|
||||
"bearing %u.%u, speed %u.%u, altitude: %i.%i}";
|
||||
|
||||
altitude_int = nav_data->altitude / 1000;
|
||||
altitude_fraction = nav_data->altitude % 1000;
|
||||
altitude_fraction = (altitude_fraction < 0) ? -altitude_fraction : altitude_fraction;
|
||||
|
||||
ret = snprintk(str, strsize, fmt, nav_data->latitude / 1000000000,
|
||||
nav_data->latitude % 1000000000, nav_data->longitude / 1000000000,
|
||||
nav_data->longitude % 1000000000, nav_data->bearing / 1000,
|
||||
nav_data->bearing % 1000, nav_data->speed / 1000, nav_data->speed % 1000,
|
||||
altitude_int, altitude_fraction);
|
||||
|
||||
return (strsize < ret) ? -ENOMEM : 0;
|
||||
}
|
||||
|
||||
int gnss_dump_time(char *str, uint16_t strsize, const struct gnss_time *utc)
|
||||
{
|
||||
int ret;
|
||||
const char *fmt = "gnss_time: {hour: %u, minute: %u, millisecond %u, month_day %u, "
|
||||
"month: %u, century_year: %u}";
|
||||
|
||||
ret = snprintk(str, strsize, fmt, utc->hour, utc->minute, utc->millisecond,
|
||||
utc->month_day, utc->month, utc->century_year);
|
||||
|
||||
return (strsize < ret) ? -ENOMEM : 0;
|
||||
}
|
||||
|
||||
#if CONFIG_GNSS_SATELLITES
|
||||
int gnss_dump_satellite(char *str, uint16_t strsize, const struct gnss_satellite *satellite)
|
||||
{
|
||||
int ret;
|
||||
const char *fmt = "gnss_satellite: {prn: %u, snr: %u, elevation %u, azimuth %u, "
|
||||
"system: %s, is_tracked: %u}";
|
||||
|
||||
ret = snprintk(str, strsize, fmt, satellite->prn, satellite->snr, satellite->elevation,
|
||||
satellite->azimuth, gnss_system_to_str(satellite->system),
|
||||
satellite->is_tracked);
|
||||
|
||||
return (strsize < ret) ? -ENOMEM : 0;
|
||||
}
|
||||
#endif
|
60
drivers/gnss/gnss_dump.h
Normal file
60
drivers/gnss/gnss_dump.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Bjarki Arge Andreasen
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef ZEPHYR_DRIVERS_GNSS_GNSS_DUMP_H_
|
||||
#define ZEPHYR_DRIVERS_GNSS_GNSS_DUMP_H_
|
||||
|
||||
#include <zephyr/drivers/gnss.h>
|
||||
|
||||
/**
|
||||
* @brief Dump struct gnss_info as string
|
||||
*
|
||||
* @param str Destination for dumped GNSS info
|
||||
* @param strsize Size of str
|
||||
* @param info GNSS info to dump
|
||||
*
|
||||
* @retval 0 if GNSS info successfully dumped
|
||||
* @retval -ENOMEM if strsize too small
|
||||
*/
|
||||
int gnss_dump_info(char *str, uint16_t strsize, const struct gnss_info *info);
|
||||
|
||||
/**
|
||||
* @brief Dump struct navigation_data as string
|
||||
*
|
||||
* @param str Destination for dumped navigation data
|
||||
* @param strsize Size of str
|
||||
* @param nav_data Navigation data to dump
|
||||
*
|
||||
* @retval 0 if navigation data successfully dumped
|
||||
* @retval -ENOMEM if strsize too small
|
||||
*/
|
||||
int gnss_dump_nav_data(char *str, uint16_t strsize, const struct navigation_data *nav_data);
|
||||
|
||||
/**
|
||||
* @brief Dump struct gnss_time as string
|
||||
*
|
||||
* @param str Destination for dumped GNSS time
|
||||
* @param strsize Size of str
|
||||
* @param utc GNSS time to dump
|
||||
*
|
||||
* @retval 0 if GNSS time successfully dumped
|
||||
* @retval -ENOMEM if strsize too small
|
||||
*/
|
||||
int gnss_dump_time(char *str, uint16_t strsize, const struct gnss_time *utc);
|
||||
|
||||
/**
|
||||
* @brief Dump struct gnss_satellite as string
|
||||
*
|
||||
* @param str Destination for dumped GNSS satellite
|
||||
* @param strsize Size of str
|
||||
* @param utc GNSS satellite to dump
|
||||
*
|
||||
* @retval 0 if GNSS satellite successfully dumped
|
||||
* @retval -ENOMEM if strsize too small
|
||||
*/
|
||||
int gnss_dump_satellite(char *str, uint16_t strsize, const struct gnss_satellite *satellite);
|
||||
|
||||
#endif /* ZEPHYR_DRIVERS_GNSS_GNSS_DUMP_H_ */
|
Loading…
Reference in a new issue