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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // A BT sender
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
34 #include <microsim/MSNet.h>
35 #include <microsim/MSLane.h>
36 #include <microsim/MSEdge.h>
37 #include <microsim/MSVehicle.h>
38 #include "MSDevice_Tripinfo.h"
39 #include "MSDevice_BTsender.h"
40 #include "MSDevice_BTreceiver.h"
41 
42 
43 // ===========================================================================
44 // static members
45 // ===========================================================================
46 std::map<std::string, MSDevice_BTsender::VehicleInformation*> MSDevice_BTsender::sVehicles;
47 
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
52 // ---------------------------------------------------------------------------
53 // static initialisation methods
54 // ---------------------------------------------------------------------------
55 void
57  insertDefaultAssignmentOptions("btsender", "Communication", oc);
58 }
59 
60 
61 void
62 MSDevice_BTsender::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
64  MSDevice_BTsender* device = new MSDevice_BTsender(v, "btsender_" + v.getID());
65  into.push_back(device);
66  }
67 }
68 
69 void
71  std::map<std::string, MSDevice_BTsender::VehicleInformation*>::iterator i;
72  for (i = sVehicles.begin(); i != sVehicles.end(); i++) {
73  delete i->second;
74  }
75 }
76 
77 
78 // ---------------------------------------------------------------------------
79 // MSDevice_BTsender-methods
80 // ---------------------------------------------------------------------------
81 MSDevice_BTsender::MSDevice_BTsender(SUMOVehicle& holder, const std::string& id)
82  : MSDevice(holder, id) {
83 }
84 
85 
87 }
88 
89 
90 bool
91 MSDevice_BTsender::notifyEnter(SUMOVehicle& veh, Notification reason, const MSLane* /* enteredLane */) {
92  if (reason == MSMoveReminder::NOTIFICATION_DEPARTED && sVehicles.find(veh.getID()) == sVehicles.end()) {
93  sVehicles[veh.getID()] = new VehicleInformation(veh.getID());
94  sVehicles[veh.getID()]->route.push_back(veh.getEdge());
95  }
96  if (reason == MSMoveReminder::NOTIFICATION_TELEPORT && sVehicles.find(veh.getID()) != sVehicles.end()) {
97  sVehicles[veh.getID()]->amOnNet = true;
98  }
100  sVehicles[veh.getID()]->route.push_back(veh.getEdge());
101  }
102  const MSVehicle& v = static_cast<MSVehicle&>(veh);
103  sVehicles[veh.getID()]->updates.push_back(VehicleState(veh.getSpeed(), veh.getPosition(), v.getLane()->getID(), veh.getPositionOnLane(), v.getRoutePosition()));
104  return true;
105 }
106 
107 
108 bool
109 MSDevice_BTsender::notifyMove(SUMOVehicle& veh, double /* oldPos */, double newPos, double newSpeed) {
110  if (sVehicles.find(veh.getID()) == sVehicles.end()) {
111  WRITE_WARNING("btsender: Can not update position of vehicle '" + veh.getID() + "' which is not on the road.");
112  return true;
113  }
114  const MSVehicle& v = static_cast<MSVehicle&>(veh);
115  sVehicles[veh.getID()]->updates.push_back(VehicleState(newSpeed, veh.getPosition(), v.getLane()->getID(), newPos, v.getRoutePosition()));
116  return true;
117 }
118 
119 
120 bool
121 MSDevice_BTsender::notifyLeave(SUMOVehicle& veh, double /* lastPos */, Notification reason, const MSLane* /* enteredLane */) {
123  return true;
124  }
125  if (sVehicles.find(veh.getID()) == sVehicles.end()) {
126  WRITE_WARNING("btsender: Can not update position of vehicle '" + veh.getID() + "' which is not on the road.");
127  return true;
128  }
129  const MSVehicle& v = static_cast<MSVehicle&>(veh);
130  sVehicles[veh.getID()]->updates.push_back(VehicleState(veh.getSpeed(), veh.getPosition(), v.getLane()->getID(), veh.getPositionOnLane(), v.getRoutePosition()));
132  sVehicles[veh.getID()]->amOnNet = false;
133  }
134  if (reason >= MSMoveReminder::NOTIFICATION_ARRIVED) {
135  sVehicles[veh.getID()]->amOnNet = false;
136  sVehicles[veh.getID()]->haveArrived = true;
137  }
138  return true;
139 }
140 
141 
142 /****************************************************************************/
143 
int getRoutePosition() const
Definition: MSVehicle.cpp:802
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:83
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:564
~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:65
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:199
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice *> &into)
Build devices for the given vehicle, if needed.
Representation of a vehicle.
Definition: SUMOVehicle.h:66
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)
Adds common command options that allow to assign devices to vehicles.
Definition: MSDevice.cpp:101
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.
Abstract in-vehicle device.
Definition: MSDevice.h:70
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.cpp:115
The vehicle has departed (was inserted into the network)
virtual double getPositionOnLane() const =0
Get the vehicle&#39;s position along the lane.
A storage for options typed value containers)
Definition: OptionsCont.h:98
static void cleanup()
removes remaining vehicleInformation in sVehicles
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:77
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.