SUMO - Simulation of Urban MObility
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
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-2013 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
30
#include <
utils/common/TplConvert.h
>
31
#include <
utils/options/OptionsCont.h
>
32
#include <
utils/iodevices/OutputDevice.h
>
33
#include <
utils/common/SUMOVehicle.h
>
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
60
MSDevice_BTsender::insertOptions
(
OptionsCont
& oc) {
61
insertDefaultAssignmentOptions
(
"btsender"
,
"Communication"
, oc);
62
}
63
64
65
void
66
MSDevice_BTsender::buildVehicleDevices
(
SUMOVehicle
& v, std::vector<MSDevice*>& into) {
67
if
(
equippedByDefaultAssignmentOptions
(
OptionsCont::getOptions
(),
"btsender"
, v)) {
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
82
MSDevice_BTsender::~MSDevice_BTsender
() {
83
}
84
85
86
bool
87
MSDevice_BTsender::notifyEnter
(
SUMOVehicle
& veh,
Notification
reason) {
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
112
MSDevice_BTsender::notifyLeave
(
SUMOVehicle
& veh,
SUMOReal
/* lastPos */
,
Notification
reason) {
113
if
(reason <
MSMoveReminder::NOTIFICATION_TELEPORT
) {
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
));
123
if
(reason >=
MSMoveReminder::NOTIFICATION_TELEPORT
) {
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
home
delphi
sumo
src
microsim
devices
MSDevice_BTsender.cpp
Generated by
1.8.2