Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2013-2024 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 MSDevice_BTsender.h
15 : /// @author Daniel Krajzewicz
16 : /// @author Michael Behrisch
17 : /// @date 14.08.2013
18 : ///
19 : // A BT sender
20 : /****************************************************************************/
21 : #pragma once
22 : #include <config.h>
23 :
24 : #include <set>
25 : #include <string>
26 : #include <microsim/MSMoveReminder.h>
27 : #include "MSVehicleDevice.h"
28 : #include "MSTransportableDevice.h"
29 : #include <utils/common/SUMOTime.h>
30 : #include <utils/geom/Boundary.h>
31 :
32 :
33 : // ===========================================================================
34 : // class declarations
35 : // ===========================================================================
36 : class SUMOVehicle;
37 : class SUMOTrafficObject;
38 :
39 :
40 : // ===========================================================================
41 : // class definitions
42 : // ===========================================================================
43 : /**
44 : * @class MSDevice_BTsender
45 : * @brief A BT sender
46 : *
47 : * @see MSDevice
48 : */
49 : class MSDevice_BTsender {
50 : public:
51 :
52 : /** @brief removes remaining vehicleInformation in sVehicles
53 : */
54 : static void cleanup();
55 :
56 : /// @brief return either lane or edge id (depending on availability)
57 : static std::string getLocation(const SUMOTrafficObject& o);
58 :
59 : /// for accessing the maps of running/arrived vehicles
60 : friend class MSDevice_BTreceiver;
61 :
62 : public:
63 : /// @brief Destructor.
64 : ~MSDevice_BTsender();
65 :
66 : /// @name Methods inherited from MSMoveReminder.
67 : /// @{
68 :
69 : /** @brief Adds the vehicle to running vehicles if it (re-) enters the network
70 : *
71 : * @param[in] veh The entering vehicle.
72 : * @param[in] reason how the vehicle enters the lane
73 : * @return Always true
74 : * @see MSMoveReminder::notifyEnter
75 : * @see MSMoveReminder::Notification
76 : */
77 : bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
78 :
79 :
80 : /** @brief Checks whether the reminder still has to be notified about the vehicle moves
81 : *
82 : * Indicator if the reminders is still active for the passed
83 : * vehicle/parameters. If false, the vehicle will erase this reminder
84 : * from its reminder-container.
85 : *
86 : * @param[in] veh Vehicle that asks this reminder.
87 : * @param[in] oldPos Position before move.
88 : * @param[in] newPos Position after move with newSpeed.
89 : * @param[in] newSpeed Moving speed.
90 : *
91 : * @return True if vehicle hasn't passed the reminder completely.
92 : */
93 : bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed);
94 :
95 :
96 : /** @brief Moves (the known) vehicle from running to arrived vehicles' list
97 : *
98 : * @param[in] veh The leaving vehicle.
99 : * @param[in] lastPos Position on the lane when leaving.
100 : * @param[in] isArrival whether the vehicle arrived at its destination
101 : * @param[in] isLaneChange whether the vehicle changed from the lane
102 : * @see MSMoveReminder
103 : * @see MSMoveReminder::notifyLeave
104 : */
105 : bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0);
106 : /// @}
107 :
108 : /** @class VehicleState
109 : * @brief A single movement state of the vehicle
110 : */
111 338520 : class VehicleState {
112 : public:
113 : /** @brief Constructor
114 : * @param[in] _speed The speed of the vehicle
115 : * @param[in] _position The position of the vehicle
116 : * @param[in] _laneID The id of the lane the vehicle is located at
117 : * @param[in] _lanePos The position of the vehicle along the lane
118 : */
119 : VehicleState(const double _speed, const Position& _position, const std::string& _laneID,
120 : const double _lanePos, const int _routePos)
121 373936 : : speed(_speed), position(_position), laneID(_laneID), lanePos(_lanePos), routePos(_routePos) {}
122 :
123 : /// @brief Destructor
124 676314 : ~VehicleState() {}
125 :
126 : /// @brief The speed of the vehicle
127 : double speed;
128 : /// @brief The position of the vehicle
129 : Position position;
130 : /// @brief The lane the vehicle was at
131 : std::string laneID;
132 : /// @brief The position at the lane of the vehicle
133 : double lanePos;
134 : /// @brief The position in the route of the vehicle
135 : int routePos;
136 :
137 : };
138 :
139 :
140 :
141 : /** @class VehicleInformation
142 : * @brief Stores the information of a vehicle
143 : */
144 : class VehicleInformation : public Named {
145 : public:
146 : /** @brief Constructor
147 : * @param[in] id The id of the vehicle
148 : */
149 1086 : VehicleInformation(const std::string& id) : Named(id), amOnNet(true), haveArrived(false) {}
150 :
151 : /// @brief Destructor
152 1584 : virtual ~VehicleInformation() {}
153 :
154 : /** @brief Returns the boundary of passed positions
155 : * @return The positions boundary
156 : */
157 376748 : Boundary getBoxBoundary() const {
158 376748 : Boundary ret;
159 1094272 : for (std::vector<VehicleState>::const_iterator i = updates.begin(); i != updates.end(); ++i) {
160 717524 : ret.add((*i).position);
161 : }
162 376748 : return ret;
163 0 : }
164 :
165 : /// @brief List of position updates during last step
166 : std::vector<VehicleState> updates;
167 :
168 : /// @brief Whether the vehicle is within the simulated network
169 : bool amOnNet;
170 :
171 : /// @brief Whether the vehicle was removed from the simulation
172 : bool haveArrived;
173 :
174 : /// @brief List of edges travelled
175 : ConstMSEdgeVector route;
176 :
177 : };
178 :
179 :
180 :
181 :
182 :
183 :
184 : protected:
185 : /// @brief The list of arrived senders
186 : static std::map<std::string, VehicleInformation*> sVehicles;
187 :
188 : /** @brief Constructor
189 : */
190 : MSDevice_BTsender() { }
191 :
192 :
193 :
194 : private:
195 : /// @brief Invalidated copy constructor.
196 : MSDevice_BTsender(const MSDevice_BTsender&);
197 :
198 : /// @brief Invalidated assignment operator.
199 : MSDevice_BTsender& operator=(const MSDevice_BTsender&);
200 :
201 :
202 : };
203 :
204 :
205 : class MSVehicleDevice_BTsender : public MSDevice_BTsender, public MSVehicleDevice {
206 : public:
207 :
208 : /** @brief Inserts MSDevice_BTsender-options
209 : * @param[filled] oc The options container to add the options to
210 : */
211 : static void insertOptions(OptionsCont& oc);
212 :
213 :
214 : /** @brief Build devices for the given vehicle, if needed
215 : *
216 : * The options are read and evaluated whether a bt-sender-device shall be built
217 : * for the given vehicle.
218 : *
219 : * The built device is stored in the given vector.
220 : *
221 : * @param[in] v The vehicle for which a device may be built
222 : * @param[filled] into The vector to store the built device in
223 : */
224 : static void buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into);
225 :
226 : /// @brief return the name for this type of device
227 0 : const std::string deviceName() const {
228 0 : return "btsender";
229 : }
230 :
231 4050 : bool notifyEnter(SUMOTrafficObject& veh, Notification reason, const MSLane* enteredLane = 0) {
232 4050 : return MSDevice_BTsender::notifyEnter(veh, reason, enteredLane);
233 : }
234 :
235 44976 : bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed) {
236 44976 : return MSDevice_BTsender::notifyMove(veh, oldPos, newPos, newSpeed);
237 : }
238 :
239 4002 : bool notifyLeave(SUMOTrafficObject& veh, double lastPos, Notification reason, const MSLane* enteredLane = 0) {
240 4002 : return MSDevice_BTsender::notifyLeave(veh, lastPos, reason, enteredLane);
241 : }
242 :
243 :
244 : private:
245 : /** @brief Constructor
246 : *
247 : * @param[in] holder The vehicle that holds this device
248 : * @param[in] id The ID of the device
249 : */
250 366 : MSVehicleDevice_BTsender(SUMOVehicle& holder, const std::string& id) :
251 366 : MSVehicleDevice(holder, id) {
252 366 : }
253 :
254 : };
255 :
256 : class MSTransportableDevice_BTsender : public MSDevice_BTsender, public MSTransportableDevice {
257 : public:
258 :
259 : /** @brief Inserts MSDevice_BTsender-options
260 : * @param[filled] oc The options container to add the options to
261 : */
262 : static void insertOptions(OptionsCont& oc);
263 :
264 :
265 : /** @brief Build devices for the given vehicle, if needed
266 : *
267 : * The options are read and evaluated whether a bt-sender-device shall be built
268 : * for the given vehicle.
269 : *
270 : * The built device is stored in the given vector.
271 : *
272 : * @param[in] v The vehicle for which a device may be built
273 : * @param[filled] into The vector to store the built device in
274 : */
275 : static void buildDevices(MSTransportable& t, std::vector<MSTransportableDevice*>& into);
276 :
277 : /// @brief return the name for this type of device
278 0 : const std::string deviceName() const {
279 0 : return "btsender";
280 : }
281 :
282 132 : bool notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0) {
283 132 : return MSDevice_BTsender::notifyEnter(veh, reason, enteredLane);
284 : }
285 :
286 0 : bool notifyMove(SUMOTrafficObject& veh, double oldPos, double newPos, double newSpeed) {
287 0 : return MSDevice_BTsender::notifyMove(veh, oldPos, newPos, newSpeed);
288 : }
289 :
290 0 : bool notifyLeave(SUMOTrafficObject& veh, double lastPos, MSMoveReminder::Notification reason, const MSLane* enteredLane = 0) {
291 0 : return MSDevice_BTsender::notifyLeave(veh, lastPos, reason, enteredLane);
292 : }
293 :
294 :
295 : private:
296 : /** @brief Constructor
297 : *
298 : * @param[in] holder The transportable that holds this device
299 : * @param[in] id The ID of the device
300 : */
301 132 : MSTransportableDevice_BTsender(MSTransportable& holder, const std::string& id) :
302 132 : MSTransportableDevice(holder, id) {
303 132 : }
304 :
305 : };
|