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();
137 PropertyList queuedRequests;
138 bool clientConnected;
139 PropertyList activeRequests;
140 void engineSpeed(double speed);
141 void vehicleSpeed(int speed);
142 void mafValue(double maf);
143 void engineCoolantTemp(int temp);
144 PropertyList removeRequests;
145 void setSupported(PropertyList list);
146 void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid) {}
147 void supportedChanged(PropertyList) {}
148 GAsyncQueue* commandQueue;
149 GAsyncQueue* subscriptionAddQueue;
150 GAsyncQueue* subscriptionRemoveQueue;
151 GAsyncQueue* singleShotQueue;
152 GAsyncQueue* responseQueue;
153 std::list<std::string> m_blacklistPidList;
154 std::map<std::string,int> m_blacklistPidCountMap;
155 void setConfiguration(map<string, string> config);
156 //void randomizeProperties();
160 std::string m_btDeviceAddress;
161 std::string m_btAdapterAddress;
162 map<VehicleProperty::Property,AsyncPropertyReply*> propertyReplyMap;
163 void updateProperty(VehicleProperty::Property property,AbstractPropertyType *value);
169 PropertyList m_supportedProperties;
170 GMutex *threadQueueMutex;
171 VehicleProperty::Property Obd2Connect;
172 typedef BasicPropertyType<bool> Obd2ConnectType;
176 #endif // OBD2SOURCE_H