Line data Source code
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 : /****************************************************************************/ 14 : /// @file MSDevice_BTsender.cpp 15 : /// @author Daniel Krajzewicz 16 : /// @author Michael Behrisch 17 : /// @date 14.08.2013 18 : /// 19 : // A BT sender 20 : /****************************************************************************/ 21 : #include <config.h> 22 : 23 : #include <utils/common/StringUtils.h> 24 : #include <utils/options/OptionsCont.h> 25 : #include <utils/iodevices/OutputDevice.h> 26 : #include <utils/vehicle/SUMOVehicle.h> 27 : #include <microsim/MSNet.h> 28 : #include <microsim/MSLane.h> 29 : #include <microsim/MSEdge.h> 30 : #include <microsim/MSVehicle.h> 31 : #include <microsim/transportables/MSTransportable.h> 32 : #include "MSDevice_Tripinfo.h" 33 : #include "MSDevice_BTsender.h" 34 : #include "MSDevice_BTreceiver.h" 35 : 36 : 37 : // =========================================================================== 38 : // static members 39 : // =========================================================================== 40 : std::map<std::string, MSDevice_BTsender::VehicleInformation*> MSDevice_BTsender::sVehicles; 41 : 42 : 43 : // =========================================================================== 44 : // method definitions 45 : // =========================================================================== 46 : // --------------------------------------------------------------------------- 47 : // static initialisation methods 48 : // --------------------------------------------------------------------------- 49 : void 50 36320 : MSVehicleDevice_BTsender::insertOptions(OptionsCont& oc) { 51 72640 : insertDefaultAssignmentOptions("btsender", "Communication", oc); 52 36320 : } 53 : 54 : 55 : void 56 4658946 : MSVehicleDevice_BTsender::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) { 57 9317892 : if (equippedByDefaultAssignmentOptions(OptionsCont::getOptions(), "btsender", v, false)) { 58 366 : MSVehicleDevice_BTsender* device = new MSVehicleDevice_BTsender(v, "btsender_" + v.getID()); 59 366 : into.push_back(device); 60 : } 61 4658946 : } 62 : 63 : void 64 36320 : MSTransportableDevice_BTsender::insertOptions(OptionsCont& oc) { 65 72640 : insertDefaultAssignmentOptions("btsender", "Communication", oc, true); 66 36320 : } 67 : 68 : 69 : void 70 456422 : MSTransportableDevice_BTsender::buildDevices(MSTransportable& t, std::vector<MSTransportableDevice*>& into) { 71 912844 : if (equippedByDefaultAssignmentOptions(OptionsCont::getOptions(), "btsender", t, false, true)) { 72 132 : MSTransportableDevice_BTsender* device = new MSTransportableDevice_BTsender(t, "btsender_" + t.getID()); 73 132 : into.push_back(device); 74 : MSDevice_BTreceiver::hasSendingPersons(); 75 : } 76 456422 : } 77 : 78 : void 79 35155 : MSDevice_BTsender::cleanup() { 80 : std::map<std::string, MSDevice_BTsender::VehicleInformation*>::iterator i; 81 35329 : for (i = sVehicles.begin(); i != sVehicles.end(); i++) { 82 174 : delete i->second; 83 : } 84 35155 : } 85 : 86 : 87 : // --------------------------------------------------------------------------- 88 : // MSDevice_BTsender-methods 89 : // --------------------------------------------------------------------------- 90 : 91 : 92 498 : MSDevice_BTsender::~MSDevice_BTsender() { 93 498 : } 94 : 95 : std::string 96 373936 : MSDevice_BTsender::getLocation(const SUMOTrafficObject& o) { 97 373936 : return o.getLane() == nullptr ? o.getEdge()->getID() : o.getLane()->getID(); 98 : } 99 : 100 : bool 101 4182 : MSDevice_BTsender::notifyEnter(SUMOTrafficObject& veh, MSMoveReminder::Notification reason, const MSLane* /* enteredLane */) { 102 4182 : if (reason == MSMoveReminder::NOTIFICATION_DEPARTED && sVehicles.find(veh.getID()) == sVehicles.end()) { 103 498 : sVehicles[veh.getID()] = new VehicleInformation(veh.getID()); 104 498 : sVehicles[veh.getID()]->route.push_back(veh.getEdge()); 105 : } 106 4182 : if (reason == MSMoveReminder::NOTIFICATION_TELEPORT && sVehicles.find(veh.getID()) != sVehicles.end()) { 107 0 : sVehicles[veh.getID()]->amOnNet = true; 108 : } 109 4182 : if (reason == MSMoveReminder::NOTIFICATION_TELEPORT || reason == MSMoveReminder::NOTIFICATION_JUNCTION) { 110 1190 : sVehicles[veh.getID()]->route.push_back(veh.getEdge()); 111 : } 112 8364 : sVehicles[veh.getID()]->updates.push_back(VehicleState(veh.getSpeed(), veh.getPosition(), getLocation(veh), veh.getPositionOnLane(), veh.getRoutePosition())); 113 4182 : return true; 114 : } 115 : 116 : 117 : bool 118 174128 : MSDevice_BTsender::notifyMove(SUMOTrafficObject& veh, double /* oldPos */, double newPos, double newSpeed) { 119 174128 : if (sVehicles.find(veh.getID()) == sVehicles.end()) { 120 0 : WRITE_WARNINGF(TL("btsender: Can not update position of vehicle '%' which is not on the road."), veh.getID()); 121 0 : return true; 122 : } 123 348256 : sVehicles[veh.getID()]->updates.push_back(VehicleState(newSpeed, veh.getPosition(), getLocation(veh), newPos, veh.getRoutePosition())); 124 174128 : return true; 125 : } 126 : 127 : 128 : bool 129 4002 : MSDevice_BTsender::notifyLeave(SUMOTrafficObject& veh, double /* lastPos */, MSMoveReminder::Notification reason, const MSLane* /* enteredLane */) { 130 4002 : if (reason < MSMoveReminder::NOTIFICATION_TELEPORT) { 131 : return true; 132 : } 133 318 : if (sVehicles.find(veh.getID()) == sVehicles.end()) { 134 0 : WRITE_WARNINGF(TL("btsender: Can not update position of vehicle '%' which is not on the road."), veh.getID()); 135 0 : return true; 136 : } 137 636 : sVehicles[veh.getID()]->updates.push_back(VehicleState(veh.getSpeed(), veh.getPosition(), getLocation(veh), veh.getPositionOnLane(), veh.getRoutePosition())); 138 : if (reason >= MSMoveReminder::NOTIFICATION_TELEPORT) { 139 318 : sVehicles[veh.getID()]->amOnNet = false; 140 : } 141 318 : if (reason >= MSMoveReminder::NOTIFICATION_ARRIVED) { 142 318 : sVehicles[veh.getID()]->amOnNet = false; 143 318 : sVehicles[veh.getID()]->haveArrived = true; 144 : } 145 : return true; 146 : } 147 : 148 : 149 : /****************************************************************************/