location.parse("GPRMC,023633.00,V,,,,,,,180314,,,N*75");
DebugOut(0)<<"lon: "<<location.longitude().toString()<<endl;
DebugOut(0)<<"lat: "<<location.latitude().toString()<<endl;
+
+ std::string testChecksuming = "GPRMC,195617.00,V,,,,,,,310314,,,N*74";
+
+ g_assert(checksum(testChecksuming));
+
+ std::string multimessage1 = "GA,235320.00,4532.48633,N,12257.";
+ std::string multimessage2 = "57383,W,";
+ std::string multimessage3 = "1,03,7.53,51.6,M,-21.3,M,,*55";
+ std::string multimessage4 = "GPGSA,A,";
+ std::string multimessage5 = "2,27,23,19,,,,,,,,,,7.60";
+ std::string multimessage6 = ",7.53,1.00*0E";
+ bool multimessageParse = false;
+
+ multimessageParse |= tryParse(multimessage1);
+ multimessageParse |= tryParse(multimessage2);
+ multimessageParse |= tryParse(multimessage3);
+ multimessageParse |= tryParse(multimessage4);
+ multimessageParse |= tryParse(multimessage5);
+ multimessageParse |= tryParse(multimessage6);
+
+ g_assert(multimessageParse);
+
}
std::string btaddapter = config["bluetoothAdapter"];
{
std::string data = device->read();
+ tryParse(data);
+}
+
+bool GpsNmeaSource::tryParse(string data)
+{
std::vector<std::string> lines;
- boost::split(lines,data,boost::is_any_of("$"));
+ boost::split(lines, data, boost::is_any_of("$"));
+
+ bool weFoundAMessage = false;
- for(int i = 0; i < lines.size(); i++)
+ for(auto line : lines)
{
- if(checksum(lines[i]))
+ if(checksum(line))
{
- buffer = lines[i];
+ buffer = line;
}
else
{
- buffer += lines[i];
+ buffer += line;
+ }
+
+ uint pos = buffer.find('G');
+
+ if(pos != std::string::npos && pos != 0)
+ {
+ ///Throw the incomplete stuff away. if it doesn't begin with "G" it'll never be complete
+ buffer = buffer.substr(pos);
}
if(checksum(buffer))
/// we have a complete message. parse it!
DebugOut(7)<<"Complete message: "<<buffer<<endl;
location->parse(buffer);
+ weFoundAMessage = true;
+ buffer = "";
+ }
+ else
+ {
+ if(pos == 0 )
+ {
+ uint cs = buffer.find('*');
+ if (cs != std::string::npos)
+ {
+ ///This means we have a false flag somewhere.
+ buffer = buffer.substr(cs+3);
+ }
+ }
}
DebugOut(7)<<"buffer: "<<buffer<<endl;
-
}
+
+ return weFoundAMessage;
}
void GpsNmeaSource::unsubscribeToPropertyChanges(VehicleProperty::Property property)
checksum ^= i;
}
- std::string sentenceCheckStr = sentence.substr(sentence.length()-4,2);
+ std::string sentenceCheckStr = sentence.substr(sentence.find('*')+1,2);
try
{
{
return false;
}
+
+ return false;
}