Commit 45b8f01d authored by Jean Meurice's avatar Jean Meurice
Browse files

DataType + VehicleBuilder update + Sim Control fix

parent e73aa2ad
Pipeline #336470 passed with stage
in 1 minute
{
"model": "TODO",
"name": "UnnamedCar",
"properties": {
"body": {
......
......@@ -4,7 +4,7 @@ package de.rwth.montisim.simulation.eecomponents.autopilots;
import java.time.Duration;
import java.time.Instant;
import de.rwth.montisim.commons.dynamicinterface.DataType;
import de.rwth.montisim.commons.dynamicinterface.BasicType;
import de.rwth.montisim.commons.utils.Geometry;
import de.rwth.montisim.commons.utils.IPM;
import de.rwth.montisim.commons.utils.Time;
......@@ -12,7 +12,6 @@ import de.rwth.montisim.commons.utils.Vec2;
import de.rwth.montisim.simulation.eecomponents.navigation.Navigation;
import de.rwth.montisim.simulation.eesimulator.actuator.Actuator;
import de.rwth.montisim.simulation.eesimulator.components.EEComponent;
import de.rwth.montisim.simulation.eesimulator.components.EEComponentType;
import de.rwth.montisim.simulation.eesimulator.events.MessageReceiveEvent;
import de.rwth.montisim.simulation.eesimulator.exceptions.EEMessageTypeException;
import de.rwth.montisim.simulation.eesimulator.message.Message;
......@@ -69,9 +68,9 @@ public class JavaAutopilot extends EEComponent {
this.trajYMsg = addInput(Navigation.TRAJECTORY_Y_MSG, Navigation.TRAJECTORY_Y_TYPE);
this.steeringMsg = addOutput(Actuator.SETTER_PREFIX + PowerTrainProperties.STEERING_VALUE_NAME,
DataType.DOUBLE);
this.accelMsg = addOutput(Actuator.SETTER_PREFIX + PowerTrainProperties.GAS_VALUE_NAME, DataType.DOUBLE);
this.brakeMsg = addOutput(Actuator.SETTER_PREFIX + PowerTrainProperties.BRAKING_VALUE_NAME, DataType.DOUBLE);
BasicType.DOUBLE);
this.accelMsg = addOutput(Actuator.SETTER_PREFIX + PowerTrainProperties.GAS_VALUE_NAME, BasicType.DOUBLE);
this.brakeMsg = addOutput(Actuator.SETTER_PREFIX + PowerTrainProperties.BRAKING_VALUE_NAME, BasicType.DOUBLE);
}
@Override
......@@ -339,9 +338,4 @@ public class JavaAutopilot extends EEComponent {
target.set(trajX[index], trajY[index]);
}
@Override
public EEComponentType getComponentType() {
return EEComponentType.COMPUTER;
}
}
\ No newline at end of file
......@@ -6,15 +6,12 @@ import java.time.Duration;
import de.rwth.montisim.commons.utils.json.Typed;
import de.rwth.montisim.simulation.eesimulator.components.BusUserProperties;
import de.rwth.montisim.simulation.eesimulator.components.EEComponentType;
import de.rwth.montisim.simulation.vehicle.VehicleBuilder;
import de.rwth.montisim.simulation.eesimulator.components.EEEventProcessor;
@Typed(JavaAutopilotProperties.TYPE)
public class JavaAutopilotProperties extends BusUserProperties {
public static final String TYPE = "java_autopilot";
static {
VehicleBuilder.registerComponentBuilder(TYPE,
(properties, context) -> new JavaAutopilot((JavaAutopilotProperties) properties));
}
public Duration compute_time = Duration.ZERO;
public transient double maxVehicleAccel;
......@@ -35,16 +32,19 @@ public class JavaAutopilotProperties extends BusUserProperties {
return this;
}
@Override
public EEComponentType getGeneralType() {
return EEComponentType.COMPUTER;
}
@Override
public String getType() {
return TYPE;
}
@Override
public EEEventProcessor build(ComponentBuildContext context) {
return new JavaAutopilot(this);
}
}
\ No newline at end of file
......@@ -3,7 +3,7 @@ package de.rwth.montisim.simulation.eecomponents.autopilots;
import java.time.*;
import de.rwth.montisim.commons.dynamicinterface.DataType;
import de.rwth.montisim.commons.dynamicinterface.BasicType;
import de.rwth.montisim.commons.utils.Time;
import de.rwth.montisim.simulation.eesimulator.actuator.Actuator;
import de.rwth.montisim.simulation.eesimulator.components.*;
......@@ -42,9 +42,9 @@ public class TestAutopilot extends EEComponent {
protected void init() throws EEMessageTypeException {
this.velocityMsg = addInput(TrueVelocity.VALUE_NAME, TrueVelocity.TYPE);
this.steeringMsg = addOutput(Actuator.SETTER_PREFIX + PowerTrainProperties.STEERING_VALUE_NAME,
DataType.DOUBLE);
this.accelMsg = addOutput(Actuator.SETTER_PREFIX + PowerTrainProperties.GAS_VALUE_NAME, DataType.DOUBLE);
this.brakeMsg = addOutput(Actuator.SETTER_PREFIX + PowerTrainProperties.BRAKING_VALUE_NAME, DataType.DOUBLE);
BasicType.DOUBLE);
this.accelMsg = addOutput(Actuator.SETTER_PREFIX + PowerTrainProperties.GAS_VALUE_NAME, BasicType.DOUBLE);
this.brakeMsg = addOutput(Actuator.SETTER_PREFIX + PowerTrainProperties.BRAKING_VALUE_NAME, BasicType.DOUBLE);
}
@Override
......@@ -84,9 +84,4 @@ public class TestAutopilot extends EEComponent {
sendMessage(sendTime, accelMsg, accel);
}
@Override
public EEComponentType getComponentType() {
return EEComponentType.COMPUTER;
}
}
\ No newline at end of file
......@@ -7,16 +7,11 @@ import de.rwth.montisim.commons.utils.json.JsonEntry;
import de.rwth.montisim.commons.utils.json.Typed;
import de.rwth.montisim.simulation.eesimulator.components.BusUserProperties;
import de.rwth.montisim.simulation.eesimulator.components.EEComponentType;
import de.rwth.montisim.simulation.vehicle.VehicleBuilder;
import de.rwth.montisim.simulation.eesimulator.components.EEEventProcessor;
@Typed(TestAutopilotProperties.TYPE)
public class TestAutopilotProperties extends BusUserProperties {
public static final String TYPE = "test_autopilot";
public static final String COMPUTER_TYPE = "test_autopilot";
static {
VehicleBuilder.registerComponentBuilder(TYPE,
(properties, context) -> new TestAutopilot((TestAutopilotProperties) properties));
}
public static enum Mode {
@JsonEntry("circle")
......@@ -57,15 +52,19 @@ public class TestAutopilotProperties extends BusUserProperties {
return new TestAutopilotProperties(Mode.START_STOP, computeTime, maxVehicleAccel, targetVelocity, 0);
}
@Override
public EEComponentType getGeneralType() {
return EEComponentType.COMPUTER;
}
@Override
public String getType() {
return TYPE;
}
@Override
public EEEventProcessor build(ComponentBuildContext context) {
return new TestAutopilot(this);
}
}
\ No newline at end of file
......@@ -4,9 +4,9 @@ package de.rwth.montisim.simulation.eecomponents.navigation;
import java.time.*;
import java.util.*;
import de.rwth.montisim.commons.dynamicinterface.*;
import de.rwth.montisim.commons.dynamicinterface.ArrayType.Dimensionality;
import de.rwth.montisim.commons.map.Path;
import de.rwth.montisim.commons.map.Pathfinding;
import de.rwth.montisim.commons.utils.*;
import de.rwth.montisim.simulation.environment.pathfinding.*;
import de.rwth.montisim.simulation.vehicle.physicalvalues.TruePosition;
import de.rwth.montisim.simulation.eesimulator.components.*;
import de.rwth.montisim.simulation.eesimulator.events.MessageReceiveEvent;
......@@ -33,12 +33,12 @@ public class Navigation extends EEComponent {
public static final String TRAJECTORY_LON_MSG = "trajectory_lon";
public static final String TRAJECTORY_LAT_MSG = "trajectory_lat";
public static final DataType AT_TARGET_POS_TYPE = DataType.BOOLEAN;
public static final DataType CURRENT_TARGET_POS_TYPE = DataType.VEC2;
public static final DataType TRAJECTORY_X_TYPE = new ArrayType(DataType.DOUBLE, Dimensionality.DYNAMIC, 10);
public static final DataType TRAJECTORY_Y_TYPE = TRAJECTORY_X_TYPE;
public static final DataType TRAJECTORY_LON_TYPE = TRAJECTORY_X_TYPE;
public static final DataType TRAJECTORY_LAT_TYPE = TRAJECTORY_X_TYPE;
public static final BasicType AT_TARGET_POS_TYPE = BasicType.BOOLEAN;
public static final BasicType CURRENT_TARGET_POS_TYPE = BasicType.VEC2;
public static final VectorType TRAJECTORY_X_TYPE = new VectorType(BasicType.DOUBLE, 128);
public static final VectorType TRAJECTORY_Y_TYPE = TRAJECTORY_X_TYPE;
public static final VectorType TRAJECTORY_LON_TYPE = TRAJECTORY_X_TYPE;
public static final VectorType TRAJECTORY_LAT_TYPE = TRAJECTORY_X_TYPE;
//MessageInformation gpsPosMsg;
transient MessageInformation truePosMsg;
......@@ -67,11 +67,11 @@ public class Navigation extends EEComponent {
@Override
protected void init() throws EEMessageTypeException {
//this.gpsPosMsg = addInput(GPS_POS_MSG, DataType.VEC2);
//this.gpsPosMsg = addInput(GPS_POS_MSG, BasicType.VEC2);
this.truePosMsg = addInput(TruePosition.VALUE_NAME, TruePosition.TYPE);
this.pushTargetPosMsg = addInput(PUSH_TARGET_POS_MSG, DataType.VEC2, true, true);
this.popTargetPosMsg = addInput(POP_TARGET_POS_MSG, DataType.EMPTY, true, true);
this.pushTargetPosMsg = addInput(PUSH_TARGET_POS_MSG, BasicType.VEC2, true, true);
this.popTargetPosMsg = addInput(POP_TARGET_POS_MSG, BasicType.EMPTY, true, true);
this.atTargetPosMsg = addOutput(AT_TARGET_POS_MSG, AT_TARGET_POS_TYPE);
this.currentTargetPosMsg = addOutput(CURRENT_TARGET_POS_MSG, CURRENT_TARGET_POS_TYPE);
......@@ -113,7 +113,7 @@ public class Navigation extends EEComponent {
}
public void pushTargetPos(Vec2 target){
pushTargetPos(target, simulator.getSimulationTime());
pushTargetPos(target, eesystem.simulator.getSimulationTime());
}
public void pushTargetPos(Vec2 target, Instant time){
......@@ -129,7 +129,7 @@ public class Navigation extends EEComponent {
currentPath = Optional.empty();
if (!currentPos.isPresent()) return;
if (targets.empty()){
sendMessage(time, atTargetPosMsg, new Boolean(true));
sendMessage(time, atTargetPosMsg, Boolean.TRUE);
return;
}
try {
......@@ -214,10 +214,4 @@ public class Navigation extends EEComponent {
return closestIndex;
}
@Override
public EEComponentType getComponentType() {
return EEComponentType.SERVICE;
}
}
\ No newline at end of file
......@@ -4,15 +4,11 @@ package de.rwth.montisim.simulation.eecomponents.navigation;
import de.rwth.montisim.commons.utils.json.Typed;
import de.rwth.montisim.simulation.eesimulator.components.BusUserProperties;
import de.rwth.montisim.simulation.eesimulator.components.EEComponentType;
import de.rwth.montisim.simulation.vehicle.VehicleBuilder;
import de.rwth.montisim.simulation.eesimulator.components.EEEventProcessor;
@Typed(NavigationProperties.TYPE)
public class NavigationProperties extends BusUserProperties {
public static final String TYPE = "navigation";
static {
VehicleBuilder.registerComponentBuilder(TYPE,
(properties, context) -> new Navigation((NavigationProperties) properties, context.pathfinding));
}
public NavigationProperties() {
this.name = "DefaultNavigation";
......@@ -33,4 +29,10 @@ public class NavigationProperties extends BusUserProperties {
return TYPE;
}
@Override
public EEEventProcessor build(ComponentBuildContext context) {
// TODO Auto-generated method stub
return new Navigation(this, context.pathfinding);
}
}
\ No newline at end of file
/* (c) https://github.com/MontiCore/monticore */
package de.rwth.montisim.simulation.eesimulator;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional;
import de.rwth.montisim.commons.eventsimulation.DiscreteEvent;
import de.rwth.montisim.commons.eventsimulation.DiscreteEventSimulator;
import de.rwth.montisim.commons.utils.ParsingException;
import de.rwth.montisim.commons.utils.json.CustomJson;
......@@ -14,12 +14,12 @@ import de.rwth.montisim.commons.utils.json.JsonTraverser.ObjectIterable;
import de.rwth.montisim.commons.utils.json.JsonTraverser.ValueType;
import de.rwth.montisim.commons.utils.json.JsonWriter;
import de.rwth.montisim.commons.utils.json.SerializationContext;
import de.rwth.montisim.commons.utils.json.SerializationException;
import de.rwth.montisim.simulation.eesimulator.components.ComponentManager;
import de.rwth.montisim.simulation.eesimulator.components.EEEventProcessor;
import de.rwth.montisim.simulation.eesimulator.events.EEDiscreteEvent;
import de.rwth.montisim.simulation.eesimulator.events.EEEventType;
import de.rwth.montisim.simulation.eesimulator.events.EEEvent;
import de.rwth.montisim.simulation.eesimulator.events.MessageReceiveEvent;
import de.rwth.montisim.simulation.eesimulator.events.EEDiscreteEvent.EventData;
import de.rwth.montisim.simulation.eesimulator.events.EEEvent.EventData;
import de.rwth.montisim.simulation.eesimulator.exceptions.EESetupErrors;
import de.rwth.montisim.simulation.eesimulator.exceptions.EESetupException;
import de.rwth.montisim.simulation.eesimulator.message.MessagePriorityComparator;
......@@ -34,28 +34,25 @@ import de.rwth.montisim.simulation.eesimulator.message.MessageTypeManager;
*
* For more information on the EE-system, see [docs/eesimulator.md]
*/
public class EESimulator extends DiscreteEventSimulator<EEEventType, EEDiscreteEvent> implements CustomJson {
public class EESystem implements CustomJson {
// Vector<DataType> types = new Vector<>();
// HashMap<DataType, Integer> typeIds = new HashMap<>();
public final DiscreteEventSimulator simulator;
protected final MessagePriorityComparator msgPrioComp;
protected final ComponentManager componentManager;
protected final MessageTypeManager messageTypeManager;
protected final EESetupErrors errors;
private boolean finalized = false;
public EESimulator(MessageTypeManager messageTypeManager) {
public EESystem(DiscreteEventSimulator simulator, MessageTypeManager messageTypeManager) {
this.simulator = simulator;
this.errors = new EESetupErrors();
this.componentManager = new ComponentManager(this.errors);
this.messageTypeManager = messageTypeManager;
this.msgPrioComp = new MessagePriorityComparator(messageTypeManager, componentManager);
}
public void processEvent(EEDiscreteEvent event) {
event.getTarget().process(event);
}
public MessageTypeManager getMessageTypeManager() {
return messageTypeManager;
}
......@@ -69,7 +66,7 @@ public class EESimulator extends DiscreteEventSimulator<EEEventType, EEDiscreteE
}
public void finalizeSetup() throws EESetupException {
componentManager.finalizeSetup();
componentManager.finalizeSetup(messageTypeManager);
errors.throwExceptions();
this.finalized = true;
}
......@@ -84,14 +81,15 @@ public class EESimulator extends DiscreteEventSimulator<EEEventType, EEDiscreteE
public static class EESerializationContext implements SerializationContext {
public final ComponentManager cm;
public final MessageTypeManager mtm;
public EESerializationContext(ComponentManager cm, MessageTypeManager mtm){
public EESerializationContext(ComponentManager cm, MessageTypeManager mtm) {
this.cm = cm;
this.mtm = mtm;
}
}
@Override
public void write(JsonWriter w, SerializationContext context) throws IllegalAccessException {
public void write(JsonWriter w, SerializationContext context) throws SerializationException {
context = new EESerializationContext(componentManager, messageTypeManager);
w.startObject();
w.writeKey(K_COMPONENTS);
......@@ -105,17 +103,17 @@ public class EESimulator extends DiscreteEventSimulator<EEEventType, EEDiscreteE
w.writeKey(K_EVENTS);
w.startArray();
// Save all events -> resolve ids
for (EEDiscreteEvent e : eventList) {
for (DiscreteEvent e : simulator.getEventList()) {
if (!(e instanceof EEEvent)) continue;
if (e instanceof MessageReceiveEvent && ((MessageReceiveEvent)e).invalid) continue;
Json.toJson(w, e.getEventData(), context);
Json.toJson(w, ((EEEvent)e).getEventData(), context);
}
w.endArray();
w.endObject();
}
@Override
public void read(JsonTraverser t, ObjectIterable it, SerializationContext context)
throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
public void read(JsonTraverser t, ObjectIterable it, SerializationContext context) throws SerializationException {
context = new EESerializationContext(componentManager, messageTypeManager);
for (Entry e : t.streamObject()) {
if (e.key.equals(K_COMPONENTS)) {
......@@ -128,7 +126,7 @@ public class EESimulator extends DiscreteEventSimulator<EEEventType, EEDiscreteE
}
} else if (e.key.equals(K_EVENTS)) {
for (ValueType vt : t.streamArray()) {
eventList.offer(Json.instantiateFromJson(t, EventData.class, context).getEvent(componentManager));
simulator.getEventList().offer(Json.instantiateFromJson(t, EventData.class, context).getEvent(componentManager));
}
} else
t.unexpected(e);
......
......@@ -3,14 +3,12 @@ package de.rwth.montisim.simulation.eesimulator.actuator;
import java.util.logging.Logger;
import de.rwth.montisim.commons.dynamicinterface.DataType;
import de.rwth.montisim.commons.dynamicinterface.DataType.Type;
import de.rwth.montisim.commons.simulation.PhysicalValue;
import de.rwth.montisim.commons.dynamicinterface.BasicType;
import de.rwth.montisim.commons.physicalvalue.PhysicalValueDouble;
import de.rwth.montisim.commons.simulation.TimeUpdate;
import de.rwth.montisim.commons.simulation.Updatable;
import de.rwth.montisim.commons.simulation.Updater;
import de.rwth.montisim.simulation.eesimulator.components.EEComponent;
import de.rwth.montisim.simulation.eesimulator.components.EEComponentType;
import de.rwth.montisim.simulation.eesimulator.events.MessageReceiveEvent;
import de.rwth.montisim.simulation.eesimulator.exceptions.EEMessageTypeException;
import de.rwth.montisim.simulation.eesimulator.message.Message;
......@@ -21,23 +19,25 @@ public class Actuator extends EEComponent implements Updatable {
public static final String SETTER_PREFIX = "set_";
public final transient ActuatorProperties properties;
final transient PhysicalValue actuatedValue;
final transient PhysicalValueDouble actuatedValue;
SensorLogic sensor;
public double targetValue;
final transient boolean sendFeedback; // Whether the actuator senses itself and sends its current value on the bus. ~>
// "Sensor enabled"
//transient boolean isDouble;
transient MessageInformation msgInfo;
public Actuator(ActuatorProperties properties, PhysicalValue actuatedValue, Updater updater) {
public Actuator(ActuatorProperties properties, PhysicalValueDouble actuatedValue, Updater updater) {
super(properties);
if (actuatedValue.type.type != Type.DOUBLE && actuatedValue.type.type != Type.FLOAT)
throw new IllegalArgumentException("Actuator can only actuate on float or double values (but here type "
+ actuatedValue.type + " for value " + actuatedValue.name + ")");
// isDouble = actuatedValue.type.equals(BasicType.DOUBLE);
// if (!isDouble && !actuatedValue.type.equals(BasicType.FLOAT))
// throw new IllegalArgumentException("Actuator can only actuate on float or double values (but here type "
// + actuatedValue.type + " for value " + actuatedValue.name + ")");
this.properties = properties;
this.actuatedValue = actuatedValue;
this.targetValue = actuatedValue.type.type == Type.DOUBLE ? (Double) actuatedValue.get()
: (Float) actuatedValue.get();
this.targetValue = actuatedValue.getValue();
// this.targetValue = isDouble ? (Double) actuatedValue.get()
// : (Float) actuatedValue.get();
updater.addUpdatable(this);
this.sendFeedback = properties.sensorProperties.isPresent();
if (sendFeedback)
......@@ -46,7 +46,7 @@ public class Actuator extends EEComponent implements Updatable {
@Override
protected void init() throws EEMessageTypeException {
this.msgInfo = addOptionalInput(SETTER_PREFIX + actuatedValue.name, DataType.DOUBLE, true);
this.msgInfo = addOptionalInput(SETTER_PREFIX + actuatedValue.name, BasicType.DOUBLE, true);
if (sendFeedback)
sensor.init(this);
}
......@@ -60,8 +60,9 @@ public class Actuator extends EEComponent implements Updatable {
// Can be overwritten for more complex actuation behavior
protected void actuate(TimeUpdate newTime) {
double val = actuatedValue.type.type == Type.DOUBLE ? (Double) actuatedValue.get()
: (Float) actuatedValue.get();
// double val = isDouble ? (Double) actuatedValue.get()
// : (Float) actuatedValue.get();
double val = actuatedValue.getValue();
double maxChange = properties.change_rate * newTime.deltaSeconds;
double delta = targetValue - val;
if (Math.abs(delta) > maxChange) {
......@@ -72,7 +73,8 @@ public class Actuator extends EEComponent implements Updatable {
val = properties.max;
if (val < properties.min)
val = properties.min;
actuatedValue.set(actuatedValue.type.type == Type.DOUBLE ? new Double(val) : new Float(val));
//actuatedValue.set(isDouble ? Double.valueOf(val) : Float.valueOf((float)val));
actuatedValue.set(Double.valueOf(val));
}
@Override
......@@ -86,9 +88,4 @@ public class Actuator extends EEComponent implements Updatable {
}
}
@Override
public EEComponentType getComponentType() {
return EEComponentType.ACTUATOR;
}
}
\ No newline at end of file
......@@ -3,10 +3,13 @@ package de.rwth.montisim.simulation.eesimulator.actuator;
import java.util.Optional;
import de.rwth.montisim.commons.physicalvalue.PhysicalValue;
import de.rwth.montisim.commons.physicalvalue.PhysicalValueDouble;
import de.rwth.montisim.commons.utils.json.JsonEntry;
import de.rwth.montisim.commons.utils.json.Typed;
import de.rwth.montisim.simulation.eesimulator.components.BusUserProperties;
import de.rwth.montisim.simulation.eesimulator.components.EEComponentType;
import de.rwth.montisim.simulation.eesimulator.components.EEEventProcessor;
import de.rwth.montisim.simulation.eesimulator.sensor.SensorProperties;
@Typed(ActuatorProperties.TYPE)
......@@ -27,7 +30,8 @@ public class ActuatorProperties extends BusUserProperties {
this.change_rate = changeRate;
}
protected ActuatorProperties() {}
protected ActuatorProperties() {
}
// TODO
// public ActuatorProperties setName(String name) {
......@@ -56,15 +60,21 @@ public class ActuatorProperties extends BusUserProperties {
return this;
}
@Override
public EEComponentType getGeneralType() {
return EEComponentType.ACTUATOR;
}
@Override
public String getType() {
return TYPE;
}
@Override
public EEEventProcessor build(ComponentBuildContext context) {
// TODO physical value name resolve as "config error"
PhysicalValue val = context.physicalValues.getPhysicalValue(physical_value_name);
if (!(val instanceof PhysicalValueDouble)) throw new IllegalArgumentException("Actuators can only work on Double type Physical values");
return new Actuator(this, (PhysicalValueDouble) val, context.componentUpdater);
}
}
\ No newline at end of file
/* (c) https://github.com/MontiCore/monticore */
package de.rwth.montisim.simulation.eesimulator.bridge;
import de.rwth.montisim.commons.eventsimulation.DiscreteEvent;
import de.rwth.montisim.commons.eventsimulation.exceptions.UnexpectedEventException;
import de.rwth.montisim.simulation.eesimulator.components.BusUser;
import de.rwth.montisim.simulation.eesimulator.components.EEComponentType;
import de.rwth.montisim.simulation.eesimulator.events.EEDiscreteEvent;
import de.rwth.montisim.simulation.eesimulator.events.MessageReceiveEvent;
import de.rwth.montisim.simulation.eesimulator.events.MessageSendEvent;
......@@ -18,28 +17,23 @@ public class Bridge extends BusUser {
}
@Override
public EEComponentType getComponentType() {
return EEComponentType.BRIDGE;
}
@Override
public void process(EEDiscreteEvent event) {
switch (event.getEventType()) {
case MESSAGE_SEND:
public void process(DiscreteEvent event) {
int type = event.getType();
if (type == MessageSendEvent.type){
dispatchMessage((MessageSendEvent) event);
break;
case MESSAGE_RECEIVE:
} else if (type == MessageReceiveEvent.type) {
MessageReceiveEvent msgRecvEvent = (MessageReceiveEvent) event;
if (properties.delay.isZero()) {
dispatchMessage(new MessageSendEvent(msgRecvEvent.getEventTime(), null, msgRecvEvent.getMessage()));
dispatchMessage(new MessageSendEvent(this, msgRecvEvent.getEventTime(), msgRecvEvent.getMessage()));
} else {
this.simulator.addEvent(new MessageSendEvent(msgRecvEvent.getEventTime().plus(properties.delay),
this, msgRecvEvent.getMessage()));
}
break;
default:
throw new UnexpectedEventException(this.toString(), event);
this.eesystem.simulator.addEvent(
new MessageSendEvent(
this,
msgRecvEvent.getEventTime().plus(properties.delay),