SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TraCIServerAPI_ArealDetector.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // APIs for getting/setting areal detector values via TraCI
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11 // Copyright (C) 2001-2014 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 #ifdef CHECK_MEMORY_LEAKS
40 #include <foreign/nvwa/debug_new.h>
41 #endif // CHECK_MEMORY_LEAKS
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 bool
49  tcpip::Storage& outputStorage) {
50  // variable & id
51  int variable = inputStorage.readUnsignedByte();
52  std::string id = inputStorage.readString();
53  // check variable
54  if (variable != ID_LIST && variable != ID_COUNT && variable != JAM_LENGTH_VEHICLE && variable != JAM_LENGTH_METERS &&
55  variable != LAST_STEP_VEHICLE_NUMBER && variable != LAST_STEP_MEAN_SPEED && variable != LAST_STEP_VEHICLE_ID_LIST
56  && variable != LAST_STEP_VEHICLE_HALTING_NUMBER && variable != ID_COUNT && variable != LAST_STEP_OCCUPANCY) {
57  return server.writeErrorStatusCmd(CMD_GET_AREAL_DETECTOR_VARIABLE, "Get Areal Detector Variable: unsupported variable specified", outputStorage);
58  }
59 
60  // begin response building
61  tcpip::Storage tempMsg;
62  // response-code, variableID, objectID
64  tempMsg.writeUnsignedByte(variable);
65  tempMsg.writeString(id);
66  if (variable == ID_LIST) {
67  std::vector<std::string> ids;
70  tempMsg.writeStringList(ids);
71  } else if (variable == ID_COUNT) {
72  std::vector<std::string> ids;
75  tempMsg.writeInt((int) ids.size());
76  } else {
78  if (e2 == 0) {
79  return server.writeErrorStatusCmd(CMD_GET_AREAL_DETECTOR_VARIABLE, "Areal detector '" + id + "' is not known", outputStorage);
80  }
81  std::vector<std::string> ids;
82  switch (variable) {
83  case ID_LIST:
84  break;
87  tempMsg.writeInt((int) e2->getCurrentVehicleNumber());
88  break;
91  tempMsg.writeDouble(e2->getCurrentMeanSpeed());
92  break;
95  ids = e2->getCurrentVehicleIDs();
96  tempMsg.writeStringList(ids);
97  break;
100  tempMsg.writeInt((int) e2->getCurrentHaltingNumber());
101  break;
102  case JAM_LENGTH_VEHICLE:
104  tempMsg.writeInt((int) e2->getCurrentJamLengthInVehicles());
105  break;
106  case JAM_LENGTH_METERS:
109  break;
110  case LAST_STEP_OCCUPANCY:
112  tempMsg.writeDouble(e2->getCurrentOccupancy());
113  break;
114  default:
115  break;
116  }
117  }
118  server.writeStatusCmd(CMD_GET_AREAL_DETECTOR_VARIABLE, RTYPE_OK, "", outputStorage);
119  server.writeResponseWithLength(outputStorage, tempMsg);
120  return true;
121 }
122 
123 #endif
124 
125 
126 /****************************************************************************/
127 
#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:78
#define RTYPE_OK
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:154
#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:304
SUMOReal getCurrentHaltingNumber() const
Returns the number of current haltings within the area.
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 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)