const VehicleProperty::Property VehicleProperty::InteriorLightCenter = "InteriorLightCenter";
const VehicleProperty::Property VehicleProperty::InteriorLightPassenger = "InteriorLightPassenger";
const VehicleProperty::Property VehicleProperty::EngineLoad = "EngineLoad";
+const VehicleProperty::Property VehicleProperty::Horn = "Horn";
+const VehicleProperty::Property VehicleProperty::FuelLevel = "FuelLevel";
+const VehicleProperty::Property VehicleProperty::FuelConsumption = "FuelConsumption";
+const VehicleProperty::Property VehicleProperty::FuelRange = "FuelRange";
+const VehicleProperty::Property VehicleProperty::FuelEconomy = "FuelEconomy";
+const VehicleProperty::Property VehicleProperty::FuelAverageEconomy = "FuelAverageEconomy";
+const VehicleProperty::Property VehicleProperty::EngineOilRemaining = "EngineOilRemaining";
std::list<VehicleProperty::Property> VehicleProperty::mCapabilities;
registerProperty(TurnSignal, [](){ return new TurnSignalType(TurnSignals::Off); });
registerProperty(ClutchStatus, [](){ return new ClutchStatusType(false); });
registerProperty(EngineOilPressure, [](){ return new EngineOilPressureType(0); });
+ registerProperty(EngineOilTemperature, [](){ return new EngineOilTemperatureType(0); });
+ REGISTERPROPERTY(EngineOilRemaining,0);
registerProperty(EngineCoolantTemperature, [](){ return new EngineCoolantTemperatureType(0); });
registerProperty(MachineGunTurretStatus, [](){ return new MachineGunTurretStatusType(false); });
registerProperty(AccelerationX, [](){ return new AccelerationType(0); });
registerProperty(ButtonEvent, [](){ return new ButtonEventType(ButtonEvents::NoButton); });
registerProperty(BatteryVoltage, [](){ return new BatteryVoltageType(0); });
registerProperty(InteriorTemperature, [](){ return new InteriorTemperatureType(0); });
- registerProperty(EngineOilTemperature, [](){ return new EngineOilTemperatureType(0); });
registerProperty(VIN, [](){ return new VINType(""); });
registerProperty(WMI, [](){ return new WMIType(""); });
REGISTERPROPERTYWITHTYPE(TirePressureLeftFront, TirePressureType, 0);
REGISTERPROPERTYWITHTYPE(InteriorLightPassenger, LightStatusType, false);
REGISTERPROPERTYWITHTYPE(InteriorLightCenter, LightStatusType, false);
REGISTERPROPERTY(EngineLoad,0);
+ REGISTERPROPERTY(Horn,false);
+ REGISTERPROPERTY(FuelLevel, 0);
+ REGISTERPROPERTY(FuelRange, 0);
+ REGISTERPROPERTY(FuelConsumption, 0);
+ REGISTERPROPERTY(FuelEconomy, 0);
+ REGISTERPROPERTY(FuelAverageEconomy, 0);
+
+
}
std::list<VehicleProperty::Property> VehicleProperty::capabilities()
static const Property EngineOilTemperature;
typedef BasicPropertyType<int> EngineOilTemperatureType;
+ static const Property EngineOilRemaining;
+ typedef BasicPropertyType<uint16_t> EngineOilRemainingType;
+
/**< Vehicle Identification Number (ISO 3779) 17 chars**/
static const Property VIN;
typedef StringPropertyType VINType;
static const Property EngineLoad;
typedef BasicPropertyType<uint16_t> EngineLoadType;
+ static const Property Horn;
+ typedef BasicPropertyType<bool> HornType;
+
+ static const Property FuelLevel;
+ typedef BasicPropertyType<uint16_t> FuelLevelType;
+
+ static const Property FuelRange;
+ typedef BasicPropertyType<uint16_t> FuelRangeType;
+
+ static const Property FuelConsumption;
+ typedef BasicPropertyType<uint16_t> FuelConsumptionType;
+
+ static const Property FuelEconomy;
+ typedef BasicPropertyType<uint16_t> FuelEconomyType;
+
+ static const Property FuelAverageEconomy;
+ typedef BasicPropertyType<uint16_t> FuelAverageEconomyType;
+
static std::list<VehicleProperty::Property> capabilities();
/*! getPropertyTypeForPropertyNameValue returns an AbstractPropertyType* for the property name
}
};
+class HornProperty: public DBusSink
+{
+public:
+ HornProperty(AbstractRoutingEngine *re, GDBusConnection *connection)
+ :DBusSink("org.automotive.horn","/org/automotive/runningstatus/horn", re, connection, map<string, string>())
+ {
+ wantProperty<bool>(VehicleProperty::Horn,"On","b",AbstractProperty::Read);
+ supportedChanged(re->supported());
+ }
+};
+
+class FuelProperty: public DBusSink
+{
+public:
+ FuelProperty(AbstractRoutingEngine *re, GDBusConnection *connection)
+ :DBusSink("org.automotive.fuel", "/org/automotive/runningstatus/fuel", re, connection, map<string, string>())
+ {
+ wantProperty<uint16_t>(VehicleProperty::FuelLevel,"Level", "y", AbstractProperty::Read);
+ wantProperty<uint16_t>(VehicleProperty::FuelRange,"Range", "q", AbstractProperty::Read);
+ wantProperty<uint16_t>(VehicleProperty::FuelConsumption,"InstantConsumption", "q", AbstractProperty::Read);
+ wantProperty<uint16_t>(VehicleProperty::FuelEconomy,"InstantEconomy", "q", AbstractProperty::Read);
+ wantProperty<uint16_t>(VehicleProperty::FuelAverageEconomy,"AverageEconomy", "q", AbstractProperty::ReadWrite);
+ supportedChanged(re->supported());
+ }
+};
+
+class EngineOilProperty: public DBusSink
+{
+public:
+ EngineOilProperty(AbstractRoutingEngine *re, GDBusConnection *connection)
+ :DBusSink("org.automotive.engineOil", "/org/automotive/runningstatus/engineOil", re, connection, map<string, string>())
+ {
+ wantProperty<uint16_t>(VehicleProperty::EngineOilRemaining, "Remaining", "y", AbstractProperty::Read);
+ wantProperty<uint16_t>(VehicleProperty::EngineOilTemperature, "Temperature", "y", AbstractProperty::Read);
+ wantProperty<uint16_t>(VehicleProperty::EngineOilPressure, "Pressure", "y", AbstractProperty::Read);
+ supportedChanged(re->supported());
+ }
+};
+
#endif
+if(obd2_plugin)
+
include(CheckIncludeFiles)
target_link_libraries(obd2sourceplugin amb -L${CMAKE_CURRENT_BINARY_DIR}/lib ${link_libraries} ${gio_LIBRARIES} ${gio-unix_LIBRARIES} )
install(TARGETS obd2sourceplugin LIBRARY DESTINATION lib/automotive-message-broker)
+
+endif(obd2_plugin)
#define __SMALLFILE__ std::string(__FILE__).substr(std::string(__FILE__).rfind("/")+1)
AbstractRoutingEngine *m_re;
+uint16_t Obd2Amb::velocity = 0;
+double Obd2Amb::fuelConsumptionOldTime = 0;
+
+
int calledPersecond = 0;
bool sendElmCommand(obdLib *obd,std::string command)
double rpm = ((replyVector[2] << 8) + replyVector[3]) / 4.0;
ObdReply *rep = new ObdReply();
rep->req = "0C";
+ rep->property = VehicleProperty::EngineSpeed;
rep->reply = boost::lexical_cast<string>(rpm);
g_async_queue_push(privResponseQueue,rep);
//printf("RPM: %f\n",rpm);
int mph = replyVector[2];
ObdReply *rep = new ObdReply();
rep->req = "0D";
+ rep->property = VehicleProperty::VehicleSpeed;
rep->reply = boost::lexical_cast<string>(mph);
g_async_queue_push(privResponseQueue,rep);
}
int temp = replyVector[2] - 40;
ObdReply *rep = new ObdReply();
rep->req = "05";
+ rep->property = VehicleProperty::EngineCoolantTemperature;
rep->reply = boost::lexical_cast<string>(temp);
g_async_queue_push(privResponseQueue,rep);
}
double maf = ((replyVector[2] << 8) + replyVector[3]) / 100.0;
ObdReply *rep = new ObdReply();
rep->req = "10";
+ rep->property = VehicleProperty::MassAirFlow;
rep->reply = boost::lexical_cast<string>(maf);
g_async_queue_push(privResponseQueue,rep);
}
else
{
//printf("Unknown response type: %i\n",replyVector[1]);
- DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Unknown response type" << replyVector[1] << "\n";
+ DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Unknown response type" << replyVector[1] << endl;
}
}
else if (replyVector[0] == 0x49)
while(gpointer retval = g_async_queue_try_pop(src->responseQueue))
{
ObdReply *reply = (ObdReply*)retval;
- if (reply->req == "05")
+
+ Obd2Amb obd2amb;
+
+ if(obd2amb.propertyPidMap.count(reply->property) != 0)
+ {
+ std::string convValue = reply->reply;
+
+ if(obd2amb.propertyConversionMap.count(reply->property))
+ {
+ convValue = obd2amb.propertyConversionMap[reply->property](reply->reply);
+ }
+
+
+ AbstractPropertyType* value = VehicleProperty::getPropertyTypeForPropertyNameValue(reply->property, convValue);
+ src->updateProperty(reply->property, value);
+ }
+
+ /*if (reply->req == "05")
{
VehicleProperty::EngineCoolantTemperatureType speed(reply->reply);
src->updateProperty(VehicleProperty::EngineCoolantTemperature,&speed);
src->updateProperty(VehicleProperty::InteriorTemperature,&temp);
}
//5C -- engine oil temp
- //46 interior temp
+ //46 interior temp*/
+
delete reply;
}
Obd2Amb obd2amb;
ObdRequest *requ = new ObdRequest();
+ requ->property = property;
requ->req = obd2amb.propertyPidMap[property];
g_async_queue_push(subscriptionRemoveQueue,requ);
}
Obd2Amb obd2amb;
ObdRequest *requ = new ObdRequest();
+ requ->property = property;
requ->req = obd2amb.propertyPidMap[property];
g_async_queue_push(singleShotQueue,requ);
}
#include <abstractsource.h>
#include <string>
+#include <sstream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
class ObdRequest
{
public:
+ VehicleProperty::Property property;
std::string req;
std::string arg;
};
class ObdReply
{
public:
+ VehicleProperty::Property property;
std::string req;
std::string reply;
};
class Obd2Amb
{
public:
+
+ typedef function<std::string (std::string)> ConversionFunction;
+
Obd2Amb()
{
propertyPidMap[VehicleProperty::VehicleSpeed] = "010D1\r";
propertyPidMap[VehicleProperty::MassAirFlow] = "01101\r";
propertyPidMap[VehicleProperty::AirIntakeTemperature] = "010F1\r";
propertyPidMap[VehicleProperty::ThrottlePosition] = "01111\r";
- propertyPidMap[VehicleProperty::BatteryVoltage] = "ATRV\r"; propertyPidMap[VehicleProperty::EngineCoolantTemperature] = "0105a\r";
+ propertyPidMap[VehicleProperty::BatteryVoltage] = "ATRV\r";
+ propertyPidMap[VehicleProperty::EngineCoolantTemperature] = "0105a\r";
propertyPidMap[VehicleProperty::EngineLoad] = "01041/r";
propertyPidMap[VehicleProperty::VIN] = "0902/r";
propertyPidMap[VehicleProperty::WMI] = "0902/r";
propertyPidMap[VehicleProperty::EngineOilTemperature] = "015C1\r";
propertyPidMap[VehicleProperty::InteriorTemperature] = "01461\r";
+ propertyPidMap[VehicleProperty::FuelConsumption] = "01101\r";
+
+
+
+ propertyConversionMap[VehicleProperty::VehicleSpeed] = [](std::string input)
+ {
+ ///velocity is used in other equations. We'll save it off in a static variable:
+ stringstream vssConvert(input);
+
+ vssConvert>>velocity;
+
+ return input;
+ };
+
+ propertyConversionMap[VehicleProperty::WMI] = [](std::string input)
+ {
+ return input.substr(0,3);
+ };
+
+ propertyConversionMap[VehicleProperty::FuelConsumption] = [](std::string input)
+ {
+ double maf;
+ stringstream mafConvert(input);
+
+ mafConvert>>maf;
+
+ mafConvert<<1 / (14.75 * 6.26) * maf * 0/60;
+
+ return mafConvert.str();
+ };
+
+
+
}
+
+
map<VehicleProperty::Property, std::string> propertyPidMap;
+ map<VehicleProperty::Property, ConversionFunction> propertyConversionMap;
+
+private:
+
+ static uint16_t velocity;
+ static double fuelConsumptionOldTime;
};
class OBD2Source : public AbstractSource