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 Zone::ZoneList airbagZones;
68 airbagZones.push_back(Zone::FrontLeft);
69 airbagZones.push_back(Zone::FrontRight);
70 airbagZones.push_back(Zone::RearLeft);
71 airbagZones.push_back(Zone::RearRight);
73 airbagStatus[Zone::FrontLeft] = Airbag::Active;
74 airbagStatus[Zone::FrontRight] = Airbag::Inactive;
75 airbagStatus[Zone::RearLeft] = Airbag::Deployed;
76 airbagStatus[Zone::RearRight] = Airbag::Deployed;
78 PropertyInfo airbagInfo(0,airbagZones);
80 propertyInfoMap[VehicleProperty::AirbagStatus] = airbagInfo;
82 re->setSupported(supported(), this);
87 extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<string, string> config)
89 return new ExampleSourcePlugin(routingengine, config);
93 string ExampleSourcePlugin::uuid()
95 return "6dd4268a-c605-4a06-9034-59c1e8344c8e";
99 void ExampleSourcePlugin::getPropertyAsync(AsyncPropertyReply *reply)
101 DebugOut()<<"ExampleSource: getPropertyAsync called for property: "<<reply->property<<endl;
105 if(reply->property == VehicleProperty::VehicleSpeed)
107 VehicleProperty::VehicleSpeedType temp(velocity);
108 reply->value = &temp;
109 reply->success = true;
110 reply->completed(reply);
112 else if(reply->property == VehicleProperty::EngineSpeed)
114 VehicleProperty::EngineSpeedType temp(engineSpeed);
115 reply->value = &temp;
116 reply->success = true;
117 reply->completed(reply);
119 else if(reply->property == VehicleProperty::AccelerationX)
121 VehicleProperty::AccelerationXType temp(accelerationX);
122 reply->value = &temp;
123 reply->success = true;
124 reply->completed(reply);
126 else if(reply->property == VehicleProperty::TransmissionShiftPosition)
128 VehicleProperty::TransmissionShiftPositionType temp(transmissionShiftPostion);
129 reply->value = &temp;
130 reply->success = true;
131 reply->completed(reply);
133 else if(reply->property == VehicleProperty::SteeringWheelAngle)
135 VehicleProperty::SteeringWheelAngleType temp(steeringWheelAngle);
136 reply->value = &temp;
137 reply->success = true;
138 reply->completed(reply);
140 else if(reply->property == VehicleProperty::VIN)
142 VehicleProperty::VINType temp("ABC00000000000000");
143 reply->value = &temp;
144 reply->success = true;
145 reply->completed(reply);
147 else if(reply->property == VehicleProperty::WMI)
149 VehicleProperty::WMIType temp("abc");
150 reply->value = &temp;
151 reply->success = true;
152 reply->completed(reply);
154 else if(reply->property == VehicleProperty::BatteryVoltage)
156 VehicleProperty::BatteryVoltageType temp(12.6);
157 reply->value = &temp;
158 reply->success = true;
159 reply->completed(reply);
161 else if(reply->property == VehicleProperty::ExteriorBrightness)
163 VehicleProperty::ExteriorBrightnessType temp(1000);
164 reply->value = &temp;
165 reply->success = true;
166 reply->completed(reply);
168 else if(reply->property == VehicleProperty::DoorsPerRow)
170 VehicleProperty::DoorsPerRowType temp;
172 BasicPropertyType<uint16_t> row1(2);
173 BasicPropertyType<uint16_t> row2(2);
174 BasicPropertyType<uint16_t> row3(1);
180 reply->value = &temp;
181 reply->success = true;
182 reply->completed(reply);
184 else if(reply->property == VehicleProperty::AirbagStatus)
186 if(airbagStatus.find(reply->zoneFilter) == airbagStatus.end())
188 reply->success = false;
189 reply->error = AsyncPropertyReply::ZoneNotSupported;
190 reply->completed(reply);
196 VehicleProperty::AirbagStatusType temp;
197 temp.setValue(airbagStatus[reply->zoneFilter]);
198 temp.zone = reply->zoneFilter;
200 reply->value = &temp;
201 reply->success = true;
202 reply->completed(reply);
205 else if(reply->property == VehicleProperty::MachineGunTurretStatus)
207 VehicleProperty::MachineGunTurretStatusType temp(true);
208 reply->value = &temp;
209 reply->success = true;
210 reply->completed(reply);
214 reply->success=false;
215 reply->error = AsyncPropertyReply::InvalidOperation;
216 reply->completed(reply);
220 void ExampleSourcePlugin::getRangePropertyAsync(AsyncRangePropertyReply *reply)
225 AsyncPropertyReply *ExampleSourcePlugin::setProperty(AsyncSetPropertyRequest request )
230 void ExampleSourcePlugin::subscribeToPropertyChanges(VehicleProperty::Property property)
232 mRequests.push_back(property);
235 PropertyList ExampleSourcePlugin::supported()
240 int ExampleSourcePlugin::supportedOperations()
242 return Get | Set | GetRanged;
245 void ExampleSourcePlugin::unsubscribeToPropertyChanges(VehicleProperty::Property property)
247 mRequests.remove(property);
250 void ExampleSourcePlugin::randomizeProperties()
252 velocity = 1 + (255.00 * (rand() / (RAND_MAX + 1.0)));
253 engineSpeed = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
254 accelerationX = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
255 transmissionShiftPostion = Transmission::TransmissionPositions(1 + (6.00 * (rand() / (RAND_MAX + 1.0))));
256 steeringWheelAngle = 1 + (359.00 * (rand() / (RAND_MAX + 1.0)));
257 throttlePos = 1 + (100.00 * (rand() / (RAND_MAX + 1.0)));
258 engineCoolant = 1 + (40.00 * (rand() / (RAND_MAX + 140.0)));
260 DebugOut()<<"setting velocity to: "<<velocity<<endl;
261 DebugOut()<<"setting enginespeed to: "<<engineSpeed<<endl;
263 VehicleProperty::VehicleSpeedType vel(velocity);
264 VehicleProperty::EngineSpeedType es(engineSpeed);
265 VehicleProperty::AccelerationXType ac(accelerationX);
266 VehicleProperty::SteeringWheelAngleType swa(steeringWheelAngle);
267 VehicleProperty::TransmissionShiftPositionType tsp(transmissionShiftPostion);
268 VehicleProperty::ThrottlePositionType tp(throttlePos);
269 VehicleProperty::EngineCoolantTemperatureType ec(engineCoolant);
270 VehicleProperty::MachineGunTurretStatusType mgt(machineGun);
272 machineGun = !machineGun;
274 vel.timestamp = amb::currentTime();
275 es.timestamp = amb::currentTime();
276 ac.timestamp = amb::currentTime();
277 swa.timestamp = amb::currentTime();
278 tsp.timestamp = amb::currentTime();
279 tp.timestamp = amb::currentTime();
280 ec.timestamp = amb::currentTime();
282 routingEngine->updateProperty(VehicleProperty::VehicleSpeed, &vel, uuid());
283 routingEngine->updateProperty(VehicleProperty::EngineSpeed, &es, uuid());
284 routingEngine->updateProperty(VehicleProperty::AccelerationX, &ac, uuid());
285 routingEngine->updateProperty(VehicleProperty::SteeringWheelAngle, &swa, uuid());
286 routingEngine->updateProperty(VehicleProperty::TransmissionShiftPosition,&tsp, uuid());
287 routingEngine->updateProperty(VehicleProperty::ThrottlePosition, &tp, uuid());
288 routingEngine->updateProperty(VehicleProperty::EngineCoolantTemperature, &ec, uuid());
289 //routingEngine->updateProperty(VehicleProperty::MachineGunTurretStatus, &mgt);
292 void ExampleSourcePlugin::addPropertySupport(VehicleProperty::Property property, Zone::Type zone)
294 mSupported.push_back(property);
296 std::list<Zone::Type> zones;
298 zones.push_back(zone);
300 PropertyInfo info(0, zones);
302 propertyInfoMap[property] = info;