reworked tests in gpsnmea
authorKevron Rees <kevron.m.rees@intel.com>
Wed, 30 Apr 2014 21:22:11 +0000 (14:22 -0700)
committerKevron Rees <kevron.m.rees@intel.com>
Wed, 30 Apr 2014 21:22:11 +0000 (14:22 -0700)
CMakeLists.txt
lib/abstractsink.cpp
lib/abstractsource.cpp
plugins/common/abstractio.hpp
plugins/common/serialport.hpp
plugins/gpsnmea/CMakeLists.txt
plugins/gpsnmea/gpsnmea.cpp
plugins/gpsnmea/gpsnmea.h

index 784dabe..26bdc8d 100644 (file)
@@ -41,6 +41,7 @@ option(enable_docs "enable Doxygen doc generation" OFF)
 
 #turn on -fpic/-fpie:
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+list(APPEND CMAKE_CXX_FLAGS "-fpie -pie -std=c++11")
 
 if(opencvlux_plugin)
    message(STATUS "OpenCV Lux plugin enabled")
@@ -84,7 +85,6 @@ find_package(Boost REQUIRED)
 pkg_check_modules(glib REQUIRED glib-2.0 gobject-2.0)
 pkg_check_modules(json REQUIRED json)
 
-list(APPEND CMAKE_CXX_FLAGS "-std=c++11")
 add_definitions(-DDBusServiceName="org.automotive.message.broker")
 
 set(include_dirs ${libtool_INCLUDE_DIR} ${glib_INCLUDE_DIRS} ${gio_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${json_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}/lib)
index 87d5509..70587a0 100644 (file)
 AbstractSink::AbstractSink(AbstractRoutingEngine* engine, map<string, string> config)
        :routingEngine(engine), configuration(config)
 {
-       routingEngine->registerSink(this);
+       if(routingEngine)
+               routingEngine->registerSink(this);
 }
 
 AbstractSink::~AbstractSink()
 {
-       routingEngine->unregisterSink(this);
+       if(routingEngine)
+               routingEngine->unregisterSink(this);
 }
 
 AbstractSinkManager::AbstractSinkManager(AbstractRoutingEngine* engine, map<string, string> config)
index d8649fe..7a94589 100644 (file)
@@ -22,7 +22,8 @@
 AbstractSource::AbstractSource(AbstractRoutingEngine* engine, map<string, string> config)
        : AbstractSink(engine,config), routingEngine(engine)
 {
-       engine->registerSource(this);
+       if(engine)
+               engine->registerSource(this);
 }
 
 AbstractSource::~AbstractSource()
index fc4d0fb..3e0aa67 100644 (file)
@@ -9,6 +9,7 @@ public:
 
        virtual bool open() = 0;
        virtual bool close() = 0;
+       virtual bool isOpen() =0;
        virtual std::string read() = 0;
        virtual void write(std::string data) = 0;
 
index 469c5f3..4fa0418 100644 (file)
@@ -20,7 +20,7 @@ private:
 
 public:
        SerialPort(std::string _tty)
-               :tty(_tty)
+               :tty(_tty), fd(0)
        {
                speed = B9600;
        }
@@ -93,6 +93,11 @@ public:
                return true;
        }
 
+       bool isOpen()
+       {
+               return (fd > 0);
+       }
+
        int fileDescriptor() { return fd; }
 
        bool close()
index 8a64834..fddfe88 100644 (file)
@@ -5,10 +5,11 @@ set(gpsnmea_sources gpsnmea.cpp )
 
 include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs} ${gio_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/plugins/common)
 
-add_library(gpsnmea MODULE ${gpsnmea_sources})
-set_target_properties(gpsnmea PROPERTIES PREFIX "")
-target_link_libraries(gpsnmea amb -L${CMAKE_CURRENT_BINARY_DIR}/lib  amb-plugins-common -L${CMAKE_CURRENT_BINARY_DIR}/plugins/common ${link_libraries} ${gio_LIBRARIES})
+add_executable(gpsnmea.so ${gpsnmea_sources})
+#add_library(gpsnmea MODULE ${gpsnmea_sources})
+set_target_properties(gpsnmea.so PROPERTIES PREFIX "")
+target_link_libraries(gpsnmea.so amb -L${CMAKE_CURRENT_BINARY_DIR}/lib  amb-plugins-common -L${CMAKE_CURRENT_BINARY_DIR}/plugins/common ${link_libraries} ${gio_LIBRARIES})
 
-install(TARGETS gpsnmea LIBRARY DESTINATION lib/automotive-message-broker)
+install(TARGETS gpsnmea.so RUNTIME DESTINATION lib/automotive-message-broker)
 
 endif(gpsnmea_plugin)
