From 6669b52c6141feb23ad78e5e0b11e7977ecff629 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Fri, 15 Jan 2010 10:44:26 +0000 Subject: [PATCH] automatically ending transmission if radio hw is turned off --- .../cooja/mspmote/interfaces/SkyByteRadio.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/SkyByteRadio.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/SkyByteRadio.java index 204c4fca9..ef82241f5 100755 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/SkyByteRadio.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/SkyByteRadio.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: SkyByteRadio.java,v 1.19 2009/12/07 12:31:19 fros4943 Exp $ + * $Id: SkyByteRadio.java,v 1.20 2010/01/15 10:44:26 fros4943 Exp $ */ package se.sics.cooja.mspmote.interfaces; @@ -92,7 +92,7 @@ public class SkyByteRadio extends Radio implements CustomDataRadio { int expLen = 0; byte[] buffer = new byte[127 + 15]; public void receivedByte(byte data) { - if (len == 0) { + if (!isTransmitting()) { lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime(); lastEvent = RadioEvent.TRANSMISSION_STARTED; isTransmitting = true; @@ -101,6 +101,12 @@ public class SkyByteRadio extends Radio implements CustomDataRadio { notifyObservers(); } + if (len >= buffer.length) { + /* Bad size packet, too large */ + logger.debug("Error: bad size: " + len + ", dropping outgoing byte: " + data); + return; + } + /* send this byte to all nodes */ lastOutgoingByte = data; lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime(); @@ -144,8 +150,16 @@ public class SkyByteRadio extends Radio implements CustomDataRadio { if (isReceiverOn()) { lastEvent = RadioEvent.HW_ON; } else { + /* Radio was turned off during transmission. + * May for example happen if watchdog triggers */ if (isTransmitting()) { logger.fatal("Turning off radio while transmitting"); + lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime(); + /*logger.debug("----- SKY TRANSMISSION FINISHED -----");*/ + isTransmitting = false; + lastEvent = RadioEvent.TRANSMISSION_FINISHED; + setChanged(); + notifyObservers(); } lastEvent = RadioEvent.HW_OFF; }