diff options
Diffstat (limited to 'plugins/obd2plugin/obd2source.h')
-rw-r--r-- | plugins/obd2plugin/obd2source.h | 98 |
1 files changed, 46 insertions, 52 deletions
diff --git a/plugins/obd2plugin/obd2source.h b/plugins/obd2plugin/obd2source.h index 9f789fa4..6c628706 100644 --- a/plugins/obd2plugin/obd2source.h +++ b/plugins/obd2plugin/obd2source.h @@ -33,6 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "obdlib.h" #include <glib.h> +#include "obdpid.h" class ObdRequest { @@ -42,6 +43,14 @@ public: std::string arg; }; + +class CommandRequest +{ +public: + std::string req; + std::vector<std::string> arglist; +}; + class ObdReply { public: @@ -51,70 +60,52 @@ public: }; + class Obd2Amb { public: typedef function<std::string (std::string)> ConversionFunction; + typedef std::vector<unsigned char> ByteArray; Obd2Amb() { - propertyPidMap[VehicleProperty::VehicleSpeed] = "010D1\r"; - propertyPidMap[VehicleProperty::EngineSpeed] = "010C1\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::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) + supportedPidsList.push_back(new VehicleSpeedPid()); + supportedPidsList.push_back(new EngineSpeedPid()); + supportedPidsList.push_back(new MassAirFlowPid()); + supportedPidsList.push_back(new VinPid()); + supportedPidsList.push_back(new WmiPid()); + supportedPidsList.push_back(new FuelConsumptionPid()); + supportedPidsList.push_back(new EngineCoolantPid()); + } + ObdPid* createPidFromReply(ByteArray replyVector) + { + for(auto itr = supportedPidsList.begin(); itr != supportedPidsList.end(); itr++) { - return input.substr(0,3); - }; - - propertyConversionMap[VehicleProperty::FuelConsumption] = [](std::string input) + if (!(*itr)->tryParse(replyVector)) + { + continue; + } + + ObdPid* pid = (*itr)->create(); + pid->tryParse(replyVector); + return pid; + } + return 0; + } + ObdPid* createPidforProperty(VehicleProperty::Property property) + { + for(auto itr = supportedPidsList.begin(); itr != supportedPidsList.end(); itr++) { - double maf; - stringstream mafConvert(input); - - mafConvert>>maf; - - mafConvert<<1 / (14.75 * 6.26) * maf * 0/60; - - return mafConvert.str(); - }; - - - + if((*itr)->property == property) + { + ObdPid* obj = *itr; + return obj->create(); + } + } } - - - map<VehicleProperty::Property, std::string> propertyPidMap; - map<VehicleProperty::Property, ConversionFunction> propertyConversionMap; - -private: - - static uint16_t velocity; - static double fuelConsumptionOldTime; + std::list<ObdPid*> supportedPidsList; }; class OBD2Source : public AbstractSource @@ -149,9 +140,12 @@ public: void setConfiguration(map<string, string> config); //void randomizeProperties(); std::string m_port; + std::string m_baud; map<VehicleProperty::Property,AsyncPropertyReply*> propertyReplyMap; list<VehicleProperty::Property> propertySubscriptionList; void updateProperty(VehicleProperty::Property property,AbstractPropertyType *value); + obdLib * obd; + private: PropertyList m_supportedProperties; GMutex *threadQueueMutex; |