Skip to content

feat(charging): provide the charging stations within a certain area #446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ buildNumber.properties
*.log
credentials.cached
*.lcs
.tiles
.tiles
/logs/
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.mosaic.interactions.communication.V2xFullMessageReception;
import org.eclipse.mosaic.interactions.communication.V2xMessageAcknowledgement;
import org.eclipse.mosaic.interactions.communication.V2xMessageReception;
import org.eclipse.mosaic.interactions.electricity.ChargingStationDiscoveryResponse;
import org.eclipse.mosaic.interactions.electricity.ChargingStationUpdate;
import org.eclipse.mosaic.interactions.electricity.VehicleBatteryUpdates;
import org.eclipse.mosaic.interactions.electricity.VehicleChargingDenial;
Expand Down Expand Up @@ -304,6 +305,8 @@ protected void processInteraction(final Interaction interaction) throws Internal
this.process((LidarUpdates) interaction);
} else if (interaction.getTypeId().startsWith(VehicleBatteryUpdates.TYPE_ID)) {
this.process((VehicleBatteryUpdates) interaction);
} else if (interaction.getTypeId().startsWith(ChargingStationDiscoveryResponse.TYPE_ID)) {
this.process((ChargingStationDiscoveryResponse) interaction);
} else if (interaction.getTypeId().startsWith(VehicleRoutesInitialization.TYPE_ID)) {
this.process((VehicleRoutesInitialization) interaction);
} else if (interaction.getTypeId().startsWith(VehicleTypesInitialization.TYPE_ID)) {
Expand Down Expand Up @@ -335,6 +338,20 @@ private void process(final VehicleBatteryUpdates vehicleBatteryUpdates) {
}
}


private void process(final ChargingStationDiscoveryResponse response) {
final AbstractSimulationUnit simulationUnit = UnitSimulator.UnitSimulator.getUnitFromId(response.getVehicleId());
if (simulationUnit == null) {
return;
}
final Event event = new Event(
response.getTime(),
simulationUnit,
response,
EventNicenessPriorityRegister.CHARGING_STATIONS_DISCOVERY
);
addEvent(event);
}
private void process(final VehicleTypesInitialization vehicleTypesInitialization) {
SimulationKernel.SimulationKernel.getVehicleTypes().putAll(vehicleTypesInitialization.getTypes());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@
import org.eclipse.mosaic.fed.application.ambassador.SimulationKernel;
import org.eclipse.mosaic.fed.application.app.api.ElectricVehicleApplication;
import org.eclipse.mosaic.fed.application.app.api.os.ElectricVehicleOperatingSystem;
import org.eclipse.mosaic.interactions.electricity.ChargingStationDiscoveryResponse;
import org.eclipse.mosaic.interactions.electricity.VehicleChargingDenial;
import org.eclipse.mosaic.interactions.electricity.VehicleChargingStartRequest;
import org.eclipse.mosaic.interactions.electricity.VehicleChargingStationDiscoveryRequest;
import org.eclipse.mosaic.interactions.electricity.VehicleChargingStopRequest;
import org.eclipse.mosaic.lib.geo.GeoArea;
import org.eclipse.mosaic.lib.geo.GeoCircle;
import org.eclipse.mosaic.lib.geo.GeoPoint;
import org.eclipse.mosaic.lib.geo.MutableGeoPoint;
import org.eclipse.mosaic.lib.geo.Polygon;
import org.eclipse.mosaic.lib.objects.vehicle.BatteryData;
import org.eclipse.mosaic.lib.objects.vehicle.VehicleType;

Expand Down Expand Up @@ -51,6 +57,12 @@ private void onVehicleChargingDenial(final VehicleChargingDenial vehicleCharging
}
}

private void onCharginStationDiscoveryResponse(ChargingStationDiscoveryResponse response) {
for (ElectricVehicleApplication application: getApplicationsIterator(ElectricVehicleApplication.class)) {
application.onChargingStationDiscoveryResponse(response);
}
}

@Override
protected boolean handleEventResource(Object resource, long eventType) {
if (resource instanceof BatteryData data) {
Expand All @@ -63,6 +75,11 @@ protected boolean handleEventResource(Object resource, long eventType) {
return true;
}

if (resource instanceof ChargingStationDiscoveryResponse response) {
onCharginStationDiscoveryResponse((ChargingStationDiscoveryResponse) response);
return true;
}

return super.handleEventResource(resource, eventType);
}

Expand Down Expand Up @@ -103,4 +120,12 @@ public void sendChargingStopRequest() {
);
sendInteractionToRti(vehicleChargingStopRequest);
}

