radio connection update: radio should not be removed from destinations, but instead flagged as interfered.

(and the radio medium will keep delivering data also to interfered destinations to avoid the half-filled RXFIFO problem)

+ minor fix: the received signal strength is the maximum of all sending radio
This commit is contained in:
fros4943 2009-11-25 15:49:58 +00:00
parent 5c67d113c8
commit 451be82efd

View file

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: AbstractRadioMedium.java,v 1.12 2009/10/29 10:31:55 fros4943 Exp $ * $Id: AbstractRadioMedium.java,v 1.13 2009/11/25 15:49:58 fros4943 Exp $
*/ */
package se.sics.cooja.radiomediums; package se.sics.cooja.radiomediums;
@ -124,9 +124,8 @@ public abstract class AbstractRadioMedium extends RadioMedium {
* *
* Determines which radios should receive or be interfered by the transmission. * Determines which radios should receive or be interfered by the transmission.
* *
* @param radio * @param radio Source radio
* Transmitting radio * @return New connection
* @return New registered connection
*/ */
abstract public RadioConnection createConnections(Radio radio); abstract public RadioConnection createConnections(Radio radio);
@ -144,19 +143,25 @@ public abstract class AbstractRadioMedium extends RadioMedium {
/* Set signal strength to strong on destinations */ /* Set signal strength to strong on destinations */
RadioConnection[] conns = getActiveConnections(); RadioConnection[] conns = getActiveConnections();
for (RadioConnection conn : conns) { for (RadioConnection conn : conns) {
if (conn.getSource().getCurrentSignalStrength() < SS_STRONG) {
conn.getSource().setCurrentSignalStrength(SS_STRONG); conn.getSource().setCurrentSignalStrength(SS_STRONG);
}
for (Radio dstRadio : conn.getDestinations()) { for (Radio dstRadio : conn.getDestinations()) {
if (conn.getSource().getCurrentSignalStrength() < SS_STRONG) {
dstRadio.setCurrentSignalStrength(SS_STRONG); dstRadio.setCurrentSignalStrength(SS_STRONG);
} }
} }
}
/* Set signal strength to weak on interfered */ /* Set signal strength to weak on interfered */
for (RadioConnection conn : conns) { for (RadioConnection conn : conns) {
for (Radio intfRadio : conn.getInterfered()) { for (Radio intfRadio : conn.getInterfered()) {
if (intfRadio.getCurrentSignalStrength() < SS_WEAK) {
intfRadio.setCurrentSignalStrength(SS_WEAK); intfRadio.setCurrentSignalStrength(SS_WEAK);
}
if (!intfRadio.isInterfered()) { if (!intfRadio.isInterfered()) {
logger.warn("Radio was not interfered"); /*logger.warn("Radio was not interfered");*/
intfRadio.interfereAnyReception(); intfRadio.interfereAnyReception();
} }
} }
@ -171,29 +176,18 @@ public abstract class AbstractRadioMedium extends RadioMedium {
* @param radio Radio * @param radio Radio
*/ */
private void removeFromActiveConnections(Radio radio) { private void removeFromActiveConnections(Radio radio) {
/* Abort ongoing receptions */ /* This radio must not be a connection source */
if (radio.isReceiving()) {
radio.interfereAnyReception();
radio.signalReceptionEnd();
}
/* Connection source */
RadioConnection connection = getActiveConnectionFrom(radio); RadioConnection connection = getActiveConnectionFrom(radio);
if (connection != null) { if (connection != null) {
for (Radio dstRadio : connection.getDestinations()) { logger.fatal("Connection source turned off radio: " + radio);
dstRadio.interfereAnyReception();
dstRadio.signalReceptionEnd();
}
for (Radio dstRadio : connection.getInterfered()) {
dstRadio.signalReceptionEnd();
}
activeConnections.remove(connection);
} }
/* Connection destination and interfered */ /* Set interfered if currently a connection destination */
for (RadioConnection conn : activeConnections) { for (RadioConnection conn : activeConnections) {
conn.removeDestination(radio); if (conn.isDestination(radio)) {
conn.removeInterfered(radio); conn.addInterfered(radio);
}
radio.interfereAnyReception();
} }
} }
@ -243,9 +237,20 @@ public abstract class AbstractRadioMedium extends RadioMedium {
} else if (event == Radio.RadioEvent.TRANSMISSION_STARTED) { } else if (event == Radio.RadioEvent.TRANSMISSION_STARTED) {
/* Create new radio connection */ /* Create new radio connection */
if (radio.isReceiving()) {
/* Radio starts transmitting when it should be receiving!
* Ok, but it won't receive the packet */
for (RadioConnection conn : activeConnections) {
if (conn.isDestination(radio)) {
conn.addInterfered(radio);
}
}
radio.interfereAnyReception();
}
RadioConnection newConnection = createConnections(radio); RadioConnection newConnection = createConnections(radio);
activeConnections.add(newConnection); activeConnections.add(newConnection);
for (Radio r: newConnection.getDestinations()) { for (Radio r: newConnection.getAllDestinations()) {
if (newConnection.getDestinationDelay(r) == 0) { if (newConnection.getDestinationDelay(r) == 0) {
r.signalReceptionStart(); r.signalReceptionStart();
} else { } else {
@ -284,8 +289,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
activeConnections.remove(connection); activeConnections.remove(connection);
lastConnection = connection; lastConnection = connection;
COUNTER_TX++; COUNTER_TX++;
for (Radio dstRadio : connection.getDestinations()) { for (Radio dstRadio : connection.getAllDestinations()) {
COUNTER_RX++;
if (connection.getDestinationDelay(dstRadio) == 0) { if (connection.getDestinationDelay(dstRadio) == 0) {
dstRadio.signalReceptionEnd(); dstRadio.signalReceptionEnd();
} else { } else {
@ -302,22 +306,11 @@ public abstract class AbstractRadioMedium extends RadioMedium {
simulation.getSimulationTime() + connection.getDestinationDelay(dstRadio)); simulation.getSimulationTime() + connection.getDestinationDelay(dstRadio));
} }
} }
for (Radio intRadio : connection.getInterfered()) { COUNTER_RX += connection.getDestinations().length;
COUNTER_INTERFERED++; COUNTER_INTERFERED += connection.getInterfered().length;
/* Check if radio is still interfered by some other connection */ for (Radio intRadio : connection.getInterferedNonDestinations()) {
boolean stillInterfered = false;
for (RadioConnection conn : getActiveConnections()) {
for (Radio r: conn.getInterfered()) {
if (intRadio == r) {
stillInterfered = true;
break;
}
}
}
if (!stillInterfered) {
intRadio.signalReceptionEnd(); intRadio.signalReceptionEnd();
} }
}
/* Update signal strengths */ /* Update signal strengths */
updateSignalStrengths(); updateSignalStrengths();
@ -341,7 +334,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
return; return;
} }
for (Radio dstRadio : connection.getDestinations()) { for (Radio dstRadio : connection.getAllDestinations()) {
if (!radio.getClass().equals(dstRadio.getClass()) || if (!radio.getClass().equals(dstRadio.getClass()) ||
!(radio instanceof CustomDataRadio)) { !(radio instanceof CustomDataRadio)) {
@ -384,7 +377,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
return; return;
} }
for (Radio dstRadio : connection.getDestinations()) { for (Radio dstRadio : connection.getAllDestinations()) {
if (radio.getClass().equals(dstRadio.getClass()) && if (radio.getClass().equals(dstRadio.getClass()) &&
radio instanceof CustomDataRadio) { radio instanceof CustomDataRadio) {
@ -466,13 +459,8 @@ public abstract class AbstractRadioMedium extends RadioMedium {
radioMediumObservable.deleteObserver(observer); radioMediumObservable.deleteObserver(observer);
} }
public RadioConnection[] getLastTickConnections() { public RadioConnection getLastConnection() {
if (lastConnection == null) { return lastConnection;
return null;
}
/* XXX Method only returns a single connection */
return new RadioConnection[] { lastConnection };
} }
} }