Eclipse SUMO - Simulation of Urban MObility
TraCIServerAPI_Vehicle.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2009-2022 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/****************************************************************************/
27// APIs for getting/setting vehicle values via TraCI
28/****************************************************************************/
29#include <config.h>
30
31#include <microsim/MSNet.h>
33#include <microsim/MSVehicle.h>
35#include <microsim/MSLane.h>
36#include <microsim/MSEdge.h>
37#include <microsim/MSGlobals.h>
46#include <libsumo/Vehicle.h>
47#include <libsumo/VehicleType.h>
51
52
53// ===========================================================================
54// method definitions
55// ===========================================================================
56bool
58 tcpip::Storage& outputStorage) {
59 const int variable = inputStorage.readUnsignedByte();
60 const std::string id = inputStorage.readString();
62 try {
63 if (!libsumo::Vehicle::handleVariable(id, variable, &server, &inputStorage)) {
64 switch (variable) {
66 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
67 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Retrieval of travel time requires a compound object.", outputStorage);
68 }
69 if (inputStorage.readInt() != 2) {
70 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Retrieval of travel time requires time and edge as parameter.", outputStorage);
71 }
72 double time = 0.;
73 if (!server.readTypeCheckingDouble(inputStorage, time)) {
74 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Retrieval of travel time requires the referenced time as first parameter.", outputStorage);
75 }
76 // edge
77 std::string edgeID;
78 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
79 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Retrieval of travel time requires the referenced edge as second parameter.", outputStorage);
80 }
81 // retrieve
83 server.getWrapperStorage().writeDouble(libsumo::Vehicle::getAdaptedTraveltime(id, time, edgeID));
84 break;
85 }
87 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
88 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Retrieval of effort requires a compound object.", outputStorage);
89 }
90 if (inputStorage.readInt() != 2) {
91 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Retrieval of effort requires time and edge as parameter.", outputStorage);
92 }
93 double time = 0.;
94 if (!server.readTypeCheckingDouble(inputStorage, time)) {
95 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Retrieval of effort requires the referenced time as first parameter.", outputStorage);
96 }
97 // edge
98 std::string edgeID;
99 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
100 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Retrieval of effort requires the referenced edge as second parameter.", outputStorage);
101 }
103 server.getWrapperStorage().writeDouble(libsumo::Vehicle::getEffort(id, time, edgeID));
104 break;
105 }
108 tcpip::Storage tempContent;
109 int cnt = 0;
111 std::vector<libsumo::TraCIBestLanesData> bestLanes = libsumo::Vehicle::getBestLanes(id);
112 tempContent.writeInt((int)bestLanes.size());
113 ++cnt;
114 for (std::vector<libsumo::TraCIBestLanesData>::const_iterator i = bestLanes.begin(); i != bestLanes.end(); ++i) {
115 const libsumo::TraCIBestLanesData& bld = *i;
117 tempContent.writeString(bld.laneID);
118 ++cnt;
120 tempContent.writeDouble(bld.length);
121 ++cnt;
123 tempContent.writeDouble(bld.occupation);
124 ++cnt;
126 tempContent.writeByte(bld.bestLaneOffset);
127 ++cnt;
129 bld.allowsContinuation ? tempContent.writeUnsignedByte(1) : tempContent.writeUnsignedByte(0);
130 ++cnt;
132 tempContent.writeStringList(bld.continuationLanes);
133 ++cnt;
134 }
135 server.getWrapperStorage().writeInt((int)cnt);
136 server.getWrapperStorage().writeStorage(tempContent);
137 break;
138 }
140 std::vector<libsumo::TraCINextTLSData> nextTLS = libsumo::Vehicle::getNextTLS(id);
142 const int cnt = 1 + (int)nextTLS.size() * 4;
143 server.getWrapperStorage().writeInt(cnt);
145 server.getWrapperStorage().writeInt((int)nextTLS.size());
146 for (std::vector<libsumo::TraCINextTLSData>::iterator it = nextTLS.begin(); it != nextTLS.end(); ++it) {
148 server.getWrapperStorage().writeString(it->id);
150 server.getWrapperStorage().writeInt(it->tlIndex);
152 server.getWrapperStorage().writeDouble(it->dist);
154 server.getWrapperStorage().writeByte(it->state);
155 }
156 break;
157 }
159 // deliberate fallThrough!
160 int limit = 0;
161 if (!server.readTypeCheckingInt(inputStorage, limit)) {
162 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Stop retrieval uses an optional integer.", outputStorage);
163 }
164 writeNextStops(server, id, limit, true);
165 break;
166 }
168 writeNextStops(server, id, 0, false);
169 break;
170 }
172 // read variables
173 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
174 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "getting stop parameter needs a compound object description.", outputStorage);
175 }
176 int compoundSize = inputStorage.readInt();
177 if (compoundSize != 2) {
178 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "getting a stop parameter needs a compound object description of 2 items.", outputStorage);
179 }
180 int nextStopIndex;
181 if (!server.readTypeCheckingInt(inputStorage, nextStopIndex)) {
182 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first setStopParameter parameter must be the nextStopIndex given as an integer.", outputStorage);
183 }
184 std::string param;
185 if (!server.readTypeCheckingString(inputStorage, param)) {
186 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The second setStopParameter parameter must be the param given as a string.", outputStorage);
187 }
189 server.getWrapperStorage().writeString(libsumo::Vehicle::getStopParameter(id, nextStopIndex, param));
190 }
191 break;
193 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
194 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Retrieval of distance requires a compound object.", outputStorage);
195 }
196 if (inputStorage.readInt() != 2) {
197 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Retrieval of distance requires position and distance type as parameter.", outputStorage);
198 }
199
200 // read position
201 int posType = inputStorage.readUnsignedByte();
202 switch (posType) {
204 try {
205 const std::string roadID = inputStorage.readString();
206 const double edgePos = inputStorage.readDouble();
207 const int laneIndex = inputStorage.readUnsignedByte();
209 server.getWrapperStorage().writeDouble(libsumo::Vehicle::getDrivingDistance(id, roadID, edgePos, laneIndex));
210 break;
211 } catch (libsumo::TraCIException& e) {
212 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, e.what(), outputStorage);
213 }
216 const double p1x = inputStorage.readDouble();
217 const double p1y = inputStorage.readDouble();
218 if (posType == libsumo::POSITION_3D) {
219 inputStorage.readDouble(); // z value is ignored
220 }
222 server.getWrapperStorage().writeDouble(libsumo::Vehicle::getDrivingDistance2D(id, p1x, p1y));
223 break;
224 }
225 default:
226 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Unknown position format used for distance request", outputStorage);
227 }
228 // read distance type
229 int distType = inputStorage.readUnsignedByte();
230 if (distType != libsumo::REQUEST_DRIVINGDIST) {
231 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Only driving distance is supported for vehicles.", outputStorage);
232 }
233 break;
234 }
236 int direction = 0;
237 if (!server.readTypeCheckingInt(inputStorage, direction)) {
238 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Retrieval of lane change state requires a direction as int.", outputStorage);
239 }
240 const std::pair<int, int> state = libsumo::Vehicle::getLaneChangeState(id, direction);
242 server.getWrapperStorage().writeInt(2);
244 server.getWrapperStorage().writeInt(state.first);
246 server.getWrapperStorage().writeInt(state.second);
247 break;
248 }
250 int flag = 0;
251 if (!server.readTypeCheckingInt(inputStorage, flag)) {
252 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Retrieval of taxi fleet requires an integer flag.", outputStorage);
253 }
255 server.getWrapperStorage().writeStringList(libsumo::Vehicle::getTaxiFleet(flag));
256 break;
257 }
259 int mode;
260 if (!server.readTypeCheckingUnsignedByte(inputStorage, mode)) {
261 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Retrieval of neighboring vehicles needs bitset to specify mode.", outputStorage);
262 }
263 const std::vector<std::pair<std::string, double> >& neighVehicles = libsumo::Vehicle::getNeighbors(id, mode);
265 server.getWrapperStorage().writeInt((int)neighVehicles.size());
266 for (auto& p : neighVehicles) {
267 server.getWrapperStorage().writeString(p.first);
268 server.getWrapperStorage().writeDouble(p.second);
269 }
270 break;
271 }
273 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
274 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Retrieval of followSpeed requires requires a compound object.", outputStorage);
275 }
276 int parameterCount = inputStorage.readInt();
277 double speed;
278 double gap;
279 double leaderSpeed;
280 double leaderMaxDecel;
281 std::string leaderID;
282 if (parameterCount == 5) {
283 // speed
284 if (!server.readTypeCheckingDouble(inputStorage, speed)) {
285 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Retrieval of followSpeed requires the speed as first parameter.", outputStorage);
286 }
287 // gap
288 if (!server.readTypeCheckingDouble(inputStorage, gap)) {
289 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Retrieval of followSpeed requires the gap as second parameter.", outputStorage);
290 }
291 // leaderSpeed
292 if (!server.readTypeCheckingDouble(inputStorage, leaderSpeed)) {
293 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Retrieval of followSpeed requires the leaderSpeed as third parameter.", outputStorage);
294 }
295 // leaderMaxDecel
296 if (!server.readTypeCheckingDouble(inputStorage, leaderMaxDecel)) {
297 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Retrieval of followSpeed requires the leaderMaxDecel as fourth parameter.", outputStorage);
298 }
299 // leaderID
300 if (!server.readTypeCheckingString(inputStorage, leaderID)) {
301 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Retrieval of followSpeed requires the leaderID as fifth parameter.", outputStorage);
302 }
303 } else {
304 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Retrieval of followSpeed requires 5 parameters.", outputStorage);
305 }
306 // retrieve
308 server.getWrapperStorage().writeDouble(libsumo::Vehicle::getFollowSpeed(id, speed, gap, leaderSpeed, leaderMaxDecel, leaderID));
309 }
310 break;
312 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
313 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Retrieval of secureGap requires requires a compound object.", outputStorage);
314 }
315 int parameterCount = inputStorage.readInt();
316 double speed;
317 double leaderSpeed;
318 double leaderMaxDecel;
319 std::string leaderID;
320 if (parameterCount == 4) {
321 // speed
322 if (!server.readTypeCheckingDouble(inputStorage, speed)) {
323 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Retrieval of secureGap requires the speed as first parameter.", outputStorage);
324 }
325 // leaderSpeed
326 if (!server.readTypeCheckingDouble(inputStorage, leaderSpeed)) {
327 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Retrieval of secureGap requires the leaderSpeed as second parameter.", outputStorage);
328 }
329 // leaderMaxDecel
330 if (!server.readTypeCheckingDouble(inputStorage, leaderMaxDecel)) {
331 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Retrieval of secureGap requires the leaderMaxDecel as third parameter.", outputStorage);
332 }
333 // leaderID
334 if (!server.readTypeCheckingString(inputStorage, leaderID)) {
335 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Retrieval of secureGap requires the leaderID as fourth parameter.", outputStorage);
336 }
337 } else {
338 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Retrieval of secureGap requires 4 parameters.", outputStorage);
339 }
340 // retrieve
342 server.getWrapperStorage().writeDouble(libsumo::Vehicle::getSecureGap(id, speed, leaderSpeed, leaderMaxDecel, leaderID));
343 }
344 break;
346 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
347 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Retrieval of stopSpeed requires requires a compound object.", outputStorage);
348 }
349 int parameterCount = inputStorage.readInt();
350 double speed;
351 double gap;
352 if (parameterCount == 2) {
353 // speed
354 if (!server.readTypeCheckingDouble(inputStorage, speed)) {
355 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Retrieval of stopSpeed requires the speed as first parameter.", outputStorage);
356 }
357 // gap
358 if (!server.readTypeCheckingDouble(inputStorage, gap)) {
359 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Retrieval of stopSpeed requires the gap as second parameter.", outputStorage);
360 }
361 } else {
362 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Retrieval of stopSpeed requires 2 parameters.", outputStorage);
363 }
364 // retrieve
366 server.getWrapperStorage().writeDouble(libsumo::Vehicle::getStopSpeed(id, speed, gap));
367 }
368 break;
369 default:
370 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Get Vehicle Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
371 }
372 }
373 } catch (libsumo::TraCIException& e) {
374 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, e.what(), outputStorage);
375 }
377 server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
378 return true;
379}
380
381
382bool
384 tcpip::Storage& outputStorage) {
385 std::string warning = ""; // additional description for response
386 // variable
387 int variable = inputStorage.readUnsignedByte();
388 if (variable != libsumo::CMD_STOP && variable != libsumo::CMD_CHANGELANE
390 && variable != libsumo::CMD_CHANGESUBLANE && variable != libsumo::CMD_OPENGAP
391 && variable != libsumo::CMD_REPLACE_STOP
392 && variable != libsumo::CMD_INSERT_STOP
393 && variable != libsumo::VAR_STOP_PARAMETER
394 && variable != libsumo::CMD_SLOWDOWN && variable != libsumo::CMD_CHANGETARGET && variable != libsumo::CMD_RESUME
395 && variable != libsumo::VAR_TYPE && variable != libsumo::VAR_ROUTE_ID && variable != libsumo::VAR_ROUTE
396 && variable != libsumo::VAR_UPDATE_BESTLANES
397 && variable != libsumo::VAR_EDGE_TRAVELTIME && variable != libsumo::VAR_EDGE_EFFORT
399 && variable != libsumo::VAR_SIGNALS && variable != libsumo::VAR_MOVE_TO
400 && variable != libsumo::VAR_LENGTH && variable != libsumo::VAR_MAXSPEED && variable != libsumo::VAR_VEHICLECLASS
401 && variable != libsumo::VAR_SPEED_FACTOR && variable != libsumo::VAR_EMISSIONCLASS
402 && variable != libsumo::VAR_WIDTH && variable != libsumo::VAR_MINGAP && variable != libsumo::VAR_SHAPECLASS
403 && variable != libsumo::VAR_ACCEL && variable != libsumo::VAR_DECEL && variable != libsumo::VAR_IMPERFECTION
405 && variable != libsumo::VAR_ACTIONSTEPLENGTH
406 && variable != libsumo::VAR_TAU && variable != libsumo::VAR_LANECHANGE_MODE
407 && variable != libsumo::VAR_SPEED && variable != libsumo::VAR_ACCELERATION && variable != libsumo::VAR_PREV_SPEED && variable != libsumo::VAR_SPEEDSETMODE && variable != libsumo::VAR_COLOR
408 && variable != libsumo::ADD && variable != libsumo::ADD_FULL && variable != libsumo::REMOVE
409 && variable != libsumo::VAR_HEIGHT
410 && variable != libsumo::VAR_ROUTING_MODE
411 && variable != libsumo::VAR_LATALIGNMENT
412 && variable != libsumo::VAR_MAXSPEED_LAT
413 && variable != libsumo::VAR_MINGAP_LAT
414 && variable != libsumo::VAR_LINE
415 && variable != libsumo::VAR_VIA
416 && variable != libsumo::VAR_HIGHLIGHT
417 && variable != libsumo::CMD_TAXI_DISPATCH
418 && variable != libsumo::MOVE_TO_XY && variable != libsumo::VAR_PARAMETER/* && variable != libsumo::VAR_SPEED_TIME_LINE && variable != libsumo::VAR_LANE_TIME_LINE*/
419 ) {
420 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Change Vehicle State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
421 }
422 // id
423 std::string id = inputStorage.readString();
424#ifdef DEBUG_MOVEXY
425 std::cout << SIMTIME << " processSet veh=" << id << "\n";
426#endif
427 const bool shouldExist = variable != libsumo::ADD && variable != libsumo::ADD_FULL;
429 if (sumoVehicle == nullptr) {
430 if (shouldExist) {
431 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Vehicle '" + id + "' is not known", outputStorage);
432 }
433 }
434 MSBaseVehicle* v = dynamic_cast<MSBaseVehicle*>(sumoVehicle);
435 if (v == nullptr && shouldExist) {
436 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Vehicle '" + id + "' is not a proper vehicle", outputStorage);
437 }
438 try {
439 switch (variable) {
440 case libsumo::CMD_STOP: {
441 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
442 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Stop needs a compound object description.", outputStorage);
443 }
444 int compoundSize = inputStorage.readInt();
445 if (compoundSize < 4 || compoundSize > 7) {
446 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Stop needs a compound object description of four to seven items.", outputStorage);
447 }
448 // read road map position
449 std::string edgeID;
450 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
451 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first stop parameter must be the edge id given as a string.", outputStorage);
452 }
453 double pos = 0;
454 if (!server.readTypeCheckingDouble(inputStorage, pos)) {
455 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);
456 }
457 int laneIndex = 0;
458 if (!server.readTypeCheckingByte(inputStorage, laneIndex)) {
459 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third stop parameter must be the lane index given as a byte.", outputStorage);
460 }
461 // waitTime
462 double duration = libsumo::INVALID_DOUBLE_VALUE;
463 if (!server.readTypeCheckingDouble(inputStorage, duration)) {
464 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "The fourth stop parameter must be the stopping duration given as a double.", outputStorage);
465 }
466 int stopFlags = 0;
467 if (compoundSize >= 5) {
468 if (!server.readTypeCheckingByte(inputStorage, stopFlags)) {
469 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fifth stop parameter must be a byte indicating its parking/triggered status.", outputStorage);
470 }
471 }
472 double startPos = libsumo::INVALID_DOUBLE_VALUE;
473 if (compoundSize >= 6) {
474 if (!server.readTypeCheckingDouble(inputStorage, startPos)) {
475 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);
476 }
477 }
478 double until = libsumo::INVALID_DOUBLE_VALUE;
479 if (compoundSize >= 7) {
480 if (!server.readTypeCheckingDouble(inputStorage, until)) {
481 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The seventh stop parameter must be the minimum departure time given as a double.", outputStorage);
482 }
483 }
484 libsumo::Vehicle::setStop(id, edgeID, pos, laneIndex, duration, stopFlags, startPos, until);
485 }
486 break;
488 if (!insertReplaceStop(server, inputStorage, outputStorage, id, true)) {
489 return false;
490 }
491 break;
493 if (!insertReplaceStop(server, inputStorage, outputStorage, id, false)) {
494 return false;
495 }
496 break;
498 // read variables
499 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
500 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting stop parameter needs a compound object description.", outputStorage);
501 }
502 int compoundSize = inputStorage.readInt();
503 if (compoundSize != 3) {
504 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting a stop parameter needs a compound object description of 3 items.", outputStorage);
505 }
506 int nextStopIndex;
507 if (!server.readTypeCheckingInt(inputStorage, nextStopIndex)) {
508 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first setStopParameter parameter must be the nextStopIndex given as an integer.", outputStorage);
509 }
510 std::string param;
511 if (!server.readTypeCheckingString(inputStorage, param)) {
512 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The second setStopParameter parameter must be the param given as a string.", outputStorage);
513 }
514 std::string value;
515 if (!server.readTypeCheckingString(inputStorage, value)) {
516 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third setStopParameter parameter must be the value given as a string.", outputStorage);
517 }
518 libsumo::Vehicle::setStopParameter(id, nextStopIndex, param, value);
519 }
520 break;
522 // read variables
523 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
524 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Reroute to stop needs a compound object description.", outputStorage);
525 }
526 int compoundSize = inputStorage.readInt();
527 if (compoundSize != 1) {
528 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Reroute to stop needs a compound object description of 1 item.", outputStorage);
529 }
530 std::string parkingAreaID;
531 if (!server.readTypeCheckingString(inputStorage, parkingAreaID)) {
532 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);
533 }
534 libsumo::Vehicle::rerouteParkingArea(id, parkingAreaID);
535 }
536 break;
537 case libsumo::CMD_RESUME: {
538 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
539 server.writeStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::RTYPE_ERR, "Resuming requires a compound object.", outputStorage);
540 return false;
541 }
542 if (inputStorage.readInt() != 0) {
543 server.writeStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::RTYPE_ERR, "Resuming should obtain an empty compound object.", outputStorage);
544 return false;
545 }
546 libsumo::Vehicle::resume(id);
547 }
548 break;
550 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
551 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Lane change needs a compound object description.", outputStorage);
552 }
553 int compounds = inputStorage.readInt();
554 if (compounds != 3 && compounds != 2) {
555 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Lane change needs a compound object description of two or three items.", outputStorage);
556 }
557 // Lane ID
558 int laneIndex = 0;
559 if (!server.readTypeCheckingByte(inputStorage, laneIndex)) {
560 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first lane change parameter must be the lane index given as a byte.", outputStorage);
561 }
562 // duration
563 double duration = 0.;
564 if (!server.readTypeCheckingDouble(inputStorage, duration)) {
565 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The second lane change parameter must be the duration given as a double.", outputStorage);
566 }
567 // relativelanechange
568 int relative = 0;
569 if (compounds == 3) {
570 if (!server.readTypeCheckingByte(inputStorage, relative)) {
571 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);
572 }
573 }
574
575 if ((laneIndex < 0 || laneIndex >= (int)v->getEdge()->getLanes().size()) && relative < 1) {
576 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "No lane with index '" + toString(laneIndex) + "' on road '" + v->getEdge()->getID() + "'.", outputStorage);
577 }
578
579 if (relative < 1) {
580 libsumo::Vehicle::changeLane(id, laneIndex, duration);
581 } else {
582 libsumo::Vehicle::changeLaneRelative(id, laneIndex, duration);
583 }
584 }
585 break;
587 double latDist = 0;
588 if (!server.readTypeCheckingDouble(inputStorage, latDist)) {
589 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Sublane-changing requires a double.", outputStorage);
590 }
591 libsumo::Vehicle::changeSublane(id, latDist);
592 }
593 break;
595 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
596 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Slow down needs a compound object description.", outputStorage);
597 }
598 if (inputStorage.readInt() != 2) {
599 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Slow down needs a compound object description of two items.", outputStorage);
600 }
601 double newSpeed = 0;
602 if (!server.readTypeCheckingDouble(inputStorage, newSpeed)) {
603 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first slow down parameter must be the speed given as a double.", outputStorage);
604 }
605 if (newSpeed < 0) {
606 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Speed must not be negative", outputStorage);
607 }
608 double duration = 0.;
609 if (!server.readTypeCheckingDouble(inputStorage, duration)) {
610 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The second slow down parameter must be the duration given as a double.", outputStorage);
611 }
612 if (duration < 0 || SIMTIME + duration > STEPS2TIME(SUMOTime_MAX - DELTA_T)) {
613 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Invalid time interval", outputStorage);
614 }
615 libsumo::Vehicle::slowDown(id, newSpeed, duration);
616 }
617 break;
619 std::string edgeID;
620 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
621 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Change target requires a string containing the id of the new destination edge as parameter.", outputStorage);
622 }
623 libsumo::Vehicle::changeTarget(id, edgeID);
624 }
625 break;
627 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
628 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Create gap needs a compound object description.", outputStorage);
629 }
630 const int nParameter = inputStorage.readInt();
631 if (nParameter != 5 && nParameter != 6) {
632 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Create gap needs a compound object description of five or six items.", outputStorage);
633 }
634 double newTimeHeadway = 0;
635 if (!server.readTypeCheckingDouble(inputStorage, newTimeHeadway)) {
636 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);
637 }
638 double newSpaceHeadway = 0;
639 if (!server.readTypeCheckingDouble(inputStorage, newSpaceHeadway)) {
640 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);
641 }
642 double duration = 0.;
643 if (!server.readTypeCheckingDouble(inputStorage, duration)) {
644 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third create gap parameter must be the duration given as a double.", outputStorage);
645 }
646 double changeRate = 0;
647 if (!server.readTypeCheckingDouble(inputStorage, changeRate)) {
648 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fourth create gap parameter must be the change rate given as a double.", outputStorage);
649 }
650 double maxDecel = 0;
651 if (!server.readTypeCheckingDouble(inputStorage, maxDecel)) {
652 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fifth create gap parameter must be the maximal braking rate given as a double.", outputStorage);
653 }
654
655 if (newTimeHeadway == -1 && newSpaceHeadway == -1 && duration == -1 && changeRate == -1 && maxDecel == -1) {
656 libsumo::Vehicle::deactivateGapControl(id);
657 } else {
658 if (newTimeHeadway <= 0) {
659 if (newTimeHeadway != -1) {
660 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The value for the new desired time headway (tau) must be positive for create gap", outputStorage);
661 } // else if == -1: keep vehicles current headway, see libsumo::Vehicle::openGap
662 }
663 if (newSpaceHeadway < 0) {
664 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The value for the new desired space headway must be non-negative for create gap", outputStorage);
665 }
666 if ((duration < 0 && duration != -1) || SIMTIME + duration > STEPS2TIME(SUMOTime_MAX - DELTA_T)) {
667 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Invalid time interval for create gap", outputStorage);
668 }
669 if (changeRate <= 0) {
670 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The value for the change rate must be positive for the openGap command", outputStorage);
671 }
672 if (maxDecel <= 0 && maxDecel != -1 && maxDecel != libsumo::INVALID_DOUBLE_VALUE) {
673 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The value for the maximal braking rate must be positive for the openGap command", outputStorage);
674 } // else if <= 0: don't limit cf model's suggested brake rate, see libsumo::Vehicle::openGap
675 std::string refVehID = "";
676 if (nParameter == 6) {
677 if (!server.readTypeCheckingString(inputStorage, refVehID)) {
678 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);
679 }
680 }
681 libsumo::Vehicle::openGap(id, newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel, refVehID);
682 }
683 }
684 break;
685 case libsumo::VAR_TYPE: {
686 std::string vTypeID;
687 if (!server.readTypeCheckingString(inputStorage, vTypeID)) {
688 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The vehicle type id must be given as a string.", outputStorage);
689 }
690 libsumo::Vehicle::setType(id, vTypeID);
691 }
692 break;
694 std::string rid;
695 if (!server.readTypeCheckingString(inputStorage, rid)) {
696 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The route id must be given as a string.", outputStorage);
697 }
698 libsumo::Vehicle::setRouteID(id, rid);
699 }
700 break;
701 case libsumo::VAR_ROUTE: {
702 std::vector<std::string> edgeIDs;
703 if (!server.readTypeCheckingStringList(inputStorage, edgeIDs)) {
704 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "A route must be defined as a list of edge ids.", outputStorage);
705 }
706 libsumo::Vehicle::setRoute(id, edgeIDs);
707 }
708 break;
710 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
711 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time requires a compound object.", outputStorage);
712 }
713 int parameterCount = inputStorage.readInt();
714 std::string edgeID;
715 double begTime = 0.;
716 double endTime = std::numeric_limits<double>::max();
717 double value = libsumo::INVALID_DOUBLE_VALUE;
718 if (parameterCount == 4) {
719 // begin time
720 if (!server.readTypeCheckingDouble(inputStorage, begTime)) {
721 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the begin time as first parameter.", outputStorage);
722 }
723 // begin time
724 if (!server.readTypeCheckingDouble(inputStorage, endTime)) {
725 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the end time as second parameter.", outputStorage);
726 }
727 // edge
728 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
729 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the referenced edge as third parameter.", outputStorage);
730 }
731 // value
732 if (!server.readTypeCheckingDouble(inputStorage, value)) {
733 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the travel time as double as fourth parameter.", outputStorage);
734 }
735 } else if (parameterCount == 2) {
736 // edge
737 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
738 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 2 parameters requires the referenced edge as first parameter.", outputStorage);
739 }
740 // value
741 if (!server.readTypeCheckingDouble(inputStorage, value)) {
742 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 2 parameters requires the travel time as second parameter.", outputStorage);
743 }
744 } else if (parameterCount == 1) {
745 // edge
746 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
747 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 1 parameter requires the referenced edge as first parameter.", outputStorage);
748 }
749 } else {
750 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time requires 1, 2, or 4 parameters.", outputStorage);
751 }
752 libsumo::Vehicle::setAdaptedTraveltime(id, edgeID, value, begTime, endTime);
753 }
754 break;
756 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
757 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort requires a compound object.", outputStorage);
758 }
759 int parameterCount = inputStorage.readInt();
760 std::string edgeID;
761 double begTime = 0.;
762 double endTime = std::numeric_limits<double>::max();
763 double value = libsumo::INVALID_DOUBLE_VALUE;
764 if (parameterCount == 4) {
765 // begin time
766 if (!server.readTypeCheckingDouble(inputStorage, begTime)) {
767 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the begin time as first parameter.", outputStorage);
768 }
769 // begin time
770 if (!server.readTypeCheckingDouble(inputStorage, endTime)) {
771 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the end time as second parameter.", outputStorage);
772 }
773 // edge
774 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
775 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the referenced edge as third parameter.", outputStorage);
776 }
777 // value
778 if (!server.readTypeCheckingDouble(inputStorage, value)) {
779 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the travel time as fourth parameter.", outputStorage);
780 }
781 } else if (parameterCount == 2) {
782 // edge
783 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
784 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 2 parameters requires the referenced edge as first parameter.", outputStorage);
785 }
786 if (!server.readTypeCheckingDouble(inputStorage, value)) {
787 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 2 parameters requires the travel time as second parameter.", outputStorage);
788 }
789 } else if (parameterCount == 1) {
790 // edge
791 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
792 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 1 parameter requires the referenced edge as first parameter.", outputStorage);
793 }
794 } else {
795 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort requires 1, 2, or 4 parameters.", outputStorage);
796 }
797 // retrieve
798 libsumo::Vehicle::setEffort(id, edgeID, value, begTime, endTime);
799 }
800 break;
802 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
803 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Rerouting requires a compound object.", outputStorage);
804 }
805 if (inputStorage.readInt() != 0) {
806 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Rerouting should obtain an empty compound object.", outputStorage);
807 }
808 libsumo::Vehicle::rerouteTraveltime(id, false);
809 }
810 break;
812 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
813 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Rerouting requires a compound object.", outputStorage);
814 }
815 if (inputStorage.readInt() != 0) {
816 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Rerouting should obtain an empty compound object.", outputStorage);
817 }
818 libsumo::Vehicle::rerouteEffort(id);
819 }
820 break;
822 int signals = 0;
823 if (!server.readTypeCheckingInt(inputStorage, signals)) {
824 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting signals requires an integer.", outputStorage);
825 }
826 libsumo::Vehicle::setSignals(id, signals);
827 }
828 break;
830 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
831 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting position requires a compound object.", outputStorage);
832 }
833 const int numArgs = inputStorage.readInt();
834 if (numArgs < 2 || numArgs > 3) {
835 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting position should obtain the lane id and the position and optionally the reason.", outputStorage);
836 }
837 // lane ID
838 std::string laneID;
839 if (!server.readTypeCheckingString(inputStorage, laneID)) {
840 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);
841 }
842 // position on lane
843 double position = 0;
844 if (!server.readTypeCheckingDouble(inputStorage, position)) {
845 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The second parameter for setting a position must be the position given as a double.", outputStorage);
846 }
847 int reason = libsumo::MOVE_AUTOMATIC;
848 if (numArgs == 3) {
849 if (!server.readTypeCheckingInt(inputStorage, reason)) {
850 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third parameter for setting a position must be the reason given as an int.", outputStorage);
851 }
852 }
853 // process
854 libsumo::Vehicle::moveTo(id, laneID, position, reason);
855 }
856 break;
857 case libsumo::VAR_SPEED: {
858 double speed = 0;
859 if (!server.readTypeCheckingDouble(inputStorage, speed)) {
860 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting speed requires a double.", outputStorage);
861 }
862 libsumo::Vehicle::setSpeed(id, speed);
863 }
864 break;
866 double accel = 0;
867 double duration = 0;
868 int inputtype = inputStorage.readUnsignedByte();
869 if (inputtype == libsumo::TYPE_COMPOUND) {
870 int parameterCount = inputStorage.readInt();
871 if (parameterCount == 2) {
872 if (!server.readTypeCheckingDouble(inputStorage, accel)) {
873 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting acceleration requires the acceleration as first parameter given as a double.", outputStorage);
874 }
875 if (!server.readTypeCheckingDouble(inputStorage, duration)) {
876 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting acceleration requires the duration as second parameter given as a double.", outputStorage);
877 }
878 } else {
879 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting acceleration requires 2 parameters.", outputStorage);
880 }
881 } else {
882 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting acceleration requires 2 parameters as compound object description.", outputStorage);
883 }
884 if (duration < 0) {
885 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Duration must not be negative.", outputStorage);
886 }
887 libsumo::Vehicle::setAcceleration(id, accel, duration);
888 }
889 break;
891 double prevSpeed = 0;
892 double prevAcceleration = libsumo::INVALID_DOUBLE_VALUE;
893 int inputtype = inputStorage.readUnsignedByte();
894 if (inputtype == libsumo::TYPE_COMPOUND) {
895 // Setting previous speed with 2 parameters, uses a compound object description
896 int parameterCount = inputStorage.readInt();
897 if (parameterCount == 2) {
898 if (!server.readTypeCheckingDouble(inputStorage, prevSpeed)) {
899 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);
900 }
901 if (!server.readTypeCheckingDouble(inputStorage, prevAcceleration)) {
902 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);
903 }
904 } else if (parameterCount == 1) {
905 if (!server.readTypeCheckingDouble(inputStorage, prevSpeed)) {
906 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);
907 }
908 } else {
909 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting previous speed requires 1 or 2 parameters.", outputStorage);
910 }
911 } else if (inputtype == libsumo::TYPE_DOUBLE) {
912 // Setting previous speed with 1 parameter (double), no compound object description
913 prevSpeed = inputStorage.readDouble();
914 } else {
915 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);
916 }
917 if (prevSpeed < 0) {
918 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Previous speed must not be negative.", outputStorage);
919 }
920 libsumo::Vehicle::setPreviousSpeed(id, prevSpeed, prevAcceleration);
921 }
922 break;
924 int speedMode = 0;
925 if (!server.readTypeCheckingInt(inputStorage, speedMode)) {
926 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting speed mode requires an integer.", outputStorage);
927 }
928 libsumo::Vehicle::setSpeedMode(id, speedMode);
929 }
930 break;
932 int laneChangeMode = 0;
933 if (!server.readTypeCheckingInt(inputStorage, laneChangeMode)) {
934 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting lane change mode requires an integer.", outputStorage);
935 }
936 libsumo::Vehicle::setLaneChangeMode(id, laneChangeMode);
937 }
938 break;
940 int routingMode = 0;
941 if (!server.readTypeCheckingInt(inputStorage, routingMode)) {
942 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting routing mode requires an integer.", outputStorage);
943 }
944 libsumo::Vehicle::setRoutingMode(id, routingMode);
945 }
946 break;
947 case libsumo::VAR_COLOR: {
949 if (!server.readTypeCheckingColor(inputStorage, col)) {
950 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The color must be given using the according type.", outputStorage);
951 }
952 libsumo::Vehicle::setColor(id, col);
953 break;
954 }
955 case libsumo::ADD: {
956 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
957 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Adding a vehicle requires a compound object.", outputStorage);
958 }
959 if (inputStorage.readInt() != 6) {
960 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Adding a vehicle needs six parameters.", outputStorage);
961 }
962 std::string vTypeID;
963 if (!server.readTypeCheckingString(inputStorage, vTypeID)) {
964 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "First parameter (type) requires a string.", outputStorage);
965 }
966 std::string routeID;
967 if (!server.readTypeCheckingString(inputStorage, routeID)) {
968 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Second parameter (route) requires a string.", outputStorage);
969 }
970 int departCode;
971 if (!server.readTypeCheckingInt(inputStorage, departCode)) {
972 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Third parameter (depart) requires an integer.", outputStorage);
973 }
974 std::string depart = toString(STEPS2TIME(departCode));
975 if (-departCode == static_cast<int>(DepartDefinition::TRIGGERED)) {
976 depart = "triggered";
977 } else if (-departCode == static_cast<int>(DepartDefinition::CONTAINER_TRIGGERED)) {
978 depart = "containerTriggered";
979 } else if (-departCode == static_cast<int>(DepartDefinition::NOW)) {
980 depart = "now";
981 }
982
983 double departPosCode;
984 if (!server.readTypeCheckingDouble(inputStorage, departPosCode)) {
985 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Fourth parameter (position) requires a double.", outputStorage);
986 }
987 std::string departPos = toString(departPosCode);
988 if (-departPosCode == (int)DepartPosDefinition::RANDOM) {
989 departPos = "random";
990 } else if (-departPosCode == (int)DepartPosDefinition::RANDOM_FREE) {
991 departPos = "random_free";
992 } else if (-departPosCode == (int)DepartPosDefinition::FREE) {
993 departPos = "free";
994 } else if (-departPosCode == (int)DepartPosDefinition::BASE) {
995 departPos = "base";
996 } else if (-departPosCode == (int)DepartPosDefinition::LAST) {
997 departPos = "last";
998 } else if (-departPosCode == (int)DepartPosDefinition::GIVEN) {
999 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Invalid departure position.", outputStorage);
1000 }
1001
1002 double departSpeedCode;
1003 if (!server.readTypeCheckingDouble(inputStorage, departSpeedCode)) {
1004 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Fifth parameter (speed) requires a double.", outputStorage);
1005 }
1006 std::string departSpeed = toString(departSpeedCode);
1007 if (-departSpeedCode == (int)DepartSpeedDefinition::RANDOM) {
1008 departSpeed = "random";
1009 } else if (-departSpeedCode == (int)DepartSpeedDefinition::MAX) {
1010 departSpeed = "max";
1011 } else if (-departSpeedCode == (int)DepartSpeedDefinition::DESIRED) {
1012 departSpeed = "desired";
1013 } else if (-departSpeedCode == (int)DepartSpeedDefinition::LIMIT) {
1014 departSpeed = "speedLimit";
1015 } else if (-departSpeedCode == (int)DepartSpeedDefinition::LAST) {
1016 departSpeed = "last";
1017 } else if (-departSpeedCode == (int)DepartSpeedDefinition::AVG) {
1018 departSpeed = "avg";
1019 }
1020
1021 int departLaneCode;
1022 if (!server.readTypeCheckingByte(inputStorage, departLaneCode)) {
1023 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Sixth parameter (lane) requires a byte.", outputStorage);
1024 }
1025 std::string departLane = toString(departLaneCode);
1026 if (-departLaneCode == (int)DepartLaneDefinition::RANDOM) {
1027 departLane = "random";
1028 } else if (-departLaneCode == (int)DepartLaneDefinition::FREE) {
1029 departLane = "free";
1030 } else if (-departLaneCode == (int)DepartLaneDefinition::ALLOWED_FREE) {
1031 departLane = "allowed";
1032 } else if (-departLaneCode == (int)DepartLaneDefinition::BEST_FREE) {
1033 departLane = "best";
1034 } else if (-departLaneCode == (int)DepartLaneDefinition::FIRST_ALLOWED) {
1035 departLane = "first";
1036 }
1037 libsumo::Vehicle::add(id, routeID, vTypeID, depart, departLane, departPos, departSpeed);
1038 }
1039 break;
1040 case libsumo::ADD_FULL: {
1041 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
1042 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Adding a vehicle requires a compound object.", outputStorage);
1043 }
1044 if (inputStorage.readInt() != 14) {
1045 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Adding a fully specified vehicle needs fourteen parameters.", outputStorage);
1046 }
1047 std::string routeID;
1048 if (!server.readTypeCheckingString(inputStorage, routeID)) {
1049 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Second parameter (route) requires a string.", outputStorage);
1050 }
1051 std::string vTypeID;
1052 if (!server.readTypeCheckingString(inputStorage, vTypeID)) {
1053 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "First parameter (type) requires a string.", outputStorage);
1054 }
1055 std::string depart;
1056 if (!server.readTypeCheckingString(inputStorage, depart)) {
1057 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Third parameter (depart) requires an string.", outputStorage);
1058 }
1059 std::string departLane;
1060 if (!server.readTypeCheckingString(inputStorage, departLane)) {
1061 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Fourth parameter (depart lane) requires a string.", outputStorage);
1062 }
1063 std::string departPos;
1064 if (!server.readTypeCheckingString(inputStorage, departPos)) {
1065 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Fifth parameter (depart position) requires a string.", outputStorage);
1066 }
1067 std::string departSpeed;
1068 if (!server.readTypeCheckingString(inputStorage, departSpeed)) {
1069 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Sixth parameter (depart speed) requires a string.", outputStorage);
1070 }
1071 std::string arrivalLane;
1072 if (!server.readTypeCheckingString(inputStorage, arrivalLane)) {
1073 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Seventh parameter (arrival lane) requires a string.", outputStorage);
1074 }
1075 std::string arrivalPos;
1076 if (!server.readTypeCheckingString(inputStorage, arrivalPos)) {
1077 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Eighth parameter (arrival position) requires a string.", outputStorage);
1078 }
1079 std::string arrivalSpeed;
1080 if (!server.readTypeCheckingString(inputStorage, arrivalSpeed)) {
1081 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Ninth parameter (arrival speed) requires a string.", outputStorage);
1082 }
1083 std::string fromTaz;
1084 if (!server.readTypeCheckingString(inputStorage, fromTaz)) {
1085 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Tenth parameter (from taz) requires a string.", outputStorage);
1086 }
1087 std::string toTaz;
1088 if (!server.readTypeCheckingString(inputStorage, toTaz)) {
1089 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Eleventh parameter (to taz) requires a string.", outputStorage);
1090 }
1091 std::string line;
1092 if (!server.readTypeCheckingString(inputStorage, line)) {
1093 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Twelth parameter (line) requires a string.", outputStorage);
1094 }
1095 int personCapacity;
1096 if (!server.readTypeCheckingInt(inputStorage, personCapacity)) {
1097 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "13th parameter (person capacity) requires an int.", outputStorage);
1098 }
1099 int personNumber;
1100 if (!server.readTypeCheckingInt(inputStorage, personNumber)) {
1101 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "14th parameter (person number) requires an int.", outputStorage);
1102 }
1103 libsumo::Vehicle::add(id, routeID, vTypeID, depart, departLane, departPos, departSpeed, arrivalLane, arrivalPos, arrivalSpeed,
1104 fromTaz, toTaz, line, personCapacity, personNumber);
1105 }
1106 break;
1107 case libsumo::REMOVE: {
1108 int why = 0;
1109 if (!server.readTypeCheckingByte(inputStorage, why)) {
1110 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Removing a vehicle requires a byte.", outputStorage);
1111 }
1112 libsumo::Vehicle::remove(id, (char)why);
1113 }
1114 break;
1115 case libsumo::MOVE_TO_XY: {
1116 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
1117 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "MoveToXY vehicle requires a compound object.", outputStorage);
1118 }
1119 const int numArgs = inputStorage.readInt();
1120 if (numArgs < 5 || numArgs > 7) {
1121 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "MoveToXY vehicle should obtain: edgeID, lane, x, y, angle and optionally keepRouteFlag and matchThreshold.", outputStorage);
1122 }
1123 // edge ID
1124 std::string edgeID;
1125 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
1126 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first parameter for moveToXY must be the edge ID given as a string.", outputStorage);
1127 }
1128 // lane index
1129 int laneNum = 0;
1130 if (!server.readTypeCheckingInt(inputStorage, laneNum)) {
1131 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The second parameter for moveToXY must be lane given as an int.", outputStorage);
1132 }
1133 // x
1134 double x = 0;
1135 if (!server.readTypeCheckingDouble(inputStorage, x)) {
1136 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third parameter for moveToXY must be the x-position given as a double.", outputStorage);
1137 }
1138 // y
1139 double y = 0;
1140 if (!server.readTypeCheckingDouble(inputStorage, y)) {
1141 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fourth parameter for moveToXY must be the y-position given as a double.", outputStorage);
1142 }
1143 // angle
1144 double angle = 0;
1145 if (!server.readTypeCheckingDouble(inputStorage, angle)) {
1146 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fifth parameter for moveToXY must be the angle given as a double.", outputStorage);
1147 }
1148
1149 int keepRouteFlag = 1;
1150 if (numArgs >= 6) {
1151 if (!server.readTypeCheckingByte(inputStorage, keepRouteFlag)) {
1152 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The sixth parameter for moveToXY must be the keepRouteFlag given as a byte.", outputStorage);
1153 }
1154 }
1155 double matchThreshold = 100;
1156 if (numArgs == 7) {
1157 if (!server.readTypeCheckingDouble(inputStorage, matchThreshold)) {
1158 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The seventh parameter for moveToXY must be the matchThreshold given as a double.", outputStorage);
1159 }
1160 }
1161 libsumo::Vehicle::moveToXY(id, edgeID, laneNum, x, y, angle, keepRouteFlag, matchThreshold);
1162 }
1163 break;
1165 double factor = 0;
1166 if (!server.readTypeCheckingDouble(inputStorage, factor)) {
1167 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting speed factor requires a double.", outputStorage);
1168 }
1169 libsumo::Vehicle::setSpeedFactor(id, factor);
1170 }
1171 break;
1172 case libsumo::VAR_LINE: {
1173 std::string line;
1174 if (!server.readTypeCheckingString(inputStorage, line)) {
1175 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The line must be given as a string.", outputStorage);
1176 }
1177 libsumo::Vehicle::setLine(id, line);
1178 }
1179 break;
1180 case libsumo::VAR_VIA: {
1181 std::vector<std::string> edgeIDs;
1182 if (!server.readTypeCheckingStringList(inputStorage, edgeIDs)) {
1183 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Vias must be defined as a list of edge ids.", outputStorage);
1184 }
1185 libsumo::Vehicle::setVia(id, edgeIDs);
1186 }
1187 break;
1189 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
1190 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "A compound object is needed for setting a parameter.", outputStorage);
1191 }
1192 //readt itemNo
1193 inputStorage.readInt();
1194 std::string name;
1195 if (!server.readTypeCheckingString(inputStorage, name)) {
1196 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The name of the parameter must be given as a string.", outputStorage);
1197 }
1198 std::string value;
1199 if (!server.readTypeCheckingString(inputStorage, value)) {
1200 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The value of the parameter must be given as a string.", outputStorage);
1201 }
1202 try {
1204 libsumo::Vehicle::setParameter(id, name, value);
1205 } catch (libsumo::TraCIException& e) {
1206 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, e.what(), outputStorage);
1207 }
1208 }
1209 break;
1211 // Highlight the vehicle by adding a tracking polygon. (NOTE: duplicated code exists for POI domain)
1212 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
1213 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "A compound object is needed for highlighting an object.", outputStorage);
1214 }
1215 const int itemNo = inputStorage.readInt();
1216 if (itemNo > 5) {
1217 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Highlighting an object needs zero to five parameters.", outputStorage);
1218 }
1220 if (itemNo > 0) {
1221 if (!server.readTypeCheckingColor(inputStorage, col)) {
1222 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first parameter for highlighting must be the highlight color.", outputStorage);
1223 }
1224 }
1225 double size = -1;
1226 if (itemNo > 1) {
1227 if (!server.readTypeCheckingDouble(inputStorage, size)) {
1228 return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The second parameter for highlighting must be the highlight size.", outputStorage);
1229 }
1230 }
1231 int alphaMax = -1;
1232 if (itemNo > 2) {
1233 if (!server.readTypeCheckingUnsignedByte(inputStorage, alphaMax)) {
1234 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third parameter for highlighting must be maximal alpha.", outputStorage);
1235 }
1236 }
1237 double duration = -1;
1238 if (itemNo > 3) {
1239 if (!server.readTypeCheckingDouble(inputStorage, duration)) {
1240 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fourth parameter for highlighting must be the highlight duration.", outputStorage);
1241 }
1242 }
1243 int type = 0;
1244 if (itemNo > 4) {
1245 if (!server.readTypeCheckingUnsignedByte(inputStorage, type)) {
1246 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fifth parameter for highlighting must be the highlight type id as ubyte.", outputStorage);
1247 }
1248 }
1249 libsumo::Vehicle::highlight(id, col, size, alphaMax, duration, type);
1250 }
1251 break;
1253 std::vector<std::string> reservations;
1254 if (!server.readTypeCheckingStringList(inputStorage, reservations)) {
1255 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "A dispatch command must be defined as a list of reservation ids.", outputStorage);
1256 }
1257 libsumo::Vehicle::dispatchTaxi(id, reservations);
1258 }
1259 break;
1261 double value = 0;
1262 if (!server.readTypeCheckingDouble(inputStorage, value)) {
1263 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting action step length requires a double.", outputStorage);
1264 }
1265 if (fabs(value) == std::numeric_limits<double>::infinity()) {
1266 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Invalid action step length.", outputStorage);
1267 }
1268 bool resetActionOffset = value >= 0.0;
1269 libsumo::Vehicle::setActionStepLength(id, fabs(value), resetActionOffset);
1270 }
1271 break;
1273 libsumo::Vehicle::updateBestLanes(id);
1274 }
1275 break;
1277 double value = 0;
1278 if (!server.readTypeCheckingDouble(inputStorage, value)) {
1279 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting minimum lateral gap requires a double.", outputStorage);
1280 }
1281 if (value < 0.0 || fabs(value) == std::numeric_limits<double>::infinity()) {
1282 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Invalid minimum lateral gap.", outputStorage);
1283 }
1284 libsumo::Vehicle::setMinGapLat(id, value);
1285 }
1286 break;
1287 default: {
1288 try {
1289 if (!TraCIServerAPI_VehicleType::setVariable(libsumo::CMD_SET_VEHICLE_VARIABLE, variable, v->getSingularType().getID(), server, inputStorage, outputStorage)) {
1290 return false;
1291 }
1292 } catch (ProcessError& e) {
1293 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, e.what(), outputStorage);
1294 } catch (libsumo::TraCIException& e) {
1295 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, e.what(), outputStorage);
1296 }
1297 }
1298 break;
1299 }
1300 } catch (libsumo::TraCIException& e) {
1301 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, e.what(), outputStorage);
1302 }
1304 return true;
1305}
1306
1307
1308void
1309TraCIServerAPI_Vehicle::writeNextStops(TraCIServer& server, const std::string& id, int limit, bool full) {
1310 std::vector<libsumo::TraCINextStopData> nextStops = libsumo::Vehicle::getStops(id, limit);
1312 const int cnt = 1 + (int)nextStops.size() * 4;
1313 server.getWrapperStorage().writeInt(cnt);
1315 server.getWrapperStorage().writeInt((int)nextStops.size());
1316 for (std::vector<libsumo::TraCINextStopData>::iterator it = nextStops.begin(); it != nextStops.end(); ++it) {
1317 int legacyStopFlags = (it->stopFlags << 1) + (it->arrival >= 0 ? 1 : 0);
1319 server.getWrapperStorage().writeString(it->lane);
1321 server.getWrapperStorage().writeDouble(it->endPos);
1323 server.getWrapperStorage().writeString(it->stoppingPlaceID);
1325 server.getWrapperStorage().writeInt(full ? it->stopFlags : legacyStopFlags);
1327 server.getWrapperStorage().writeDouble(it->duration);
1329 server.getWrapperStorage().writeDouble(it->until);
1330 if (full) {
1332 server.getWrapperStorage().writeDouble(it->startPos);
1334 server.getWrapperStorage().writeDouble(it->intendedArrival);
1336 server.getWrapperStorage().writeDouble(it->arrival);
1338 server.getWrapperStorage().writeDouble(it->depart);
1340 server.getWrapperStorage().writeString(it->split);
1342 server.getWrapperStorage().writeString(it->join);
1344 server.getWrapperStorage().writeString(it->actType);
1346 server.getWrapperStorage().writeString(it->tripId);
1348 server.getWrapperStorage().writeString(it->line);
1350 server.getWrapperStorage().writeDouble(it->speed);
1351 }
1352 }
1353}
1354
1355bool
1356TraCIServerAPI_Vehicle::insertReplaceStop(TraCIServer& server, tcpip::Storage& inputStorage, tcpip::Storage& outputStorage, const std::string& id, bool replace) {
1357 const std::string m1 = replace ? "Replacing" : "Inserting";
1358 const std::string m2 = replace ? "replacement" : "insertion";
1359
1360 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
1361 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, m1 + " stop needs a compound object description.", outputStorage);
1362 }
1363 int compoundSize = inputStorage.readInt();
1364 if (compoundSize != 8 && compoundSize != 9) {
1365 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, m1 + " stop needs a compound object description of eight or nine items.", outputStorage);
1366 }
1367 // read road map position
1368 std::string edgeID;
1369 if (!server.readTypeCheckingString(inputStorage, edgeID)) {
1370 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first stop " + m2 + " parameter must be the edge id given as a string.", outputStorage);
1371 }
1372 double pos = 0;
1373 if (!server.readTypeCheckingDouble(inputStorage, pos)) {
1374 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);
1375 }
1376 int laneIndex = 0;
1377 if (!server.readTypeCheckingByte(inputStorage, laneIndex)) {
1378 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third stop " + m2 + " parameter must be the lane index given as a byte.", outputStorage);
1379 }
1380 // waitTime
1381 double duration = libsumo::INVALID_DOUBLE_VALUE;
1382 if (!server.readTypeCheckingDouble(inputStorage, duration)) {
1383 return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "The fourth stop " + m2 + " parameter must be the stopping duration given as a double.", outputStorage);
1384 }
1385 int stopFlags = 0;
1386 if (!server.readTypeCheckingInt(inputStorage, stopFlags)) {
1387 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fifth stop " + m2 + " parameter must be a int indicating its parking/triggered status.", outputStorage);
1388 }
1389 double startPos = libsumo::INVALID_DOUBLE_VALUE;
1390 if (!server.readTypeCheckingDouble(inputStorage, startPos)) {
1391 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);
1392 }
1393 double until = libsumo::INVALID_DOUBLE_VALUE;
1394 if (!server.readTypeCheckingDouble(inputStorage, until)) {
1395 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The seventh stop " + m2 + " parameter must be the minimum departure time given as a double.", outputStorage);
1396 }
1397 int nextStopIndex = 0;
1398 if (!server.readTypeCheckingInt(inputStorage, nextStopIndex)) {
1399 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The eigth stop " + m2 + " parameter must be the replacement index given as a int.", outputStorage);
1400 }
1401 int teleport = 0;
1402 if (compoundSize == 9) {
1403 if (!server.readTypeCheckingByte(inputStorage, teleport)) {
1404 return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The nineth stop " + m2 + " parameter must be the teleport flag given as a byte.", outputStorage);
1405 }
1406 }
1407 if (replace) {
1408 libsumo::Vehicle::replaceStop(id, nextStopIndex, edgeID, pos, laneIndex, duration, stopFlags, startPos, until, teleport);
1409 } else {
1410 libsumo::Vehicle::insertStop(id, nextStopIndex, edgeID, pos, laneIndex, duration, stopFlags, startPos, until, teleport);
1411 }
1412 return true;
1413}
1414/****************************************************************************/
SUMOTime DELTA_T
Definition: SUMOTime.cpp:37
#define STEPS2TIME(x)
Definition: SUMOTime.h:54
#define SUMOTime_MAX
Definition: SUMOTime.h:33
#define SIMTIME
Definition: SUMOTime.h:61
@ 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
The position is set by the vehroute device.
@ 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...
@ NOW
The vehicle is discarded if emission fails (not fully implemented yet)
@ 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.
Definition: MSBaseVehicle.h:55
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:183
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
Definition: MSNet.h:379
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.
Definition: MSVehicleType.h:91
const std::string & getID() const
Returns the id.
Definition: Named.h:74
Representation of a vehicle.
Definition: SUMOVehicle.h:60
static void writeNextStops(TraCIServer &server, const std::string &id, int limit, bool full)
helper function to write the response for VAR_NEXT_STOPS and VAR_NEXT_STOPS2
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 readTypeCheckingInt(tcpip::Storage &inputStorage, int &into)
Reads the value type and an int, verifying the type.
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.
An error which allows to continue.
Definition: TraCIDefs.h:138
virtual std::string readString()
Definition: storage.cpp:180
virtual void writeString(const std::string &s)
Definition: storage.cpp:197
virtual void writeInt(int)
Definition: storage.cpp:321
virtual void writeDouble(double)
Definition: storage.cpp:354
virtual int readUnsignedByte()
Definition: storage.cpp:155
virtual void writeStringList(const std::vector< std::string > &s)
Definition: storage.cpp:247
virtual void writeUnsignedByte(int)
Definition: storage.cpp:165
virtual void writeByte(int)
Definition: storage.cpp:140
virtual void writeStorage(tcpip::Storage &store)
Definition: storage.cpp:388
virtual double readDouble()
Definition: storage.cpp:362
virtual int readInt()
Definition: storage.cpp:311
const unsigned char flag[]
Definition: flag.cpp:24
TRACI_CONST double INVALID_DOUBLE_VALUE
TRACI_CONST int POSITION_3D
TRACI_CONST int POSITION_ROADMAP
TRACI_CONST int VAR_LANECHANGE_MODE
TRACI_CONST int MOVE_AUTOMATIC
TRACI_CONST int VAR_VEHICLECLASS
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_SECURE_GAP
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_FOLLOW_SPEED
TRACI_CONST int VAR_TAU
TRACI_CONST int TYPE_COMPOUND
TRACI_CONST int VAR_NEXT_TLS
TRACI_CONST int VAR_EDGE_EFFORT
TRACI_CONST int VAR_ROUTE
TRACI_CONST int VAR_BEST_LANES
TRACI_CONST int VAR_HIGHLIGHT
TRACI_CONST int TYPE_UBYTE
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 POSITION_2D
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 TYPE_STRINGLIST
TRACI_CONST int VAR_TAXI_FLEET
TRACI_CONST int TYPE_INTEGER
TRACI_CONST int VAR_PREV_SPEED
TRACI_CONST int VAR_SPEEDSETMODE
TRACI_CONST int CMD_REPLACE_STOP
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_STOP_SPEED
TRACI_CONST int VAR_IMPERFECTION
TRACI_CONST int VAR_HEIGHT
TRACI_CONST int VAR_APPARENT_DECEL
TRACI_CONST int REQUEST_DRIVINGDIST
TRACI_CONST int VAR_SPEED
TRACI_CONST int VAR_DECEL
TRACI_CONST int VAR_SIGNALS
TRACI_CONST int VAR_MINGAP_LAT
TRACI_CONST int VAR_NEXT_STOPS2
TRACI_CONST int CMD_SLOWDOWN
TRACI_CONST int VAR_ACCELERATION
TRACI_CONST int VAR_ROUTE_ID
TRACI_CONST int TYPE_DOUBLE
TRACI_CONST int DISTANCE_REQUEST
TRACI_CONST int TYPE_BYTE
TRACI_CONST int CMD_OPENGAP
TRACI_CONST int CMD_CHANGELANE
TRACI_CONST int RTYPE_ERR
TRACI_CONST int VAR_NEIGHBORS
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
TRACI_CONST int TYPE_STRING
TRACI_CONST int VAR_NEXT_STOPS
double length
The length than can be driven from that lane without lane change.
Definition: TraCIDefs.h:507
double occupation
The traffic density along length.
Definition: TraCIDefs.h:509
bool allowsContinuation
Whether this lane allows continuing the route.
Definition: TraCIDefs.h:513
int bestLaneOffset
The offset of this lane from the best lane.
Definition: TraCIDefs.h:511
std::vector< std::string > continuationLanes
The sequence of lanes that best allows continuing the route without lane change.
Definition: TraCIDefs.h:515
std::string laneID
The id of the lane.
Definition: TraCIDefs.h:505