3 Copyright (C) 2012 Intel Corporation
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.
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.
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
26 #include <abstractsource.h>
29 #include <sys/types.h>
41 VehicleProperty::Property property;
51 std::vector<std::string> arglist;
57 VehicleProperty::Property property;
68 typedef function<std::string (std::string)> ConversionFunction;
70 typedef std::vector<unsigned char> ByteArray;
73 supportedPidsList.push_back(new VehicleSpeedPid());
74 supportedPidsList.push_back(new EngineSpeedPid());
75 supportedPidsList.push_back(new MassAirFlowPid());
76 supportedPidsList.push_back(new VinPid());
77 supportedPidsList.push_back(new WmiPid());
78 supportedPidsList.push_back(new FuelConsumptionPid());
79 supportedPidsList.push_back(new EngineCoolantPid());
80 supportedPidsList.push_back(new AirIntakeTemperaturePid());
85 for(auto itr = supportedPidsList.begin(); itr != supportedPidsList.end(); itr++)
91 ObdPid* createPidFromReply(ByteArray replyVector)
93 for(auto itr = supportedPidsList.begin(); itr != supportedPidsList.end(); itr++)
95 if (!(*itr)->tryParse(replyVector))
100 ObdPid* pid = (*itr)->create();
101 pid->tryParse(replyVector);
106 ObdPid* createPidforProperty(VehicleProperty::Property property)
108 for(auto itr = supportedPidsList.begin(); itr != supportedPidsList.end(); itr++)
110 VehicleProperty::Property p = (*itr)->property;
114 return obj->create();
120 std::list<ObdPid*> supportedPidsList;
123 class OBD2Source : public AbstractSource
127 OBD2Source(AbstractRoutingEngine* re, map<string, string> config);
131 void getPropertyAsync(AsyncPropertyReply *reply);
132 void getRangePropertyAsync(AsyncRangePropertyReply *reply){}
133 AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request);
134 void subscribeToPropertyChanges(VehicleProperty::Property property);
135 void unsubscribeToPropertyChanges(VehicleProperty::Property property);
136 PropertyList supported();
138 int supportedOperations();
140 PropertyList queuedRequests;
141 bool clientConnected;
142 PropertyList activeRequests;
143 void engineSpeed(double speed);
144 void vehicleSpeed(int speed);
145 void mafValue(double maf);
146 void engineCoolantTemp(int temp);
147 PropertyList removeRequests;
148 void setSupported(PropertyList list);
149 void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid) {}
150 void supportedChanged(PropertyList) {}
151 GAsyncQueue* commandQueue;
152 GAsyncQueue* subscriptionAddQueue;
153 GAsyncQueue* subscriptionRemoveQueue;
154 GAsyncQueue* singleShotQueue;
155 GAsyncQueue* responseQueue;
156 std::list<std::string> m_blacklistPidList;
157 std::map<std::string,int> m_blacklistPidCountMap;
158 void setConfiguration(map<string, string> config);
159 //void randomizeProperties();
163 std::string m_btDeviceAddress;
164 std::string m_btAdapterAddress;
165 map<VehicleProperty::Property,AsyncPropertyReply*> propertyReplyMap;
166 void updateProperty(VehicleProperty::Property property,AbstractPropertyType *value);
172 PropertyList m_supportedProperties;
173 GMutex *threadQueueMutex;
174 VehicleProperty::Property Obd2Connect;
175 typedef BasicPropertyType<bool> Obd2ConnectType;
179 #endif // OBD2SOURCE_H