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 /****************************************************************************/
10 // APIs for getting/setting areal detector values via TraCI
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
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"
40 
41 #ifdef CHECK_MEMORY_LEAKS
42 #include <foreign/nvwa/debug_new.h>
43 #endif // CHECK_MEMORY_LEAKS
44 
45 
46 // ===========================================================================
47 // method definitions
48 // ===========================================================================
49 bool
51  tcpip::Storage& outputStorage) {
52  // variable & id
53  int variable = inputStorage.readUnsignedByte();
54  std::string id = inputStorage.readString();
55  // check variable
56  if (variable != ID_LIST && variable != ID_COUNT && variable != JAM_LENGTH_VEHICLE && variable != JAM_LENGTH_METERS &&
57  variable != LAST_STEP_VEHICLE_NUMBER && variable != LAST_STEP_MEAN_SPEED && variable != LAST_STEP_VEHICLE_ID_LIST
58  && variable != LAST_STEP_VEHICLE_HALTING_NUMBER && variable != ID_COUNT && variable != LAST_STEP_OCCUPANCY) {
59  return server.writeErrorStatusCmd(CMD_GET_AREAL_DETECTOR_VARIABLE, "Get Areal Detector Variable: unsupported variable specified", outputStorage);
60  }
61 
62  // begin response building
63  tcpip::Storage tempMsg;
64  // response-code, variableID, objectID
66  tempMsg.writeUnsignedByte(variable);
67  tempMsg.writeString(id);
68  if (variable == ID_LIST) {
69  std::vector<std::string> ids;
72  tempMsg.writeStringList(ids);
73  } else if (variable == ID_COUNT) {
74  std::vector<std::string> ids;
77  tempMsg.writeInt((int) ids.size());
78  } else {
80  if (e2 == 0) {
81  return server.writeErrorStatusCmd(CMD_GET_AREAL_DETECTOR_VARIABLE, "Areal detector '" + id + "' is not known", outputStorage);
82  }
83  std::vector<std::string> ids;
84  switch (variable) {
85  case ID_LIST:
86  break;
89  tempMsg.writeInt((int) e2->getCurrentVehicleNumber());
90  break;
93  tempMsg.writeDouble(e2->getCurrentMeanSpeed());
94  break;
97  ids = e2->getCurrentVehicleIDs();
98  tempMsg.writeStringList(ids);
99  break;
102  tempMsg.writeInt((int) e2->getCurrentHaltingNumber());
103  break;
104  case JAM_LENGTH_VEHICLE:
106  tempMsg.writeInt((int) e2->getCurrentJamLengthInVehicles());
107  break;
108  case JAM_LENGTH_METERS:
111  break;
112  case LAST_STEP_OCCUPANCY:
114  tempMsg.writeDouble(e2->getCurrentOccupancy());
115  break;
116  default:
117  break;
118  }
119  }
120  server.writeStatusCmd(CMD_GET_AREAL_DETECTOR_VARIABLE, RTYPE_OK, "", outputStorage);
121  server.writeResponseWithLength(outputStorage, tempMsg);
122  return true;
123 }
124 
125 #endif
126 
127 
128 /****************************************************************************/
129