nmea数据具体各字段的含义请参考标准定义,这里给出一个C++实现的例子,环境是Android,本文只解析了几个常用的字段;
本示例的关键方法有split、startswith方法和stringToNumber模版函数
-
bool GnssNmeaParser::startsWith(const std::string &src, const std::string &str)
-
{
-
int srcpos =
0;
-
int srclen = src.
length();
-
int sublen = str.
length();
-
if (srclen < sublen) {
-
return
false;
-
}
-
return (
0 == src.
compare(srcpos, sublen, str));
-
}
-
-
bool GnssNmeaParser::endsWith(const std::string &src, const std::string &str)
-
{
-
int srcpos =
0;
-
int srclen = src.
length();
-
int sublen = str.
length();
-
if (srclen < sublen) {
-
return
false;
-
}
-
srcpos = srclen - sublen;
-
return (
0 == src.
compare(srcpos, sublen, str));
-
}
-
template <
class
T>
-
T stringToNumber(const std::string &sstr)
-
{
-
T number {};
-
std::istringstream iss {};
-
iss.
str(sstr);
-
iss >> number;
/* can auto remove leading 0 */
-
return number;
-
}
-
size_t GnssNmeaParser::split(const std::string &line, const std::string &delim, std::vector<std::string> &vstr)
-
{
-
size_t pstart =
0;
-
size_t phit =
0;
-
std::string sstr;
-
size_t length = line.
length();
-
-
vstr.
clear();
-
for (;pstart <= length;)
-
{
-
phit = line.
find(delim, pstart);
-
if (std::string::npos != phit)
-
{
-
/* find delim, get substr */
-
sstr = line.
substr(pstart, phit-pstart);
-
vstr.
push_back(sstr);
-
pstart = phit + delim.
size();
-
}
else {
-
/* not find delim, append remaining str and break */
-
vstr.
push_back(line.
substr(pstart));
-
break;
-
}
-
}
-
return vstr.
size();
-
}
for Android Gnss V1.0
解析.h头文件
-
#ifndef HAL_GNSS_V1_0_GNSSNMEAPARSER_H
-
#define HAL_GNSS_V1_0_GNSSNMEAPARSER_H
-
-
#include <cstdio>
-
#include <iostream>
-
#include <sstream>
-
#include <bitset>
-
#include <vector>
-
#include <map>
-
#include <queue>
-
-
#include <hardware/gps.h>
-
-
#define GNSS_NMEA_LINE_SEP "\n"
-
#define GNSS_NMEA_ELEMENT_SEP ","
-
#define GNSS_NMEA_PARSER_VERSION "v1.0-20.0716"
-
-
-
#if __GNSS_HAL_DEBUG_ON__
-
/* Flags that indicate information about the satellite */
-
typedef
uint8_t LocGnssSvFlags;
-
#define GNSS_SV_FLAGS_NONE 0
-
#define GNSS_SV_FLAGS_HAS_EPHEMERIS_DATA (1)
-
#define GNSS_SV_FLAGS_HAS_ALMANAC_DATA (2)
-
#define GNSS_SV_FLAGS_USED_IN_FIX (4)
-
-
//hardware/libhardware/include/hardware/gps.h
-
typedef
int64_t GpsUtcTime;
-
/**
-
* Flags that indicate information about the satellite
-
*/
-
typedef
uint8_t GnssSvFlags;
-
-
/**
-
* Constellation type of GnssSvInfo
-
*/
-
typedef
uint8_t GnssConstellationType;
-
-
/** Represents a location. */
-
typedef
struct {
-
/** set to sizeof(GpsLocation) */
-
size_t size;
-
/** Contains GpsLocationFlags bits. */
-
uint16_t flags;
-
/** Represents latitude in degrees. */
-
double latitude;
-
/** Represents longitude in degrees. */
-
double longitude;
-
/**
-
* Represents altitude in meters above the WGS 84 reference ellipsoid.
-
*/
-
double altitude;
-
/** Represents speed in meters per second. */
-
float speed;
-
/** Represents heading in degrees. */
-
float bearing;
-
/** Represents expected accuracy in meters. */
-
float accuracy;
-
/** Timestamp for the location fix. */
-
GpsUtcTime timestamp;
-
} GpsLocation;
-
-
typedef
struct {
-
/** set to sizeof(GnssSvInfo) */
-
size_t size;
-
-
/**
-
* Pseudo-random number for the SV, or FCN/OSN number for Glonass. The
-
* distinction is made by looking at constellation field. Values should be
-
* in the range of:
-
*
-
* - GPS: 1-32
-
* - SBAS: 120-151, 183-192
-
* - GLONASS: 1-24, the orbital slot number (OSN), if known. Or, if not:
-
* 93-106, the frequency channel number (FCN) (-7 to +6) offset by + 100
-
* i.e. report an FCN of -7 as 93, FCN of 0 as 100, and FCN of +6 as 106.
-
* - QZSS: 193-200
-
* - Galileo: 1-36
-
* - Beidou: 1-37
-
*/
-
int16_t svid;
-
-
/**
-
* Defines the constellation of the given SV. Value should be one of those
-
* GNSS_CONSTELLATION_* constants
-
*/
-
GnssConstellationType constellation;
-
-
/**
-
* Carrier-to-noise density in dB-Hz, typically in the range [0, 63].
-
* It contains the measured C/N0 value for the signal at the antenna port.
-
*
-
* This is a mandatory value.
-
*/
-
float c_n0_dbhz;
-
-
/** Elevation of SV in degrees. */
-
float elevation;
-
-
/** Azimuth of SV in degrees. */
-
float azimuth;
-
-
/**
-
* Contains additional data about the given SV. Value should be one of those
-
* GNSS_SV_FLAGS_* constants
-
*/
-
GnssSvFlags flags;
-
-
} GnssSvInfo;
-
-
/**
-
* Legacy struct to represents SV information.
-
* Deprecated, to be removed in the next Android release.
-
* Use GnssSvInfo instead.
-
*/
-
typedef
struct {
-
/** set to sizeof(GpsSvInfo) */
-
size_t size;
-
/** Pseudo-random number for the SV. */
-
int prn;
-
/** Signal to noise ratio. */
-
float snr;
-
/** Elevation of SV in degrees. */
-
float elevation;
-
/** Azimuth of SV in degrees. */
-
float azimuth;
-
} GpsSvInfo;
-
-
/**
-
* Legacy struct to represents SV status.
-
* Deprecated, to be removed in the next Android release.
-
* Use GnssSvStatus instead.
-
*/
-
typedef
struct {
-
/** set to sizeof(GpsSvStatus) */
-
size_t size;
-
int num_svs;
-
GpsSvInfo sv_list[GPS_MAX_SVS];
-
uint32_t ephemeris_mask;
-
uint32_t almanac_mask;
-
uint32_t used_in_fix_mask;
-
} GpsSvStatus;
-
-
typedef
struct {
-
/** set to sizeof(GnssSvStatus) */
-
size_t size;
-
/** Number of GPS SVs currently visible, refers to the SVs stored in sv_list */
-
int num_svs;
-
/**
-


最低0.47元/天 解锁文章
1886

被折叠的 条评论
为什么被折叠?



