using new radio packet format
This commit is contained in:
parent
1270545cc2
commit
e765735bad
3 changed files with 58 additions and 115 deletions
|
@ -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: ContikiRadio.java,v 1.18 2008/03/17 09:50:27 fros4943 Exp $
|
* $Id: ContikiRadio.java,v 1.19 2008/03/18 12:52:01 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.contikimote.interfaces;
|
package se.sics.cooja.contikimote.interfaces;
|
||||||
|
@ -39,12 +39,11 @@ import org.jdom.Element;
|
||||||
|
|
||||||
import se.sics.cooja.*;
|
import se.sics.cooja.*;
|
||||||
import se.sics.cooja.contikimote.ContikiMoteInterface;
|
import se.sics.cooja.contikimote.ContikiMoteInterface;
|
||||||
import se.sics.cooja.interfaces.PacketRadio;
|
|
||||||
import se.sics.cooja.interfaces.Position;
|
import se.sics.cooja.interfaces.Position;
|
||||||
import se.sics.cooja.interfaces.Radio;
|
import se.sics.cooja.interfaces.Radio;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents a radio transciever. In order to simulate different
|
* This class represents a radio transceiver. In order to simulate different
|
||||||
* transmission rates, the underlying Contiki system can be locked in either
|
* transmission rates, the underlying Contiki system can be locked in either
|
||||||
* transmission or reception states (using multi-threading). When a transmission
|
* transmission or reception states (using multi-threading). When a transmission
|
||||||
* is initiated, it will automatically lock the Contiki system. When a packet is
|
* is initiated, it will automatically lock the Contiki system. When a packet is
|
||||||
|
@ -77,8 +76,7 @@ import se.sics.cooja.interfaces.Radio;
|
||||||
*
|
*
|
||||||
* @author Fredrik Osterlind
|
* @author Fredrik Osterlind
|
||||||
*/
|
*/
|
||||||
public class ContikiRadio extends Radio implements ContikiMoteInterface,
|
public class ContikiRadio extends Radio implements ContikiMoteInterface {
|
||||||
PacketRadio {
|
|
||||||
private Mote myMote;
|
private Mote myMote;
|
||||||
|
|
||||||
private SectionMoteMemory myMoteMemory;
|
private SectionMoteMemory myMoteMemory;
|
||||||
|
@ -102,9 +100,9 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface,
|
||||||
|
|
||||||
private double energyListeningRadioPerTick = -1;
|
private double energyListeningRadioPerTick = -1;
|
||||||
|
|
||||||
private byte[] packetToMote = null;
|
private RadioPacket packetToMote = null;
|
||||||
|
|
||||||
private byte[] packetFromMote = null;
|
private RadioPacket packetFromMote = null;
|
||||||
|
|
||||||
private boolean radioOn = true;
|
private boolean radioOn = true;
|
||||||
|
|
||||||
|
@ -157,16 +155,16 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Packet radio support */
|
/* Packet radio support */
|
||||||
public byte[] getLastPacketTransmitted() {
|
public RadioPacket getLastPacketTransmitted() {
|
||||||
return packetFromMote;
|
return packetFromMote;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getLastPacketReceived() {
|
public RadioPacket getLastPacketReceived() {
|
||||||
return packetToMote;
|
return packetToMote;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReceivedPacket(byte[] data) {
|
public void setReceivedPacket(RadioPacket packet) {
|
||||||
packetToMote = data;
|
packetToMote = packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* General radio support */
|
/* General radio support */
|
||||||
|
@ -227,8 +225,8 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface,
|
||||||
myMoteMemory.setByteValueOf("simReceiving", (byte) 0);
|
myMoteMemory.setByteValueOf("simReceiving", (byte) 0);
|
||||||
|
|
||||||
// Set data
|
// Set data
|
||||||
myMoteMemory.setIntValueOf("simInSize", packetToMote.length);
|
myMoteMemory.setIntValueOf("simInSize", packetToMote.getPacketData().length);
|
||||||
myMoteMemory.setByteArray("simInDataBuffer", packetToMote);
|
myMoteMemory.setByteArray("simInDataBuffer", packetToMote.getPacketData());
|
||||||
|
|
||||||
lastEventTime = myMote.getSimulation().getSimulationTime();
|
lastEventTime = myMote.getSimulation().getSimulationTime();
|
||||||
lastEvent = RadioEvent.RECEPTION_FINISHED;
|
lastEvent = RadioEvent.RECEPTION_FINISHED;
|
||||||
|
@ -374,8 +372,8 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface,
|
||||||
myMoteMemory.setByteValueOf("simTransmitting", (byte) 0);
|
myMoteMemory.setByteValueOf("simTransmitting", (byte) 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
packetFromMote = myMoteMemory.getByteArray("simOutDataBuffer", size);
|
packetFromMote = new COOJARadioPacket(myMoteMemory.getByteArray("simOutDataBuffer", size));
|
||||||
if (packetFromMote == null || packetFromMote.length == 0) {
|
if (packetFromMote.getPacketData() == null || packetFromMote.getPacketData().length == 0) {
|
||||||
logger.warn("Skipping zero sized Contiki packet (no buffer)");
|
logger.warn("Skipping zero sized Contiki packet (no buffer)");
|
||||||
myMoteMemory.setByteValueOf("simTransmitting", (byte) 0);
|
myMoteMemory.setByteValueOf("simTransmitting", (byte) 0);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -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: DisturberRadio.java,v 1.5 2008/03/17 09:50:27 fros4943 Exp $
|
* $Id: DisturberRadio.java,v 1.6 2008/03/18 12:54:39 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.motes;
|
package se.sics.cooja.motes;
|
||||||
|
@ -43,16 +43,16 @@ import se.sics.cooja.*;
|
||||||
import se.sics.cooja.interfaces.*;
|
import se.sics.cooja.interfaces.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This radio periodically transmits data on a configurable channel.
|
* This radio transmits data packet over and over again on a configurable channel.
|
||||||
*
|
*
|
||||||
* @author Fredrik Osterlind, Thiemo Voigt
|
* @author Fredrik Osterlind, Thiemo Voigt
|
||||||
*/
|
*/
|
||||||
public class DisturberRadio extends Radio implements PacketRadio {
|
public class DisturberRadio extends Radio {
|
||||||
private Mote myMote;
|
private Mote myMote;
|
||||||
|
|
||||||
private static Logger logger = Logger.getLogger(DisturberRadio.class);
|
private static Logger logger = Logger.getLogger(DisturberRadio.class);
|
||||||
|
|
||||||
private static byte[] packetFromMote = new byte[] { 1, 2, 3, 4, 5 };
|
private RadioPacket packetFromMote = new COOJARadioPacket(new byte[] { 1, 2, 3, 4, 5 });
|
||||||
|
|
||||||
private boolean transmitting = false;
|
private boolean transmitting = false;
|
||||||
|
|
||||||
|
@ -80,15 +80,15 @@ public class DisturberRadio extends Radio implements PacketRadio {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Packet radio support */
|
/* Packet radio support */
|
||||||
public byte[] getLastPacketTransmitted() {
|
public RadioPacket getLastPacketTransmitted() {
|
||||||
return packetFromMote;
|
return packetFromMote;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getLastPacketReceived() {
|
public RadioPacket getLastPacketReceived() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setReceivedPacket(byte[] data) {
|
public void setReceivedPacket(RadioPacket packet) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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.3 2007/04/23 11:33:54 fros4943 Exp $
|
* $Id: AbstractRadioMedium.java,v 1.4 2008/03/18 12:57:04 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.radiomediums;
|
package se.sics.cooja.radiomediums;
|
||||||
|
@ -67,8 +67,6 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
||||||
|
|
||||||
private RadioConnection[] lastTickConnections = null;
|
private RadioConnection[] lastTickConnections = null;
|
||||||
|
|
||||||
private ConnectionLogger myLogger = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This constructor should always be called from implemented radio mediums.
|
* This constructor should always be called from implemented radio mediums.
|
||||||
*
|
*
|
||||||
|
@ -94,8 +92,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
||||||
/**
|
/**
|
||||||
* Creates a new connection from given radio.
|
* Creates a new connection from given radio.
|
||||||
*
|
*
|
||||||
* This method is responsible for determining which radio should receive or be
|
* Determines which radios should receive or be interfered by the transmission.
|
||||||
* interfered by the transmission.
|
|
||||||
*
|
*
|
||||||
* @param radio
|
* @param radio
|
||||||
* Transmitting radio
|
* Transmitting radio
|
||||||
|
@ -104,48 +101,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
||||||
abstract public RadioConnection createConnections(Radio radio);
|
abstract public RadioConnection createConnections(Radio radio);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Forward given packet from source to all destinations in given connection.
|
* Updates all radio interfaces' signal strengths according to
|
||||||
* This method is called sometime during an active connection.
|
|
||||||
*
|
|
||||||
* @param connection
|
|
||||||
* Radio connection
|
|
||||||
* @param packetData
|
|
||||||
* Packet data
|
|
||||||
*/
|
|
||||||
public void forwardPacket(RadioConnection connection, byte[] packetData) {
|
|
||||||
Radio sourceRadio = connection.getSource();
|
|
||||||
if (packetData == null || packetData.length == 0) {
|
|
||||||
logger.warn("Trying to forward null packet");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sourceRadio instanceof ByteRadio) {
|
|
||||||
// Byte radios only forwards packets to packet radios
|
|
||||||
for (Radio receivingRadio : connection.getDestinations()) {
|
|
||||||
if (receivingRadio instanceof ByteRadio) {
|
|
||||||
// Do nothing (data will be forwarded on byte-per-byte basis)
|
|
||||||
} else if (receivingRadio instanceof PacketRadio) {
|
|
||||||
// Forward packet data
|
|
||||||
((PacketRadio) receivingRadio).setReceivedPacket(packetData);
|
|
||||||
} else {
|
|
||||||
logger.warn("Packet was not forwarded correctly");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (sourceRadio instanceof PacketRadio) {
|
|
||||||
// Packet radios forwards packets to all packet radios
|
|
||||||
for (Radio receivingRadio : connection.getDestinations()) {
|
|
||||||
if (receivingRadio instanceof PacketRadio) {
|
|
||||||
// Forward packet data
|
|
||||||
((PacketRadio) receivingRadio).setReceivedPacket(packetData);
|
|
||||||
} else {
|
|
||||||
logger.warn("Packet was not forwarded correctly");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method should update all radio interfaces' signal strengths according to
|
|
||||||
* the current active connections.
|
* the current active connections.
|
||||||
*/
|
*/
|
||||||
abstract public void updateSignalStrengths();
|
abstract public void updateSignalStrengths();
|
||||||
|
@ -181,8 +137,9 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (connToRemove != null)
|
if (connToRemove != null) {
|
||||||
activeConnections.remove(connToRemove);
|
activeConnections.remove(connToRemove);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -231,7 +188,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
||||||
} else if (event == Radio.RadioEvent.TRANSMISSION_STARTED) {
|
} else if (event == Radio.RadioEvent.TRANSMISSION_STARTED) {
|
||||||
/* Create radio connections */
|
/* Create radio connections */
|
||||||
|
|
||||||
RadioConnection newConnection = createConnections((Radio) radio);
|
RadioConnection newConnection = createConnections(radio);
|
||||||
if (newConnection != null) {
|
if (newConnection != null) {
|
||||||
activeConnections.add(newConnection);
|
activeConnections.add(newConnection);
|
||||||
}
|
}
|
||||||
|
@ -273,8 +230,8 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
||||||
// Wake up tick observer
|
// Wake up tick observer
|
||||||
radioMediumObservable.setRadioMediumChanged();
|
radioMediumObservable.setRadioMediumChanged();
|
||||||
|
|
||||||
} else if (event == Radio.RadioEvent.BYTE_TRANSMITTED) {
|
} else if (event == Radio.RadioEvent.CUSTOM_DATA_TRANSMITTED) {
|
||||||
/* Forward byte */
|
/* Forward custom data */
|
||||||
|
|
||||||
// Find corresponding connection of radio
|
// Find corresponding connection of radio
|
||||||
RadioConnection connection = null;
|
RadioConnection connection = null;
|
||||||
|
@ -288,12 +245,11 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
||||||
if (connection == null) {
|
if (connection == null) {
|
||||||
logger.fatal("Can't find active connection to forward byte in");
|
logger.fatal("Can't find active connection to forward byte in");
|
||||||
} else {
|
} else {
|
||||||
byte b = ((ByteRadio) radio).getLastByteTransmitted();
|
Object data = ((CustomDataRadio) radio).getLastCustomDataTransmitted();
|
||||||
long delay = ((ByteRadio) radio).getLastByteTransmittedDelay();
|
|
||||||
|
|
||||||
for (Radio dstRadio : connection.getDestinations()) {
|
for (Radio dstRadio : connection.getDestinations()) {
|
||||||
if (dstRadio instanceof ByteRadio) {
|
if (dstRadio instanceof CustomDataRadio) {
|
||||||
((ByteRadio) dstRadio).receiveByte(b, delay);
|
((CustomDataRadio) dstRadio).receiveCustomData(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -313,8 +269,14 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
||||||
if (connection == null) {
|
if (connection == null) {
|
||||||
logger.fatal("Can't find active connection to forward byte in");
|
logger.fatal("Can't find active connection to forward byte in");
|
||||||
} else {
|
} else {
|
||||||
byte[] packetData = ((PacketRadio) radio).getLastPacketTransmitted();
|
byte[] packetData = radio.getLastPacketTransmitted().getPacketData();
|
||||||
forwardPacket(connection, packetData);
|
|
||||||
|
Radio srcRadio = connection.getSource();
|
||||||
|
for (Radio dstRadio : connection.getDestinations()) {
|
||||||
|
if (!(srcRadio instanceof CustomDataRadio) || !(dstRadio instanceof CustomDataRadio)) {
|
||||||
|
dstRadio.setReceivedPacket(new COOJARadioPacket(packetData));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (event == Radio.RadioEvent.UNKNOWN) {
|
} else if (event == Radio.RadioEvent.UNKNOWN) {
|
||||||
|
@ -328,11 +290,9 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This observer is responsible for making last tick connections available to
|
* This observer is responsible for making last tick connections available to
|
||||||
* external observers, as well as forwarding finished connections to any
|
* external observers.
|
||||||
* registered connection logger.
|
|
||||||
*
|
*
|
||||||
* @see #getLastTickConnections()
|
* @see #getLastTickConnections()
|
||||||
* @see #setConnectionLogger(ConnectionLogger)
|
|
||||||
*/
|
*/
|
||||||
private Observer tickObserver = new Observer() {
|
private Observer tickObserver = new Observer() {
|
||||||
public void update(Observable obs, Object obj) {
|
public void update(Observable obs, Object obj) {
|
||||||
|
@ -344,21 +304,17 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do nothing if radio medium unchanged
|
// Do nothing if radio medium unchanged
|
||||||
if (!radioMediumObservable.hasChanged())
|
if (!radioMediumObservable.hasChanged()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Log any new finished connections
|
// Log any new finished connections
|
||||||
if (finishedConnections.size() > 0) {
|
if (finishedConnections.size() > 0) {
|
||||||
lastTickConnections = new RadioConnection[finishedConnections.size()];
|
lastTickConnections = new RadioConnection[finishedConnections.size()];
|
||||||
for (int i = 0; i < finishedConnections.size(); i++)
|
for (int i = 0; i < finishedConnections.size(); i++) {
|
||||||
lastTickConnections[i] = finishedConnections.get(i);
|
lastTickConnections[i] = finishedConnections.get(i);
|
||||||
finishedConnections.clear();
|
|
||||||
|
|
||||||
// Notify radio medium logger of the finished transmissions
|
|
||||||
if (myLogger != null) {
|
|
||||||
for (RadioConnection conn : lastTickConnections)
|
|
||||||
myLogger.logConnection(conn);
|
|
||||||
}
|
}
|
||||||
|
finishedConnections.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify all other radio medium observers
|
// Notify all other radio medium observers
|
||||||
|
@ -381,19 +337,12 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
||||||
isTickObserver = true;
|
isTickObserver = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warn if radio medium does not support radio
|
|
||||||
if (!(radio instanceof PacketRadio)) {
|
|
||||||
logger
|
|
||||||
.warn("Radio medium does not support radio (no transmission supported)");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register and start observing radio
|
// Register and start observing radio
|
||||||
registeredRadios.add(radio);
|
registeredRadios.add(radio);
|
||||||
radio.addObserver(radioEventsObserver);
|
radio.addObserver(radioEventsObserver);
|
||||||
|
|
||||||
// Set initial signal strenth
|
// Set initial signal strength
|
||||||
updateSignalStrengths();
|
updateSignalStrengths();
|
||||||
//TODO radio.setCurrentSignalStrength(SS_NOTHING);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,8 +374,4 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
||||||
return lastTickConnections;
|
return lastTickConnections;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConnectionLogger(ConnectionLogger connection) {
|
|
||||||
myLogger = connection;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue