![]() |
SUMO - Simulation of Urban MObility
|
C++ TraCI client API implementation. More...
#include <TraCIAPI.h>
Data Structures | |
class | EdgeScope |
Scope for interaction with edges. More... | |
class | GUIScope |
Scope for interaction with the gui. More... | |
class | InductionLoopScope |
Scope for interaction with inductive loops. More... | |
class | JunctionScope |
Scope for interaction with junctions. More... | |
class | LaneAreaScope |
Scope for interaction with lane area detectors. More... | |
class | LaneScope |
Scope for interaction with lanes. More... | |
class | MeMeScope |
Scope for interaction with multi entry/-exit detectors. More... | |
class | PersonScope |
Scope for interaction with vehicles. More... | |
class | POIScope |
Scope for interaction with POIs. More... | |
class | PolygonScope |
Scope for interaction with polygons. More... | |
class | RouteScope |
Scope for interaction with routes. More... | |
class | SimulationScope |
Scope for interaction with the simulation. More... | |
class | TraCIScopeWrapper |
An abstract interface for accessing type-dependent values. More... | |
class | TrafficLightScope |
Scope for interaction with traffic lights. More... | |
class | VehicleScope |
Scope for interaction with vehicles. More... | |
class | VehicleTypeScope |
Scope for interaction with vehicle types. More... | |
Public Member Functions | |
void | load (const std::vector< std::string > &args) |
Let sumo load a simulation using the given command line like options. More... | |
void | simulationStep (double time=0) |
Advances by one step (or up to the given time) More... | |
TraCIAPI () | |
Constructor. More... | |
~TraCIAPI () | |
Destructor. More... | |
Connection handling | |
void | connect (const std::string &host, int port) |
Connects to the specified SUMO server. More... | |
void | setOrder (int order) |
set priority (execution order) for the client More... | |
void | close () |
ends the simulation and closes the connection More... | |
Atomar getter | |
int | getUnsignedByte (int cmd, int var, const std::string &id, tcpip::Storage *add=0) |
int | getByte (int cmd, int var, const std::string &id, tcpip::Storage *add=0) |
int | getInt (int cmd, int var, const std::string &id, tcpip::Storage *add=0) |
double | getDouble (int cmd, int var, const std::string &id, tcpip::Storage *add=0) |
libsumo::TraCIPositionVector | getPolygon (int cmd, int var, const std::string &id, tcpip::Storage *add=0) |
libsumo::TraCIPosition | getPosition (int cmd, int var, const std::string &id, tcpip::Storage *add=0) |
libsumo::TraCIPosition | getPosition3D (int cmd, int var, const std::string &id, tcpip::Storage *add=0) |
std::string | getString (int cmd, int var, const std::string &id, tcpip::Storage *add=0) |
std::vector< std::string > | getStringVector (int cmd, int var, const std::string &id, tcpip::Storage *add=0) |
libsumo::TraCIColor | getColor (int cmd, int var, const std::string &id, tcpip::Storage *add=0) |
Data Fields | |
EdgeScope | edge |
Scope for interaction with edges. More... | |
GUIScope | gui |
Scope for interaction with the gui. More... | |
InductionLoopScope | inductionloop |
Scope for interaction with inductive loops. More... | |
JunctionScope | junction |
Scope for interaction with junctions. More... | |
LaneScope | lane |
Scope for interaction with lanes. More... | |
LaneAreaScope | lanearea |
Scope for interaction with lanes. More... | |
MeMeScope | multientryexit |
Scope for interaction with multi-entry/-exit detectors. More... | |
PersonScope | person |
Scope for interaction with persons. More... | |
POIScope | poi |
Scope for interaction with POIs. More... | |
PolygonScope | polygon |
Scope for interaction with polygons. More... | |
RouteScope | route |
Scope for interaction with routes. More... | |
SimulationScope | simulation |
Scope for interaction with the simulation. More... | |
TrafficLightScope | trafficlights |
Scope for interaction with traffic lights. More... | |
VehicleScope | vehicle |
Scope for interaction with vehicles. More... | |
VehicleTypeScope | vehicletype |
Scope for interaction with vehicle types. More... | |
Protected Member Functions | |
void | closeSocket () |
Closes the connection. More... | |
void | readContextSubscription (int cmdId, tcpip::Storage &inMsg) |
void | readVariables (tcpip::Storage &inMsg, const std::string &objectID, int variableCount, libsumo::SubscriptionResults &into) |
void | readVariableSubscription (int cmdId, tcpip::Storage &inMsg) |
void | send_commandMoveToXY (const std::string &vehicleID, const std::string &edgeID, const int lane, const double x, const double y, const double angle, const int keepRoute) const |
Command sending methods | |
void | send_commandSimulationStep (double time) const |
Sends a SimulationStep command. More... | |
void | send_commandClose () const |
Sends a Close command. More... | |
void | send_commandSetOrder (int order) const |
Sends a SetOrder command. More... | |
void | send_commandGetVariable (int domID, int varID, const std::string &objID, tcpip::Storage *add=0) const |
Sends a GetVariable request. More... | |
void | send_commandSetValue (int domID, int varID, const std::string &objID, tcpip::Storage &content) const |
Sends a SetVariable request. More... | |
void | send_commandSubscribeObjectVariable (int domID, const std::string &objID, double beginTime, double endTime, const std::vector< int > &vars) const |
Sends a SubscribeVariable request. More... | |
void | send_commandSubscribeObjectContext (int domID, const std::string &objID, double beginTime, double endTime, int domain, double range, const std::vector< int > &vars) const |
Sends a SubscribeContext request. More... | |
void | check_resultState (tcpip::Storage &inMsg, int command, bool ignoreCommandId=false, std::string *acknowledgement=0) const |
Validates the result state of a command. More... | |
int | check_commandGetResult (tcpip::Storage &inMsg, int command, int expectedType=-1, bool ignoreCommandId=false) const |
Validates the result state of a command. More... | |
void | processGET (tcpip::Storage &inMsg, int command, int expectedType, bool ignoreCommandId=false) const |
Static Protected Member Functions | |
template<class T > | |
static std::string | toString (const T &t, std::streamsize accuracy=PRECISION) |
Protected Attributes | |
std::map< int, TraCIScopeWrapper * > | myDomains |
tcpip::Socket * | mySocket |
The socket. More... | |
C++ TraCI client API implementation.
Definition at line 52 of file TraCIAPI.h.
TraCIAPI::TraCIAPI | ( | ) |
Constructor.
Definition at line 41 of file TraCIAPI.cpp.
References edge, gui, junction, lane, lanearea, multientryexit, myDomains, person, poi, polygon, RESPONSE_SUBSCRIBE_EDGE_VARIABLE, RESPONSE_SUBSCRIBE_GUI_VARIABLE, RESPONSE_SUBSCRIBE_JUNCTION_VARIABLE, RESPONSE_SUBSCRIBE_LANE_VARIABLE, RESPONSE_SUBSCRIBE_LANEAREA_VARIABLE, RESPONSE_SUBSCRIBE_MULTIENTRYEXIT_VARIABLE, RESPONSE_SUBSCRIBE_PERSON_VARIABLE, RESPONSE_SUBSCRIBE_POI_VARIABLE, RESPONSE_SUBSCRIBE_POLYGON_VARIABLE, RESPONSE_SUBSCRIBE_ROUTE_VARIABLE, RESPONSE_SUBSCRIBE_SIM_VARIABLE, RESPONSE_SUBSCRIBE_TL_VARIABLE, RESPONSE_SUBSCRIBE_VEHICLE_VARIABLE, RESPONSE_SUBSCRIBE_VEHICLETYPE_VARIABLE, route, simulation, trafficlights, vehicle, and vehicletype.
TraCIAPI::~TraCIAPI | ( | ) |
|
protected |
Validates the result state of a command.
Definition at line 325 of file TraCIAPI.cpp.
References tcpip::Storage::position(), tcpip::Storage::readInt(), tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), and toString().
Referenced by TraCITestClient::commandGetVariable(), processGET(), and simulationStep().
|
protected |
Validates the result state of a command.
[in] | inMsg | The buffer to read the message from |
[in] | command | The original command id |
[in] | ignoreCommandId | Whether the returning command id shall be validated |
[in] | acknowledgement | Pointer to an existing string into which the acknowledgement message shall be inserted |
Definition at line 286 of file TraCIAPI.cpp.
References mySocket, tcpip::Storage::position(), tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), tcpip::Socket::receiveExact(), RTYPE_ERR, RTYPE_NOTIMPLEMENTED, RTYPE_OK, and toString().
Referenced by close(), TraCITestClient::commandClose(), TraCITestClient::commandGetVariable(), TraCITestClient::commandSetOrder(), TraCITestClient::commandSetValue(), TraCITestClient::commandSimulationStep(), TraCITestClient::commandSubscribeContextVariable(), TraCITestClient::commandSubscribeObjectVariable(), load(), processGET(), setOrder(), and simulationStep().
void TraCIAPI::close | ( | ) |
ends the simulation and closes the connection
Definition at line 102 of file TraCIAPI.cpp.
References check_resultState(), closeSocket(), CMD_CLOSE, and send_commandClose().
|
protected |
Closes the connection.
Definition at line 112 of file TraCIAPI.cpp.
References tcpip::Socket::close(), and mySocket.
Referenced by close(), TraCITestClient::run(), and toString().
void TraCIAPI::connect | ( | const std::string & | host, |
int | port | ||
) |
Connects to the specified SUMO server.
[in] | host | The name of the host to connect to |
[in] | port | The port to connect to |
tcpip::SocketException | if the connection fails |
Definition at line 74 of file TraCIAPI.cpp.
References tcpip::Socket::connect(), and mySocket.
Referenced by TraCITestClient::run().
int TraCIAPI::getByte | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 365 of file TraCIAPI.cpp.
References processGET(), tcpip::Storage::readByte(), send_commandGetVariable(), and TYPE_BYTE.
libsumo::TraCIColor TraCIAPI::getColor | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 462 of file TraCIAPI.cpp.
References libsumo::TraCIColor::a, libsumo::TraCIColor::b, libsumo::TraCIColor::g, processGET(), libsumo::TraCIColor::r, tcpip::Storage::readUnsignedByte(), send_commandGetVariable(), and TYPE_COLOR.
Referenced by TraCIAPI::PersonScope::~PersonScope(), TraCIAPI::POIScope::~POIScope(), TraCIAPI::PolygonScope::~PolygonScope(), and TraCIAPI::VehicleTypeScope::~VehicleTypeScope().
double TraCIAPI::getDouble | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 383 of file TraCIAPI.cpp.
References processGET(), tcpip::Storage::readDouble(), send_commandGetVariable(), and TYPE_DOUBLE.
int TraCIAPI::getInt | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 374 of file TraCIAPI.cpp.
References processGET(), tcpip::Storage::readInt(), send_commandGetVariable(), and TYPE_INTEGER.
libsumo::TraCIPositionVector TraCIAPI::getPolygon | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 392 of file TraCIAPI.cpp.
References processGET(), tcpip::Storage::readDouble(), tcpip::Storage::readInt(), tcpip::Storage::readUnsignedByte(), send_commandGetVariable(), TYPE_POLYGON, libsumo::TraCIPosition::x, libsumo::TraCIPosition::y, and libsumo::TraCIPosition::z.
libsumo::TraCIPosition TraCIAPI::getPosition | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 413 of file TraCIAPI.cpp.
References POSITION_2D, processGET(), tcpip::Storage::readDouble(), send_commandGetVariable(), libsumo::TraCIPosition::x, libsumo::TraCIPosition::y, and libsumo::TraCIPosition::z.
Referenced by TraCIAPI::InductionLoopScope::~InductionLoopScope(), TraCIAPI::JunctionScope::~JunctionScope(), TraCIAPI::PersonScope::~PersonScope(), and TraCIAPI::POIScope::~POIScope().
libsumo::TraCIPosition TraCIAPI::getPosition3D | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 426 of file TraCIAPI.cpp.
References POSITION_3D, processGET(), tcpip::Storage::readDouble(), send_commandGetVariable(), libsumo::TraCIPosition::x, libsumo::TraCIPosition::y, and libsumo::TraCIPosition::z.
Referenced by TraCIAPI::PersonScope::~PersonScope().
std::string TraCIAPI::getString | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 439 of file TraCIAPI.cpp.
References processGET(), tcpip::Storage::readString(), send_commandGetVariable(), and TYPE_STRING.
std::vector< std::string > TraCIAPI::getStringVector | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 448 of file TraCIAPI.cpp.
References processGET(), tcpip::Storage::readInt(), tcpip::Storage::readString(), send_commandGetVariable(), and TYPE_STRINGLIST.
int TraCIAPI::getUnsignedByte | ( | int | cmd, |
int | var, | ||
const std::string & | id, | ||
tcpip::Storage * | add = 0 |
||
) |
Definition at line 356 of file TraCIAPI.cpp.
References processGET(), tcpip::Storage::readUnsignedByte(), send_commandGetVariable(), and TYPE_UBYTE.
void TraCIAPI::load | ( | const std::vector< std::string > & | args | ) |
Let sumo load a simulation using the given command line like options.
Definition at line 589 of file TraCIAPI.cpp.
References check_resultState(), CMD_LOAD, mySocket, tcpip::Socket::sendExact(), TYPE_STRINGLIST, tcpip::Storage::writeInt(), tcpip::Storage::writeStringList(), and tcpip::Storage::writeUnsignedByte().
Referenced by TraCITestClient::testAPI().
|
protected |
Definition at line 349 of file TraCIAPI.cpp.
References check_commandGetResult(), and check_resultState().
Referenced by getByte(), getColor(), getDouble(), getInt(), getPolygon(), getPosition(), getPosition3D(), getString(), getStringVector(), and getUnsignedByte().
|
protected |
Definition at line 552 of file TraCIAPI.cpp.
References myDomains, tcpip::Storage::readInt(), tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), and readVariables().
Referenced by simulationStep().
|
protected |
Definition at line 476 of file TraCIAPI.cpp.
References POSITION_2D, POSITION_3D, tcpip::Storage::readDouble(), tcpip::Storage::readInt(), tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), RTYPE_OK, toString(), TYPE_COLOR, TYPE_DOUBLE, TYPE_INTEGER, TYPE_STRING, and TYPE_STRINGLIST.
Referenced by readContextSubscription(), and readVariableSubscription().
|
protected |
Definition at line 544 of file TraCIAPI.cpp.
References myDomains, tcpip::Storage::readString(), tcpip::Storage::readUnsignedByte(), and readVariables().
Referenced by simulationStep().
|
protected |
Sends a Close command.
Definition at line 136 of file TraCIAPI.cpp.
References CMD_CLOSE, mySocket, tcpip::Socket::sendExact(), and tcpip::Storage::writeUnsignedByte().
Referenced by close(), and TraCITestClient::commandClose().
|
protected |
Sends a GetVariable request.
[in] | domID | The domain of the variable |
[in] | varID | The variable to retrieve |
[in] | objID | The object to retrieve the variable from |
[in] | add | Optional additional parameter |
Definition at line 160 of file TraCIAPI.cpp.
References mySocket, tcpip::Socket::sendExact(), tcpip::Storage::size(), tcpip::Storage::writeStorage(), tcpip::Storage::writeString(), and tcpip::Storage::writeUnsignedByte().
Referenced by TraCITestClient::commandGetVariable(), getByte(), getColor(), getDouble(), getInt(), getPolygon(), getPosition(), getPosition3D(), getString(), getStringVector(), and getUnsignedByte().
|
protected |
Definition at line 266 of file TraCIAPI.cpp.
References CMD_SET_VEHICLE_VARIABLE, MOVE_TO_XY, send_commandSetValue(), TYPE_BYTE, TYPE_COMPOUND, TYPE_DOUBLE, TYPE_INTEGER, TYPE_STRING, tcpip::Storage::writeByte(), tcpip::Storage::writeDouble(), tcpip::Storage::writeInt(), tcpip::Storage::writeString(), and tcpip::Storage::writeUnsignedByte().
|
protected |
Sends a SetOrder command.
Definition at line 147 of file TraCIAPI.cpp.
References CMD_SETORDER, mySocket, tcpip::Socket::sendExact(), tcpip::Storage::writeInt(), and tcpip::Storage::writeUnsignedByte().
Referenced by TraCITestClient::commandSetOrder().
|
protected |
Sends a SetVariable request.
[in] | domID | The domain of the variable |
[in] | varID | The variable to set |
[in] | objID | The object to change |
[in] | content | The value of the variable |
Definition at line 187 of file TraCIAPI.cpp.
References mySocket, tcpip::Socket::sendExact(), tcpip::Storage::size(), tcpip::Storage::writeStorage(), tcpip::Storage::writeString(), and tcpip::Storage::writeUnsignedByte().
Referenced by TraCITestClient::commandSetValue(), and send_commandMoveToXY().
|
protected |
Sends a SimulationStep command.
Definition at line 123 of file TraCIAPI.cpp.
References CMD_SIMSTEP, mySocket, tcpip::Socket::sendExact(), tcpip::Storage::writeDouble(), and tcpip::Storage::writeUnsignedByte().
Referenced by TraCITestClient::commandSimulationStep(), and simulationStep().
|
protected |
Sends a SubscribeContext request.
[in] | domID | The domain of the variable |
[in] | objID | The object to subscribe the variables from |
[in] | beginTime | The begin time step of subscriptions |
[in] | endTime | The end time step of subscriptions |
[in] | domain | The domain of the objects which values shall be returned |
[in] | range | The range around the obj to investigate |
[in] | vars | The variables to subscribe |
Definition at line 236 of file TraCIAPI.cpp.
References mySocket, tcpip::Socket::sendExact(), tcpip::Storage::size(), tcpip::Storage::writeDouble(), tcpip::Storage::writeInt(), tcpip::Storage::writeString(), and tcpip::Storage::writeUnsignedByte().
Referenced by TraCITestClient::commandSubscribeContextVariable().
|
protected |
Sends a SubscribeVariable request.
[in] | domID | The domain of the variable |
[in] | objID | The object to subscribe the variables from |
[in] | beginTime | The begin time step of subscriptions |
[in] | endTime | The end time step of subscriptions |
[in] | vars | The variables to subscribe |
Definition at line 208 of file TraCIAPI.cpp.
References mySocket, tcpip::Socket::sendExact(), tcpip::Storage::size(), tcpip::Storage::writeDouble(), tcpip::Storage::writeInt(), tcpip::Storage::writeString(), and tcpip::Storage::writeUnsignedByte().
Referenced by TraCITestClient::commandSubscribeObjectVariable().
void TraCIAPI::setOrder | ( | int | order | ) |
set priority (execution order) for the client
Definition at line 87 of file TraCIAPI.cpp.
References check_resultState(), CMD_SETORDER, mySocket, tcpip::Socket::sendExact(), tcpip::Storage::writeInt(), and tcpip::Storage::writeUnsignedByte().
Referenced by TraCITestClient::testAPI().
void TraCIAPI::simulationStep | ( | double | time = 0 | ) |
Advances by one step (or up to the given time)
Definition at line 567 of file TraCIAPI.cpp.
References check_commandGetResult(), check_resultState(), CMD_SIMSTEP, myDomains, readContextSubscription(), tcpip::Storage::readInt(), readVariableSubscription(), RESPONSE_SUBSCRIBE_INDUCTIONLOOP_VARIABLE, RESPONSE_SUBSCRIBE_PERSON_VARIABLE, and send_commandSimulationStep().
Referenced by TraCITestClient::testAPI().
|
inlinestaticprotected |
Definition at line 972 of file TraCIAPI.h.
References closeSocket().
Referenced by TraCIAPI::VehicleScope::add(), check_commandGetResult(), check_resultState(), and readVariables().
EdgeScope TraCIAPI::edge |
Scope for interaction with edges.
Definition at line 853 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
GUIScope TraCIAPI::gui |
Scope for interaction with the gui.
Definition at line 855 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
InductionLoopScope TraCIAPI::inductionloop |
Scope for interaction with inductive loops.
Definition at line 857 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI().
JunctionScope TraCIAPI::junction |
Scope for interaction with junctions.
Definition at line 859 of file TraCIAPI.h.
Referenced by TraCIAPI().
LaneScope TraCIAPI::lane |
Scope for interaction with lanes.
Definition at line 861 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
LaneAreaScope TraCIAPI::lanearea |
Scope for interaction with lanes.
Definition at line 863 of file TraCIAPI.h.
Referenced by TraCIAPI().
MeMeScope TraCIAPI::multientryexit |
Scope for interaction with multi-entry/-exit detectors.
Definition at line 865 of file TraCIAPI.h.
Referenced by TraCIAPI().
|
protected |
Definition at line 984 of file TraCIAPI.h.
Referenced by readContextSubscription(), readVariableSubscription(), simulationStep(), and TraCIAPI().
|
protected |
The socket.
Definition at line 986 of file TraCIAPI.h.
Referenced by check_resultState(), closeSocket(), connect(), load(), send_commandClose(), send_commandGetVariable(), send_commandSetOrder(), send_commandSetValue(), send_commandSimulationStep(), send_commandSubscribeObjectContext(), send_commandSubscribeObjectVariable(), setOrder(), and ~TraCIAPI().
PersonScope TraCIAPI::person |
Scope for interaction with persons.
Definition at line 867 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
POIScope TraCIAPI::poi |
Scope for interaction with POIs.
Definition at line 869 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
PolygonScope TraCIAPI::polygon |
Scope for interaction with polygons.
Definition at line 871 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
RouteScope TraCIAPI::route |
Scope for interaction with routes.
Definition at line 873 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
SimulationScope TraCIAPI::simulation |
Scope for interaction with the simulation.
Definition at line 875 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
TrafficLightScope TraCIAPI::trafficlights |
Scope for interaction with traffic lights.
Definition at line 877 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
VehicleScope TraCIAPI::vehicle |
Scope for interaction with vehicles.
Definition at line 879 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().
VehicleTypeScope TraCIAPI::vehicletype |
Scope for interaction with vehicle types.
Definition at line 881 of file TraCIAPI.h.
Referenced by TraCITestClient::testAPI(), and TraCIAPI().