SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSDevice_BTsender.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // A BT sender
8 /****************************************************************************/
9 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
10 // Copyright (C) 2001-2014 DLR (http://www.dlr.de/) and contributors
11 /****************************************************************************/
12 //
13 // This file is part of SUMO.
14 // SUMO is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
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 #ifdef CHECK_MEMORY_LEAKS
43 #include <foreign/nvwa/debug_new.h>
44 #endif // CHECK_MEMORY_LEAKS
45 
46 
47 // ===========================================================================
48 // static members
49 // ===========================================================================
50 std::map<std::string, MSDevice_BTsender::VehicleInformation*> MSDevice_BTsender::sVehicles;
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
56 // ---------------------------------------------------------------------------
57 // static initialisation methods
58 // ---------------------------------------------------------------------------
59 void
61  insertDefaultAssignmentOptions("btsender", "Communication", oc);
62 }
63 
64 
65 void
66 MSDevice_BTsender::buildVehicleDevices(SUMOVehicle& v, std::vector<MSDevice*>& into) {
68  MSDevice_BTsender* device = new MSDevice_BTsender(v, "btsender_" + v.getID());
69  into.push_back(device);
70  }
71 }
72 
73 
74 // ---------------------------------------------------------------------------
75 // MSDevice_BTsender-methods
76 // ---------------------------------------------------------------------------
77 MSDevice_BTsender::MSDevice_BTsender(SUMOVehicle& holder, const std::string& id)
78  : MSDevice(holder, id) {
79 }
80 
81 
83 }
84 
85 
86 bool
88  if (reason == MSMoveReminder::NOTIFICATION_DEPARTED && sVehicles.find(veh.getID()) == sVehicles.end()) {
89  sVehicles[veh.getID()] = new VehicleInformation(veh.getID());
90  }
91  sVehicles[veh.getID()]->updates.push_back(VehicleState(
92  MSNet::getInstance()->getCurrentTimeStep(), veh.getSpeed(), static_cast<MSVehicle&>(veh).getAngle(), static_cast<MSVehicle&>(veh).getPosition(), static_cast<MSVehicle&>(veh).getLane()->getID(), veh.getPositionOnLane()
93  ));
94  return true;
95 }
96 
97 
98 bool
99 MSDevice_BTsender::notifyMove(SUMOVehicle& veh, SUMOReal /* oldPos */, SUMOReal newPos, SUMOReal newSpeed) {
100  if (sVehicles.find(veh.getID()) == sVehicles.end()) {
101  WRITE_WARNING("btsender: Can not update position of a vehicle that is not within the road network (" + veh.getID() + ").");
102  return true;
103  }
104  sVehicles[veh.getID()]->updates.push_back(VehicleState(
105  MSNet::getInstance()->getCurrentTimeStep(), newSpeed, static_cast<MSVehicle&>(veh).getAngle(), static_cast<MSVehicle&>(veh).getPosition(), static_cast<MSVehicle&>(veh).getLane()->getID(), newPos
106  ));
107  return true;
108 }
109 
110 
111 bool
114  return true;
115  }
116  if (sVehicles.find(veh.getID()) == sVehicles.end()) {
117  WRITE_WARNING("btsender: Can not update position of a vehicle that is not within the road network (" + veh.getID() + ").");
118  return true;
119  }
120  sVehicles[veh.getID()]->updates.push_back(VehicleState(
121  MSNet::getInstance()->getCurrentTimeStep(), veh.getSpeed(), static_cast<MSVehicle&>(veh).getAngle(), static_cast<MSVehicle&>(veh).getPosition(), static_cast<MSVehicle&>(veh).getLane()->getID(), veh.getPositionOnLane()
122  ));
124  sVehicles[veh.getID()]->amOnNet = false;
125  }
126  if (reason >= MSMoveReminder::NOTIFICATION_ARRIVED) {
127  sVehicles[veh.getID()]->haveArrived = true;
128  }
129  return true;
130 }
131 
132 
133 /****************************************************************************/
134 
Representation of a vehicle in the micro simulation.
Definition: MSVehicle.h:77
~MSDevice_BTsender()
Destructor.
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.
Notification
Definition of a vehicle state.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:154
const MSLane * getLane() const
Returns the lane the reminder works on.
#define WRITE_WARNING(msg)
Definition: MsgHandler.h:196
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
const std::string & getID() const
Returns the id.
Definition: Named.h:60
Representation of a vehicle.
Definition: SUMOVehicle.h:63
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:83
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTsender-options.
Abstract in-vehicle device.
Definition: MSDevice.h:68
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, SUMOVehicle &v)
Determines whether a vehicle should get a certain device.
Definition: MSDevice.cpp:97
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:108
#define SUMOReal
Definition: config.h:215
Stores the information of a vehicle.
static std::map< std::string, VehicleInformation * > sVehicles
The list of arrived senders.
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.