Eclipse SUMO - Simulation of Urban MObility
Command_SaveTLSState.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
16 // Writes the state of the tls to a file (in each second)
17 /****************************************************************************/
18 // ===========================================================================
19 // included modules
20 // ===========================================================================
21 #include <config.h>
22 
23 #include "Command_SaveTLSState.h"
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 
44 }
45 
46 
49  myOutputDevice << " <tlsState time=\"" << time2string(currentTime)
50  << "\" id=\"" << myLogics.getActive()->getID()
51  << "\" programID=\"" << myLogics.getActive()->getProgramID()
52  << "\" phase=\"" << myLogics.getActive()->getCurrentPhaseIndex()
53  << "\" state=\"" << myLogics.getActive()->getCurrentPhaseDef().getState() << "\"/>\n";
54  return DELTA_T;
55 }
56 
57 
58 
59 /****************************************************************************/
MSEventControl::addEvent
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
Definition: MSEventControl.cpp:53
MSNet.h
OutputDevice
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:64
MSTrafficLightLogic::getProgramID
const std::string & getProgramID() const
Returns this tl-logic's id.
Definition: MSTrafficLightLogic.h:172
DELTA_T
SUMOTime DELTA_T
Definition: SUMOTime.cpp:35
MsgHandler.h
SUMOTime
long long int SUMOTime
Definition: SUMOTime.h:35
MSTrafficLightLogic::getCurrentPhaseIndex
virtual int getCurrentPhaseIndex() const =0
Returns the current index within the program.
Command_SaveTLSState::~Command_SaveTLSState
~Command_SaveTLSState()
Destructor.
Definition: Command_SaveTLSState.cpp:43
MSTLLogicControl::TLSLogicVariants::getActive
MSTrafficLightLogic * getActive() const
Definition: MSTLLogicControl.cpp:197
Command_SaveTLSState::Command_SaveTLSState
Command_SaveTLSState(const MSTLLogicControl::TLSLogicVariants &logics, OutputDevice &od)
Constructor.
Definition: Command_SaveTLSState.cpp:35
MSTrafficLightLogic.h
MSNet::getEndOfTimestepEvents
MSEventControl * getEndOfTimestepEvents()
Returns the event control for events executed at the end of a time step.
Definition: MSNet.h:440
MSPhaseDefinition::getState
const std::string & getState() const
Returns the state within this phase.
Definition: MSPhaseDefinition.h:200
OutputDevice.h
time2string
std::string time2string(SUMOTime t)
Definition: SUMOTime.cpp:65
UtilExceptions.h
MSNet::getInstance
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:168
Command_SaveTLSState::myOutputDevice
OutputDevice & myOutputDevice
The device to write to.
Definition: Command_SaveTLSState.h:79
Command_SaveTLSState.h
MSTLLogicControl::TLSLogicVariants
Storage for all programs of a single tls.
Definition: MSTLLogicControl.h:86
config.h
Command_SaveTLSState::execute
SUMOTime execute(SUMOTime currentTime)
Writes the current state of the tls.
Definition: Command_SaveTLSState.cpp:48
Command_SaveTLSState::myLogics
const MSTLLogicControl::TLSLogicVariants & myLogics
The traffic light logic to use.
Definition: Command_SaveTLSState.h:82
MSEventControl.h
OutputDevice::writeXMLHeader
bool writeXMLHeader(const std::string &rootElement, const std::string &schemaFile, std::map< SumoXMLAttr, std::string > attrs=std::map< SumoXMLAttr, std::string >())
Writes an XML header with optional configuration.
Definition: OutputDevice.cpp:228
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:77
MSTrafficLightLogic::getCurrentPhaseDef
virtual const MSPhaseDefinition & getCurrentPhaseDef() const =0
Returns the definition of the current phase.