Eclipse SUMO - Simulation of Urban MObility
TraCIServerAPI_InductionLoop.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2009-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
17 // APIs for getting/setting induction loop values via TraCI
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <microsim/MSNet.h>
28 #include <libsumo/InductionLoop.h>
29 #include <libsumo/TraCIConstants.h>
31 
32 
33 // ===========================================================================
34 // method definitions
35 // ===========================================================================
36 bool
38  tcpip::Storage& outputStorage) {
39  const int variable = inputStorage.readUnsignedByte();
40  const std::string id = inputStorage.readString();
42  try {
43  if (!libsumo::InductionLoop::handleVariable(id, variable, &server)) {
44  switch (variable) {
46  std::vector<libsumo::TraCIVehicleData> vd = libsumo::InductionLoop::getVehicleData(id);
48  tcpip::Storage tempContent;
49  int cnt = 0;
51  tempContent.writeInt((int)vd.size());
52  ++cnt;
53  for (const libsumo::TraCIVehicleData& svd : vd) {
55  tempContent.writeString(svd.id);
56  ++cnt;
58  tempContent.writeDouble(svd.length);
59  ++cnt;
61  tempContent.writeDouble(svd.entryTime);
62  ++cnt;
64  tempContent.writeDouble(svd.leaveTime);
65  ++cnt;
67  tempContent.writeString(svd.typeID);
68  ++cnt;
69  }
70  server.getWrapperStorage().writeInt((int)cnt);
71  server.getWrapperStorage().writeStorage(tempContent);
72  break;
73  }
74  default:
76  "Get Induction Loop Variable: unsupported variable " + toHex(variable, 2)
77  + " specified", outputStorage);
78  }
79  }
80  } catch (libsumo::TraCIException& e) {
81  return server.writeErrorStatusCmd(libsumo::CMD_GET_INDUCTIONLOOP_VARIABLE, e.what(), outputStorage);
82  }
84  server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
85  return true;
86 }
87 
88 
89 /****************************************************************************/
90 
libsumo::RTYPE_OK
TRACI_CONST int RTYPE_OK
Definition: TraCIConstants.h:352
tcpip::Storage::writeUnsignedByte
virtual void writeUnsignedByte(int)
Definition: storage.cpp:160
MSNet.h
MSDetectorControl.h
libsumo::InductionLoop::getVehicleData
static std::vector< libsumo::TraCIVehicleData > getVehicleData(const std::string &detID)
Definition: InductionLoop.cpp:109
TraCIServerAPI_InductionLoop.h
TraCIServer::writeResponseWithLength
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
Definition: TraCIServer.cpp:1366
libsumo::TraCIVehicleData
mirrors MSInductLoop::VehicleData
Definition: TraCIDefs.h:286
TraCIServer::getWrapperStorage
tcpip::Storage & getWrapperStorage()
Definition: TraCIServer.cpp:174
libsumo::LAST_STEP_VEHICLE_DATA
TRACI_CONST int LAST_STEP_VEHICLE_DATA
Definition: TraCIConstants.h:534
tcpip::Storage::writeDouble
virtual void writeDouble(double)
Definition: storage.cpp:349
TraCIServer::writeStatusCmd
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
Definition: TraCIServer.cpp:968
TraCIServer::initWrapper
void initWrapper(const int domainID, const int variable, const std::string &objID)
Definition: TraCIServer.cpp:102
tcpip::Storage::writeString
virtual void writeString(const std::string &s)
Definition: storage.cpp:192
tcpip::Storage::writeInt
virtual void writeInt(int)
Definition: storage.cpp:316
libsumo::TYPE_DOUBLE
TRACI_CONST int TYPE_DOUBLE
Definition: TraCIConstants.h:335
tcpip::Storage::writeStorage
virtual void writeStorage(tcpip::Storage &store)
Definition: storage.cpp:383
tcpip::Storage::readUnsignedByte
virtual int readUnsignedByte()
Definition: storage.cpp:150
TraCIConstants.h
libsumo::TYPE_INTEGER
TRACI_CONST int TYPE_INTEGER
Definition: TraCIConstants.h:333
TraCIServerAPI_InductionLoop::processGet
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa0: Get Induction Loop Variable)
Definition: TraCIServerAPI_InductionLoop.cpp:37
toHex
std::string toHex(const T i, std::streamsize numDigits=0)
Definition: ToString.h:57
InductionLoop.h
libsumo::InductionLoop::handleVariable
static bool handleVariable(const std::string &objID, const int variable, VariableWrapper *wrapper)
Definition: InductionLoop.cpp:166
libsumo::TraCIException
Definition: TraCIDefs.h:89
libsumo::CMD_GET_INDUCTIONLOOP_VARIABLE
TRACI_CONST int CMD_GET_INDUCTIONLOOP_VARIABLE
Definition: TraCIConstants.h:93
libsumo::TYPE_STRING
TRACI_CONST int TYPE_STRING
Definition: TraCIConstants.h:337
config.h
tcpip::Storage::readString
virtual std::string readString()
Definition: storage.cpp:175
libsumo::RESPONSE_GET_INDUCTIONLOOP_VARIABLE
TRACI_CONST int RESPONSE_GET_INDUCTIONLOOP_VARIABLE
Definition: TraCIConstants.h:95
TraCIServer
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:61
tcpip::Storage
Definition: storage.h:38
libsumo::TYPE_COMPOUND
TRACI_CONST int TYPE_COMPOUND
Definition: TraCIConstants.h:341
TraCIServer::writeErrorStatusCmd
bool writeErrorStatusCmd(int commandId, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage with status = RTYPE_ERR.
Definition: TraCIServer.cpp:982