Path: blob/main/src/traci-server/TraCIServerAPI_InductionLoop.cpp
193678 views
/****************************************************************************/1// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2// Copyright (C) 2009-2026 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::processSet(TraCIServer& server, tcpip::Storage& inputStorage,37tcpip::Storage& outputStorage) {38std::string warning = ""; // additional description for response39// variable40int variable = inputStorage.readUnsignedByte();41if (variable != libsumo::VAR_PARAMETER42&& variable != libsumo::VAR_VIRTUAL_DETECTION43) {44return server.writeErrorStatusCmd(libsumo::CMD_SET_INDUCTIONLOOP_VARIABLE, "Set Induction Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);45}46// id47std::string id = inputStorage.readString();48// process49try {50switch (variable) {51case libsumo::VAR_VIRTUAL_DETECTION: {52libsumo::InductionLoop::overrideTimeSinceDetection(id, StoHelp::readTypedDouble(inputStorage, "Setting time since last detection requires a double."));53break;54}55case libsumo::VAR_PARAMETER: {56StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting a parameter.");57const std::string name = StoHelp::readTypedString(inputStorage, "The name of the parameter must be given as a string.");58const std::string value = StoHelp::readTypedString(inputStorage, "The value of the parameter must be given as a string.");59libsumo::InductionLoop::setParameter(id, name, value);60break;61}62default:63break;64}65} catch (libsumo::TraCIException& e) {66return server.writeErrorStatusCmd(libsumo::CMD_SET_INDUCTIONLOOP_VARIABLE, e.what(), outputStorage);67}68server.writeStatusCmd(libsumo::CMD_SET_INDUCTIONLOOP_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);69return true;70}717273/****************************************************************************/747576