2 Copyright (C) 2012 Intel Corporation
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "vehicleproperty.h"
23 #define REGISTERPROPERTY(property, defaultValue) \
24 registerProperty(property, []() { return new property ## Type(defaultValue); });
26 #define REGISTERPROPERTYWITHTYPE(property, type, defaultValue) \
27 registerProperty(property, []() { return new type(defaultValue); });
31 std::map<VehicleProperty::Property, VehicleProperty::PropertyTypeFactoryCallback> VehicleProperty::registeredPropertyFactoryMap;
33 const VehicleProperty::Property VehicleProperty::NoValue = "NoValue";
34 const VehicleProperty::Property VehicleProperty::VehicleSpeed = "VehicleSpeed";
35 const VehicleProperty::Property VehicleProperty::EngineSpeed = "EngineSpeed";
36 const VehicleProperty::Property VehicleProperty::TransmissionShiftPosition = "TransmissionShiftPosition";
37 const VehicleProperty::Property VehicleProperty::TransmissionGearPosition = "TransmissionGearPostion";
38 const VehicleProperty::Property VehicleProperty::TransmissionMode = "TransmissionMode";
39 const VehicleProperty::Property VehicleProperty::ThrottlePosition = "ThrottlePosition";
40 const VehicleProperty::Property VehicleProperty::WheelBrake = "WheelBrake";
41 const VehicleProperty::Property VehicleProperty::SteeringWheelAngle = "SteeringWheelAngle";
42 const VehicleProperty::Property VehicleProperty::TurnSignal = "TurnSignal";
43 const VehicleProperty::Property VehicleProperty::ClutchStatus = "ClutchStatus";
44 const VehicleProperty::Property VehicleProperty::EngineOilPressure = "EngineOilPressure";
45 const VehicleProperty::Property VehicleProperty::EngineCoolantTemperature = "EngineCoolantTemperature";
46 const VehicleProperty::Property VehicleProperty::MachineGunTurretStatus = "MachineGunTurretStatus";
47 const VehicleProperty::Property VehicleProperty::AccelerationX = "AccelerationX";
48 const VehicleProperty::Property VehicleProperty::AccelerationY = "AccelerationY";
49 const VehicleProperty::Property VehicleProperty::AccelerationZ = "AccelerationZ";
50 const VehicleProperty::Property VehicleProperty::MassAirFlow = "MassAirFlow";
51 const VehicleProperty::Property VehicleProperty::ButtonEvent = "ButtonEvent";
52 const VehicleProperty::Property VehicleProperty::AirIntakeTemperature = "AirIntakeTemperature";
53 const VehicleProperty::Property VehicleProperty::BatteryVoltage = "BatteryVoltage";
54 const VehicleProperty::Property VehicleProperty::InteriorTemperature = "InteriorTemperature";
55 const VehicleProperty::Property VehicleProperty::EngineOilTemperature = "EngineOilTemperature";
56 const VehicleProperty::Property VehicleProperty::VIN = "VIN";
57 const VehicleProperty::Property VehicleProperty::WMI = "WMI";
58 const VehicleProperty::Property VehicleProperty::TirePressureLeftFront = "TirePressureLeftFront";
59 const VehicleProperty::Property VehicleProperty::TirePressureRightFront = "TirePressureRightFront";
60 const VehicleProperty::Property VehicleProperty::TirePressureLeftRear = "TirePressureLeftRear";
61 const VehicleProperty::Property VehicleProperty::TirePressureRightRear = "TirePressureRightRear";
62 const VehicleProperty::Property VehicleProperty::VehiclePowerMode = "VehiclePowerMode";
63 const VehicleProperty::Property VehicleProperty::TripMeterA = "TripMeterA";
64 const VehicleProperty::Property VehicleProperty::TripMeterB = "TripMeterB";
65 const VehicleProperty::Property VehicleProperty::TripMeterC = "TripMeterC";
67 std::list<VehicleProperty::Property> VehicleProperty::mCapabilities;
69 VehicleProperty::VehicleProperty()
71 registerProperty( VehicleSpeed, [](){ return new VehicleSpeedType(0); });
72 registerProperty(EngineSpeed, [](){ return new EngineSpeedType(0); });
73 registerProperty(TransmissionShiftPosition, [](){ return new TransmissionShiftPositionType(Transmission::Neutral); });
74 registerProperty(TransmissionGearPosition, [](){ return new TransmissionGearPositionType(Transmission::Neutral); });
75 REGISTERPROPERTY(TransmissionMode,Transmission::Normal);
76 registerProperty(ThrottlePosition, [](){ return new ThrottlePositionType(0); });
77 registerProperty(WheelBrake, [](){ return new WheelBrakeType(false); });
78 registerProperty(SteeringWheelAngle, [](){ return new SteeringWheelAngleType(0); });
79 registerProperty(TurnSignal, [](){ return new TurnSignalType(TurnSignals::Off); });
80 registerProperty(ClutchStatus, [](){ return new ClutchStatusType(false); });
81 registerProperty(EngineOilPressure, [](){ return new EngineOilPressureType(0); });
82 registerProperty(EngineCoolantTemperature, [](){ return new EngineCoolantTemperatureType(0); });
83 registerProperty(MachineGunTurretStatus, [](){ return new MachineGunTurretStatusType(false); });
84 registerProperty(AccelerationX, [](){ return new AccelerationType(0); });
85 registerProperty(AccelerationY, [](){ return new AccelerationType(0); });
86 registerProperty(AccelerationZ, [](){ return new AccelerationType(0); });
87 registerProperty(MassAirFlow, [](){ return new MassAirFlowType(0); });
88 registerProperty(ButtonEvent, [](){ return new ButtonEventType(ButtonEvents::NoButton); });
89 registerProperty(BatteryVoltage, [](){ return new BatteryVoltageType(0); });
90 registerProperty(InteriorTemperature, [](){ return new InteriorTemperatureType(0); });
91 registerProperty(EngineOilTemperature, [](){ return new EngineOilTemperatureType(0); });
92 registerProperty(VIN, [](){ return new VINType(""); });
93 registerProperty(WMI, [](){ return new WMIType(""); });
94 REGISTERPROPERTYWITHTYPE(TirePressureLeftFront, TirePressureType, 0);
95 REGISTERPROPERTYWITHTYPE(TirePressureRightFront, TirePressureType, 0);
96 REGISTERPROPERTYWITHTYPE(TirePressureLeftRear, TirePressureType, 0);
97 REGISTERPROPERTYWITHTYPE(TirePressureRightRear, TirePressureType, 0);
98 registerProperty( VehiclePowerMode,[](){ return new VehiclePowerModeType(Power::Off); } );
99 REGISTERPROPERTYWITHTYPE(TripMeterA,TripMeterType,0);
100 REGISTERPROPERTYWITHTYPE(TripMeterB,TripMeterType,0);
101 REGISTERPROPERTYWITHTYPE(TripMeterC,TripMeterType,0);
104 std::list<VehicleProperty::Property> VehicleProperty::capabilities()
106 return mCapabilities;
109 AbstractPropertyType* VehicleProperty::getPropertyTypeForPropertyNameValue(VehicleProperty::Property name, std::string value)
112 if(registeredPropertyFactoryMap.count(name) > 0)
114 VehicleProperty::PropertyTypeFactoryCallback cb = registeredPropertyFactoryMap[name];
117 AbstractPropertyType* type = cb();
119 throw std::runtime_error("Cannot return NULL in a PropertyTypeFactory");
121 type->fromString(value);
131 void VehicleProperty::registerProperty(VehicleProperty::Property name, VehicleProperty::PropertyTypeFactoryCallback factory)
133 registeredPropertyFactoryMap[name] = factory;
134 mCapabilities.push_back(name);
137 VehicleProperty vehiclePropertyConstruct;