Path: blob/main/src/traci-server/TraCIServerAPI_LaneArea.cpp
169665 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2014-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_LaneArea.cpp14/// @author Mario Krumnow15/// @author Robbin Blokpoel16/// @author Daniel Krajzewicz17/// @author Michael Behrisch18/// @date 03.02.201419///20// APIs for getting/setting areal detector values via TraCI21/****************************************************************************/22#include <config.h>2324#include <microsim/output/MSDetectorControl.h>25#include <libsumo/LaneArea.h>26#include <libsumo/TraCIConstants.h>27#include <libsumo/StorageHelper.h>28#include "TraCIServer.h"29#include "TraCIServerAPI_LaneArea.h"303132// ===========================================================================33// method definitions34// ===========================================================================35bool36TraCIServerAPI_LaneArea::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_LANEAREA_VARIABLE, variable, id);41try {42if (!libsumo::LaneArea::handleVariable(id, variable, &server, &inputStorage)) {43return server.writeErrorStatusCmd(libsumo::CMD_GET_LANEAREA_VARIABLE, "Get Lane Area Detector Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);44}45} catch (libsumo::TraCIException& e) {46return server.writeErrorStatusCmd(libsumo::CMD_GET_LANEAREA_VARIABLE, e.what(), outputStorage);47}48server.writeStatusCmd(libsumo::CMD_GET_LANEAREA_VARIABLE, libsumo::RTYPE_OK, "", outputStorage);49server.writeResponseWithLength(outputStorage, server.getWrapperStorage());50return true;51}525354bool55TraCIServerAPI_LaneArea::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&& variable != libsumo::VAR_VIRTUAL_DETECTION62) {63return server.writeErrorStatusCmd(libsumo::CMD_SET_LANEAREA_VARIABLE, "Set Lane Area Detector Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);64}65// id66std::string id = inputStorage.readString();67// process68try {69switch (variable) {70case libsumo::VAR_VIRTUAL_DETECTION: {71const int vehNum = StoHelp::readTypedInt(inputStorage, "Overriding the number of detected vehicles requires an integer");72libsumo::LaneArea::overrideVehicleNumber(id, vehNum);73break;74}75case libsumo::VAR_PARAMETER: {76StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting a parameter.");77const std::string name = StoHelp::readTypedString(inputStorage, "The name of the parameter must be given as a string.");78const std::string value = StoHelp::readTypedString(inputStorage, "The value of the parameter must be given as a string.");79libsumo::LaneArea::setParameter(id, name, value);80break;81}82default:83break;84}85} catch (libsumo::TraCIException& e) {86return server.writeErrorStatusCmd(libsumo::CMD_SET_LANEAREA_VARIABLE, e.what(), outputStorage);87}88server.writeStatusCmd(libsumo::CMD_SET_LANEAREA_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);89return true;90}919293/****************************************************************************/949596