refactored setProperty: made it async with callback
[profile/ivi/automotive-message-broker.git] / plugins / obd2plugin / obd2source.h
1
2 /*
3 Copyright (C) 2012 Intel Corporation
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19
20
21 #ifndef OBD2SOURCE_H
22 #define OBD2SOURCE_H
23
24
25
26 #include <abstractsource.h>
27 #include <string>
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <fcntl.h>
31 #include <termios.h>
32 #include "obdlib.h"
33 #include <glib.h>
34
35
36 class ObdRequest
37 {
38 public:
39   std::string req;
40   std::string arg;
41 };
42
43 class ObdReply
44 {
45 public:
46   std::string req;
47   std::string reply;
48 };
49
50
51 class Obd2Amb
52 {
53 public:
54         Obd2Amb()
55         {
56                 propertyPidMap[VehicleProperty::VehicleSpeed] = "010D1\r";
57                 propertyPidMap[VehicleProperty::EngineSpeed] = "010C1\r";
58                 propertyPidMap[VehicleProperty::MassAirFlow] = "01101\r";
59                 propertyPidMap[VehicleProperty::AirIntakeTemperature] = "010F1\r";
60                 propertyPidMap[VehicleProperty::ThrottlePosition] = "01111\r";
61                 propertyPidMap[VehicleProperty::BatteryVoltage] = "ATRV\r";     propertyPidMap[VehicleProperty::EngineCoolantTemperature]  = "0105a\r";
62                 propertyPidMap[VehicleProperty::EngineLoad] = "01041/r";
63                 propertyPidMap[VehicleProperty::VIN] = "0902/r";
64                 propertyPidMap[VehicleProperty::WMI] = "0902/r";
65                 propertyPidMap[VehicleProperty::EngineOilTemperature] = "015C1\r";
66                 propertyPidMap[VehicleProperty::InteriorTemperature] = "01461\r";
67         }
68
69         map<VehicleProperty::Property, std::string> propertyPidMap;
70 };
71
72 class OBD2Source : public AbstractSource
73 {
74
75 public:
76         OBD2Source(AbstractRoutingEngine* re, map<string, string> config);
77         string uuid();
78         int portHandle;
79         void getPropertyAsync(AsyncPropertyReply *reply);
80         void getRangePropertyAsync(AsyncRangePropertyReply *reply){}
81         AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request);
82         void subscribeToPropertyChanges(VehicleProperty::Property property);
83         void unsubscribeToPropertyChanges(VehicleProperty::Property property);
84         PropertyList supported();
85         PropertyList queuedRequests;
86         bool clientConnected;
87         PropertyList activeRequests;
88         void engineSpeed(double speed);
89         void vehicleSpeed(int speed);
90         void mafValue(double maf);
91         void engineCoolantTemp(int temp);
92         PropertyList removeRequests;
93         void setSupported(PropertyList list);
94         void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid) {}
95         void supportedChanged(PropertyList) {}
96         GAsyncQueue* commandQueue;
97         GAsyncQueue* subscriptionAddQueue;
98         GAsyncQueue* subscriptionRemoveQueue;
99         GAsyncQueue* singleShotQueue;
100         GAsyncQueue* responseQueue;
101         void setConfiguration(map<string, string> config);
102         //void randomizeProperties();
103         std::string m_port;
104         map<VehicleProperty::Property,AsyncPropertyReply*> propertyReplyMap;
105         void updateProperty(VehicleProperty::Property property,AbstractPropertyType *value);
106 private:
107         PropertyList m_supportedProperties;
108         GMutex *threadQueueMutex;
109         
110
111 };
112
113 #endif // OBD2SOURCE_H