added trip meter property
[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
30 #include <abstractpropertytype.h>
31
32 namespace ButtonEvents {
33 enum ButtonEventType {
34         NoButton = 0,
35         PlayButton = 1,
36         SkipButton = 1 << 1,
37         PrevButton = 1 << 2,
38         PauseButton = 1 << 3,
39         Preset1Button = 1 << 4,
40         Preset2Button = 1 << 5,
41         Preset3Button = 1 << 6,
42         Preset4Button = 1 << 7,
43         StopButton = 1 << 8,
44         NavigateUpButton = 1 << 9,
45         NavigateDownButton = 1 << 10,
46         NavigateLeftButton = 1 << 11,
47         NavigateRightButton = 1 << 12
48 };
49 }
50
51 namespace TurnSignals {
52 enum TurnSignalType
53 {
54         Off=0,
55         Right=1,
56         Left=2,
57         Hazard=3
58 };
59 }
60
61 namespace Transmission {
62 enum TransmissionPositions
63 {
64         Neutral = 0,
65         First,
66         Second,
67         Third,
68         Forth,
69         Fifth,
70         Sixth,
71         Seventh,
72         Eighth,
73         Ninth,
74         Tenth,
75         CVT = 64,
76         Drive = 96,
77         Reverse = 128,
78         Park = 255
79
80 };
81 }
82
83 namespace Power {
84 enum PowerModes
85 {
86         Off = 0,
87         Accessory1 = 1,
88         Accessory2 = 2,
89         Run = 3
90 };
91 }
92
93 class VehicleProperty
94 {
95
96 public:
97         
98
99         VehicleProperty();
100
101         typedef std::string Property;
102         typedef std::function<AbstractPropertyType* (void)> PropertyTypeFactoryCallback;
103
104         /// Various property types:
105
106         static const Property NoValue;
107
108         /**< Vehicle Velocity in km/h */
109         static const Property VehicleSpeed;
110         typedef BasicPropertyType<uint16_t> VehicleSpeedType;
111
112         /**< Engine Speed in rotations per minute */
113         static const Property EngineSpeed;
114         typedef BasicPropertyType<uint16_t> EngineSpeedType;
115
116          /**< Transmission Shift Position
117          * 0 = Neutral
118          * 1 = 1st
119          * 2 = 2nd
120          * ...
121          * 96 = Drive
122          * 128 = Reverse
123          * 255 = Park
124          */
125         static const Property TransmissionShiftPosition;
126         typedef BasicPropertyType<Transmission::TransmissionPositions> TransmissionShiftPositionType;
127
128         /**< Transmission Gear Position
129         * 0 = Neutral
130         * 1 = 1st
131         * 2 = 2nd
132         * ...
133         * 64 = CVT
134         * 128 = Reverse
135         */
136         static const Property TransmissionGearPosition;
137         typedef BasicPropertyType<Transmission::TransmissionPositions> TransmissionGearPositionType;
138
139         /**< Throttle position 0-100% */
140         static const Property ThrottlePosition;
141         typedef BasicPropertyType<uint16_t> ThrottlePositionType;
142
143         /**< Wheel brake position.  Engaged = true, Idle = false */
144         static const Property WheelBrake;
145         typedef BasicPropertyType<bool> WheelBrakeType;
146
147         /**< Steering wheel angle (0-359) */
148         static const Property SteeringWheelAngle;
149         typedef BasicPropertyType<uint16_t> SteeringWheelAngleType;
150
151         /**< 0=off, 1=right, 2=left, 3=hazard */
152         static const Property TurnSignal;
153         typedef BasicPropertyType<TurnSignals::TurnSignalType> TurnSignalType;
154
155         /**< Clutch pedal status 0=off, 1=on */
156         static const Property ClutchStatus;
157         typedef BasicPropertyType<bool> ClutchStatusType;
158
159          /**< Oil pressure TODO: units */
160         static const Property EngineOilPressure;
161         typedef BasicPropertyType<uint16_t> EngineOilPressureType;
162
163         /**< Engine coolant temperature in degrees celcius **/
164         static const Property EngineCoolantTemperature;
165         typedef BasicPropertyType<int> EngineCoolantTemperatureType;
166
167         /**< 0=off, 1=on */
168         static const Property MachineGunTurretStatus;
169         typedef BasicPropertyType<bool> MachineGunTurretStatusType;
170
171         /**< Acceleration on the 'x' axis in 1/1000 gravitational acceleration "g-force" */
172         static const Property AccelerationX;
173         typedef BasicPropertyType<uint16_t> AccelerationType;
174
175         /**< Acceleration on the 'y' axis in 1/1000 gravitational acceleration "g-force" */
176         static const Property AccelerationY;
177
178         /**< Acceleration on the 'z' axis in 1/1000 gravitational acceleration "g-force" */
179         static const Property AccelerationZ;
180
181         /**< Mass Air Flow.  TODO: units */
182         static const Property MassAirFlow;
183         typedef BasicPropertyType<uint16_t> MassAirFlowType;
184
185         /**< Button Event @see ButtonEvents::ButtonEventType */
186         static const Property ButtonEvent;
187         typedef BasicPropertyType<ButtonEvents::ButtonEventType> ButtonEventType;
188
189         /**< Air intake temperature in degrees celcius */
190         static const Property AirIntakeTemperature;
191         typedef BasicPropertyType<int> AirIntakeTemperatureType;
192
193         /**< Battery voltage in volts */
194         static const Property BatteryVoltage;
195         typedef BasicPropertyType<double> BatteryVoltageType;
196
197         /**< Interior Air Temperature in degrees celcius */
198         static const Property InteriorTemperature;
199         typedef BasicPropertyType<int> InteriorTemperatureType;
200
201         /**< Engine Oil Temperature in degrees celcius */
202         static const Property EngineOilTemperature;
203         typedef BasicPropertyType<int> EngineOilTemperatureType;
204
205         /**< Vehicle Identification Number (ISO 3779) 17 chars**/
206         static const Property VIN;
207         typedef StringPropertyType VINType;
208
209         /**< World Manufacturer Identifier (SAE) 3 characters. */
210         static const Property WMI;
211         typedef StringPropertyType WMIType;
212
213         /**< Tire pressure in kPa */
214         static const Property TirePressureLeftFront;
215         static const Property TirePressureRightFront;
216         static const Property TirePressureLeftRear;
217         static const Property TirePressureRightRear;
218         typedef BasicPropertyType<uint16_t> TirePressureType;
219
220         static const Property VehiclePowerMode;
221         typedef BasicPropertyType<Power::PowerModes> VehiclePowerModeType;
222
223         static const Property TripMeterA;
224         static const Property TripMeterB;
225         static const Property TripMeterC;
226         typedef BasicPropertyType<uint16_t> TripMeterType;
227
228         static std::list<VehicleProperty::Property> capabilities();
229
230         /*! getPropertyTypeForPropertyNameValue returns an AbstractPropertyType* for the property name
231           * with the value specified by 'value'.  Ownership of the returned AbstractPropertyType* is
232           * transfered to the caller.
233           */
234         static AbstractPropertyType* getPropertyTypeForPropertyNameValue(Property name, std::string value);
235
236         static void registerProperty(Property name, PropertyTypeFactoryCallback factory);
237
238 private:
239
240         static std::map<Property, PropertyTypeFactoryCallback> registeredPropertyFactoryMap;
241         static std::list<VehicleProperty::Property> mCapabilities;
242 };
243
244 typedef std::list<VehicleProperty::Property> PropertyList;
245 typedef std::set<VehicleProperty::Property> PropertySet;
246
247 #endif // VEHICLEPROPERTY_H