SUMO - Simulation of Urban MObility
MSDevice_BTsender.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2013-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 /****************************************************************************/
16 // A BT sender
17 /****************************************************************************/
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <config.h>
23 
28 #include <microsim/MSNet.h>
29 #include <microsim/MSLane.h>
30 #include <microsim/MSEdge.h>
31 #include <microsim/MSVehicle.h>
32 #include "MSDevice_Tripinfo.h"
33 #include "MSDevice_BTsender.h"
34 #include "MSDevice_BTreceiver.h"
35 
36 
37 // ===========================================================================
38 // static members
39 // ===========================================================================
40 std::map<std::string, MSDevice_BTsender::VehicleInformation*> MSDevice_BTsender::sVehicles;
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
46 // ---------------------------------------------------------------------------
47 // static initialisation methods
48 // ---------------------------------------------------------------------------
49 void
51  insertDefaultAssignmentOptions("btsender", "Communication", oc);
52 }
53 
54 
55 void
56 MSDevice_BTsender::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
57  if (equippedByDefaultAssignmentOptions(OptionsCont::getOptions(), "btsender", v, false)) {
58  MSDevice_BTsender* device = new MSDevice_BTsender(v, "btsender_" + v.getID());
59  into.push_back(device);
60  }
61 }
62 
63 void
65  std::map<std::string, MSDevice_BTsender::VehicleInformation*>::iterator i;
66  for (i = sVehicles.begin(); i != sVehicles.end(); i++) {
67  delete i->second;
68  }
69 }
70 
71 
72 // ---------------------------------------------------------------------------
73 // MSDevice_BTsender-methods
74 // ---------------------------------------------------------------------------
75 MSDevice_BTsender::MSDevice_BTsender(SUMOVehicle& holder, const std::string& id)
76  : MSVehicleDevice(holder, id) {
77 }
78 
79 
81 }
82 
83 
84 bool
85 MSDevice_BTsender::notifyEnter(SUMOVehicle& veh, Notification reason, const MSLane* /* enteredLane */) {
86  if (reason == MSMoveReminder::NOTIFICATION_DEPARTED && sVehicles.find(veh.getID()) == sVehicles.end()) {
87  sVehicles[veh.getID()] = new VehicleInformation(veh.getID());
88  sVehicles[veh.getID()]->route.push_back(veh.getEdge());
89  }
90  if (reason == MSMoveReminder::NOTIFICATION_TELEPORT && sVehicles.find(veh.getID()) != sVehicles.end()) {
91  sVehicles[veh.getID()]->amOnNet = true;
92  }
94  sVehicles[veh.getID()]->route.push_back(veh.getEdge());
95  }
96  const MSVehicle& v = static_cast<MSVehicle&>(veh);
97  sVehicles[veh.getID()]->updates.push_back(VehicleState(veh.getSpeed(), veh.getPosition(), v.getLane()->getID(), veh.getPositionOnLane(), v.getRoutePosition()));
98  return true;
99 }
100 
101 
102 bool
103 MSDevice_BTsender::notifyMove(SUMOVehicle& veh, double /* oldPos */, double newPos, double newSpeed) {
104  if (sVehicles.find(veh.getID()) == sVehicles.end()) {
105  WRITE_WARNING("btsender: Can not update position of vehicle '" + veh.getID() + "' which is not on the road.");
106  return true;
107  }
108  const MSVehicle& v = static_cast<MSVehicle&>(veh);
109  sVehicles[veh.getID()]->updates.push_back(VehicleState(newSpeed, veh.getPosition(), v.getLane()->getID(), newPos, v.getRoutePosition()));
110  return true;
111 }
112 
113 
114 bool
115 MSDevice_BTsender::notifyLeave(SUMOVehicle& veh, double /* lastPos */, Notification reason, const MSLane* /* enteredLane */) {
117  return true;
118  }
119  if (sVehicles.find(veh.getID()) == sVehicles.end()) {
120  WRITE_WARNING("btsender: Can not update position of vehicle '" + veh.getID() + "' which is not on the road.");
121  return true;
122  }
123  const MSVehicle& v = static_cast<MSVehicle&>(veh);
124  sVehicles[veh.getID()]->updates.push_back(VehicleState(veh.getSpeed(), veh.getPosition(), v.getLane()->getID(), veh.getPositionOnLane(), v.getRoutePosition()));
126  sVehicles[veh.getID()]->amOnNet = false;
127  }
128  if (reason >= MSMoveReminder::NOTIFICATION_ARRIVED) {
129  sVehicles[veh.getID()]->amOnNet = false;
130  sVehicles[veh.getID()]->haveArrived = true;
131  }
132  return true;
133 }
134 
135 
136 /****************************************************************************/
137 
int getRoutePosition() const
Definition: MSVehicle.cpp:1027
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:79
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:565
~MSDevice_BTsender()
Destructor.
The vehicle arrived at a junction.
bool notifyMove(SUMOVehicle &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
virtual const MSEdge * getEdge() const =0
Returns the edge the vehicle is currently at.
Notification
Definition of a vehicle state.
const std::string & getID() const
Returns the id.
Definition: Named.h:78
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:241
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice *> &into)
Build devices for the given vehicle, if needed.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
A single movement state of the vehicle.
The vehicle arrived at its destination (is deleted)
MSDevice_BTsender(SUMOVehicle &holder, const std::string &id)
Constructor.
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc, const bool isPerson=false)
Adds common command options that allow to assign devices to vehicles.
Definition: MSDevice.cpp:121
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTsender-options.
bool notifyLeave(SUMOVehicle &veh, double lastPos, Notification reason, const MSLane *enteredLane=0)
Moves (the known) vehicle from running to arrived vehicles&#39; list.
The vehicle has departed (was inserted into the network)
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, DEVICEHOLDER &v, bool outputOptionSet, const bool isPerson=false)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.h:208
virtual double getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
A storage for options typed value containers)
Definition: OptionsCont.h:92
static void cleanup()
removes remaining vehicleInformation in sVehicles
Abstract in-vehicle device.
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
Stores the information of a vehicle.
static std::map< std::string, VehicleInformation * > sVehicles
The list of arrived senders.
virtual double getSpeed() const =0
Returns the vehicle&#39;s current speed.
Representation of a lane in the micro simulation.
Definition: MSLane.h:78
virtual const std::string & getID() const =0
Get the vehicle&#39;s ID.
bool notifyEnter(SUMOVehicle &veh, Notification reason, const MSLane *enteredLane=0)
Adds the vehicle to running vehicles if it (re-) enters the network.
The vehicle is being teleported.