summaryrefslogtreecommitdiff
path: root/plugins/exampleplugin.cpp
blob: 8ee40550a59eec0fd2519ebe879d9797cdc6637c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
Copyright (C) 2012 Intel Corporation

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "exampleplugin.h"
#include "timestamp.h"

#include <iostream>
#include <boost/assert.hpp>
#include <glib.h>

using namespace std;

#include "debugout.h"

uint16_t accelerationX = 0;
Transmission::TransmissionPositions transmissionShiftPostion = Transmission::Neutral;
uint16_t steeringWheelAngle=0;
uint16_t throttlePos = 0;
uint16_t engineCoolant = 40;
bool machineGun = false;
uint16_t exteriorBrightness = 500;

static gboolean timeoutCallback(gpointer data)
{
	ExampleSourcePlugin* src = (ExampleSourcePlugin*)data;
	
	src->randomizeProperties();
	
	return true;
}

ExampleSourcePlugin::ExampleSourcePlugin(AbstractRoutingEngine* re, map<string, string> config)
:AbstractSource(re, config), velocity(0), engineSpeed(0)
{
	re->setSupported(supported(), this);
	debugOut("setting timeout");
	g_timeout_add(1000, timeoutCallback, this );
	
}



extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<string, string> config)
{
	return new ExampleSourcePlugin(routingengine, config);
	
}

string ExampleSourcePlugin::uuid()
{
	return "6dd4268a-c605-4a06-9034-59c1e8344c8e";
}


void ExampleSourcePlugin::getPropertyAsync(AsyncPropertyReply *reply)
{
	DebugOut()<<"ExampleSource: getPropertyAsync called for property: "<<reply->property<<endl;

	if(reply->property == VehicleProperty::VehicleSpeed)
	{
		VehicleProperty::VehicleSpeedType temp(velocity);
		reply->value = &temp;
		reply->success = true;
		reply->completed(reply);
	}
	else if(reply->property == VehicleProperty::EngineSpeed)
	{
		VehicleProperty::EngineSpeedType temp(engineSpeed);
		reply->value = &temp;
		reply->success = true;
		reply->completed(reply);
	}
	else if(reply->property == VehicleProperty::AccelerationX)
	{
		VehicleProperty::AccelerationXType temp(accelerationX);
		reply->value = &temp;
		reply->success = true;
		reply->completed(reply);
	}
	else if(reply->property == VehicleProperty::TransmissionShiftPosition)
	{
		VehicleProperty::TransmissionShiftPositionType temp(transmissionShiftPostion);
		reply->value = &temp;
		reply->success = true;
		reply->completed(reply);
	}
	else if(reply->property == VehicleProperty::SteeringWheelAngle)
	{
		VehicleProperty::SteeringWheelAngleType temp(steeringWheelAngle);
		reply->value = &temp;
		reply->success = true;
		reply->completed(reply);
	}
	else if(reply->property == VehicleProperty::VIN)
	{
		VehicleProperty::VINType temp("ABC00000000000000");
		reply->value = &temp;
		reply->success = true;
		reply->completed(reply);
	}
	else if(reply->property == VehicleProperty::WMI)
	{
		VehicleProperty::WMIType temp("abc");
		reply->value = &temp;
		reply->success = true;
		reply->completed(reply);
	}
	else if(reply->property == VehicleProperty::BatteryVoltage)
	{
		VehicleProperty::BatteryVoltageType temp(12.6);
		reply->value = &temp;
		reply->success = true;
		reply->completed(reply);
	}
	else if(reply->property == VehicleProperty::ExteriorBrightness)
	{
		VehicleProperty::ExteriorBrightnessType temp(1000);
		reply->value = &temp;
		reply->success = true;
		reply->completed(reply);
	}
	else if(reply->property == VehicleProperty::DoorsPerRow)
	{
		VehicleProperty::DoorsPerRowType temp;

		BasicPropertyType<uint16_t> row1(2);
		BasicPropertyType<uint16_t> row2(2);
		BasicPropertyType<uint16_t> row3(1);

		temp.append(&row1);
		temp.append(&row2);
		temp.append(&row3);

		reply->value = &temp;
		reply->success = true;
		reply->completed(reply);
	}
	else if(reply->property == VehicleProperty::AirbagStatus)
	{
		VehicleProperty::AirbagStatusType temp;

		temp.append(Airbag::Driver, Airbag::Active);
		temp.append(Airbag::Passenger, Airbag::Active);
		temp.append(Airbag::LeftSide, Airbag::Active);
		temp.append(Airbag::RightSide, Airbag::Active);

		reply->value = &temp;
		reply->success = true;
		reply->completed(reply);
	}
	else if(reply->property == VehicleProperty::MachineGunTurretStatus)
	{
		VehicleProperty::MachineGunTurretStatusType temp(true);
		reply->value = &temp;
		reply->success = true;
		reply->completed(reply);
	}
	else if(reply->property == VehicleProperty::ExteriorBrightness)
	{
		VehicleProperty::ExteriorBrightnessType temp(exteriorBrightness);
		reply->value = &temp;
		reply->success = true;
		reply->completed(reply);
	}
}

