#include <stdexcept>
#include <boost/any.hpp>
#include <boost/lexical_cast.hpp>
+#include <boost/utility.hpp>
+#include <type_traits>
class AbstractPropertyType
{
BasicPropertyType(std::string val)
{
if(!val.empty() && val != "")
- setValue(boost::lexical_cast<T,std::string>(val));
+ {
+ serialize<T>(val);
+ }
else throw std::runtime_error("value cannot be empty");
}
return stream.str();
}
+
+private:
+
+ template <class N>
+ void serialize(std::string val, typename std::enable_if<std::is_enum<N>::value, N>::type* = 0)
+ {
+ int someTemp;
+
+ std::stringstream stream(val);
+
+ stream>>someTemp;
+ setValue((N)someTemp);
+ }
+
+ template <class N>
+ void serialize(std::string val, typename std::enable_if<!std::is_enum<N>::value, N>::type* = 0)
+ {
+ std::stringstream stream(val);
+ N someTemp;
+ stream>>someTemp;
+ setValue(someTemp);
+ }
};
class StringPropertyType: public AbstractPropertyType
}
}
-
bool contains(T value)
{
return (std::find(mList->begin(), mList->end(), value) != mList->end());
else if(name == AccelerationY) return new AccelerationType(value);
else if(name == AccelerationZ) return new AccelerationType(value);
else if(name == MassAirFlow) return new MassAirFlowType(value);
+ else if(name == ButtonEvent) return new ButtonEventType(value);
else if(name == AirIntakeTemperature) return new AirIntakeTemperatureType(value);
else if(name == BatteryVoltage) return new BatteryVoltageType(value);
else if(name == InteriorTemperature) return new InteriorTemperatureType(value);
};
}
+namespace TurnSignals {
+enum TurnSignalType
+{
+ Off=0,
+ Right=1,
+ Left=2,
+ Hazard=3
+};
+}
+
class VehicleProperty
{
/**< 0=off, 1=right, 2=left, 3=hazard */
static const Property TurnSignal;
- typedef BasicPropertyType<uint16_t> TurnSignalType;
+ typedef BasicPropertyType<TurnSignals::TurnSignalType> TurnSignalType;
/**< Clutch pedal status 0=off, 1=on */
static const Property ClutchStatus;
/**< Button Event @see ButtonEvents::ButtonEventType */
static const Property ButtonEvent;
- typedef BasicPropertyType<int> ButtonEventType;
+ typedef BasicPropertyType<ButtonEvents::ButtonEventType> ButtonEventType;
/**< Air intake temperature in degrees celcius */
static const Property AirIntakeTemperature;
add_subdirectory(dbus)
add_subdirectory(websocketsink)
add_subdirectory(obd2plugin)
-
+add_subdirectory(demosink)
add_subdirectory(websocketsourceplugin)
--- /dev/null
+
+include_directories(${CMAKE_SOURCE_DIR}/lib ${include_dirs})
+
+pkg_check_modules(giounix REQUIRED gio-unix-2.0)
+set(link_libraries ${link_libraries} ${giounix_LIBRARIES})
+#set(include_dirs ${include_dirs} ${giounix_INCLUDE_DIRS})
+include_directories(${giounix_INCLUDE_DIRS})
+
+set(demosinkplugin_headers demosinkplugin.h)
+set(demosinkplugin_sources demosinkplugin.cpp)
+
+add_library(demosinkplugin MODULE ${demosinkplugin_sources})
+set_target_properties(demosinkplugin PROPERTIES PREFIX "")
+target_link_libraries(demosinkplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries})
+
+install(TARGETS demosinkplugin LIBRARY DESTINATION lib/automotive-message-broker)
--- /dev/null
+/*
+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 "demosinkplugin.h"
+#include "abstractroutingengine.h"
+
+#include <iostream>
+#include <stdexcept>
+#include <boost/assert.hpp>
+#include <glib.h>
+
+using namespace std;
+
+#include "debugout.h"
+
+string findReplace(string str, string tofind, string replacewith, string exclusions="")
+{
+ size_t i=0;
+
+ size_t exclusionPos = exclusions.find(tofind,0);
+
+ while((i = str.find(tofind,i)) != string::npos)
+ {
+ if( exclusionPos != string::npos )
+ {
+ if(str.substr(i-exclusionPos,exclusions.length()) == exclusions)
+ {
+ i+=replacewith.size();
+ continue;
+ }
+ }
+
+ str.replace(i,tofind.size(),replacewith);
+ i+=replacewith.size();
+ }
+
+}
+
+
+DemoSink::DemoSink(AbstractRoutingEngine* re)
+:AbstractSink(re)
+{
+
+}
+
+DemoSink::~DemoSink()
+{
+
+}
+
+extern "C" AbstractSinkManager * create(AbstractRoutingEngine* routingengine)
+{
+ return new DemoSinkManager(routingengine);
+}
+
+string DemoSink::uuid()
+{
+ return "5b0e8a04-d6d7-43af-b827-1663627a25d9";
+}
+
+void DemoSink::propertyChanged(VehicleProperty::Property property, AbstractPropertyType *value, string uuid)
+{
+ std::string app = configuration["script"];
+
+ string cmdline = findReplace(app,"%1",value->toString());
+ GError* error = NULL;
+
+ g_spawn_command_line_async(cmdline.c_str(), &error);
+
+}
+
+void DemoSink::supportedChanged(PropertyList list)
+{
+ routingEngine->subscribeToProperty(VehicleProperty::ButtonEvent, this);
+ routingEngine->subscribeToProperty(VehicleProperty::TurnSignal, this);
+}
--- /dev/null
+/*
+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 WHEELPLUGIN_H
+#define WHEELPLUGIN_H
+
+#include <abstractsink.h>
+#include <string>
+
+using namespace std;
+
+class DemoSink: public AbstractSink
+{
+
+public:
+ DemoSink(AbstractRoutingEngine* re);
+ ~DemoSink();
+
+ string uuid();
+
+ void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid);
+ void supportedChanged(PropertyList);
+
+ friend class WheelPrivate;
+
+private:
+
+ PropertySet mRequests;
+};
+
+class DemoSinkManager: public AbstractSinkManager
+{
+public:
+ DemoSinkManager(AbstractRoutingEngine* engine)
+ :AbstractSinkManager(engine)
+ {
+ new DemoSink(engine);
+ }
+};
+
+#endif // WHEELPLUGIN_H
char *button;
uint16_t machineGuns;
- uint16_t turnSignal;
+ TurnSignals::TurnSignalType turnSignal;
uint16_t currentGear;
uint16_t oilPSI;
uint16_t coolantTemp;
WheelPrivate::WheelPrivate(WheelSourcePlugin *parent, AbstractRoutingEngine *route)
:re(route), gis(nullptr), axis(nullptr), button(nullptr),
-oilPSI(10), coolantTemp(100), turnSignal(0), throttle(0),
+oilPSI(10), coolantTemp(100), turnSignal(TurnSignals::Off), throttle(0),
machineGuns(false), currentGear(0), steeringAngle(0),
clutch(false), oldClutch(false), brake(false), oldBrake(false)
{
void WheelPrivate::changeTurnSignal(TurnSignal dir, bool val)
{
- int tsVal=0;
+ TurnSignals::TurnSignalType tsVal= TurnSignals::Off;
if (val) {
- if (dir == TS_LEFT)
- tsVal = 2;
+ if (dir == TurnSignals::Left)
+ tsVal = TurnSignals::Left;
else
- tsVal = 1;
+ tsVal = TurnSignals::Right;
}
this->turnSignal = tsVal;
VehicleProperty::TurnSignalType temp(this->turnSignal);