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