SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2016 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 #ifdef CHECK_MEMORY_LEAKS
44 #include <foreign/nvwa/debug_new.h>
45 #endif // CHECK_MEMORY_LEAKS
46 
47 
48 // ===========================================================================
49 // static members
50 // ===========================================================================
51 std::map<std::string, MSDevice_BTsender::VehicleInformation*> MSDevice_BTsender::sVehicles;
52 
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
57 // ---------------------------------------------------------------------------
58 // static initialisation methods
59 // ---------------------------------------------------------------------------
60 void
62  insertDefaultAssignmentOptions("btsender", "Communication", oc);
63 }
64 
65 
66 void
67 MSDevice_BTsender::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
69  MSDevice_BTsender* device = new MSDevice_BTsender(v, "btsender_" + v.getID());
70  into.push_back(device);
71  }
72 }
73 
74 void
76  std::map<std::string, MSDevice_BTsender::VehicleInformation*>::iterator i;
77  for (i = sVehicles.begin(); i != sVehicles.end(); i++) {
78  delete i->second;
79  }
80 }
81 
82 
83 // ---------------------------------------------------------------------------
84 // MSDevice_BTsender-methods
85 // ---------------------------------------------------------------------------
86 MSDevice_BTsender::MSDevice_BTsender(SUMOVehicle& holder, const std::string& id)
87  : MSDevice(holder, id) {
88 }
89 
90 
92 }
93 
94 
95 bool
97  if (reason == MSMoveReminder::NOTIFICATION_DEPARTED && sVehicles.find(veh.getID()) == sVehicles.end()) {
98  sVehicles[veh.getID()] = new VehicleInformation(veh.getID());
99  sVehicles[veh.getID()]->route.push_back(veh.getEdge());
100  }
101  if (reason == MSMoveReminder::NOTIFICATION_TELEPORT && sVehicles.find(veh.getID()) != sVehicles.end()) {
102  sVehicles[veh.getID()]->amOnNet = true;
103  }
105  sVehicles[veh.getID()]->route.push_back(veh.getEdge());
106  }
107  const MSVehicle& v = static_cast<MSVehicle&>(veh);
108  sVehicles[veh.getID()]->updates.push_back(VehicleState(veh.getSpeed(), veh.getPosition(), v.getLane()->getID(), veh.getPositionOnLane(), v.getRoutePosition()));
109  return true;
110 }
111 
112 
113 bool
114 MSDevice_BTsender::notifyMove(SUMOVehicle& veh, SUMOReal /* oldPos */, SUMOReal newPos, SUMOReal newSpeed) {
115  if (sVehicles.find(veh.getID()) == sVehicles.end()) {
116  WRITE_WARNING("btsender: Can not update position of vehicle '" + veh.getID() + "' which is not on the road.");
117  return true;
118  }
119  const MSVehicle& v = static_cast<MSVehicle&>(veh);
120  sVehicles[veh.getID()]->updates.push_back(VehicleState(newSpeed, veh.getPosition(), v.getLane()->getID(), newPos, v.getRoutePosition()));
121  return true;
122 }
123 
124 
125 bool
128  return true;
129  }
130  if (sVehicles.find(veh.getID()) == sVehicles.end()) {
131  WRITE_WARNING("btsender: Can not update position of vehicle '" + veh.getID() + "' which is not on the road.");
132  return true;
133  }
134  const MSVehicle& v = static_cast<MSVehicle&>(veh);
135  sVehicles[veh.getID()]->updates.push_back(VehicleState(veh.getSpeed(), veh.getPosition(), v.getLane()->getID(), veh.getPositionOnLane(), v.getRoutePosition()));
137  sVehicles[veh.getID()]->amOnNet = false;
138  }
139  if (reason >= MSMoveReminder::NOTIFICATION_ARRIVED) {
140  sVehicles[veh.getID()]->amOnNet = false;
141  sVehicles[veh.getID()]->haveArrived = true;
142  }
143  return true;
144 }
145 
146 
147 /****************************************************************************/
148 
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:82
~MSDevice_BTsender()
Destructor.
The vehicle arrived at a junction.
bool notifyEnter(SUMOVehicle &veh, Notification reason)
Adds the vehicle to running vehicles if it (re-) enters the network.
virtual SUMOReal getPositionOnLane() const =0
Get the vehicle's position along the lane.
virtual const MSEdge * getEdge() const =0
Returns the edge the vehicle is currently at.
Notification
Definition of a vehicle state.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:200
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
const std::string & getID() const
Returns the id.
Definition: Named.h:66
Representation of a vehicle.
Definition: SUMOVehicle.h:66
A single movement state of the vehicle.
bool notifyLeave(SUMOVehicle &veh, SUMOReal lastPos, Notification reason)
Moves (the known) vehicle from running to arrived vehicles' list.
bool notifyMove(SUMOVehicle &veh, SUMOReal oldPos, SUMOReal newPos, SUMOReal newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
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:94
int getRoutePosition() const
Definition: MSVehicle.cpp:679
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTsender-options.
Abstract in-vehicle device.
Definition: MSDevice.h:69
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.cpp:108
The vehicle has departed (was inserted into the network)
virtual SUMOReal getSpeed() const =0
Returns the vehicle's current speed.
A storage for options typed value containers)
Definition: OptionsCont.h:99
static void cleanup()
removes remaining vehicleInformation in sVehicles
virtual Position getPosition(const SUMOReal offset=0) const =0
Return current position (x/y, cartesian)
#define SUMOReal
Definition: config.h:214
Stores the information of a vehicle.
static std::map< std::string, VehicleInformation * > sVehicles
The list of arrived senders.
MSLane * getLane() const
Returns the lane the vehicle is on.
Definition: MSVehicle.h:487
virtual const std::string & getID() const =0
Get the vehicle's ID.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSDevice * > &into)
Build devices for the given vehicle, if needed.
The vehicle is being teleported.