Path: blob/main/src/traci-server/TraCIServerAPI_Junction.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_Junction.cpp14/// @author Daniel Krajzewicz15/// @author Laura Bieker16/// @author Michael Behrisch17/// @author Mario Krumnow18/// @author Jakob Erdmann19/// @date 07.05.200920///21// APIs for getting/setting junction values via TraCI22/****************************************************************************/23#include <config.h>2425#include <microsim/MSJunctionControl.h>26#include "TraCIServer.h"27#include <libsumo/Junction.h>28#include <libsumo/StorageHelper.h>29#include "TraCIServerAPI_Junction.h"303132// ===========================================================================33// method definitions34// ===========================================================================35bool36TraCIServerAPI_Junction::processGet(TraCIServer& server, tcpip::Storage& inputStorage,37tcpip::Storage& outputStorage) {38const int variable = inputStorage.readUnsignedByte();39const std::string id = inputStorage.readString();40server.initWrapper(libsumo::RESPONSE_GET_JUNCTION_VARIABLE, variable, id);41try {42if (!libsumo::Junction::handleVariable(id, variable, &server, &inputStorage)) {43return server.writeErrorStatusCmd(libsumo::CMD_GET_JUNCTION_VARIABLE, "Get Junction Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);44}45} catch (libsumo::TraCIException& e) {46return server.writeErrorStatusCmd(libsumo::CMD_GET_JUNCTION_VARIABLE, e.what(), outputStorage);47}48server.writeStatusCmd(libsumo::CMD_GET_JUNCTION_VARIABLE, libsumo::RTYPE_OK, "", outputStorage);49server.writeResponseWithLength(outputStorage, server.getWrapperStorage());50return true;51}525354bool55TraCIServerAPI_Junction::processSet(TraCIServer& server, tcpip::Storage& inputStorage,56tcpip::Storage& outputStorage) {57std::string warning = ""; // additional description for response58// variable59int variable = inputStorage.readUnsignedByte();60if (variable != libsumo::VAR_PARAMETER61) {62return server.writeErrorStatusCmd(libsumo::CMD_SET_JUNCTION_VARIABLE, "Set Junction Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);63}64// id65std::string id = inputStorage.readString();66// process67try {68switch (variable) {69case libsumo::VAR_PARAMETER: {70StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting a parameter.");71const std::string name = StoHelp::readTypedString(inputStorage, "The name of the parameter must be given as a string.");72const std::string value = StoHelp::readTypedString(inputStorage, "The value of the parameter must be given as a string.");73libsumo::Junction::setParameter(id, name, value);74break;75}76default:77break;78}79} catch (libsumo::TraCIException& e) {80return server.writeErrorStatusCmd(libsumo::CMD_SET_JUNCTION_VARIABLE, e.what(), outputStorage);81}82server.writeStatusCmd(libsumo::CMD_SET_JUNCTION_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);83return true;84}858687/****************************************************************************/888990