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-2020 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
21 // APIs for getting/setting induction loop values via TraCI
22 /****************************************************************************/
23 #include <config.h>
24 
25 #include <microsim/MSNet.h>
27 #include <libsumo/InductionLoop.h>
28 #include <libsumo/TraCIConstants.h>
30 
31 
32 // ===========================================================================
33 // method definitions
34 // ===========================================================================
35 bool
37  tcpip::Storage& outputStorage) {
38  const int variable = inputStorage.readUnsignedByte();
39  const std::string id = inputStorage.readString();
41  try {
42  if (!libsumo::InductionLoop::handleVariable(id, variable, &server)) {
43  switch (variable) {
45  std::vector<libsumo::TraCIVehicleData> vd = libsumo::InductionLoop::getVehicleData(id);
47  tcpip::Storage tempContent;
48  int cnt = 0;
50  tempContent.writeInt((int)vd.size());
51  ++cnt;
52  for (const libsumo::TraCIVehicleData& svd : vd) {
54  tempContent.writeString(svd.id);
55  ++cnt;
57  tempContent.writeDouble(svd.length);
58  ++cnt;
60  tempContent.writeDouble(svd.entryTime);
61  ++cnt;
63  tempContent.writeDouble(svd.leaveTime);
64  ++cnt;
66  tempContent.writeString(svd.typeID);
67  ++cnt;
68  }
69  server.getWrapperStorage().writeInt((int)cnt);
70  server.getWrapperStorage().writeStorage(tempContent);
71  break;
72  }
73  default:
75  "Get Induction Loop Variable: unsupported variable " + toHex(variable, 2)
76  + " specified", outputStorage);
77  }
78  }
79  } catch (libsumo::TraCIException& e) {
80  return server.writeErrorStatusCmd(libsumo::CMD_GET_INDUCTIONLOOP_VARIABLE, e.what(), outputStorage);
81  }
83  server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
84  return true;
85 }
86 
87 
88 /****************************************************************************/
std::string toHex(const T i, std::streamsize numDigits=0)
Definition: ToString.h:54
static bool processGet(TraCIServer &server, tcpip::Storage &inputStorage, tcpip::Storage &outputStorage)
Processes a get value command (Command 0xa0: Get Induction Loop Variable)
TraCI server used to control sumo by a remote TraCI client.
Definition: TraCIServer.h:59
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
tcpip::Storage & getWrapperStorage()
void initWrapper(const int domainID, const int variable, const std::string &objID)
bool writeErrorStatusCmd(int commandId, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage with status = RTYPE_ERR.
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
virtual std::string readString()
Definition: storage.cpp:175
virtual void writeString(const std::string &s)
Definition: storage.cpp:192
virtual void writeInt(int)
Definition: storage.cpp:316
virtual void writeDouble(double)
Definition: storage.cpp:349
virtual int readUnsignedByte()
Definition: storage.cpp:150
virtual void writeUnsignedByte(int)
Definition: storage.cpp:160
virtual void writeStorage(tcpip::Storage &store)
Definition: storage.cpp:383
TRACI_CONST int LAST_STEP_VEHICLE_DATA
TRACI_CONST int TYPE_COMPOUND
TRACI_CONST int TYPE_INTEGER
TRACI_CONST int RESPONSE_GET_INDUCTIONLOOP_VARIABLE
TRACI_CONST int TYPE_DOUBLE
TRACI_CONST int RTYPE_OK
TRACI_CONST int CMD_GET_INDUCTIONLOOP_VARIABLE
TRACI_CONST int TYPE_STRING
mirrors MSInductLoop::VehicleData
Definition: TraCIDefs.h:328