Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
Command_SaveTLSSwitchStates.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 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/****************************************************************************/
19// Writes the switch times of a tls into a file when the tls switches
20/****************************************************************************/
21#include <config.h>
22
26#include <microsim/MSNet.h>
30
31
32// ===========================================================================
33// method definitions
34// ===========================================================================
36 OutputDevice& od)
37 : myOutputDevice(od), myLogics(logics) {
39 myOutputDevice.writeXMLHeader("tlsStates", "tlsstates_file.xsd");
40}
41
42
45
46
49 const std::string& state = myLogics.getActive()->getCurrentPhaseDef().getState();
50 if (state != myPreviousState || myLogics.getActive()->getProgramID() != myPreviousProgramID) {
51 myOutputDevice.openTag("tlsState");
52 myOutputDevice.writeAttr(SUMO_ATTR_TIME, time2string(currentTime));
53 myOutputDevice.writeAttr(SUMO_ATTR_ID, myLogics.getActive()->getID());
54 myOutputDevice.writeAttr(SUMO_ATTR_PROGRAMID, myLogics.getActive()->getProgramID());
55 myOutputDevice.writeAttr(SUMO_ATTR_PHASE, myLogics.getActive()->getCurrentPhaseIndex());
56 myOutputDevice.writeAttr(SUMO_ATTR_STATE, myLogics.getActive()->getCurrentPhaseDef().getState());
57 if (!myLogics.getActive()->getCurrentPhaseDef().getName().empty()) {
58 myOutputDevice.writeAttr(SUMO_ATTR_NAME, myLogics.getActive()->getCurrentPhaseDef().getName());
59 }
60 myOutputDevice.closeTag();
61 myPreviousState = state;
62 myPreviousProgramID = myLogics.getActive()->getProgramID();
63 }
64 return DELTA_T;
65}
66
67
68/****************************************************************************/
long long int SUMOTime
Definition GUI.h:36
SUMOTime DELTA_T
Definition SUMOTime.cpp:38
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition SUMOTime.cpp:91
@ SUMO_ATTR_PHASE
@ SUMO_ATTR_NAME
@ SUMO_ATTR_ID
@ SUMO_ATTR_PROGRAMID
@ SUMO_ATTR_STATE
The state of a link.
@ SUMO_ATTR_TIME
trigger: the time of the step
std::string myPreviousState
Storage for prior state.
OutputDevice & myOutputDevice
The device to write to.
Command_SaveTLSSwitchStates(const MSTLLogicControl::TLSLogicVariants &logics, OutputDevice &od)
Constructor.
std::string myPreviousProgramID
Storage for prior sub-id.
const MSTLLogicControl::TLSLogicVariants & myLogics
The traffic light logic to use.
SUMOTime execute(SUMOTime currentTime)
Writes the state of the tls if a change occurred.
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition MSNet.cpp:186
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition MSNet.h:495
Storage for all programs of a single tls.
Static storage of an output device and its base (abstract) implementation.