1 #ifndef LIBPROPELLER_GPSPARSER_H_
2 #define LIBPROPELLER_GPSPARSER_H_
4 #include "libpropeller/serial/serial.h"
29 bool Start(
const int rx_pin,
const int tx_pin,
const int baud) {
31 next_character_position_ = 0;
32 gps_serial_.
Start(rx_pin, tx_pin, baud);
34 recording_sentence_ =
false;
58 return Get(internal_buffer_);
73 char *
Get(
char string[],
const int maxBytes = kNmeaMaxLength) {
76 int byte = gps_serial_.
Get(0);
77 if (
byte == -1)
return NULL;
79 if (next_character_position_ == 6) {
80 CheckForPGTOP(
string);
84 if (recording_sentence_ ==
false &&
byte != kSentenceStartCharacter) {
86 }
else if (
byte ==
'\r' ||
byte ==
'\n') {
87 return TerminateString(
string);
90 recording_sentence_ =
true;
91 string[next_character_position_++] = byte;
94 if (next_character_position_ == maxBytes - 1) {
95 return TerminateString(
string);
104 static const int kNmeaMaxLength = 85;
105 static const int kBufferSize = kNmeaMaxLength;
106 static const char kSentenceStartCharacter =
'$';
108 int next_character_position_;
109 char internal_buffer_[kBufferSize];
110 bool recording_sentence_;
112 char * TerminateString(
char string[]) {
113 string[next_character_position_] = 0;
114 next_character_position_ = 0;
115 recording_sentence_ =
false;
119 void CheckForPGTOP(
char string[]) {
120 if (
string[1] ==
'P' &&
125 next_character_position_ = 0;
126 recording_sentence_ =
false;
134 Serial * getSerial(
void) {
138 friend class ::UnityTests;
143 #endif // LIBPROPELLER_GPSPARSER_H_