From 290fa8d8b190352458b3dc3907758a1a4f1b9624 Mon Sep 17 00:00:00 2001 From: Georg Date: Tue, 1 Oct 2024 14:09:16 +0200 Subject: [PATCH] fix(tutorial): minor improvements on tutorial applications (#409) * fix: Use own position when logging at which point the route was changed * fix: separate event-tx and message-rx functionality * fix: rather print connections than nodes because that's the more critical information * fix: remove redundant information * refactor: use precise wording, as the route switch may still fail --- .../mosaic/app/tutorial/EventSendingApp.java | 41 +---------- .../app/tutorial/MessageReceivingApp.java | 73 +++++++++++++++++++ .../app/tutorial/WeatherWarningApp.java | 14 ++-- .../Tiergarten/mapping/mapping_config.json | 1 + .../navigation/NavigationModule.java | 2 +- .../lib/objects/vehicle/VehicleRoute.java | 2 +- 6 files changed, 85 insertions(+), 48 deletions(-) create mode 100644 app/tutorials/traffic-light-communication/src/main/java/org/eclipse/mosaic/app/tutorial/MessageReceivingApp.java diff --git a/app/tutorials/traffic-light-communication/src/main/java/org/eclipse/mosaic/app/tutorial/EventSendingApp.java b/app/tutorials/traffic-light-communication/src/main/java/org/eclipse/mosaic/app/tutorial/EventSendingApp.java index 57223c3de..69bebb989 100644 --- a/app/tutorials/traffic-light-communication/src/main/java/org/eclipse/mosaic/app/tutorial/EventSendingApp.java +++ b/app/tutorials/traffic-light-communication/src/main/java/org/eclipse/mosaic/app/tutorial/EventSendingApp.java @@ -16,18 +16,10 @@ package org.eclipse.mosaic.app.tutorial; import org.eclipse.mosaic.app.tutorial.message.IntraVehicleMsg; -import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.AdHocModuleConfiguration; -import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.CamBuilder; -import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.ReceivedAcknowledgement; -import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.ReceivedV2xMessage; import org.eclipse.mosaic.fed.application.app.AbstractApplication; import org.eclipse.mosaic.fed.application.app.api.Application; -import org.eclipse.mosaic.fed.application.app.api.CommunicationApplication; import org.eclipse.mosaic.fed.application.app.api.VehicleApplication; import org.eclipse.mosaic.fed.application.app.api.os.VehicleOperatingSystem; -import org.eclipse.mosaic.interactions.communication.V2xMessageTransmission; -import org.eclipse.mosaic.lib.enums.AdHocChannel; -import org.eclipse.mosaic.lib.enums.SensorType; import org.eclipse.mosaic.lib.objects.vehicle.VehicleData; import org.eclipse.mosaic.lib.util.scheduling.Event; @@ -35,7 +27,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class EventSendingApp extends AbstractApplication implements VehicleApplication, CommunicationApplication { +public class EventSendingApp extends AbstractApplication implements VehicleApplication { /** * Used for choosing a RAND id for the message that is sent intra-vehicle. */ @@ -44,12 +36,6 @@ public class EventSendingApp extends AbstractApplication @Override public void onStartup() { getLog().infoSimTime(this, "Initialize application"); - getOs().getAdHocModule().enable(new AdHocModuleConfiguration() - .addRadio() - .channel(AdHocChannel.CCH) - .power(50) - .create()); - getLog().infoSimTime(this, "Activated AdHoc Module"); } @Override @@ -57,42 +43,19 @@ public void onVehicleUpdated(@Nullable VehicleData previousVehicleData, @Nonnull final List applications = getOs().getApplications(); final IntraVehicleMsg message = new IntraVehicleMsg(getOs().getId(), getRandom().nextInt(0, MAX_ID)); - // Example usage for how to detect sensor readings - if (getOs().getStateOfEnvironmentSensor(SensorType.OBSTACLE) > 0) { - getLog().infoSimTime(this, "Reading sensor"); - } - for (Application application : applications) { final Event event = new Event(getOs().getSimulationTime() + 10, application, message); this.getOs().getEventManager().addEvent(event); } } - @Override - public void onMessageReceived(ReceivedV2xMessage receivedV2xMessage) { - getLog().infoSimTime(this, "Received V2X Message from {}", receivedV2xMessage.getMessage().getRouting().getSource().getSourceName()); - } - @Override public void processEvent(Event event) throws Exception { - getLog().infoSimTime(this, "Received event: {}", getOs().getSimulationTimeMs(), event.getResourceClassSimpleName()); + getLog().infoSimTime(this, "Received event: {}", event.getResourceClassSimpleName()); } @Override public void onShutdown() { getLog().infoSimTime(this, "Shutdown application"); } - - @Override - public void onAcknowledgementReceived(ReceivedAcknowledgement acknowledgedMessage) { - } - - @Override - public void onCamBuilding(CamBuilder camBuilder) { - } - - @Override - public void onMessageTransmitted(V2xMessageTransmission v2xMessageTransmission) { - } - } diff --git a/app/tutorials/traffic-light-communication/src/main/java/org/eclipse/mosaic/app/tutorial/MessageReceivingApp.java b/app/tutorials/traffic-light-communication/src/main/java/org/eclipse/mosaic/app/tutorial/MessageReceivingApp.java new file mode 100644 index 000000000..3f1154fdb --- /dev/null +++ b/app/tutorials/traffic-light-communication/src/main/java/org/eclipse/mosaic/app/tutorial/MessageReceivingApp.java @@ -0,0 +1,73 @@ +/* + * 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: mosaic@fokus.fraunhofer.de + */ + +package org.eclipse.mosaic.app.tutorial; + +import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.AdHocModuleConfiguration; +import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.CamBuilder; +import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.ReceivedAcknowledgement; +import org.eclipse.mosaic.fed.application.ambassador.simulation.communication.ReceivedV2xMessage; +import org.eclipse.mosaic.fed.application.app.AbstractApplication; +import org.eclipse.mosaic.fed.application.app.api.CommunicationApplication; +import org.eclipse.mosaic.fed.application.app.api.os.VehicleOperatingSystem; +import org.eclipse.mosaic.interactions.communication.V2xMessageTransmission; +import org.eclipse.mosaic.lib.enums.AdHocChannel; +import org.eclipse.mosaic.lib.util.scheduling.Event; + +import java.util.List; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +public class MessageReceivingApp extends AbstractApplication implements CommunicationApplication { + + @Override + public void onStartup() { + getLog().infoSimTime(this, "Initialize application"); + getOs().getAdHocModule().enable(new AdHocModuleConfiguration() + .addRadio() + .channel(AdHocChannel.CCH) + .power(50) + .create()); + getLog().infoSimTime(this, "Activated AdHoc Module"); + } + + @Override + public void onShutdown() { + getLog().infoSimTime(this, "Shutdown application"); + } + + @Override + public void processEvent(Event event) throws Exception { + getLog().infoSimTime(this, "Received event: {}", event.getResourceClassSimpleName()); + } + + @Override + public void onMessageReceived(ReceivedV2xMessage receivedV2xMessage) { + getLog().infoSimTime(this, "Received V2X Message from {}", receivedV2xMessage.getMessage().getRouting().getSource().getSourceName()); + } + + @Override + public void onAcknowledgementReceived(ReceivedAcknowledgement acknowledgedMessage) { + } + + @Override + public void onCamBuilding(CamBuilder camBuilder) { + } + + @Override + public void onMessageTransmitted(V2xMessageTransmission v2xMessageTransmission) { + } + +} diff --git a/app/tutorials/weather-warning/src/main/java/org/eclipse/mosaic/app/tutorial/WeatherWarningApp.java b/app/tutorials/weather-warning/src/main/java/org/eclipse/mosaic/app/tutorial/WeatherWarningApp.java index 818b8c4dc..e328edfd9 100644 --- a/app/tutorials/weather-warning/src/main/java/org/eclipse/mosaic/app/tutorial/WeatherWarningApp.java +++ b/app/tutorials/weather-warning/src/main/java/org/eclipse/mosaic/app/tutorial/WeatherWarningApp.java @@ -57,7 +57,7 @@ public class WeatherWarningApp extends AbstractApplication