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 /****************************************************************************/
7 // APIs for getting/setting areal detector values via TraCI
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
10 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #ifndef NO_TRACI
32 
33 #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 != ID_COUNT && variable != JAM_LENGTH_VEHICLE && variable != JAM_LENGTH_METERS) {
54  return server.writeErrorStatusCmd(CMD_GET_AREAL_DETECTOR_VARIABLE, "Get Areal Detector Variable: unsupported variable specified", outputStorage);
55  }
56 
57  // begin response building
58  tcpip::Storage tempMsg;
59  // response-code, variableID, objectID
61  tempMsg.writeUnsignedByte(variable);
62  tempMsg.writeString(id);
63  if (variable == ID_LIST) {
64  std::vector<std::string> ids;
67  tempMsg.writeStringList(ids);
68  } else if (variable == ID_COUNT) {
69  std::vector<std::string> ids;
72  tempMsg.writeInt((int) ids.size());
73  } else {
75  if (e2 == 0) {
76  return server.writeErrorStatusCmd(CMD_GET_AREAL_DETECTOR_VARIABLE, "Areal detector '" + id + "' is not known", outputStorage);
77  }
78  switch (variable) {
79  case ID_LIST:
80  break;
81  case JAM_LENGTH_VEHICLE:
83  tempMsg.writeInt((int) e2->getCurrentJamLengthInVehicles());
84  break;
85  case JAM_LENGTH_METERS:
88  break;
89 
90  default:
91  break;
92  }
93  }
94  server.writeStatusCmd(CMD_GET_AREAL_DETECTOR_VARIABLE, RTYPE_OK, "", outputStorage);
95  server.writeResponseWithLength(outputStorage, tempMsg);
96  return true;
97 }
98 
99 #endif
100 
101 
102 /****************************************************************************/
103 
An areal (along a single lane) detector.
Definition: MSE2Collector.h:77
#define RTYPE_OK
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:150
#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)
#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:294
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
virtual void writeString(const std::string &s)
#define TYPE_DOUBLE
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 ID_COUNT
#define TYPE_INTEGER
#define ID_LIST
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa1: Get AreaDetector Variable)