diff options
author | Kevron Rees <kevron.m.rees@intel.com> | 2014-12-22 13:23:54 -0800 |
---|---|---|
committer | Kevron Rees <kevron.m.rees@intel.com> | 2014-12-22 13:23:54 -0800 |
commit | bbbf257a0c9c8449250804b6a805f6d41750f7ea (patch) | |
tree | e3d8c2dcfe6e4f6475c27b0553310cc8c954a1f1 | |
parent | 2e2ff7dbe832911bf2843da5b4d3d7598d82341d (diff) | |
download | automotive-message-broker-bbbf257a0c9c8449250804b6a805f6d41750f7ea.tar.gz |
fixed database and obd2
-rw-r--r-- | plugins/database/CMakeLists.txt | 2 | ||||
-rw-r--r-- | plugins/database/databasesink.cpp | 123 | ||||
-rw-r--r-- | plugins/database/databasesink.h | 16 | ||||
-rw-r--r-- | plugins/obd2plugin/obd2source.cpp | 6 | ||||
-rw-r--r-- | plugins/obd2plugin/obdlib.cpp | 4 | ||||
-rw-r--r-- | plugins/obd2plugin/obdpid.h | 4 | ||||
-rw-r--r-- | plugins/opencvlux/README | 1 |
7 files changed, 37 insertions, 119 deletions
diff --git a/plugins/database/CMakeLists.txt b/plugins/database/CMakeLists.txt index 4d94b89c..8f977d25 100644 --- a/plugins/database/CMakeLists.txt +++ b/plugins/database/CMakeLists.txt @@ -14,4 +14,6 @@ target_link_libraries(databasesinkplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib $ install(TARGETS databasesinkplugin LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/README ${CMAKE_CURRENT_SOURCE_DIR}/README @ONLY) + endif(database_plugin) diff --git a/plugins/database/databasesink.cpp b/plugins/database/databasesink.cpp index 08964308..f7ed7cf7 100644 --- a/plugins/database/databasesink.cpp +++ b/plugins/database/databasesink.cpp @@ -18,7 +18,7 @@ extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<str return plugin; } -void * cbFunc(Shared* shared) +static void * cbFunc(Shared* shared) { if(!shared) { @@ -139,13 +139,12 @@ int getNextEvent(gpointer data) DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, map<std::string, std::string> config, AbstractSource &parent) :AmbPluginImpl(engine, config, parent), shared(nullptr), playback(false), playbackShared(nullptr), playbackMultiplier(1) { - databaseName = "storage"; tablename = "data"; tablecreate = "CREATE TABLE IF NOT EXISTS data (key TEXT, value BLOB, source TEXT, zone INTEGER, time REAL, sequence REAL, tripId TEXT)"; if(config.find("bufferLength") != config.end()) { - bufferLength = atoi(config["bufferLength"].c_str()); + bufferLength = boost::lexical_cast<int>(config["bufferLength"]); } if(config.find("frequency") != config.end()) @@ -158,8 +157,6 @@ DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, map<std::string, std:: { DebugOut(DebugOut::Error)<<"Failed to parse frequency: Invalid value "<<config["frequency"]<<endl; } - - } if(config.find("properties") != config.end()) @@ -172,13 +169,13 @@ DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, map<std::string, std:: engine->subscribeToProperty(itr, &parent); } - addPropertySupport(Zone::None, [](){ return new DatabaseFileType("storage"); }); - addPropertySupport(Zone::None, [](){ return new DatabasePlaybackType(false); }); - addPropertySupport(Zone::None, [](){ return new DatabaseLoggingType(false); }); + databaseName = addPropertySupport(Zone::None, [](){ return new DatabaseFileType("storage"); }); + playback = addPropertySupport(Zone::None, [](){ return new DatabasePlaybackType(false); }); + databaseLogging = addPropertySupport(Zone::None, [](){ return new DatabaseLoggingType(false); }); if(config.find("startOnLoad")!= config.end()) { - setLogging(config["startOnLoad"] == "true"); + databaseLogging->setValue(config["startOnLoad"] == "true"); } if(config.find("playbackMultiplier")!= config.end()) @@ -188,7 +185,7 @@ DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, map<std::string, std:: if(config.find("playbackOnLoad")!= config.end()) { - setPlayback(config["playbackOnLoad"] == "true"); + playback->setValue(config["playbackOnLoad"] == "true"); } } @@ -257,7 +254,8 @@ void DatabaseSink::stopDb() obj.quit = true; shared->queue.append(obj); - thread.join(); + if(thread && thread->joinable()) + thread->join(); delete shared; shared = NULL; @@ -265,7 +263,7 @@ void DatabaseSink::stopDb() void DatabaseSink::startDb() { - if(playback.basicValue()) + if(playback->value<bool>()) { DebugOut(0)<<"ERROR: tried to start logging during playback. Only logging or playback can be used at one time"<<endl; return; @@ -279,15 +277,18 @@ void DatabaseSink::startDb() initDb(); - thread = std::thread(cbFunc, shared); + if(thread && thread->joinable()) + thread->detach(); + + thread = amb::make_unique(new std::thread(cbFunc, shared)); } void DatabaseSink::startPlayback() { - if(playback.basicValue()) + if(playback->value<bool>()) return; - playback = true; + playback->setValue(true); initDb(); @@ -333,35 +334,14 @@ void DatabaseSink::initDb() if(shared) delete shared; shared = new Shared; - shared->db->init(databaseName.value<std::string>(), tablename, tablecreate); -} - -void DatabaseSink::setPlayback(bool v) -{ - AsyncSetPropertyRequest request; - request.property = DatabasePlayback; - request.value = new DatabasePlaybackType(v); - - setProperty(request); -} - -void DatabaseSink::setLogging(bool b) -{ - databaseLogging = b; - AsyncSetPropertyRequest request; - request.property = DatabaseLogging; - request.value = &databaseLogging; - - setProperty(request); + shared->db->init(databaseName->value<std::string>(), tablename, tablecreate); } void DatabaseSink::setDatabaseFileName(string filename) { - databaseName = filename; - initDb(); - vector<vector<string> > supportedStr = shared->db->select("SELECT DISTINCT key, zone FROM "+tablename); + vector<vector<string> > supportedStr = shared->db->select("SELECT DISTINCT key, zone FROM " + tablename); for(int i=0; i < supportedStr.size(); i++) { @@ -418,54 +398,17 @@ void DatabaseSink::init() { if(configuration.find("databaseFile") != configuration.end()) { + databaseName->setValue(configuration["databaseFile"]); setDatabaseFileName(configuration["databaseFile"]); } routingEngine->updateSupported(supported(), PropertyList(), &source); } -void DatabaseSink::getPropertyAsync(AsyncPropertyReply *reply) -{ - reply->success = false; - - if(reply->property == DatabaseFile) - { - DatabaseFileType temp(databaseName); - reply->value = &temp; - - reply->success = true; - reply->completed(reply); - - return; - } - else if(reply->property == DatabaseLogging) - { - databaseLogging = shared != nullptr; - - reply->value = &databaseLogging; - reply->success = true; - reply->completed(reply); - - return; - } - - else if(reply->property == DatabasePlayback) - { - DatabasePlaybackType temp = playback; - reply->value = &temp; - reply->success = true; - reply->completed(reply); - - return; - } - - reply->completed(reply); -} - void DatabaseSink::getRangePropertyAsync(AsyncRangePropertyReply *reply) { BaseDB * db = new BaseDB(); - db->init(databaseName.value<std::string>(), tablename, tablecreate); + db->init(databaseName->value<std::string>(), tablename, tablecreate); ostringstream query; query.precision(15); @@ -532,46 +475,28 @@ void DatabaseSink::getRangePropertyAsync(AsyncRangePropertyReply *reply) AsyncPropertyReply *DatabaseSink::setProperty(AsyncSetPropertyRequest request) { - AsyncPropertyReply* reply = new AsyncPropertyReply(request); - reply->success = false; + AsyncPropertyReply* reply = AmbPluginImpl::setProperty(request); if(request.property == DatabaseLogging) { if(request.value->value<bool>()) { - setPlayback(false); startDb(); - reply->success = true; - databaseLogging = true; - routingEngine->updateProperty(&databaseLogging,uuid()); } else { stopDb(); - reply->success = true; - databaseLogging = false; - routingEngine->updateProperty(&databaseLogging,uuid()); } } - else if(request.property == DatabaseFile) { - std::string fname = request.value->toString(); - - databaseName = fname; - - routingEngine->updateProperty(&databaseName,uuid()); - - reply->success = true; + setDatabaseFileName(databaseName->value<std::string>()); } else if( request.property == DatabasePlayback) { if(request.value->value<bool>()) { - setLogging(false); startPlayback(); - - routingEngine->updateProperty(&playback,uuid()); } else { @@ -579,11 +504,7 @@ AsyncPropertyReply *DatabaseSink::setProperty(AsyncSetPropertyRequest request) playbackShared->stop = true; playback = false; - - routingEngine->updateProperty(&playback,uuid()); } - - reply->success = true; } return reply; diff --git a/plugins/database/databasesink.h b/plugins/database/databasesink.h index 930b4d06..2e9709d9 100644 --- a/plugins/database/databasesink.h +++ b/plugins/database/databasesink.h @@ -150,7 +150,6 @@ public: void init(); ///source role: - virtual void getPropertyAsync(AsyncPropertyReply *reply); virtual void getRangePropertyAsync(AsyncRangePropertyReply *reply); virtual AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request); virtual void subscribeToPropertyChanges(VehicleProperty::Property property); @@ -164,23 +163,20 @@ private: //methods: void startDb(); void startPlayback(); void initDb(); - void setPlayback(bool v); - void setLogging(bool b); - void setDatabaseFileName(std::string filename); + void setDatabaseFileName(std::string filename); private: PropertyList mSubscriptions; Shared *shared; - std::thread thread; - //std::string databaseName; + std::unique_ptr<std::thread> thread; std::string tablename; std::string tablecreate; - std::list<VehicleProperty::Property> propertiesToSubscribeTo; + PropertyList propertiesToSubscribeTo; PlaybackShared* playbackShared; uint playbackMultiplier; - DatabasePlaybackType playback; - DatabaseFileType databaseName; - DatabaseLoggingType databaseLogging; + std::shared_ptr<AbstractPropertyType> playback; + std::shared_ptr<AbstractPropertyType> databaseName; + std::shared_ptr<AbstractPropertyType> databaseLogging; }; #endif // DATABASESINK_H diff --git a/plugins/obd2plugin/obd2source.cpp b/plugins/obd2plugin/obd2source.cpp index 0251958e..4aa6b7ba 100644 --- a/plugins/obd2plugin/obd2source.cpp +++ b/plugins/obd2plugin/obd2source.cpp @@ -741,7 +741,7 @@ void OBD2Source::subscribeToPropertyChanges(VehicleProperty::Property property) g_async_queue_push(subscriptionAddQueue, pid); CommandRequest *req = new CommandRequest(); req->req = "connectifnot"; - g_async_queue_push(commandQueue,req); + g_async_queue_push(commandQueue, req); } } @@ -807,13 +807,13 @@ AsyncPropertyReply *OBD2Source::setProperty(AsyncSetPropertyRequest request ) { CommandRequest *req = new CommandRequest(); req->req = "connectifnot"; - g_async_queue_push(commandQueue,req); + g_async_queue_push(commandQueue, req); } else { CommandRequest *req = new CommandRequest(); req->req = "disconnect"; - g_async_queue_push(commandQueue,req); + g_async_queue_push(commandQueue, req); } } diff --git a/plugins/obd2plugin/obdlib.cpp b/plugins/obd2plugin/obdlib.cpp index 3a1e9ec0..e223ea10 100644 --- a/plugins/obd2plugin/obdlib.cpp +++ b/plugins/obd2plugin/obdlib.cpp @@ -58,7 +58,7 @@ int obdLib::openPort(const int fd, int baudrate) //struct termios oldtio;
struct termios newtio;
//bzero(&newtio,sizeof(newtio));
- tcgetattr(portHandle,&newtio);
+ tcgetattr(portHandle, &newtio);
long BAUD = B9600;
switch (baudrate)
{
@@ -107,7 +107,7 @@ int obdLib::openPort(const int fd, int baudrate) debug(obdLib::DEBUG_VERBOSE,"Setting baud rate to %i\n",baudrate);
}
fcntl(portHandle, F_SETFL, 0); //Set to blocking
- tcsetattr(portHandle,TCSANOW,&newtio);
+ tcsetattr(portHandle, TCSANOW, &newtio);
return 0;
}
diff --git a/plugins/obd2plugin/obdpid.h b/plugins/obd2plugin/obdpid.h index 12eb20ca..20db314a 100644 --- a/plugins/obd2plugin/obdpid.h +++ b/plugins/obd2plugin/obdpid.h @@ -33,9 +33,9 @@ public: static ByteArray compress(ByteArray replyVector) { ByteArray tmp; - for (int i=0;i<replyVector.size();i++) + for (int i=0;i<replyVector.size()-1;i++) { - tmp.push_back(obdLib::byteArrayToByte(replyVector[i],replyVector[i+1])); + tmp.push_back(obdLib::byteArrayToByte(replyVector[i], replyVector[i+1])); i++; } return tmp; diff --git a/plugins/opencvlux/README b/plugins/opencvlux/README index d182c32d..3dcb32ba 100644 --- a/plugins/opencvlux/README +++ b/plugins/opencvlux/README @@ -1,5 +1,4 @@ OpenCV "lux" plugin -Version: @PROJECT_VERSION@ This plugin simulates the ExteriorBrigtness property using a traditional webcamera. It works by taking the mean pixel intensity of the web camera image and estimating lux. The particular |