SUMO - Simulation of Urban MObility
TraCIServerAPI_Junction.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2009-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
21 // APIs for getting/setting junction values via TraCI
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #ifndef NO_TRACI
35 
37 #include "TraCIServer.h"
38 #include <libsumo/Junction.h>
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
45 bool
47  tcpip::Storage& outputStorage) {
48  // variable
49  int variable = inputStorage.readUnsignedByte();
50  std::string id = inputStorage.readString();
51  // check variable
52  if (variable != ID_LIST && variable != VAR_POSITION && variable != ID_COUNT && variable != VAR_SHAPE) {
53  return server.writeErrorStatusCmd(CMD_GET_JUNCTION_VARIABLE, "Get Junction Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
54  }
55  // begin response building
56  tcpip::Storage tempMsg;
57  // response-code, variableID, objectID
59  tempMsg.writeUnsignedByte(variable);
60  tempMsg.writeString(id);
61 
62  try {
63  switch (variable) {
64  case ID_LIST:
67  break;
68  case ID_COUNT:
71  break;
72  case VAR_POSITION: {
75  tempMsg.writeDouble(p.x);
76  tempMsg.writeDouble(p.y);
77  break;
78  }
79  case VAR_SHAPE: {
82  tempMsg.writeUnsignedByte(MIN2(255, (int) shp.size()));
83  for (int iPoint = 0; iPoint < MIN2(255, (int) shp.size()); ++iPoint) {
84  tempMsg.writeDouble(shp[iPoint].x);
85  tempMsg.writeDouble(shp[iPoint].y);
86  }
87  break;
88  }
89  default:
90  break;
91 
92  }
93  } catch (libsumo::TraCIException& e) {
94  return server.writeErrorStatusCmd(CMD_GET_JUNCTION_VARIABLE, e.what(), outputStorage);
95  }
96  server.writeStatusCmd(CMD_GET_JUNCTION_VARIABLE, RTYPE_OK, "", outputStorage);
97  server.writeResponseWithLength(outputStorage, tempMsg);
98 
99  return true;
100 }
101 
102 bool
103 TraCIServerAPI_Junction::getPosition(const std::string& id, Position& p) {
105  if (j == 0) {
106  return false;
107  }
108  p = j->getPosition();
109  return true;
110 }
111 
112 
113 #endif
114 
115 
116 /****************************************************************************/
117 
static int getIDCount()
Definition: Junction.cpp:54
#define POSITION_2D
#define VAR_POSITION
The base class for an intersection.
Definition: MSJunction.h:64
#define RTYPE_OK
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa9: Get Junction Variable)
#define TYPE_POLYGON
static TraCIPosition getPosition(const std::string &junctionID)
Definition: Junction.cpp:59
#define TYPE_STRINGLIST
virtual void writeUnsignedByte(int)
bool writeErrorStatusCmd(int commandId, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage with status = RTYPE_ERR.
#define VAR_SHAPE
virtual void writeInt(int)
virtual int readUnsignedByte()
static MSJunction * getJunction(const std::string &id)
Definition: Junction.cpp:69
static TraCIPositionVector getShape(const std::string &junctionID)
Definition: Junction.cpp:64
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
virtual void writeStringList(const std::vector< std::string > &s)
T MIN2(T a, T b)
Definition: StdDefs.h:67
const Position & getPosition() const
Definition: MSJunction.cpp:62
virtual std::string readString()
#define CMD_GET_JUNCTION_VARIABLE
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:69
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
virtual void writeString(const std::string &s)
std::string toHex(const T i, std::streamsize numDigits=0)
Definition: ToString.h:65
std::vector< TraCIPosition > TraCIPositionVector
Definition: TraCIDefs.h:85
static bool getPosition(const std::string &id, Position &p)
Returns the named junction&#39;s position.
#define RESPONSE_GET_JUNCTION_VARIABLE
virtual void writeDouble(double)
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
#define ID_COUNT
A 3D-position.
Definition: TraCIDefs.h:71
#define TYPE_INTEGER
#define ID_LIST
static std::vector< std::string > getIDList()
Definition: Junction.cpp:47