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 re->setSupported(supported(), this);
50 debugOut("setting timeout");
51 g_timeout_add(1000, timeoutCallback, this );
57 extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<string, string> config)
59 return new ExampleSourcePlugin(routingengine, config);
63 string ExampleSourcePlugin::uuid()
65 return "6dd4268a-c605-4a06-9034-59c1e8344c8e";
69 void ExampleSourcePlugin::getPropertyAsync(AsyncPropertyReply *reply)
71 DebugOut()<<"ExampleSource: getPropertyAsync called for property: "<<reply->property<<endl;
75 if(reply->property == VehicleProperty::VehicleSpeed)
77 VehicleProperty::VehicleSpeedType temp(velocity);
79 reply->success = true;
80 reply->completed(reply);
82 else if(reply->property == VehicleProperty::EngineSpeed)
84 VehicleProperty::EngineSpeedType temp(engineSpeed);
86 reply->success = true;
87 reply->completed(reply);
89 else if(reply->property == VehicleProperty::AccelerationX)
91 VehicleProperty::AccelerationType temp(accelerationX);
93 reply->success = true;
94 reply->completed(reply);
96 else if(reply->property == VehicleProperty::TransmissionShiftPosition)
98 VehicleProperty::TransmissionShiftPositionType temp(transmissionShiftPostion);
100 reply->success = true;
101 reply->completed(reply);
103 else if(reply->property == VehicleProperty::SteeringWheelAngle)
105 VehicleProperty::SteeringWheelAngleType temp(steeringWheelAngle);
106 reply->value = &temp;
107 reply->success = true;
108 reply->completed(reply);
110 else if(reply->property == VehicleProperty::VIN)
112 VehicleProperty::VINType temp("ABC00000000000000");
113 reply->value = &temp;
114 reply->success = true;
115 reply->completed(reply);
117 else if(reply->property == VehicleProperty::WMI)
119 VehicleProperty::WMIType temp("abc");
120 reply->value = &temp;
121 reply->success = true;
122 reply->completed(reply);
124 else if(reply->property == VehicleProperty::BatteryVoltage)
126 VehicleProperty::BatteryVoltageType temp(12.6);
127 reply->value = &temp;
128 reply->success = true;
129 reply->completed(reply);
131 else if(reply->property == VehicleProperty::ExteriorBrightness)
133 VehicleProperty::ExteriorBrightnessType temp(1000);
134 reply->value = &temp;
135 reply->success = true;
136 reply->completed(reply);
138 else if(reply->property == VehicleProperty::DoorsPerRow)
140 VehicleProperty::DoorsPerRowType temp;
142 BasicPropertyType<uint16_t> row1(2);
143 BasicPropertyType<uint16_t> row2(2);
144 BasicPropertyType<uint16_t> row3(1);
150 reply->value = &temp;
151 reply->success = true;
152 reply->completed(reply);
156 void ExampleSourcePlugin::getRangePropertyAsync(AsyncRangePropertyReply *reply)
161 AsyncPropertyReply *ExampleSourcePlugin::setProperty(AsyncSetPropertyRequest request )
166 void ExampleSourcePlugin::subscribeToPropertyChanges(VehicleProperty::Property property)
168 mRequests.push_back(property);
171 PropertyList ExampleSourcePlugin::supported()
174 props.push_back(VehicleProperty::EngineSpeed);
175 props.push_back(VehicleProperty::VehicleSpeed);
176 props.push_back(VehicleProperty::AccelerationX);
177 props.push_back(VehicleProperty::TransmissionShiftPosition);
178 props.push_back(VehicleProperty::SteeringWheelAngle);
179 props.push_back(VehicleProperty::ThrottlePosition);
180 props.push_back(VehicleProperty::EngineCoolantTemperature);
181 props.push_back(VehicleProperty::VIN);
182 props.push_back(VehicleProperty::WMI);
183 props.push_back(VehicleProperty::BatteryVoltage);
184 props.push_back(VehicleProperty::MachineGunTurretStatus);
185 props.push_back(VehicleProperty::ExteriorBrightness);
186 props.push_back(VehicleProperty::DoorsPerRow);
191 int ExampleSourcePlugin::supportedOperations()
193 return Get | Set | GetRanged;
196 void ExampleSourcePlugin::unsubscribeToPropertyChanges(VehicleProperty::Property property)
198 mRequests.remove(property);
201 void ExampleSourcePlugin::randomizeProperties()
203 velocity = 1 + (255.00 * (rand() / (RAND_MAX + 1.0)));
204 engineSpeed = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
205 accelerationX = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
206 transmissionShiftPostion = Transmission::TransmissionPositions(1 + (6.00 * (rand() / (RAND_MAX + 1.0))));
207 steeringWheelAngle = 1 + (359.00 * (rand() / (RAND_MAX + 1.0)));
208 throttlePos = 1 + (100.00 * (rand() / (RAND_MAX + 1.0)));
209 engineCoolant = 1 + (40.00 * (rand() / (RAND_MAX + 140.0)));
211 DebugOut()<<"setting velocity to: "<<velocity<<endl;
212 DebugOut()<<"setting enginespeed to: "<<engineSpeed<<endl;
214 VehicleProperty::VehicleSpeedType vel(velocity);
215 VehicleProperty::EngineSpeedType es(engineSpeed);
216 VehicleProperty::AccelerationType ac(accelerationX);
217 VehicleProperty::SteeringWheelAngleType swa(steeringWheelAngle);
218 VehicleProperty::TransmissionShiftPositionType tsp(transmissionShiftPostion);
219 VehicleProperty::ThrottlePositionType tp(throttlePos);
220 VehicleProperty::EngineCoolantTemperatureType ec(engineCoolant);
221 VehicleProperty::MachineGunTurretStatusType mgt(machineGun);
223 machineGun = !machineGun;
225 vel.timestamp = amb::currentTime();
226 es.timestamp = amb::currentTime();
227 ac.timestamp = amb::currentTime();
228 swa.timestamp = amb::currentTime();
229 tsp.timestamp = amb::currentTime();
230 tp.timestamp = amb::currentTime();
231 ec.timestamp = amb::currentTime();
233 routingEngine->updateProperty(VehicleProperty::VehicleSpeed, &vel, uuid());
234 routingEngine->updateProperty(VehicleProperty::EngineSpeed, &es, uuid());
235 routingEngine->updateProperty(VehicleProperty::AccelerationX, &ac, uuid());
236 routingEngine->updateProperty(VehicleProperty::SteeringWheelAngle, &swa, uuid());
237 routingEngine->updateProperty(VehicleProperty::TransmissionShiftPosition,&tsp, uuid());
238 routingEngine->updateProperty(VehicleProperty::ThrottlePosition, &tp, uuid());
239 routingEngine->updateProperty(VehicleProperty::EngineCoolantTemperature, &ec, uuid());
240 //routingEngine->updateProperty(VehicleProperty::MachineGunTurretStatus, &mgt);