From: Kevron Rees Date: Tue, 9 Sep 2014 22:19:23 +0000 (-0700) Subject: fixes for bluemonkey and wheel X-Git-Tag: 0.12.903~118 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c35dda01cb680efc95b62f8fd4290df3a6478c1a;p=profile%2Fivi%2Fautomotive-message-broker.git fixes for bluemonkey and wheel --- diff --git a/TODO b/TODO index 95f7c7f..35687bc 100644 --- a/TODO +++ b/TODO @@ -1,10 +1,6 @@ -For 0.12 +- Refactor obd2 plugin with AsyncQueue. Use thread safe-update property. - Rewrite websocket test html - - -For 0.11 - - Implement all the DBus properties in the docs/ directory. - update json protocol to include getPropertyInfo calls - update json protocol to support rangerequests with PropertyList instead of a signel property (Verify) @@ -15,17 +11,6 @@ For 0.11 - create docs for all plugins (README) - handle badly formed messages properly (ie not crash) in websocketsink - GetHistory must filter on source - -Completed: - -- DBus support for time and sequece being an additional api call (ie, getVehicleSpeed()). - DONE -- DBus support for objects with multiple sources and multiple 'zones' (/${sourceID}/[${zone}/]batteryVoltage) - DONE -- Document changes to the DBus API in the IDL - DONE -- add API to get number of sources per a given property (ie uint AbstractRoutingEngine::getSourcesForProperty(VehicleProperty::Property)) - DONE -- per-source property filtering in routing engine - DONE - - -Other: - grep all the TODOs in the code and do them - improve obd2source speed via Physical Addressing (see https://www.scantool.net/forum/index.php?topic=6661.msg25024#msg25024) - investigate and enable use of provisioning in ssl websockets diff --git a/lib/abstractpropertytype.h b/lib/abstractpropertytype.h index f68bfca..c22d2ff 100644 --- a/lib/abstractpropertytype.h +++ b/lib/abstractpropertytype.h @@ -368,20 +368,6 @@ public: setValue(basicValue() - 1); } - BasicPropertyType operator ++ (int) - { - BasicPropertyType temp = *this; - temp.setValue(basicValue() + 1); - return temp; - } - - BasicPropertyType operator -- (int) - { - BasicPropertyType temp = *this; - temp.setValue(basicValue() - 1); - return temp; - } - bool operator < (const BasicPropertyType& other) const { return value() < other.value(); diff --git a/lib/vehicleproperty.h b/lib/vehicleproperty.h index b2cfa81..3c5b97d 100644 --- a/lib/vehicleproperty.h +++ b/lib/vehicleproperty.h @@ -420,7 +420,6 @@ public: */ static const Property SteeringWheelAngle; PROPERTYTYPE(SteeringWheelAngle, SteeringWheelAngleType, BasicPropertyType, uint16_t) - //typedef BasicPropertyType SteeringWheelAngleType; /// TODO: Rename to "SteeringWheel" in 0.13 static const Property SteeringWheelAngleW3C; @@ -429,22 +428,18 @@ public: /**< 0=off, 1=right, 2=left, 3=hazard */ static const Property TurnSignal; PROPERTYTYPEBASIC(TurnSignal, TurnSignals::TurnSignalType) - //typedef BasicPropertyType TurnSignalType; /**< Clutch pedal status 0=off, 1=on */ static const Property ClutchStatus; PROPERTYTYPE(ClutchStatus, ClutchStatusType,BasicPropertyType,bool) - //typedef BasicPropertyType ClutchStatusType; /**< Oil pressure TODO: units */ static const Property EngineOilPressure; - PROPERTYTYPE(EngineOilPressure, EngineOilPressureType,BasicPropertyType, uint16_t) - //typedef BasicPropertyType EngineOilPressureType; + PROPERTYTYPE(EngineOilPressure, EngineOilPressureType, BasicPropertyType, uint16_t) /**< Engine coolant temperature in degrees celcius **/ static const Property EngineCoolantTemperature; PROPERTYTYPE(EngineCoolantTemperature, EngineCoolantTemperatureType, BasicPropertyType, int) - //typedef BasicPropertyType EngineCoolantTemperatureType; static const Property EngineCoolantLevel; PROPERTYTYPE(EngineCoolantLevel, EngineCoolantLevelType, BasicPropertyType, uint) @@ -452,12 +447,10 @@ public: /**< 0=off, 1=on */ static const Property MachineGunTurretStatus; PROPERTYTYPEBASIC(MachineGunTurretStatus, bool) - //typedef BasicPropertyType MachineGunTurretStatusType; /**< Acceleration on the 'x' axis in 1/1000 gravitational acceleration "g-force" */ static const Property AccelerationX; PROPERTYTYPE(AccelerationX, AccelerationXType, BasicPropertyType, uint16_t) - //typedef BasicPropertyType AccelerationType; /**< Acceleration on the 'y' axis in 1/1000 gravitational acceleration "g-force" */ static const Property AccelerationY; diff --git a/plugins/bluemonkey/bluemonkey.cpp b/plugins/bluemonkey/bluemonkey.cpp index 4e577bb..5ff5689 100644 --- a/plugins/bluemonkey/bluemonkey.cpp +++ b/plugins/bluemonkey/bluemonkey.cpp @@ -382,7 +382,7 @@ void Property::setValue(QVariant v) { if(reply->success) { - propertyChanged(reply->property, reply->value, reply->value->sourceUuid); + propertyChanged(reply->value); } delete reply; }; @@ -444,9 +444,9 @@ QString Property::type() void Property::setType(QString t) { if(mValue && type() != "") - routingEngine->unsubscribeToProperty(type().toStdString(),this); + routingEngine->unsubscribeToProperty(type().toStdString(), this); - routingEngine->subscribeToProperty(t.toStdString(),this); + routingEngine->subscribeToProperty(t.toStdString(), this); mValue = VehicleProperty::getPropertyTypeForPropertyNameValue(t.toStdString()); @@ -458,7 +458,7 @@ void Property::setType(QString t) request.completed = [this](AsyncPropertyReply* reply) { if(reply->success) - propertyChanged(reply->property, reply->value,uuid()); + propertyChanged(reply->value); delete reply; }; @@ -466,7 +466,7 @@ void Property::setType(QString t) routingEngine->getPropertyAsync(request); } -void Property::propertyChanged(VehicleProperty::Property property, AbstractPropertyType *value, string uuid) +void Property::propertyChanged(AbstractPropertyType *value) { if(mValue) { diff --git a/plugins/bluemonkey/bluemonkey.h b/plugins/bluemonkey/bluemonkey.h index e67814c..a9fd240 100644 --- a/plugins/bluemonkey/bluemonkey.h +++ b/plugins/bluemonkey/bluemonkey.h @@ -54,7 +54,7 @@ public: DebugOut()<<"Bluemonkey Property Supported Changed"<message <message << endl; + } + }, nullptr); } diff --git a/plugins/common/bluetooth5.h b/plugins/common/bluetooth5.h index 52170db..0b479c3 100644 --- a/plugins/common/bluetooth5.h +++ b/plugins/common/bluetooth5.h @@ -11,13 +11,18 @@ class Bluetooth5 public: Bluetooth5(); + bool setDevice(std::string address); void getDeviceForAddress(std::string address, ConnectedCallback onnectedCallback); - void disconnect(std::string address, std::string adapterAddy = ""); void connected(int fd); + void connect( ConnectedCallback onconnectedCallback); + void disconnect(); + + private: ConnectedCallback mConnected; + std::string mPath; }; #endif diff --git a/plugins/obd2plugin/obd2source.cpp b/plugins/obd2plugin/obd2source.cpp index 3253c15..aa585b5 100644 --- a/plugins/obd2plugin/obd2source.cpp +++ b/plugins/obd2plugin/obd2source.cpp @@ -28,6 +28,12 @@ #include "debugout.h" #include "bluetooth.hpp" #include "timestamp.h" +#include "bluetooth5.h" +#include "superptr.hpp" + +#ifdef USE_BLUEZ5 +Bluetooth5 bt; +#endif #define __SMALLFILE__ std::string(__FILE__).substr(std::string(__FILE__).rfind("/")+1) AbstractRoutingEngine *m_re; @@ -39,7 +45,7 @@ int calledPersecond = 0; bool sendElmCommand(obdLib *obd,std::string command) { - std::vector replyVector; + std::vector replyVector; std::string reply; obd->sendObdRequestString(command.append("\r").c_str(),command.length()+1,&replyVector,10,3); for (unsigned int i=0;iopenPort(fd,baud) == -1) + if(obd->openPort(fd, baud) == -1) return false; } else @@ -123,7 +129,7 @@ bool connect(obdLib* obd, std::string device, std::string strbaud, int fd = -1) DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Error turning off linefeeds"<sendObdRequestString("010C1\r",6,&replyVector,500,5); + obd->sendObdRequestString("010C1\r", 6, &replyVector, 500, 5); return true; } @@ -136,17 +142,16 @@ void threadLoop(gpointer data) GAsyncQueue *privSubscriptionAddQueue = g_async_queue_ref(((OBD2Source*)data)->subscriptionAddQueue); GAsyncQueue *privSubscriptionRemoveQueue = g_async_queue_ref(((OBD2Source*)data)->subscriptionRemoveQueue); GAsyncQueue *privStatusQueue = g_async_queue_ref(((OBD2Source*)data)->statusQueue); - + obdLib *obd = new obdLib(); OBD2Source *source = (OBD2Source*)data; obd->setCommsCallback([](const char* mssg, void* data) { DebugOut(6)<setDebugCallback([](const char* mssg, void* data, obdLib::DebugLevel debugLevel) { DebugOut(debugLevel)< reqList; std::list repeatReqList; ObdPid::ByteArray replyVector; - std::string reply; std::string port; std::string baud; bool connected=false; @@ -154,14 +159,11 @@ void threadLoop(gpointer data) int timeoutCount = 0; while (source->m_threadLive) { - //gpointer query = g_async_queue_pop(privCommandQueue); - - gpointer query = g_async_queue_try_pop(privSingleShotQueue); if (query != nullptr) { //printf("Got request!\n"); - + ObdPid *req = (ObdPid*)query; DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Got single shot request: " << req->pid.substr(0,req->pid.length()-1) << ":" << req->property <req] = req->arg; //printf("Command: %s\n",req->req.c_str()); DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Command:" << req->req << endl; - if (req->req == "connect" ) - { - - if (source->m_isBluetooth) - { - - BluetoothDevice bt; - std::string tempPort = bt.getDeviceForAddress(source->m_btDeviceAddress, source->m_btAdapterAddress); - if(tempPort != "") - { - DebugOut(3)<<"Using bluetooth device \""<m_btDeviceAddress<<"\" bound to: "<arglist[0]; - baud = req->arglist[1]; - } - connected = connect(obd,port,baud); - - if(connected) - { - StatusMessage *statusreq = new StatusMessage(); - statusreq->statusStr = "connected"; - g_async_queue_push(privStatusQueue,statusreq); - } - else - { - StatusMessage *statusreq = new StatusMessage(); - statusreq->statusStr = "disconnected"; - g_async_queue_push(privStatusQueue,statusreq); - } - - } - else if (req->req == "connectifnot") + if (req->req == "connectifnot") { if (!connected) { if (source->m_isBluetooth) { +#ifdef USE_BLUEZ5 + bt.getDeviceForAddress(source->m_btDeviceAddress, [&obd, baud, &privStatusQueue](int fd) + { + bool connected = connect(obd, "", baud, fd); + + if(connected) + { + StatusMessage *statusreq = new StatusMessage(); + statusreq->statusStr = "connected"; + g_async_queue_push(privStatusQueue, statusreq); + } + else + { + StatusMessage *statusreq = new StatusMessage(); + statusreq->statusStr = "disconnected"; + g_async_queue_push(privStatusQueue, statusreq); + } + }); +#else BluetoothDevice bt; std::string tempPort = bt.getDeviceForAddress(source->m_btDeviceAddress, source->m_btAdapterAddress); if(tempPort != "") { - DebugOut(3)<<"Using bluetooth device \""<m_btDeviceAddress<<"\" bound to: "<m_btDeviceAddress << "\" bound to: " << tempPort << endl; port = tempPort; } else { - DebugOut(DebugOut::Error)<<"Error creating bluetooth device"<statusStr = "connected"; - g_async_queue_push(privStatusQueue,statusreq); + if(connected) + { + StatusMessage *statusreq = new StatusMessage(); + statusreq->statusStr = "connected"; + g_async_queue_push(privStatusQueue, statusreq); + } + else + { + StatusMessage *statusreq = new StatusMessage(); + statusreq->statusStr = "disconnected"; + g_async_queue_push(privStatusQueue, statusreq); + } + +#endif } else { - StatusMessage *statusreq = new StatusMessage(); - statusreq->statusStr = "disconnected"; - g_async_queue_push(privStatusQueue,statusreq); + + connected = connect(obd, port, baud); + + if(connected) + { + StatusMessage *statusreq = new StatusMessage(); + statusreq->statusStr = "connected"; + g_async_queue_push(privStatusQueue, statusreq); + } + else + { + StatusMessage *statusreq = new StatusMessage(); + statusreq->statusStr = "disconnected"; + g_async_queue_push(privStatusQueue, statusreq); + } } } } @@ -262,8 +268,12 @@ void threadLoop(gpointer data) { DebugOut() << __SMALLFILE__ << ":" << __LINE__ << "Using queued disconnect" << (ulong)req << endl; obd->closePort(); +#ifdef USE_BLUEZ5 + bt.disconnect(); +#else BluetoothDevice bt; bt.disconnect(source->m_btDeviceAddress, source->m_btAdapterAddress); +#endif connected = false; StatusMessage *statusreq = new StatusMessage(); statusreq->statusStr = "disconnected"; @@ -360,7 +370,7 @@ void threadLoop(gpointer data) int count = (*source->m_blacklistPidCountMap.find((*i)->pid)).second; if (count > 10) { - + } source->m_blacklistPidCountMap.erase(source->m_blacklistPidCountMap.find((*i)->pid)); source->m_blacklistPidCountMap.insert(pair((*i)->pid,count)); @@ -391,7 +401,7 @@ void threadLoop(gpointer data) { DebugOut() << __SMALLFILE__ << ":" << __LINE__ << "OBD Other error:" << obd->lastError() << endl; } - + CommandRequest *req = new CommandRequest(); DebugOut() << __SMALLFILE__ << ":" << __LINE__ << "Queuing up a disconnect" << (ulong)req << endl; req->req = "disconnect"; @@ -436,7 +446,7 @@ void threadLoop(gpointer data) //usleep(10000); } repeatReqList.clear(); - + } if (connected) { @@ -447,19 +457,20 @@ static int updateProperties( gpointer data) { OBD2Source* src = (OBD2Source*)data; - + while (gpointer retval = g_async_queue_try_pop(src->statusQueue)) { StatusMessage *reply = (StatusMessage*)retval; if (reply->statusStr == "disconnected") { OBD2Source::Obd2ConnectType val(Obd2Connected,false); - src->updateProperty(Obd2Connected,&val); + src->updateProperty(&val); } else if (reply->statusStr == "connected") { OBD2Source::Obd2ConnectType val(Obd2Connected, true); - src->updateProperty(Obd2Connected,&val); + val.priority = OBD2Source::Obd2ConnectType::Instant; + src->updateProperty(&val); } else if (reply->statusStr == "error:nodata" || reply->statusStr == "error:timeout") { @@ -487,20 +498,20 @@ static int updateProperties( gpointer data) { ObdPid *reply = (ObdPid*)retval; - - AbstractPropertyType* value = VehicleProperty::getPropertyTypeForPropertyNameValue(reply->property, reply->value); - src->updateProperty(reply->property, value); - delete value; + auto value = amb::make_unique(VehicleProperty::getPropertyTypeForPropertyNameValue(reply->property, reply->value)); + value->priority = AbstractPropertyType::Instant; + src->updateProperty(value.get()); } return true; } -void OBD2Source::updateProperty(VehicleProperty::Property property,AbstractPropertyType* value) +void OBD2Source::updateProperty(AbstractPropertyType* value) { + VehicleProperty::Property property = value->name; if(property == Obd2Connected) obd2Connected.setValue(value->anyValue()); - + if (propertyReplyMap.find(property) != propertyReplyMap.end()) { propertyReplyMap[property]->value = value; @@ -549,13 +560,13 @@ void OBD2Source::setConfiguration(map config) { // //Config has been passed, let's start stuff up. configuration = config; - + //Default values std::string port = "/dev/ttyUSB0"; std::string baud = "115200"; std::string btadapter = ""; m_isBluetooth = false; - + //Try to load config //printf("OBD2Source::setConfiguration\n"); for (map::iterator i=configuration.begin();i!=configuration.end();i++) @@ -607,7 +618,7 @@ void OBD2Source::setConfiguration(map config) req->arglist.push_back(port); req->arglist.push_back(baud); g_async_queue_push(commandQueue,req); - + m_port = port; m_baud = baud; m_gThread = g_thread_new("mythread",(GThreadFunc)&threadLoop,this); @@ -626,7 +637,7 @@ OBD2Source::OBD2Source(AbstractRoutingEngine *re, map config) } clientConnected = false; - m_re = re; + m_re = re; m_threadLive = true; Obd2Amb obd2amb; @@ -670,7 +681,7 @@ int OBD2Source::supportedOperations() extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map config) { return new OBD2Source(routingengine, config); - + } const string OBD2Source::uuid() { @@ -699,18 +710,19 @@ void OBD2Source::subscribeToPropertyChanges(VehicleProperty::Property property) if(!pid) { + DebugOut(DebugOut::Warning) << "We don't support this property: " << property <pid) != m_blacklistPidCountMap.end()) { m_blacklistPidCountMap.erase(m_blacklistPidCountMap.find(pid->pid)); } - - - g_async_queue_push(subscriptionAddQueue,pid); + + + g_async_queue_push(subscriptionAddQueue, pid); CommandRequest *req = new CommandRequest(); req->req = "connectifnot"; g_async_queue_push(commandQueue,req); diff --git a/plugins/obd2plugin/obd2source.h b/plugins/obd2plugin/obd2source.h index 6b20e30..d93f1b4 100644 --- a/plugins/obd2plugin/obd2source.h +++ b/plugins/obd2plugin/obd2source.h @@ -114,7 +114,7 @@ public: { continue; } - + ObdPid* pid = (*itr)->create(); return pid; } @@ -181,7 +181,7 @@ public: std::string m_btDeviceAddress; std::string m_btAdapterAddress; map propertyReplyMap; - void updateProperty(VehicleProperty::Property property,AbstractPropertyType *value); + void updateProperty(AbstractPropertyType *value); obdLib * obd; bool m_threadLive; GThread *m_gThread; diff --git a/plugins/wheel/wheelplugin.cpp b/plugins/wheel/wheelplugin.cpp index e8cb142..f6ebdbb 100644 --- a/plugins/wheel/wheelplugin.cpp +++ b/plugins/wheel/wheelplugin.cpp @@ -517,7 +517,11 @@ void WheelPrivate::changeGear(int gear) void WheelPrivate::changeOilPressure(bool increase) { - (increase ? *(oilPSI)++ : *(oilPSI)--); + if(increase) + oilPSI->setValue(oilPSI->basicValue()+1); + else if(oilPSI->basicValue() > 0) + oilPSI->setValue(oilPSI->basicValue()-1); + this->re->updateProperty(oilPSI, mParent->uuid()); }