Path: blob/main/src/traci-server/TraCIServerAPI_InductionLoop.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_InductionLoop.cpp14/// @author Daniel Krajzewicz15/// @author Laura Bieker16/// @author Michael Behrisch17/// @author Jakob Erdmann18/// @date 07.05.200919///20// APIs for getting/setting induction loop values via TraCI21/****************************************************************************/22#include <config.h>2324#include <microsim/MSNet.h>25#include <microsim/output/MSDetectorControl.h>26#include <libsumo/InductionLoop.h>27#include <libsumo/TraCIConstants.h>28#include <libsumo/StorageHelper.h>29#include "TraCIServerAPI_InductionLoop.h"303132// ===========================================================================33// method definitions34// ===========================================================================35bool36TraCIServerAPI_InductionLoop::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_INDUCTIONLOOP_VARIABLE, variable, id);41try {42if (!libsumo::InductionLoop::handleVariable(id, variable, &server, &inputStorage)) {43return server.writeErrorStatusCmd(libsumo::CMD_GET_INDUCTIONLOOP_VARIABLE,44"Get Induction Loop Variable: unsupported variable " + toHex(variable, 2)45+ " specified", outputStorage);46}47} catch (libsumo::TraCIException& e) {48return server.writeErrorStatusCmd(libsumo::CMD_GET_INDUCTIONLOOP_VARIABLE, e.what(), outputStorage);49}50server.writeStatusCmd(libsumo::CMD_GET_INDUCTIONLOOP_VARIABLE, libsumo::RTYPE_OK, "", outputStorage);51server.writeResponseWithLength(outputStorage, server.getWrapperStorage());52return true;53}545556bool57TraCIServerAPI_InductionLoop::processSet(TraCIServer& server, tcpip::Storage& inputStorage,58tcpip::Storage& outputStorage) {59std::string warning = ""; // additional description for response60// variable61int variable = inputStorage.readUnsignedByte();62if (variable != libsumo::VAR_PARAMETER63&& variable != libsumo::VAR_VIRTUAL_DETECTION64) {65return server.writeErrorStatusCmd(libsumo::CMD_SET_INDUCTIONLOOP_VARIABLE, "Set Induction Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);66}67// id68std::string id = inputStorage.readString();69// process70try {71switch (variable) {72case libsumo::VAR_VIRTUAL_DETECTION: {73double time = -1;74if (!server.readTypeCheckingDouble(inputStorage, time)) {75return server.writeErrorStatusCmd(libsumo::CMD_SET_INDUCTIONLOOP_VARIABLE, "Setting time since last detection requires a double.", outputStorage);76}77libsumo::InductionLoop::overrideTimeSinceDetection(id, time);78break;79}80case libsumo::VAR_PARAMETER: {81StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting a parameter.");82const std::string name = StoHelp::readTypedString(inputStorage, "The name of the parameter must be given as a string.");83const std::string value = StoHelp::readTypedString(inputStorage, "The value of the parameter must be given as a string.");84libsumo::InductionLoop::setParameter(id, name, value);85break;86}87default:88break;89}90} catch (libsumo::TraCIException& e) {91return server.writeErrorStatusCmd(libsumo::CMD_SET_INDUCTIONLOOP_VARIABLE, e.what(), outputStorage);92}93server.writeStatusCmd(libsumo::CMD_SET_INDUCTIONLOOP_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);94return true;95}969798/****************************************************************************/99100101