Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
TraCIServerAPI_Vehicle.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2009-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
28// APIs for getting/setting vehicle values via TraCI
29/****************************************************************************/
30#include <config.h>
31
32#include <microsim/MSNet.h>
34#include <microsim/MSVehicle.h>
36#include <microsim/MSLane.h>
37#include <microsim/MSEdge.h>
38#include <microsim/MSGlobals.h>
48#include <libsumo/Vehicle.h>
49#include <libsumo/VehicleType.h>
53
54
55// ===========================================================================
56// method definitions
57// ===========================================================================
58bool
60 tcpip::Storage& outputStorage) {
61 const int variable = inputStorage.readUnsignedByte();
62 const std::string id = inputStorage.readString();
64 try {
65 if (!libsumo::Vehicle::handleVariable(id, variable, &server, &inputStorage)) {
66 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Get Vehicle Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
67 }
68 } catch (libsumo::TraCIException& e) {
69 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, e.what(), outputStorage);
70 }
72 server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
73 return true;
74}
75
76
77bool
79 tcpip::Storage& outputStorage) {
80 std::string warning = ""; // additional description for response
81 // variable
82 int variable = inputStorage.readUnsignedByte();
83 if (variable != libsumo::CMD_STOP && variable != libsumo::CMD_CHANGELANE
85 && variable != libsumo::CMD_CHANGESUBLANE && variable != libsumo::CMD_OPENGAP
86 && variable != libsumo::CMD_REPLACE_STOP
87 && variable != libsumo::CMD_INSERT_STOP
88 && variable != libsumo::VAR_STOP_PARAMETER
89 && variable != libsumo::CMD_SLOWDOWN && variable != libsumo::CMD_CHANGETARGET && variable != libsumo::CMD_RESUME
90 && variable != libsumo::VAR_TYPE && variable != libsumo::VAR_ROUTE_ID && variable != libsumo::VAR_ROUTE
93 && variable != libsumo::VAR_EDGE_TRAVELTIME && variable != libsumo::VAR_EDGE_EFFORT
95 && variable != libsumo::VAR_SIGNALS && variable != libsumo::VAR_MOVE_TO
96 && variable != libsumo::VAR_LENGTH && variable != libsumo::VAR_MAXSPEED && variable != libsumo::VAR_VEHICLECLASS
97 && variable != libsumo::VAR_SPEED_FACTOR && variable != libsumo::VAR_EMISSIONCLASS
98 && variable != libsumo::VAR_WIDTH && variable != libsumo::VAR_MINGAP && variable != libsumo::VAR_SHAPECLASS
99 && variable != libsumo::VAR_ACCEL && variable != libsumo::VAR_DECEL && variable != libsumo::VAR_IMPERFECTION
101 && variable != libsumo::VAR_ACTIONSTEPLENGTH
102 && variable != libsumo::VAR_TAU && variable != libsumo::VAR_LANECHANGE_MODE
103 && variable != libsumo::VAR_SPEED && variable != libsumo::VAR_ACCELERATION && variable != libsumo::VAR_PREV_SPEED && variable != libsumo::VAR_SPEEDSETMODE && variable != libsumo::VAR_COLOR
104 && variable != libsumo::ADD && variable != libsumo::ADD_FULL && variable != libsumo::REMOVE
105 && variable != libsumo::VAR_HEIGHT
106 && variable != libsumo::VAR_MASS
107 && variable != libsumo::VAR_ROUTING_MODE
108 && variable != libsumo::VAR_LATALIGNMENT
109 && variable != libsumo::VAR_MAXSPEED_LAT
110 && variable != libsumo::VAR_MINGAP_LAT
111 && variable != libsumo::VAR_LINE
112 && variable != libsumo::VAR_VIA
113 && variable != libsumo::VAR_IMPATIENCE
114 && variable != libsumo::VAR_BOARDING_DURATION
115 && variable != libsumo::VAR_HIGHLIGHT
116 && variable != libsumo::CMD_TAXI_DISPATCH
117 && variable != libsumo::MOVE_TO_XY && variable != libsumo::VAR_PARAMETER/* && variable != libsumo::VAR_SPEED_TIME_LINE && variable != libsumo::VAR_LANE_TIME_LINE*/
118 ) {
119 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Change Vehicle State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
120 }
121 // id
122 std::string id = inputStorage.readString();
123#ifdef DEBUG_MOVEXY
124 std::cout << SIMTIME << " processSet veh=" << id << "\n";
125#endif
126 const bool shouldExist = variable != libsumo::ADD && variable != libsumo::ADD_FULL;
128 if (sumoVehicle == nullptr) {
129 if (shouldExist) {
130 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Vehicle '" + id + "' is not known", outputStorage);
131 }
132 }
133 MSBaseVehicle* v = dynamic_cast<MSBaseVehicle*>(sumoVehicle);
134 if (v == nullptr && shouldExist) {
135 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Vehicle '" + id + "' is not a proper vehicle", outputStorage);
136 }
137 try {
138 switch (variable) {
139 case libsumo::CMD_STOP: {
140 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
141 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Stop needs a compound object description.", outputStorage);
142 }
143 int compoundSize = inputStorage.readInt();
144 if (compoundSize < 4 || compoundSize > 7) {
145 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Stop needs a compound object description of four to seven items.", outputStorage);
146 }
147 // read road map position
148 std::string edgeID;
149 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
150 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first stop parameter must be the edge id given as a string.", outputStorage);
151 }
152 double pos = 0;
153 if (!server.readTypeCheckingDouble(inputStorage, pos)) {
154 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The second stop parameter must be the end position along the edge given as a double.", outputStorage);
155 }
156 int laneIndex = 0;
157 if (!server.readTypeCheckingByte(inputStorage, laneIndex)) {
158 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third stop parameter must be the lane index given as a byte.", outputStorage);
159 }
160 // waitTime
161 double duration = libsumo::INVALID_DOUBLE_VALUE;
162 if (!server.readTypeCheckingDouble(inputStorage, duration)) {
163 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "The fourth stop parameter must be the stopping duration given as a double.", outputStorage);
164 }
165 int stopFlags = 0;
166 if (compoundSize >= 5) {
167 if (!server.readTypeCheckingByte(inputStorage, stopFlags)) {
168 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fifth stop parameter must be a byte indicating its parking/triggered status.", outputStorage);
169 }
170 }
171 double startPos = libsumo::INVALID_DOUBLE_VALUE;
172 if (compoundSize >= 6) {
173 if (!server.readTypeCheckingDouble(inputStorage, startPos)) {
174 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The sixth stop parameter must be the start position along the edge given as a double.", outputStorage);
175 }
176 }
177 double until = libsumo::INVALID_DOUBLE_VALUE;
178 if (compoundSize >= 7) {
179 if (!server.readTypeCheckingDouble(inputStorage, until)) {
180 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The seventh stop parameter must be the minimum departure time given as a double.", outputStorage);
181 }
182 }
183 libsumo::Vehicle::setStop(id, edgeID, pos, laneIndex, duration, stopFlags, startPos, until);
184 }
185 break;
187 if (!insertReplaceStop(server, inputStorage, outputStorage, id, true)) {
188 return false;
189 }
190 break;
192 if (!insertReplaceStop(server, inputStorage, outputStorage, id, false)) {
193 return false;
194 }
195 break;
197 // read variables
198 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
199 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting stop parameter needs a compound object description.", outputStorage);
200 }
201 int compoundSize = inputStorage.readInt();
202 if (compoundSize != 3 && compoundSize != 4) {
203 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting a stop parameter needs a compound object description of 3 or 4 items.", outputStorage);
204 }
205 const int nextStopIndex = StoHelp::readTypedInt(inputStorage, "The first setStopParameter parameter must be the nextStopIndex given as an integer.");
206 std::string param;
207 if (!server.readTypeCheckingString(inputStorage, param)) {
208 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The second setStopParameter parameter must be the param given as a string.", outputStorage);
209 }
210 std::string value;
211 if (!server.readTypeCheckingString(inputStorage, value)) {
212 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third setStopParameter parameter must be the value given as a string.", outputStorage);
213 }
214 int customParam = 0;
215 if (compoundSize == 4) {
216 if (!server.readTypeCheckingByte(inputStorage, customParam)) {
217 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fourth setStopParameter parameter must be the customParam flag given as a byte.", outputStorage);
218 }
219 }
220 libsumo::Vehicle::setStopParameter(id, nextStopIndex, param, value, customParam != 0);
221 }
222 break;
224 // read variables
225 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
226 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Reroute to stop needs a compound object description.", outputStorage);
227 }
228 int compoundSize = inputStorage.readInt();
229 if (compoundSize != 1) {
230 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Reroute to stop needs a compound object description of 1 item.", outputStorage);
231 }
232 std::string parkingAreaID;
233 if (!server.readTypeCheckingString(inputStorage, parkingAreaID)) {
234 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first reroute to stop parameter must be the parking area id given as a string.", outputStorage);
235 }
236 libsumo::Vehicle::rerouteParkingArea(id, parkingAreaID);
237 }
238 break;
239 case libsumo::CMD_RESUME: {
240 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
241 server.writeStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::RTYPE_ERR, "Resuming requires a compound object.", outputStorage);
242 return false;
243 }
244 if (inputStorage.readInt() != 0) {
245 server.writeStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::RTYPE_ERR, "Resuming should obtain an empty compound object.", outputStorage);
246 return false;
247 }
248 libsumo::Vehicle::resume(id);
249 }
250 break;
252 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
253 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Lane change needs a compound object description.", outputStorage);
254 }
255 int compounds = inputStorage.readInt();
256 if (compounds != 3 && compounds != 2) {
257 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Lane change needs a compound object description of two or three items.", outputStorage);
258 }
259 // Lane ID
260 int laneIndex = 0;
261 if (!server.readTypeCheckingByte(inputStorage, laneIndex)) {
262 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first lane change parameter must be the lane index given as a byte.", outputStorage);
263 }
264 // duration
265 double duration = 0.;
266 if (!server.readTypeCheckingDouble(inputStorage, duration)) {
267 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The second lane change parameter must be the duration given as a double.", outputStorage);
268 }
269 // relativelanechange
270 int relative = 0;
271 if (compounds == 3) {
272 if (!server.readTypeCheckingByte(inputStorage, relative)) {
273 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third lane change parameter must be a Byte for defining whether a relative lane change should be applied.", outputStorage);
274 }
275 }
276
277 if ((laneIndex < 0 || laneIndex >= (int)v->getEdge()->getLanes().size()) && relative < 1) {
278 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "No lane with index '" + toString(laneIndex) + "' on road '" + v->getEdge()->getID() + "'.", outputStorage);
279 }
280
281 if (relative < 1) {
282 libsumo::Vehicle::changeLane(id, laneIndex, duration);
283 } else {
284 libsumo::Vehicle::changeLaneRelative(id, laneIndex, duration);
285 }
286 }
287 break;
289 double latDist = 0;
290 if (!server.readTypeCheckingDouble(inputStorage, latDist)) {
291 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Sublane-changing requires a double.", outputStorage);
292 }
293 libsumo::Vehicle::changeSublane(id, latDist);
294 }
295 break;
297 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
298 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Slow down needs a compound object description.", outputStorage);
299 }
300 if (inputStorage.readInt() != 2) {
301 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Slow down needs a compound object description of two items.", outputStorage);
302 }
303 double newSpeed = 0;
304 if (!server.readTypeCheckingDouble(inputStorage, newSpeed)) {
305 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first slow down parameter must be the speed given as a double.", outputStorage);
306 }
307 if (newSpeed < 0) {
308 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Speed must not be negative", outputStorage);
309 }
310 double duration = 0.;
311 if (!server.readTypeCheckingDouble(inputStorage, duration)) {
312 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The second slow down parameter must be the duration given as a double.", outputStorage);
313 }
314 if (duration < 0 || SIMTIME + duration > STEPS2TIME(SUMOTime_MAX - DELTA_T)) {
315 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Invalid time interval", outputStorage);
316 }
317 libsumo::Vehicle::slowDown(id, newSpeed, duration);
318 }
319 break;
321 std::string edgeID;
322 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
323 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Change target requires a string containing the id of the new destination edge as parameter.", outputStorage);
324 }
325 libsumo::Vehicle::changeTarget(id, edgeID);
326 }
327 break;
329 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
330 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Create gap needs a compound object description.", outputStorage);
331 }
332 const int nParameter = inputStorage.readInt();
333 if (nParameter != 5 && nParameter != 6) {
334 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Create gap needs a compound object description of five or six items.", outputStorage);
335 }
336 double newTimeHeadway = 0;
337 if (!server.readTypeCheckingDouble(inputStorage, newTimeHeadway)) {
338 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first create gap parameter must be the new desired time headway (tau) given as a double.", outputStorage);
339 }
340 double newSpaceHeadway = 0;
341 if (!server.readTypeCheckingDouble(inputStorage, newSpaceHeadway)) {
342 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The second create gap parameter must be the new desired space headway given as a double.", outputStorage);
343 }
344 double duration = 0.;
345 if (!server.readTypeCheckingDouble(inputStorage, duration)) {
346 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third create gap parameter must be the duration given as a double.", outputStorage);
347 }
348 double changeRate = 0;
349 if (!server.readTypeCheckingDouble(inputStorage, changeRate)) {
350 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fourth create gap parameter must be the change rate given as a double.", outputStorage);
351 }
352 double maxDecel = 0;
353 if (!server.readTypeCheckingDouble(inputStorage, maxDecel)) {
354 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fifth create gap parameter must be the maximal braking rate given as a double.", outputStorage);
355 }
356
357 if (newTimeHeadway == -1 && newSpaceHeadway == -1 && duration == -1 && changeRate == -1 && maxDecel == -1) {
358 libsumo::Vehicle::deactivateGapControl(id);
359 } else {
360 if (newTimeHeadway <= 0) {
361 if (newTimeHeadway != -1) {
362 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The value for the new desired time headway (tau) must be positive for create gap", outputStorage);
363 } // else if == -1: keep vehicles current headway, see libsumo::Vehicle::openGap
364 }
365 if (newSpaceHeadway < 0) {
366 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The value for the new desired space headway must be non-negative for create gap", outputStorage);
367 }
368 if ((duration < 0 && duration != -1) || SIMTIME + duration > STEPS2TIME(SUMOTime_MAX - DELTA_T)) {
369 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Invalid time interval for create gap", outputStorage);
370 }
371 if (changeRate <= 0) {
372 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The value for the change rate must be positive for the openGap command", outputStorage);
373 }
374 if (maxDecel <= 0 && maxDecel != -1 && maxDecel != libsumo::INVALID_DOUBLE_VALUE) {
375 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The value for the maximal braking rate must be positive for the openGap command", outputStorage);
376 } // else if <= 0: don't limit cf model's suggested brake rate, see libsumo::Vehicle::openGap
377 std::string refVehID = "";
378 if (nParameter == 6) {
379 if (!server.readTypeCheckingString(inputStorage, refVehID)) {
380 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The sixth create gap parameter must be a reference vehicle's ID given as a string.", outputStorage);
381 }
382 }
383 libsumo::Vehicle::openGap(id, newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel, refVehID);
384 }
385 }
386 break;
387 case libsumo::VAR_TYPE: {
388 std::string vTypeID;
389 if (!server.readTypeCheckingString(inputStorage, vTypeID)) {
390 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The vehicle type id must be given as a string.", outputStorage);
391 }
392 libsumo::Vehicle::setType(id, vTypeID);
393 }
394 break;
396 std::string rid;
397 if (!server.readTypeCheckingString(inputStorage, rid)) {
398 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The route id must be given as a string.", outputStorage);
399 }
400 libsumo::Vehicle::setRouteID(id, rid);
401 }
402 break;
403 case libsumo::VAR_ROUTE: {
404 std::vector<std::string> edgeIDs;
405 if (!server.readTypeCheckingStringList(inputStorage, edgeIDs)) {
406 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "A route must be defined as a list of edge ids.", outputStorage);
407 }
408 libsumo::Vehicle::setRoute(id, edgeIDs);
409 }
410 break;
412 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
413 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time requires a compound object.", outputStorage);
414 }
415 int parameterCount = inputStorage.readInt();
416 std::string edgeID;
417 double begTime = 0.;
418 double endTime = std::numeric_limits<double>::max();
419 double value = libsumo::INVALID_DOUBLE_VALUE;
420 if (parameterCount == 4) {
421 // begin time
422 if (!server.readTypeCheckingDouble(inputStorage, begTime)) {
423 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the begin time as first parameter.", outputStorage);
424 }
425 // begin time
426 if (!server.readTypeCheckingDouble(inputStorage, endTime)) {
427 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the end time as second parameter.", outputStorage);
428 }
429 // edge
430 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
431 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the referenced edge as third parameter.", outputStorage);
432 }
433 // value
434 if (!server.readTypeCheckingDouble(inputStorage, value)) {
435 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the travel time as double as fourth parameter.", outputStorage);
436 }
437 } else if (parameterCount == 2) {
438 // edge
439 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
440 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 2 parameters requires the referenced edge as first parameter.", outputStorage);
441 }
442 // value
443 if (!server.readTypeCheckingDouble(inputStorage, value)) {
444 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 2 parameters requires the travel time as second parameter.", outputStorage);
445 }
446 } else if (parameterCount == 1) {
447 // edge
448 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
449 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 1 parameter requires the referenced edge as first parameter.", outputStorage);
450 }
451 } else {
452 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time requires 1, 2, or 4 parameters.", outputStorage);
453 }
454 libsumo::Vehicle::setAdaptedTraveltime(id, edgeID, value, begTime, endTime);
455 }
456 break;
458 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
459 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort requires a compound object.", outputStorage);
460 }
461 int parameterCount = inputStorage.readInt();
462 std::string edgeID;
463 double begTime = 0.;
464 double endTime = std::numeric_limits<double>::max();
465 double value = libsumo::INVALID_DOUBLE_VALUE;
466 if (parameterCount == 4) {
467 // begin time
468 if (!server.readTypeCheckingDouble(inputStorage, begTime)) {
469 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the begin time as first parameter.", outputStorage);
470 }
471 // begin time
472 if (!server.readTypeCheckingDouble(inputStorage, endTime)) {
473 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the end time as second parameter.", outputStorage);
474 }
475 // edge
476 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
477 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the referenced edge as third parameter.", outputStorage);
478 }
479 // value
480 if (!server.readTypeCheckingDouble(inputStorage, value)) {
481 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the travel time as fourth parameter.", outputStorage);
482 }
483 } else if (parameterCount == 2) {
484 // edge
485 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
486 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 2 parameters requires the referenced edge as first parameter.", outputStorage);
487 }
488 if (!server.readTypeCheckingDouble(inputStorage, value)) {
489 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 2 parameters requires the travel time as second parameter.", outputStorage);
490 }
491 } else if (parameterCount == 1) {
492 // edge
493 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
494 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 1 parameter requires the referenced edge as first parameter.", outputStorage);
495 }
496 } else {
497 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort requires 1, 2, or 4 parameters.", outputStorage);
498 }
499 // retrieve
500 libsumo::Vehicle::setEffort(id, edgeID, value, begTime, endTime);
501 }
502 break;
504 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
505 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Rerouting requires a compound object.", outputStorage);
506 }
507 if (inputStorage.readInt() != 0) {
508 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Rerouting should obtain an empty compound object.", outputStorage);
509 }
510 libsumo::Vehicle::rerouteTraveltime(id, false);
511 }
512 break;
514 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
515 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Rerouting requires a compound object.", outputStorage);
516 }
517 if (inputStorage.readInt() != 0) {
518 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Rerouting should obtain an empty compound object.", outputStorage);
519 }
520 libsumo::Vehicle::rerouteEffort(id);
521 }
522 break;
524 libsumo::Vehicle::setSignals(id, StoHelp::readTypedInt(inputStorage, "Setting signals requires an integer."));
525 break;
527 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
528 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting position requires a compound object.", outputStorage);
529 }
530 const int numArgs = inputStorage.readInt();
531 if (numArgs < 2 || numArgs > 3) {
532 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting position should obtain the lane id and the position and optionally the reason.", outputStorage);
533 }
534 // lane ID
535 std::string laneID;
536 if (!server.readTypeCheckingString(inputStorage, laneID)) {
537 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first parameter for setting a position must be the lane ID given as a string.", outputStorage);
538 }
539 // position on lane
540 double position = 0;
541 if (!server.readTypeCheckingDouble(inputStorage, position)) {
542 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The second parameter for setting a position must be the position given as a double.", outputStorage);
543 }
544 int reason = libsumo::MOVE_AUTOMATIC;
545 if (numArgs == 3) {
546 reason = StoHelp::readTypedInt(inputStorage, "The third parameter for setting a position must be the reason given as an int.");
547 }
548 // process
549 libsumo::Vehicle::moveTo(id, laneID, position, reason);
550 }
551 break;
553 double impatience = 0;
554 if (!server.readTypeCheckingDouble(inputStorage, impatience)) {
555 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting impatience requires a double.", outputStorage);
556 }
557 libsumo::Vehicle::setImpatience(id, impatience);
558 }
559 break;
560 case libsumo::VAR_SPEED: {
561 double speed = 0;
562 if (!server.readTypeCheckingDouble(inputStorage, speed)) {
563 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting speed requires a double.", outputStorage);
564 }
565 libsumo::Vehicle::setSpeed(id, speed);
566 }
567 break;
569 double accel = 0;
570 double duration = 0;
571 int inputtype = inputStorage.readUnsignedByte();
572 if (inputtype == libsumo::TYPE_COMPOUND) {
573 int parameterCount = inputStorage.readInt();
574 if (parameterCount == 2) {
575 if (!server.readTypeCheckingDouble(inputStorage, accel)) {
576 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting acceleration requires the acceleration as first parameter given as a double.", outputStorage);
577 }
578 if (!server.readTypeCheckingDouble(inputStorage, duration)) {
579 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting acceleration requires the duration as second parameter given as a double.", outputStorage);
580 }
581 } else {
582 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting acceleration requires 2 parameters.", outputStorage);
583 }
584 } else {
585 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting acceleration requires 2 parameters as compound object description.", outputStorage);
586 }
587 if (duration < 0) {
588 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Duration must not be negative.", outputStorage);
589 }
590 libsumo::Vehicle::setAcceleration(id, accel, duration);
591 }
592 break;
594 double prevSpeed = 0;
595 double prevAcceleration = libsumo::INVALID_DOUBLE_VALUE;
596 int inputtype = inputStorage.readUnsignedByte();
597 if (inputtype == libsumo::TYPE_COMPOUND) {
598 // Setting previous speed with 2 parameters, uses a compound object description
599 int parameterCount = inputStorage.readInt();
600 if (parameterCount == 2) {
601 if (!server.readTypeCheckingDouble(inputStorage, prevSpeed)) {
602 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting previous speed using 2 parameters requires the previous speed as first parameter given as a double.", outputStorage);
603 }
604 if (!server.readTypeCheckingDouble(inputStorage, prevAcceleration)) {
605 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting previous speed using 2 parameters requires the previous acceleration as second parameter given as a double.", outputStorage);
606 }
607 } else if (parameterCount == 1) {
608 if (!server.readTypeCheckingDouble(inputStorage, prevSpeed)) {
609 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting previous speed using 1 parameter requires the previous speed as first parameter given as a double.", outputStorage);
610 }
611 } else {
612 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting previous speed requires 1 or 2 parameters.", outputStorage);
613 }
614 } else if (inputtype == libsumo::TYPE_DOUBLE) {
615 // Setting previous speed with 1 parameter (double), no compound object description
616 prevSpeed = inputStorage.readDouble();
617 } else {
618 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting previous speed requires 1 parameter given as a double or 2 parameters as compound object description.", outputStorage);
619 }
620 if (prevSpeed < 0) {
621 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Previous speed must not be negative.", outputStorage);
622 }
623 libsumo::Vehicle::setPreviousSpeed(id, prevSpeed, prevAcceleration);
624 }
625 break;
627 libsumo::Vehicle::setSpeedMode(id, StoHelp::readTypedInt(inputStorage, "Setting speed mode requires an integer."));
628 break;
630 libsumo::Vehicle::setLaneChangeMode(id, StoHelp::readTypedInt(inputStorage, "Setting lane change mode requires an integer."));
631 break;
633 libsumo::Vehicle::setRoutingMode(id, StoHelp::readTypedInt(inputStorage, "Setting routing mode requires an integer."));
634 break;
635 case libsumo::VAR_COLOR: {
637 if (!server.readTypeCheckingColor(inputStorage, col)) {
638 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The color must be given using the according type.", outputStorage);
639 }
640 libsumo::Vehicle::setColor(id, col);
641 break;
642 }
643 case libsumo::ADD: {
644 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
645 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Adding a vehicle requires a compound object.", outputStorage);
646 }
647 if (inputStorage.readInt() != 6) {
648 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Adding a vehicle needs six parameters.", outputStorage);
649 }
650 std::string vTypeID;
651 if (!server.readTypeCheckingString(inputStorage, vTypeID)) {
652 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "First parameter (type) requires a string.", outputStorage);
653 }
654 std::string routeID;
655 if (!server.readTypeCheckingString(inputStorage, routeID)) {
656 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Second parameter (route) requires a string.", outputStorage);
657 }
658 const int departCode = StoHelp::readTypedInt(inputStorage, "Third parameter (depart) requires an integer.");
659 std::string depart = toString(STEPS2TIME(departCode));
660 if (-departCode == static_cast<int>(DepartDefinition::TRIGGERED)) {
661 depart = "triggered";
662 } else if (-departCode == static_cast<int>(DepartDefinition::CONTAINER_TRIGGERED)) {
663 depart = "containerTriggered";
664 } else if (-departCode == static_cast<int>(DepartDefinition::NOW)) {
665 depart = "now";
666 } else if (-departCode == static_cast<int>(DepartDefinition::SPLIT)) {
667 depart = "split";
668 } else if (-departCode == static_cast<int>(DepartDefinition::BEGIN)) {
669 depart = "begin";
670 }
671
672 double departPosCode;
673 if (!server.readTypeCheckingDouble(inputStorage, departPosCode)) {
674 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Fourth parameter (position) requires a double.", outputStorage);
675 }
676 std::string departPos = toString(departPosCode);
677 if (-departPosCode == (int)DepartPosDefinition::RANDOM) {
678 departPos = "random";
679 } else if (-departPosCode == (int)DepartPosDefinition::RANDOM_FREE) {
680 departPos = "random_free";
681 } else if (-departPosCode == (int)DepartPosDefinition::FREE) {
682 departPos = "free";
683 } else if (-departPosCode == (int)DepartPosDefinition::BASE) {
684 departPos = "base";
685 } else if (-departPosCode == (int)DepartPosDefinition::LAST) {
686 departPos = "last";
687 } else if (-departPosCode == (int)DepartPosDefinition::GIVEN) {
688 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Invalid departure position.", outputStorage);
689 }
690
691 double departSpeedCode;
692 if (!server.readTypeCheckingDouble(inputStorage, departSpeedCode)) {
693 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Fifth parameter (speed) requires a double.", outputStorage);
694 }
695 std::string departSpeed = toString(departSpeedCode);
696 if (-departSpeedCode == (int)DepartSpeedDefinition::RANDOM) {
697 departSpeed = "random";
698 } else if (-departSpeedCode == (int)DepartSpeedDefinition::MAX) {
699 departSpeed = "max";
700 } else if (-departSpeedCode == (int)DepartSpeedDefinition::DESIRED) {
701 departSpeed = "desired";
702 } else if (-departSpeedCode == (int)DepartSpeedDefinition::LIMIT) {
703 departSpeed = "speedLimit";
704 } else if (-departSpeedCode == (int)DepartSpeedDefinition::LAST) {
705 departSpeed = "last";
706 } else if (-departSpeedCode == (int)DepartSpeedDefinition::AVG) {
707 departSpeed = "avg";
708 }
709
710 int departLaneCode;
711 if (!server.readTypeCheckingByte(inputStorage, departLaneCode)) {
712 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Sixth parameter (lane) requires a byte.", outputStorage);
713 }
714 std::string departLane = toString(departLaneCode);
715 if (-departLaneCode == (int)DepartLaneDefinition::RANDOM) {
716 departLane = "random";
717 } else if (-departLaneCode == (int)DepartLaneDefinition::FREE) {
718 departLane = "free";
719 } else if (-departLaneCode == (int)DepartLaneDefinition::ALLOWED_FREE) {
720 departLane = "allowed";
721 } else if (-departLaneCode == (int)DepartLaneDefinition::BEST_FREE) {
722 departLane = "best";
723 } else if (-departLaneCode == (int)DepartLaneDefinition::FIRST_ALLOWED) {
724 departLane = "first";
725 }
726 libsumo::Vehicle::add(id, routeID, vTypeID, depart, departLane, departPos, departSpeed);
727 }
728 break;
729 case libsumo::ADD_FULL: {
730 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
731 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Adding a vehicle requires a compound object.", outputStorage);
732 }
733 if (inputStorage.readInt() != 14) {
734 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Adding a fully specified vehicle needs fourteen parameters.", outputStorage);
735 }
736 std::string routeID;
737 if (!server.readTypeCheckingString(inputStorage, routeID)) {
738 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Second parameter (route) requires a string.", outputStorage);
739 }
740 std::string vTypeID;
741 if (!server.readTypeCheckingString(inputStorage, vTypeID)) {
742 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "First parameter (type) requires a string.", outputStorage);
743 }
744 std::string depart;
745 if (!server.readTypeCheckingString(inputStorage, depart)) {
746 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Third parameter (depart) requires an string.", outputStorage);
747 }
748 std::string departLane;
749 if (!server.readTypeCheckingString(inputStorage, departLane)) {
750 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Fourth parameter (depart lane) requires a string.", outputStorage);
751 }
752 std::string departPos;
753 if (!server.readTypeCheckingString(inputStorage, departPos)) {
754 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Fifth parameter (depart position) requires a string.", outputStorage);
755 }
756 std::string departSpeed;
757 if (!server.readTypeCheckingString(inputStorage, departSpeed)) {
758 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Sixth parameter (depart speed) requires a string.", outputStorage);
759 }
760 std::string arrivalLane;
761 if (!server.readTypeCheckingString(inputStorage, arrivalLane)) {
762 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Seventh parameter (arrival lane) requires a string.", outputStorage);
763 }
764 std::string arrivalPos;
765 if (!server.readTypeCheckingString(inputStorage, arrivalPos)) {
766 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Eighth parameter (arrival position) requires a string.", outputStorage);
767 }
768 std::string arrivalSpeed;
769 if (!server.readTypeCheckingString(inputStorage, arrivalSpeed)) {
770 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Ninth parameter (arrival speed) requires a string.", outputStorage);
771 }
772 std::string fromTaz;
773 if (!server.readTypeCheckingString(inputStorage, fromTaz)) {
774 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Tenth parameter (from taz) requires a string.", outputStorage);
775 }
776 std::string toTaz;
777 if (!server.readTypeCheckingString(inputStorage, toTaz)) {
778 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Eleventh parameter (to taz) requires a string.", outputStorage);
779 }
780 std::string line;
781 if (!server.readTypeCheckingString(inputStorage, line)) {
782 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Twelth parameter (line) requires a string.", outputStorage);
783 }
784 const int personCapacity = StoHelp::readTypedInt(inputStorage, "13th parameter (person capacity) requires an int.");
785 const int personNumber = StoHelp::readTypedInt(inputStorage, "14th parameter (person number) requires an int.");
786 libsumo::Vehicle::add(id, routeID, vTypeID, depart, departLane, departPos, departSpeed, arrivalLane, arrivalPos, arrivalSpeed,
787 fromTaz, toTaz, line, personCapacity, personNumber);
788 }
789 break;
790 case libsumo::REMOVE: {
791 int why = 0;
792 if (!server.readTypeCheckingByte(inputStorage, why)) {
793 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Removing a vehicle requires a byte.", outputStorage);
794 }
795 libsumo::Vehicle::remove(id, (char)why);
796 }
797 break;
798 case libsumo::MOVE_TO_XY: {
799 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
800 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "MoveToXY vehicle requires a compound object.", outputStorage);
801 }
802 const int numArgs = inputStorage.readInt();
803 if (numArgs < 5 || numArgs > 7) {
804 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "MoveToXY vehicle should obtain: edgeID, lane, x, y, angle and optionally keepRouteFlag and matchThreshold.", outputStorage);
805 }
806 std::string edgeID;
807 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
808 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first parameter for moveToXY must be the edge ID given as a string.", outputStorage);
809 }
810 const int laneIndex = StoHelp::readTypedInt(inputStorage, "The second parameter for moveToXY must be lane given as an int.");
811 double x = 0;
812 if (!server.readTypeCheckingDouble(inputStorage, x)) {
813 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third parameter for moveToXY must be the x-position given as a double.", outputStorage);
814 }
815 double y = 0;
816 if (!server.readTypeCheckingDouble(inputStorage, y)) {
817 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fourth parameter for moveToXY must be the y-position given as a double.", outputStorage);
818 }
819 double angle = 0;
820 if (!server.readTypeCheckingDouble(inputStorage, angle)) {
821 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fifth parameter for moveToXY must be the angle given as a double.", outputStorage);
822 }
823
824 int keepRouteFlag = 1;
825 if (numArgs >= 6) {
826 if (!server.readTypeCheckingByte(inputStorage, keepRouteFlag)) {
827 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The sixth parameter for moveToXY must be the keepRouteFlag given as a byte.", outputStorage);
828 }
829 }
830 double matchThreshold = 100;
831 if (numArgs == 7) {
832 if (!server.readTypeCheckingDouble(inputStorage, matchThreshold)) {
833 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The seventh parameter for moveToXY must be the matchThreshold given as a double.", outputStorage);
834 }
835 }
836 libsumo::Vehicle::moveToXY(id, edgeID, laneIndex, x, y, angle, keepRouteFlag, matchThreshold);
837 }
838 break;
840 double factor = 0;
841 if (!server.readTypeCheckingDouble(inputStorage, factor)) {
842 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting speed factor requires a double.", outputStorage);
843 }
844 libsumo::Vehicle::setSpeedFactor(id, factor);
845 }
846 break;
847 case libsumo::VAR_LINE: {
848 std::string line;
849 if (!server.readTypeCheckingString(inputStorage, line)) {
850 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The line must be given as a string.", outputStorage);
851 }
852 libsumo::Vehicle::setLine(id, line);
853 }
854 break;
855 case libsumo::VAR_VIA: {
856 std::vector<std::string> edgeIDs;
857 if (!server.readTypeCheckingStringList(inputStorage, edgeIDs)) {
858 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Vias must be defined as a list of edge ids.", outputStorage);
859 }
860 libsumo::Vehicle::setVia(id, edgeIDs);
861 }
862 break;
864 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
865 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "A compound object is needed for setting a parameter.", outputStorage);
866 }
867 //readt itemNo
868 inputStorage.readInt();
869 std::string name;
870 if (!server.readTypeCheckingString(inputStorage, name)) {
871 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The name of the parameter must be given as a string.", outputStorage);
872 }
873 std::string value;
874 if (!server.readTypeCheckingString(inputStorage, value)) {
875 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The value of the parameter must be given as a string.", outputStorage);
876 }
877 try {
879 libsumo::Vehicle::setParameter(id, name, value);
880 } catch (libsumo::TraCIException& e) {
881 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, e.what(), outputStorage);
882 }
883 }
884 break;
886 // Highlight the vehicle by adding a tracking polygon. (NOTE: duplicated code exists for POI domain)
887 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
888 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "A compound object is needed for highlighting an object.", outputStorage);
889 }
890 const int itemNo = inputStorage.readInt();
891 if (itemNo > 5) {
892 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Highlighting an object needs zero to five parameters.", outputStorage);
893 }
895 if (itemNo > 0) {
896 if (!server.readTypeCheckingColor(inputStorage, col)) {
897 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first parameter for highlighting must be the highlight color.", outputStorage);
898 }
899 }
900 double size = -1;
901 if (itemNo > 1) {
902 if (!server.readTypeCheckingDouble(inputStorage, size)) {
903 return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The second parameter for highlighting must be the highlight size.", outputStorage);
904 }
905 }
906 int alphaMax = -1;
907 if (itemNo > 2) {
908 if (!server.readTypeCheckingUnsignedByte(inputStorage, alphaMax)) {
909 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third parameter for highlighting must be maximal alpha.", outputStorage);
910 }
911 }
912 double duration = -1;
913 if (itemNo > 3) {
914 if (!server.readTypeCheckingDouble(inputStorage, duration)) {
915 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fourth parameter for highlighting must be the highlight duration.", outputStorage);
916 }
917 }
918 int type = 0;
919 if (itemNo > 4) {
920 if (!server.readTypeCheckingUnsignedByte(inputStorage, type)) {
921 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fifth parameter for highlighting must be the highlight type id as ubyte.", outputStorage);
922 }
923 }
924 libsumo::Vehicle::highlight(id, col, size, alphaMax, duration, type);
925 }
926 break;
928 std::vector<std::string> reservations;
929 if (!server.readTypeCheckingStringList(inputStorage, reservations)) {
930 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "A dispatch command must be defined as a list of reservation ids.", outputStorage);
931 }
932 libsumo::Vehicle::dispatchTaxi(id, reservations);
933 }
934 break;
936 double value = 0;
937 if (!server.readTypeCheckingDouble(inputStorage, value)) {
938 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting action step length requires a double.", outputStorage);
939 }
940 if (fabs(value) == std::numeric_limits<double>::infinity()) {
941 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Invalid action step length.", outputStorage);
942 }
943 bool resetActionOffset = value >= 0.0;
944 libsumo::Vehicle::setActionStepLength(id, fabs(value), resetActionOffset);
945 }
946 break;
948 double value = 0;
949 if (!server.readTypeCheckingDouble(inputStorage, value)) {
950 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting lateral lane position requires a double.", outputStorage);
951 }
952 libsumo::Vehicle::setLateralLanePosition(id, value);
953 }
954 break;
956 libsumo::Vehicle::updateBestLanes(id);
957 }
958 break;
959 case libsumo::VAR_MINGAP: {
960 double value = 0;
961 if (!server.readTypeCheckingDouble(inputStorage, value)) {
962 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting minimum gap requires a double.", outputStorage);
963 }
964 if (value < 0.0 || fabs(value) == std::numeric_limits<double>::infinity()) {
965 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Invalid minimum gap.", outputStorage);
966 }
967 libsumo::Vehicle::setMinGap(id, value);
968 }
969 break;
971 double value = 0;
972 if (!server.readTypeCheckingDouble(inputStorage, value)) {
973 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting minimum lateral gap requires a double.", outputStorage);
974 }
975 if (value < 0.0 || fabs(value) == std::numeric_limits<double>::infinity()) {
976 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Invalid minimum lateral gap.", outputStorage);
977 }
978 libsumo::Vehicle::setMinGapLat(id, value);
979 }
980 break;
981 default: {
982 try {
983 if (!TraCIServerAPI_VehicleType::setVariable(libsumo::CMD_SET_VEHICLE_VARIABLE, variable, v->getSingularType().getID(), server, inputStorage, outputStorage)) {
984 return false;
985 }
986 } catch (ProcessError& e) {
987 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, e.what(), outputStorage);
988 } catch (libsumo::TraCIException& e) {
989 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, e.what(), outputStorage);
990 }
991 }
992 break;
993 }
994 } catch (libsumo::TraCIException& e) {
995 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, e.what(), outputStorage);
996 }
998 return true;
999}
1000
1001
1002bool
1003TraCIServerAPI_Vehicle::insertReplaceStop(TraCIServer& server, tcpip::Storage& inputStorage, tcpip::Storage& outputStorage, const std::string& id, bool replace) {
1004 const std::string m1 = replace ? "Replacing" : "Inserting";
1005 const std::string m2 = replace ? "replacement" : "insertion";
1006
1007 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
1008 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, m1 + " stop needs a compound object description.", outputStorage);
1009 }
1010 int compoundSize = inputStorage.readInt();
1011 if (compoundSize != 8 && compoundSize != 9) {
1012 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, m1 + " stop needs a compound object description of eight or nine items.", outputStorage);
1013 }
1014 // read road map position
1015 std::string edgeID;
1016 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
1017 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first stop " + m2 + " parameter must be the edge id given as a string.", outputStorage);
1018 }
1019 double pos = 0;
1020 if (!server.readTypeCheckingDouble(inputStorage, pos)) {
1021 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The second stop " + m2 + " parameter must be the end position along the edge given as a double.", outputStorage);
1022 }
1023 int laneIndex = 0;
1024 if (!server.readTypeCheckingByte(inputStorage, laneIndex)) {
1025 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third stop " + m2 + " parameter must be the lane index given as a byte.", outputStorage);
1026 }
1027 // waitTime
1028 double duration = libsumo::INVALID_DOUBLE_VALUE;
1029 if (!server.readTypeCheckingDouble(inputStorage, duration)) {
1030 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "The fourth stop " + m2 + " parameter must be the stopping duration given as a double.", outputStorage);
1031 }
1032 const int stopFlags = StoHelp::readTypedInt(inputStorage, "The fifth stop " + m2 + " parameter must be a int indicating its parking/triggered status.");
1033 double startPos = libsumo::INVALID_DOUBLE_VALUE;
1034 if (!server.readTypeCheckingDouble(inputStorage, startPos)) {
1035 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The sixth stop " + m2 + " parameter must be the start position along the edge given as a double.", outputStorage);
1036 }
1037 double until = libsumo::INVALID_DOUBLE_VALUE;
1038 if (!server.readTypeCheckingDouble(inputStorage, until)) {
1039 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The seventh stop " + m2 + " parameter must be the minimum departure time given as a double.", outputStorage);
1040 }
1041 const int nextStopIndex = StoHelp::readTypedInt(inputStorage, "The eigth stop " + m2 + " parameter must be the replacement index given as a int.");
1042 int teleport = 0;
1043 if (compoundSize == 9) {
1044 if (!server.readTypeCheckingByte(inputStorage, teleport)) {
1045 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The nineth stop " + m2 + " parameter must be the teleport flag given as a byte.", outputStorage);
1046 }
1047 }
1048 if (replace) {
1049 libsumo::Vehicle::replaceStop(id, nextStopIndex, edgeID, pos, laneIndex, duration, stopFlags, startPos, until, teleport);
1050 } else {
1051 libsumo::Vehicle::insertStop(id, nextStopIndex, edgeID, pos, laneIndex, duration, stopFlags, startPos, until, teleport);
1052 }
1053 return true;
1054}
1055/****************************************************************************/
SUMOTime DELTA_T
Definition SUMOTime.cpp:38
#define STEPS2TIME(x)
Definition SUMOTime.h:55
#define SUMOTime_MAX
Definition SUMOTime.h:34
#define SIMTIME
Definition SUMOTime.h:62
@ RANDOM
The lane is chosen randomly.
@ BEST_FREE
The least occupied lane from best lanes.
@ ALLOWED_FREE
The least occupied lane from lanes which allow the continuation.
@ FIRST_ALLOWED
The rightmost lane the vehicle may use.
@ FREE
The least occupied lane is used.
@ RANDOM
A random position is chosen.
@ GIVEN
The position is given.
@ FREE
A free position is chosen.
@ BASE
Back-at-zero position.
@ LAST
Insert behind the last vehicle as close as possible to still allow the specified departSpeed....
@ RANDOM_FREE
If a fixed number of random choices fails, a free position is chosen.
@ RANDOM
The speed is chosen randomly.
@ MAX
The maximum safe speed is used.
@ LIMIT
The maximum lane speed is used (speedLimit)
@ DESIRED
The maximum lane speed is used (speedLimit * speedFactor)
@ LAST
The speed of the last vehicle. Fallback to DepartSpeedDefinition::DESIRED if there is no vehicle on t...
@ AVG
The average speed on the lane. Fallback to DepartSpeedDefinition::DESIRED if there is no vehicle on t...
@ BEGIN
The departure is at simulation start.
@ NOW
The vehicle is discarded if emission fails (not fully implemented yet)
@ SPLIT
The departure is triggered by a train split.
@ CONTAINER_TRIGGERED
The departure is container triggered.
@ TRIGGERED
The departure is person triggered.
std::string toHex(const T i, std::streamsize numDigits=0)
Definition ToString.h:56
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
The base class for microscopic and mesoscopic vehicles.
MSVehicleType & getSingularType()
Replaces the current vehicle type with a new one used by this vehicle only.
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition MSEdge.h:168
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:186
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition MSNet.h:392
SUMOVehicle * getVehicle(const std::string &id) const
Returns the vehicle with the given id.
const std::string & getID() const
Returns the name of the vehicle type.
const std::string & getID() const
Returns the id.
Definition Named.h:74
Representation of a vehicle.
Definition SUMOVehicle.h:62
static bool insertReplaceStop(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage, const std::string &id, bool replace)
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc4: Change Vehicle State)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa4: Get Vehicle Variable)
static bool setVariable(const int cmd, const int variable, const std::string &id, TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value for the given type.
TraCI server used to control sumo by a remote TraCI client.
Definition TraCIServer.h:59
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
bool readTypeCheckingString(tcpip::Storage &inputStorage, std::string &into)
Reads the value type and a string, verifying the type.
bool readTypeCheckingByte(tcpip::Storage &inputStorage, int &into)
Reads the value type and a byte, verifying the type.
tcpip::Storage & getWrapperStorage()
bool readTypeCheckingUnsignedByte(tcpip::Storage &inputStorage, int &into)
Reads the value type and an unsigned byte, verifying the type.
void initWrapper(const int domainID, const int variable, const std::string &objID)
bool writeErrorStatusCmd(int commandId, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage with status = RTYPE_ERR.
bool readTypeCheckingStringList(tcpip::Storage &inputStorage, std::vector< std::string > &into)
Reads the value type and a string list, verifying the type.
bool readTypeCheckingDouble(tcpip::Storage &inputStorage, double &into)
Reads the value type and a double, verifying the type.
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
bool readTypeCheckingColor(tcpip::Storage &inputStorage, libsumo::TraCIColor &into)
Reads the value type and a color, verifying the type.
static int readTypedInt(tcpip::Storage &ret, const std::string &error="")
An error which allows to continue.
Definition TraCIDefs.h:145
virtual std::string readString()
Definition storage.cpp:180
virtual int readUnsignedByte()
Definition storage.cpp:155
virtual double readDouble()
Definition storage.cpp:362
virtual int readInt()
Definition storage.cpp:311
TRACI_CONST double INVALID_DOUBLE_VALUE
TRACI_CONST int VAR_LANECHANGE_MODE
TRACI_CONST int MOVE_AUTOMATIC
TRACI_CONST int VAR_VEHICLECLASS
TRACI_CONST int VAR_IMPATIENCE
TRACI_CONST int VAR_LATALIGNMENT
TRACI_CONST int VAR_TYPE
TRACI_CONST int CMD_CHANGESUBLANE
TRACI_CONST int VAR_ROUTING_MODE
TRACI_CONST int VAR_MINGAP
TRACI_CONST int CMD_TAXI_DISPATCH
TRACI_CONST int VAR_SHAPECLASS
TRACI_CONST int CMD_STOP
TRACI_CONST int VAR_LINE
TRACI_CONST int VAR_EDGE_TRAVELTIME
TRACI_CONST int CMD_GET_VEHICLE_VARIABLE
TRACI_CONST int CMD_RESUME
TRACI_CONST int VAR_ACTIONSTEPLENGTH
TRACI_CONST int VAR_SPEED_FACTOR
TRACI_CONST int MOVE_TO_XY
TRACI_CONST int VAR_TAU
TRACI_CONST int TYPE_COMPOUND
TRACI_CONST int VAR_EDGE_EFFORT
TRACI_CONST int VAR_ROUTE
TRACI_CONST int VAR_HIGHLIGHT
TRACI_CONST int VAR_BOARDING_DURATION
TRACI_CONST int CMD_SET_POI_VARIABLE
TRACI_CONST int VAR_MOVE_TO
TRACI_CONST int VAR_UPDATE_BESTLANES
TRACI_CONST int VAR_COLOR
TRACI_CONST int VAR_WIDTH
TRACI_CONST int VAR_STOP_PARAMETER
TRACI_CONST int VAR_MAXSPEED
TRACI_CONST int CMD_CHANGETARGET
TRACI_CONST int ADD_FULL
TRACI_CONST int CMD_REROUTE_TO_PARKING
TRACI_CONST int RESPONSE_GET_VEHICLE_VARIABLE
TRACI_CONST int CMD_REROUTE_TRAVELTIME
TRACI_CONST int VAR_PREV_SPEED
TRACI_CONST int VAR_SPEEDSETMODE
TRACI_CONST int CMD_REPLACE_STOP
TRACI_CONST int VAR_MASS
TRACI_CONST int CMD_SET_VEHICLE_VARIABLE
TRACI_CONST int VAR_LENGTH
TRACI_CONST int VAR_MAXSPEED_LAT
TRACI_CONST int CMD_REROUTE_EFFORT
TRACI_CONST int VAR_PARAMETER
TRACI_CONST int REMOVE
TRACI_CONST int CMD_INSERT_STOP
TRACI_CONST int VAR_IMPERFECTION
TRACI_CONST int VAR_HEIGHT
TRACI_CONST int VAR_APPARENT_DECEL
TRACI_CONST int VAR_SPEED
TRACI_CONST int VAR_DECEL
TRACI_CONST int VAR_SIGNALS
TRACI_CONST int VAR_MINGAP_LAT
TRACI_CONST int CMD_SLOWDOWN
TRACI_CONST int VAR_ACCELERATION
TRACI_CONST int VAR_ROUTE_ID
TRACI_CONST int TYPE_DOUBLE
TRACI_CONST int CMD_OPENGAP
TRACI_CONST int VAR_LANEPOSITION_LAT
TRACI_CONST int CMD_CHANGELANE
TRACI_CONST int RTYPE_ERR
TRACI_CONST int VAR_EMERGENCY_DECEL
TRACI_CONST int RTYPE_OK
TRACI_CONST int VAR_EMISSIONCLASS
TRACI_CONST int VAR_ACCEL
TRACI_CONST int ADD
TRACI_CONST int VAR_VIA