Replaced MSPSim interface SkyByteRadio with Msp802154Radio to easier support other 802.15.4 radio chips than CC2420.

This commit is contained in:
Niclas Finne 2012-05-21 17:33:39 +02:00
parent 4c03780e2b
commit 9dd2327f07
6 changed files with 55 additions and 70 deletions

View File

@ -59,7 +59,7 @@ import se.sics.cooja.mspmote.interfaces.Exp5438LED;
import se.sics.cooja.mspmote.interfaces.MspClock; import se.sics.cooja.mspmote.interfaces.MspClock;
import se.sics.cooja.mspmote.interfaces.MspDebugOutput; import se.sics.cooja.mspmote.interfaces.MspDebugOutput;
import se.sics.cooja.mspmote.interfaces.MspMoteID; import se.sics.cooja.mspmote.interfaces.MspMoteID;
import se.sics.cooja.mspmote.interfaces.SkyByteRadio; import se.sics.cooja.mspmote.interfaces.Msp802154Radio;
import se.sics.cooja.mspmote.interfaces.UsciA1Serial; import se.sics.cooja.mspmote.interfaces.UsciA1Serial;
@ClassDescription("TI MSP-EXP430F5438") @ClassDescription("TI MSP-EXP430F5438")
@ -188,7 +188,7 @@ public class Exp5438MoteType extends MspMoteType {
MoteAttributes.class, MoteAttributes.class,
MspClock.class, MspClock.class,
MspMoteID.class, MspMoteID.class,
SkyByteRadio.class, Msp802154Radio.class,
UsciA1Serial.class, UsciA1Serial.class,
Exp5438LED.class, Exp5438LED.class,
/*Exp5438LCD.class,*/ /* TODO */ /*Exp5438LCD.class,*/ /* TODO */

View File

@ -55,6 +55,7 @@ import se.sics.cooja.WatchpointMote;
import se.sics.cooja.interfaces.IPAddress; import se.sics.cooja.interfaces.IPAddress;
import se.sics.cooja.motes.AbstractEmulatedMote; import se.sics.cooja.motes.AbstractEmulatedMote;
import se.sics.cooja.mspmote.interfaces.MspSerial; import se.sics.cooja.mspmote.interfaces.MspSerial;
import se.sics.cooja.mspmote.interfaces.Msp802154Radio;
import se.sics.cooja.mspmote.plugins.CodeVisualizerSkin; import se.sics.cooja.mspmote.plugins.CodeVisualizerSkin;
import se.sics.cooja.mspmote.plugins.MspBreakpoint; import se.sics.cooja.mspmote.plugins.MspBreakpoint;
import se.sics.cooja.plugins.Visualizer; import se.sics.cooja.plugins.Visualizer;
@ -401,6 +402,9 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
if (intfClass.equals("se.sics.cooja.mspmote.interfaces.ESBLog")) { if (intfClass.equals("se.sics.cooja.mspmote.interfaces.ESBLog")) {
intfClass = MspSerial.class.getName(); intfClass = MspSerial.class.getName();
} }
if (intfClass.equals("se.sics.cooja.mspmote.interfaces.SkyByteRadio")) {
intfClass = Msp802154Radio.class.getName();
}
if (intfClass.equals("se.sics.cooja.mspmote.interfaces.SkySerial")) { if (intfClass.equals("se.sics.cooja.mspmote.interfaces.SkySerial")) {
intfClass = MspSerial.class.getName(); intfClass = MspSerial.class.getName();
} }

View File

@ -50,6 +50,7 @@ import se.sics.cooja.MoteType;
import se.sics.cooja.ProjectConfig; import se.sics.cooja.ProjectConfig;
import se.sics.cooja.Simulation; import se.sics.cooja.Simulation;
import se.sics.cooja.interfaces.IPAddress; import se.sics.cooja.interfaces.IPAddress;
import se.sics.cooja.mspmote.interfaces.Msp802154Radio;
import se.sics.cooja.mspmote.interfaces.MspSerial; import se.sics.cooja.mspmote.interfaces.MspSerial;
import se.sics.mspsim.util.DebugInfo; import se.sics.mspsim.util.DebugInfo;
import se.sics.mspsim.util.ELF; import se.sics.mspsim.util.ELF;
@ -272,6 +273,10 @@ public abstract class MspMoteType implements MoteType {
logger.warn("Old simulation config detected: ESBLog was replaced by MspSerial"); logger.warn("Old simulation config detected: ESBLog was replaced by MspSerial");
intfClass = MspSerial.class.getName(); intfClass = MspSerial.class.getName();
} }
if (intfClass.equals("se.sics.cooja.mspmote.interfaces.SkyByteRadio")) {
logger.warn("Old simulation config detected: SkyByteRadio was replaced by Msp802154Radio");
intfClass = Msp802154Radio.class.getName();
}
if (intfClass.equals("se.sics.cooja.mspmote.interfaces.SkySerial")) { if (intfClass.equals("se.sics.cooja.mspmote.interfaces.SkySerial")) {
logger.warn("Old simulation config detected: SkySerial was replaced by MspSerial"); logger.warn("Old simulation config detected: SkySerial was replaced by MspSerial");
intfClass = MspSerial.class.getName(); intfClass = MspSerial.class.getName();

View File

@ -62,7 +62,7 @@ import se.sics.cooja.mspmote.interfaces.MspClock;
import se.sics.cooja.mspmote.interfaces.MspDebugOutput; import se.sics.cooja.mspmote.interfaces.MspDebugOutput;
import se.sics.cooja.mspmote.interfaces.MspMoteID; import se.sics.cooja.mspmote.interfaces.MspMoteID;
import se.sics.cooja.mspmote.interfaces.SkyButton; import se.sics.cooja.mspmote.interfaces.SkyButton;
import se.sics.cooja.mspmote.interfaces.SkyByteRadio; import se.sics.cooja.mspmote.interfaces.Msp802154Radio;
import se.sics.cooja.mspmote.interfaces.SkyCoffeeFilesystem; import se.sics.cooja.mspmote.interfaces.SkyCoffeeFilesystem;
import se.sics.cooja.mspmote.interfaces.SkyFlash; import se.sics.cooja.mspmote.interfaces.SkyFlash;
import se.sics.cooja.mspmote.interfaces.SkyLED; import se.sics.cooja.mspmote.interfaces.SkyLED;
@ -215,7 +215,7 @@ public class SkyMoteType extends MspMoteType {
SkyButton.class, SkyButton.class,
SkyFlash.class, SkyFlash.class,
SkyCoffeeFilesystem.class, SkyCoffeeFilesystem.class,
SkyByteRadio.class, Msp802154Radio.class,
MspSerial.class, MspSerial.class,
SkyLED.class, SkyLED.class,
MspDebugOutput.class, /* EXPERIMENTAL: Enable me for COOJA_DEBUG(..) */ MspDebugOutput.class, /* EXPERIMENTAL: Enable me for COOJA_DEBUG(..) */

View File

@ -58,7 +58,7 @@ import se.sics.cooja.interfaces.RimeAddress;
import se.sics.cooja.mspmote.interfaces.MspClock; import se.sics.cooja.mspmote.interfaces.MspClock;
import se.sics.cooja.mspmote.interfaces.MspDebugOutput; import se.sics.cooja.mspmote.interfaces.MspDebugOutput;
import se.sics.cooja.mspmote.interfaces.MspMoteID; import se.sics.cooja.mspmote.interfaces.MspMoteID;
import se.sics.cooja.mspmote.interfaces.SkyByteRadio; import se.sics.cooja.mspmote.interfaces.Msp802154Radio;
import se.sics.cooja.mspmote.interfaces.TyndallLED; import se.sics.cooja.mspmote.interfaces.TyndallLED;
import se.sics.cooja.mspmote.interfaces.UsciA0Serial; import se.sics.cooja.mspmote.interfaces.UsciA0Serial;
@ -188,7 +188,7 @@ public class TyndallMoteType extends MspMoteType {
MoteAttributes.class, MoteAttributes.class,
MspClock.class, MspClock.class,
MspMoteID.class, MspMoteID.class,
SkyByteRadio.class, Msp802154Radio.class,
UsciA0Serial.class, UsciA0Serial.class,
TyndallLED.class, TyndallLED.class,
MspDebugOutput.class MspDebugOutput.class

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008, Swedish Institute of Computer Science. * Copyright (c) 2008-2012, Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -26,16 +26,13 @@
* 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: SkyByteRadio.java,v 1.27 2010/09/09 19:52:26 nifi Exp $
*/ */
package se.sics.cooja.mspmote.interfaces; package se.sics.cooja.mspmote.interfaces;
import java.util.Collection; import java.util.Collection;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
import se.sics.cooja.ClassDescription; import se.sics.cooja.ClassDescription;
import se.sics.cooja.Mote; import se.sics.cooja.Mote;
import se.sics.cooja.RadioPacket; import se.sics.cooja.RadioPacket;
@ -45,33 +42,32 @@ import se.sics.cooja.interfaces.Position;
import se.sics.cooja.interfaces.Radio; import se.sics.cooja.interfaces.Radio;
import se.sics.cooja.mspmote.MspMote; import se.sics.cooja.mspmote.MspMote;
import se.sics.cooja.mspmote.MspMoteTimeEvent; import se.sics.cooja.mspmote.MspMoteTimeEvent;
import se.sics.mspsim.chip.CC2420;
import se.sics.mspsim.chip.ChannelListener; import se.sics.mspsim.chip.ChannelListener;
import se.sics.mspsim.chip.RFListener; import se.sics.mspsim.chip.RFListener;
import se.sics.mspsim.chip.Radio802154;
import se.sics.mspsim.core.Chip; import se.sics.mspsim.core.Chip;
import se.sics.mspsim.core.OperatingModeListener; import se.sics.mspsim.core.OperatingModeListener;
/** /**
* CC2420 to COOJA wrapper. * MSPSim 802.15.4 radio to COOJA wrapper.
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
@ClassDescription("CC2420") @ClassDescription("IEEE 802.15.4 Radio")
public class SkyByteRadio extends Radio implements CustomDataRadio { public class Msp802154Radio extends Radio implements CustomDataRadio {
private static Logger logger = Logger.getLogger(SkyByteRadio.class); private static Logger logger = Logger.getLogger(Msp802154Radio.class);
/** /**
* Cross-level: * Cross-level:
* Inter-byte delay for delivering cross-level packet bytes. * Inter-byte delay for delivering cross-level packet bytes.
*/ */
public static final long DELAY_BETWEEN_BYTES = public static final long DELAY_BETWEEN_BYTES =
(long) (1000.0*Simulation.MILLISECOND/(250000.0/8.0)); /* us. Corresponds to 250kbit/s */ (long) (1000.0*Simulation.MILLISECOND/(250000.0/8.0)); /* us. Corresponds to 250kbit/s */
private long lastEventTime = 0;
private RadioEvent lastEvent = RadioEvent.UNKNOWN; private RadioEvent lastEvent = RadioEvent.UNKNOWN;
private final MspMote mote; private final MspMote mote;
private final CC2420 cc2420; private final Radio802154 radio;
private boolean isInterfered = false; private boolean isInterfered = false;
private boolean isTransmitting = false; private boolean isTransmitting = false;
@ -83,24 +79,23 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
private RadioPacket lastOutgoingPacket = null; private RadioPacket lastOutgoingPacket = null;
private RadioPacket lastIncomingPacket = null; private RadioPacket lastIncomingPacket = null;
public SkyByteRadio(Mote m) { public Msp802154Radio(Mote m) {
this.mote = (MspMote)m; this.mote = (MspMote)m;
this.cc2420 = (CC2420) this.mote.getCPU().getChip(CC2420.class); this.radio = this.mote.getCPU().getChip(Radio802154.class);
if (cc2420 == null) { if (radio == null) {
throw new IllegalStateException("Mote is not equipped with a CC2420"); throw new IllegalStateException("Mote is not equipped with an IEEE 802.15.4 radio");
} }
cc2420.addRFListener(new RFListener() { radio.addRFListener(new RFListener() {
int len = 0; int len = 0;
int expLen = 0; int expLen = 0;
byte[] buffer = new byte[127 + 15]; byte[] buffer = new byte[127 + 15];
public void receivedByte(byte data) { public void receivedByte(byte data) {
if (!isTransmitting()) { if (!isTransmitting()) {
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime();
lastEvent = RadioEvent.TRANSMISSION_STARTED; lastEvent = RadioEvent.TRANSMISSION_STARTED;
isTransmitting = true; isTransmitting = true;
len = 0; len = 0;
/*logger.debug("----- SKY TRANSMISSION STARTED -----");*/ /*logger.debug("----- 802.15.4 TRANSMISSION STARTED -----");*/
setChanged(); setChanged();
notifyObservers(); notifyObservers();
} }
@ -113,7 +108,6 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
/* send this byte to all nodes */ /* send this byte to all nodes */
lastOutgoingByte = data; lastOutgoingByte = data;
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime();
lastEvent = RadioEvent.CUSTOM_DATA_TRANSMITTED; lastEvent = RadioEvent.CUSTOM_DATA_TRANSMITTED;
setChanged(); setChanged();
notifyObservers(); notifyObservers();
@ -126,17 +120,15 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
} }
if (len == expLen) { if (len == expLen) {
/*logger.debug("----- SKY CUSTOM DATA TRANSMITTED -----");*/ /*logger.debug("----- 802.15.4 CUSTOM DATA TRANSMITTED -----");*/
lastOutgoingPacket = CC2420RadioPacketConverter.fromCC2420ToCooja(buffer); lastOutgoingPacket = CC2420RadioPacketConverter.fromCC2420ToCooja(buffer);
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime();
lastEvent = RadioEvent.PACKET_TRANSMITTED; lastEvent = RadioEvent.PACKET_TRANSMITTED;
/*logger.debug("----- SKY PACKET TRANSMITTED -----");*/ /*logger.debug("----- 802.15.4 PACKET TRANSMITTED -----");*/
setChanged(); setChanged();
notifyObservers(); notifyObservers();
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime(); /*logger.debug("----- 802.15.4 TRANSMISSION FINISHED -----");*/
/*logger.debug("----- SKY TRANSMISSION FINISHED -----");*/
isTransmitting = false; isTransmitting = false;
lastEvent = RadioEvent.TRANSMISSION_FINISHED; lastEvent = RadioEvent.TRANSMISSION_FINISHED;
setChanged(); setChanged();
@ -146,10 +138,9 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
} }
}); });
cc2420.addOperatingModeListener(new OperatingModeListener() { radio.addOperatingModeListener(new OperatingModeListener() {
public void modeChanged(Chip source, int mode) { public void modeChanged(Chip source, int mode) {
if (isReceiverOn()) { if (radio.isReadyToReceive()) {
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime();
lastEvent = RadioEvent.HW_ON; lastEvent = RadioEvent.HW_ON;
setChanged(); setChanged();
notifyObservers(); notifyObservers();
@ -159,11 +150,10 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
} }
}); });
cc2420.addChannelListener(new ChannelListener() { radio.addChannelListener(new ChannelListener() {
public void channelChanged(int channel) { public void channelChanged(int channel) {
/* XXX Currently assumes zero channel switch time */ /* XXX Currently assumes zero channel switch time */
lastEvent = RadioEvent.UNKNOWN; lastEvent = RadioEvent.UNKNOWN;
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime();
setChanged(); setChanged();
notifyObservers(); notifyObservers();
} }
@ -183,22 +173,19 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
} }
}; };
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime();
lastEvent = RadioEvent.PACKET_TRANSMITTED; lastEvent = RadioEvent.PACKET_TRANSMITTED;
/*logger.debug("----- SKY PACKET TRANSMITTED -----");*/ /*logger.debug("----- 802.15.4 PACKET TRANSMITTED -----");*/
setChanged(); setChanged();
notifyObservers(); notifyObservers();
/* Register that transmission ended in radio medium */ /* Register that transmission ended in radio medium */
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime(); /*logger.debug("----- 802.15.4 TRANSMISSION FINISHED -----");*/
/*logger.debug("----- SKY TRANSMISSION FINISHED -----");*/
isTransmitting = false; isTransmitting = false;
lastEvent = RadioEvent.TRANSMISSION_FINISHED; lastEvent = RadioEvent.TRANSMISSION_FINISHED;
setChanged(); setChanged();
notifyObservers(); notifyObservers();
} }
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime();
lastEvent = RadioEvent.HW_OFF; lastEvent = RadioEvent.HW_OFF;
setChanged(); setChanged();
notifyObservers(); notifyObservers();
@ -216,11 +203,11 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
public void setReceivedPacket(RadioPacket packet) { public void setReceivedPacket(RadioPacket packet) {
/* Note: /* Note:
* Only nodes at other abstraction levels deliver full packets. * Only nodes at other abstraction levels deliver full packets.
* Sky motes would instead directly deliver bytes. */ * MSPSim motes with 802.15.4 radios would instead directly deliver bytes. */
lastIncomingPacket = packet; lastIncomingPacket = packet;
/* TODO Check isReceiverOn() instead? */ /* TODO Check isReceiverOn() instead? */
if (cc2420.getState() != CC2420.RadioState.RX_SFD_SEARCH) { if (radio.isReadyToReceive()) {
logger.warn("Radio is turned off, dropping packet data"); logger.warn("Radio is turned off, dropping packet data");
return; return;
} }
@ -237,9 +224,9 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
getMote().getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) { getMote().getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) {
public void execute(long t) { public void execute(long t) {
super.execute(t); super.execute(t);
cc2420.receivedByte(byteToDeliver); radio.receivedByte(byteToDeliver);
mote.requestImmediateWakeup(); mote.requestImmediateWakeup();
} }
}, deliveryTime); }, deliveryTime);
deliveryTime += DELAY_BETWEEN_BYTES; deliveryTime += DELAY_BETWEEN_BYTES;
} }
@ -270,9 +257,9 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
mote.getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) { mote.getSimulation().scheduleEvent(new MspMoteTimeEvent(mote, 0) {
public void execute(long t) { public void execute(long t) {
super.execute(t); super.execute(t);
cc2420.receivedByte(inputByte); radio.receivedByte(inputByte);
mote.requestImmediateWakeup(); mote.requestImmediateWakeup();
} }
}, mote.getSimulation().getSimulationTime()); }, mote.getSimulation().getSimulationTime());
} }
@ -291,21 +278,18 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
} }
public int getChannel() { public int getChannel() {
cc2420.updateActiveFrequency(); return radio.getActiveChannel();
return cc2420.getActiveChannel();
} }
public int getFrequency() { public int getFrequency() {
cc2420.updateActiveFrequency(); return radio.getActiveFrequency();
return cc2420.getActiveFrequency();
} }
public void signalReceptionStart() { public void signalReceptionStart() {
isReceiving = true; isReceiving = true;
lastEventTime = mote.getSimulation().getSimulationTime();
lastEvent = RadioEvent.RECEPTION_STARTED; lastEvent = RadioEvent.RECEPTION_STARTED;
/*logger.debug("----- SKY RECEPTION STARTED -----");*/ /*logger.debug("----- 802.15.4 RECEPTION STARTED -----");*/
setChanged(); setChanged();
notifyObservers(); notifyObservers();
} }
@ -315,9 +299,8 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
isReceiving = false; isReceiving = false;
isInterfered = false; isInterfered = false;
lastEventTime = mote.getSimulation().getSimulationTime();
lastEvent = RadioEvent.RECEPTION_FINISHED; lastEvent = RadioEvent.RECEPTION_FINISHED;
/*logger.debug("----- SKY RECEPTION FINISHED -----");*/ /*logger.debug("----- 802.15.4 RECEPTION FINISHED -----");*/
setChanged(); setChanged();
notifyObservers(); notifyObservers();
} }
@ -331,19 +314,18 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
isReceiving = false; isReceiving = false;
lastIncomingPacket = null; lastIncomingPacket = null;
lastEventTime = mote.getSimulation().getSimulationTime();
lastEvent = RadioEvent.RECEPTION_INTERFERED; lastEvent = RadioEvent.RECEPTION_INTERFERED;
/*logger.debug("----- SKY RECEPTION INTERFERED -----");*/ /*logger.debug("----- 802.15.4 RECEPTION INTERFERED -----");*/
setChanged(); setChanged();
notifyObservers(); notifyObservers();
} }
public double getCurrentOutputPower() { public double getCurrentOutputPower() {
return cc2420.getOutputPower(); return radio.getOutputPower();
} }
public int getCurrentOutputPowerIndicator() { public int getCurrentOutputPowerIndicator() {
return cc2420.getOutputPowerIndicator(); return radio.getOutputPowerIndicator();
} }
public int getOutputPowerIndicatorMax() { public int getOutputPowerIndicatorMax() {
@ -385,13 +367,13 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
} }
avg /= rssiLast.length; avg /= rssiLast.length;
cc2420.setRSSI((int) avg); radio.setRSSI((int) avg);
rssiLastCounter--; rssiLastCounter--;
if (rssiLastCounter > 0) { if (rssiLastCounter > 0) {
mote.getSimulation().scheduleEvent(this, t+DELAY_BETWEEN_BYTES/2); mote.getSimulation().scheduleEvent(this, t+DELAY_BETWEEN_BYTES/2);
} }
} }
}, mote.getSimulation().getSimulationTime()); }, mote.getSimulation().getSimulationTime());
} }
rssiLastCounter = 8; rssiLastCounter = 8;
@ -413,12 +395,6 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
} }
public boolean isReceiverOn() { public boolean isReceiverOn() {
if (cc2420.getMode() == CC2420.MODE_POWER_OFF) { return radio.isReadyToReceive();
return false;
}
if (cc2420.getMode() == CC2420.MODE_TXRX_OFF) {
return false;
}
return true;
} }
} }