automatically ending transmission if radio hw is turned off

This commit is contained in:
fros4943 2010-01-15 10:44:26 +00:00
parent 515f5c7f78
commit 6669b52c61

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: 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; package se.sics.cooja.mspmote.interfaces;
@ -92,7 +92,7 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
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 (len == 0) { if (!isTransmitting()) {
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime(); lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime();
lastEvent = RadioEvent.TRANSMISSION_STARTED; lastEvent = RadioEvent.TRANSMISSION_STARTED;
isTransmitting = true; isTransmitting = true;
@ -101,6 +101,12 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
notifyObservers(); 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 */ /* send this byte to all nodes */
lastOutgoingByte = data; lastOutgoingByte = data;
lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime(); lastEventTime = SkyByteRadio.this.mote.getSimulation().getSimulationTime();
@ -144,8 +150,16 @@ public class SkyByteRadio extends Radio implements CustomDataRadio {
if (isReceiverOn()) { if (isReceiverOn()) {
lastEvent = RadioEvent.HW_ON; lastEvent = RadioEvent.HW_ON;
} else { } else {
/* Radio was turned off during transmission.
* May for example happen if watchdog triggers */
if (isTransmitting()) { if (isTransmitting()) {
logger.fatal("Turning off radio while transmitting"); 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; lastEvent = RadioEvent.HW_OFF;
} }