Cooja: Refactored AbstractRadioMedium:update(): if -> switch
This commit is contained in:
parent
f34826f3f1
commit
3c9e3e1b95
|
@ -224,48 +224,47 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
|||
Radio radio = (Radio) obs;
|
||||
|
||||
final Radio.RadioEvent event = radio.getLastEvent();
|
||||
if (event == Radio.RadioEvent.RECEPTION_STARTED ||
|
||||
event == Radio.RadioEvent.RECEPTION_INTERFERED ||
|
||||
event == Radio.RadioEvent.RECEPTION_FINISHED ||
|
||||
event == Radio.RadioEvent.UNKNOWN) {
|
||||
/* Ignored */
|
||||
|
||||
switch (event) {
|
||||
case RECEPTION_STARTED:
|
||||
case RECEPTION_INTERFERED:
|
||||
case RECEPTION_FINISHED:
|
||||
case UNKNOWN:
|
||||
return;
|
||||
}
|
||||
|
||||
if (event == Radio.RadioEvent.HW_ON) {
|
||||
|
||||
case HW_ON: {
|
||||
/* Update signal strengths */
|
||||
updateSignalStrengths();
|
||||
|
||||
} else if (event == Radio.RadioEvent.HW_OFF) {
|
||||
|
||||
}
|
||||
break;
|
||||
case HW_OFF: {
|
||||
/* Remove any radio connections from this radio */
|
||||
removeFromActiveConnections(radio);
|
||||
|
||||
/* Update signal strengths */
|
||||
updateSignalStrengths();
|
||||
|
||||
} else if (event == Radio.RadioEvent.TRANSMISSION_STARTED) {
|
||||
}
|
||||
break;
|
||||
case TRANSMISSION_STARTED: {
|
||||
/* Create new radio connection */
|
||||
|
||||
if (radio.isReceiving()) {
|
||||
/* Radio starts transmitting when it should be receiving!
|
||||
* Ok, but it won't receive the packet */
|
||||
/*
|
||||
* Radio starts transmitting when it should be
|
||||
* receiving! Ok, but it won't receive the packet
|
||||
*/
|
||||
radio.interfereAnyReception();
|
||||
for (RadioConnection conn : activeConnections) {
|
||||
if (conn.isDestination(radio)) {
|
||||
conn.addInterfered(radio);
|
||||
}
|
||||
}
|
||||
radio.interfereAnyReception();
|
||||
}
|
||||
|
||||
RadioConnection newConnection = createConnections(radio);
|
||||
activeConnections.add(newConnection);
|
||||
for (Radio r: newConnection.getAllDestinations()) {
|
||||
|
||||
for (Radio r : newConnection.getAllDestinations()) {
|
||||
if (newConnection.getDestinationDelay(r) == 0) {
|
||||
r.signalReceptionStart();
|
||||
} else {
|
||||
|
||||
/* EXPERIMENTAL: Simulating propagation delay */
|
||||
final Radio delayedRadio = r;
|
||||
TimeEvent delayedEvent = new TimeEvent(0) {
|
||||
|
@ -273,21 +272,18 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
|||
delayedRadio.signalReceptionStart();
|
||||
}
|
||||
};
|
||||
simulation.scheduleEvent(
|
||||
delayedEvent,
|
||||
simulation.getSimulationTime() + newConnection.getDestinationDelay(r));
|
||||
simulation.scheduleEvent(delayedEvent, simulation.getSimulationTime() + newConnection.getDestinationDelay(r));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* Update signal strengths */
|
||||
} /* Update signal strengths */
|
||||
updateSignalStrengths();
|
||||
|
||||
/* Notify observers */
|
||||
lastConnection = null;
|
||||
radioMediumObservable.setRadioMediumChangedAndNotify();
|
||||
|
||||
} else if (event == Radio.RadioEvent.TRANSMISSION_FINISHED) {
|
||||
}
|
||||
break;
|
||||
case TRANSMISSION_FINISHED: {
|
||||
/* Remove radio connection */
|
||||
|
||||
/* Connection */
|
||||
|
@ -312,8 +308,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
|||
delayedRadio.signalReceptionEnd();
|
||||
}
|
||||
};
|
||||
simulation.scheduleEvent(
|
||||
delayedEvent,
|
||||
simulation.scheduleEvent(delayedEvent,
|
||||
simulation.getSimulationTime() + connection.getDestinationDelay(dstRadio));
|
||||
}
|
||||
}
|
||||
|
@ -328,8 +323,9 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
|||
|
||||
/* Notify observers */
|
||||
radioMediumObservable.setRadioMediumChangedAndNotify();
|
||||
|
||||
} else if (event == Radio.RadioEvent.CUSTOM_DATA_TRANSMITTED) {
|
||||
}
|
||||
break;
|
||||
case CUSTOM_DATA_TRANSMITTED: {
|
||||
|
||||
/* Connection */
|
||||
RadioConnection connection = getActiveConnectionFrom(radio);
|
||||
|
@ -347,8 +343,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
|||
|
||||
for (Radio dstRadio : connection.getAllDestinations()) {
|
||||
|
||||
if (!radio.getClass().equals(dstRadio.getClass()) ||
|
||||
!(radio instanceof CustomDataRadio)) {
|
||||
if (!radio.getClass().equals(dstRadio.getClass()) || !(radio instanceof CustomDataRadio)) {
|
||||
/* Radios communicate via radio packets */
|
||||
continue;
|
||||
}
|
||||
|
@ -365,15 +360,15 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
|||
delayedRadio.receiveCustomData(delayedData);
|
||||
}
|
||||
};
|
||||
simulation.scheduleEvent(
|
||||
delayedEvent,
|
||||
simulation.scheduleEvent(delayedEvent,
|
||||
simulation.getSimulationTime() + connection.getDestinationDelay(dstRadio));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} else if (event == Radio.RadioEvent.PACKET_TRANSMITTED) {
|
||||
|
||||
}
|
||||
break;
|
||||
case PACKET_TRANSMITTED: {
|
||||
/* Connection */
|
||||
RadioConnection connection = getActiveConnectionFrom(radio);
|
||||
if (connection == null) {
|
||||
|
@ -390,8 +385,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
|||
|
||||
for (Radio dstRadio : connection.getAllDestinations()) {
|
||||
|
||||
if (radio.getClass().equals(dstRadio.getClass()) &&
|
||||
radio instanceof CustomDataRadio) {
|
||||
if (radio.getClass().equals(dstRadio.getClass()) && radio instanceof CustomDataRadio) {
|
||||
/* Radios instead communicate via custom data objects */
|
||||
continue;
|
||||
}
|
||||
|
@ -409,14 +403,14 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
|||
delayedRadio.setReceivedPacket(delayedPacket);
|
||||
}
|
||||
};
|
||||
simulation.scheduleEvent(
|
||||
delayedEvent,
|
||||
simulation.scheduleEvent(delayedEvent,
|
||||
simulation.getSimulationTime() + connection.getDestinationDelay(dstRadio));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
logger.fatal("Unsupported radio event: " + event);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue