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"
21 #include "listplusplus.h"
27 #define REGISTERPROPERTY(property, defaultValue) \
28 registerPropertyPriv(property, []() { return new property ## Type(defaultValue); });
30 #define REGISTERPROPERTYWITHTYPE(property, type, defaultValue) \
31 registerPropertyPriv(property, []() { return new type(defaultValue); });
35 std::map<VehicleProperty::Property, VehicleProperty::PropertyTypeFactoryCallback> VehicleProperty::registeredPropertyFactoryMap;
37 const VehicleProperty::Property VehicleProperty::NoValue = "NoValue";
38 const VehicleProperty::Property VehicleProperty::VehicleSpeed = "VehicleSpeed";
39 const VehicleProperty::Property VehicleProperty::EngineSpeed = "EngineSpeed";
40 const VehicleProperty::Property VehicleProperty::TransmissionShiftPosition = "TransmissionShiftPosition";
41 const VehicleProperty::Property VehicleProperty::TransmissionGearPosition = "TransmissionGearPostion";
42 const VehicleProperty::Property VehicleProperty::TransmissionMode = "TransmissionMode";
43 const VehicleProperty::Property VehicleProperty::ThrottlePosition = "ThrottlePosition";
44 const VehicleProperty::Property VehicleProperty::WheelBrake = "WheelBrake";
45 const VehicleProperty::Property VehicleProperty::WheelBrakePressure = "WheelBrakePressure";
46 const VehicleProperty::Property VehicleProperty::SteeringWheelAngle = "SteeringWheelAngle";
47 const VehicleProperty::Property VehicleProperty::TurnSignal = "TurnSignal";
48 const VehicleProperty::Property VehicleProperty::ClutchStatus = "ClutchStatus";
49 const VehicleProperty::Property VehicleProperty::EngineOilPressure = "EngineOilPressure";
50 const VehicleProperty::Property VehicleProperty::EngineCoolantTemperature = "EngineCoolantTemperature";
51 const VehicleProperty::Property VehicleProperty::MachineGunTurretStatus = "MachineGunTurretStatus";
52 const VehicleProperty::Property VehicleProperty::AccelerationX = "AccelerationX";
53 const VehicleProperty::Property VehicleProperty::AccelerationY = "AccelerationY";
54 const VehicleProperty::Property VehicleProperty::AccelerationZ = "AccelerationZ";
55 const VehicleProperty::Property VehicleProperty::MassAirFlow = "MassAirFlow";
56 const VehicleProperty::Property VehicleProperty::ButtonEvent = "ButtonEvent";
57 const VehicleProperty::Property VehicleProperty::AirIntakeTemperature = "AirIntakeTemperature";
58 const VehicleProperty::Property VehicleProperty::BatteryVoltage = "BatteryVoltage";
59 const VehicleProperty::Property VehicleProperty::BatteryCurrent = "BatteryCurrent";
60 const VehicleProperty::Property VehicleProperty::InteriorTemperature = "InteriorTemperature";
61 const VehicleProperty::Property VehicleProperty::EngineOilTemperature = "EngineOilTemperature";
62 const VehicleProperty::Property VehicleProperty::VIN = "VIN";
63 const VehicleProperty::Property VehicleProperty::WMI = "WMI";
64 const VehicleProperty::Property VehicleProperty::TirePressureLeftFront = "TirePressureLeftFront";
65 const VehicleProperty::Property VehicleProperty::TirePressureRightFront = "TirePressureRightFront";
66 const VehicleProperty::Property VehicleProperty::TirePressureLeftRear = "TirePressureLeftRear";
67 const VehicleProperty::Property VehicleProperty::TirePressureRightRear = "TirePressureRightRear";
68 const VehicleProperty::Property VehicleProperty::TireTemperatureLeftFront = "TireTemperatureLeftFront";
69 const VehicleProperty::Property VehicleProperty::TireTemperatureRightFront = "TireTemperatureRightFront";
70 const VehicleProperty::Property VehicleProperty::TireTemperatureLeftRear = "TireTemperatureLeftRear";
71 const VehicleProperty::Property VehicleProperty::TireTemperatureRightRear = "TireTemperatureRightRear";
72 const VehicleProperty::Property VehicleProperty::VehiclePowerMode = "VehiclePowerMode";
73 const VehicleProperty::Property VehicleProperty::TripMeterA = "TripMeterA";
74 const VehicleProperty::Property VehicleProperty::TripMeterB = "TripMeterB";
75 const VehicleProperty::Property VehicleProperty::TripMeterC = "TripMeterC";
76 const VehicleProperty::Property VehicleProperty::CruiseControlActive = "CruiseControlActive";
77 const VehicleProperty::Property VehicleProperty::CruiseControlSpeed = "CruiseControlSpeed";
78 const VehicleProperty::Property VehicleProperty::LightHead = "LightHead";
79 const VehicleProperty::Property VehicleProperty::LightLeftTurn = "LightLeftTurn";
80 const VehicleProperty::Property VehicleProperty::LightRightTurn = "LightRightTurn";
81 const VehicleProperty::Property VehicleProperty::LightParking = "LightParking";
82 const VehicleProperty::Property VehicleProperty::LightFog = "LightFog";
83 const VehicleProperty::Property VehicleProperty::LightHazard= "LightHazard";
84 const VehicleProperty::Property VehicleProperty::LightHighBeam = "LightHighBeam";
85 const VehicleProperty::Property VehicleProperty::LightBrake= "LightBrake";
86 const VehicleProperty::Property VehicleProperty::InteriorLightDriver = "InteriorLightDriver";
87 const VehicleProperty::Property VehicleProperty::InteriorLightCenter = "InteriorLightCenter";
88 const VehicleProperty::Property VehicleProperty::InteriorLightPassenger = "InteriorLightPassenger";
89 const VehicleProperty::Property VehicleProperty::EngineLoad = "EngineLoad";
90 const VehicleProperty::Property VehicleProperty::Horn = "Horn";
91 const VehicleProperty::Property VehicleProperty::FuelLevel = "FuelLevel";
92 const VehicleProperty::Property VehicleProperty::FuelConsumption = "FuelConsumption";
93 const VehicleProperty::Property VehicleProperty::FuelRange = "FuelRange";
94 const VehicleProperty::Property VehicleProperty::FuelEconomy = "FuelEconomy";
95 const VehicleProperty::Property VehicleProperty::FuelAverageEconomy = "FuelAverageEconomy";
96 const VehicleProperty::Property VehicleProperty::FuelType = "FuelType";
97 const VehicleProperty::Property VehicleProperty::FuelPositionSide = "FuelPositionSide";
98 const VehicleProperty::Property VehicleProperty::EngineOilRemaining = "EngineOilRemaining";
99 const VehicleProperty::Property VehicleProperty::ExteriorBrightness = "ExteriorBrightness";
100 const VehicleProperty::Property VehicleProperty::Latitude = "Latitude";
101 const VehicleProperty::Property VehicleProperty::Longitude = "Longitude";
102 const VehicleProperty::Property VehicleProperty::Direction = "Direction";
103 const VehicleProperty::Property VehicleProperty::Altitude = "Altitude";
104 const VehicleProperty::Property VehicleProperty::VehicleWidth = "VehicleWidth";
105 const VehicleProperty::Property VehicleProperty::VehicleHeight = "VehicleHeight";
106 const VehicleProperty::Property VehicleProperty::VehicleLength = "VehicleLength";
107 const VehicleProperty::Property VehicleProperty::VehicleType = "VehicleType";
108 const VehicleProperty::Property VehicleProperty::DoorsPerRow = "DoorsPerRow";
109 const VehicleProperty::Property VehicleProperty::TransmissionGearType = "TransmissionGearType";
110 const VehicleProperty::Property VehicleProperty::FrontWheelRadius = "FrontWheelRadius";
111 const VehicleProperty::Property VehicleProperty::RearWheelRadius = "RearWheelRadius";
112 const VehicleProperty::Property VehicleProperty::WheelTrack = "WheelTrack";
113 const VehicleProperty::Property VehicleProperty::Odometer = "Odometer";
114 const VehicleProperty::Property VehicleProperty::TransmissionFluidLevel = "TransmissionFluidLevel";
115 const VehicleProperty::Property VehicleProperty::BrakeFluidLevel = "BrakeFluidLevel";
116 const VehicleProperty::Property VehicleProperty::WasherFluidLevel = "WasherFluidLevel";
117 const VehicleProperty::Property VehicleProperty::SecurityAlertStatus = "SecurityAlertStatus";
118 const VehicleProperty::Property VehicleProperty::ParkingBrakeStatus = "ParkingBrakeStatus";
119 const VehicleProperty::Property VehicleProperty::ParkingLightStatus = "ParkingLightStatus";
120 const VehicleProperty::Property VehicleProperty::HazardLightStatus = "HazardLightStatus";
123 std::list<VehicleProperty::Property> VehicleProperty::mCapabilities;
124 std::list<VehicleProperty::Property> VehicleProperty::mCustomProperties;
126 VehicleProperty::VehicleProperty()
128 registerPropertyPriv( VehicleSpeed, [](){ return new VehicleSpeedType(0); });
129 registerPropertyPriv(EngineSpeed, [](){ return new EngineSpeedType(0); });
130 registerPropertyPriv(TransmissionShiftPosition, [](){ return new TransmissionShiftPositionType(Transmission::Neutral); });
131 registerPropertyPriv(TransmissionGearPosition, [](){ return new TransmissionGearPositionType(Transmission::Neutral); });
132 REGISTERPROPERTY(TransmissionMode,Transmission::Normal);
133 registerPropertyPriv(ThrottlePosition, [](){ return new ThrottlePositionType(0); });
134 registerPropertyPriv(WheelBrake, [](){ return new WheelBrakeType(false); });
135 REGISTERPROPERTY(WheelBrakePressure,0);
136 registerPropertyPriv(SteeringWheelAngle, [](){ return new SteeringWheelAngleType(0); });
137 registerPropertyPriv(TurnSignal, [](){ return new TurnSignalType(TurnSignals::Off); });
138 registerPropertyPriv(ClutchStatus, [](){ return new ClutchStatusType(false); });
139 registerPropertyPriv(EngineOilPressure, [](){ return new EngineOilPressureType(0); });
140 registerPropertyPriv(EngineOilTemperature, [](){ return new EngineOilTemperatureType(0); });
141 REGISTERPROPERTY(EngineOilRemaining,0);
142 registerPropertyPriv(EngineCoolantTemperature, [](){ return new EngineCoolantTemperatureType(0); });
143 registerPropertyPriv(MachineGunTurretStatus, [](){ return new MachineGunTurretStatusType(false); });
144 registerPropertyPriv(AccelerationX, [](){ return new AccelerationType(0); });
145 registerPropertyPriv(AccelerationY, [](){ return new AccelerationType(0); });
146 registerPropertyPriv(AccelerationZ, [](){ return new AccelerationType(0); });
147 registerPropertyPriv(MassAirFlow, [](){ return new MassAirFlowType(0); });
148 registerPropertyPriv(ButtonEvent, [](){ return new ButtonEventType(ButtonEvents::NoButton); });
149 REGISTERPROPERTY(AirIntakeTemperature,0)
150 registerPropertyPriv(BatteryVoltage, [](){ return new BatteryVoltageType(0); });
151 REGISTERPROPERTY(BatteryCurrent,0);
152 registerPropertyPriv(InteriorTemperature, [](){ return new InteriorTemperatureType(0); });
153 registerPropertyPriv(VIN, [](){ return new VINType(""); });
154 registerPropertyPriv(WMI, [](){ return new WMIType(""); });
155 REGISTERPROPERTYWITHTYPE(TirePressureLeftFront, TirePressureType, 0);
156 REGISTERPROPERTYWITHTYPE(TirePressureRightFront, TirePressureType, 0);
157 REGISTERPROPERTYWITHTYPE(TirePressureLeftRear, TirePressureType, 0);
158 REGISTERPROPERTYWITHTYPE(TirePressureRightRear, TirePressureType, 0);
159 REGISTERPROPERTYWITHTYPE(TireTemperatureLeftFront,TireTemperatureType,0);
160 REGISTERPROPERTYWITHTYPE(TireTemperatureRightFront,TireTemperatureType,0);
161 REGISTERPROPERTYWITHTYPE(TireTemperatureLeftRear,TireTemperatureType,0);
162 REGISTERPROPERTYWITHTYPE(TireTemperatureRightRear,TireTemperatureType,0);
163 registerPropertyPriv( VehiclePowerMode,[](){ return new VehiclePowerModeType(Power::Off); } );
164 REGISTERPROPERTYWITHTYPE(TripMeterA,TripMeterType,0);
165 REGISTERPROPERTYWITHTYPE(TripMeterB,TripMeterType,0);
166 REGISTERPROPERTYWITHTYPE(TripMeterC,TripMeterType,0);
167 REGISTERPROPERTY(CruiseControlActive, false);
168 REGISTERPROPERTY(CruiseControlSpeed,0);
169 REGISTERPROPERTYWITHTYPE(LightHead, LightStatusType, false);
170 REGISTERPROPERTYWITHTYPE(LightLeftTurn,LightStatusType, false);
171 REGISTERPROPERTYWITHTYPE(LightRightTurn, LightStatusType, false);
172 REGISTERPROPERTYWITHTYPE(LightParking, LightStatusType, false);
173 REGISTERPROPERTYWITHTYPE(LightFog, LightStatusType, false);
174 REGISTERPROPERTYWITHTYPE(LightHazard, LightStatusType, false);
175 REGISTERPROPERTYWITHTYPE(LightHighBeam, LightStatusType, false);
176 REGISTERPROPERTYWITHTYPE(LightBrake, LightStatusType, false);
177 REGISTERPROPERTYWITHTYPE(InteriorLightDriver, LightStatusType, false);
178 REGISTERPROPERTYWITHTYPE(InteriorLightPassenger, LightStatusType, false);
179 REGISTERPROPERTYWITHTYPE(InteriorLightCenter, LightStatusType, false);
180 REGISTERPROPERTY(EngineLoad,0);
181 REGISTERPROPERTY(Horn, false);
182 REGISTERPROPERTY(FuelLevel, 0);
183 REGISTERPROPERTY(FuelRange, 0);
184 REGISTERPROPERTY(FuelConsumption, 0);
185 REGISTERPROPERTY(FuelEconomy, 0);
186 REGISTERPROPERTY(FuelAverageEconomy, 0);
187 REGISTERPROPERTY(FuelType, Fuel::Unknown);
188 REGISTERPROPERTY(FuelPositionSide, Fuel::UnknownPosition);
189 REGISTERPROPERTY(ExteriorBrightness, 0);
190 REGISTERPROPERTYWITHTYPE(VehicleWidth,VehicleSizeType,0);
191 REGISTERPROPERTYWITHTYPE(VehicleHeight,VehicleSizeType,0);
192 REGISTERPROPERTYWITHTYPE(VehicleLength,VehicleSizeType,0);
193 REGISTERPROPERTY(Latitude,0);
194 REGISTERPROPERTY(Longitude,0);
195 REGISTERPROPERTY(Altitude,0);
196 REGISTERPROPERTY(Direction,0);
197 REGISTERPROPERTY(VehicleType,Vehicle::Unknown);
198 registerPropertyPriv(DoorsPerRow,[]() { BasicPropertyType<uint16_t> d(0); return new DoorsPerRowType(&d); });
199 REGISTERPROPERTY(TransmissionGearType,Transmission::Unknown);
200 REGISTERPROPERTYWITHTYPE(FrontWheelRadius, WheelRadiusType, 0);
201 REGISTERPROPERTYWITHTYPE(RearWheelRadius, WheelRadiusType, 0);
202 REGISTERPROPERTY(WheelTrack,0);
203 REGISTERPROPERTY(Odometer,0);
204 REGISTERPROPERTY(TransmissionFluidLevel,0);
205 REGISTERPROPERTY(BrakeFluidLevel,0);
206 REGISTERPROPERTY(WasherFluidLevel,0);
207 REGISTERPROPERTY(SecurityAlertStatus,0);
208 REGISTERPROPERTY(ParkingBrakeStatus,false);
209 REGISTERPROPERTY(ParkingLightStatus,false);
210 REGISTERPROPERTY(HazardLightStatus,false);
215 std::list<VehicleProperty::Property> VehicleProperty::capabilities()
217 return mCapabilities;
220 std::list<VehicleProperty::Property> VehicleProperty::customProperties()
222 return mCustomProperties;
225 AbstractPropertyType* VehicleProperty::getPropertyTypeForPropertyNameValue(VehicleProperty::Property name, std::string value)
227 if(registeredPropertyFactoryMap.count(name) > 0)
229 VehicleProperty::PropertyTypeFactoryCallback cb = registeredPropertyFactoryMap[name];
232 AbstractPropertyType* type = cb();
234 throw std::runtime_error("Cannot return NULL in a PropertyTypeFactory");
237 type->fromString(value);
246 bool VehicleProperty::registerProperty(VehicleProperty::Property name, VehicleProperty::PropertyTypeFactoryCallback factory)
249 mCustomProperties.push_back(name);
251 return registerPropertyPriv(name, factory);
254 bool VehicleProperty::registerPropertyPriv(VehicleProperty::Property name, VehicleProperty::PropertyTypeFactoryCallback factory)
256 if(ListPlusPlus<Property>(&mCapabilities).contains(name))
258 DebugOut(0)<<__FUNCTION__<<" ERROR: property '"<<name<<"'' already registered."<<endl;
262 registeredPropertyFactoryMap[name] = factory;
263 mCapabilities.push_back(name);
269 VehicleProperty vehiclePropertyConstruct;