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