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;
33 uint16_t engineCoolant = 40;
35 static gboolean timeoutCallback(gpointer data)
37 ExampleSourcePlugin* src = (ExampleSourcePlugin*)data;
39 src->randomizeProperties();
44 ExampleSourcePlugin::ExampleSourcePlugin(AbstractRoutingEngine* re)
45 :AbstractSource(re), velocity(0), engineSpeed(0)
47 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 = BasicPropertyType<uint16_t>(velocity);
83 reply->completed(reply);
85 else if(reply->property == VehicleProperty::EngineSpeed)
87 reply->value = BasicPropertyType<uint16_t>(engineSpeed);
88 reply->completed(reply);
90 else if(reply->property == VehicleProperty::AccelerationX)
92 reply->value = BasicPropertyType<uint16_t>(accelerationX);
93 reply->completed(reply);
95 else if(reply->property == VehicleProperty::TransmissionShiftPosition)
97 reply->value = BasicPropertyType<uint16_t>(transmissionShiftPostion);
98 reply->completed(reply);
100 else if(reply->property == VehicleProperty::SteeringWheelAngle)
102 reply->value = BasicPropertyType<uint16_t>(steeringWheelAngle);
103 reply->completed(reply);
107 void ExampleSourcePlugin::setProperty(VehicleProperty::Property , AbstractPropertyType )
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);
126 props.push_back(VehicleProperty::EngineCoolantTemperature);
131 void ExampleSourcePlugin::unsubscribeToPropertyChanges(VehicleProperty::Property property)
133 mRequests.remove(property);
136 void ExampleSourcePlugin::randomizeProperties()
138 velocity = 1 + (255.00 * (rand() / (RAND_MAX + 1.0)));
139 engineSpeed = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
140 accelerationX = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
141 transmissionShiftPostion = 1 + (6.00 * (rand() / (RAND_MAX + 1.0)));
142 steeringWheelAngle = 1 + (359.00 * (rand() / (RAND_MAX + 1.0)));
143 throttlePos = 1 + (100.00 * (rand() / (RAND_MAX + 1.0)));
144 engineCoolant = 1 + (40.00 * (rand() / (RAND_MAX + 140.0)));
146 DebugOut()<<"setting velocity to: "<<velocity<<endl;
147 DebugOut()<<"setting enginespeed to: "<<engineSpeed<<endl;
149 routingEngine->updateProperty(VehicleProperty::VehicleSpeed, BasicPropertyType<uint16_t>(velocity));
150 routingEngine->updateProperty(VehicleProperty::EngineSpeed, BasicPropertyType<uint16_t>(engineSpeed));
151 routingEngine->updateProperty(VehicleProperty::AccelerationX, BasicPropertyType<uint16_t>(accelerationX));
152 routingEngine->updateProperty(VehicleProperty::SteeringWheelAngle, BasicPropertyType<uint16_t>(steeringWheelAngle));
153 routingEngine->updateProperty(VehicleProperty::TransmissionShiftPosition, BasicPropertyType<uint16_t>(transmissionShiftPostion));
154 routingEngine->updateProperty(VehicleProperty::ThrottlePosition, BasicPropertyType<uint16_t>(throttlePos));
155 routingEngine->updateProperty(VehicleProperty::EngineCoolantTemperature, BasicPropertyType<uint16_t>(engineCoolant));