Path: blob/main/src/traci-server/TraCIServerAPI_Vehicle.cpp
169665 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2009-2025 German Aerospace Center (DLR) and others.3// This program and the accompanying materials are made available under the4// terms of the Eclipse Public License 2.0 which is available at5// https://www.eclipse.org/legal/epl-2.0/6// This Source Code may also be made available under the following Secondary7// Licenses when the conditions for such availability set forth in the Eclipse8// Public License 2.0 are satisfied: GNU General Public License, version 29// or later which is available at10// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later12/****************************************************************************/13/// @file TraCIServerAPI_Vehicle.cpp14/// @author Daniel Krajzewicz15/// @author Laura Bieker16/// @author Christoph Sommer17/// @author Michael Behrisch18/// @author Bjoern Hendriks19/// @author Mario Krumnow20/// @author Jakob Erdmann21/// @author Leonhard Luecken22/// @author Robert Hilbrich23/// @author Lara Codeca24/// @author Mirko Barthauer25/// @date 07.05.200926///27// APIs for getting/setting vehicle values via TraCI28/****************************************************************************/29#include <config.h>3031#include <microsim/MSNet.h>32#include <microsim/MSInsertionControl.h>33#include <microsim/MSVehicle.h>34#include <microsim/MSVehicleControl.h>35#include <microsim/MSLane.h>36#include <microsim/MSEdge.h>37#include <microsim/MSGlobals.h>38#include <microsim/lcmodels/MSAbstractLaneChangeModel.h>39#include <utils/geom/PositionVector.h>40#include <utils/router/DijkstraRouter.h>41#include <utils/router/DijkstraRouter.h>42#include <utils/emissions/PollutantsInterface.h>43#include <utils/emissions/HelpersHarmonoise.h>44#include <utils/vehicle/SUMOVehicleParameter.h>45#include <libsumo/StorageHelper.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"525354// ===========================================================================55// method definitions56// ===========================================================================57bool58TraCIServerAPI_Vehicle::processGet(TraCIServer& server, tcpip::Storage& inputStorage,59tcpip::Storage& outputStorage) {60const int variable = inputStorage.readUnsignedByte();61const std::string id = inputStorage.readString();62server.initWrapper(libsumo::RESPONSE_GET_VEHICLE_VARIABLE, variable, id);63try {64if (!libsumo::Vehicle::handleVariable(id, variable, &server, &inputStorage)) {65return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Get Vehicle Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);66}67} catch (libsumo::TraCIException& e) {68return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, e.what(), outputStorage);69}70server.writeStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, libsumo::RTYPE_OK, "", outputStorage);71server.writeResponseWithLength(outputStorage, server.getWrapperStorage());72return true;73}747576bool77TraCIServerAPI_Vehicle::processSet(TraCIServer& server, tcpip::Storage& inputStorage,78tcpip::Storage& outputStorage) {79std::string warning = ""; // additional description for response80// variable81int variable = inputStorage.readUnsignedByte();82if (variable != libsumo::CMD_STOP && variable != libsumo::CMD_CHANGELANE83&& variable != libsumo::CMD_REROUTE_TO_PARKING84&& variable != libsumo::CMD_CHANGESUBLANE && variable != libsumo::CMD_OPENGAP85&& variable != libsumo::CMD_REPLACE_STOP86&& variable != libsumo::CMD_INSERT_STOP87&& variable != libsumo::VAR_STOP_PARAMETER88&& variable != libsumo::CMD_SLOWDOWN && variable != libsumo::CMD_CHANGETARGET && variable != libsumo::CMD_RESUME89&& variable != libsumo::VAR_TYPE && variable != libsumo::VAR_ROUTE_ID && variable != libsumo::VAR_ROUTE90&& variable != libsumo::VAR_LANEPOSITION_LAT91&& variable != libsumo::VAR_UPDATE_BESTLANES92&& variable != libsumo::VAR_EDGE_TRAVELTIME && variable != libsumo::VAR_EDGE_EFFORT93&& variable != libsumo::CMD_REROUTE_TRAVELTIME && variable != libsumo::CMD_REROUTE_EFFORT94&& variable != libsumo::VAR_SIGNALS && variable != libsumo::VAR_MOVE_TO95&& variable != libsumo::VAR_LENGTH && variable != libsumo::VAR_MAXSPEED && variable != libsumo::VAR_VEHICLECLASS96&& variable != libsumo::VAR_SPEED_FACTOR && variable != libsumo::VAR_EMISSIONCLASS97&& variable != libsumo::VAR_WIDTH && variable != libsumo::VAR_MINGAP && variable != libsumo::VAR_SHAPECLASS98&& variable != libsumo::VAR_ACCEL && variable != libsumo::VAR_DECEL && variable != libsumo::VAR_IMPERFECTION99&& variable != libsumo::VAR_APPARENT_DECEL && variable != libsumo::VAR_EMERGENCY_DECEL100&& variable != libsumo::VAR_ACTIONSTEPLENGTH101&& variable != libsumo::VAR_TAU && variable != libsumo::VAR_LANECHANGE_MODE102&& variable != libsumo::VAR_SPEED && variable != libsumo::VAR_ACCELERATION && variable != libsumo::VAR_PREV_SPEED && variable != libsumo::VAR_SPEEDSETMODE && variable != libsumo::VAR_COLOR103&& variable != libsumo::ADD && variable != libsumo::ADD_FULL && variable != libsumo::REMOVE104&& variable != libsumo::VAR_HEIGHT105&& variable != libsumo::VAR_MASS106&& variable != libsumo::VAR_ROUTING_MODE107&& variable != libsumo::VAR_LATALIGNMENT108&& variable != libsumo::VAR_MAXSPEED_LAT109&& variable != libsumo::VAR_MINGAP_LAT110&& variable != libsumo::VAR_LINE111&& variable != libsumo::VAR_VIA112&& variable != libsumo::VAR_IMPATIENCE113&& variable != libsumo::VAR_BOARDING_DURATION114&& variable != libsumo::VAR_HIGHLIGHT115&& variable != libsumo::CMD_TAXI_DISPATCH116&& variable != libsumo::MOVE_TO_XY && variable != libsumo::VAR_PARAMETER/* && variable != libsumo::VAR_SPEED_TIME_LINE && variable != libsumo::VAR_LANE_TIME_LINE*/117) {118return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Change Vehicle State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);119}120// id121std::string id = inputStorage.readString();122#ifdef DEBUG_MOVEXY123std::cout << SIMTIME << " processSet veh=" << id << "\n";124#endif125const bool shouldExist = variable != libsumo::ADD && variable != libsumo::ADD_FULL;126SUMOVehicle* sumoVehicle = MSNet::getInstance()->getVehicleControl().getVehicle(id);127if (sumoVehicle == nullptr) {128if (shouldExist) {129return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Vehicle '" + id + "' is not known", outputStorage);130}131}132MSBaseVehicle* v = dynamic_cast<MSBaseVehicle*>(sumoVehicle);133if (v == nullptr && shouldExist) {134return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "Vehicle '" + id + "' is not a proper vehicle", outputStorage);135}136try {137switch (variable) {138case libsumo::CMD_STOP: {139if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {140return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Stop needs a compound object description.", outputStorage);141}142int compoundSize = inputStorage.readInt();143if (compoundSize < 4 || compoundSize > 7) {144return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Stop needs a compound object description of four to seven items.", outputStorage);145}146// read road map position147std::string edgeID;148if (!server.readTypeCheckingString(inputStorage, edgeID)) {149return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first stop parameter must be the edge id given as a string.", outputStorage);150}151double pos = 0;152if (!server.readTypeCheckingDouble(inputStorage, pos)) {153return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The second stop parameter must be the end position along the edge given as a double.", outputStorage);154}155int laneIndex = 0;156if (!server.readTypeCheckingByte(inputStorage, laneIndex)) {157return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third stop parameter must be the lane index given as a byte.", outputStorage);158}159// waitTime160double duration = libsumo::INVALID_DOUBLE_VALUE;161if (!server.readTypeCheckingDouble(inputStorage, duration)) {162return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "The fourth stop parameter must be the stopping duration given as a double.", outputStorage);163}164int stopFlags = 0;165if (compoundSize >= 5) {166if (!server.readTypeCheckingByte(inputStorage, stopFlags)) {167return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fifth stop parameter must be a byte indicating its parking/triggered status.", outputStorage);168}169}170double startPos = libsumo::INVALID_DOUBLE_VALUE;171if (compoundSize >= 6) {172if (!server.readTypeCheckingDouble(inputStorage, startPos)) {173return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The sixth stop parameter must be the start position along the edge given as a double.", outputStorage);174}175}176double until = libsumo::INVALID_DOUBLE_VALUE;177if (compoundSize >= 7) {178if (!server.readTypeCheckingDouble(inputStorage, until)) {179return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The seventh stop parameter must be the minimum departure time given as a double.", outputStorage);180}181}182libsumo::Vehicle::setStop(id, edgeID, pos, laneIndex, duration, stopFlags, startPos, until);183}184break;185case libsumo::CMD_REPLACE_STOP:186if (!insertReplaceStop(server, inputStorage, outputStorage, id, true)) {187return false;188}189break;190case libsumo::CMD_INSERT_STOP:191if (!insertReplaceStop(server, inputStorage, outputStorage, id, false)) {192return false;193}194break;195case libsumo::VAR_STOP_PARAMETER: {196// read variables197if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {198return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting stop parameter needs a compound object description.", outputStorage);199}200int compoundSize = inputStorage.readInt();201if (compoundSize != 3 && compoundSize != 4) {202return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting a stop parameter needs a compound object description of 3 or 4 items.", outputStorage);203}204const int nextStopIndex = StoHelp::readTypedInt(inputStorage, "The first setStopParameter parameter must be the nextStopIndex given as an integer.");205std::string param;206if (!server.readTypeCheckingString(inputStorage, param)) {207return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The second setStopParameter parameter must be the param given as a string.", outputStorage);208}209std::string value;210if (!server.readTypeCheckingString(inputStorage, value)) {211return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third setStopParameter parameter must be the value given as a string.", outputStorage);212}213int customParam = 0;214if (compoundSize == 4) {215if (!server.readTypeCheckingByte(inputStorage, customParam)) {216return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fourth setStopParameter parameter must be the customParam flag given as a byte.", outputStorage);217}218}219libsumo::Vehicle::setStopParameter(id, nextStopIndex, param, value, customParam != 0);220}221break;222case libsumo::CMD_REROUTE_TO_PARKING: {223// read variables224if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {225return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Reroute to stop needs a compound object description.", outputStorage);226}227int compoundSize = inputStorage.readInt();228if (compoundSize != 1) {229return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Reroute to stop needs a compound object description of 1 item.", outputStorage);230}231std::string parkingAreaID;232if (!server.readTypeCheckingString(inputStorage, parkingAreaID)) {233return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first reroute to stop parameter must be the parking area id given as a string.", outputStorage);234}235libsumo::Vehicle::rerouteParkingArea(id, parkingAreaID);236}237break;238case libsumo::CMD_RESUME: {239if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {240server.writeStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::RTYPE_ERR, "Resuming requires a compound object.", outputStorage);241return false;242}243if (inputStorage.readInt() != 0) {244server.writeStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::RTYPE_ERR, "Resuming should obtain an empty compound object.", outputStorage);245return false;246}247libsumo::Vehicle::resume(id);248}249break;250case libsumo::CMD_CHANGELANE: {251if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {252return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Lane change needs a compound object description.", outputStorage);253}254int compounds = inputStorage.readInt();255if (compounds != 3 && compounds != 2) {256return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Lane change needs a compound object description of two or three items.", outputStorage);257}258// Lane ID259int laneIndex = 0;260if (!server.readTypeCheckingByte(inputStorage, laneIndex)) {261return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first lane change parameter must be the lane index given as a byte.", outputStorage);262}263// duration264double duration = 0.;265if (!server.readTypeCheckingDouble(inputStorage, duration)) {266return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The second lane change parameter must be the duration given as a double.", outputStorage);267}268// relativelanechange269int relative = 0;270if (compounds == 3) {271if (!server.readTypeCheckingByte(inputStorage, relative)) {272return 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);273}274}275276if ((laneIndex < 0 || laneIndex >= (int)v->getEdge()->getLanes().size()) && relative < 1) {277return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "No lane with index '" + toString(laneIndex) + "' on road '" + v->getEdge()->getID() + "'.", outputStorage);278}279280if (relative < 1) {281libsumo::Vehicle::changeLane(id, laneIndex, duration);282} else {283libsumo::Vehicle::changeLaneRelative(id, laneIndex, duration);284}285}286break;287case libsumo::CMD_CHANGESUBLANE: {288double latDist = 0;289if (!server.readTypeCheckingDouble(inputStorage, latDist)) {290return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Sublane-changing requires a double.", outputStorage);291}292libsumo::Vehicle::changeSublane(id, latDist);293}294break;295case libsumo::CMD_SLOWDOWN: {296if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {297return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Slow down needs a compound object description.", outputStorage);298}299if (inputStorage.readInt() != 2) {300return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Slow down needs a compound object description of two items.", outputStorage);301}302double newSpeed = 0;303if (!server.readTypeCheckingDouble(inputStorage, newSpeed)) {304return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first slow down parameter must be the speed given as a double.", outputStorage);305}306if (newSpeed < 0) {307return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Speed must not be negative", outputStorage);308}309double duration = 0.;310if (!server.readTypeCheckingDouble(inputStorage, duration)) {311return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The second slow down parameter must be the duration given as a double.", outputStorage);312}313if (duration < 0 || SIMTIME + duration > STEPS2TIME(SUMOTime_MAX - DELTA_T)) {314return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Invalid time interval", outputStorage);315}316libsumo::Vehicle::slowDown(id, newSpeed, duration);317}318break;319case libsumo::CMD_CHANGETARGET: {320std::string edgeID;321if (!server.readTypeCheckingString(inputStorage, edgeID)) {322return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Change target requires a string containing the id of the new destination edge as parameter.", outputStorage);323}324libsumo::Vehicle::changeTarget(id, edgeID);325}326break;327case libsumo::CMD_OPENGAP: {328if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {329return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Create gap needs a compound object description.", outputStorage);330}331const int nParameter = inputStorage.readInt();332if (nParameter != 5 && nParameter != 6) {333return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Create gap needs a compound object description of five or six items.", outputStorage);334}335double newTimeHeadway = 0;336if (!server.readTypeCheckingDouble(inputStorage, newTimeHeadway)) {337return 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);338}339double newSpaceHeadway = 0;340if (!server.readTypeCheckingDouble(inputStorage, newSpaceHeadway)) {341return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The second create gap parameter must be the new desired space headway given as a double.", outputStorage);342}343double duration = 0.;344if (!server.readTypeCheckingDouble(inputStorage, duration)) {345return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third create gap parameter must be the duration given as a double.", outputStorage);346}347double changeRate = 0;348if (!server.readTypeCheckingDouble(inputStorage, changeRate)) {349return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fourth create gap parameter must be the change rate given as a double.", outputStorage);350}351double maxDecel = 0;352if (!server.readTypeCheckingDouble(inputStorage, maxDecel)) {353return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fifth create gap parameter must be the maximal braking rate given as a double.", outputStorage);354}355356if (newTimeHeadway == -1 && newSpaceHeadway == -1 && duration == -1 && changeRate == -1 && maxDecel == -1) {357libsumo::Vehicle::deactivateGapControl(id);358} else {359if (newTimeHeadway <= 0) {360if (newTimeHeadway != -1) {361return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The value for the new desired time headway (tau) must be positive for create gap", outputStorage);362} // else if == -1: keep vehicles current headway, see libsumo::Vehicle::openGap363}364if (newSpaceHeadway < 0) {365return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The value for the new desired space headway must be non-negative for create gap", outputStorage);366}367if ((duration < 0 && duration != -1) || SIMTIME + duration > STEPS2TIME(SUMOTime_MAX - DELTA_T)) {368return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Invalid time interval for create gap", outputStorage);369}370if (changeRate <= 0) {371return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The value for the change rate must be positive for the openGap command", outputStorage);372}373if (maxDecel <= 0 && maxDecel != -1 && maxDecel != libsumo::INVALID_DOUBLE_VALUE) {374return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The value for the maximal braking rate must be positive for the openGap command", outputStorage);375} // else if <= 0: don't limit cf model's suggested brake rate, see libsumo::Vehicle::openGap376std::string refVehID = "";377if (nParameter == 6) {378if (!server.readTypeCheckingString(inputStorage, refVehID)) {379return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The sixth create gap parameter must be a reference vehicle's ID given as a string.", outputStorage);380}381}382libsumo::Vehicle::openGap(id, newTimeHeadway, newSpaceHeadway, duration, changeRate, maxDecel, refVehID);383}384}385break;386case libsumo::VAR_TYPE: {387std::string vTypeID;388if (!server.readTypeCheckingString(inputStorage, vTypeID)) {389return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The vehicle type id must be given as a string.", outputStorage);390}391libsumo::Vehicle::setType(id, vTypeID);392}393break;394case libsumo::VAR_ROUTE_ID: {395std::string rid;396if (!server.readTypeCheckingString(inputStorage, rid)) {397return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The route id must be given as a string.", outputStorage);398}399libsumo::Vehicle::setRouteID(id, rid);400}401break;402case libsumo::VAR_ROUTE: {403std::vector<std::string> edgeIDs;404if (!server.readTypeCheckingStringList(inputStorage, edgeIDs)) {405return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "A route must be defined as a list of edge ids.", outputStorage);406}407libsumo::Vehicle::setRoute(id, edgeIDs);408}409break;410case libsumo::VAR_EDGE_TRAVELTIME: {411if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {412return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time requires a compound object.", outputStorage);413}414int parameterCount = inputStorage.readInt();415std::string edgeID;416double begTime = 0.;417double endTime = std::numeric_limits<double>::max();418double value = libsumo::INVALID_DOUBLE_VALUE;419if (parameterCount == 4) {420// begin time421if (!server.readTypeCheckingDouble(inputStorage, begTime)) {422return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the begin time as first parameter.", outputStorage);423}424// begin time425if (!server.readTypeCheckingDouble(inputStorage, endTime)) {426return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the end time as second parameter.", outputStorage);427}428// edge429if (!server.readTypeCheckingString(inputStorage, edgeID)) {430return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the referenced edge as third parameter.", outputStorage);431}432// value433if (!server.readTypeCheckingDouble(inputStorage, value)) {434return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 4 parameters requires the travel time as double as fourth parameter.", outputStorage);435}436} else if (parameterCount == 2) {437// edge438if (!server.readTypeCheckingString(inputStorage, edgeID)) {439return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 2 parameters requires the referenced edge as first parameter.", outputStorage);440}441// value442if (!server.readTypeCheckingDouble(inputStorage, value)) {443return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 2 parameters requires the travel time as second parameter.", outputStorage);444}445} else if (parameterCount == 1) {446// edge447if (!server.readTypeCheckingString(inputStorage, edgeID)) {448return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time using 1 parameter requires the referenced edge as first parameter.", outputStorage);449}450} else {451return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting travel time requires 1, 2, or 4 parameters.", outputStorage);452}453libsumo::Vehicle::setAdaptedTraveltime(id, edgeID, value, begTime, endTime);454}455break;456case libsumo::VAR_EDGE_EFFORT: {457if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {458return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort requires a compound object.", outputStorage);459}460int parameterCount = inputStorage.readInt();461std::string edgeID;462double begTime = 0.;463double endTime = std::numeric_limits<double>::max();464double value = libsumo::INVALID_DOUBLE_VALUE;465if (parameterCount == 4) {466// begin time467if (!server.readTypeCheckingDouble(inputStorage, begTime)) {468return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the begin time as first parameter.", outputStorage);469}470// begin time471if (!server.readTypeCheckingDouble(inputStorage, endTime)) {472return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the end time as second parameter.", outputStorage);473}474// edge475if (!server.readTypeCheckingString(inputStorage, edgeID)) {476return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the referenced edge as third parameter.", outputStorage);477}478// value479if (!server.readTypeCheckingDouble(inputStorage, value)) {480return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 4 parameters requires the travel time as fourth parameter.", outputStorage);481}482} else if (parameterCount == 2) {483// edge484if (!server.readTypeCheckingString(inputStorage, edgeID)) {485return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 2 parameters requires the referenced edge as first parameter.", outputStorage);486}487if (!server.readTypeCheckingDouble(inputStorage, value)) {488return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 2 parameters requires the travel time as second parameter.", outputStorage);489}490} else if (parameterCount == 1) {491// edge492if (!server.readTypeCheckingString(inputStorage, edgeID)) {493return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort using 1 parameter requires the referenced edge as first parameter.", outputStorage);494}495} else {496return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting effort requires 1, 2, or 4 parameters.", outputStorage);497}498// retrieve499libsumo::Vehicle::setEffort(id, edgeID, value, begTime, endTime);500}501break;502case libsumo::CMD_REROUTE_TRAVELTIME: {503if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {504return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Rerouting requires a compound object.", outputStorage);505}506if (inputStorage.readInt() != 0) {507return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Rerouting should obtain an empty compound object.", outputStorage);508}509libsumo::Vehicle::rerouteTraveltime(id, false);510}511break;512case libsumo::CMD_REROUTE_EFFORT: {513if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {514return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Rerouting requires a compound object.", outputStorage);515}516if (inputStorage.readInt() != 0) {517return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Rerouting should obtain an empty compound object.", outputStorage);518}519libsumo::Vehicle::rerouteEffort(id);520}521break;522case libsumo::VAR_SIGNALS:523libsumo::Vehicle::setSignals(id, StoHelp::readTypedInt(inputStorage, "Setting signals requires an integer."));524break;525case libsumo::VAR_MOVE_TO: {526if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {527return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting position requires a compound object.", outputStorage);528}529const int numArgs = inputStorage.readInt();530if (numArgs < 2 || numArgs > 3) {531return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting position should obtain the lane id and the position and optionally the reason.", outputStorage);532}533// lane ID534std::string laneID;535if (!server.readTypeCheckingString(inputStorage, laneID)) {536return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first parameter for setting a position must be the lane ID given as a string.", outputStorage);537}538// position on lane539double position = 0;540if (!server.readTypeCheckingDouble(inputStorage, position)) {541return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The second parameter for setting a position must be the position given as a double.", outputStorage);542}543int reason = libsumo::MOVE_AUTOMATIC;544if (numArgs == 3) {545reason = StoHelp::readTypedInt(inputStorage, "The third parameter for setting a position must be the reason given as an int.");546}547// process548libsumo::Vehicle::moveTo(id, laneID, position, reason);549}550break;551case libsumo::VAR_IMPATIENCE: {552double impatience = 0;553if (!server.readTypeCheckingDouble(inputStorage, impatience)) {554return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting impatience requires a double.", outputStorage);555}556libsumo::Vehicle::setImpatience(id, impatience);557}558break;559case libsumo::VAR_SPEED: {560double speed = 0;561if (!server.readTypeCheckingDouble(inputStorage, speed)) {562return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting speed requires a double.", outputStorage);563}564libsumo::Vehicle::setSpeed(id, speed);565}566break;567case libsumo::VAR_ACCELERATION: {568double accel = 0;569double duration = 0;570int inputtype = inputStorage.readUnsignedByte();571if (inputtype == libsumo::TYPE_COMPOUND) {572int parameterCount = inputStorage.readInt();573if (parameterCount == 2) {574if (!server.readTypeCheckingDouble(inputStorage, accel)) {575return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting acceleration requires the acceleration as first parameter given as a double.", outputStorage);576}577if (!server.readTypeCheckingDouble(inputStorage, duration)) {578return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting acceleration requires the duration as second parameter given as a double.", outputStorage);579}580} else {581return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting acceleration requires 2 parameters.", outputStorage);582}583} else {584return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting acceleration requires 2 parameters as compound object description.", outputStorage);585}586if (duration < 0) {587return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Duration must not be negative.", outputStorage);588}589libsumo::Vehicle::setAcceleration(id, accel, duration);590}591break;592case libsumo::VAR_PREV_SPEED: {593double prevSpeed = 0;594double prevAcceleration = libsumo::INVALID_DOUBLE_VALUE;595int inputtype = inputStorage.readUnsignedByte();596if (inputtype == libsumo::TYPE_COMPOUND) {597// Setting previous speed with 2 parameters, uses a compound object description598int parameterCount = inputStorage.readInt();599if (parameterCount == 2) {600if (!server.readTypeCheckingDouble(inputStorage, prevSpeed)) {601return 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);602}603if (!server.readTypeCheckingDouble(inputStorage, prevAcceleration)) {604return 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);605}606} else if (parameterCount == 1) {607if (!server.readTypeCheckingDouble(inputStorage, prevSpeed)) {608return 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);609}610} else {611return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting previous speed requires 1 or 2 parameters.", outputStorage);612}613} else if (inputtype == libsumo::TYPE_DOUBLE) {614// Setting previous speed with 1 parameter (double), no compound object description615prevSpeed = inputStorage.readDouble();616} else {617return 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);618}619if (prevSpeed < 0) {620return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Previous speed must not be negative.", outputStorage);621}622libsumo::Vehicle::setPreviousSpeed(id, prevSpeed, prevAcceleration);623}624break;625case libsumo::VAR_SPEEDSETMODE:626libsumo::Vehicle::setSpeedMode(id, StoHelp::readTypedInt(inputStorage, "Setting speed mode requires an integer."));627break;628case libsumo::VAR_LANECHANGE_MODE:629libsumo::Vehicle::setLaneChangeMode(id, StoHelp::readTypedInt(inputStorage, "Setting lane change mode requires an integer."));630break;631case libsumo::VAR_ROUTING_MODE:632libsumo::Vehicle::setRoutingMode(id, StoHelp::readTypedInt(inputStorage, "Setting routing mode requires an integer."));633break;634case libsumo::VAR_COLOR: {635libsumo::TraCIColor col;636if (!server.readTypeCheckingColor(inputStorage, col)) {637return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The color must be given using the according type.", outputStorage);638}639libsumo::Vehicle::setColor(id, col);640break;641}642case libsumo::ADD: {643if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {644return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Adding a vehicle requires a compound object.", outputStorage);645}646if (inputStorage.readInt() != 6) {647return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Adding a vehicle needs six parameters.", outputStorage);648}649std::string vTypeID;650if (!server.readTypeCheckingString(inputStorage, vTypeID)) {651return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "First parameter (type) requires a string.", outputStorage);652}653std::string routeID;654if (!server.readTypeCheckingString(inputStorage, routeID)) {655return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Second parameter (route) requires a string.", outputStorage);656}657const int departCode = StoHelp::readTypedInt(inputStorage, "Third parameter (depart) requires an integer.");658std::string depart = toString(STEPS2TIME(departCode));659if (-departCode == static_cast<int>(DepartDefinition::TRIGGERED)) {660depart = "triggered";661} else if (-departCode == static_cast<int>(DepartDefinition::CONTAINER_TRIGGERED)) {662depart = "containerTriggered";663} else if (-departCode == static_cast<int>(DepartDefinition::NOW)) {664depart = "now";665} else if (-departCode == static_cast<int>(DepartDefinition::SPLIT)) {666depart = "split";667} else if (-departCode == static_cast<int>(DepartDefinition::BEGIN)) {668depart = "begin";669}670671double departPosCode;672if (!server.readTypeCheckingDouble(inputStorage, departPosCode)) {673return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Fourth parameter (position) requires a double.", outputStorage);674}675std::string departPos = toString(departPosCode);676if (-departPosCode == (int)DepartPosDefinition::RANDOM) {677departPos = "random";678} else if (-departPosCode == (int)DepartPosDefinition::RANDOM_FREE) {679departPos = "random_free";680} else if (-departPosCode == (int)DepartPosDefinition::FREE) {681departPos = "free";682} else if (-departPosCode == (int)DepartPosDefinition::BASE) {683departPos = "base";684} else if (-departPosCode == (int)DepartPosDefinition::LAST) {685departPos = "last";686} else if (-departPosCode == (int)DepartPosDefinition::GIVEN) {687return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Invalid departure position.", outputStorage);688}689690double departSpeedCode;691if (!server.readTypeCheckingDouble(inputStorage, departSpeedCode)) {692return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Fifth parameter (speed) requires a double.", outputStorage);693}694std::string departSpeed = toString(departSpeedCode);695if (-departSpeedCode == (int)DepartSpeedDefinition::RANDOM) {696departSpeed = "random";697} else if (-departSpeedCode == (int)DepartSpeedDefinition::MAX) {698departSpeed = "max";699} else if (-departSpeedCode == (int)DepartSpeedDefinition::DESIRED) {700departSpeed = "desired";701} else if (-departSpeedCode == (int)DepartSpeedDefinition::LIMIT) {702departSpeed = "speedLimit";703} else if (-departSpeedCode == (int)DepartSpeedDefinition::LAST) {704departSpeed = "last";705} else if (-departSpeedCode == (int)DepartSpeedDefinition::AVG) {706departSpeed = "avg";707}708709int departLaneCode;710if (!server.readTypeCheckingByte(inputStorage, departLaneCode)) {711return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Sixth parameter (lane) requires a byte.", outputStorage);712}713std::string departLane = toString(departLaneCode);714if (-departLaneCode == (int)DepartLaneDefinition::RANDOM) {715departLane = "random";716} else if (-departLaneCode == (int)DepartLaneDefinition::FREE) {717departLane = "free";718} else if (-departLaneCode == (int)DepartLaneDefinition::ALLOWED_FREE) {719departLane = "allowed";720} else if (-departLaneCode == (int)DepartLaneDefinition::BEST_FREE) {721departLane = "best";722} else if (-departLaneCode == (int)DepartLaneDefinition::FIRST_ALLOWED) {723departLane = "first";724}725libsumo::Vehicle::add(id, routeID, vTypeID, depart, departLane, departPos, departSpeed);726}727break;728case libsumo::ADD_FULL: {729if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {730return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Adding a vehicle requires a compound object.", outputStorage);731}732if (inputStorage.readInt() != 14) {733return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Adding a fully specified vehicle needs fourteen parameters.", outputStorage);734}735std::string routeID;736if (!server.readTypeCheckingString(inputStorage, routeID)) {737return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Second parameter (route) requires a string.", outputStorage);738}739std::string vTypeID;740if (!server.readTypeCheckingString(inputStorage, vTypeID)) {741return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "First parameter (type) requires a string.", outputStorage);742}743std::string depart;744if (!server.readTypeCheckingString(inputStorage, depart)) {745return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Third parameter (depart) requires an string.", outputStorage);746}747std::string departLane;748if (!server.readTypeCheckingString(inputStorage, departLane)) {749return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Fourth parameter (depart lane) requires a string.", outputStorage);750}751std::string departPos;752if (!server.readTypeCheckingString(inputStorage, departPos)) {753return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Fifth parameter (depart position) requires a string.", outputStorage);754}755std::string departSpeed;756if (!server.readTypeCheckingString(inputStorage, departSpeed)) {757return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Sixth parameter (depart speed) requires a string.", outputStorage);758}759std::string arrivalLane;760if (!server.readTypeCheckingString(inputStorage, arrivalLane)) {761return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Seventh parameter (arrival lane) requires a string.", outputStorage);762}763std::string arrivalPos;764if (!server.readTypeCheckingString(inputStorage, arrivalPos)) {765return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Eighth parameter (arrival position) requires a string.", outputStorage);766}767std::string arrivalSpeed;768if (!server.readTypeCheckingString(inputStorage, arrivalSpeed)) {769return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Ninth parameter (arrival speed) requires a string.", outputStorage);770}771std::string fromTaz;772if (!server.readTypeCheckingString(inputStorage, fromTaz)) {773return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Tenth parameter (from taz) requires a string.", outputStorage);774}775std::string toTaz;776if (!server.readTypeCheckingString(inputStorage, toTaz)) {777return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Eleventh parameter (to taz) requires a string.", outputStorage);778}779std::string line;780if (!server.readTypeCheckingString(inputStorage, line)) {781return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Twelth parameter (line) requires a string.", outputStorage);782}783const int personCapacity = StoHelp::readTypedInt(inputStorage, "13th parameter (person capacity) requires an int.");784const int personNumber = StoHelp::readTypedInt(inputStorage, "14th parameter (person number) requires an int.");785libsumo::Vehicle::add(id, routeID, vTypeID, depart, departLane, departPos, departSpeed, arrivalLane, arrivalPos, arrivalSpeed,786fromTaz, toTaz, line, personCapacity, personNumber);787}788break;789case libsumo::REMOVE: {790int why = 0;791if (!server.readTypeCheckingByte(inputStorage, why)) {792return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Removing a vehicle requires a byte.", outputStorage);793}794libsumo::Vehicle::remove(id, (char)why);795}796break;797case libsumo::MOVE_TO_XY: {798if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {799return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "MoveToXY vehicle requires a compound object.", outputStorage);800}801const int numArgs = inputStorage.readInt();802if (numArgs < 5 || numArgs > 7) {803return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "MoveToXY vehicle should obtain: edgeID, lane, x, y, angle and optionally keepRouteFlag and matchThreshold.", outputStorage);804}805std::string edgeID;806if (!server.readTypeCheckingString(inputStorage, edgeID)) {807return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first parameter for moveToXY must be the edge ID given as a string.", outputStorage);808}809const int laneIndex = StoHelp::readTypedInt(inputStorage, "The second parameter for moveToXY must be lane given as an int.");810double x = 0;811if (!server.readTypeCheckingDouble(inputStorage, x)) {812return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third parameter for moveToXY must be the x-position given as a double.", outputStorage);813}814double y = 0;815if (!server.readTypeCheckingDouble(inputStorage, y)) {816return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fourth parameter for moveToXY must be the y-position given as a double.", outputStorage);817}818double angle = 0;819if (!server.readTypeCheckingDouble(inputStorage, angle)) {820return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fifth parameter for moveToXY must be the angle given as a double.", outputStorage);821}822823int keepRouteFlag = 1;824if (numArgs >= 6) {825if (!server.readTypeCheckingByte(inputStorage, keepRouteFlag)) {826return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The sixth parameter for moveToXY must be the keepRouteFlag given as a byte.", outputStorage);827}828}829double matchThreshold = 100;830if (numArgs == 7) {831if (!server.readTypeCheckingDouble(inputStorage, matchThreshold)) {832return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The seventh parameter for moveToXY must be the matchThreshold given as a double.", outputStorage);833}834}835libsumo::Vehicle::moveToXY(id, edgeID, laneIndex, x, y, angle, keepRouteFlag, matchThreshold);836}837break;838case libsumo::VAR_SPEED_FACTOR: {839double factor = 0;840if (!server.readTypeCheckingDouble(inputStorage, factor)) {841return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting speed factor requires a double.", outputStorage);842}843libsumo::Vehicle::setSpeedFactor(id, factor);844}845break;846case libsumo::VAR_LINE: {847std::string line;848if (!server.readTypeCheckingString(inputStorage, line)) {849return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The line must be given as a string.", outputStorage);850}851libsumo::Vehicle::setLine(id, line);852}853break;854case libsumo::VAR_VIA: {855std::vector<std::string> edgeIDs;856if (!server.readTypeCheckingStringList(inputStorage, edgeIDs)) {857return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Vias must be defined as a list of edge ids.", outputStorage);858}859libsumo::Vehicle::setVia(id, edgeIDs);860}861break;862case libsumo::VAR_PARAMETER: {863if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {864return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "A compound object is needed for setting a parameter.", outputStorage);865}866//readt itemNo867inputStorage.readInt();868std::string name;869if (!server.readTypeCheckingString(inputStorage, name)) {870return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The name of the parameter must be given as a string.", outputStorage);871}872std::string value;873if (!server.readTypeCheckingString(inputStorage, value)) {874return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The value of the parameter must be given as a string.", outputStorage);875}876try {877/// XXX but a big try/catch around all retrieval cases878libsumo::Vehicle::setParameter(id, name, value);879} catch (libsumo::TraCIException& e) {880return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, e.what(), outputStorage);881}882}883break;884case libsumo::VAR_HIGHLIGHT: {885// Highlight the vehicle by adding a tracking polygon. (NOTE: duplicated code exists for POI domain)886if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {887return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "A compound object is needed for highlighting an object.", outputStorage);888}889const int itemNo = inputStorage.readInt();890if (itemNo > 5) {891return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Highlighting an object needs zero to five parameters.", outputStorage);892}893libsumo::TraCIColor col = libsumo::TraCIColor(255, 0, 0);894if (itemNo > 0) {895if (!server.readTypeCheckingColor(inputStorage, col)) {896return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first parameter for highlighting must be the highlight color.", outputStorage);897}898}899double size = -1;900if (itemNo > 1) {901if (!server.readTypeCheckingDouble(inputStorage, size)) {902return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "The second parameter for highlighting must be the highlight size.", outputStorage);903}904}905int alphaMax = -1;906if (itemNo > 2) {907if (!server.readTypeCheckingUnsignedByte(inputStorage, alphaMax)) {908return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third parameter for highlighting must be maximal alpha.", outputStorage);909}910}911double duration = -1;912if (itemNo > 3) {913if (!server.readTypeCheckingDouble(inputStorage, duration)) {914return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fourth parameter for highlighting must be the highlight duration.", outputStorage);915}916}917int type = 0;918if (itemNo > 4) {919if (!server.readTypeCheckingUnsignedByte(inputStorage, type)) {920return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The fifth parameter for highlighting must be the highlight type id as ubyte.", outputStorage);921}922}923libsumo::Vehicle::highlight(id, col, size, alphaMax, duration, type);924}925break;926case libsumo::CMD_TAXI_DISPATCH: {927std::vector<std::string> reservations;928if (!server.readTypeCheckingStringList(inputStorage, reservations)) {929return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "A dispatch command must be defined as a list of reservation ids.", outputStorage);930}931libsumo::Vehicle::dispatchTaxi(id, reservations);932}933break;934case libsumo::VAR_ACTIONSTEPLENGTH: {935double value = 0;936if (!server.readTypeCheckingDouble(inputStorage, value)) {937return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting action step length requires a double.", outputStorage);938}939if (fabs(value) == std::numeric_limits<double>::infinity()) {940return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Invalid action step length.", outputStorage);941}942bool resetActionOffset = value >= 0.0;943libsumo::Vehicle::setActionStepLength(id, fabs(value), resetActionOffset);944}945break;946case libsumo::VAR_LANEPOSITION_LAT: {947double value = 0;948if (!server.readTypeCheckingDouble(inputStorage, value)) {949return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting lateral lane position requires a double.", outputStorage);950}951libsumo::Vehicle::setLateralLanePosition(id, value);952}953break;954case libsumo::VAR_UPDATE_BESTLANES: {955libsumo::Vehicle::updateBestLanes(id);956}957break;958case libsumo::VAR_MINGAP: {959double value = 0;960if (!server.readTypeCheckingDouble(inputStorage, value)) {961return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting minimum gap requires a double.", outputStorage);962}963if (value < 0.0 || fabs(value) == std::numeric_limits<double>::infinity()) {964return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Invalid minimum gap.", outputStorage);965}966libsumo::Vehicle::setMinGap(id, value);967}968break;969case libsumo::VAR_MINGAP_LAT: {970double value = 0;971if (!server.readTypeCheckingDouble(inputStorage, value)) {972return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Setting minimum lateral gap requires a double.", outputStorage);973}974if (value < 0.0 || fabs(value) == std::numeric_limits<double>::infinity()) {975return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "Invalid minimum lateral gap.", outputStorage);976}977libsumo::Vehicle::setMinGapLat(id, value);978}979break;980default: {981try {982if (!TraCIServerAPI_VehicleType::setVariable(libsumo::CMD_SET_VEHICLE_VARIABLE, variable, v->getSingularType().getID(), server, inputStorage, outputStorage)) {983return false;984}985} catch (ProcessError& e) {986return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, e.what(), outputStorage);987} catch (libsumo::TraCIException& e) {988return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, e.what(), outputStorage);989}990}991break;992}993} catch (libsumo::TraCIException& e) {994return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, e.what(), outputStorage);995}996server.writeStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);997return true;998}99910001001bool1002TraCIServerAPI_Vehicle::insertReplaceStop(TraCIServer& server, tcpip::Storage& inputStorage, tcpip::Storage& outputStorage, const std::string& id, bool replace) {1003const std::string m1 = replace ? "Replacing" : "Inserting";1004const std::string m2 = replace ? "replacement" : "insertion";10051006if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {1007return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, m1 + " stop needs a compound object description.", outputStorage);1008}1009int compoundSize = inputStorage.readInt();1010if (compoundSize != 8 && compoundSize != 9) {1011return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, m1 + " stop needs a compound object description of eight or nine items.", outputStorage);1012}1013// read road map position1014std::string edgeID;1015if (!server.readTypeCheckingString(inputStorage, edgeID)) {1016return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The first stop " + m2 + " parameter must be the edge id given as a string.", outputStorage);1017}1018double pos = 0;1019if (!server.readTypeCheckingDouble(inputStorage, pos)) {1020return 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);1021}1022int laneIndex = 0;1023if (!server.readTypeCheckingByte(inputStorage, laneIndex)) {1024return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The third stop " + m2 + " parameter must be the lane index given as a byte.", outputStorage);1025}1026// waitTime1027double duration = libsumo::INVALID_DOUBLE_VALUE;1028if (!server.readTypeCheckingDouble(inputStorage, duration)) {1029return server.writeErrorStatusCmd(libsumo::CMD_GET_VEHICLE_VARIABLE, "The fourth stop " + m2 + " parameter must be the stopping duration given as a double.", outputStorage);1030}1031const int stopFlags = StoHelp::readTypedInt(inputStorage, "The fifth stop " + m2 + " parameter must be a int indicating its parking/triggered status.");1032double startPos = libsumo::INVALID_DOUBLE_VALUE;1033if (!server.readTypeCheckingDouble(inputStorage, startPos)) {1034return 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);1035}1036double until = libsumo::INVALID_DOUBLE_VALUE;1037if (!server.readTypeCheckingDouble(inputStorage, until)) {1038return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The seventh stop " + m2 + " parameter must be the minimum departure time given as a double.", outputStorage);1039}1040const int nextStopIndex = StoHelp::readTypedInt(inputStorage, "The eigth stop " + m2 + " parameter must be the replacement index given as a int.");1041int teleport = 0;1042if (compoundSize == 9) {1043if (!server.readTypeCheckingByte(inputStorage, teleport)) {1044return server.writeErrorStatusCmd(libsumo::CMD_SET_VEHICLE_VARIABLE, "The nineth stop " + m2 + " parameter must be the teleport flag given as a byte.", outputStorage);1045}1046}1047if (replace) {1048libsumo::Vehicle::replaceStop(id, nextStopIndex, edgeID, pos, laneIndex, duration, stopFlags, startPos, until, teleport);1049} else {1050libsumo::Vehicle::insertStop(id, nextStopIndex, edgeID, pos, laneIndex, duration, stopFlags, startPos, until, teleport);1051}1052return true;1053}1054/****************************************************************************/105510561057