void ExampleSourcePlugin::getRangePropertyAsync(AsyncRangePropertyReply *reply)
{

}

AsyncPropertyReply *ExampleSourcePlugin::setProperty(AsyncSetPropertyRequest request )
{

}

void ExampleSourcePlugin::subscribeToPropertyChanges(VehicleProperty::Property property)
{
	mRequests.push_back(property);
}

PropertyList ExampleSourcePlugin::supported()
{
	PropertyList props;
	props.push_back(VehicleProperty::EngineSpeed);
	props.push_back(VehicleProperty::VehicleSpeed);
	props.push_back(VehicleProperty::AccelerationX);
	props.push_back(VehicleProperty::TransmissionShiftPosition);
	props.push_back(VehicleProperty::SteeringWheelAngle);
	props.push_back(VehicleProperty::ThrottlePosition);
	props.push_back(VehicleProperty::EngineCoolantTemperature);
	props.push_back(VehicleProperty::VIN);
	props.push_back(VehicleProperty::WMI);
	props.push_back(VehicleProperty::BatteryVoltage);
	props.push_back(VehicleProperty::MachineGunTurretStatus);
	props.push_back(VehicleProperty::ExteriorBrightness);
	props.push_back(VehicleProperty::DoorsPerRow);
	props.push_back(VehicleProperty::AirbagStatus);
	props.push_back(VehicleProperty::MachineGunTurretStatus);
	props.push_back(VehicleProperty::ExteriorBrightness);
	
	return props;
}

int ExampleSourcePlugin::supportedOperations()
{
	return Get | Set | GetRanged;
}

void ExampleSourcePlugin::unsubscribeToPropertyChanges(VehicleProperty::Property property)
{
	mRequests.remove(property);
}

void ExampleSourcePlugin::randomizeProperties()
{
	velocity = 1 + (255.00 * (rand() / (RAND_MAX + 1.0)));
	engineSpeed = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
	accelerationX = 1 + (15000.00 * (rand() / (RAND_MAX + 1.0)));
	transmissionShiftPostion = Transmission::TransmissionPositions(1 + (6.00 * (rand() / (RAND_MAX + 1.0))));
	steeringWheelAngle = 1 + (359.00 * (rand() / (RAND_MAX + 1.0)));
	throttlePos = 1 + (100.00 * (rand() / (RAND_MAX + 1.0)));
	engineCoolant = 1 + (40.00 * (rand() / (RAND_MAX + 140.0)));
	exteriorBrightness = 1 + (5000 * (rand() / (RAND_MAX + 1.0)));
	
	DebugOut()<<"setting velocity to: "<<velocity<<endl;
	DebugOut()<<"setting enginespeed to: "<<engineSpeed<<endl;
	
	VehicleProperty::VehicleSpeedType vel(velocity);
	VehicleProperty::EngineSpeedType es(engineSpeed);
	VehicleProperty::AccelerationXType ac(accelerationX);
	VehicleProperty::SteeringWheelAngleType swa(steeringWheelAngle);
	VehicleProperty::TransmissionShiftPositionType tsp(transmissionShiftPostion);
	VehicleProperty::ThrottlePositionType tp(throttlePos);
	VehicleProperty::EngineCoolantTemperatureType ec(engineCoolant);
	VehicleProperty::MachineGunTurretStatusType mgt(machineGun);
	VehicleProperty::ExteriorBrightnessType eb(exteriorBrightness);

	machineGun = !machineGun;

	routingEngine->updateProperty(VehicleProperty::VehicleSpeed, &vel, uuid());
	routingEngine->updateProperty(VehicleProperty::EngineSpeed, &es, uuid());
	routingEngine->updateProperty(VehicleProperty::AccelerationX, &ac, uuid());
	routingEngine->updateProperty(VehicleProperty::SteeringWheelAngle, &swa, uuid());
	routingEngine->updateProperty(VehicleProperty::TransmissionShiftPosition,&tsp, uuid());
	routingEngine->updateProperty(VehicleProperty::ThrottlePosition, &tp, uuid());
	routingEngine->updateProperty(VehicleProperty::EngineCoolantTemperature, &ec, uuid());
	//routingEngine->updateProperty(VehicleProperty::MachineGunTurretStatus, &mgt);
	routingEngine->updateProperty(VehicleProperty::ExteriorBrightness, &eb, uuid());
}