summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevron Rees <tripzero.kev@gmail.com>2014-10-20 08:17:54 -0700
committerKevron Rees <tripzero.kev@gmail.com>2014-10-20 08:17:54 -0700
commit94b3fe8f0e7aefc905fb157efba7bd1b8e12ec44 (patch)
treefbb166938c3acb11a5c1f953af158430a49867c3
parentdd8c4aa58c18868fba3c0864100a30419ff766cb (diff)
parent386768a44f2213bc49d2c3f2f57e40efe0776976 (diff)
downloadautomotive-message-broker-94b3fe8f0e7aefc905fb157efba7bd1b8e12ec44.tar.gz
Merge pull request #25 from tripzero/0.120.11.904
update to docs, deleted callback, obd2 disconnect bug
-rw-r--r--ambd/core.cpp18
-rw-r--r--examples/bluemonkey/bluemonkeyconfig18
-rw-r--r--examples/bluemonkey/bluemonkeyconfig.in6
-rw-r--r--lib/abstractpropertytype.h100
-rw-r--r--lib/asyncqueue.hpp7
-rw-r--r--plugins/dbus/dbusplugin.cpp3
-rw-r--r--plugins/dbus/environmentproperties.h4
-rw-r--r--plugins/dbus/maintenance.h2
-rw-r--r--plugins/dbus/varianttype.cpp4
-rw-r--r--plugins/obd2plugin/obd2source.cpp9
-rw-r--r--plugins/obd2plugin/obd2source.h3
-rw-r--r--plugins/wheel/wheelplugin.cpp7
12 files changed, 129 insertions, 52 deletions
diff --git a/ambd/core.cpp b/ambd/core.cpp
index 9911cc10..277ba5a6 100644
--- a/ambd/core.cpp
+++ b/ambd/core.cpp
@@ -157,11 +157,29 @@ void Core::updateProperty(AbstractPropertyType *value, const string & uuid)
if(value->priority == AbstractPropertyType::Instant)
updateProperty(value);
else if(value->priority == AbstractPropertyType::High)
+ {
+ value->destroyed.push_back([this](AbstractPropertyType* v)
+ {
+ updatePropertyQueueHigh.remove(v);
+ });
updatePropertyQueueHigh.append(value);
+ }
else if(value->priority == AbstractPropertyType::Normal)
+ {
+ value->destroyed.push_back([this](AbstractPropertyType* v)
+ {
+ updatePropertyQueue.remove(v);
+ });
updatePropertyQueue.append(value);
+ }
else if(value->priority == AbstractPropertyType::Low)
+ {
+ value->destroyed.push_back([this](AbstractPropertyType* v)
+ {
+ updatePropertyQueueLow.remove(v);
+ });
updatePropertyQueueLow.append(value);
+ }
}
void Core::updateProperty(AbstractPropertyType * value)
diff --git a/examples/bluemonkey/bluemonkeyconfig b/examples/bluemonkey/bluemonkeyconfig
deleted file mode 100644
index fb0080c8..00000000
--- a/examples/bluemonkey/bluemonkeyconfig
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "mainloop" : "/usr/lib/i386-linux-gnu/automotive-message-broker/automotive-message-broker/qtmainloopplugin.so",
-
- "sources" : [
- {
- "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/automotive-message-broker/bluemonkeyplugin.so",
- "config" : "/etc/ambd/bluemonkey/config.js"
- }
- ],
-
- "sinks" : [
-
- {
- "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/automotive-message-broker/examplesinkplugin.so"
- }
- ]
-}
-
diff --git a/examples/bluemonkey/bluemonkeyconfig.in b/examples/bluemonkey/bluemonkeyconfig.in
index 434651bd..64f299c3 100644
--- a/examples/bluemonkey/bluemonkeyconfig.in
+++ b/examples/bluemonkey/bluemonkeyconfig.in
@@ -1,9 +1,9 @@
{
- "mainloop" : "@PLUGIN_INSTALL_PATH@/automotive-message-broker/qtmainloopplugin.so",
+ "mainloop" : "@PLUGIN_INSTALL_PATH@/qtmainloopplugin.so",
"sources" : [
{
- "path" : "@PLUGIN_INSTALL_PATH@/automotive-message-broker/bluemonkeyplugin.so",
+ "path" : "@PLUGIN_INSTALL_PATH@/bluemonkeyplugin.so",
"config" : "/etc/ambd/bluemonkey/config.js"
}
],
@@ -11,7 +11,7 @@
"sinks" : [
{
- "path" : "@PLUGIN_INSTALL_PATH@/automotive-message-broker/examplesinkplugin.so"
+ "path" : "@PLUGIN_INSTALL_PATH@/examplesinkplugin.so"
}
]
}
diff --git a/lib/abstractpropertytype.h b/lib/abstractpropertytype.h
index decc456a..b9e2a339 100644
--- a/lib/abstractpropertytype.h
+++ b/lib/abstractpropertytype.h
@@ -24,6 +24,7 @@
#include <stdexcept>
#include <vector>
#include <iostream>
+#include <memory>
#include <boost/any.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/utility.hpp>
@@ -74,27 +75,55 @@ public:
*/
enum Priority
{
- Normal = 0,
- Low,
- High,
- Instant
+ Normal = 0, /*!< normal priority. This is default */
+ Low, /*!< Low priority. */
+ High, /*!< High priority*/
+ Instant /*!< Instant. Using this priority is not thread safe. This is typically used for
+ * Properties that need to be deterministic.
+ */
};
- AbstractPropertyType(std::string property): name(property), timestamp(amb::currentTime()), sequence(-1), zone(Zone::None), priority(Normal)
+ AbstractPropertyType(std::string property)
+ : name(property), timestamp(amb::currentTime()), sequence(-1), zone(Zone::None), priority(Normal)
{
void*(name);
}
- virtual ~AbstractPropertyType() { }
+ virtual ~AbstractPropertyType()
+ {
+ for(auto i : destroyed)
+ {
+ if(i) i(this);
+ }
+ }
+ /**
+ * @brief toString
+ * @return strigified value
+ */
virtual std::string toString() const = 0;
+ /**
+ * @brief fromString converts from string value
+ */
virtual void fromString(std::string)= 0;
+ /**
+ * @brief toVariant
+ * @return GVariant representation of value. Caller must unref the returned GVariant
+ */
virtual GVariant* toVariant() = 0;
+ /**
+ * @brief fromVariant converts GVariant value into compatible native value. Caller owns
+ * GVariant argument.
+ */
virtual void fromVariant(GVariant*) = 0;
+ /**
+ * @brief copy
+ * @return a copy of the AbstractPropertyType
+ */
virtual AbstractPropertyType* copy() = 0;
/**
@@ -126,14 +155,33 @@ public:
return one != two;
}
+ /**
+ * @brief name Property name. @see VehicleProperty for built-in supported property names
+ */
std::string name;
+ /**
+ * @brief timestamp. Timestamp when the value was last updated by the system. This is updated automatically
+ * any time setValue() is called
+ * @see amb::currentTime()
+ * @see setValue()
+ */
double timestamp;
+ /**
+ * @brief sequence internal counter. Useful as a unique indentifier. values is -1 if not used (default).
+ */
int32_t sequence;
+ /**
+ * @brief sourceUuid uuid of the source that produced this property. This is set by the routingengine
+ * if left unmodified.
+ */
std::string sourceUuid;
+ /**
+ * @brief zone that the property is situated in.
+ */
Zone::Type zone;
/*!
@@ -144,23 +192,40 @@ public:
*/
Priority priority;
+ /**
+ * @brief setValue
+ * @param val boost::any value. NOTE: boost::any does not accept type coercion. Types must match exactly
+ * with native type. (ie, don't use "int" if the native type is "uint")
+ */
virtual void setValue(boost::any val)
{
mValue = val;
timestamp = amb::currentTime();
}
+ /**
+ * \brief value() native value. Does not use type coercion. Will throw if types do not match.
+ */
template <typename T>
T value() const
{
return boost::any_cast<T>(mValue);
}
+ /**
+ * @brief anyValue
+ * @return boost::any value
+ */
boost::any anyValue()
{
return mValue;
}
+ /**
+ * @brief destroyed is called if this property is destroyed.
+ */
+ std::vector<std::function<void(AbstractPropertyType*)>> destroyed;
+
protected:
boost::any mValue;
@@ -319,7 +384,13 @@ public:
}
};
-
+/**
+ * \brief BasicPropertyType is a typed property type. Most internal types are derived from this class
+ * \example
+ * std::unique_ptr<BasicPropertyType<int>> boostPSI = new BasicPropertyType<int>("BoostPSI",5);
+ * boostPSI->priority = AbstractPropertyType::Instant; //set instant because we clean up right after.
+ * routingEngine->updateProperty(boostPSI.get(), sourceUuid());
+ */
template <typename T>
class BasicPropertyType: public AbstractPropertyType
{
@@ -406,16 +477,6 @@ public:
mValue = T();
}
- /*BasicPropertyType(std::string val)
- :AbstractPropertyType("")
- {
- if(!val.empty() && val != "")
- {
- serialize<T>(val);
- }
- else setValue(T());
- }*/
-
AbstractPropertyType* copy()
{
return new BasicPropertyType<T>(*this);
@@ -448,6 +509,11 @@ public:
setValue(deserializeVariant<T>(v));
}
+ /**
+ * @brief basicValue
+ * @return Typed version of value. Slightly more useful than @see AbstractPropertyType::value()
+ */
+
T basicValue()
{
return value<T>();
diff --git a/lib/asyncqueue.hpp b/lib/asyncqueue.hpp
index ce2c1f72..f7881e4f 100644
--- a/lib/asyncqueue.hpp
+++ b/lib/asyncqueue.hpp
@@ -19,6 +19,7 @@
#include <glib.h>
#include <abstractpropertytype.h>
+#include "listplusplus.h"
#include <mutex>
#include <unordered_set>
@@ -66,6 +67,12 @@ public:
mQueue.insert(item);
}
+ void remove(T item)
+ {
+ std::lock_guard<std::mutex> lock(mutex);
+ removeOne(&mQueue, item);
+ }
+
protected:
std::mutex mutex;
std::unordered_set<T,std::hash<T>, Pred> mQueue;
diff --git a/plugins/dbus/dbusplugin.cpp b/plugins/dbus/dbusplugin.cpp
index b936e4a4..3e9fc86a 100644
--- a/plugins/dbus/dbusplugin.cpp
+++ b/plugins/dbus/dbusplugin.cpp
@@ -71,9 +71,6 @@ void DBusSink::supportedChanged(const PropertyList &supportedProperties)
void DBusSink::propertyChanged(AbstractPropertyType *value)
{
- if(!isRegistered())
- return;
-
VehicleProperty::Property property = value->name;
if( value->zone != zoneFilter)
diff --git a/plugins/dbus/environmentproperties.h b/plugins/dbus/environmentproperties.h
index 40655a15..3815152d 100644
--- a/plugins/dbus/environmentproperties.h
+++ b/plugins/dbus/environmentproperties.h
@@ -28,7 +28,7 @@ class Temperature: public DBusSink
{
public:
Temperature(AbstractRoutingEngine* re, GDBusConnection* connection)
- :DBusSink("InteriorTemperature", re, connection, map<string, string>())
+ :DBusSink("Temperature", re, connection, map<string, string>())
{
/**
* @attributeName Interior
@@ -196,7 +196,7 @@ public:
{
wantPropertyVariant(VehicleProperty::AirflowDirectionW3C, "AirflowDirection", AbstractProperty::ReadWrite);
- wantPropertyVariant(VehicleProperty::FanSpeed, "FanSpeed", AbstractProperty::ReadWrite);
+ wantPropertyVariant(VehicleProperty::FanSpeed, "FanSpeedLevel", AbstractProperty::ReadWrite);
wantPropertyVariant(VehicleProperty::TargetTemperature, "TargetTemperature", AbstractProperty::ReadWrite);
diff --git a/plugins/dbus/maintenance.h b/plugins/dbus/maintenance.h
index 97bc187f..6f1cd941 100644
--- a/plugins/dbus/maintenance.h
+++ b/plugins/dbus/maintenance.h
@@ -101,7 +101,7 @@ public:
**/
wantPropertyVariant(VehicleProperty::BatteryCurrent, "Current", AbstractProperty::Read);
- wantPropertyVariant(VehicleProperty::BatteryCurrent, "ChargeLevel", AbstractProperty::Read);
+ wantPropertyVariant(VehicleProperty::BatteryChargeLevel, "ChargeLevel", AbstractProperty::Read);
}
};
diff --git a/plugins/dbus/varianttype.cpp b/plugins/dbus/varianttype.cpp
index 730ed59c..933eccad 100644
--- a/plugins/dbus/varianttype.cpp
+++ b/plugins/dbus/varianttype.cpp
@@ -36,7 +36,7 @@ void VariantType::initialize()
/// do not request if not supported:
PropertyList proplist = routingEngine->supported();
- if(contains(proplist,mAmbPropertyName))
+ if(contains(proplist, mAmbPropertyName))
routingEngine->getPropertyAsync(request);
}
@@ -55,7 +55,7 @@ GVariant *VariantType::toGVariant()
void VariantType::fromGVariant(GVariant *val)
{
AbstractPropertyType *v = VehicleProperty::getPropertyTypeForPropertyNameValue(mAmbPropertyName);
- v->fromVariant( val );
+ v->fromVariant(val);
AsyncSetPropertyRequest request;
request.property = mAmbPropertyName;
diff --git a/plugins/obd2plugin/obd2source.cpp b/plugins/obd2plugin/obd2source.cpp
index 1032ab3b..c95bda20 100644
--- a/plugins/obd2plugin/obd2source.cpp
+++ b/plugins/obd2plugin/obd2source.cpp
@@ -463,14 +463,13 @@ static int updateProperties( gpointer data)
StatusMessage *reply = (StatusMessage*)retval;
if (reply->statusStr == "disconnected")
{
- OBD2Source::Obd2ConnectType val(Obd2Connected,false);
- src->updateProperty(&val);
+ src->obd2Connected.setValue(false);
+ src->updateProperty(&src->obd2Connected);
}
else if (reply->statusStr == "connected")
{
- OBD2Source::Obd2ConnectType val(Obd2Connected, true);
- val.priority = OBD2Source::Obd2ConnectType::Instant;
- src->updateProperty(&val);
+ src->obd2Connected.setValue(false);
+ src->updateProperty(&src->obd2Connected);
}
else if (reply->statusStr == "error:nodata" || reply->statusStr == "error:timeout")
{
diff --git a/plugins/obd2plugin/obd2source.h b/plugins/obd2plugin/obd2source.h
index 39774807..ba8cc2bf 100644
--- a/plugins/obd2plugin/obd2source.h
+++ b/plugins/obd2plugin/obd2source.h
@@ -187,12 +187,13 @@ public:
GThread *m_gThread;
typedef BasicPropertyType<bool> Obd2ConnectType;
+ Obd2ConnectType obd2Connected;
private:
PropertyList m_supportedProperties;
std::map<VehicleProperty::Property, AbstractPropertyType*> oldValueMap;
GMutex *threadQueueMutex;
- Obd2ConnectType obd2Connected;
+
};
diff --git a/plugins/wheel/wheelplugin.cpp b/plugins/wheel/wheelplugin.cpp
index f6ebdbb6..0ddfd799 100644
--- a/plugins/wheel/wheelplugin.cpp
+++ b/plugins/wheel/wheelplugin.cpp
@@ -99,6 +99,7 @@ private:
VehicleProperty::EngineOilPressureType *oilPSI;
VehicleProperty::EngineCoolantTemperatureType *coolantTemp;
VehicleProperty::SteeringWheelAngleType *steeringAngle;
+ VehicleProperty::SteeringWheelAngleW3CType *steeringAngleW3C;
VehicleProperty::ThrottlePositionType *throttle;
VehicleProperty::ClutchStatusType *clutch;
VehicleProperty::WheelBrakeType *brake;
@@ -162,6 +163,7 @@ PropertyList WheelSourcePlugin::supported()
props.push_back(VehicleProperty::ThrottlePosition);
props.push_back(VehicleProperty::WheelBrake);
props.push_back(VehicleProperty::SteeringWheelAngle);
+ props.push_back(VehicleProperty::SteeringWheelAngleW3C);
props.push_back(VehicleProperty::TurnSignal);
props.push_back(VehicleProperty::ClutchStatus);
props.push_back(VehicleProperty::EngineOilPressure);
@@ -208,6 +210,7 @@ WheelPrivate::WheelPrivate(WheelSourcePlugin *parent, AbstractRoutingEngine *rou
engineSpeed(new VehicleProperty::EngineSpeedType(0)),
vehicleSpeed(new VehicleProperty::VehicleSpeedType(0)),
steeringAngle(new VehicleProperty::SteeringWheelAngleType(0)),
+ steeringAngleW3C(new VehicleProperty::SteeringWheelAngleW3CType(0)),
clutch(new VehicleProperty::ClutchStatusType(false)),
brake(new VehicleProperty::WheelBrakeType(false)),
tempButton(new VehicleProperty::ButtonEventType(ButtonEvents::NoButton)),
@@ -308,6 +311,8 @@ AbstractPropertyType *WheelPrivate::getProperty(VehicleProperty::Property propTy
return this->brake;
else if (propType == VehicleProperty::SteeringWheelAngle)
return this->steeringAngle;
+ else if (propType == VehicleProperty::SteeringWheelAngleW3C)
+ return this->steeringAngleW3C;
else if (propType == VehicleProperty::TurnSignal)
return this->turnSignal;
else if (propType == VehicleProperty::ClutchStatus)
@@ -536,7 +541,9 @@ void WheelPrivate::changeCoolantTemp(bool increase)
void WheelPrivate::changeSteeringAngle(int val)
{
*steeringAngle = (((double)val/(double)32767.0) + (double)1.0) * (double)180.0;
+ *steeringAngleW3C = (((double)val/(double)32767.0) + (double)1.0) * (double)180.0;
this->re->updateProperty(steeringAngle, mParent->uuid());
+ this->re->updateProperty(steeringAngleW3C, mParent->uuid());
}
void WheelPrivate::changeClutch(int val)