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;
56 std::string statusStr;
57 VehicleProperty::Property property;
62 VehicleProperty::Property property;
73 typedef function<std::string (std::string)> ConversionFunction;
75 typedef std::vector<unsigned char> ByteArray;
78 supportedPidsList.push_back(new VehicleSpeedPid());
79 supportedPidsList.push_back(new EngineSpeedPid());
80 supportedPidsList.push_back(new MassAirFlowPid());
81 supportedPidsList.push_back(new VinPid());
82 supportedPidsList.push_back(new WmiPid());
83 supportedPidsList.push_back(new FuelConsumptionPid());
84 supportedPidsList.push_back(new EngineCoolantPid());
85 supportedPidsList.push_back(new AirIntakeTemperaturePid());
86 supportedPidsList.push_back(new EngineLoadPid());
87 supportedPidsList.push_back(new ThrottlePositionPid());
88 supportedPidsList.push_back(new BatteryVoltagePid());
93 for(auto itr = supportedPidsList.begin(); itr != supportedPidsList.end(); itr++)
99 ObdPid* createPidFromReply(ByteArray replyVector)
101 for(auto itr = supportedPidsList.begin(); itr != supportedPidsList.end(); itr++)
103 if (!(*itr)->tryParse(replyVector))
108 ObdPid* pid = (*itr)->create();
109 //pid->tryParse(replyVector);
114 ObdPid* createPidforProperty(VehicleProperty::Property property)
116 for(auto itr = supportedPidsList.begin(); itr != supportedPidsList.end(); itr++)
118 VehicleProperty::Property p = (*itr)->property;
122 return obj->create();
128 std::list<ObdPid*> supportedPidsList;
131 class OBD2Source : public AbstractSource
135 OBD2Source(AbstractRoutingEngine* re, map<string, string> config);
139 void getPropertyAsync(AsyncPropertyReply *reply);
140 void getRangePropertyAsync(AsyncRangePropertyReply *reply){}
141 AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request);
142 void subscribeToPropertyChanges(VehicleProperty::Property property);
143 void unsubscribeToPropertyChanges(VehicleProperty::Property property);
144 PropertyList supported();
146 int supportedOperations();
148 PropertyList queuedRequests;
149 bool clientConnected;
150 PropertyList activeRequests;
151 void engineSpeed(double speed);
152 void vehicleSpeed(int speed);
153 void mafValue(double maf);
154 void engineCoolantTemp(int temp);
155 PropertyList removeRequests;
156 void setSupported(PropertyList list);
157 void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid) {}
158 void supportedChanged(PropertyList) {}
159 GAsyncQueue* commandQueue;
160 GAsyncQueue* statusQueue;
161 GAsyncQueue* subscriptionAddQueue;
162 GAsyncQueue* subscriptionRemoveQueue;
163 GAsyncQueue* singleShotQueue;
164 GAsyncQueue* responseQueue;
165 std::list<std::string> m_blacklistPidList;
166 std::map<std::string,int> m_blacklistPidCountMap;
167 void setConfiguration(map<string, string> config);
168 //void randomizeProperties();
172 std::string m_btDeviceAddress;
173 std::string m_btAdapterAddress;
174 map<VehicleProperty::Property,AsyncPropertyReply*> propertyReplyMap;
175 void updateProperty(VehicleProperty::Property property,AbstractPropertyType *value);
181 PropertyList m_supportedProperties;
182 std::map<VehicleProperty::Property, AbstractPropertyType*> oldValueMap;
183 GMutex *threadQueueMutex;
184 typedef BasicPropertyType<bool> Obd2ConnectType;
188 #endif // OBD2SOURCE_H