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;
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;
71 if(reply->property == VehicleProperty::VehicleSpeed)
73 VehicleProperty::VehicleSpeedType temp(velocity);
75 reply->completed(reply);
77 else if(reply->property == VehicleProperty::EngineSpeed)
79 VehicleProperty::EngineSpeedType temp(engineSpeed);
81 reply->completed(reply);
83 else if(reply->property == VehicleProperty::AccelerationX)
85 VehicleProperty::AccelerationType temp(accelerationX);
87 reply->completed(reply);
89 else if(reply->property == VehicleProperty::TransmissionShiftPosition)
91 VehicleProperty::TransmissionShiftPositionType temp(transmissionShiftPostion);
93 reply->completed(reply);
95 else if(reply->property == VehicleProperty::SteeringWheelAngle)
97 VehicleProperty::SteeringWheelAngleType temp(steeringWheelAngle);
99 reply->completed(reply);
101 else if(reply->property == VehicleProperty::VIN)
103 VehicleProperty::VINType temp("abc00000000000000");
104 reply->value = &temp;
105 reply->completed(reply);
107 else if(reply->property == VehicleProperty::WMI)
109 VehicleProperty::WMIType temp("abc");
110 reply->value = &temp;
111 reply->completed(reply);
113 else if(reply->property == VehicleProperty::BatteryVoltage)
115 VehicleProperty::BatteryVoltageType temp(12.6);
116 reply->value = &temp;
117 reply->completed(reply);
121 void ExampleSourcePlugin::setProperty(VehicleProperty::Property , AbstractPropertyType *)
126 void ExampleSourcePlugin::subscribeToPropertyChanges(VehicleProperty::Property property)
128 mRequests.push_back(property);
131 PropertyList ExampleSourcePlugin::supported()
134 props.push_back(VehicleProperty::EngineSpeed);
135 props.push_back(VehicleProperty::VehicleSpeed);
136 props.push_back(VehicleProperty::AccelerationX);
137 props.push_back(VehicleProperty::TransmissionShiftPosition);
138 props.push_back(VehicleProperty::SteeringWheelAngle);
139 props.push_back(VehicleProperty::ThrottlePosition);
140 props.push_back(VehicleProperty::EngineCoolantTemperature);
141 props.push_back(VehicleProperty::VIN);
142 props.push_back(VehicleProperty::WMI);
143 props.push_back(VehicleProperty::BatteryVoltage);
144 props.push_back(VehicleProperty::MachineGunTurretStatus);
149 void ExampleSourcePlugin::unsubscribeToPropertyChanges(VehicleProperty::Property property)
151 mRequests.remove(property);
154 void ExampleSourcePlugin::randomizeProperties()
156 velocity = 1 + (255.00 * (rand() / (RAND_MAX + 1.0)));
157 engineSpeed = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
158 accelerationX = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
159 transmissionShiftPostion = 1 + (6.00 * (rand() / (RAND_MAX + 1.0)));
160 steeringWheelAngle = 1 + (359.00 * (rand() / (RAND_MAX + 1.0)));
161 throttlePos = 1 + (100.00 * (rand() / (RAND_MAX + 1.0)));
162 engineCoolant = 1 + (40.00 * (rand() / (RAND_MAX + 140.0)));
164 DebugOut()<<"setting velocity to: "<<velocity<<endl;
165 DebugOut()<<"setting enginespeed to: "<<engineSpeed<<endl;
167 VehicleProperty::VehicleSpeedType vel(velocity);
168 VehicleProperty::EngineSpeedType es(engineSpeed);
169 VehicleProperty::AccelerationType ac(accelerationX);
170 VehicleProperty::SteeringWheelAngleType swa(steeringWheelAngle);
171 VehicleProperty::TransmissionShiftPositionType tsp(transmissionShiftPostion);
172 VehicleProperty::ThrottlePositionType tp(throttlePos);
173 VehicleProperty::EngineCoolantTemperatureType ec(engineCoolant);
174 VehicleProperty::MachineGunTurretStatusType mgt(machineGun);
176 machineGun = !machineGun;
178 routingEngine->updateProperty(VehicleProperty::VehicleSpeed, &vel);
179 routingEngine->updateProperty(VehicleProperty::EngineSpeed, &es);
180 routingEngine->updateProperty(VehicleProperty::AccelerationX, &ac);
181 routingEngine->updateProperty(VehicleProperty::SteeringWheelAngle, &swa);
182 routingEngine->updateProperty(VehicleProperty::TransmissionShiftPosition,&tsp);
183 routingEngine->updateProperty(VehicleProperty::ThrottlePosition, &tp);
184 routingEngine->updateProperty(VehicleProperty::EngineCoolantTemperature, &ec);
185 //routingEngine->updateProperty(VehicleProperty::MachineGunTurretStatus, &mgt);