SUMO - Simulation of Urban MObility
MSDevice_BTsender.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // A BT sender
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2013-2017 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
35 #include <microsim/MSNet.h>
36 #include <microsim/MSLane.h>
37 #include <microsim/MSEdge.h>
38 #include <microsim/MSVehicle.h>
39 #include "MSDevice_Tripinfo.h"
40 #include "MSDevice_BTsender.h"
41 #include "MSDevice_BTreceiver.h"
42 
43 
44 // ===========================================================================
45 // static members
46 // ===========================================================================
47 std::map<std::string, MSDevice_BTsender::VehicleInformation*> MSDevice_BTsender::sVehicles;
48 
49 
50 // ===========================================================================
51 // method definitions
52 // ===========================================================================
53 // ---------------------------------------------------------------------------
54 // static initialisation methods
55 // ---------------------------------------------------------------------------
56 void
58  insertDefaultAssignmentOptions("btsender", "Communication", oc);
59 }
60 
61 
62 void
63 MSDevice_BTsender::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
65  MSDevice_BTsender* device = new MSDevice_BTsender(v, "btsender_" + v.getID());
66  into.push_back(device);
67  }
68 }
69 
70 void
72  std::map<std::string, MSDevice_BTsender::VehicleInformation*>::iterator i;
73  for (i = sVehicles.begin(); i != sVehicles.end(); i++) {
74  delete i->second;
75  }
76 }
77 
78 
79 // ---------------------------------------------------------------------------
80 // MSDevice_BTsender-methods
81 // ---------------------------------------------------------------------------
82 MSDevice_BTsender::MSDevice_BTsender(SUMOVehicle& holder, const std::string& id)
83  : MSDevice(holder, id) {
84 }
85 
86 
88 }
89 
90 
91 bool
92 MSDevice_BTsender::notifyEnter(SUMOVehicle& veh, Notification reason, const MSLane* /* enteredLane */) {
93  if (reason == MSMoveReminder::NOTIFICATION_DEPARTED && sVehicles.find(veh.getID()) == sVehicles.end()) {
94  sVehicles[veh.getID()] = new VehicleInformation(veh.getID());
95  sVehicles[veh.getID()]->route.push_back(veh.getEdge());
96  }
97  if (reason == MSMoveReminder::NOTIFICATION_TELEPORT && sVehicles.find(veh.getID()) != sVehicles.end()) {
98  sVehicles[veh.getID()]->amOnNet = true;
99  }
101  sVehicles[veh.getID()]->route.push_back(veh.getEdge());
102  }
103  const MSVehicle& v = static_cast<MSVehicle&>(veh);
104  sVehicles[veh.getID()]->updates.push_back(VehicleState(veh.getSpeed(), veh.getPosition(), v.getLane()->getID(), veh.getPositionOnLane(), v.getRoutePosition()));
105  return true;
106 }
107 
108 
109 bool
110 MSDevice_BTsender::notifyMove(SUMOVehicle& veh, double /* oldPos */, double newPos, double newSpeed) {
111  if (sVehicles.find(veh.getID()) == sVehicles.end()) {
112  WRITE_WARNING("btsender: Can not update position of vehicle '" + veh.getID() + "' which is not on the road.");
113  return true;
114  }
115  const MSVehicle& v = static_cast<MSVehicle&>(veh);
116  sVehicles[veh.getID()]->updates.push_back(VehicleState(newSpeed, veh.getPosition(), v.getLane()->getID(), newPos, v.getRoutePosition()));
117  return true;
118 }
119 
120 
121 bool
122 MSDevice_BTsender::notifyLeave(SUMOVehicle& veh, double /* lastPos */, Notification reason, const MSLane* /* enteredLane */) {
124  return true;
125  }
126  if (sVehicles.find(veh.getID()) == sVehicles.end()) {
127  WRITE_WARNING("btsender: Can not update position of vehicle '" + veh.getID() + "' which is not on the road.");
128  return true;
129  }
130  const MSVehicle& v = static_cast<MSVehicle&>(veh);
131  sVehicles[veh.getID()]->updates.push_back(VehicleState(veh.getSpeed(), veh.getPosition(), v.getLane()->getID(), veh.getPositionOnLane(), v.getRoutePosition()));
133  sVehicles[veh.getID()]->amOnNet = false;
134  }
135  if (reason >= MSMoveReminder::NOTIFICATION_ARRIVED) {
136  sVehicles[veh.getID()]->amOnNet = false;
137  sVehicles[veh.getID()]->haveArrived = true;
138  }
139  return true;
140 }
141 
142 
143 /****************************************************************************/
144 
int getRoutePosition() const
Definition: MSVehicle.cpp:678
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:488
~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:66
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice *> &into)
Build devices for the given vehicle, if needed.
Representation of a vehicle.
Definition: SUMOVehicle.h:67
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:93
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:71
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.cpp:107
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:99
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:79
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.