index b36f8b8..75ff340 100644 (file)
@@ -216,12 +216,13 @@ void Location::parseTime(string h, string m, string s, string dd, string mm, str
                if(mGpsTime != temp)
                {
                        mGpsTime = temp;
-                       routingEngine->updateProperty(&mGpsTime, mUuid);
+                       if(routingEngine)
+                               routingEngine->updateProperty(&mGpsTime, mUuid);
                }
        }
        catch(...)
        {
-               DebugOut(DebugOut::Warning)<<"Failed to parse time "<<endl;
+               DebugOut(5)<<"Failed to parse time "<<endl;
        }
 }
 
@@ -242,13 +243,15 @@ void Location::parseLatitude(string d, string m, string ns)
 
                if(mLatitude != temp)
                {
-                       mLatitude = temp;\
-                       routingEngine->updateProperty(&mLatitude, mUuid);
+                       mLatitude = temp;
+
+                       if(routingEngine)
+                               routingEngine->updateProperty(&mLatitude, mUuid);
                }
        }
        catch(...)
        {
-               DebugOut(DebugOut::Warning)<<"Failed to parse latitude"<<endl;
+               DebugOut(5)<<"Failed to parse latitude"<<endl;
        }
 }
 
@@ -268,13 +271,15 @@ void Location::parseLongitude(string d, string m, string ew)
 
                if(mLongitude != temp)
                {
-                       mLongitude = temp;\
-                       routingEngine->updateProperty(&mLongitude, mUuid);
+                       mLongitude = temp;
+
+                       if(routingEngine)
+                               routingEngine->updateProperty(&mLongitude, mUuid);
                }
        }
        catch(...)
        {
-               DebugOut(DebugOut::Warning)<<"failed to parse longitude"<<endl;
+               DebugOut(5)<<"failed to parse longitude: "<<d<<" "<<m<<" "<<ew<<endl;
        }
 }
 
@@ -290,12 +295,14 @@ void Location::parseSpeed(string spd)
                if(mSpeed != temp)
                {
                        mSpeed = temp;
-                       routingEngine->updateProperty(&mSpeed, mUuid);
+
+                       if(routingEngine)
+                               routingEngine->updateProperty(&mSpeed, mUuid);
                }
        }
        catch(...)
        {
-               DebugOut(DebugOut::Warning)<<"failed to parse speed"<<endl;
+               DebugOut(5)<<"failed to parse speed"<<endl;
        }
 }
 
@@ -308,12 +315,13 @@ void Location::parseDirection(string dir)
                if(mDirection != temp)
                {
                        mDirection = temp;
-                       routingEngine->updateProperty(&mDirection, mUuid);
+                       if(routingEngine)
+                               routingEngine->updateProperty(&mDirection, mUuid);
                }
        }
        catch(...)
        {
-               DebugOut(DebugOut::Warning)<<"Failed to parse direction: "<<dir<<endl;
+               DebugOut(5)<<"Failed to parse direction: "<<dir<<endl;
        }
 }
 
@@ -329,14 +337,16 @@ void Location::parseAltitude(string alt)
                if(mAltitude != temp)
                {
                        mAltitude = temp;
-                       routingEngine->updateProperty(&mAltitude, mUuid);
+
+                       if(routingEngine)
+                               routingEngine->updateProperty(&mAltitude, mUuid);
                }
 
                mAltitude = VehicleProperty::AltitudeType(a);
        }
        catch(...)
        {
-               DebugOut(DebugOut::Warning)<<"failed to parse altitude"<<endl;
+               DebugOut(5)<<"failed to parse altitude"<<endl;
        }
 }
 
@@ -378,7 +388,7 @@ extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<str
 }
 
 GpsNmeaSource::GpsNmeaSource(AbstractRoutingEngine *re, map<string, string> config)
