SUMO - Simulation of Urban MObility
TraCIServerAPI_ArealDetector.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // APIs for getting/setting areal detector values via TraCI
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2014 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
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 
36 #include "TraCIConstants.h"
39 
40 #ifdef CHECK_MEMORY_LEAKS
41 #include <foreign/nvwa/debug_new.h>
42 #endif // CHECK_MEMORY_LEAKS
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 bool
50  tcpip::Storage& outputStorage) {
51  // variable & id
52  int variable = inputStorage.readUnsignedByte();
53  std::string id = inputStorage.readString();
54  // check variable
55  if (variable != ID_LIST && variable != ID_COUNT && variable != JAM_LENGTH_VEHICLE && variable != JAM_LENGTH_METERS &&
56  variable != LAST_STEP_VEHICLE_NUMBER && variable != LAST_STEP_MEAN_SPEED && variable != LAST_STEP_VEHICLE_ID_LIST
57  && variable != LAST_STEP_VEHICLE_HALTING_NUMBER && variable != ID_COUNT && variable != LAST_STEP_OCCUPANCY) {
58  return server.writeErrorStatusCmd(CMD_GET_AREAL_DETECTOR_VARIABLE, "Get Areal Detector Variable: unsupported variable specified", outputStorage);
59  }
60 
61  // begin response building
62  tcpip::Storage tempMsg;
63  // response-code, variableID, objectID
65  tempMsg.writeUnsignedByte(variable);
66  tempMsg.writeString(id);
67  if (variable == ID_LIST) {
68  std::vector<std::string> ids;
71  tempMsg.writeStringList(ids);
72  } else if (variable == ID_COUNT) {
73  std::vector<std::string> ids;
76  tempMsg.writeInt((int) ids.size());
77  } else {
79  if (e2 == 0) {
80  return server.writeErrorStatusCmd(CMD_GET_AREAL_DETECTOR_VARIABLE, "Areal detector '" + id + "' is not known", outputStorage);
81  }
82  std::vector<std::string> ids;
83  switch (variable) {
84  case ID_LIST:
85  break;
88  tempMsg.writeInt((int) e2->getCurrentVehicleNumber());
89  break;
92  tempMsg.writeDouble(e2->getCurrentMeanSpeed());
93  break;
96  ids = e2->getCurrentVehicleIDs();
97  tempMsg.writeStringList(ids);
98  break;
101  tempMsg.writeInt(e2->getCurrentHaltingNumber());
102  break;
103  case JAM_LENGTH_VEHICLE:
105  tempMsg.writeInt((int) e2->getCurrentJamLengthInVehicles());
106  break;
107  case JAM_LENGTH_METERS:
110  break;
111  case LAST_STEP_OCCUPANCY:
113  tempMsg.writeDouble(e2->getCurrentOccupancy());
114  break;
115  default:
116  break;
117  }
118  }
119  server.writeStatusCmd(CMD_GET_AREAL_DETECTOR_VARIABLE, RTYPE_OK, "", outputStorage);
120  server.writeResponseWithLength(outputStorage, tempMsg);
121  return true;
122 }
123 
124 #endif
125 
126 
127 /****************************************************************************/
128 
#define LAST_STEP_MEAN_SPEED
std::vector< std::string > getCurrentVehicleIDs() const
Returns the IDs of the vehicles within the area.
An areal (along a single lane) detector.
Definition: MSE2Collector.h:79
#define RTYPE_OK
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
#define TYPE_STRINGLIST
#define JAM_LENGTH_METERS
SUMOReal getCurrentJamLengthInMeters() const
Returns the length of all jams in 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)
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.
#define CMD_GET_AREAL_DETECTOR_VARIABLE
#define JAM_LENGTH_VEHICLE
void insertIDs(std::vector< std::string > &into) const
virtual void writeStringList(const std::vector< std::string > &s)
SUMOReal getCurrentMeanSpeed() const
Returns the mean vehicle speed of vehicles currently on the detector.
#define RESPONSE_GET_AREAL_DETECTOR_VARIABLE
virtual std::string readString()
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:74
MSDetectorControl & getDetectorControl()
Returns the detector control.
Definition: MSNet.h:339
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
SUMOReal getCurrentOccupancy() const
Returns the curent detector occupancy.
unsigned getCurrentVehicleNumber() const
Returns the number of vehicles currently on the detector.
virtual void writeDouble(double)
unsigned getCurrentJamLengthInVehicles() const
Returns the length of all jams in vehicles.
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
int getCurrentHaltingNumber() const
Returns the number of current haltings within the area.
#define TYPE_INTEGER
#define ID_LIST
#define LAST_STEP_VEHICLE_HALTING_NUMBER
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa1: Get AreaDetector Variable)