Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSDevice_BTsender.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2013-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
19// A BT sender
20/****************************************************************************/
21#include <config.h>
22
27#include <microsim/MSNet.h>
28#include <microsim/MSLane.h>
29#include <microsim/MSEdge.h>
30#include <microsim/MSVehicle.h>
32#include "MSDevice_Tripinfo.h"
33#include "MSDevice_BTsender.h"
34#include "MSDevice_BTreceiver.h"
35
36
37// ===========================================================================
38// static members
39// ===========================================================================
40std::map<std::string, MSDevice_BTsender::VehicleInformation*> MSDevice_BTsender::sVehicles;
41
42
43// ===========================================================================
44// method definitions
45// ===========================================================================
46// ---------------------------------------------------------------------------
47// static initialisation methods
48// ---------------------------------------------------------------------------
49void
53
54
55void
56MSVehicleDevice_BTsender::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
58 MSVehicleDevice_BTsender* device = new MSVehicleDevice_BTsender(v, "btsender_" + v.getID());
59 into.push_back(device);
60 }
61}
62
63void
67
68
69void
70MSTransportableDevice_BTsender::buildDevices(MSTransportable& t, std::vector<MSTransportableDevice*>& into) {
71 if (equippedByDefaultAssignmentOptions(OptionsCont::getOptions(), "btsender", t, false, true)) {
73 into.push_back(device);
75 }
76}
77
78void
80 std::map<std::string, MSDevice_BTsender::VehicleInformation*>::iterator i;
81 for (i = sVehicles.begin(); i != sVehicles.end(); i++) {
82 delete i->second;
83 }
84}
85
86
87// ---------------------------------------------------------------------------
88// MSDevice_BTsender-methods
89// ---------------------------------------------------------------------------
90
91
94
95std::string
97 return o.getLane() == nullptr ? o.getEdge()->getID() : o.getLane()->getID();
98}
99
100bool
102 if (reason == MSMoveReminder::NOTIFICATION_DEPARTED && sVehicles.find(veh.getID()) == sVehicles.end()) {
103 sVehicles[veh.getID()] = new VehicleInformation(veh.getID());
104 sVehicles[veh.getID()]->route.push_back(veh.getEdge());
105 }
106 if (reason == MSMoveReminder::NOTIFICATION_TELEPORT && sVehicles.find(veh.getID()) != sVehicles.end()) {
107 sVehicles[veh.getID()]->amOnNet = true;
108 }
110 sVehicles[veh.getID()]->route.push_back(veh.getEdge());
111 }
112 sVehicles[veh.getID()]->updates.push_back(VehicleState(veh.getSpeed(), veh.getPosition(), getLocation(veh), veh.getPositionOnLane(), veh.getRoutePosition()));
113 return true;
114}
115
116
117bool
118MSDevice_BTsender::notifyMove(SUMOTrafficObject& veh, double /* oldPos */, double newPos, double newSpeed) {
119 if (sVehicles.find(veh.getID()) == sVehicles.end()) {
120 WRITE_WARNINGF(TL("btsender: Can not update position of vehicle '%' which is not on the road."), veh.getID());
121 return true;
122 }
123 sVehicles[veh.getID()]->updates.push_back(VehicleState(newSpeed, veh.getPosition(), getLocation(veh), newPos, veh.getRoutePosition()));
124 return true;
125}
126
127
128bool
129MSDevice_BTsender::notifyLeave(SUMOTrafficObject& veh, double /* lastPos */, MSMoveReminder::Notification reason, const MSLane* /* enteredLane */) {
131 return true;
132 }
133 if (sVehicles.find(veh.getID()) == sVehicles.end()) {
134 WRITE_WARNINGF(TL("btsender: Can not update position of vehicle '%' which is not on the road."), veh.getID());
135 return true;
136 }
137 sVehicles[veh.getID()]->updates.push_back(VehicleState(veh.getSpeed(), veh.getPosition(), getLocation(veh), veh.getPositionOnLane(), veh.getRoutePosition()));
139 sVehicles[veh.getID()]->amOnNet = false;
140 }
142 sVehicles[veh.getID()]->amOnNet = false;
143 sVehicles[veh.getID()]->haveArrived = true;
144 }
145 return true;
146}
147
148
149/****************************************************************************/
#define WRITE_WARNINGF(...)
Definition MsgHandler.h:296
#define TL(string)
Definition MsgHandler.h:315
static void hasSendingPersons()
Stores the information of a vehicle.
A single movement state of the vehicle.
bool notifyEnter(SUMOTrafficObject &veh, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Adds the vehicle to running vehicles if it (re-) enters the network.
bool notifyLeave(SUMOTrafficObject &veh, double lastPos, MSMoveReminder::Notification reason, const MSLane *enteredLane=0)
Moves (the known) vehicle from running to arrived vehicles' list.
static std::string getLocation(const SUMOTrafficObject &o)
return either lane or edge id (depending on availability)
~MSDevice_BTsender()
Destructor.
bool notifyMove(SUMOTrafficObject &veh, double oldPos, double newPos, double newSpeed)
Checks whether the reminder still has to be notified about the vehicle moves.
static void cleanup()
removes remaining vehicleInformation in sVehicles
static std::map< std::string, VehicleInformation * > sVehicles
The list of arrived senders.
static void insertDefaultAssignmentOptions(const std::string &deviceName, const std::string &optionsTopic, OptionsCont &oc, const bool isPerson=false)
Adds common command options that allow to assign devices to vehicles.
Definition MSDevice.cpp:155
static bool equippedByDefaultAssignmentOptions(const OptionsCont &oc, const std::string &deviceName, DEVICEHOLDER &v, bool outputOptionSet, const bool isPerson=false)
Determines whether a vehicle should get a certain device.
Definition MSDevice.h:195
Representation of a lane in the micro simulation.
Definition MSLane.h:84
Notification
Definition of a vehicle state.
@ NOTIFICATION_ARRIVED
The vehicle arrived at its destination (is deleted)
@ NOTIFICATION_DEPARTED
The vehicle has departed (was inserted into the network)
@ NOTIFICATION_JUNCTION
The vehicle arrived at a junction.
@ NOTIFICATION_TELEPORT
The vehicle is being teleported.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTsender-options.
static void buildDevices(MSTransportable &t, std::vector< MSTransportableDevice * > &into)
Build devices for the given vehicle, if needed.
static void insertOptions(OptionsCont &oc)
Inserts MSDevice_BTsender-options.
static void buildVehicleDevices(SUMOVehicle &v, std::vector< MSVehicleDevice * > &into)
Build devices for the given vehicle, if needed.
const std::string & getID() const
Returns the id.
Definition Named.h:74
A storage for options typed value containers)
Definition OptionsCont.h:89
static OptionsCont & getOptions()
Retrieves the options.
Representation of a vehicle, person, or container.
virtual const MSLane * getLane() const =0
Returns the lane the object is currently at.
virtual double getSpeed() const =0
Returns the object's current speed.
virtual Position getPosition(const double offset=0) const =0
Return current position (x/y, cartesian)
virtual int getRoutePosition() const =0
return index of edge within route
virtual const MSEdge * getEdge() const =0
Returns the edge the object is currently at.
virtual double getPositionOnLane() const =0
Get the object's position along the lane.
Representation of a vehicle.
Definition SUMOVehicle.h:62