-       :AbstractSource(re,config), mUuid("33d86462-1708-4f78-a001-99ea8d55422b")
+       :AbstractSource(re,config), mUuid("33d86462-1708-4f78-a001-99ea8d55422b"), device(nullptr)
 {
        int baudrate = 0;
        location =new Location(re, mUuid);
@@ -397,58 +407,7 @@ GpsNmeaSource::GpsNmeaSource(AbstractRoutingEngine *re, map<string, string> conf
 
        if(config.find("test") != config.end())
        {
-               Location location(routingEngine, mUuid);
-               location.parse("GPRMC,061211,A,2351.9605,S,15112.5239,E,000.0,053.4,170303,009.9,E*6E");
-
-               DebugOut(0)<<"lat: "<<location.latitude().toString()<<endl;
-
-               g_assert(location.latitude().toString() == "-23.86600833");
-               g_assert(location.gpsTime().toString() == "1050585131");
-
-               location.parse("GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47");
-
-               DebugOut(0)<<"alt: "<<location.altitude().toString()<<endl;
-               DebugOut(0)<<"lat: "<<location.latitude().toString()<<endl;
-               g_assert(location.altitude().toString() == "545.4");
-               g_assert(location.latitude().toString() == "48.1173");
-
-               location.parse("GPRMC,060136.00,A,3101.40475,N,12126.87095,E,0.760,,160114,,,A*74");
-               DebugOut(0)<<"lon: "<<location.longitude().toString()<<endl;
-               DebugOut(0)<<"lat: "<<location.latitude().toString()<<endl;
-               
-               //Test incomplete message:
-               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*";
-               std::string multimessage7 = "0E";
-
-               bool multimessageParse = false;
-
-               multimessageParse |= tryParse(multimessage1);
-               multimessageParse |= tryParse(multimessage2);
-               multimessageParse |= tryParse(multimessage3);
-               multimessageParse |= tryParse(multimessage4);
-               multimessageParse |= tryParse(multimessage5);
-               multimessageParse |= tryParse(multimessage6);
-               multimessageParse |= tryParse(multimessage7);
-
-               g_assert(multimessageParse);
-
-               //test false message:
-
-               g_assert(!checksum("GPRMC,172758.296,V"));
-
+               test();
        }
 
        std::string btaddapter = config["bluetoothAdapter"];
@@ -493,7 +452,8 @@ GpsNmeaSource::GpsNmeaSource(AbstractRoutingEngine *re, map<string, string> conf
 
 GpsNmeaSource::~GpsNmeaSource()
 {
-       device->close();
+       if(device && device->isOpen())
+               device->close();
 }
 
 const string GpsNmeaSource::uuid()
@@ -556,6 +516,61 @@ void GpsNmeaSource::canHasData()
        tryParse(data);
 }
 
+void GpsNmeaSource::test()
+{
+       Location location(nullptr, "");
+       location.parse("GPRMC,061211,A,2351.9605,S,15112.5239,E,000.0,053.4,170303,009.9,E*6E");
+
+       DebugOut(0)<<"lat: "<<location.latitude().toString()<<endl;
+
+       g_assert(location.latitude().toString() == "-23.86600833");
+       g_assert(location.gpsTime().toString() == "1050585131");
+
+       location.parse("GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47");
+
+       DebugOut(0)<<"alt: "<<location.altitude().toString()<<endl;
+       DebugOut(0)<<"lat: "<<location.latitude().toString()<<endl;
+       g_assert(location.altitude().toString() == "545.4");
+       g_assert(location.latitude().toString() == "48.1173");
+
+       location.parse("GPRMC,060136.00,A,3101.40475,N,12126.87095,E,0.760,,160114,,,A*74");
+       DebugOut(0)<<"lon: "<<location.longitude().toString()<<endl;
+       DebugOut(0)<<"lat: "<<location.latitude().toString()<<endl;
+
+       //Test incomplete message:
+       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*";
+       std::string multimessage7 = "0E";
+
+       bool multimessageParse = false;
+
+       multimessageParse |= tryParse(multimessage1);
+       multimessageParse |= tryParse(multimessage2);
+       multimessageParse |= tryParse(multimessage3);
+       multimessageParse |= tryParse(multimessage4);
+       multimessageParse |= tryParse(multimessage5);
+       multimessageParse |= tryParse(multimessage6);
+       multimessageParse |= tryParse(multimessage7);
+
+       g_assert(multimessageParse);
+
+       //test false message:
+
+       g_assert(!checksum("GPRMC,172758.296,V"));
+}
+
 bool GpsNmeaSource::tryParse(string data)
 {
        std::vector<std::string> lines;
@@ -661,3 +676,13 @@ bool GpsNmeaSource::checksum(std::string sentence)
 
        return false;
 }
+
+
+int main(int argc, char** argv)
+{
+       DebugOut::setDebugThreshhold(7);
+       GpsNmeaSource plugin(nullptr, std::map<std::string, std::string>());
+       plugin.test();
+
+       return 1;
+}
index f8e758d..2179ed5 100644 (file)
@@ -57,8 +57,12 @@ public:
 
        void canHasData();
 
+       void test();
+
 private:
 
+
+
        bool tryParse(std::string data);
 
        void addPropertySupport(VehicleProperty::Property property, Zone::Type zone);