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::ThrottlePosition = "ThrottlePosition";
39 const VehicleProperty::Property VehicleProperty::WheelBrake = "WheelBrake";
40 const VehicleProperty::Property VehicleProperty::SteeringWheelAngle = "SteeringWheelAngle";
41 const VehicleProperty::Property VehicleProperty::TurnSignal = "TurnSignal";
42 const VehicleProperty::Property VehicleProperty::ClutchStatus = "ClutchStatus";
43 const VehicleProperty::Property VehicleProperty::EngineOilPressure = "EngineOilPressure";
44 const VehicleProperty::Property VehicleProperty::EngineCoolantTemperature = "EngineCoolantTemperature";
45 const VehicleProperty::Property VehicleProperty::MachineGunTurretStatus = "MachineGunTurretStatus";
46 const VehicleProperty::Property VehicleProperty::AccelerationX = "AccelerationX";
47 const VehicleProperty::Property VehicleProperty::AccelerationY = "AccelerationY";
48 const VehicleProperty::Property VehicleProperty::AccelerationZ = "AccelerationZ";
49 const VehicleProperty::Property VehicleProperty::MassAirFlow = "MassAirFlow";
50 const VehicleProperty::Property VehicleProperty::ButtonEvent = "ButtonEvent";
51 const VehicleProperty::Property VehicleProperty::AirIntakeTemperature = "AirIntakeTemperature";
52 const VehicleProperty::Property VehicleProperty::BatteryVoltage = "BatteryVoltage";
53 const VehicleProperty::Property VehicleProperty::InteriorTemperature = "InteriorTemperature";
54 const VehicleProperty::Property VehicleProperty::EngineOilTemperature = "EngineOilTemperature";
55 const VehicleProperty::Property VehicleProperty::VIN = "VIN";
56 const VehicleProperty::Property VehicleProperty::WMI = "WMI";
57 const VehicleProperty::Property VehicleProperty::TirePressureLeftFront = "TirePressureLeftFront";
58 const VehicleProperty::Property VehicleProperty::TirePressureRightFront = "TirePressureRightFront";
59 const VehicleProperty::Property VehicleProperty::TirePressureLeftRear = "TirePressureLeftRear";
60 const VehicleProperty::Property VehicleProperty::TirePressureRightRear = "TirePressureRightRear";
61 const VehicleProperty::Property VehicleProperty::VehiclePowerMode = "VehiclePowerMode";
62 const VehicleProperty::Property VehicleProperty::TripMeterA = "TripMeterA";
63 const VehicleProperty::Property VehicleProperty::TripMeterB = "TripMeterB";
64 const VehicleProperty::Property VehicleProperty::TripMeterC = "TripMeterC";
66 std::list<VehicleProperty::Property> VehicleProperty::mCapabilities;
68 VehicleProperty::VehicleProperty()
70 registerProperty( VehicleSpeed, [](){ return new VehicleSpeedType(0); });
71 registerProperty(EngineSpeed, [](){ return new EngineSpeedType(0); });
72 registerProperty(TransmissionShiftPosition, [](){ return new TransmissionShiftPositionType(Transmission::Neutral); });
73 registerProperty(TransmissionGearPosition, [](){ return new TransmissionGearPositionType(Transmission::Neutral); });
74 registerProperty(ThrottlePosition, [](){ return new ThrottlePositionType(0); });
75 registerProperty(WheelBrake, [](){ return new WheelBrakeType(false); });
76 registerProperty(SteeringWheelAngle, [](){ return new SteeringWheelAngleType(0); });
77 registerProperty(TurnSignal, [](){ return new TurnSignalType(TurnSignals::Off); });
78 registerProperty(ClutchStatus, [](){ return new ClutchStatusType(false); });
79 registerProperty(EngineOilPressure, [](){ return new EngineOilPressureType(0); });
80 registerProperty(EngineCoolantTemperature, [](){ return new EngineCoolantTemperatureType(0); });
81 registerProperty(MachineGunTurretStatus, [](){ return new MachineGunTurretStatusType(false); });
82 registerProperty(AccelerationX, [](){ return new AccelerationType(0); });
83 registerProperty(AccelerationY, [](){ return new AccelerationType(0); });
84 registerProperty(AccelerationZ, [](){ return new AccelerationType(0); });
85 registerProperty(MassAirFlow, [](){ return new MassAirFlowType(0); });
86 registerProperty(ButtonEvent, [](){ return new ButtonEventType(ButtonEvents::NoButton); });
87 registerProperty(BatteryVoltage, [](){ return new BatteryVoltageType(0); });
88 registerProperty(InteriorTemperature, [](){ return new InteriorTemperatureType(0); });
89 registerProperty(EngineOilTemperature, [](){ return new EngineOilTemperatureType(0); });
90 registerProperty(VIN, [](){ return new VINType(""); });
91 registerProperty(WMI, [](){ return new WMIType(""); });
92 REGISTERPROPERTYWITHTYPE(TirePressureLeftFront, TirePressureType, 0);
93 REGISTERPROPERTYWITHTYPE(TirePressureRightFront, TirePressureType, 0);
94 REGISTERPROPERTYWITHTYPE(TirePressureLeftRear, TirePressureType, 0);
95 REGISTERPROPERTYWITHTYPE(TirePressureRightRear, TirePressureType, 0);
96 registerProperty( VehiclePowerMode,[](){ return new VehiclePowerModeType(Power::Off); } );
97 REGISTERPROPERTYWITHTYPE(TripMeterA,TripMeterType,0);
98 REGISTERPROPERTYWITHTYPE(TripMeterB,TripMeterType,0);
99 REGISTERPROPERTYWITHTYPE(TripMeterC,TripMeterType,0);
102 std::list<VehicleProperty::Property> VehicleProperty::capabilities()
104 return mCapabilities;
107 AbstractPropertyType* VehicleProperty::getPropertyTypeForPropertyNameValue(VehicleProperty::Property name, std::string value)
110 if(registeredPropertyFactoryMap.count(name) > 0)
112 VehicleProperty::PropertyTypeFactoryCallback cb = registeredPropertyFactoryMap[name];
115 AbstractPropertyType* type = cb();
117 throw std::runtime_error("Cannot return NULL in a PropertyTypeFactory");
119 type->fromString(value);
129 void VehicleProperty::registerProperty(VehicleProperty::Property name, VehicleProperty::PropertyTypeFactoryCallback factory)
131 registeredPropertyFactoryMap[name] = factory;
132 mCapabilities.push_back(name);
135 VehicleProperty vehiclePropertyConstruct;