SUMO - Simulation of Urban MObility
TraCIServerAPI_MultiEntryExit.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // APIs for getting/setting multi-entry/multi-exit detector values via TraCI
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #ifndef NO_TRACI
33 
34 #include "TraCIConstants.h"
38 
39 
40 // ===========================================================================
41 // method definitions
42 // ===========================================================================
43 bool
45  tcpip::Storage& outputStorage) {
46  // variable & id
47  int variable = inputStorage.readUnsignedByte();
48  std::string id = inputStorage.readString();
49  // check variable
50  if (variable != ID_LIST && variable != LAST_STEP_VEHICLE_NUMBER && variable != LAST_STEP_MEAN_SPEED
52  && variable != ID_COUNT) {
53  return server.writeErrorStatusCmd(CMD_GET_MULTIENTRYEXIT_VARIABLE, "Get MeMeDetector 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  try {
62  switch (variable) {
63  case ID_LIST:
66  break;
67  case ID_COUNT:
70  break;
74  break;
78  break;
82  break;
86  break;
87  default:
88  break;
89  }
90  } catch (TraCIException& e) {
91  return server.writeErrorStatusCmd(CMD_GET_MULTIENTRYEXIT_VARIABLE, e.what(), outputStorage);
92  }
93  server.writeStatusCmd(CMD_GET_MULTIENTRYEXIT_VARIABLE, RTYPE_OK, "", outputStorage);
94  server.writeResponseWithLength(outputStorage, tempMsg);
95  return true;
96 }
97 
98 #endif
99 
100 
101 /****************************************************************************/
102 
#define LAST_STEP_MEAN_SPEED
static std::vector< std::string > getIDList()
#define RTYPE_OK
static std::vector< std::string > getLastStepVehicleIDs(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.
static int getLastStepVehicleNumber(const std::string &detID)
virtual void writeInt(int)
static int getLastStepHaltingNumber(const std::string &detID)
virtual int readUnsignedByte()
static int getIDCount()
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:74
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
#define TYPE_DOUBLE
std::string toHex(const T i, std::streamsize numDigits=0)
Definition: ToString.h:66
#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
static double getLastStepMeanSpeed(const std::string &detID)
#define LAST_STEP_VEHICLE_HALTING_NUMBER