diff options
author | Kevron Rees <tripzero.kev@gmail.com> | 2013-03-14 17:33:41 -0700 |
---|---|---|
committer | Kevron Rees <tripzero.kev@gmail.com> | 2013-03-14 17:33:41 -0700 |
commit | 8e7e49d8b02622aa90895d3a61389313ab2bb13b (patch) | |
tree | 23e0ce30d3c62ddd0b54ec7741869648aa19c96c | |
parent | aacfcec158cbb7411be7c337e0c8f51f0ba2ccfe (diff) | |
parent | b34f6af9195b344a5b4f8e88e2c22630e67b6fda (diff) | |
download | automotive-message-broker-8e7e49d8b02622aa90895d3a61389313ab2bb13b.tar.gz |
Merge branch 'master' of https://github.com/otcshare/automotive-message-broker
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | examples/databaseconfig | 3 | ||||
-rw-r--r-- | examples/gpsdconfig | 15 | ||||
-rw-r--r-- | examples/opencvconfig | 15 | ||||
-rw-r--r-- | examples/storage | bin | 15360 -> 15360 bytes | |||
-rw-r--r-- | lib/abstractpropertytype.h | 12 | ||||
-rw-r--r-- | lib/vehicleproperty.h | 2 | ||||
-rw-r--r-- | plugins/CMakeLists.txt | 1 | ||||
-rw-r--r-- | plugins/database/databasesink.cpp | 320 | ||||
-rw-r--r-- | plugins/database/databasesink.h | 56 | ||||
-rw-r--r-- | plugins/dbus/amb-qt/ambqt.h | 14 | ||||
-rw-r--r-- | plugins/dbus/dbusinterfacemanager.cpp | 1 | ||||
-rw-r--r-- | plugins/examplesink.cpp | 2 | ||||
-rw-r--r-- | plugins/gpsd/CMakeLists.txt | 17 | ||||
-rw-r--r-- | plugins/gpsd/gpsdplugin.cpp | 211 | ||||
-rw-r--r-- | plugins/gpsd/gpsdplugin.h | 82 | ||||
-rw-r--r-- | plugins/obd2plugin/obd2source.cpp | 2 | ||||
-rw-r--r-- | plugins/opencvlux/README | 3 | ||||
-rw-r--r-- | plugins/opencvlux/opencvluxplugin.h | 4 | ||||
-rw-r--r-- | plugins/websocketsink/CMakeLists.txt | 10 |
20 files changed, 688 insertions, 83 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d38fd4f..204361a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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/databaseconfig b/examples/databaseconfig index 9007fe58..23cde224 100644 --- a/examples/databaseconfig +++ b/examples/databaseconfig @@ -14,6 +14,9 @@ { "name" : "Example Sink", "path" : "/usr/lib/automotive-message-broker/examplesinkplugin.so" + }, + { + "path" : "/usr/lib/automotive-message-broker/dbussinkplugin.so" } ] } diff --git a/examples/gpsdconfig b/examples/gpsdconfig new file mode 100644 index 00000000..3d6c09df --- /dev/null +++ b/examples/gpsdconfig @@ -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" + } + ] +} + diff --git a/examples/opencvconfig b/examples/opencvconfig new file mode 100644 index 00000000..fc6c2529 --- /dev/null +++ b/examples/opencvconfig @@ -0,0 +1,15 @@ +{ + "sources" : [ + { + "name" : "OpenCV Lux Plugin", + "path" : "/usr/lib/automotive-message-broker/opencvluxplugin.so" + } + ], + "sinks": [ + { + "name" : "DBusSink", + "path" : "/usr/lib/automotive-message-broker/dbussinkplugin.so" + } + ] +} + diff --git a/examples/storage b/examples/storage Binary files differindex 19a06f00..c21b03bc 100644 --- a/examples/storage +++ b/examples/storage diff --git a/lib/abstractpropertytype.h b/lib/abstractpropertytype.h index dc625e5e..2f67058a 100644 --- a/lib/abstractpropertytype.h +++ b/lib/abstractpropertytype.h @@ -334,7 +334,7 @@ class StringPropertyType: public AbstractPropertyType { public: StringPropertyType(std::string val) - :AbstractPropertyType(),mVariant(NULL) + :AbstractPropertyType() { setValue(val); } @@ -370,22 +370,14 @@ public: { //mVariant = Glib::Variant<std::string>::create(toString()); - if(mVariant) - g_variant_unref(mVariant); - - mVariant = g_variant_ref(g_variant_new_string(toString().c_str())); + return g_variant_new_string(toString().c_str()); - return mVariant; } void fromVariant(GVariant *v) { setValue(std::string(g_variant_get_string(v,NULL))); } - -private: - - GVariant* mVariant; }; template <class T> diff --git a/lib/vehicleproperty.h b/lib/vehicleproperty.h index 5807bf1f..9f95b3f7 100644 --- a/lib/vehicleproperty.h +++ b/lib/vehicleproperty.h @@ -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; diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index ce755b74..c0cf1e1f 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -28,3 +28,4 @@ add_subdirectory(websocketsourceplugin) add_subdirectory(tpms) add_subdirectory(database) add_subdirectory(opencvlux) +add_subdirectory(gpsd) diff --git a/plugins/database/databasesink.cpp b/plugins/database/databasesink.cpp index 85c751df..5c44f54f 100644 --- a/plugins/database/databasesink.cpp +++ b/plugins/database/databasesink.cpp @@ -1,5 +1,6 @@ #include "databasesink.h" #include "abstractroutingengine.h" +#include "listplusplus.h" #include <json-glib/json-glib.h> @@ -8,52 +9,101 @@ extern "C" AbstractSinkManager * create(AbstractRoutingEngine* routingengine, ma return new DatabaseSinkManager(routingengine, config); } -DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, map<std::string, std::string> config) - :AbstractSource(engine,config) +void * cbFunc(gpointer data) { - databaseName = "storage"; - tablename = "data"; - tablecreate = "CREATE TABLE IF NOT EXISTS data (key TEXT, value BLOB, source TEXT, time REAL, sequence REAL)"; - shared = new Shared; - shared->db->init(databaseName, tablename, tablecreate); + Shared *shared = static_cast<Shared*>(data); + + if(!shared) + { + throw std::runtime_error("Could not cast shared object."); + } - auto cb = [](gpointer data) + while(1) { - Shared *shared = (Shared*)data; + DBObject* obj = shared->queue.pop(); - while(1) + if( obj->quit ) { - DBObject* obj = shared->queue.pop(); + delete obj; + break; + } - if( obj->quit ) - { - delete obj; - break; - } + DictionaryList<string> dict; - DictionaryList<string> dict; + NameValuePair<string> one("key", obj->key); + NameValuePair<string> two("value", obj->value); + NameValuePair<string> three("source", obj->source); + NameValuePair<string> four("time", boost::lexical_cast<string>(obj->time)); + NameValuePair<string> five("sequence", boost::lexical_cast<string>(obj->sequence)); - NameValuePair<string> one("key", obj->key); - NameValuePair<string> two("value", obj->value); - NameValuePair<string> three("source", obj->source); - NameValuePair<string> four("time", boost::lexical_cast<string>(obj->time)); - NameValuePair<string> five("sequence", boost::lexical_cast<string>(obj->sequence)); + dict.push_back(one); + dict.push_back(two); + dict.push_back(three); + dict.push_back(four); + dict.push_back(five); - dict.push_back(one); - dict.push_back(two); - dict.push_back(three); - dict.push_back(four); - dict.push_back(five); + shared->db->insert(dict); + delete obj; + } - shared->db->insert(dict); - delete obj; - } + return NULL; +} + +int getNextEvent(gpointer data) +{ + PlaybackShared* pbshared = static_cast<PlaybackShared*>(data); + + if(!pbshared) + throw std::runtime_error("failed to cast PlaybackShared object"); + + auto itr = pbshared->playbackQueue.begin(); + + if(itr == pbshared->playbackQueue.end()) + { + return 0; + } + + DBObject* obj = *itr; + + AbstractPropertyType* value = VehicleProperty::getPropertyTypeForPropertyNameValue(obj->key,obj->value); + + if(value) + { + pbshared->routingEngine->updateProperty(obj->key, value, pbshared->uuid); + value->timestamp = obj->time; + value->sequence = obj->sequence; + } + + if(++itr != pbshared->playbackQueue.end()) + { + DBObject *o2 = *itr; + double t = o2->time - obj->time; + + if(t > 0) + g_timeout_add(t*1000, getNextEvent, pbshared); + else + g_timeout_add(t, getNextEvent, pbshared); + } + + pbshared->playbackQueue.remove(obj); + delete obj; + + return 0; +} + +DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, map<std::string, std::string> config) + :AbstractSource(engine,config),thread(NULL),shared(NULL),playback(false),playbackShared(NULL) +{ + databaseName = "storage"; + tablename = "data"; + tablecreate = "CREATE TABLE IF NOT EXISTS data (key TEXT, value BLOB, source TEXT, time REAL, sequence REAL)"; - void* ret = NULL; - return ret; - }; + //startDb(); - thread = g_thread_new("dbthread", cb, shared); + if(config.find("startOnLoad")!= config.end()) + { + startDb(); + } parseConfig(); @@ -62,18 +112,27 @@ DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, map<std::string, std:: engine->subscribeToProperty(*itr,this); } + mSupported.push_back(DatabaseFileProperty); + mSupported.push_back(DatabaseLoggingProperty); + mSupported.push_back(DatabasePlaybackProperty); + + routingEngine->setSupported(mSupported,this); + } DatabaseSink::~DatabaseSink() { - DBObject* obj = new DBObject(); - obj->quit = true; - - shared->queue.append(obj); + if(shared) + { + DBObject* obj = new DBObject(); + obj->quit = true; - g_thread_join(thread); + shared->queue.append(obj); - delete shared; + g_thread_join(thread); + g_thread_unref(thread); + delete shared; + } } @@ -84,13 +143,7 @@ void DatabaseSink::supportedChanged(PropertyList supportedProperties) PropertyList DatabaseSink::supported() { - PropertyList props; - - props.push_back(VehicleProperty::EngineSpeed); - props.push_back(VehicleProperty::VehicleSpeed); - props.push_back(DatabaseLoggingProperty); - - return props; + return mSupported; } void DatabaseSink::parseConfig() @@ -106,7 +159,10 @@ void DatabaseSink::parseConfig() JsonNode* node = json_parser_get_root(parser); if(node == nullptr) - throw std::runtime_error("Unable to get JSON root object"); + { + /// no options + return; + } JsonReader* reader = json_reader_new(node); @@ -133,8 +189,106 @@ void DatabaseSink::parseConfig() g_object_unref(parser); } +void DatabaseSink::stopDb() +{ + if(!shared) + return; + + DBObject *obj = new DBObject(); + obj->quit = true; + shared->queue.append(obj); + + g_thread_join(thread); + + delete shared; + shared = NULL; +} + +void DatabaseSink::startDb() +{ + if(playback) + { + DebugOut(0)<<"ERROR: tried to start logging during playback. Only logging or playback can be used at one time"<<endl; + return; + } + + if(shared) + { + DebugOut(0)<<"WARNING: logging already started. doing nothing."<<endl; + return; + } + + initDb(); + +// thread = g_thread_new("dbthread", cbFunc, shared); +} + +void DatabaseSink::startPlayback() +{ + if(playback) + return; + + playback = true; + + initDb(); + + /// get supported: + + vector<vector<string> > supportedStr = shared->db->select("SELECT DISTINCT key FROM "+tablename); + + for(int i=0; i < supportedStr.size(); i++) + { + if(!ListPlusPlus<VehicleProperty::Property>(&mSupported).contains(supportedStr[i][0])) + mSupported.push_back(supportedStr[i][0]); + } + + routingEngine->setSupported(supported(), this); + + /// populate playback queue: + + vector<vector<string> > results = shared->db->select("SELECT * FROM "+tablename); + + if(playbackShared) + { + delete playbackShared; + } + + playbackShared = new PlaybackShared(routingEngine,uuid()); + + for(int i=0;i<results.size();i++) + { + if(results[i].size() < 5) + { + throw std::runtime_error("column mismatch in query"); + } + + DBObject* obj = new DBObject(); + + obj->key = results[i][0]; + obj->value = results[i][1]; + obj->source = results[i][2]; + obj->time = boost::lexical_cast<double>(results[i][3]); +// obj->sequence = boost::lexical_cast<int>(results[i][4]); + + playbackShared->playbackQueue.push_back(obj); + } + + g_timeout_add(0,getNextEvent,playbackShared); +} + +void DatabaseSink::initDb() +{ + if(shared) delete shared; + + shared = new Shared; + shared->db->init(databaseName, tablename, tablecreate); +} + void DatabaseSink::propertyChanged(VehicleProperty::Property property, AbstractPropertyType *value, std::string uuid) { + if(!shared) + return; + DBObject* obj = new DBObject; obj->key = property; obj->value = value->toString(); @@ -153,7 +307,40 @@ std::string DatabaseSink::uuid() void DatabaseSink::getPropertyAsync(AsyncPropertyReply *reply) { + reply->success = false; + + if(reply->property == DatabaseFileProperty) + { + StringPropertyType temp(databaseName); + reply->value = &temp; + + reply->success = true; + reply->completed(reply); + + return; + } + else if(reply->property == DatabaseLoggingProperty) + { + BasicPropertyType<bool> temp = shared; + + reply->value = &temp; + reply->success = true; + reply->completed(reply); + return; + } + + else if(reply->property == DatabasePlaybackProperty) + { + BasicPropertyType<bool> temp = playback; + reply->value = &temp; + reply->success = true; + reply->completed(reply); + + return; + } + + reply->completed(reply); } void DatabaseSink::getRangePropertyAsync(AsyncRangePropertyReply *reply) @@ -225,7 +412,44 @@ AsyncPropertyReply *DatabaseSink::setProperty(AsyncSetPropertyRequest request) if(request.value->value<bool>()) { ///TODO: start or stop logging thread + startDb(); + reply->success = true; + BasicPropertyType<bool> temp(true); + routingEngine->updateProperty(DatabaseLoggingProperty,&temp,uuid()); } + else + { + stopDb(); + reply->success = true; + BasicPropertyType<bool> temp(false); + routingEngine->updateProperty(DatabaseLoggingProperty,&temp,uuid()); + } + } + + else if(request.property == DatabaseFileProperty) + { + std::string fname = request.value->toString(); + + databaseName = fname; + + StringPropertyType temp(databaseName); + + routingEngine->updateProperty(DatabaseFileProperty,&temp,uuid()); + + reply->success = true; + } + else if( request.property == DatabasePlaybackProperty) + { + if(request.value->value<bool>()) + { + startPlayback(); + } + else + { + /// TODO: stop playback + } + + reply->success = true; } return reply; diff --git a/plugins/database/databasesink.h b/plugins/database/databasesink.h index c41017cd..7a2607f9 100644 --- a/plugins/database/databasesink.h +++ b/plugins/database/databasesink.h @@ -26,7 +26,11 @@ #include <glib.h> +#include <functional> + #define DatabaseLoggingProperty "DatabaseLogging" +#define DatabasePlaybackProperty "DatabasePlayback" +#define DatabaseFileProperty "DatabaseFile" template <typename T> class Queue @@ -34,25 +38,26 @@ class Queue public: Queue() { - mutex = g_mutex_new(); + g_mutex_init(&mutex); + g_cond_init(&cond); } int count() { - g_mutex_lock(mutex); + g_mutex_lock(&mutex); int ret = mQueue.count(); - g_mutex_unlock(mutex); + g_mutex_unlock(&mutex); return ret; } T pop() { - g_mutex_lock(mutex); + g_mutex_lock(&mutex); while(!mQueue.size()) { - g_cond_wait(&cond, mutex); + g_cond_wait(&cond, &mutex); } auto itr = mQueue.begin(); @@ -61,24 +66,24 @@ public: mQueue.erase(itr); - g_mutex_unlock(mutex); + g_mutex_unlock(&mutex); return item; } void append(T item) { - g_mutex_lock(mutex); + g_mutex_lock(&mutex); g_cond_signal(&cond); mQueue.push_back(item); - g_mutex_unlock(mutex); + g_mutex_unlock(&mutex); } private: - GMutex * mutex; + GMutex mutex; GCond cond; std::vector<T> mQueue; }; @@ -110,6 +115,28 @@ public: Queue<DBObject*> queue; }; +class PlaybackShared +{ +public: + PlaybackShared(AbstractRoutingEngine* re, std::string u) + :routingEngine(re),uuid(u) {} + ~PlaybackShared() + { + for(auto itr = playbackQueue.begin(); itr != playbackQueue.end(); itr++) + { + DBObject* obj = *itr; + + delete obj; + } + + playbackQueue.clear(); + } + + AbstractRoutingEngine* routingEngine; + std::list<DBObject*> playbackQueue; + std::string uuid; +}; + class DatabaseSink : public AbstractSource { @@ -127,11 +154,15 @@ public: virtual void subscribeToPropertyChanges(VehicleProperty::Property property); virtual void unsubscribeToPropertyChanges(VehicleProperty::Property property); virtual PropertyList supported(); - int supportedOperations() { return GetRanged; } + int supportedOperations() { return GetRanged | Get | Set;} private: //methods: void parseConfig(); + void stopDb(); + void startDb(); + void startPlayback(); + void initDb(); private: PropertyList mSubscriptions; @@ -141,6 +172,9 @@ private: std::string tablename; std::string tablecreate; std::list<VehicleProperty::Property> propertiesToSubscribeTo; + PropertyList mSupported; + bool playback; + PlaybackShared* playbackShared; }; class DatabaseSinkManager: public AbstractSinkManager @@ -151,6 +185,8 @@ public: { new DatabaseSink(routingEngine, config); VehicleProperty::registerProperty(DatabaseLoggingProperty, [](){return new BasicPropertyType<bool>(false);}); + VehicleProperty::registerProperty(DatabasePlaybackProperty, [](){return new BasicPropertyType<bool>(false);}); +VehicleProperty::registerProperty(DatabaseFileProperty, [](){return new StringPropertyType("out.ogg");}); } }; diff --git a/plugins/dbus/amb-qt/ambqt.h b/plugins/dbus/amb-qt/ambqt.h index ade3c05a..c406d737 100644 --- a/plugins/dbus/amb-qt/ambqt.h +++ b/plugins/dbus/amb-qt/ambqt.h @@ -19,7 +19,7 @@ class AmbProperty: public QObject Q_OBJECT Q_PROPERTY(QString propertyName READ propertyName WRITE setPropertyName) AUTOPROPERTY(QString, propertyName, PropertyName) - Q_PROPERTY(QVariant value READ value NOTIFY valueChanged) + Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) Q_PROPERTY(QString interfaceName READ interfaceName WRITE setInterfaceName) AUTOPROPERTY(QString, interfaceName, InterfaceName) Q_PROPERTY(QString objectPath READ objectPath WRITE setObjectPath) @@ -35,7 +35,7 @@ class AmbProperty: public QObject { if(!mDBusInterface || !mDBusInterface->isValid()) { - qDebug()<<"error Interface is not valid"; + qDebug()<<"error Interface is not valid: "<<interfaceName(); return QVariant::Invalid; } @@ -44,6 +44,16 @@ class AmbProperty: public QObject return value; } + void setValue(QVariant v) + { + if(!mDBusInterface || !mDBusInterface->isValid()) + { + qDebug()<<"error Interface is not valid "<<interfaceName(); + } + + mDBusInterface->setProperty(propertyName().toAscii(), v); + } + Q_SIGNALS: void propertyChanged(QVariant, double); void valueChanged(QVariant); diff --git a/plugins/dbus/dbusinterfacemanager.cpp b/plugins/dbus/dbusinterfacemanager.cpp index 812df7b8..024ad8ec 100644 --- a/plugins/dbus/dbusinterfacemanager.cpp +++ b/plugins/dbus/dbusinterfacemanager.cpp @@ -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(); diff --git a/plugins/examplesink.cpp b/plugins/examplesink.cpp index 86b3a8d9..9f5ed063 100644 --- a/plugins/examplesink.cpp +++ b/plugins/examplesink.cpp @@ -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 index 00000000..10fe2302 --- /dev/null +++ b/plugins/gpsd/CMakeLists.txt @@ -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 index 00000000..b3432f2a --- /dev/null +++ b/plugins/gpsd/gpsdplugin.cpp @@ -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 index 00000000..7a1004ed --- /dev/null +++ b/plugins/gpsd/gpsdplugin.h @@ -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 diff --git a/plugins/obd2plugin/obd2source.cpp b/plugins/obd2plugin/obd2source.cpp index 66ea0011..582c944f 100644 --- a/plugins/obd2plugin/obd2source.cpp +++ b/plugins/obd2plugin/obd2source.cpp @@ -76,7 +76,7 @@ std::string reply; { //No reply found //printf("Error!\n"); - DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Error resetting ELM\n"; + DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Error resetting ELM"<<endl; } else { diff --git a/plugins/opencvlux/README b/plugins/opencvlux/README index e118bd7b..76cad19d 100644 --- a/plugins/opencvlux/README +++ b/plugins/opencvlux/README @@ -38,7 +38,8 @@ Camera to use. The string "0" corrisponds to /dev/video0, "1" to /dev/video1, e Default: "0" "threaded" -Compute pixel intensity in another thread. Set to "true" or "false" +Compute pixel intensity in another thread. Set to "true" or "false". This feature has been disabled +for now. Default: "false" diff --git a/plugins/opencvlux/opencvluxplugin.h b/plugins/opencvlux/opencvluxplugin.h index 30c84b63..0955ad9f 100644 --- a/plugins/opencvlux/opencvluxplugin.h +++ b/plugins/opencvlux/opencvluxplugin.h @@ -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> diff --git a/plugins/websocketsink/CMakeLists.txt b/plugins/websocketsink/CMakeLists.txt index 5fc4eb86..c2e26a0b 100644 --- a/plugins/websocketsink/CMakeLists.txt +++ b/plugins/websocketsink/CMakeLists.txt @@ -1,18 +1,12 @@ include(CheckIncludeFiles) include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs}) -find_library(websockets_LIBRARY websockets DOC "libwebsockets") - -if(websockets_LIBRARY) - message(STATUS "libwebsockets found") -else(websockets_LIBRARY) - message(FATAL_ERROR "libwebsockets not found. please install libwebsockets") -endif(websockets_LIBRARY) +pkg_check_modules(websockets REQUIRED libwebsockets) set(websocketsinkplugin_headers websocketsink.h websocketmanager.h) set(websocketsinkplugin_sources websocketsinkmanager.cpp websocketsink.cpp) add_library(websocketsinkplugin MODULE ${websocketsinkplugin_sources}) set_target_properties(websocketsinkplugin PROPERTIES PREFIX "") -target_link_libraries(websocketsinkplugin amb ${websockets_LIBRARY} -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries}) +target_link_libraries(websocketsinkplugin amb ${websockets_LIBRARIES} -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries}) install(TARGETS websocketsinkplugin LIBRARY DESTINATION lib/automotive-message-broker) |