added gpsd plugin for location and speed
authorKevron Rees <kevron_m_rees@linux.intel.com>
Fri, 8 Mar 2013 23:43:29 +0000 (15:43 -0800)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Fri, 8 Mar 2013 23:43:29 +0000 (15:43 -0800)
CMakeLists.txt
examples/gpsdconfig [new file with mode: 0644]
lib/vehicleproperty.h
plugins/CMakeLists.txt
plugins/dbus/dbusinterfacemanager.cpp
plugins/examplesink.cpp
plugins/gpsd/CMakeLists.txt [new file with mode: 0644]
plugins/gpsd/gpsdplugin.cpp [new file with mode: 0644]
plugins/gpsd/gpsdplugin.h [new file with mode: 0644]
plugins/opencvlux/opencvluxplugin.h

index 1d38fd4..204361a 100644 (file)
@@ -22,6 +22,7 @@ option(obd2_plugin "OBD-II plugin" ON)
 option(database_plugin "Database plugins" OFF)
 option(qt_bindings "AMB Qt DBus bindings" OFF)
 option(opencvlux_plugin "OpenCV Lux plugin" OFF)
+option(gpsd_plugin "gpsd location plugin" OFF)
 
 if(opencvlux_plugin)
    message(STATUS "OpenCV Lux plugin enabled")
diff --git a/examples/gpsdconfig b/examples/gpsdconfig
new file mode 100644 (file)
index 0000000..3d6c09d
--- /dev/null
@@ -0,0 +1,15 @@
+{
+       "sources" : [ 
+               {
+                       "name" : "gpsd plugin",
+                       "path" : "/usr/lib/automotive-message-broker/gpsdplugin.so",
+                       "updateVelocity" : "true"
+               }
+       ],
+       "sinks": [
+               {
+                       "path" : "/usr/lib/automotive-message-broker/dbussinkplugin.so"
+               }
+       ]
+}
+
index 5807bf1..9f95b3f 100644 (file)
@@ -455,7 +455,7 @@ public:
        typedef BasicPropertyType<double> AltitudeType;
 
        static const Property Direction;
-       typedef BasicPropertyType<uint> DirectionType;
+       typedef BasicPropertyType<uint16_t> DirectionType;
 
        static const Property VehicleWidth;
        static const Property VehicleHeight;
index ce755b7..c0cf1e1 100644 (file)
@@ -28,3 +28,4 @@ add_subdirectory(websocketsourceplugin)
 add_subdirectory(tpms)
 add_subdirectory(database)
 add_subdirectory(opencvlux)
+add_subdirectory(gpsd)
index 812df7b..024ad8e 100644 (file)
@@ -69,6 +69,7 @@ on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_d
        ConstructProperty(ParkingBrakeProperty);
        ConstructProperty(ParkingLightProperty);
        ConstructProperty(HazardLightProperty);
+       ConstructProperty(LocationProperty);
 
        PropertyList list = VehicleProperty::customProperties();
 
index 659771c..ce68dbe 100644 (file)
@@ -49,6 +49,8 @@ void ExampleSink::supportedChanged(PropertyList supportedProperties)
        printf("Support changed!\n");
        routingEngine->subscribeToProperty(VehicleProperty::EngineSpeed, this);
        routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed, this);
+       routingEngine->subscribeToProperty(VehicleProperty::Latitude, this);
+       routingEngine->subscribeToProperty(VehicleProperty::Longitude, this);
 
        AsyncPropertyRequest velocityRequest;
        velocityRequest.property = VehicleProperty::VehicleSpeed;
