Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
TraCIServerAPI_Lane.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2009-2025 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/****************************************************************************/
24// APIs for getting/setting lane values via TraCI
25/****************************************************************************/
26#include <config.h>
27
28#include <microsim/MSEdge.h>
30#include <microsim/MSLane.h>
31#include <microsim/MSNet.h>
32#include <microsim/MSVehicle.h>
34#include <libsumo/Lane.h>
37#include "TraCIServer.h"
38#include "TraCIServerAPI_Lane.h"
39
40
41// ===========================================================================
42// method definitions
43// ===========================================================================
44bool
46 tcpip::Storage& outputStorage) {
47 std::string warning = ""; // additional description for response
48 // variable
49 int variable = inputStorage.readUnsignedByte();
50 if (variable != libsumo::VAR_MAXSPEED && variable != libsumo::VAR_LENGTH && variable != libsumo::LANE_ALLOWED && variable != libsumo::LANE_DISALLOWED
51 && variable != libsumo::VAR_PARAMETER && variable != libsumo::LANE_CHANGES) {
52 return server.writeErrorStatusCmd(libsumo::CMD_SET_LANE_VARIABLE, "Change Lane State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
53 }
54 // id
55 std::string id = inputStorage.readString();
57 if (l == nullptr) {
58 return server.writeErrorStatusCmd(libsumo::CMD_SET_LANE_VARIABLE, "Lane '" + id + "' is not known", outputStorage);
59 }
60 try {
61 // process
62 switch (variable) {
64 const double value = StoHelp::readTypedDouble(inputStorage, "The speed must be given as a double.");
65 libsumo::Lane::setMaxSpeed(id, value);
66 break;
67 }
69 const double value = StoHelp::readTypedDouble(inputStorage, "The friction must be given as a double.");
70 libsumo::Lane::setFriction(id, value);
71 break;
72 }
74 const double value = StoHelp::readTypedDouble(inputStorage, "The length must be given as a double.");
75 libsumo::Lane::setLength(id, value);
76 break;
77 }
79 const std::vector<std::string> classes = StoHelp::readTypedStringList(inputStorage, "Allowed vehicle classes must be given as a list of strings.");
80 libsumo::Lane::setAllowed(id, classes);
81 break;
82 }
84 const std::vector<std::string> classes = StoHelp::readTypedStringList(inputStorage, "Not allowed vehicle classes must be given as a list of strings.");
85 libsumo::Lane::setDisallowed(id, classes);
86 break;
87 }
89 StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting lane change permissions.");
90 const std::vector<std::string> classes = StoHelp::readTypedStringList(inputStorage, "Vehicle classes allowed to change lane must be given as a list of strings.");
91 const int direction = StoHelp::readTypedByte(inputStorage, "The lane change direction must be given as an integer.");
92 libsumo::Lane::setChangePermissions(id, classes, direction);
93 break;
94 }
96 StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting a parameter.");
97 const std::string name = StoHelp::readTypedString(inputStorage, "The name of the parameter must be given as a string.");
98 const std::string value = StoHelp::readTypedString(inputStorage, "The value of the parameter must be given as a string.");
99 libsumo::Lane::setParameter(id, name, value);
100 break;
101 }
102 default:
103 break;
104 }
105 } catch (libsumo::TraCIException& e) {
106 return server.writeErrorStatusCmd(libsumo::CMD_SET_LANE_VARIABLE, e.what(), outputStorage);
107 }
108 server.writeStatusCmd(libsumo::CMD_SET_LANE_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);
109 return true;
110}
111
112
113/****************************************************************************/
std::string toHex(const T i, std::streamsize numDigits=0)
Definition ToString.h:56
Representation of a lane in the micro simulation.
Definition MSLane.h:84
static bool dictionary(const std::string &id, MSLane *lane)
Static (sic!) container methods {.
Definition MSLane.cpp:2489
static bool processSet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a set value command (Command 0xc3: Change Lane State)
TraCI server used to control sumo by a remote TraCI client.
Definition TraCIServer.h:59
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
bool writeErrorStatusCmd(int commandId, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage with status = RTYPE_ERR.
static int readTypedByte(tcpip::Storage &ret, const std::string &error="")
static int readCompound(tcpip::Storage &ret, int expectedSize=-1, const std::string &error="")
static std::vector< std::string > readTypedStringList(tcpip::Storage &ret, const std::string &error="")
static std::string readTypedString(tcpip::Storage &ret, const std::string &error="")
static double readTypedDouble(tcpip::Storage &ret, const std::string &error="")
An error which allows to continue.
Definition TraCIDefs.h:145
virtual std::string readString()
Definition storage.cpp:180
virtual int readUnsignedByte()
Definition storage.cpp:155
TRACI_CONST int LANE_CHANGES
TRACI_CONST int VAR_MAXSPEED
TRACI_CONST int VAR_LENGTH
TRACI_CONST int VAR_PARAMETER
TRACI_CONST int CMD_SET_LANE_VARIABLE
TRACI_CONST int LANE_DISALLOWED
TRACI_CONST int VAR_FRICTION
TRACI_CONST int RTYPE_OK
TRACI_CONST int LANE_ALLOWED