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-2018 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 /****************************************************************************/
18 // APIs for getting/setting induction loop values via TraCI
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <microsim/MSNet.h>
29 #include <libsumo/InductionLoop.h>
30 #include "TraCIConstants.h"
32 
33 
34 // ===========================================================================
35 // method definitions
36 // ===========================================================================
37 bool
39  tcpip::Storage& outputStorage) {
40  const int variable = inputStorage.readUnsignedByte();
41  const std::string id = inputStorage.readString();
43  try {
44  if (!libsumo::InductionLoop::handleVariable(id, variable, &server)) {
45  switch (variable) {
47  std::vector<libsumo::TraCIVehicleData> vd = libsumo::InductionLoop::getVehicleData(id);
49  tcpip::Storage tempContent;
50  int cnt = 0;
51  tempContent.writeUnsignedByte(TYPE_INTEGER);
52  tempContent.writeInt((int)vd.size());
53  ++cnt;
54  for (const libsumo::TraCIVehicleData& svd : vd) {
55  tempContent.writeUnsignedByte(TYPE_STRING);
56  tempContent.writeString(svd.id);
57  ++cnt;
58  tempContent.writeUnsignedByte(TYPE_DOUBLE);
59  tempContent.writeDouble(svd.length);
60  ++cnt;
61  tempContent.writeUnsignedByte(TYPE_DOUBLE);
62  tempContent.writeDouble(svd.entryTime);
63  ++cnt;
64  tempContent.writeUnsignedByte(TYPE_DOUBLE);
65  tempContent.writeDouble(svd.leaveTime);
66  ++cnt;
67  tempContent.writeUnsignedByte(TYPE_STRING);
68  tempContent.writeString(svd.typeID);
69  ++cnt;
70  }
71  server.getWrapperStorage().writeInt((int)cnt);
72  server.getWrapperStorage().writeStorage(tempContent);
73  break;
74  }
75  default:
77  "Get Induction Loop Variable: unsupported variable " + toHex(variable, 2)
78  + " specified", outputStorage);
79  }
80  }
81  } catch (libsumo::TraCIException& e) {
82  return server.writeErrorStatusCmd(CMD_GET_INDUCTIONLOOP_VARIABLE, e.what(), outputStorage);
83  }
84  server.writeStatusCmd(CMD_GET_INDUCTIONLOOP_VARIABLE, RTYPE_OK, "", outputStorage);
85  server.writeResponseWithLength(outputStorage, server.getWrapperStorage());
86  return true;
87 }
88 
89 
90 /****************************************************************************/
91 
#define TYPE_COMPOUND
mirrors MSInductLoop::VehicleData
Definition: TraCIDefs.h:272
#define CMD_GET_INDUCTIONLOOP_VARIABLE
#define LAST_STEP_VEHICLE_DATA
#define RTYPE_OK
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)
#define TYPE_STRING
virtual int readUnsignedByte()
tcpip::Storage & getWrapperStorage()
virtual std::string readString()
static bool handleVariable(const std::string &objID, const int variable, VariableWrapper *wrapper)
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:62
#define RESPONSE_GET_INDUCTIONLOOP_VARIABLE
virtual void writeStorage(tcpip::Storage &store)
void writeResponseWithLength(tcpip::Storage &outputStorage, tcpip::Storage &tempMsg)
static std::vector< libsumo::TraCIVehicleData > getVehicleData(const std::string &detID)
virtual void writeString(const std::string &s)
#define TYPE_DOUBLE
std::string toHex(const T i, std::streamsize numDigits=0)
Definition: ToString.h:59
virtual void writeDouble(double)
void writeStatusCmd(int commandId, int status, const std::string &description, tcpip::Storage &outputStorage)
Writes a status command to the given storage.
void initWrapper(const int domainID, const int variable, const std::string &objID)
#define TYPE_INTEGER