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->completed(reply);
81 else if(reply->property == VehicleProperty::EngineSpeed)
83 VehicleProperty::EngineSpeedType temp(engineSpeed);
85 reply->completed(reply);
87 else if(reply->property == VehicleProperty::AccelerationX)
89 VehicleProperty::AccelerationType temp(accelerationX);
91 reply->completed(reply);
93 else if(reply->property == VehicleProperty::TransmissionShiftPosition)
95 VehicleProperty::TransmissionShiftPositionType temp(transmissionShiftPostion);
97 reply->completed(reply);
99 else if(reply->property == VehicleProperty::SteeringWheelAngle)
101 VehicleProperty::SteeringWheelAngleType temp(steeringWheelAngle);
102 reply->value = &temp;
103 reply->completed(reply);
105 else if(reply->property == VehicleProperty::VIN)
107 VehicleProperty::VINType temp("ABC00000000000000");
108 reply->value = &temp;
109 reply->completed(reply);
111 else if(reply->property == VehicleProperty::WMI)
113 VehicleProperty::WMIType temp("abc");
114 reply->value = &temp;
115 reply->completed(reply);
117 else if(reply->property == VehicleProperty::BatteryVoltage)
119 VehicleProperty::BatteryVoltageType temp(12.6);
120 reply->value = &temp;
121 reply->completed(reply);
125 void ExampleSourcePlugin::getRangePropertyAsync(AsyncRangePropertyReply *reply)
130 AsyncPropertyReply *ExampleSourcePlugin::setProperty(AsyncSetPropertyRequest request )
135 void ExampleSourcePlugin::subscribeToPropertyChanges(VehicleProperty::Property property)
137 mRequests.push_back(property);
140 PropertyList ExampleSourcePlugin::supported()
143 props.push_back(VehicleProperty::EngineSpeed);
144 props.push_back(VehicleProperty::VehicleSpeed);
145 props.push_back(VehicleProperty::AccelerationX);
146 props.push_back(VehicleProperty::TransmissionShiftPosition);
147 props.push_back(VehicleProperty::SteeringWheelAngle);
148 props.push_back(VehicleProperty::ThrottlePosition);
149 props.push_back(VehicleProperty::EngineCoolantTemperature);
150 props.push_back(VehicleProperty::VIN);
151 props.push_back(VehicleProperty::WMI);
152 props.push_back(VehicleProperty::BatteryVoltage);
153 props.push_back(VehicleProperty::MachineGunTurretStatus);
158 int ExampleSourcePlugin::supportedOperations()
160 return Get | Set | GetRanged;
163 void ExampleSourcePlugin::unsubscribeToPropertyChanges(VehicleProperty::Property property)
165 mRequests.remove(property);
168 void ExampleSourcePlugin::randomizeProperties()
170 velocity = 1 + (255.00 * (rand() / (RAND_MAX + 1.0)));
171 engineSpeed = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
172 accelerationX = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
173 transmissionShiftPostion = Transmission::TransmissionPositions(1 + (6.00 * (rand() / (RAND_MAX + 1.0))));
174 steeringWheelAngle = 1 + (359.00 * (rand() / (RAND_MAX + 1.0)));
175 throttlePos = 1 + (100.00 * (rand() / (RAND_MAX + 1.0)));
176 engineCoolant = 1 + (40.00 * (rand() / (RAND_MAX + 140.0)));
178 DebugOut()<<"setting velocity to: "<<velocity<<endl;
179 DebugOut()<<"setting enginespeed to: "<<engineSpeed<<endl;
181 VehicleProperty::VehicleSpeedType vel(velocity);
182 VehicleProperty::EngineSpeedType es(engineSpeed);
183 VehicleProperty::AccelerationType ac(accelerationX);
184 VehicleProperty::SteeringWheelAngleType swa(steeringWheelAngle);
185 VehicleProperty::TransmissionShiftPositionType tsp(transmissionShiftPostion);
186 VehicleProperty::ThrottlePositionType tp(throttlePos);
187 VehicleProperty::EngineCoolantTemperatureType ec(engineCoolant);
188 VehicleProperty::MachineGunTurretStatusType mgt(machineGun);
190 machineGun = !machineGun;
192 vel.timestamp = amb::currentTime();
193 es.timestamp = amb::currentTime();
194 ac.timestamp = amb::currentTime();
195 swa.timestamp = amb::currentTime();
196 tsp.timestamp = amb::currentTime();
197 tp.timestamp = amb::currentTime();
198 ec.timestamp = amb::currentTime();
200 routingEngine->updateProperty(VehicleProperty::VehicleSpeed, &vel, uuid());
201 routingEngine->updateProperty(VehicleProperty::EngineSpeed, &es, uuid());
202 routingEngine->updateProperty(VehicleProperty::AccelerationX, &ac, uuid());
203 routingEngine->updateProperty(VehicleProperty::SteeringWheelAngle, &swa, uuid());
204 routingEngine->updateProperty(VehicleProperty::TransmissionShiftPosition,&tsp, uuid());
205 routingEngine->updateProperty(VehicleProperty::ThrottlePosition, &tp, uuid());
206 routingEngine->updateProperty(VehicleProperty::EngineCoolantTemperature, &ec, uuid());
207 //routingEngine->updateProperty(VehicleProperty::MachineGunTurretStatus, &mgt);