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
56  && variable != ID_COUNT
57  && variable != JAM_LENGTH_VEHICLE
58  && variable != JAM_LENGTH_METERS
59  && variable != LAST_STEP_VEHICLE_NUMBER
60  && variable != LAST_STEP_MEAN_SPEED
61  && variable != LAST_STEP_VEHICLE_ID_LIST
63  && variable != ID_COUNT
64  && variable != LAST_STEP_OCCUPANCY
65  && variable != VAR_POSITION
66  && variable != VAR_LANE_ID
67  && variable != VAR_LENGTH) {
68  return server.writeErrorStatusCmd(CMD_GET_AREAL_DETECTOR_VARIABLE, "Get Areal Detector Variable: unsupported variable specified", outputStorage);
69  }
70 
71  // begin response building
72  tcpip::Storage tempMsg;
73  // response-code, variableID, objectID
75  tempMsg.writeUnsignedByte(variable);
76  tempMsg.writeString(id);
77  if (variable == ID_LIST) {
78  std::vector<std::string> ids;
81  tempMsg.writeStringList(ids);
82  } else if (variable == ID_COUNT) {
83  std::vector<std::string> ids;
86  tempMsg.writeInt((int) ids.size());
87  } else {
89  if (e2 == 0) {
90  return server.writeErrorStatusCmd(CMD_GET_AREAL_DETECTOR_VARIABLE, "Areal detector '" + id + "' is not known", outputStorage);
91  }
92  std::vector<std::string> ids;
93  switch (variable) {
94  case ID_LIST:
95  break;
98  tempMsg.writeInt((int) e2->getCurrentVehicleNumber());
99  break;
102  tempMsg.writeDouble(e2->getCurrentMeanSpeed());
103  break;
106  ids = e2->getCurrentVehicleIDs();
107  tempMsg.writeStringList(ids);
108  break;
111  tempMsg.writeInt(e2->getCurrentHaltingNumber());
112  break;
113  case JAM_LENGTH_VEHICLE:
115  tempMsg.writeInt((int) e2->getCurrentJamLengthInVehicles());
116  break;
117  case JAM_LENGTH_METERS:
120  break;
121  case LAST_STEP_OCCUPANCY:
123  tempMsg.writeDouble(e2->getCurrentOccupancy());
124  break;
125  case VAR_POSITION:
127  tempMsg.writeDouble(e2->getStartPos());
128  break;
129  case VAR_LANE_ID:
131  tempMsg.writeString(e2->getLane()->getID());
132  break;
133  case VAR_LENGTH:
135  tempMsg.writeDouble(e2->getEndPos() - e2->getStartPos());
136  break;
137  default:
138  break;
139  }
140  }
141  server.writeStatusCmd(CMD_GET_AREAL_DETECTOR_VARIABLE, RTYPE_OK, "", outputStorage);
142  server.writeResponseWithLength(outputStorage, tempMsg);
143  return true;
144 }
145 
146 #endif
147 
148 
149 /****************************************************************************/
150 
#define LAST_STEP_MEAN_SPEED
std::vector< std::string > getCurrentVehicleIDs() const
Returns the IDs of the vehicles within the area.
#define VAR_LENGTH
#define VAR_POSITION
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:162
#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.
const MSLane * getLane() const
Returns the lane the reminder works on.
virtual void writeInt(int)
#define TYPE_STRING
virtual int readUnsignedByte()
T get(const std::string &id) const
Retrieves an item.
const std::string & getID() const
Returns the id.
Definition: Named.h:65
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
SUMOReal getStartPos() const
Returns the begin position of the detector.
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:359
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
#define VAR_LANE_ID
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)
SUMOReal getEndPos() const
Returns the end position of the detector.