SUMO - Simulation of Urban MObility
TraCIServerAPI_MultiEntryExit.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-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 /****************************************************************************/
18 // APIs for getting/setting multi-entry/multi-exit detector values via TraCI
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #ifndef NO_TRACI
32 
34 #include "TraCIConstants.h"
35 #include <libsumo/MultiEntryExit.h>
37 
38 
39 // ===========================================================================
40 // method definitions
41 // ===========================================================================
42 bool
44  tcpip::Storage& outputStorage) {
45  // variable & id
46  int variable = inputStorage.readUnsignedByte();
47  std::string id = inputStorage.readString();
48  // check variable
49  if (variable != ID_LIST && variable != LAST_STEP_VEHICLE_NUMBER && variable != LAST_STEP_MEAN_SPEED
51  && variable != ID_COUNT) {
52  return server.writeErrorStatusCmd(CMD_GET_MULTIENTRYEXIT_VARIABLE, "Get MeMeDetector Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
53  }
54  // begin response building
55  tcpip::Storage tempMsg;
56  // response-code, variableID, objectID
58  tempMsg.writeUnsignedByte(variable);
59  tempMsg.writeString(id);
60  try {
61  switch (variable) {
62  case ID_LIST:
65  break;
66  case ID_COUNT:
69  break;
73  break;
77  break;
81  break;
85  break;
86  default:
87  break;
88  }
89  } catch (libsumo::TraCIException& e) {
90  return server.writeErrorStatusCmd(CMD_GET_MULTIENTRYEXIT_VARIABLE, e.what(), outputStorage);
91  }
92  server.writeStatusCmd(CMD_GET_MULTIENTRYEXIT_VARIABLE, RTYPE_OK, "", outputStorage);
93  server.writeResponseWithLength(outputStorage, tempMsg);
94  return true;
95 }
96 
97 #endif
98 
99 
100 /****************************************************************************/
101 
#define LAST_STEP_MEAN_SPEED
static double getLastStepMeanSpeed(const std::string &detID)
#define RTYPE_OK
static int getLastStepVehicleNumber(const std::string &detID)
static int getLastStepHaltingNumber(const std::string &detID)
#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.
virtual void writeInt(int)
virtual int readUnsignedByte()
virtual void writeStringList(const std::vector< std::string > &s)
static int getIDCount()
static std::vector< std::string > getIDList()
virtual std::string readString()
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:69
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 > getLastStepVehicleIDs(const std::string &detID)
#define TYPE_DOUBLE
std::string toHex(const T i, std::streamsize numDigits=0)
Definition: ToString.h:65
#define RESPONSE_GET_MULTIENTRYEXIT_VARIABLE
#define CMD_GET_MULTIENTRYEXIT_VARIABLE
virtual void writeDouble(double)
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa1: Get MeMeDetector Variable)
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
#define ID_COUNT
#define TYPE_INTEGER
#define ID_LIST
#define LAST_STEP_VEHICLE_HALTING_NUMBER