mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
Unified statistics counters between UBX and NMEA parser and moved them
to GPS.c.
This commit is contained in:
parent
b6ebee403d
commit
15fa42058e
@ -90,6 +90,8 @@ static char* gps_rx_buffer;
|
||||
static uint32_t timeOfLastCommandMs;
|
||||
static uint32_t timeOfLastUpdateMs;
|
||||
|
||||
static struct GPS_RX_STATS gpsRxStats;
|
||||
|
||||
// ****************
|
||||
/**
|
||||
* Initialise the gps module
|
||||
@ -215,12 +217,12 @@ static void gpsTask(void *parameters)
|
||||
switch (gpsProtocol) {
|
||||
#if defined(PIOS_INCLUDE_GPS_NMEA_PARSER)
|
||||
case GPSSETTINGS_DATAPROTOCOL_NMEA:
|
||||
res = parse_nmea_stream (c,gps_rx_buffer, &gpsposition);
|
||||
res = parse_nmea_stream (c,gps_rx_buffer, &gpsposition, &gpsRxStats);
|
||||
break;
|
||||
#endif
|
||||
#if defined(PIOS_INCLUDE_GPS_UBX_PARSER)
|
||||
case GPSSETTINGS_DATAPROTOCOL_UBX:
|
||||
res = parse_ubx_stream (c,gps_rx_buffer, &gpsposition);
|
||||
res = parse_ubx_stream (c,gps_rx_buffer, &gpsposition, &gpsRxStats);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
|
@ -79,10 +79,6 @@ static bool nmeaProcessGPGSA(GPSPositionData * GpsData, bool* gpsDataUpdated, ch
|
||||
static bool nmeaProcessGPGSV(GPSPositionData * GpsData, bool* gpsDataUpdated, char* param[], uint8_t nbParam);
|
||||
#endif //PIOS_GPS_MINIMAL
|
||||
|
||||
static uint32_t numUpdates;
|
||||
static uint32_t numChecksumErrors;
|
||||
static uint32_t numParsingErrors;
|
||||
|
||||
static struct nmea_parser nmea_parsers[] = {
|
||||
{
|
||||
.prefix = "GPGGA",
|
||||
@ -118,7 +114,7 @@ static struct nmea_parser nmea_parsers[] = {
|
||||
#endif //PIOS_GPS_MINIMAL
|
||||
};
|
||||
|
||||
int parse_nmea_stream (uint8_t c, char *gps_rx_buffer, GPSPositionData *GpsData)
|
||||
int parse_nmea_stream (uint8_t c, char *gps_rx_buffer, GPSPositionData *GpsData, struct GPS_RX_STATS *gpsRxStats)
|
||||
{
|
||||
static uint8_t rx_count = 0;
|
||||
static bool start_flag = false;
|
||||
@ -139,7 +135,7 @@ int parse_nmea_stream (uint8_t c, char *gps_rx_buffer, GPSPositionData *GpsData)
|
||||
{
|
||||
// The buffer is already full and we haven't found a valid NMEA sentence.
|
||||
// Flush the buffer and note the overflow event.
|
||||
// gpsRxOverflow++;
|
||||
gpsRxStats->gpsRxOverflow++;
|
||||
start_flag = false;
|
||||
found_cr = false;
|
||||
rx_count = 0;
|
||||
@ -180,7 +176,7 @@ int parse_nmea_stream (uint8_t c, char *gps_rx_buffer, GPSPositionData *GpsData)
|
||||
if (!NMEA_checksum(&gps_rx_buffer[1]))
|
||||
{ // Invalid checksum. May indicate dropped characters on Rx.
|
||||
//PIOS_DEBUG_PinHigh(2);
|
||||
++numChecksumErrors;
|
||||
gpsRxStats->gpsRxChkSumError++;
|
||||
//PIOS_DEBUG_PinLow(2);
|
||||
return PARSER_ERROR;
|
||||
}
|
||||
@ -188,11 +184,11 @@ int parse_nmea_stream (uint8_t c, char *gps_rx_buffer, GPSPositionData *GpsData)
|
||||
{ // Valid checksum, use this packet to update the GPS position
|
||||
if (!NMEA_update_position(&gps_rx_buffer[1], GpsData)) {
|
||||
//PIOS_DEBUG_PinHigh(2);
|
||||
++numParsingErrors;
|
||||
gpsRxStats->gpsRxParserError++;
|
||||
//PIOS_DEBUG_PinLow(2);
|
||||
}
|
||||
else
|
||||
++numUpdates;
|
||||
gpsRxStats->gpsRxReceived++;;
|
||||
|
||||
return PARSER_COMPLETE;
|
||||
}
|
||||
|
@ -36,13 +36,9 @@
|
||||
#include "UBX.h"
|
||||
#include "gps.h"
|
||||
|
||||
static uint32_t gpsRxReceived = 0;
|
||||
static uint32_t gpsRxChkSumError = 0;
|
||||
static uint32_t gpsRxOverflow = 0;
|
||||
|
||||
// parse incoming character stream for messages in UBX binary format
|
||||
|
||||
int parse_ubx_stream (uint8_t c, char *gps_rx_buffer, GPSPositionData *GpsData)
|
||||
int parse_ubx_stream (uint8_t c, char *gps_rx_buffer, GPSPositionData *GpsData, struct GPS_RX_STATS *gpsRxStats)
|
||||
{
|
||||
enum proto_states {
|
||||
START,
|
||||
@ -87,7 +83,7 @@ int parse_ubx_stream (uint8_t c, char *gps_rx_buffer, GPSPositionData *GpsData)
|
||||
case UBX_LEN2:
|
||||
ubx->header.len += (c << 8);
|
||||
if (ubx->header.len > sizeof(UBXPayload)) {
|
||||
gpsRxOverflow++;
|
||||
gpsRxStats->gpsRxOverflow++;
|
||||
proto_state = START;
|
||||
} else {
|
||||
rx_count = 0;
|
||||
@ -100,7 +96,7 @@ int parse_ubx_stream (uint8_t c, char *gps_rx_buffer, GPSPositionData *GpsData)
|
||||
if (++rx_count == ubx->header.len)
|
||||
proto_state = UBX_CHK1;
|
||||
} else {
|
||||
gpsRxOverflow++;
|
||||
gpsRxStats->gpsRxOverflow++;
|
||||
proto_state = START;
|
||||
}
|
||||
break;
|
||||
@ -114,7 +110,7 @@ int parse_ubx_stream (uint8_t c, char *gps_rx_buffer, GPSPositionData *GpsData)
|
||||
parse_ubx_message(ubx, GpsData);
|
||||
proto_state = FINISHED;
|
||||
} else {
|
||||
gpsRxChkSumError++;
|
||||
gpsRxStats->gpsRxChkSumError++;
|
||||
proto_state = START;
|
||||
}
|
||||
break;
|
||||
@ -124,7 +120,7 @@ int parse_ubx_stream (uint8_t c, char *gps_rx_buffer, GPSPositionData *GpsData)
|
||||
if (proto_state == START)
|
||||
return PARSER_ERROR; // parser couldn't use this byte
|
||||
else if (proto_state == FINISHED) {
|
||||
gpsRxReceived++;
|
||||
gpsRxStats->gpsRxReceived++;
|
||||
proto_state = START;
|
||||
return PARSER_COMPLETE; // message complete & processed
|
||||
}
|
||||
|
@ -45,6 +45,13 @@
|
||||
#define PARSER_INCOMPLETE 0 // parser needs more data to complete the message
|
||||
#define PARSER_COMPLETE 1 // parser has received a complete message and finished processing
|
||||
|
||||
struct GPS_RX_STATS {
|
||||
uint16_t gpsRxReceived;
|
||||
uint16_t gpsRxChkSumError;
|
||||
uint16_t gpsRxOverflow;
|
||||
uint16_t gpsRxParserError;
|
||||
};
|
||||
|
||||
int32_t GPSInitialize(void);
|
||||
|
||||
#endif // GPS_H
|
||||
|
@ -33,11 +33,12 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "gps.h"
|
||||
|
||||
#define NMEA_MAX_PACKET_LENGTH 96 // 82 max NMEA msg size plus 12 margin (because some vendors add custom crap) plus CR plus Linefeed
|
||||
|
||||
extern bool NMEA_update_position(char *nmea_sentence, GPSPositionData *GpsData);
|
||||
extern bool NMEA_checksum(char *nmea_sentence);
|
||||
extern int parse_nmea_stream(uint8_t, char *, GPSPositionData *);
|
||||
extern int parse_nmea_stream(uint8_t, char *, GPSPositionData *, struct GPS_RX_STATS *);
|
||||
|
||||
#endif /* NMEA_H */
|
||||
|
@ -32,6 +32,8 @@
|
||||
#define UBX_H
|
||||
#include "openpilot.h"
|
||||
#include "gpsposition.h"
|
||||
#include "gps.h"
|
||||
|
||||
|
||||
#define UBX_SYNC1 0xb5 // UBX protocol synchronization characters
|
||||
#define UBX_SYNC2 0x62
|
||||
@ -217,6 +219,6 @@ struct UBXPacket {
|
||||
|
||||
bool checksum_ubx_message(struct UBXPacket *);
|
||||
uint32_t parse_ubx_message(struct UBXPacket *, GPSPositionData *);
|
||||
int parse_ubx_stream(uint8_t, char *, GPSPositionData *);
|
||||
int parse_ubx_stream(uint8_t, char *, GPSPositionData *, struct GPS_RX_STATS *);
|
||||
|
||||
#endif /* UBX_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user