Path: blob/main/src/traci-server/TraCIServerAPI_Lane.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_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::processGet(TraCIServer& server, tcpip::Storage& inputStorage,45tcpip::Storage& outputStorage) {46const int variable = inputStorage.readUnsignedByte();47const std::string id = inputStorage.readString();48server.initWrapper(libsumo::RESPONSE_GET_LANE_VARIABLE, variable, id);49try {50if (!libsumo::Lane::handleVariable(id, variable, &server, &inputStorage)) {51return server.writeErrorStatusCmd(libsumo::CMD_GET_LANE_VARIABLE, "Get Lane Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);52}53} catch (libsumo::TraCIException& e) {54return server.writeErrorStatusCmd(libsumo::CMD_GET_LANE_VARIABLE, e.what(), outputStorage);55}56server.writeStatusCmd(libsumo::CMD_GET_LANE_VARIABLE, libsumo::RTYPE_OK, "", outputStorage);57server.writeResponseWithLength(outputStorage, server.getWrapperStorage());58return true;59}606162bool63TraCIServerAPI_Lane::processSet(TraCIServer& server, tcpip::Storage& inputStorage,64tcpip::Storage& outputStorage) {65std::string warning = ""; // additional description for response66// variable67int variable = inputStorage.readUnsignedByte();68if (variable != libsumo::VAR_MAXSPEED && variable != libsumo::VAR_LENGTH && variable != libsumo::LANE_ALLOWED && variable != libsumo::LANE_DISALLOWED69&& variable != libsumo::VAR_PARAMETER && variable != libsumo::LANE_CHANGES) {70return server.writeErrorStatusCmd(libsumo::CMD_SET_LANE_VARIABLE, "Change Lane State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);71}72// id73std::string id = inputStorage.readString();74MSLane* l = MSLane::dictionary(id);75if (l == nullptr) {76return server.writeErrorStatusCmd(libsumo::CMD_SET_LANE_VARIABLE, "Lane '" + id + "' is not known", outputStorage);77}78try {79// process80switch (variable) {81case libsumo::VAR_MAXSPEED: {82const double value = StoHelp::readTypedDouble(inputStorage, "The speed must be given as a double.");83libsumo::Lane::setMaxSpeed(id, value);84break;85}86case libsumo::VAR_FRICTION: {87const double value = StoHelp::readTypedDouble(inputStorage, "The friction must be given as a double.");88libsumo::Lane::setFriction(id, value);89break;90}91case libsumo::VAR_LENGTH: {92const double value = StoHelp::readTypedDouble(inputStorage, "The length must be given as a double.");93libsumo::Lane::setLength(id, value);94break;95}96case libsumo::LANE_ALLOWED: {97const std::vector<std::string> classes = StoHelp::readTypedStringList(inputStorage, "Allowed vehicle classes must be given as a list of strings.");98libsumo::Lane::setAllowed(id, classes);99break;100}101case libsumo::LANE_DISALLOWED: {102const std::vector<std::string> classes = StoHelp::readTypedStringList(inputStorage, "Not allowed vehicle classes must be given as a list of strings.");103libsumo::Lane::setDisallowed(id, classes);104break;105}106case libsumo::LANE_CHANGES: {107StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting lane change permissions.");108const std::vector<std::string> classes = StoHelp::readTypedStringList(inputStorage, "Vehicle classes allowed to change lane must be given as a list of strings.");109const int direction = StoHelp::readTypedByte(inputStorage, "The lane change direction must be given as an integer.");110libsumo::Lane::setChangePermissions(id, classes, direction);111break;112}113case libsumo::VAR_PARAMETER: {114StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting a parameter.");115const std::string name = StoHelp::readTypedString(inputStorage, "The name of the parameter must be given as a string.");116const std::string value = StoHelp::readTypedString(inputStorage, "The value of the parameter must be given as a string.");117libsumo::Lane::setParameter(id, name, value);118break;119}120default:121break;122}123} catch (libsumo::TraCIException& e) {124return server.writeErrorStatusCmd(libsumo::CMD_SET_LANE_VARIABLE, e.what(), outputStorage);125}126server.writeStatusCmd(libsumo::CMD_SET_LANE_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);127return true;128}129130131/****************************************************************************/132133134