SUMO - Simulation of Urban MObility
TraCIServerAPI_LaneArea.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 
37 #include "TraCIConstants.h"
38 #include "TraCIDefs.h"
39 #include "TraCIServer.h"
40 #include "lib/TraCI_LaneArea.h"
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
55  && variable != ID_COUNT
56  && variable != JAM_LENGTH_VEHICLE
57  && variable != JAM_LENGTH_METERS
58  && variable != LAST_STEP_VEHICLE_NUMBER
59  && variable != LAST_STEP_MEAN_SPEED
60  && variable != LAST_STEP_VEHICLE_ID_LIST
62  && variable != ID_COUNT
63  && variable != LAST_STEP_OCCUPANCY
64  && variable != VAR_POSITION
65  && variable != VAR_LANE_ID
66  && variable != VAR_LENGTH) {
67  return server.writeErrorStatusCmd(CMD_GET_LANEAREA_VARIABLE, "Get Areal Detector Variable: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
68  }
69 
70  // begin response building
71  tcpip::Storage tempMsg;
72  // response-code, variableID, objectID
74  tempMsg.writeUnsignedByte(variable);
75  tempMsg.writeString(id);
76  try {
77  switch (variable) {
78  case ID_LIST:
81  break;
82  case ID_COUNT:
85  break;
89  break;
93  break;
97  break;
101  break;
102  case JAM_LENGTH_VEHICLE:
105  break;
106  case JAM_LENGTH_METERS:
109  break;
110  case LAST_STEP_OCCUPANCY:
113  break;
114  case VAR_POSITION:
117  break;
118  case VAR_LANE_ID:
121  break;
122  case VAR_LENGTH:
125  break;
126  default:
127  break;
128  }
129  } catch (TraCIException& e) {
130  return server.writeErrorStatusCmd(CMD_GET_LANEAREA_VARIABLE, e.what(), outputStorage);
131  }
132  server.writeStatusCmd(CMD_GET_LANEAREA_VARIABLE, RTYPE_OK, "", outputStorage);
133  server.writeResponseWithLength(outputStorage, tempMsg);
134  return true;
135 }
136 
137 #endif
138 
139 
140 /****************************************************************************/
141 
#define LAST_STEP_MEAN_SPEED
#define VAR_LENGTH
#define VAR_POSITION
static double getLastStepMeanSpeed(const std::string &detID)
#define RTYPE_OK
#define CMD_GET_LANEAREA_VARIABLE
#define TYPE_STRINGLIST
#define JAM_LENGTH_METERS
static double getJamLengthMeters(const std::string &detID)
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.
static int getLastStepHaltingNumber(const std::string &detID)
virtual void writeInt(int)
#define TYPE_STRING
virtual int readUnsignedByte()
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa1: Get AreaDetector Variable)
static int getJamLengthVehicle(const std::string &detID)
static int getIDCount()
#define JAM_LENGTH_VEHICLE
virtual void writeStringList(const std::vector< std::string > &s)
static int getLastStepVehicleNumber(const std::string &detID)
static std::string getLaneID(const std::string &detID)
virtual std::string readString()
static double getPosition(const std::string &detID)
static double getLength(const std::string &detID)
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:74
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
#define LAST_STEP_VEHICLE_NUMBER
static std::vector< std::string > getIDList()
virtual void writeString(const std::string &s)
#define LAST_STEP_VEHICLE_ID_LIST
static double getLastStepOccupancy(const std::string &detID)
#define TYPE_DOUBLE
std::string toHex(const T i, std::streamsize numDigits=0)
Definition: ToString.h:66
virtual void writeDouble(double)
#define RESPONSE_GET_LANEAREA_VARIABLE
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
static std::vector< std::string > getLastStepVehicleIDs(const std::string &detID)
#define TYPE_INTEGER
#define ID_LIST
#define LAST_STEP_VEHICLE_HALTING_NUMBER