Path: blob/main/src/traci-server/TraCIServerAPI_Lane.cpp
193678 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2009-2026 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_Lane.cpp14/// @author Daniel Krajzewicz15/// @author Jakob Erdmann16/// @author Michael Behrisch17/// @author Laura Bieker18/// @author Mario Krumnow19/// @author Leonhard Luecken20/// @author Mirko Barthauer21/// @date 07.05.200922///23// APIs for getting/setting lane values via TraCI24/****************************************************************************/25#include <config.h>2627#include <microsim/MSEdge.h>28#include <microsim/MSEdgeControl.h>29#include <microsim/MSLane.h>30#include <microsim/MSNet.h>31#include <microsim/MSVehicle.h>32#include <microsim/transportables/MSTransportable.h>33#include <libsumo/Lane.h>34#include <libsumo/TraCIConstants.h>35#include <libsumo/StorageHelper.h>36#include "TraCIServer.h"37#include "TraCIServerAPI_Lane.h"383940// ===========================================================================41// method definitions42// ===========================================================================43bool44TraCIServerAPI_Lane::processSet(TraCIServer& server, tcpip::Storage& inputStorage,45tcpip::Storage& outputStorage) {46std::string warning = ""; // additional description for response47// variable48int variable = inputStorage.readUnsignedByte();49if (variable != libsumo::VAR_MAXSPEED && variable != libsumo::VAR_LENGTH && variable != libsumo::LANE_ALLOWED && variable != libsumo::LANE_DISALLOWED50&& variable != libsumo::VAR_PARAMETER && variable != libsumo::LANE_CHANGES) {51return server.writeErrorStatusCmd(libsumo::CMD_SET_LANE_VARIABLE, "Change Lane State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);52}53// id54std::string id = inputStorage.readString();55MSLane* l = MSLane::dictionary(id);56if (l == nullptr) {57return server.writeErrorStatusCmd(libsumo::CMD_SET_LANE_VARIABLE, "Lane '" + id + "' is not known", outputStorage);58}59try {60// process61switch (variable) {62case libsumo::VAR_MAXSPEED: {63const double value = StoHelp::readTypedDouble(inputStorage, "The speed must be given as a double.");64libsumo::Lane::setMaxSpeed(id, value);65break;66}67case libsumo::VAR_FRICTION: {68const double value = StoHelp::readTypedDouble(inputStorage, "The friction must be given as a double.");69libsumo::Lane::setFriction(id, value);70break;71}72case libsumo::VAR_LENGTH: {73const double value = StoHelp::readTypedDouble(inputStorage, "The length must be given as a double.");74libsumo::Lane::setLength(id, value);75break;76}77case libsumo::LANE_ALLOWED: {78const std::vector<std::string> classes = StoHelp::readTypedStringList(inputStorage, "Allowed vehicle classes must be given as a list of strings.");79libsumo::Lane::setAllowed(id, classes);80break;81}82case libsumo::LANE_DISALLOWED: {83const std::vector<std::string> classes = StoHelp::readTypedStringList(inputStorage, "Not allowed vehicle classes must be given as a list of strings.");84libsumo::Lane::setDisallowed(id, classes);85break;86}87case libsumo::LANE_CHANGES: {88StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting lane change permissions.");89const std::vector<std::string> classes = StoHelp::readTypedStringList(inputStorage, "Vehicle classes allowed to change lane must be given as a list of strings.");90const int direction = StoHelp::readTypedByte(inputStorage, "The lane change direction must be given as an integer.");91libsumo::Lane::setChangePermissions(id, classes, direction);92break;93}94case libsumo::VAR_PARAMETER: {95StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting a parameter.");96const std::string name = StoHelp::readTypedString(inputStorage, "The name of the parameter must be given as a string.");97const std::string value = StoHelp::readTypedString(inputStorage, "The value of the parameter must be given as a string.");98libsumo::Lane::setParameter(id, name, value);99break;100}101default:102break;103}104} catch (libsumo::TraCIException& e) {105return server.writeErrorStatusCmd(libsumo::CMD_SET_LANE_VARIABLE, e.what(), outputStorage);106}107server.writeStatusCmd(libsumo::CMD_SET_LANE_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);108return true;109}110111112/****************************************************************************/113114115