SUMO - Simulation of Urban MObility
TraCIServerAPI_LaneArea.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2014-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 /****************************************************************************/
20 // APIs for getting/setting areal detector values via TraCI
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #ifndef NO_TRACI
34 
36 #include "TraCIConstants.h"
37 #include "TraCIServer.h"
38 #include <libsumo/LaneArea.h>
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
45 bool
47  tcpip::Storage& outputStorage) {
48  // variable & id
49  int variable = inputStorage.readUnsignedByte();
50  std::string id = inputStorage.readString();
51  // check variable
52  if (variable != ID_LIST
53  && variable != ID_COUNT
54  && variable != JAM_LENGTH_VEHICLE
55  && variable != JAM_LENGTH_METERS
56  && variable != LAST_STEP_VEHICLE_NUMBER
57  && variable != LAST_STEP_MEAN_SPEED
58  && variable != LAST_STEP_VEHICLE_ID_LIST
60  && variable != ID_COUNT
61  && variable != LAST_STEP_OCCUPANCY
62  && variable != VAR_POSITION
63  && variable != VAR_LANE_ID
64  && variable != VAR_LENGTH) {
65  return server.writeErrorStatusCmd(CMD_GET_LANEAREA_VARIABLE, "Get Areal Detector Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
66  }
67 
68  // begin response building
69  tcpip::Storage tempMsg;
70  // response-code, variableID, objectID
72  tempMsg.writeUnsignedByte(variable);
73  tempMsg.writeString(id);
74  try {
75  switch (variable) {
76  case ID_LIST:
79  break;
80  case ID_COUNT:
83  break;
87  break;
91  break;
95  break;
99  break;
100  case JAM_LENGTH_VEHICLE:
103  break;
104  case JAM_LENGTH_METERS:
107  break;
108  case LAST_STEP_OCCUPANCY:
111  break;
112  case VAR_POSITION:
115  break;
116  case VAR_LANE_ID:
119  break;
120  case VAR_LENGTH:
123  break;
124  default:
125  break;
126  }
127  } catch (libsumo::TraCIException& e) {
128  return server.writeErrorStatusCmd(CMD_GET_LANEAREA_VARIABLE, e.what(), outputStorage);
129  }
130  server.writeStatusCmd(CMD_GET_LANEAREA_VARIABLE, RTYPE_OK, "", outputStorage);
131  server.writeResponseWithLength(outputStorage, tempMsg);
132  return true;
133 }
134 
135 #endif
136 
137 
138 /****************************************************************************/
139 
#define LAST_STEP_MEAN_SPEED
#define VAR_LENGTH
static std::string getLaneID(const std::string &detID)
Definition: LaneArea.cpp:96
static double getPosition(const std::string &detID)
Definition: LaneArea.cpp:90
#define VAR_POSITION
#define RTYPE_OK
#define CMD_GET_LANEAREA_VARIABLE
#define TYPE_STRINGLIST
#define JAM_LENGTH_METERS
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.
virtual void writeInt(int)
static int getLastStepVehicleNumber(const std::string &detID)
Definition: LaneArea.cpp:109
#define TYPE_STRING
virtual int readUnsignedByte()
static double getJamLengthMeters(const std::string &detID)
Definition: LaneArea.cpp:66
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa1: Get AreaDetector Variable)
static double getLength(const std::string &detID)
Definition: LaneArea.cpp:102
static int getIDCount()
Definition: LaneArea.cpp:53
#define JAM_LENGTH_VEHICLE
static double getLastStepMeanSpeed(const std::string &detID)
Definition: LaneArea.cpp:72
virtual void writeStringList(const std::vector< std::string > &s)
virtual std::string readString()
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:69
static int getJamLengthVehicle(const std::string &detID)
Definition: LaneArea.cpp:60
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
#define LAST_STEP_VEHICLE_NUMBER
virtual void writeString(const std::string &s)
#define LAST_STEP_VEHICLE_ID_LIST
static std::vector< std::string > getIDList()
Definition: LaneArea.cpp:45
#define TYPE_DOUBLE
std::string toHex(const T i, std::streamsize numDigits=0)
Definition: ToString.h:65
virtual void writeDouble(double)
static int getLastStepHaltingNumber(const std::string &detID)
Definition: LaneArea.cpp:115
static double getLastStepOccupancy(const std::string &detID)
Definition: LaneArea.cpp:84
#define RESPONSE_GET_LANEAREA_VARIABLE
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
#define LAST_STEP_OCCUPANCY
#define ID_COUNT
#define VAR_LANE_ID
#define TYPE_INTEGER
#define ID_LIST
static std::vector< std::string > getLastStepVehicleIDs(const std::string &detID)
Definition: LaneArea.cpp:78
#define LAST_STEP_VEHICLE_HALTING_NUMBER