LCOV - code coverage report
Current view: top level - src/traci-server - TraCIServerAPI_TrafficLight.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 216 289 74.7 %
Date: 2024-05-08 15:29:52 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /****************************************************************************/
       2             : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3             : // Copyright (C) 2009-2024 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             : /****************************************************************************/
      14             : /// @file    TraCIServerAPI_TrafficLight.cpp
      15             : /// @author  Daniel Krajzewicz
      16             : /// @author  Laura Bieker
      17             : /// @author  Michael Behrisch
      18             : /// @author  Jakob Erdmann
      19             : /// @date    07.05.2009
      20             : ///
      21             : // APIs for getting/setting traffic light values via TraCI
      22             : /****************************************************************************/
      23             : #include <config.h>
      24             : 
      25             : #include <microsim/MSLane.h>
      26             : #include <microsim/MSEdge.h>
      27             : #include <microsim/traffic_lights/MSTLLogicControl.h>
      28             : #include <microsim/traffic_lights/MSSimpleTrafficLightLogic.h>
      29             : #include <libsumo/TraCIConstants.h>
      30             : #include <libsumo/StorageHelper.h>
      31             : #include <libsumo/TrafficLight.h>
      32             : #include "TraCIServerAPI_TrafficLight.h"
      33             : 
      34             : 
      35             : // ===========================================================================
      36             : // method definitions
      37             : // ===========================================================================
      38             : bool
      39      126447 : TraCIServerAPI_TrafficLight::processGet(TraCIServer& server, tcpip::Storage& inputStorage,
      40             :                                         tcpip::Storage& outputStorage) {
      41      126447 :     const int variable = inputStorage.readUnsignedByte();
      42      126447 :     const std::string id = inputStorage.readString();
      43      126447 :     server.initWrapper(libsumo::RESPONSE_GET_TL_VARIABLE, variable, id);
      44             :     try {
      45      126447 :         if (!libsumo::TrafficLight::handleVariable(id, variable, &server, &inputStorage)) {
      46       19262 :             switch (variable) {
      47          69 :                 case libsumo::TL_COMPLETE_DEFINITION_RYG: {
      48          69 :                     std::vector<libsumo::TraCILogic> logics = libsumo::TrafficLight::getAllProgramLogics(id);
      49          69 :                     tcpip::Storage& storage = server.getWrapperStorage();
      50          69 :                     StoHelp::writeCompound(storage, (int)logics.size());
      51         193 :                     for (const libsumo::TraCILogic& logic : logics) {
      52             :                         StoHelp::writeCompound(storage, 5);
      53         124 :                         StoHelp::writeTypedString(storage, logic.programID);
      54         124 :                         StoHelp::writeTypedInt(storage, logic.type);
      55         124 :                         StoHelp::writeTypedInt(storage, logic.currentPhaseIndex);
      56         124 :                         StoHelp::writeCompound(storage, (int)logic.phases.size());
      57         935 :                         for (const std::shared_ptr<libsumo::TraCIPhase>& phase : logic.phases) {
      58             :                             StoHelp::writeCompound(storage, 6);
      59         811 :                             StoHelp::writeTypedDouble(storage, phase->duration);
      60         811 :                             StoHelp::writeTypedString(storage, phase->state);
      61         811 :                             StoHelp::writeTypedDouble(storage, phase->minDur);
      62         811 :                             StoHelp::writeTypedDouble(storage, phase->maxDur);
      63         811 :                             StoHelp::writeCompound(storage, (int)phase->next.size());
      64         907 :                             for (int n : phase->next) {
      65             :                                 StoHelp::writeTypedInt(storage, n);
      66             :                             }
      67         811 :                             StoHelp::writeTypedString(storage, phase->name);
      68             :                         }
      69         124 :                         StoHelp::writeCompound(storage, (int)logic.subParameter.size());
      70         136 :                         for (const auto& item : logic.subParameter) {
      71          48 :                             StoHelp::writeTypedStringList(storage, std::vector<std::string> {item.first, item.second});
      72             :                         }
      73             :                     }
      74             :                     break;
      75          69 :                 }
      76          35 :                 case libsumo::TL_CONTROLLED_LINKS: {
      77          35 :                     const std::vector<std::vector<libsumo::TraCILink> > links = libsumo::TrafficLight::getControlledLinks(id);
      78          35 :                     server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_COMPOUND);
      79          35 :                     tcpip::Storage tempContent;
      80          35 :                     tempContent.writeUnsignedByte(libsumo::TYPE_INTEGER);
      81          35 :                     tempContent.writeInt((int)links.size());
      82             :                     int cnt = 1;
      83         610 :                     for (const std::vector<libsumo::TraCILink>& sublinks : links) {
      84         575 :                         tempContent.writeUnsignedByte(libsumo::TYPE_INTEGER);
      85         575 :                         tempContent.writeInt((int)sublinks.size());
      86         575 :                         ++cnt;
      87        1150 :                         for (const libsumo::TraCILink& link : sublinks) {
      88         575 :                             tempContent.writeUnsignedByte(libsumo::TYPE_STRINGLIST);
      89        2300 :                             tempContent.writeStringList(std::vector<std::string>({ link.fromLane, link.toLane, link.viaLane }));
      90         575 :                             ++cnt;
      91             :                         }
      92             :                     }
      93          35 :                     server.getWrapperStorage().writeInt(cnt);
      94          35 :                     server.getWrapperStorage().writeStorage(tempContent);
      95             :                     break;
      96          35 :                 }
      97         142 :                 case libsumo::VAR_PERSON_NUMBER: {
      98         142 :                     int index = 0;
      99         142 :                     if (!server.readTypeCheckingInt(inputStorage, index)) {
     100           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The phase index must be given as an integer.", outputStorage);
     101             :                     }
     102         142 :                     server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_INTEGER);
     103         142 :                     server.getWrapperStorage().writeInt(libsumo::TrafficLight::getServedPersonCount(id, index));
     104         142 :                     break;
     105             :                 }
     106        5986 :                 case libsumo::TL_BLOCKING_VEHICLES: {
     107        5986 :                     int index = 0;
     108        5986 :                     if (!server.readTypeCheckingInt(inputStorage, index)) {
     109           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The link index must be given as an integer.", outputStorage);
     110             :                     }
     111        5986 :                     server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRINGLIST);
     112        5986 :                     server.getWrapperStorage().writeStringList(libsumo::TrafficLight::getBlockingVehicles(id, index));
     113        5986 :                     break;
     114             :                 }
     115        5978 :                 case libsumo::TL_RIVAL_VEHICLES: {
     116        5978 :                     int index = 0;
     117        5978 :                     if (!server.readTypeCheckingInt(inputStorage, index)) {
     118           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The link index must be given as an integer.", outputStorage);
     119             :                     }
     120        5978 :                     server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRINGLIST);
     121        5978 :                     server.getWrapperStorage().writeStringList(libsumo::TrafficLight::getRivalVehicles(id, index));
     122        5978 :                     break;
     123             :                 }
     124        5978 :                 case libsumo::TL_PRIORITY_VEHICLES: {
     125        5978 :                     int index = 0;
     126        5978 :                     if (!server.readTypeCheckingInt(inputStorage, index)) {
     127           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The link index must be given as an integer.", outputStorage);
     128             :                     }
     129        5978 :                     server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRINGLIST);
     130        5978 :                     server.getWrapperStorage().writeStringList(libsumo::TrafficLight::getPriorityVehicles(id, index));
     131        5978 :                     break;
     132             :                 }
     133             :                 case libsumo::TL_CONSTRAINT: {
     134             :                     std::string tripId;
     135         976 :                     if (!server.readTypeCheckingString(inputStorage, tripId)) {
     136           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The tripId must be given as a string.", outputStorage);
     137             :                     }
     138         976 :                     std::vector<libsumo::TraCISignalConstraint> constraints = libsumo::TrafficLight::getConstraints(id, tripId);
     139         976 :                     server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_COMPOUND);
     140         976 :                     const int cnt = 1 + (int)constraints.size() * 5;
     141         976 :                     server.getWrapperStorage().writeInt(cnt);
     142         976 :                     server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_INTEGER);
     143         976 :                     server.getWrapperStorage().writeInt((int)constraints.size());
     144        1758 :                     for (const auto& c : constraints) {
     145         782 :                         writeConstraint(server, c);
     146             :                     }
     147             :                     break;
     148         976 :                 }
     149             :                 case libsumo::TL_CONSTRAINT_BYFOE: {
     150             :                     std::string foeId;
     151           8 :                     if (!server.readTypeCheckingString(inputStorage, foeId)) {
     152           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The foeId must be given as a string.", outputStorage);
     153             :                     }
     154           8 :                     std::vector<libsumo::TraCISignalConstraint> constraints = libsumo::TrafficLight::getConstraintsByFoe(id, foeId);
     155           8 :                     server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_COMPOUND);
     156           8 :                     const int cnt = 1 + (int)constraints.size() * 5;
     157           8 :                     server.getWrapperStorage().writeInt(cnt);
     158           8 :                     server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_INTEGER);
     159           8 :                     server.getWrapperStorage().writeInt((int)constraints.size());
     160          36 :                     for (const auto& c : constraints) {
     161          28 :                         writeConstraint(server, c);
     162             :                     }
     163             :                     break;
     164           8 :                 }
     165          88 :                 case libsumo::TL_CONSTRAINT_SWAP: {
     166          88 :                     if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
     167           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "A compound object is needed for swapping constraints.", outputStorage);
     168             :                     }
     169             :                     //read itemNo
     170          88 :                     inputStorage.readInt();
     171             :                     std::string tripId;
     172          88 :                     if (!server.readTypeCheckingString(inputStorage, tripId)) {
     173           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The tripId must be given as a string.", outputStorage);
     174             :                     }
     175             :                     std::string foeSignal;
     176          88 :                     if (!server.readTypeCheckingString(inputStorage, foeSignal)) {
     177           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The foeSignal id must be given as a string.", outputStorage);
     178             :                     }
     179             :                     std::string foeId;
     180          88 :                     if (!server.readTypeCheckingString(inputStorage, foeId)) {
     181           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The foe tripId must be given as a string.", outputStorage);
     182             :                     }
     183          88 :                     std::vector<libsumo::TraCISignalConstraint> constraints = libsumo::TrafficLight::swapConstraints(id, tripId, foeSignal, foeId);
     184          88 :                     server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_COMPOUND);
     185          88 :                     const int cnt = 1 + (int)constraints.size() * 5;
     186          88 :                     server.getWrapperStorage().writeInt(cnt);
     187          88 :                     server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_INTEGER);
     188          88 :                     server.getWrapperStorage().writeInt((int)constraints.size());
     189         168 :                     for (const auto& c : constraints) {
     190          80 :                         writeConstraint(server, c);
     191             :                     }
     192             :                     break;
     193          88 :                 }
     194           0 :                 case libsumo::TL_EXTERNAL_STATE: {
     195           0 :                     if (!MSNet::getInstance()->getTLSControl().knows(id)) {
     196           0 :                         throw libsumo::TraCIException("Traffic light '" + id + "' is not known");
     197             :                     }
     198           0 :                     MSTrafficLightLogic* tls = MSNet::getInstance()->getTLSControl().get(id).getActive();
     199           0 :                     const std::string& state = tls->getCurrentPhaseDef().getState();
     200           0 :                     const Parameterised::Map& params = tls->getParametersMap();
     201             :                     int num = 0;
     202           0 :                     for (Parameterised::Map::const_iterator i = params.begin(); i != params.end(); ++i) {
     203           0 :                         if ("connection:" == (*i).first.substr(0, 11)) {
     204           0 :                             ++num;
     205             :                         }
     206             :                     }
     207             : 
     208           0 :                     server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_COMPOUND);
     209           0 :                     server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_INTEGER);
     210           0 :                     server.getWrapperStorage().writeInt(num * 2);
     211           0 :                     for (Parameterised::Map::const_iterator i = params.begin(); i != params.end(); ++i) {
     212           0 :                         if ("connection:" != (*i).first.substr(0, 11)) {
     213           0 :                             continue;
     214             :                         }
     215           0 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_STRING);
     216           0 :                         server.getWrapperStorage().writeString((*i).second); // foreign id
     217           0 :                         std::string connection = (*i).first.substr(11);
     218             :                         std::string from, to;
     219             :                         const std::string::size_type b = connection.find("->");
     220           0 :                         if (b == std::string::npos) {
     221             :                             from = connection;
     222             :                         } else {
     223           0 :                             from = connection.substr(0, b);
     224           0 :                             to = connection.substr(b + 2);
     225             :                         }
     226             :                         bool denotesEdge = from.find("_") == std::string::npos;
     227             :                         MSLane* fromLane = nullptr;
     228             :                         const MSTrafficLightLogic::LaneVectorVector& lanes = tls->getLaneVectors();
     229             :                         MSTrafficLightLogic::LaneVectorVector::const_iterator j = lanes.begin();
     230           0 :                         for (; j != lanes.end() && fromLane == nullptr;) {
     231           0 :                             for (MSTrafficLightLogic::LaneVector::const_iterator k = (*j).begin(); k != (*j).end() && fromLane == nullptr;) {
     232           0 :                                 if (denotesEdge && (*k)->getEdge().getID() == from) {
     233             :                                     fromLane = *k;
     234           0 :                                 } else if (!denotesEdge && (*k)->getID() == from) {
     235             :                                     fromLane = *k;
     236             :                                 }
     237           0 :                                 if (fromLane == nullptr) {
     238             :                                     ++k;
     239             :                                 }
     240             :                             }
     241           0 :                             if (fromLane == nullptr) {
     242             :                                 ++j;
     243             :                             }
     244             :                         }
     245           0 :                         if (fromLane == nullptr) {
     246           0 :                             return server.writeErrorStatusCmd(libsumo::CMD_GET_TL_VARIABLE, "Could not find edge or lane '" + from + "' in traffic light '" + id + "'.", outputStorage);
     247             :                         }
     248           0 :                         int pos = (int)std::distance(lanes.begin(), j);
     249           0 :                         server.getWrapperStorage().writeUnsignedByte(libsumo::TYPE_UBYTE);
     250           0 :                         server.getWrapperStorage().writeUnsignedByte(state[pos]); // state
     251             :                     }
     252             :                     break;
     253             :                 }
     254           2 :                 default:
     255           4 :                     return server.writeErrorStatusCmd(libsumo::CMD_GET_TL_VARIABLE, "Get TLS Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
     256             :             }
     257             :         }
     258           3 :     } catch (libsumo::TraCIException& e) {
     259           3 :         return server.writeErrorStatusCmd(libsumo::CMD_GET_TL_VARIABLE, e.what(), outputStorage);
     260           3 :     }
     261      126442 :     server.writeStatusCmd(libsumo::CMD_GET_TL_VARIABLE, libsumo::RTYPE_OK, "", outputStorage);
     262      126442 :     server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
     263             :     return true;
     264             : }
     265             : 
     266             : 
     267             : bool
     268        3542 : TraCIServerAPI_TrafficLight::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
     269             :                                         tcpip::Storage& outputStorage) {
     270        3542 :     std::string warning = ""; // additional description for response
     271             :     // variable
     272        3542 :     const int variable = inputStorage.readUnsignedByte();
     273        3542 :     if (variable != libsumo::TL_PHASE_INDEX && variable != libsumo::TL_PROGRAM && variable != libsumo::TL_PHASE_DURATION
     274        3542 :             && variable != libsumo::TL_RED_YELLOW_GREEN_STATE && variable != libsumo::TL_COMPLETE_PROGRAM_RYG
     275         191 :             && variable != libsumo::VAR_NAME
     276             :             && variable != libsumo::TL_CONSTRAINT_REMOVE
     277         135 :             && variable != libsumo::TL_CONSTRAINT_UPDATE
     278         112 :             && variable != libsumo::TL_CONSTRAINT_ADD
     279         112 :             && variable != libsumo::VAR_PARAMETER) {
     280           2 :         return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "Change TLS State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
     281             :     }
     282        3541 :     const std::string id = inputStorage.readString();
     283             :     try {
     284        3541 :         switch (variable) {
     285        3265 :             case libsumo::TL_PHASE_INDEX: {
     286        3265 :                 int index = 0;
     287        3265 :                 if (!server.readTypeCheckingInt(inputStorage, index)) {
     288           2 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The phase index must be given as an integer.", outputStorage);
     289             :                 }
     290        3264 :                 libsumo::TrafficLight::setPhase(id, index);
     291             :             }
     292        3261 :             break;
     293             :             case libsumo::VAR_NAME: {
     294             :                 std::string name;
     295          11 :                 if (!server.readTypeCheckingString(inputStorage, name)) {
     296           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The phase name must be given as a string.", outputStorage);
     297             :                 }
     298          11 :                 libsumo::TrafficLight::setPhaseName(id, name);
     299             :             }
     300             :             break;
     301             :             case libsumo::TL_PROGRAM: {
     302             :                 std::string subID;
     303          25 :                 if (!server.readTypeCheckingString(inputStorage, subID)) {
     304           1 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The program must be given as a string.", outputStorage);
     305             :                 }
     306          25 :                 libsumo::TrafficLight::setProgram(id, subID);
     307             :             }
     308             :             break;
     309          28 :             case libsumo::TL_PHASE_DURATION: {
     310          28 :                 double duration = 0.;
     311          28 :                 if (!server.readTypeCheckingDouble(inputStorage, duration)) {
     312           2 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The phase duration must be given as a double.", outputStorage);
     313             :                 }
     314          27 :                 libsumo::TrafficLight::setPhaseDuration(id, duration);
     315             :             }
     316          27 :             break;
     317             :             case libsumo::TL_RED_YELLOW_GREEN_STATE: {
     318             :                 std::string state;
     319          33 :                 if (!server.readTypeCheckingString(inputStorage, state)) {
     320           2 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The phase must be given as a string.", outputStorage);
     321             :                 }
     322          32 :                 libsumo::TrafficLight::setRedYellowGreenState(id, state);
     323             :             }
     324             :             break;
     325          45 :             case libsumo::TL_COMPLETE_PROGRAM_RYG: {
     326          45 :                 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
     327           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "A compound object is needed for setting a new program.", outputStorage);
     328             :                 }
     329             :                 //read itemNo
     330          45 :                 inputStorage.readInt();
     331             :                 libsumo::TraCILogic logic;
     332          45 :                 if (!server.readTypeCheckingString(inputStorage, logic.programID)) {
     333           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "set program: 1. parameter (programID) must be a string.", outputStorage);
     334             :                 }
     335          45 :                 if (!server.readTypeCheckingInt(inputStorage, logic.type)) {
     336           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "set program: 2. parameter (type) must be an int.", outputStorage);
     337             :                 }
     338          45 :                 if (!server.readTypeCheckingInt(inputStorage, logic.currentPhaseIndex)) {
     339           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "set program: 3. parameter (index) must be an int.", outputStorage);
     340             :                 }
     341          45 :                 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
     342           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "A compound object is needed for the phases.", outputStorage);
     343             :                 }
     344          45 :                 const int numPhases = inputStorage.readInt();
     345         219 :                 for (int j = 0; j < numPhases; ++j) {
     346         174 :                     if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
     347           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "A compound object is needed for every phase.", outputStorage);
     348             :                     }
     349         174 :                     const int items = inputStorage.readInt();
     350         174 :                     if (items != 6 && items != 5) {
     351           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "A phase compound object requires 5 or 6 items.", outputStorage);
     352             :                     }
     353         174 :                     double duration = 0., minDuration = 0., maxDuration = 0.;
     354             :                     std::vector<int> next;
     355             :                     std::string name;
     356         174 :                     if (!server.readTypeCheckingDouble(inputStorage, duration)) {
     357           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "set program: 4.1. parameter (duration) must be a double.", outputStorage);
     358             :                     }
     359             :                     std::string state;
     360         174 :                     if (!server.readTypeCheckingString(inputStorage, state)) {
     361           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "set program: 4.2. parameter (phase) must be a string.", outputStorage);
     362             :                     }
     363         174 :                     if (!server.readTypeCheckingDouble(inputStorage, minDuration)) {
     364           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "set program: 4.3. parameter (min duration) must be a double.", outputStorage);
     365             :                     }
     366         174 :                     if (!server.readTypeCheckingDouble(inputStorage, maxDuration)) {
     367           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "set program: 4.4. parameter (max duration) must be a double.", outputStorage);
     368             :                     }
     369         174 :                     if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
     370           0 :                         return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "set program 4.5 parameter (next) must be a compound (list of ints).", outputStorage);
     371             :                     }
     372         174 :                     const int numNext = inputStorage.readInt();
     373         186 :                     for (int k = 0; k < numNext; k++) {
     374             :                         int nextEntry;
     375          12 :                         if (!server.readTypeCheckingInt(inputStorage, nextEntry)) {
     376           0 :                             return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "set program: 4.5. parameter (next) must be a list of int.", outputStorage);
     377             :                         }
     378          12 :                         next.push_back(nextEntry);
     379             :                     }
     380         174 :                     if (items == 6) {
     381         156 :                         if (!server.readTypeCheckingString(inputStorage, name)) {
     382           0 :                             return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "set program: 4.6. parameter (name) must be a string.", outputStorage);
     383             :                         }
     384             :                     }
     385         174 :                     logic.phases.emplace_back(new libsumo::TraCIPhase(duration, state, minDuration, maxDuration, next, name));
     386             :                 }
     387          45 :                 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
     388           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "set program: 5. parameter (subparams) must be a compound object.", outputStorage);
     389             :                 }
     390          45 :                 const int numParams = inputStorage.readInt();
     391          45 :                 for (int j = 0; j < numParams; j++) {
     392             :                     std::vector<std::string> par;
     393           0 :                     server.readTypeCheckingStringList(inputStorage, par);
     394           0 :                     logic.subParameter[par[0]] = par[1];
     395           0 :                 }
     396             :                 libsumo::TrafficLight::setCompleteRedYellowGreenDefinition(id, logic);
     397          45 :             }
     398             :             break;
     399          20 :             case libsumo::TL_CONSTRAINT_REMOVE: {
     400          20 :                 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
     401           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "A compound object is needed for removing constraints.", outputStorage);
     402             :                 }
     403             :                 //read itemNo
     404          20 :                 inputStorage.readInt();
     405             :                 std::string tripId;
     406          20 :                 if (!server.readTypeCheckingString(inputStorage, tripId)) {
     407           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The tripId must be given as a string.", outputStorage);
     408             :                 }
     409             :                 std::string foeSignal;
     410          20 :                 if (!server.readTypeCheckingString(inputStorage, foeSignal)) {
     411           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The foeSignal id must be given as a string.", outputStorage);
     412             :                 }
     413             :                 std::string foeId;
     414          20 :                 if (!server.readTypeCheckingString(inputStorage, foeId)) {
     415           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The foe tripId must be given as a string.", outputStorage);
     416             :                 }
     417          20 :                 libsumo::TrafficLight::removeConstraints(id, tripId, foeSignal, foeId);
     418             :             }
     419             :             break;
     420             :             case libsumo::TL_CONSTRAINT_UPDATE: {
     421             :                 std::string tripId;
     422           3 :                 if (!server.readTypeCheckingString(inputStorage, tripId)) {
     423           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The tripId index must be given as a string.", outputStorage);
     424             :                 }
     425           6 :                 libsumo::TrafficLight::updateConstraints(id, tripId);
     426             :             }
     427             :             break;
     428           4 :             case libsumo::TL_CONSTRAINT_ADD: {
     429           4 :                 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
     430           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "A compound object is needed for adding constraints.", outputStorage);
     431             :                 }
     432             :                 //read itemNo
     433           4 :                 inputStorage.readInt();
     434             :                 std::string tripId;
     435           4 :                 if (!server.readTypeCheckingString(inputStorage, tripId)) {
     436           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The tripId must be given as a string.", outputStorage);
     437             :                 }
     438             :                 std::string foeSignal;
     439           4 :                 if (!server.readTypeCheckingString(inputStorage, foeSignal)) {
     440           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The foe signal must be given as a string.", outputStorage);
     441             :                 }
     442             :                 std::string foeId;
     443           4 :                 if (!server.readTypeCheckingString(inputStorage, foeId)) {
     444           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The foe tripId must be given as a string.", outputStorage);
     445             :                 }
     446             :                 int type;
     447           4 :                 if (!server.readTypeCheckingInt(inputStorage, type)) {
     448           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The type must be an int.", outputStorage);
     449             :                 }
     450             :                 int limit;
     451           4 :                 if (!server.readTypeCheckingInt(inputStorage, limit)) {
     452           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The limit must be an int.", outputStorage);
     453             :                 }
     454           4 :                 libsumo::TrafficLight::addConstraint(id, tripId, foeSignal, foeId, type, limit);
     455             :             }
     456             :             break;
     457         107 :             case libsumo::VAR_PARAMETER: {
     458         107 :                 if (inputStorage.readUnsignedByte() != libsumo::TYPE_COMPOUND) {
     459           0 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "A compound object is needed for setting a parameter.", outputStorage);
     460             :                 }
     461             :                 //read itemNo
     462         107 :                 inputStorage.readInt();
     463             :                 std::string name;
     464         107 :                 if (!server.readTypeCheckingString(inputStorage, name)) {
     465           4 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The name of the parameter must be given as a string.", outputStorage);
     466             :                 }
     467             :                 std::string value;
     468         107 :                 if (!server.readTypeCheckingString(inputStorage, value)) {
     469           4 :                     return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, "The value of the parameter must be given as a string.", outputStorage);
     470             :                 }
     471         107 :                 libsumo::TrafficLight::setParameter(id, name, value);
     472             :             }
     473             :             break;
     474             :             default:
     475             :                 break;
     476             :         }
     477           9 :     } catch (libsumo::TraCIException& e) {
     478           9 :         return server.writeErrorStatusCmd(libsumo::CMD_SET_TL_VARIABLE, e.what(), outputStorage);
     479           9 :     }
     480        3529 :     server.writeStatusCmd(libsumo::CMD_SET_TL_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);
     481             :     return true;
     482             : }
     483             : 
     484             : 
     485             : void
     486         890 : TraCIServerAPI_TrafficLight::writeConstraint(TraCIServer& server, const libsumo::TraCISignalConstraint& c) {
     487         890 :     StoHelp::writeTypedString(server.getWrapperStorage(), c.signalId);
     488         890 :     StoHelp::writeTypedString(server.getWrapperStorage(), c.tripId);
     489         890 :     StoHelp::writeTypedString(server.getWrapperStorage(), c.foeId);
     490         890 :     StoHelp::writeTypedString(server.getWrapperStorage(), c.foeSignal);
     491         890 :     StoHelp::writeTypedInt(server.getWrapperStorage(), c.limit);
     492         890 :     StoHelp::writeTypedInt(server.getWrapperStorage(), c.type);
     493         890 :     StoHelp::writeTypedByte(server.getWrapperStorage(), c.mustWait);
     494         890 :     StoHelp::writeTypedByte(server.getWrapperStorage(), c.active);
     495             :     std::vector<std::string> paramItems;
     496        1338 :     for (auto item : c.param) {
     497         448 :         paramItems.push_back(item.first);
     498         448 :         paramItems.push_back(item.second);
     499         448 :     }
     500         890 :     StoHelp::writeTypedStringList(server.getWrapperStorage(), paramItems);
     501         890 : }
     502             : 
     503             : 
     504             : /****************************************************************************/

Generated by: LCOV version 1.14