2 Copyright (C) 2012 Intel Corporation
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.
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.
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
19 #include "exampleplugin.h"
20 #include "timestamp.h"
23 #include <boost/assert.hpp>
30 uint16_t accelerationX = 0;
31 Transmission::TransmissionPositions transmissionShiftPostion = Transmission::Neutral;
32 uint16_t steeringWheelAngle=0;
33 uint16_t throttlePos = 0;
34 uint16_t engineCoolant = 40;
35 bool machineGun = false;
37 static gboolean timeoutCallback(gpointer data)
39 ExampleSourcePlugin* src = (ExampleSourcePlugin*)data;
41 src->randomizeProperties();
46 ExampleSourcePlugin::ExampleSourcePlugin(AbstractRoutingEngine* re, map<string, string> config)
47 :AbstractSource(re, config), velocity(0), engineSpeed(0)
49 debugOut("setting timeout");
50 g_timeout_add(1000, timeoutCallback, this );
52 addPropertySupport(VehicleProperty::EngineSpeed, Zone::None);
53 addPropertySupport(VehicleProperty::VehicleSpeed, Zone::None);
54 addPropertySupport(VehicleProperty::AccelerationX, Zone::None);
55 addPropertySupport(VehicleProperty::TransmissionShiftPosition, Zone::None);
56 addPropertySupport(VehicleProperty::SteeringWheelAngle, Zone::None);
57 addPropertySupport(VehicleProperty::ThrottlePosition, Zone::None);
58 addPropertySupport(VehicleProperty::EngineCoolantTemperature, Zone::None);
59 addPropertySupport(VehicleProperty::VIN, Zone::None);
60 addPropertySupport(VehicleProperty::WMI, Zone::None);
61 addPropertySupport(VehicleProperty::BatteryVoltage, Zone::None);
62 addPropertySupport(VehicleProperty::MachineGunTurretStatus, Zone::None);
63 addPropertySupport(VehicleProperty::ExteriorBrightness, Zone::None);
64 addPropertySupport(VehicleProperty::DoorsPerRow, Zone::None);
65 addPropertySupport(VehicleProperty::AirbagStatus, Zone::FrontLeft);
67 re->setSupported(supported(), this);
72 extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<string, string> config)
74 return new ExampleSourcePlugin(routingengine, config);
78 string ExampleSourcePlugin::uuid()
80 return "6dd4268a-c605-4a06-9034-59c1e8344c8e";
84 void ExampleSourcePlugin::getPropertyAsync(AsyncPropertyReply *reply)
86 DebugOut()<<"ExampleSource: getPropertyAsync called for property: "<<reply->property<<endl;
90 if(reply->property == VehicleProperty::VehicleSpeed)
92 VehicleProperty::VehicleSpeedType temp(velocity);
94 reply->success = true;
95 reply->completed(reply);
97 else if(reply->property == VehicleProperty::EngineSpeed)
99 VehicleProperty::EngineSpeedType temp(engineSpeed);
100 reply->value = &temp;
101 reply->success = true;
102 reply->completed(reply);
104 else if(reply->property == VehicleProperty::AccelerationX)
106 VehicleProperty::AccelerationXType temp(accelerationX);
107 reply->value = &temp;
108 reply->success = true;
109 reply->completed(reply);
111 else if(reply->property == VehicleProperty::TransmissionShiftPosition)
113 VehicleProperty::TransmissionShiftPositionType temp(transmissionShiftPostion);
114 reply->value = &temp;
115 reply->success = true;
116 reply->completed(reply);
118 else if(reply->property == VehicleProperty::SteeringWheelAngle)
120 VehicleProperty::SteeringWheelAngleType temp(steeringWheelAngle);
121 reply->value = &temp;
122 reply->success = true;
123 reply->completed(reply);
125 else if(reply->property == VehicleProperty::VIN)
127 VehicleProperty::VINType temp("ABC00000000000000");
128 reply->value = &temp;
129 reply->success = true;
130 reply->completed(reply);
132 else if(reply->property == VehicleProperty::WMI)
134 VehicleProperty::WMIType temp("abc");
135 reply->value = &temp;
136 reply->success = true;
137 reply->completed(reply);
139 else if(reply->property == VehicleProperty::BatteryVoltage)
141 VehicleProperty::BatteryVoltageType temp(12.6);
142 reply->value = &temp;
143 reply->success = true;
144 reply->completed(reply);
146 else if(reply->property == VehicleProperty::ExteriorBrightness)
148 VehicleProperty::ExteriorBrightnessType temp(1000);
149 reply->value = &temp;
150 reply->success = true;
151 reply->completed(reply);
153 else if(reply->property == VehicleProperty::DoorsPerRow)
155 VehicleProperty::DoorsPerRowType temp;
157 BasicPropertyType<uint16_t> row1(2);
158 BasicPropertyType<uint16_t> row2(2);
159 BasicPropertyType<uint16_t> row3(1);
165 reply->value = &temp;
166 reply->success = true;
167 reply->completed(reply);
169 else if(reply->property == VehicleProperty::AirbagStatus)
172 if(reply->zoneFilter != Zone::None && reply->zoneFilter != Zone::FrontLeft)
174 reply->success = false;
175 reply->error = AsyncPropertyReply::ZoneNotSupported;
176 reply->completed(reply);
179 VehicleProperty::AirbagStatusType temp(Airbag::Active);
180 temp.zone = Zone::FrontLeft;
182 reply->value = &temp;
183 reply->success = true;
184 reply->completed(reply);
186 else if(reply->property == VehicleProperty::MachineGunTurretStatus)
188 VehicleProperty::MachineGunTurretStatusType temp(true);
189 reply->value = &temp;
190 reply->success = true;
191 reply->completed(reply);
195 void ExampleSourcePlugin::getRangePropertyAsync(AsyncRangePropertyReply *reply)
200 AsyncPropertyReply *ExampleSourcePlugin::setProperty(AsyncSetPropertyRequest request )
205 void ExampleSourcePlugin::subscribeToPropertyChanges(VehicleProperty::Property property)
207 mRequests.push_back(property);
210 PropertyList ExampleSourcePlugin::supported()
215 int ExampleSourcePlugin::supportedOperations()
217 return Get | Set | GetRanged;
220 void ExampleSourcePlugin::unsubscribeToPropertyChanges(VehicleProperty::Property property)
222 mRequests.remove(property);
225 void ExampleSourcePlugin::randomizeProperties()
227 velocity = 1 + (255.00 * (rand() / (RAND_MAX + 1.0)));
228 engineSpeed = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
229 accelerationX = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
230 transmissionShiftPostion = Transmission::TransmissionPositions(1 + (6.00 * (rand() / (RAND_MAX + 1.0))));
231 steeringWheelAngle = 1 + (359.00 * (rand() / (RAND_MAX + 1.0)));
232 throttlePos = 1 + (100.00 * (rand() / (RAND_MAX + 1.0)));
233 engineCoolant = 1 + (40.00 * (rand() / (RAND_MAX + 140.0)));
235 DebugOut()<<"setting velocity to: "<<velocity<<endl;
236 DebugOut()<<"setting enginespeed to: "<<engineSpeed<<endl;
238 VehicleProperty::VehicleSpeedType vel(velocity);
239 VehicleProperty::EngineSpeedType es(engineSpeed);
240 VehicleProperty::AccelerationXType ac(accelerationX);
241 VehicleProperty::SteeringWheelAngleType swa(steeringWheelAngle);
242 VehicleProperty::TransmissionShiftPositionType tsp(transmissionShiftPostion);
243 VehicleProperty::ThrottlePositionType tp(throttlePos);
244 VehicleProperty::EngineCoolantTemperatureType ec(engineCoolant);
245 VehicleProperty::MachineGunTurretStatusType mgt(machineGun);
247 machineGun = !machineGun;
249 vel.timestamp = amb::currentTime();
250 es.timestamp = amb::currentTime();
251 ac.timestamp = amb::currentTime();
252 swa.timestamp = amb::currentTime();
253 tsp.timestamp = amb::currentTime();
254 tp.timestamp = amb::currentTime();
255 ec.timestamp = amb::currentTime();
257 routingEngine->updateProperty(VehicleProperty::VehicleSpeed, &vel, uuid());
258 routingEngine->updateProperty(VehicleProperty::EngineSpeed, &es, uuid());
259 routingEngine->updateProperty(VehicleProperty::AccelerationX, &ac, uuid());
260 routingEngine->updateProperty(VehicleProperty::SteeringWheelAngle, &swa, uuid());
261 routingEngine->updateProperty(VehicleProperty::TransmissionShiftPosition,&tsp, uuid());
262 routingEngine->updateProperty(VehicleProperty::ThrottlePosition, &tp, uuid());
263 routingEngine->updateProperty(VehicleProperty::EngineCoolantTemperature, &ec, uuid());
264 //routingEngine->updateProperty(VehicleProperty::MachineGunTurretStatus, &mgt);
267 void ExampleSourcePlugin::addPropertySupport(VehicleProperty::Property property, Zone::Type zone)
269 mSupported.push_back(property);
271 std::list<Zone::Type> zones;
273 zones.push_back(zone);
275 PropertyInfo info(0, zones);
277 propertyInfoMap[property] = info;