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"
22 #include <boost/assert.hpp>
29 uint16_t accelerationX = 0;
30 Transmission::TransmissionPositions transmissionShiftPostion = Transmission::Neutral;
31 uint16_t steeringWheelAngle=0;
32 uint16_t throttlePos = 0;
33 uint16_t engineCoolant = 40;
34 bool machineGun = false;
36 static gboolean timeoutCallback(gpointer data)
38 ExampleSourcePlugin* src = (ExampleSourcePlugin*)data;
40 src->randomizeProperties();
45 ExampleSourcePlugin::ExampleSourcePlugin(AbstractRoutingEngine* re, map<string, string> config)
46 :AbstractSource(re, config), velocity(0), engineSpeed(0)
48 re->setSupported(supported(), this);
49 debugOut("setting timeout");
50 g_timeout_add(1000, timeoutCallback, this );
56 extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<string, string> config)
58 return new ExampleSourcePlugin(routingengine, config);
62 string ExampleSourcePlugin::uuid()
64 return "6dd4268a-c605-4a06-9034-59c1e8344c8e";
68 void ExampleSourcePlugin::getPropertyAsync(AsyncPropertyReply *reply)
70 DebugOut()<<"ExampleSource: getPropertyAsync called for property: "<<reply->property<<endl;
74 if(reply->property == VehicleProperty::VehicleSpeed)
76 VehicleProperty::VehicleSpeedType temp(velocity);
78 reply->completed(reply);
80 else if(reply->property == VehicleProperty::EngineSpeed)
82 VehicleProperty::EngineSpeedType temp(engineSpeed);
84 reply->completed(reply);
86 else if(reply->property == VehicleProperty::AccelerationX)
88 VehicleProperty::AccelerationType temp(accelerationX);
90 reply->completed(reply);
92 else if(reply->property == VehicleProperty::TransmissionShiftPosition)
94 VehicleProperty::TransmissionShiftPositionType temp(transmissionShiftPostion);
96 reply->completed(reply);
98 else if(reply->property == VehicleProperty::SteeringWheelAngle)
100 VehicleProperty::SteeringWheelAngleType temp(steeringWheelAngle);
101 reply->value = &temp;
102 reply->completed(reply);
104 else if(reply->property == VehicleProperty::VIN)
106 VehicleProperty::VINType temp("ABC00000000000000");
107 reply->value = &temp;
108 reply->completed(reply);
110 else if(reply->property == VehicleProperty::WMI)
112 VehicleProperty::WMIType temp("abc");
113 reply->value = &temp;
114 reply->completed(reply);
116 else if(reply->property == VehicleProperty::BatteryVoltage)
118 VehicleProperty::BatteryVoltageType temp(12.6);
119 reply->value = &temp;
120 reply->completed(reply);
124 void ExampleSourcePlugin::getRangePropertyAsync(AsyncRangePropertyReply *reply)
129 AsyncPropertyReply *ExampleSourcePlugin::setProperty(AsyncSetPropertyRequest request )
134 void ExampleSourcePlugin::subscribeToPropertyChanges(VehicleProperty::Property property)
136 mRequests.push_back(property);
139 PropertyList ExampleSourcePlugin::supported()
142 props.push_back(VehicleProperty::EngineSpeed);
143 props.push_back(VehicleProperty::VehicleSpeed);
144 props.push_back(VehicleProperty::AccelerationX);
145 props.push_back(VehicleProperty::TransmissionShiftPosition);
146 props.push_back(VehicleProperty::SteeringWheelAngle);
147 props.push_back(VehicleProperty::ThrottlePosition);
148 props.push_back(VehicleProperty::EngineCoolantTemperature);
149 props.push_back(VehicleProperty::VIN);
150 props.push_back(VehicleProperty::WMI);
151 props.push_back(VehicleProperty::BatteryVoltage);
152 props.push_back(VehicleProperty::MachineGunTurretStatus);
157 void ExampleSourcePlugin::unsubscribeToPropertyChanges(VehicleProperty::Property property)
159 mRequests.remove(property);
162 void ExampleSourcePlugin::randomizeProperties()
164 velocity = 1 + (255.00 * (rand() / (RAND_MAX + 1.0)));
165 engineSpeed = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
166 accelerationX = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
167 transmissionShiftPostion = Transmission::TransmissionPositions(1 + (6.00 * (rand() / (RAND_MAX + 1.0))));
168 steeringWheelAngle = 1 + (359.00 * (rand() / (RAND_MAX + 1.0)));
169 throttlePos = 1 + (100.00 * (rand() / (RAND_MAX + 1.0)));
170 engineCoolant = 1 + (40.00 * (rand() / (RAND_MAX + 140.0)));
172 DebugOut()<<"setting velocity to: "<<velocity<<endl;
173 DebugOut()<<"setting enginespeed to: "<<engineSpeed<<endl;
175 VehicleProperty::VehicleSpeedType vel(velocity);
176 VehicleProperty::EngineSpeedType es(engineSpeed);
177 VehicleProperty::AccelerationType ac(accelerationX);
178 VehicleProperty::SteeringWheelAngleType swa(steeringWheelAngle);
179 VehicleProperty::TransmissionShiftPositionType tsp(transmissionShiftPostion);
180 VehicleProperty::ThrottlePositionType tp(throttlePos);
181 VehicleProperty::EngineCoolantTemperatureType ec(engineCoolant);
182 VehicleProperty::MachineGunTurretStatusType mgt(machineGun);
184 machineGun = !machineGun;
186 routingEngine->updateProperty(VehicleProperty::VehicleSpeed, &vel);
187 routingEngine->updateProperty(VehicleProperty::EngineSpeed, &es);
188 routingEngine->updateProperty(VehicleProperty::AccelerationX, &ac);
189 routingEngine->updateProperty(VehicleProperty::SteeringWheelAngle, &swa);
190 routingEngine->updateProperty(VehicleProperty::TransmissionShiftPosition,&tsp);
191 routingEngine->updateProperty(VehicleProperty::ThrottlePosition, &tp);
192 routingEngine->updateProperty(VehicleProperty::EngineCoolantTemperature, &ec);
193 //routingEngine->updateProperty(VehicleProperty::MachineGunTurretStatus, &mgt);