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