fixed up gpsnmea to work with devices with very fragmented nmea messages
authorKevron Rees <kevron.m.rees@intel.com>
Tue, 1 Apr 2014 00:36:52 +0000 (17:36 -0700)
committerKevron Rees <kevron.m.rees@intel.com>
Tue, 1 Apr 2014 00:36:52 +0000 (17:36 -0700)
build/plugins/cansimplugin/CMakeFiles/cansimplugin.dir/flags.make
build/plugins/cansimplugin/CMakeFiles/cansimplugin.dir/link.txt
plugins/gpsnmea/gpsnmea.cpp
plugins/gpsnmea/gpsnmea.h

index 18b275b..8586e6c 100644 (file)
@@ -2,7 +2,7 @@
 # Generated by "Unix Makefiles" Generator, CMake Version 2.8
 
 # compile CXX with /usr/lib/icecc/bin/g++
-CXX_FLAGS = -g -fPIC -I/home/tripzero/src/automotive-message-broker/lib -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/json-c -I/usr/include/gio-unix-2.0 -I/home/tripzero/src/automotive-message-broker/plugins/common    -std=c++11
+CXX_FLAGS = -std=c++11 -g -fPIC -I/home/tripzero/src/automotive-message-broker/lib -I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/json-c -I/usr/include/gio-unix-2.0 -I/home/tripzero/src/automotive-message-broker/plugins/common   
 
 CXX_DEFINES = -DDBusServiceName=\"org.automotive.message.broker\" -DPROJECT_CODENAME=\"veyron\" -DPROJECT_NAME=\"automotive-message-broker\" -DPROJECT_QUALITY=\"alpha\" -DPROJECT_VERSION=\"0.11.808\" -Dcansimplugin_EXPORTS
 
index c4db0c1..75f0d42 100644 (file)
@@ -1 +1 @@
-/usr/lib/icecc/bin/g++  -fPIC -g   -shared -Wl,-soname,cansimplugin.so -o cansimplugin.so CMakeFiles/cansimplugin.dir/cansimplugin.cpp.o ../../lib/libamb.so.0.11.808 ../common/libamb-plugins-common.so -L/home/tripzero/src/automotive-message-broker/build/plugins/cansimplugin/plugins/common -lamb -lltdl -lgobject-2.0 -lglib-2.0 -ljson-c -L/home/tripzero/src/automotive-message-broker/build/lib -lrt -luuid -lgio-2.0 -lgobject-2.0 -lglib-2.0 -ljson-c -Wl,-rpath,/home/tripzero/src/automotive-message-broker/build/lib:/home/tripzero/src/automotive-message-broker/build/plugins/common: 
+/usr/lib/icecc/bin/g++  -fPIC -std=c++11 -g   -shared -Wl,-soname,cansimplugin.so -o cansimplugin.so CMakeFiles/cansimplugin.dir/cansimplugin.cpp.o ../../lib/libamb.so.0.11.808 ../common/libamb-plugins-common.so -L/home/tripzero/src/automotive-message-broker/build/plugins/cansimplugin/plugins/common -lamb -lltdl -lgobject-2.0 -lglib-2.0 -ljson-c -L/home/tripzero/src/automotive-message-broker/build/lib -lrt -luuid -lgio-2.0 -lgobject-2.0 -lglib-2.0 -ljson-c -Wl,-rpath,/home/tripzero/src/automotive-message-broker/build/lib:/home/tripzero/src/automotive-message-broker/build/plugins/common: 
index dcac3e6..ea6c262 100644 (file)
@@ -413,6 +413,28 @@ GpsNmeaSource::GpsNmeaSource(AbstractRoutingEngine *re, map<string, string> conf
                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"];
@@ -506,19 +528,34 @@ void GpsNmeaSource::canHasData()
 {
        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))
@@ -526,11 +563,26 @@ void GpsNmeaSource::canHasData()
                        /// 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)
@@ -568,7 +620,7 @@ bool GpsNmeaSource::checksum(std::string sentence)
                        checksum ^= i;
        }
 
-       std::string sentenceCheckStr = sentence.substr(sentence.length()-4,2);
+       std::string sentenceCheckStr = sentence.substr(sentence.find('*')+1,2);
 
        try
        {
@@ -581,4 +633,6 @@ bool GpsNmeaSource::checksum(std::string sentence)
        {
                return false;
        }
+
+       return false;
 }
index 34ac4b6..f8e758d 100644 (file)
@@ -56,9 +56,11 @@ public:
        }
 
        void canHasData();
-       
+
 private:
 
+       bool tryParse(std::string data);
+
        void addPropertySupport(VehicleProperty::Property property, Zone::Type zone);
 
        bool checksum(string sentence);