Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2017-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 ChargingStation.cpp 15 : /// @author Jakob Erdmann 16 : /// @date 16.03.2020 17 : /// 18 : // C++ TraCI client API implementation 19 : /****************************************************************************/ 20 : #include <config.h> 21 : 22 : #include <microsim/MSNet.h> 23 : #include <microsim/MSLane.h> 24 : #include <microsim/MSStoppingPlace.h> 25 : #include <libsumo/TraCIConstants.h> 26 : #include "Helper.h" 27 : #include "ChargingStation.h" 28 : 29 : 30 : namespace libsumo { 31 : // =========================================================================== 32 : // static member initializations 33 : // =========================================================================== 34 : SubscriptionResults ChargingStation::mySubscriptionResults; 35 : ContextSubscriptionResults ChargingStation::myContextSubscriptionResults; 36 : 37 : 38 : // =========================================================================== 39 : // static member definitions 40 : // =========================================================================== 41 : std::vector<std::string> 42 206 : ChargingStation::getIDList() { 43 : std::vector<std::string> ids; 44 722 : for (auto& item : MSNet::getInstance()->getStoppingPlaces(SUMO_TAG_CHARGING_STATION)) { 45 516 : ids.push_back(item.first); 46 : } 47 204 : std::sort(ids.begin(), ids.end()); 48 204 : return ids; 49 2 : } 50 : 51 : int 52 5 : ChargingStation::getIDCount() { 53 5 : return (int)getIDList().size(); 54 : } 55 : 56 : 57 : std::string 58 12 : ChargingStation::getLaneID(const std::string& stopID) { 59 12 : return getChargingStation(stopID)->getLane().getID(); 60 : } 61 : 62 : double 63 12 : ChargingStation::getStartPos(const std::string& stopID) { 64 12 : return getChargingStation(stopID)->getBeginLanePosition(); 65 : } 66 : 67 : double 68 12 : ChargingStation::getEndPos(const std::string& stopID) { 69 12 : return getChargingStation(stopID)->getEndLanePosition(); 70 : } 71 : 72 : 73 : std::string 74 12 : ChargingStation::getName(const std::string& stopID) { 75 12 : return getChargingStation(stopID)->getMyName(); 76 : } 77 : 78 : 79 : int 80 120 : ChargingStation::getVehicleCount(const std::string& stopID) { 81 120 : return (int)getChargingStation(stopID)->getStoppedVehicles().size(); 82 : } 83 : 84 : 85 : std::vector<std::string> 86 120 : ChargingStation::getVehicleIDs(const std::string& stopID) { 87 : std::vector<std::string> result; 88 192 : for (const SUMOVehicle* veh : getChargingStation(stopID)->getStoppedVehicles()) { 89 72 : result.push_back(veh->getID()); 90 : } 91 120 : return result; 92 0 : } 93 : 94 : 95 : std::string 96 0 : ChargingStation::getParameter(const std::string& stopID, const std::string& param) { 97 0 : return getChargingStation(stopID)->getParameter(param, ""); 98 : } 99 : 100 : 101 0 : LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(ChargingStation) 102 : 103 : void 104 0 : ChargingStation::setParameter(const std::string& stopID, const std::string& key, const std::string& value) { 105 0 : getChargingStation(stopID)->setParameter(key, value); 106 0 : } 107 : 108 : 109 152 : LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(ChargingStation, CHARGINGSTATION) 110 : 111 : 112 : MSStoppingPlace* 113 288 : ChargingStation::getChargingStation(const std::string& id) { 114 288 : return Helper::getStoppingPlace(id, SUMO_TAG_CHARGING_STATION); 115 : } 116 : 117 : 118 : std::shared_ptr<VariableWrapper> 119 267 : ChargingStation::makeWrapper() { 120 267 : return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults); 121 : } 122 : 123 : 124 : bool 125 320 : ChargingStation::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) { 126 320 : switch (variable) { 127 125 : case TRACI_ID_LIST: 128 125 : return wrapper->wrapStringList(objID, variable, getIDList()); 129 3 : case ID_COUNT: 130 3 : return wrapper->wrapInt(objID, variable, getIDCount()); 131 8 : case VAR_LANE_ID: 132 16 : return wrapper->wrapString(objID, variable, getLaneID(objID)); 133 8 : case VAR_POSITION: 134 8 : return wrapper->wrapDouble(objID, variable, getStartPos(objID)); 135 8 : case VAR_LANEPOSITION: 136 8 : return wrapper->wrapDouble(objID, variable, getEndPos(objID)); 137 8 : case VAR_NAME: 138 16 : return wrapper->wrapString(objID, variable, getName(objID)); 139 80 : case VAR_STOP_STARTING_VEHICLES_NUMBER: 140 80 : return wrapper->wrapInt(objID, variable, getVehicleCount(objID)); 141 80 : case VAR_STOP_STARTING_VEHICLES_IDS: 142 80 : return wrapper->wrapStringList(objID, variable, getVehicleIDs(objID)); 143 0 : case libsumo::VAR_PARAMETER: 144 0 : paramData->readUnsignedByte(); 145 0 : return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString())); 146 0 : case libsumo::VAR_PARAMETER_WITH_KEY: 147 0 : paramData->readUnsignedByte(); 148 0 : return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString())); 149 : default: 150 : return false; 151 : } 152 : } 153 : 154 : } 155 : 156 : 157 : /****************************************************************************/