driver/sensors: Add constellation for GNSS

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
This commit is contained in:
wangjianyu3
2024-06-21 11:27:28 +08:00
committed by Xiang Xiao
parent c652f41c87
commit e830db0316
2 changed files with 57 additions and 0 deletions
+38
View File
@@ -33,6 +33,7 @@
#include <poll.h>
#include <debug.h>
#include <minmea/minmea.h>
#include <sys/param.h>
/****************************************************************************
* Pre-processor Definitions
@@ -89,6 +90,12 @@ struct gnss_upperhalf_s
struct sensor_gnss gnss;
};
struct gnss_constellation_s
{
FAR const char *prefix;
int id;
};
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
@@ -136,6 +143,16 @@ static const struct file_operations g_gnss_fops =
gnss_poll /* poll */
};
static const struct gnss_constellation_s g_gnss_constellation[] =
{
{ "GP", SENSOR_GNSS_CONSTELLATION_GPS},
{ "GL", SENSOR_GNSS_CONSTELLATION_GLONASS},
{ "GQ", SENSOR_GNSS_CONSTELLATION_QZSS},
{ "GB", SENSOR_GNSS_CONSTELLATION_BEIDOU},
{ "BD", SENSOR_GNSS_CONSTELLATION_BEIDOU},
{ "GA", SENSOR_GNSS_CONSTELLATION_GALILEO},
};
/****************************************************************************
* Private Functions
****************************************************************************/
@@ -498,6 +515,7 @@ static void gnss_parse_nmea(FAR struct gnss_upperhalf_s *upper,
{
struct minmea_sentence_gsv frame;
struct sensor_gnss_satellite satellite;
size_t i;
memset(&satellite, 0, sizeof(satellite));
if (minmea_parse_gsv(&frame, nmea))
@@ -508,6 +526,26 @@ static void gnss_parse_nmea(FAR struct gnss_upperhalf_s *upper,
memcpy(satellite.info, frame.sats,
sizeof(satellite.info[0]) * 4);
lower = &upper->dev[GNSS_SATELLITE_IDX].lower;
for (i = 0; i < nitems(g_gnss_constellation); i++)
{
if (!strncmp(g_gnss_constellation[i].prefix, nmea,
strlen(g_gnss_constellation[i].prefix)))
{
satellite.constellation = g_gnss_constellation[i].id;
if ((satellite.constellation ==
SENSOR_GNSS_CONSTELLATION_GPS) &&
(frame.msg_nr > 32))
{
satellite.constellation =
SENSOR_GNSS_CONSTELLATION_SBAS;
}
break;
}
}
lower->push_event(lower->priv, &satellite,
sizeof(satellite));
}
+19
View File
@@ -558,12 +558,31 @@ struct sensor_gnss /* Type: GNSS */
uint32_t satellites_used; /* Number of satellites used */
};
/* Ref: android14-release/hardware/libhardware/include_all/hardware/\
* gnss-base.h
*/
enum sensor_gnss_constellation
{
SENSOR_GNSS_CONSTELLATION_UNKNOWN = 0,
SENSOR_GNSS_CONSTELLATION_GPS = 1,
SENSOR_GNSS_CONSTELLATION_SBAS = 2,
SENSOR_GNSS_CONSTELLATION_GLONASS = 3,
SENSOR_GNSS_CONSTELLATION_QZSS = 4,
SENSOR_GNSS_CONSTELLATION_BEIDOU = 5,
SENSOR_GNSS_CONSTELLATION_GALILEO = 6,
};
struct sensor_gnss_satellite
{
uint64_t timestamp; /* Time since system start, Units is microseconds */
uint32_t count; /* Total number of messages of satellites visible */
uint32_t satellites; /* Total number of satellites in view */
/* Constellation of the given svid, see SENSOR_GNSS_CONSTELLATION_*. */
uint32_t constellation;
struct satellite
{
uint32_t svid; /* Space vehicle ID */