diff --git a/plugins/gpsd/CMakeLists.txt b/plugins/gpsd/CMakeLists.txt
new file mode 100644 (file)
index 0000000..10fe230
--- /dev/null
@@ -0,0 +1,17 @@
+if(gpsd_plugin)
+
+
+pkg_check_modules(gpsd REQUIRED libgps)
+
+include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs} ${gpsd_INCLUDE_DIRS})
+
+set(gpsdplugin_headers gpsdplugin.h)
+set(gpsdplugin_sources gpsdplugin.cpp)
+
+add_library(gpsdplugin MODULE ${gpsdplugin_sources})
+set_target_properties(gpsdplugin PROPERTIES PREFIX "")
+target_link_libraries(gpsdplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${gpsd_LIBRARIES})
+
+install(TARGETS gpsdplugin LIBRARY DESTINATION lib/automotive-message-broker)
+
+endif(gpsd_plugin)
diff --git a/plugins/gpsd/gpsdplugin.cpp b/plugins/gpsd/gpsdplugin.cpp
new file mode 100644 (file)
index 0000000..b3432f2
--- /dev/null
@@ -0,0 +1,211 @@
+/*
+Copyright (C) 2012 Intel Corporation
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "gpsdplugin.h"
+#include "timestamp.h"
+
+#include <iostream>
+#include <boost/assert.hpp>
+
+using namespace std;
+
+#include "debugout.h"
+
+static int updateGpsposition(gpointer data)
+{
+       GpsdPlugin::Shared* shared = static_cast<GpsdPlugin::Shared*>(data);
+
+#if (GPSD_API_MAJOR_VERSION >= 5)
+
+       if (!gps_waiting (&shared->gps, 0))
+       {
+               return 1;
+       }
+
+       if(gps_read(&shared->gps) == -1)
+       {
+               DebugOut(0)<<"failed to read gps data from gpsd."<<endl;
+               return 1;
+       }
+#else
+
+       gps_poll(&gps);
+
+#endif
+
+       double time = amb::currentTime();
+
+       if(shared->gps.fix.mode > 2)
+       {
+               if(shared->gps.fix.latitude != shared->oldlat)
+                       shared->oldlat = shared->gps.fix.latitude;
+               if(shared->gps.fix.longitude != shared->oldlon)
+                       shared->oldlon = shared->gps.fix.longitude;
+               if(shared->gps.fix.altitude != shared->oldalt)
+                       shared->oldalt = shared->gps.fix.altitude;
+               if(shared->gps.fix.track != shared->oldheading)
+                       shared->oldheading = shared->gps.fix.track;
+               if(shared->gps.fix.speed * MPS_TO_KPH != shared->oldspeed)
+               {
+                       shared->oldspeed = shared->gps.fix.speed * MPS_TO_KPH;
+               }
+
+               shared->parent->updateProperty();
+       }
+
+       return 1;
+}
+
+GpsdPlugin::GpsdPlugin(AbstractRoutingEngine* re, map<string, string> config)
+       :AbstractSource(re, config)
+{
+       shared = new Shared(this);
+
+#if(GPSD_API_MAJOR_VERSION >= 5)
+       int ret = gps_open("localhost","2947", &shared->gps);
+
+       if(ret != 0)
+       {
+               debugOut("failed to open gps");
+               DebugOut()<<"return value: "<<ret<<endl;
+               (void)fprintf(stderr,"no gpsd running or network error: %d, %s\n",
+                                         errno, gps_errstr(errno));
+               return;
+       }
+#else
+       shared->gps = *(gps_open("localhost","2947"));
+
+#endif
+
+       gps_stream(&shared->gps, WATCH_ENABLE | WATCH_JSON, NULL);
+
+       int timeout=200;
+
+       if(config.find("timeout") != config.end())
+       {
+               timeout = atoi(config["timeout"].c_str());
+       }
+
+       updateVelocity = false;
+
+       if(config.find("updateVelocity") != config.end())
+       {
+               updateVelocity = config["updateVelocity"] == "true";
+       }
+
+       g_timeout_add(timeout,updateGpsposition,shared);
+
+       re->setSupported(supported(), this);
+}
+
+GpsdPlugin::~GpsdPlugin()
+{
+       (void) gps_stream(&shared->gps, WATCH_DISABLE, NULL);
+       gps_close(&shared->gps);
+}
+
+extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<string, string> config)
+{
+       return new GpsdPlugin(routingengine, config);
+       
+}
+
+string GpsdPlugin::uuid()
+{
+       return "326011dd-65cd-4be6-a75e-3e8d46a05b5e";
+}
+
+
+void GpsdPlugin::getPropertyAsync(AsyncPropertyReply *reply)
+{
+       /*if(reply->property == VehicleProperty::ExteriorBrightness)
+       {
+               replyQueue.push_back(reply);
+       }*/
+
+//     else  ///We don't support what you are asking for.  Reply false
+       {
+               reply->value = NULL;
+               reply->success = false;
+               reply->completed(reply);
+       }
+}
+
+void GpsdPlugin::getRangePropertyAsync(AsyncRangePropertyReply *reply)
+{
+       throw std::runtime_error("GpsdPlugin does not support this operation.  We should never hit this method.");
+}
+
+AsyncPropertyReply *GpsdPlugin::setProperty(AsyncSetPropertyRequest request )
+{
+       throw std::runtime_error("GpsdPlugin does not support this operation.  We should never hit this method.");
+}
+
+void GpsdPlugin::subscribeToPropertyChanges(VehicleProperty::Property property)
+{
+
+       //mRequests.push_back(property);
+}
+
+void GpsdPlugin::unsubscribeToPropertyChanges(VehicleProperty::Property property)
+{
+       //mRequests.remove(property);
+}
+
+PropertyList GpsdPlugin::supported()
+{
+       PropertyList props;
+       props.push_back(VehicleProperty::Latitude);
+       props.push_back(VehicleProperty::Longitude);
+       props.push_back(VehicleProperty::Altitude);
+       props.push_back(VehicleProperty::Direction);
+
+       if(updateVelocity)
+               props.push_back(VehicleProperty::VehicleSpeed);
+
+       
+       return props;
+}
+
+int GpsdPlugin::supportedOperations()
+{
+       return Get;
+}
+
+
+void GpsdPlugin::updateProperty()
+{
+       VehicleProperty::LatitudeType lat(shared->oldlat);
+       routingEngine->updateProperty(VehicleProperty::Latitude,&lat, uuid());
+
+       VehicleProperty::LongitudeType lon(shared->oldlon);
+       routingEngine->updateProperty(VehicleProperty::Longitude, &lon, uuid());
+
+       VehicleProperty::AltitudeType alt(shared->oldalt);
+       routingEngine->updateProperty(VehicleProperty::Altitude, &alt, uuid());
+
+       VehicleProperty::DirectionType heading(shared->oldheading);
+       routingEngine->updateProperty(VehicleProperty::Direction, &heading, uuid());
+
+       if(updateVelocity)
+       {
+               VehicleProperty::VehicleSpeedType speed(shared->oldspeed);
+               routingEngine->updateProperty(VehicleProperty::VehicleSpeed, &speed, uuid());
+       }
+}
+
diff --git a/plugins/gpsd/gpsdplugin.h b/plugins/gpsd/gpsdplugin.h
new file mode 100644 (file)
index 0000000..7a1004e
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+Copyright (C) 2012 Intel Corporation
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#ifndef GPSDPLUGIN_H
+#define GPSDPLUGIN_H
+
+#include <abstractsource.h>
+#include <string>
+
+#include <gps.h>
+
+using namespace std;
+
+class GpsdPlugin: public AbstractSource
+{
+
+public:
+
+       class Shared
+       {
+       public:
+               Shared(GpsdPlugin* p)
+                       :oldspeed(0), oldalt(0), oldlat(0), oldlon(0), oldheading(0), parent(p)
+               {
+
+               }
+
+               struct gps_data_t gps;
+               double oldspeed;
+               double oldalt;
+               double oldlat;
+               double oldlon;
+               double oldheading;
+               GpsdPlugin* parent;
+       };
+
+       GpsdPlugin(AbstractRoutingEngine* re, map<string, string> config);
+       ~GpsdPlugin();
+       string uuid();
+       void getPropertyAsync(AsyncPropertyReply *reply);
+       void getRangePropertyAsync(AsyncRangePropertyReply *reply);
+       AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request);
+       void subscribeToPropertyChanges(VehicleProperty::Property property);
+       void unsubscribeToPropertyChanges(VehicleProperty::Property property);
+       PropertyList supported();
+
+       int supportedOperations();
+       
+       void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid) {}
+       void supportedChanged(PropertyList) {}
+       
+       void updateProperty();
+
+
+private:       
+       uint lastLux;
+       std::string device;
+       std::list<AsyncPropertyReply*> replyQueue;
+       Shared* shared;
+
+       bool updateVelocity;
+};
+
+
+
+
+#endif // EXAMPLEPLUGIN_H
index 30c84b6..0955ad9 100644 (file)
@@ -16,8 +16,8 @@ License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
-#ifndef EXAMPLEPLUGIN_H
-#define EXAMPLEPLUGIN_H
+#ifndef OPENCVLUXPLUGIN_H
+#define OPENCVLUXPLUGIN_H
 
 #include <abstractsource.h>
 #include <string>