Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2001-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 Command_SaveTLSSwitchStates.cpp 15 : /// @author Daniel Krajzewicz 16 : /// @author Michael Behrisch 17 : /// @date 08.05.2007 18 : /// 19 : // Writes the switch times of a tls into a file when the tls switches 20 : /****************************************************************************/ 21 : #include <config.h> 22 : 23 : #include "Command_SaveTLSSwitchStates.h" 24 : #include <microsim/traffic_lights/MSTrafficLightLogic.h> 25 : #include <microsim/MSEventControl.h> 26 : #include <microsim/MSNet.h> 27 : #include <utils/common/UtilExceptions.h> 28 : #include <utils/common/MsgHandler.h> 29 : #include <utils/iodevices/OutputDevice.h> 30 : 31 : 32 : // =========================================================================== 33 : // method definitions 34 : // =========================================================================== 35 533 : Command_SaveTLSSwitchStates::Command_SaveTLSSwitchStates(const MSTLLogicControl::TLSLogicVariants& logics, 36 533 : OutputDevice& od) 37 533 : : myOutputDevice(od), myLogics(logics) { 38 533 : MSNet::getInstance()->getEndOfTimestepEvents()->addEvent(this); 39 1599 : myOutputDevice.writeXMLHeader("tlsStates", "tlsstates_file.xsd"); 40 533 : } 41 : 42 : 43 1062 : Command_SaveTLSSwitchStates::~Command_SaveTLSSwitchStates() { 44 1062 : } 45 : 46 : 47 : SUMOTime 48 3295649 : Command_SaveTLSSwitchStates::execute(SUMOTime currentTime) { 49 3295649 : const std::string& state = myLogics.getActive()->getCurrentPhaseDef().getState(); 50 3295649 : if (state != myPreviousState || myLogics.getActive()->getProgramID() != myPreviousProgramID) { 51 52899 : myOutputDevice.openTag("tlsState"); 52 52899 : myOutputDevice.writeAttr(SUMO_ATTR_TIME, time2string(currentTime)); 53 52899 : myOutputDevice.writeAttr(SUMO_ATTR_ID, myLogics.getActive()->getID()); 54 52899 : myOutputDevice.writeAttr(SUMO_ATTR_PROGRAMID, myLogics.getActive()->getProgramID()); 55 52899 : myOutputDevice.writeAttr(SUMO_ATTR_PHASE, myLogics.getActive()->getCurrentPhaseIndex()); 56 52899 : myOutputDevice.writeAttr(SUMO_ATTR_STATE, myLogics.getActive()->getCurrentPhaseDef().getState()); 57 52899 : if (!myLogics.getActive()->getCurrentPhaseDef().getName().empty()) { 58 3537 : myOutputDevice.writeAttr(SUMO_ATTR_NAME, myLogics.getActive()->getCurrentPhaseDef().getName()); 59 : } 60 105798 : myOutputDevice.closeTag(); 61 : myPreviousState = state; 62 52899 : myPreviousProgramID = myLogics.getActive()->getProgramID(); 63 : } 64 3295649 : return DELTA_T; 65 : } 66 : 67 : 68 : /****************************************************************************/