Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
libsumo/ChargingStation.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2017-2023 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/****************************************************************************/
18// C++ TraCI client API implementation
19/****************************************************************************/
20#include <config.h>
21
22#include <microsim/MSNet.h>
23#include <microsim/MSLane.h>
26#include "Helper.h"
27#include "ChargingStation.h"
28
29
30namespace libsumo {
31// ===========================================================================
32// static member initializations
33// ===========================================================================
34SubscriptionResults ChargingStation::mySubscriptionResults;
35ContextSubscriptionResults ChargingStation::myContextSubscriptionResults;
36
37
38// ===========================================================================
39// static member definitions
40// ===========================================================================
41std::vector<std::string>
42ChargingStation::getIDList() {
43 std::vector<std::string> ids;
44 for (auto& item : MSNet::getInstance()->getStoppingPlaces(SUMO_TAG_CHARGING_STATION)) {
45 ids.push_back(item.first);
46 }
47 std::sort(ids.begin(), ids.end());
48 return ids;
49}
50
51int
52ChargingStation::getIDCount() {
53 return (int)getIDList().size();
54}
55
56
57std::string
58ChargingStation::getLaneID(const std::string& stopID) {
59 return getChargingStation(stopID)->getLane().getID();
60}
61
62double
63ChargingStation::getStartPos(const std::string& stopID) {
64 return getChargingStation(stopID)->getBeginLanePosition();
65}
66
67double
68ChargingStation::getEndPos(const std::string& stopID) {
69 return getChargingStation(stopID)->getEndLanePosition();
70}
71
72
73std::string
74ChargingStation::getName(const std::string& stopID) {
75 return getChargingStation(stopID)->getMyName();
76}
77
78
79int
80ChargingStation::getVehicleCount(const std::string& stopID) {
81 return (int)getChargingStation(stopID)->getStoppedVehicles().size();
82}
83
84
85std::vector<std::string>
86ChargingStation::getVehicleIDs(const std::string& stopID) {
87 std::vector<std::string> result;
88 for (const SUMOVehicle* veh : getChargingStation(stopID)->getStoppedVehicles()) {
89 result.push_back(veh->getID());
90 }
91 return result;
92}
93
94
95std::string
96ChargingStation::getParameter(const std::string& stopID, const std::string& param) {
97 return getChargingStation(stopID)->getParameter(param, "");
98}
99
100
102
103void
104ChargingStation::setParameter(const std::string& stopID, const std::string& key, const std::string& value) {
105 getChargingStation(stopID)->setParameter(key, value);
106}
107
108
110
111
113ChargingStation::getChargingStation(const std::string& id) {
115}
116
117
118std::shared_ptr<VariableWrapper>
119ChargingStation::makeWrapper() {
120 return std::make_shared<Helper::SubscriptionWrapper>(handleVariable, mySubscriptionResults, myContextSubscriptionResults);
121}
122
123
124bool
125ChargingStation::handleVariable(const std::string& objID, const int variable, VariableWrapper* wrapper, tcpip::Storage* paramData) {
126 switch (variable) {
127 case TRACI_ID_LIST:
128 return wrapper->wrapStringList(objID, variable, getIDList());
129 case ID_COUNT:
130 return wrapper->wrapInt(objID, variable, getIDCount());
131 case VAR_LANE_ID:
132 return wrapper->wrapString(objID, variable, getLaneID(objID));
133 case VAR_POSITION:
134 return wrapper->wrapDouble(objID, variable, getStartPos(objID));
135 case VAR_LANEPOSITION:
136 return wrapper->wrapDouble(objID, variable, getEndPos(objID));
137 case VAR_NAME:
138 return wrapper->wrapString(objID, variable, getName(objID));
140 return wrapper->wrapInt(objID, variable, getVehicleCount(objID));
142 return wrapper->wrapStringList(objID, variable, getVehicleIDs(objID));
144 paramData->readUnsignedByte();
145 return wrapper->wrapString(objID, variable, getParameter(objID, paramData->readString()));
147 paramData->readUnsignedByte();
148 return wrapper->wrapStringPair(objID, variable, getParameterWithKey(objID, paramData->readString()));
149 default:
150 return false;
151 }
152}
153
154}
155
156
157/****************************************************************************/
@ CHARGINGSTATION
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
#define LIBSUMO_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOM)
Definition TraCIDefs.h:76
#define LIBSUMO_GET_PARAMETER_WITH_KEY_IMPLEMENTATION(CLASS)
Definition TraCIDefs.h:123
C++ TraCI client API implementation.
The simulated network and simulation perfomer.
Definition MSNet.h:88
A lane area vehicles can halt at.
Representation of a vehicle.
Definition SUMOVehicle.h:62
static MSStoppingPlace * getStoppingPlace(const std::string &id, const SumoXMLTag type)
Definition Helper.cpp:527
virtual std::string readString()
Definition storage.cpp:180
virtual int readUnsignedByte()
Definition storage.cpp:155
TRACI_CONST int VAR_NAME
TRACI_CONST int VAR_STOP_STARTING_VEHICLES_NUMBER
TRACI_CONST int TRACI_ID_LIST
std::map< std::string, libsumo::SubscriptionResults > ContextSubscriptionResults
Definition TraCIDefs.h:338
TRACI_CONST int VAR_POSITION
std::map< std::string, libsumo::TraCIResults > SubscriptionResults
{object->{variable->value}}
Definition TraCIDefs.h:337
TRACI_CONST int ID_COUNT
TRACI_CONST int VAR_PARAMETER
TRACI_CONST int VAR_LANEPOSITION
TRACI_CONST int VAR_LANE_ID
TRACI_CONST int VAR_PARAMETER_WITH_KEY
TRACI_CONST int VAR_STOP_STARTING_VEHICLES_IDS