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 uint16_t transmissionShiftPostion = 0;
31 uint16_t steeringWheelAngle=0;
32 uint16_t throttlePos = 0;
34 static gboolean timeoutCallback(gpointer data)
36 ExampleSourcePlugin* src = (ExampleSourcePlugin*)data;
38 src->randomizeProperties();
43 ExampleSourcePlugin::ExampleSourcePlugin(AbstractRoutingEngine* re)
44 :AbstractSource(re), velocity(0), engineSpeed(0)
46 re->setSupported(supported(), this);
48 debugOut("setting timeout");
49 g_timeout_add(1000, timeoutCallback, this );
55 extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine)
57 return new ExampleSourcePlugin(routingengine);
61 string ExampleSourcePlugin::uuid()
63 return "6dd4268a-c605-4a06-9034-59c1e8344c8e";
66 boost::any ExampleSourcePlugin::getProperty(VehicleProperty::Property property)
68 if(property == VehicleProperty::VehicleSpeed)
72 else if(property == VehicleProperty::EngineSpeed)
78 void ExampleSourcePlugin::getPropertyAsync(AsyncPropertyReply *reply)
80 if(reply->property == VehicleProperty::VehicleSpeed)
82 reply->value = velocity;
83 reply->completed(reply);
85 else if(reply->property == VehicleProperty::EngineSpeed)
87 reply->value = engineSpeed;
88 reply->completed(reply);
90 else if(reply->property == VehicleProperty::AccelerationX)
92 reply->value = accelerationX;
93 reply->completed(reply);
95 else if(reply->property == VehicleProperty::TransmissionShiftPosition)
97 reply->value = transmissionShiftPostion;
98 reply->completed(reply);
100 else if(reply->property == VehicleProperty::SteeringWheelAngle)
102 reply->value = steeringWheelAngle;
103 reply->completed(reply);
107 void ExampleSourcePlugin::setProperty(VehicleProperty::Property , boost::any )
112 void ExampleSourcePlugin::subscribeToPropertyChanges(VehicleProperty::Property property)
114 mRequests.push_back(property);
117 PropertyList ExampleSourcePlugin::supported()
120 props.push_back(VehicleProperty::EngineSpeed);
121 props.push_back(VehicleProperty::VehicleSpeed);
122 props.push_back(VehicleProperty::AccelerationX);
123 props.push_back(VehicleProperty::TransmissionShiftPosition);
124 props.push_back(VehicleProperty::SteeringWheelAngle);
125 props.push_back(VehicleProperty::ThrottlePosition);
130 void ExampleSourcePlugin::unsubscribeToPropertyChanges(VehicleProperty::Property property)
132 mRequests.remove(property);
135 void ExampleSourcePlugin::randomizeProperties()
137 velocity = 1 + (255.00 * (rand() / (RAND_MAX + 1.0)));
138 engineSpeed = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
139 accelerationX = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
140 transmissionShiftPostion = 1 + (6.00 * (rand() / (RAND_MAX + 1.0)));
141 steeringWheelAngle = 1 + (359.00 * (rand() / (RAND_MAX + 1.0)));
142 throttlePos = 1 + (100.00 * (rand() / (RAND_MAX + 1.0)));
144 DebugOut()<<"setting velocity to: "<<velocity<<endl;
145 DebugOut()<<"setting enginespeed to: "<<engineSpeed<<endl;
147 routingEngine->updateProperty(VehicleProperty::VehicleSpeed, velocity);
148 routingEngine->updateProperty(VehicleProperty::EngineSpeed, engineSpeed);
149 routingEngine->updateProperty(VehicleProperty::AccelerationX, accelerationX);
150 routingEngine->updateProperty(VehicleProperty::SteeringWheelAngle, steeringWheelAngle);
151 routingEngine->updateProperty(VehicleProperty::TransmissionShiftPosition, transmissionShiftPostion);
152 routingEngine->updateProperty(VehicleProperty::ThrottlePosition, throttlePos);