public void sendChargingStationDiscoveryRequest(GeoCircle searchArea) {
VehicleChargingStationDiscoveryRequest request = new VehicleChargingStationDiscoveryRequest(
this.getSimulationTime(),
this.getId(),
searchArea);
sendInteractionToRti(request);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ public class EventNicenessPriorityRegister {

// batteryUpdated
public final static long BATTERY_UPDATED = -99_998_900;

// discover charging stations
public final static long CHARGING_STATIONS_DISCOVERY = -99_998_900;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package org.eclipse.mosaic.fed.application.app.api;

import org.eclipse.mosaic.interactions.electricity.ChargingStationDiscoveryResponse;
import org.eclipse.mosaic.interactions.electricity.VehicleChargingDenial;
import org.eclipse.mosaic.lib.objects.vehicle.BatteryData;

Expand Down Expand Up @@ -42,4 +43,6 @@ public interface ElectricVehicleApplication extends VehicleApplication, Applicat
* @param vehicleChargingDenial The interaction containing further information about the rejected charging request
*/
void onVehicleChargingDenial(final VehicleChargingDenial vehicleChargingDenial);

void onChargingStationDiscoveryResponse(ChargingStationDiscoveryResponse response);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package org.eclipse.mosaic.fed.application.app.api.os;

import org.eclipse.mosaic.lib.geo.GeoCircle;
import org.eclipse.mosaic.lib.objects.vehicle.BatteryData;

import javax.annotation.Nullable;
Expand Down Expand Up @@ -45,4 +46,11 @@ public interface ElectricVehicleOperatingSystem extends VehicleOperatingSystem {
* Sends a request to stop charging the battery of the vehicle.
*/
void sendChargingStopRequest();

/**
* Sends a request to locate all charging stations in the provided area.
*
* @param searchArea The area where the charging stations are search
*/
void sendChargingStationDiscoveryRequest(GeoCircle searchArea);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.mosaic.fed.application.app.empty.ElectricVehicleNoopApp;
import org.eclipse.mosaic.interactions.application.ApplicationInteraction;
import org.eclipse.mosaic.interactions.communication.V2xMessageTransmission;
import org.eclipse.mosaic.interactions.electricity.ChargingStationDiscoveryResponse;
import org.eclipse.mosaic.interactions.electricity.VehicleChargingDenial;
import org.eclipse.mosaic.lib.objects.traffic.SumoTraciResult;
import org.eclipse.mosaic.lib.objects.vehicle.BatteryData;
Expand Down Expand Up @@ -108,6 +109,11 @@ public void onVehicleChargingDenial(VehicleChargingDenial vehicleChargingDenial)
thisApplicationSpy.onVehicleChargingDenial(vehicleChargingDenial);
}

@Override
public void onChargingStationDiscoveryResponse(ChargingStationDiscoveryResponse response) {

}

@Override
public void onVehicleUpdated(@Nullable VehicleData previousVehicleData, @Nonnull VehicleData updatedVehicleData) {
thisApplicationSpy.onVehicleUpdated(previousVehicleData, updatedVehicleData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.mosaic.fed.application.app.api.os.ElectricVehicleOperatingSystem;
import org.eclipse.mosaic.interactions.application.ApplicationInteraction;
import org.eclipse.mosaic.interactions.communication.V2xMessageTransmission;
import org.eclipse.mosaic.interactions.electricity.ChargingStationDiscoveryResponse;
import org.eclipse.mosaic.interactions.electricity.VehicleChargingDenial;
import org.eclipse.mosaic.lib.objects.traffic.SumoTraciResult;
import org.eclipse.mosaic.lib.objects.vehicle.BatteryData;
Expand Down Expand Up @@ -70,6 +71,11 @@ public void onBatteryDataUpdated(@Nullable BatteryData previousBatteryData, @Non
public void onVehicleChargingDenial(VehicleChargingDenial vehicleChargingDenial) {
}

@Override
public void onChargingStationDiscoveryResponse(ChargingStationDiscoveryResponse response) {

}

@Override
public void onAcknowledgementReceived(ReceivedAcknowledgement acknowledgedMessage) {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2024 Fraunhofer FOKUS and others. All rights reserved.
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contact: [email protected]
*/

package org.eclipse.mosaic.interactions.electricity;

import static org.apache.commons.lang3.builder.ToStringStyle.SHORT_PREFIX_STYLE;

import org.eclipse.mosaic.lib.objects.electricity.ChargingStationData;
import org.eclipse.mosaic.rti.api.Interaction;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.util.Collection;

/**
* An {@link Interaction} that contains a list of {@link ChargingStationData} objects as a response to a {@link VehicleChargingStationDiscoveryRequest}.
*/
public class ChargingStationDiscoveryResponse extends Interaction {
public ChargingStationDiscoveryResponse(long time, String vehicleId, Collection<ChargingStationData> chargingStations) {
super(time);

this.chargingStations = chargingStations;
this.vehicleId = vehicleId;
}

/**
* String identifying the type of this interaction.
*/
public static final String TYPE_ID = createTypeIdentifier(ChargingStationDiscoveryResponse.class);

/**
* The queried list {@link ChargingStationData} originating from the {@link VehicleChargingStationDiscoveryRequest}.
*/
private final Collection<ChargingStationData> chargingStations;

/**
* The ID of the requesting vehicle.
*/
private final String vehicleId;

public String getVehicleId() {
return vehicleId;
}

public Collection<ChargingStationData> getChargingStations() {
return chargingStations;
}

@Override
public int hashCode() {
return new HashCodeBuilder(9, 97)
.append(vehicleId)
.append(chargingStations)
.toHashCode();
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj.getClass() != getClass()) {
return false;
}

ChargingStationDiscoveryResponse other = (ChargingStationDiscoveryResponse) obj;
return new EqualsBuilder()
.append(this.vehicleId, other.vehicleId)
.append(this.chargingStations, other.chargingStations)
.isEquals();
}

@Override
public String toString() {
return new ToStringBuilder(this, SHORT_PREFIX_STYLE)
.appendSuper(super.toString())
.append("vehicleId", vehicleId)
.append("chargingStations", chargingStations.stream().map(ChargingStationData::toString))
.toString();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright (c) 2024 Fraunhofer FOKUS and others. All rights reserved.
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*
* Contact: [email protected]
*/

package org.eclipse.mosaic.interactions.electricity;

import static org.apache.commons.lang3.builder.ToStringStyle.SHORT_PREFIX_STYLE;

import org.eclipse.mosaic.lib.geo.GeoCircle;
import org.eclipse.mosaic.rti.api.Interaction;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

import java.io.Serial;

/**
* An {@link Interaction} used by electric vehicles to find charging stations ({@link org.eclipse.mosaic.lib.objects.electricity.ChargingStationData}) in a certain area.
*/
public class VehicleChargingStationDiscoveryRequest extends Interaction {
public VehicleChargingStationDiscoveryRequest(long time, String vehicleId, GeoCircle searchArea) {
super(time);

this.vehicleId = vehicleId;
this.searchArea = searchArea;
}

@Serial
private static final long serialVersionUID = 1L;

/**
* String identifying the type of this interaction.
*/
public static final String TYPE_ID = createTypeIdentifier(VehicleChargingStationDiscoveryRequest.class);

/**
* String identifying the vehicle sending this interaction.
*/
private final String vehicleId;

/**
* An area given by a point and a radius in which the requested {@link org.eclipse.mosaic.lib.objects.electricity.ChargingStationData} objects are.
*/
private final GeoCircle searchArea;

public String getVehicleId() {
return vehicleId;
}

public GeoCircle getSearchArea() {
return searchArea;
}

@Override
public int hashCode() {
return new HashCodeBuilder(9, 97)
.append(vehicleId)
.append(searchArea)
.toHashCode();
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (obj == this) {
return true;
}
if (obj.getClass() != getClass()) {
return false;
}

VehicleChargingStationDiscoveryRequest other = (VehicleChargingStationDiscoveryRequest) obj;
return new EqualsBuilder()
.append(this.vehicleId, other.vehicleId)
.append(this.searchArea, other.searchArea)
.isEquals();
}

@Override
public String toString() {
return new ToStringBuilder(this, SHORT_PREFIX_STYLE)
.appendSuper(super.toString())
.append("vehicleId", vehicleId)
.append("searchArea", searchArea)
.toString();
}
}
Loading