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