Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2012-2025 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 : /****************************************************************************/
14 : /// @file InductionLoop.cpp
15 : /// @author Daniel Krajzewicz
16 : /// @author Mario Krumnow
17 : /// @author Jakob Erdmann
18 : /// @author Michael Behrisch
19 : /// @date 30.05.2012
20 : ///
21 : // C++ TraCI client API implementation
22 : /****************************************************************************/
23 : #include <config.h>
24 :
25 : #define LIBTRACI 1
26 : #include <libsumo/InductionLoop.h>
27 : #include "Domain.h"
28 :
29 :
30 : namespace libtraci {
31 :
32 : typedef Domain<libsumo::CMD_GET_INDUCTIONLOOP_VARIABLE, libsumo::CMD_SET_INDUCTIONLOOP_VARIABLE> Dom;
33 :
34 :
35 : // ===========================================================================
36 : // member definitions
37 : // ===========================================================================
38 : std::vector<std::string>
39 95 : InductionLoop::getIDList() {
40 189 : return Dom::getStringVector(libsumo::TRACI_ID_LIST, "");
41 : }
42 :
43 :
44 : int
45 4 : InductionLoop::getIDCount() {
46 8 : return Dom::getInt(libsumo::ID_COUNT, "");
47 : }
48 :
49 :
50 : double
51 4 : InductionLoop::getPosition(const std::string& loopID) {
52 4 : return Dom::getDouble(libsumo::VAR_POSITION, loopID);
53 : }
54 :
55 :
56 : std::string
57 4 : InductionLoop::getLaneID(const std::string& loopID) {
58 4 : return Dom::getString(libsumo::VAR_LANE_ID, loopID);
59 : }
60 :
61 :
62 : int
63 204 : InductionLoop::getLastStepVehicleNumber(const std::string& loopID) {
64 204 : return Dom::getInt(libsumo::LAST_STEP_VEHICLE_NUMBER, loopID);
65 : }
66 :
67 :
68 : double
69 22 : InductionLoop::getLastStepMeanSpeed(const std::string& loopID) {
70 22 : return Dom::getDouble(libsumo::LAST_STEP_MEAN_SPEED, loopID);
71 : }
72 :
73 :
74 : std::vector<std::string>
75 228 : InductionLoop::getLastStepVehicleIDs(const std::string& loopID) {
76 228 : return Dom::getStringVector(libsumo::LAST_STEP_VEHICLE_ID_LIST, loopID);
77 : }
78 :
79 :
80 : double
81 164 : InductionLoop::getLastStepOccupancy(const std::string& loopID) {
82 164 : return Dom::getDouble(libsumo::LAST_STEP_OCCUPANCY, loopID);
83 : }
84 :
85 :
86 : double
87 22 : InductionLoop::getLastStepMeanLength(const std::string& loopID) {
88 22 : return Dom::getDouble(libsumo::LAST_STEP_LENGTH, loopID);
89 : }
90 :
91 :
92 : double
93 22 : InductionLoop::getTimeSinceDetection(const std::string& loopID) {
94 22 : return Dom::getDouble(libsumo::LAST_STEP_TIME_SINCE_DETECTION, loopID);
95 : }
96 :
97 :
98 : std::vector<libsumo::TraCIVehicleData>
99 17424 : InductionLoop::getVehicleData(const std::string& loopID) {
100 17424 : std::unique_lock<std::mutex> lock{ libtraci::Connection::getActive().getMutex() };
101 : std::vector<libsumo::TraCIVehicleData> result;
102 : tcpip::Storage& ret = Dom::get(libsumo::LAST_STEP_VEHICLE_DATA, loopID);
103 17424 : ret.readInt(); // components
104 34848 : StoHelp::readVehicleDataVector(ret, result);
105 17424 : return result;
106 0 : }
107 :
108 :
109 : double
110 120 : InductionLoop::getIntervalOccupancy(const std::string& loopID) {
111 120 : return Dom::getDouble(libsumo::VAR_INTERVAL_OCCUPANCY, loopID);
112 : }
113 :
114 :
115 : double
116 120 : InductionLoop::getIntervalMeanSpeed(const std::string& loopID) {
117 120 : return Dom::getDouble(libsumo::VAR_INTERVAL_SPEED, loopID);
118 : }
119 :
120 :
121 : int
122 120 : InductionLoop::getIntervalVehicleNumber(const std::string& loopID) {
123 120 : return Dom::getInt(libsumo::VAR_INTERVAL_NUMBER, loopID);
124 : }
125 :
126 :
127 : std::vector<std::string>
128 120 : InductionLoop::getIntervalVehicleIDs(const std::string& loopID) {
129 120 : return Dom::getStringVector(libsumo::VAR_INTERVAL_IDS, loopID);
130 : }
131 :
132 :
133 : double
134 120 : InductionLoop::getLastIntervalOccupancy(const std::string& loopID) {
135 120 : return Dom::getDouble(libsumo::VAR_LAST_INTERVAL_OCCUPANCY, loopID);
136 : }
137 :
138 :
139 : double
140 120 : InductionLoop::getLastIntervalMeanSpeed(const std::string& loopID) {
141 120 : return Dom::getDouble(libsumo::VAR_LAST_INTERVAL_SPEED, loopID);
142 : }
143 :
144 :
145 : int
146 120 : InductionLoop::getLastIntervalVehicleNumber(const std::string& loopID) {
147 120 : return Dom::getInt(libsumo::VAR_LAST_INTERVAL_NUMBER, loopID);
148 : }
149 :
150 :
151 : std::vector<std::string>
152 120 : InductionLoop::getLastIntervalVehicleIDs(const std::string& loopID) {
153 120 : return Dom::getStringVector(libsumo::VAR_LAST_INTERVAL_IDS, loopID);
154 : }
155 :
156 :
157 : void
158 5 : InductionLoop::overrideTimeSinceDetection(const std::string& loopID, double time) {
159 5 : Dom::setDouble(libsumo::VAR_VIRTUAL_DETECTION, loopID, time);
160 5 : }
161 :
162 :
163 12 : LIBTRACI_PARAMETER_IMPLEMENTATION(InductionLoop, INDUCTIONLOOP)
164 264 : LIBTRACI_SUBSCRIPTION_IMPLEMENTATION(InductionLoop, INDUCTIONLOOP)
165 :
166 :
167 : } // namespace libtraci
168 :
169 : /****************************************************************************/
|