added parking and environment properties
[profile/ivi/automotive-message-broker.git] / lib / vehicleproperty.h
1 /*
2     Copyright (C) 2012  Intel Corporation
3
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.
8
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.
13
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
17 */
18
19
20 #ifndef VEHICLEPROPERTY_H
21 #define VEHICLEPROPERTY_H
22
23 #include "nullptr.h"
24 #include <string>
25 #include <list>
26 #include <set>
27 #include <sstream>
28 #include <map>
29 #include <functional>
30
31 #include <abstractpropertytype.h>
32
33 namespace ButtonEvents {
34 enum ButtonEventType {
35         NoButton = 0,
36         PlayButton = 1,
37         SkipButton = 1 << 1,
38         PrevButton = 1 << 2,
39         PauseButton = 1 << 3,
40         Preset1Button = 1 << 4,
41         Preset2Button = 1 << 5,
42         Preset3Button = 1 << 6,
43         Preset4Button = 1 << 7,
44         StopButton = 1 << 8,
45         NavigateUpButton = 1 << 9,
46         NavigateDownButton = 1 << 10,
47         NavigateLeftButton = 1 << 11,
48         NavigateRightButton = 1 << 12
49 };
50 }
51
52 namespace TurnSignals {
53 enum TurnSignalType
54 {
55         Off=0,
56         Right=1,
57         Left=2,
58         Hazard=3
59 };
60 }
61
62 namespace Transmission {
63 enum TransmissionPositions
64 {
65         Neutral = 0,
66         First,
67         Second,
68         Third,
69         Forth,
70         Fifth,
71         Sixth,
72         Seventh,
73         Eighth,
74         Ninth,
75         Tenth,
76         CVT = 64,
77         Drive = 96,
78         Reverse = 128,
79         Park = 255
80
81 };
82 enum Mode {
83         Normal=0,
84         Sports = 1,
85         Economy = 2,
86         OEMCustom1 = 3,
87         OEMCustom2 = 4
88 };
89
90 enum Type {
91         Unknown = -1,
92         Auto = 0,
93         Manual = 1,
94         CV = 2
95 };
96 }
97
98 namespace Power {
99 /**< Vehicle Power Modes
100  * Off = Vehicle is off and key is in the "off" position.
101  * Accessory1 = Vehicle is off and key is in Accessory1 position.
102  * Accessory2 = Vehicle is off and key is in Accessory2 position.
103  * Run = Vehichle is running.  Key is in the running position.
104  */
105 enum PowerModes
106 {
107         Off = 0,
108         Accessory1 = 1,
109         Accessory2 = 2,
110         Run = 3
111 };
112 }
113
114 namespace Fuel{
115 enum Type
116 {
117         Unknown = -1,
118         Gasoline = 0,
119         High_Octane,
120         Diesel,
121         Electric,
122         Hydrogen
123 };
124
125 enum RefuelPosition
126 {
127         UnknownPosition = -1,
128         Left = 0,
129         Right,
130         Front,
131         Rear
132 };
133 }
134
135 namespace Vehicle {
136 enum Type
137 {
138         Unknown = -1,
139         Sedan = 0,
140         Coupe,
141         Cabriole,
142         Roadster,
143         SUV,
144         Truck
145 };
146 }
147
148 namespace Security {
149 enum Status
150 {
151         Idle = 0,
152         Armed,
153         AlarmDetected
154 };
155 }
156
157
158 class VehicleProperty
159 {
160
161 public:
162         
163
164         VehicleProperty();
165
166         typedef std::string Property;
167         typedef std::function<AbstractPropertyType* (void)> PropertyTypeFactoryCallback;
168
169         /// Various property types:
170
171         static const Property NoValue;
172
173         /**< Vehicle Velocity in km/h */
174         static const Property VehicleSpeed;
175         typedef BasicPropertyType<uint16_t> VehicleSpeedType;
176
177         /**< Engine Speed in rotations per minute */
178         static const Property EngineSpeed;
179         typedef BasicPropertyType<uint16_t> EngineSpeedType;
180
181          /**< Transmission Shift Position
182          * 0 = Neutral
183          * 1 = 1st
184          * 2 = 2nd
185          * ...
186          * 96 = Drive
187          * 128 = Reverse
188          * 255 = Park
189          */
190         static const Property TransmissionShiftPosition;
191         typedef BasicPropertyType<Transmission::TransmissionPositions> TransmissionShiftPositionType;
192
193         /**< Transmission Gear Position
194         * 0 = Neutral
195         * 1 = 1st
196         * 2 = 2nd
197         * ...
198         * 64 = CVT
199         * 128 = Reverse
200         */
201         static const Property TransmissionGearPosition;
202         typedef BasicPropertyType<Transmission::TransmissionPositions> TransmissionGearPositionType;
203
204         static const Property TransmissionMode;
205         typedef BasicPropertyType<Transmission::Mode> TransmissionModeType;
206
207         /**< Throttle position 0-100% */
208         static const Property ThrottlePosition;
209         typedef BasicPropertyType<uint16_t> ThrottlePositionType;
210
211         /**< Wheel brake position.  Engaged = true, Idle = false */
212         static const Property WheelBrake;
213         typedef BasicPropertyType<bool> WheelBrakeType;
214
215         static const Property WheelBrakePressure;
216         typedef BasicPropertyType<uint16_t> WheelBrakePressureType;
217
218         /**< Steering wheel angle (0-359) */
219         static const Property SteeringWheelAngle;
220         typedef BasicPropertyType<uint16_t> SteeringWheelAngleType;
221
222         /**< 0=off, 1=right, 2=left, 3=hazard */
223         static const Property TurnSignal;
224         typedef BasicPropertyType<TurnSignals::TurnSignalType> TurnSignalType;
225
226         /**< Clutch pedal status 0=off, 1=on */
227         static const Property ClutchStatus;
228         typedef BasicPropertyType<bool> ClutchStatusType;
229
230          /**< Oil pressure TODO: units */
231         static const Property EngineOilPressure;
232         typedef BasicPropertyType<uint16_t> EngineOilPressureType;
233
234         /**< Engine coolant temperature in degrees celcius **/
235         static const Property EngineCoolantTemperature;
236         typedef BasicPropertyType<int> EngineCoolantTemperatureType;
237
238         /**< 0=off, 1=on */
239         static const Property MachineGunTurretStatus;
240         typedef BasicPropertyType<bool> MachineGunTurretStatusType;
241
242         /**< Acceleration on the 'x' axis in 1/1000 gravitational acceleration "g-force" */
243         static const Property AccelerationX;
244         typedef BasicPropertyType<uint16_t> AccelerationType;
245
246         /**< Acceleration on the 'y' axis in 1/1000 gravitational acceleration "g-force" */
247         static const Property AccelerationY;
248
249         /**< Acceleration on the 'z' axis in 1/1000 gravitational acceleration "g-force" */
250         static const Property AccelerationZ;
251
252         /**< Mass Air Flow.  TODO: units */
253         static const Property MassAirFlow;
254         typedef BasicPropertyType<uint16_t> MassAirFlowType;
255
256         /**< Button Event @see ButtonEvents::ButtonEventType */
257         static const Property ButtonEvent;
258         typedef BasicPropertyType<ButtonEvents::ButtonEventType> ButtonEventType;
259
260         /**< Air intake temperature in degrees celcius */
261         static const Property AirIntakeTemperature;
262         typedef BasicPropertyType<int> AirIntakeTemperatureType;
263
264         /**< Battery voltage in volts */
265         static const Property BatteryVoltage;
266         typedef BasicPropertyType<double> BatteryVoltageType;
267
268         static const Property BatteryCurrent;
269         typedef BasicPropertyType<double> BatteryCurrentType;
270
271         /**< Interior Air Temperature in degrees celcius */
272         static const Property InteriorTemperature;
273         typedef BasicPropertyType<int> InteriorTemperatureType;
274
275         /**< Engine Oil Temperature in degrees celcius */
276         static const Property EngineOilTemperature;
277         typedef BasicPropertyType<int> EngineOilTemperatureType;
278
279         static const Property EngineOilRemaining;
280         typedef BasicPropertyType<uint16_t> EngineOilRemainingType;
281
282         /**< Vehicle Identification Number (ISO 3779) 17 chars**/
283         static const Property VIN;
284         typedef StringPropertyType VINType;
285
286         /**< World Manufacturer Identifier (SAE) 3 characters. */
287         static const Property WMI;
288         typedef StringPropertyType WMIType;
289
290         /**< Tire pressure in kPa */
291         static const Property TirePressureLeftFront;
292         static const Property TirePressureRightFront;
293         static const Property TirePressureLeftRear;
294         static const Property TirePressureRightRear;
295         typedef BasicPropertyType<double> TirePressureType;
296
297         /**< Tire temperature in degrees C */
298         static const Property TireTemperatureLeftFront;
299         static const Property TireTemperatureRightFront;
300         static const Property TireTemperatureLeftRear;
301         static const Property TireTemperatureRightRear;
302         typedef BasicPropertyType<double> TireTemperatureType;
303         
304         /**< Vehicle Power Mode.
305          *@see Power::PowerModes
306          */
307         static const Property VehiclePowerMode;
308         typedef BasicPropertyType<Power::PowerModes> VehiclePowerModeType;
309
310         static const Property TripMeterA;
311         static const Property TripMeterB;
312         static const Property TripMeterC;
313         typedef BasicPropertyType<uint16_t> TripMeterType;
314
315         static const Property CruiseControlActive;
316         typedef BasicPropertyType<bool> CruiseControlActiveType;
317
318         static const Property CruiseControlSpeed;
319         typedef BasicPropertyType<uint16_t> CruiseControlSpeedType;
320
321         static const Property LightHead;
322         static const Property LightRightTurn;
323         static const Property LightLeftTurn;
324         static const Property LightBrake;
325         static const Property LightFog;
326         static const Property LightHazard;
327         static const Property LightParking;
328         static const Property LightHighBeam;
329         typedef BasicPropertyType<bool> LightStatusType;
330         static const Property InteriorLightDriver;
331         static const Property InteriorLightCenter;
332         static const Property InteriorLightPassenger;
333
334         static const Property EngineLoad;
335         typedef BasicPropertyType<uint16_t> EngineLoadType;
336
337         static const Property Horn;
338         typedef BasicPropertyType<bool> HornType;
339
340         static const Property FuelLevel;
341         typedef BasicPropertyType<uint16_t> FuelLevelType;
342
343         static const Property FuelRange;
344         typedef BasicPropertyType<uint16_t> FuelRangeType;
345
346         static const Property FuelConsumption;
347         typedef BasicPropertyType<uint16_t> FuelConsumptionType;
348
349         static const Property FuelEconomy;
350         typedef BasicPropertyType<uint16_t> FuelEconomyType;
351
352         static const Property FuelAverageEconomy;
353         typedef BasicPropertyType<uint16_t> FuelAverageEconomyType;
354
355         static const Property FuelType;
356         typedef BasicPropertyType<Fuel::Type> FuelTypeType;
357
358         static const Property FuelPositionSide;
359         typedef BasicPropertyType<Fuel::RefuelPosition> FuelPositionSideType;
360
361         static const Property ExteriorBrightness;
362         typedef BasicPropertyType<uint16_t> ExteriorBrightnessType;
363         
364         static const Property Latitude;
365         typedef BasicPropertyType<double> LatitudeType;
366
367         static const Property Longitude;
368         typedef BasicPropertyType<double> LongitudeType;
369
370         static const Property Altitude;
371         typedef BasicPropertyType<double> AltitudeType;
372
373         static const Property Direction;
374         typedef BasicPropertyType<uint> DirectionType;
375
376         static const Property VehicleWidth;
377         static const Property VehicleHeight;
378         static const Property VehicleLength;
379         typedef BasicPropertyType<uint> VehicleSizeType;
380
381
382         static const Property VehicleType;
383         typedef BasicPropertyType<Vehicle::Type> VehicleTypeType;
384
385         static const Property DoorsPerRow;
386         typedef ListPropertyType<BasicPropertyType<uint16_t> > DoorsPerRowType;
387
388         static const Property TransmissionGearType;
389         typedef BasicPropertyType<Transmission::Type> TransmissionGearTypeType;
390
391         static const Property FrontWheelRadius;
392         static const Property RearWheelRadius;
393         typedef BasicPropertyType<uint16_t> WheelRadiusType;
394
395         static const Property WheelTrack;
396         typedef BasicPropertyType<uint> WheelTrackType;
397
398         static const Property Odometer;
399         typedef BasicPropertyType<uint> OdometerType;
400
401         /**< Transmission Fluid Level 0-100%.
402          **/
403         static const Property TransmissionFluidLevel;
404         typedef BasicPropertyType<uint16_t> TransmissionFluidLevelType;
405
406         /**< Brake Fluid Level 0-100%.
407          **/
408         static const Property BrakeFluidLevel;
409         typedef BasicPropertyType<uint16_t> BrakeFluidLevelType;
410
411         /**< Washer Fluid Level 0-100%.
412          **/
413         static const Property WasherFluidLevel;
414         typedef BasicPropertyType<uint16_t> WasherFluidLevelType;
415
416         /**< Securty Alert Status
417          * status of security alert
418          * @see Security::Status
419          */
420         static const Property SecurityAlertStatus;
421         typedef BasicPropertyType<Security::Status> SecurityAlertStatusType;
422
423         /**< Parking Brake Status
424          * status of parking break active (true) or inactive (false)
425          */
426         static const Property ParkingBrakeStatus;
427         typedef BasicPropertyType<bool> ParkingBrakeStatusType;
428
429         /**< Parking Light Status
430          * status of parking lights active (true) or inactive (false)
431          */
432         static const Property ParkingLightStatus;
433         typedef BasicPropertyType<bool> ParkingLightStatusType;
434
435         /**< Hazard Lights Status
436          * status of parking lights active (true) or inactive (false)
437          */
438         static const Property HazardLightStatus;
439         typedef BasicPropertyType<bool> HazardLightStatusType;
440
441
442         /** END PROPERTIES **/
443
444
445         static std::list<VehicleProperty::Property> capabilities();
446         static std::list<VehicleProperty::Property> customProperties();
447
448         /*! getPropertyTypeForPropertyNameValue returns an AbstractPropertyType* for the property name
449           * with the value specified by 'value'.  Ownership of the returned AbstractPropertyType* is
450           * transfered to the caller.
451           */
452         static AbstractPropertyType* getPropertyTypeForPropertyNameValue(Property name, std::string value="");
453
454         /*! registerProperty registers properties with the Vehicle Property system.  Returns true if property
455          *  has been registered successfully.
456          *  @param name - name of property.  Name cannot match any existing property or it will be rejected and
457          *  this method will return false.
458          *  @param factor - callback function that returns an AbstractPropertyType representation of the value.
459          *  custom properties will need to return a custom AbstractPropertyType based object.
460          *  @example :
461          *
462          *  #include <vehicleproperty.h>
463          *  #include <abstractpropertytype.h>
464          *
465          *  //Somewhere in a source plugin:
466          *  ...
467          *  Property VehicleJetEngineStatus = "VehicleJetEngineStatus";
468          *  VehicleProperty::registerProperty(VehicleJetEngineStatus, [](){return new BasicPropertyType<bool>(false);});
469          *  ...
470          *  //other initialization
471          */
472         static bool registerProperty(Property name, PropertyTypeFactoryCallback factory);
473
474
475
476 private:
477         static bool registerPropertyPriv(Property name, PropertyTypeFactoryCallback factory);
478
479         static std::map<Property, PropertyTypeFactoryCallback> registeredPropertyFactoryMap;
480         static std::list<VehicleProperty::Property> mCapabilities;
481         static std::list<VehicleProperty::Property> mCustomProperties;
482 };
483
484 typedef std::list<VehicleProperty::Property> PropertyList;
485 typedef std::set<VehicleProperty::Property> PropertySet;
486
487 #endif // VEHICLEPROPERTY_H