Skip to content

Commit

Permalink
clean(application): clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
kschrab committed Sep 3, 2024
1 parent a21a86f commit e0120de
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.eclipse.mosaic.lib.objects.addressing.AdHocMessageRoutingBuilder;
import org.eclipse.mosaic.lib.objects.communication.AdHocConfiguration;
import org.eclipse.mosaic.lib.objects.communication.InterfaceConfiguration;
import org.eclipse.mosaic.lib.objects.v2x.MessageRouting;
import org.eclipse.mosaic.lib.objects.v2x.V2xMessage;

import org.slf4j.Logger;
Expand Down Expand Up @@ -117,9 +116,7 @@ public Integer sendCam() {
log.warn("sendCAM: Ad hoc communication disabled (!adhocModule.isEnabled()).");
return null;
}

final MessageRouting routing = createMessageRouting().topoBroadCast();
return super.sendCam(routing);
return super.sendCam(createMessageRouting().topoBroadCast());
}

@Override
Expand Down Expand Up @@ -147,6 +144,6 @@ public AdHocMessageRoutingBuilder createMessageRouting() {
throw new UnsupportedOperationException("Cannot send message from senders without a location.");
}
GeoPoint position = ((Locatable) getOwner()).getPosition();
return new AdHocMessageRoutingBuilder(this.getOwner().getId(), position);
return new AdHocMessageRoutingBuilder(getOwner().getId(), position);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@

import org.eclipse.mosaic.fed.application.app.api.os.modules.Locatable;
import org.eclipse.mosaic.interactions.communication.CellularCommunicationConfiguration;
import org.eclipse.mosaic.lib.enums.DestinationType;
import org.eclipse.mosaic.lib.geo.GeoCircle;
import org.eclipse.mosaic.lib.geo.GeoPoint;
import org.eclipse.mosaic.lib.objects.addressing.CellMessageRoutingBuilder;
import org.eclipse.mosaic.lib.objects.communication.CellConfiguration;
import org.eclipse.mosaic.lib.objects.v2x.MessageRouting;
import org.eclipse.mosaic.lib.objects.v2x.V2xMessage;

import org.slf4j.Logger;
Expand Down Expand Up @@ -109,26 +107,44 @@ public Integer sendCam() {
log.warn("sendCAM: Cell communication disabled (!cellModule.isEnabled()).");
return null;
}

if (configuration == null || configuration.getCamConfiguration() == null) {
log.warn("sendCAM: No camConfiguration with addressingMode and geoRadius given.");
return null;
}

CellModuleConfiguration.CellCamConfiguration camConfiguration = configuration.getCamConfiguration();
final MessageRouting routing;
if (camConfiguration.getAddressingMode().equals(DestinationType.CELL_TOPOCAST)) {
routing = createMessageRouting().topoCast(camConfiguration.getTopocastReceiver());
} else {
if (!(getOwner() instanceof Locatable)) {
throw new UnsupportedOperationException("Cannot send CAM for entities without a location.");
}
final GeoCircle destination = new GeoCircle(((Locatable) getOwner()).getPosition(), camConfiguration.getGeoRadius());
if (camConfiguration.getAddressingMode().equals(DestinationType.CELL_GEOCAST)) {
routing = createMessageRouting().geoBroadcastBasedOnUnicast(destination);
} else {
routing = createMessageRouting().geoBroadcastMbms(destination);
}
switch (camConfiguration.getAddressingMode()) {
case CELL_TOPOCAST:
return sendCamViaTopocast(camConfiguration);
case CELL_GEOCAST:
return sendCamViaGeoBroadcast(camConfiguration);
case CELL_GEOCAST_MBMS:
return sendCamViaGeoBroadcastMbms(camConfiguration);
default:
log.warn("sendCam: Unsupported addressing mode {}.", camConfiguration.getAddressingMode());
return null;
}
}

private Integer sendCamViaTopocast(CellModuleConfiguration.CellCamConfiguration camConfiguration) {
return super.sendCam(createMessageRouting().topoCast(camConfiguration.getTopocastReceiver()));
}

private Integer sendCamViaGeoBroadcast(CellModuleConfiguration.CellCamConfiguration camConfiguration) {
if (!(getOwner() instanceof Locatable)) {
throw new UnsupportedOperationException("Cannot send CAM for entities without a location.");
}
final GeoCircle destination = new GeoCircle(((Locatable) getOwner()).getPosition(), camConfiguration.getGeoRadius());
return super.sendCam(createMessageRouting().geoBroadcastBasedOnUnicast(destination));
}

private Integer sendCamViaGeoBroadcastMbms(CellModuleConfiguration.CellCamConfiguration camConfiguration) {
if (!(getOwner() instanceof Locatable)) {
throw new UnsupportedOperationException("Cannot send CAM for entities without a location.");
}
return super.sendCam(routing);
final GeoCircle destination = new GeoCircle(((Locatable) getOwner()).getPosition(), camConfiguration.getGeoRadius());
return super.sendCam(createMessageRouting().geoBroadcastMbms(destination));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ protected AbstractCamSendingApp() {
/**
* Constructor with a configuration class and a configuration filename.
*
* @param configClazz Configuration class defining ETSI specific parameter.
* @param configClass Configuration class defining ETSI specific parameter.
* @param configFileName Configuration filename.
*/
protected AbstractCamSendingApp(Class<? extends CEtsi> configClazz, String configFileName) {
super(configClazz, configFileName);
protected AbstractCamSendingApp(Class<? extends CEtsi> configClass, String configFileName) {
super(configClass, configFileName);
}


Expand Down

0 comments on commit e0120de

Please sign in to comment.