SUMO - Simulation of Urban MObility
TraCIServerAPI_MeMeDetector.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-2016 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"
37 
38 #ifdef CHECK_MEMORY_LEAKS
39 #include <foreign/nvwa/debug_new.h>
40 #endif // CHECK_MEMORY_LEAKS
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
46 bool
48  tcpip::Storage& outputStorage) {
49  // variable & id
50  int variable = inputStorage.readUnsignedByte();
51  std::string id = inputStorage.readString();
52  // check variable
53  if (variable != ID_LIST && variable != LAST_STEP_VEHICLE_NUMBER && variable != LAST_STEP_MEAN_SPEED
55  && variable != ID_COUNT) {
56  return server.writeErrorStatusCmd(CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, "Get MeMeDetector Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
57  }
58  // begin response building
59  tcpip::Storage tempMsg;
60  // response-code, variableID, objectID
62  tempMsg.writeUnsignedByte(variable);
63  tempMsg.writeString(id);
64  if (variable == ID_LIST) {
65  std::vector<std::string> ids;
68  tempMsg.writeStringList(ids);
69  } else if (variable == ID_COUNT) {
70  std::vector<std::string> ids;
73  tempMsg.writeInt((int) ids.size());
74  } else {
76  if (e3 == 0) {
77  return server.writeErrorStatusCmd(CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE, "Areal detector '" + id + "' is not known", outputStorage);
78  }
79  switch (variable) {
80  case ID_LIST:
81  break;
84  tempMsg.writeInt(e3->getVehiclesWithin());
85  break;
88  tempMsg.writeDouble(e3->getCurrentMeanSpeed());
89  break;
92  std::vector<std::string> ids = e3->getCurrentVehicleIDs();
93  tempMsg.writeStringList(ids);
94  }
95  break;
98  tempMsg.writeInt(e3->getCurrentHaltingNumber());
99  break;
100  default:
101  break;
102  }
103  }
105  server.writeResponseWithLength(outputStorage, tempMsg);
106  return true;
107 }
108 
109 #endif
110 
111 
112 /****************************************************************************/
113 
#define LAST_STEP_MEAN_SPEED
#define RTYPE_OK
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
#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()
T get(const std::string &id) const
Retrieves an item.
const NamedObjectCont< MSDetectorFileOutput * > & getTypedDetectors(SumoXMLTag type) const
Returns the list of detectors of the given type.
void insertIDs(std::vector< std::string > &into) const
virtual void writeStringList(const std::vector< std::string > &s)
virtual std::string readString()
int getVehiclesWithin() const
Returns the number of vehicles within the area.
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:73
MSDetectorControl & getDetectorControl()
Returns the detector control.
Definition: MSNet.h:370
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 CMD_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE
#define TYPE_DOUBLE
std::string toHex(const T i, std::streamsize numDigits=0)
Definition: ToString.h:65
A detector of vehicles passing an area between entry/exit points.
Definition: MSE3Collector.h:65
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.
SUMOReal getCurrentMeanSpeed() const
Returns the mean speed within the area.
int getCurrentHaltingNumber() const
Returns the number of current haltings within the area.
#define ID_COUNT
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa1: Get MeMeDetector Variable)
#define TYPE_INTEGER
#define ID_LIST
#define LAST_STEP_VEHICLE_HALTING_NUMBER
std::vector< std::string > getCurrentVehicleIDs() const
Returns the number of vehicles within the area.
#define RESPONSE_GET_MULTI_ENTRY_EXIT_DETECTOR_VARIABLE