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 /****************************************************************************/
8 // A BT sender
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
11 // Copyright (C) 2013-2014 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 
75 // ---------------------------------------------------------------------------
76 // MSDevice_BTsender-methods
77 // ---------------------------------------------------------------------------
78 MSDevice_BTsender::MSDevice_BTsender(SUMOVehicle& holder, const std::string& id)
79  : MSDevice(holder, id) {
80 }
81 
82 
84 }
85 
86 
87 bool
89  if (reason == MSMoveReminder::NOTIFICATION_DEPARTED && sVehicles.find(veh.getID()) == sVehicles.end()) {
90  sVehicles[veh.getID()] = new VehicleInformation(veh.getID());
91  }
92  sVehicles[veh.getID()]->updates.push_back(VehicleState(
93  MSNet::getInstance()->getCurrentTimeStep(), veh.getSpeed(), static_cast<MSVehicle&>(veh).getAngle(), static_cast<MSVehicle&>(veh).getPosition(), static_cast<MSVehicle&>(veh).getLane()->getID(), veh.getPositionOnLane()
94  ));
95  return true;
96 }
97 
98 
99 bool
100 MSDevice_BTsender::notifyMove(SUMOVehicle& veh, SUMOReal /* oldPos */, SUMOReal newPos, SUMOReal newSpeed) {
101  if (sVehicles.find(veh.getID()) == sVehicles.end()) {
102  WRITE_WARNING("btsender: Can not update position of a vehicle that is not within the road network (" + veh.getID() + ").");
103  return true;
104  }
105  sVehicles[veh.getID()]->updates.push_back(VehicleState(
106  MSNet::getInstance()->getCurrentTimeStep(), newSpeed, static_cast<MSVehicle&>(veh).getAngle(), static_cast<MSVehicle&>(veh).getPosition(), static_cast<MSVehicle&>(veh).getLane()->getID(), newPos
107  ));
108  return true;
109 }
110 
111 
112 bool
115  return true;
116  }
117  if (sVehicles.find(veh.getID()) == sVehicles.end()) {
118  WRITE_WARNING("btsender: Can not update position of a vehicle that is not within the road network (" + veh.getID() + ").");
119  return true;
120  }
121  sVehicles[veh.getID()]->updates.push_back(VehicleState(
122  MSNet::getInstance()->getCurrentTimeStep(), veh.getSpeed(), static_cast<MSVehicle&>(veh).getAngle(), static_cast<MSVehicle&>(veh).getPosition(), static_cast<MSVehicle&>(veh).getLane()->getID(), veh.getPositionOnLane()
123  ));
125  sVehicles[veh.getID()]->amOnNet = false;
126  }
127  if (reason >= MSMoveReminder::NOTIFICATION_ARRIVED) {
128  sVehicles[veh.getID()]->haveArrived = true;
129  }
130  return true;
131 }
132 
133 
134 /****************************************************************************/
135