tr1001 implements a custom data radio. may deliver null packets is gcr decoding fails
This commit is contained in:
parent
560837b4db
commit
275ee04f5b
1 changed files with 43 additions and 59 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: TR1001Radio.java,v 1.2 2008/03/17 09:52:03 fros4943 Exp $
|
* $Id: TR1001Radio.java,v 1.3 2008/03/18 13:15:41 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.mspmote.interfaces;
|
package se.sics.cooja.mspmote.interfaces;
|
||||||
|
@ -49,13 +49,13 @@ import se.sics.cooja.mspmote.ESBMote;
|
||||||
* @author Fredrik Osterlind
|
* @author Fredrik Osterlind
|
||||||
*/
|
*/
|
||||||
@ClassDescription("TR1001 Radio")
|
@ClassDescription("TR1001 Radio")
|
||||||
public class TR1001Radio extends Radio implements USARTListener, ByteRadio {
|
public class TR1001Radio extends Radio implements USARTListener, CustomDataRadio {
|
||||||
private static Logger logger = Logger.getLogger(TR1001Radio.class);
|
private static Logger logger = Logger.getLogger(TR1001Radio.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minimum delay in CPU cycles between each byte fed to USART.
|
* Minimum delay in CPU cycles between each byte fed to USART.
|
||||||
*/
|
*/
|
||||||
private static final long CYCLES_BETWEEN_BYTES = 1200; /* ~19.200 bps */
|
public static final long CYCLES_BETWEEN_BYTES = 1200; /* ~19.200 bps */
|
||||||
|
|
||||||
private ESBMote mspMote;
|
private ESBMote mspMote;
|
||||||
|
|
||||||
|
@ -71,12 +71,12 @@ public class TR1001Radio extends Radio implements USARTListener, ByteRadio {
|
||||||
|
|
||||||
private USART radioUSART = null;
|
private USART radioUSART = null;
|
||||||
|
|
||||||
private byte[] packetToMote = null;
|
private RadioPacket packetToMote = null;
|
||||||
|
|
||||||
private byte[] packetFromMote = null;
|
private RadioPacket packetFromMote = null;
|
||||||
|
|
||||||
/* Outgoing packet data buffer */
|
/* Outgoing packet data buffer */
|
||||||
private byte[] outgoingData = new byte[1024]; // TODO Decrease max size
|
private TR1001RadioByte[] outgoingData = new TR1001RadioByte[128]; /* TODO Adaptive max size */
|
||||||
|
|
||||||
private int outgoingDataLength = 0;
|
private int outgoingDataLength = 0;
|
||||||
|
|
||||||
|
@ -88,15 +88,13 @@ public class TR1001Radio extends Radio implements USARTListener, ByteRadio {
|
||||||
private Vector<Long> bufferedByteDelays = new Vector<Long>();
|
private Vector<Long> bufferedByteDelays = new Vector<Long>();
|
||||||
|
|
||||||
/* Outgoing byte data buffer */
|
/* Outgoing byte data buffer */
|
||||||
private byte byteFromMote = -1;
|
private TR1001RadioByte tr1001ByteFromMote = null;
|
||||||
|
|
||||||
|
private TR1001RadioByte tr1001ByteToMote = null;
|
||||||
|
|
||||||
private long transmissionStartCycles = -1;
|
private long transmissionStartCycles = -1;
|
||||||
|
|
||||||
private long byteFromMoteDelay = -1;
|
|
||||||
|
|
||||||
/* Incoming byte data buffer */
|
/* Incoming byte data buffer */
|
||||||
private byte byteToMote = -1;
|
|
||||||
|
|
||||||
private byte lastDeliveredByte = -1;
|
private byte lastDeliveredByte = -1;
|
||||||
|
|
||||||
private long lastDeliveredByteTimestamp = -1;
|
private long lastDeliveredByteTimestamp = -1;
|
||||||
|
@ -125,17 +123,17 @@ public class TR1001Radio extends Radio implements USARTListener, ByteRadio {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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[] p) {
|
public void setReceivedPacket(RadioPacket packet) {
|
||||||
packetToMote = p;
|
packetToMote = packet;
|
||||||
if (packetToMote == null || packetToMote.length == 0) {
|
if (packetToMote.getPacketData() == null || packetToMote.getPacketData().length == 0) {
|
||||||
logger.fatal("Received null packet");
|
logger.fatal("Received null packet");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -146,31 +144,30 @@ public class TR1001Radio extends Radio implements USARTListener, ByteRadio {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Convert to TR1001 packet data */
|
/* Convert to TR1001 packet data */
|
||||||
byte[] tr1001Frame = TR1001RadioPacketConverter.fromCoojaToTR1001(p);
|
TR1001RadioByte[] tr1001bytes = TR1001RadioPacketConverter.fromCoojaToTR1001(packetToMote);
|
||||||
|
|
||||||
/* Feed to the CPU "slowly" */
|
/* Feed to the CPU "slowly" */
|
||||||
for (byte element : tr1001Frame) {
|
for (TR1001RadioByte b : tr1001bytes) {
|
||||||
receiveByte(element, CYCLES_BETWEEN_BYTES);
|
receiveCustomData(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Byte radio support */
|
/* Custom data radio support */
|
||||||
public byte getLastByteTransmitted() {
|
public Object getLastCustomDataTransmitted() {
|
||||||
return byteFromMote;
|
return tr1001ByteFromMote;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLastByteTransmittedDelay() {
|
public Object getLastCustomDataReceived() {
|
||||||
return byteFromMoteDelay;
|
return tr1001ByteToMote;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte getLastByteReceived() {
|
public void receiveCustomData(Object data) {
|
||||||
return byteToMote;
|
if (data instanceof TR1001RadioByte) {
|
||||||
}
|
tr1001ByteToMote = ((TR1001RadioByte) data);
|
||||||
|
|
||||||
public void receiveByte(byte b, long delay) {
|
bufferedBytes.add(tr1001ByteToMote.getByte());
|
||||||
byteToMote = b;
|
bufferedByteDelays.add(tr1001ByteToMote.getDelay());
|
||||||
bufferedBytes.add(b);
|
}
|
||||||
bufferedByteDelays.add(delay);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -238,8 +235,10 @@ public class TR1001Radio extends Radio implements USARTListener, ByteRadio {
|
||||||
transmitting = true;
|
transmitting = true;
|
||||||
lastEventTime = mspMote.getSimulation().getSimulationTime();
|
lastEventTime = mspMote.getSimulation().getSimulationTime();
|
||||||
lastEvent = RadioEvent.TRANSMISSION_STARTED;
|
lastEvent = RadioEvent.TRANSMISSION_STARTED;
|
||||||
|
|
||||||
transmissionStartCycles = mspMote.getCPU().cycles;
|
transmissionStartCycles = mspMote.getCPU().cycles;
|
||||||
lastDeliveredByteTimestamp = transmissionStartCycles;
|
lastDeliveredByteTimestamp = transmissionStartCycles;
|
||||||
|
|
||||||
this.setChanged();
|
this.setChanged();
|
||||||
this.notifyObservers();
|
this.notifyObservers();
|
||||||
}
|
}
|
||||||
|
@ -252,36 +251,27 @@ public class TR1001Radio extends Radio implements USARTListener, ByteRadio {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store packet data
|
// Deliver byte to radio medium as custom data
|
||||||
outgoingData[outgoingDataLength++] = (byte) data;
|
lastEvent = RadioEvent.CUSTOM_DATA_TRANSMITTED;
|
||||||
|
tr1001ByteFromMote = new TR1001RadioByte((byte) data, mspMote.getCPU().cycles - lastDeliveredByteTimestamp);
|
||||||
// Deliver byte to radio medium
|
outgoingData[outgoingDataLength++] = tr1001ByteFromMote;
|
||||||
lastEvent = RadioEvent.BYTE_TRANSMITTED;
|
|
||||||
byteFromMote = (byte) data;
|
|
||||||
byteFromMoteDelay = mspMote.getCPU().cycles - lastDeliveredByteTimestamp;
|
|
||||||
lastDeliveredByteTimestamp = mspMote.getCPU().cycles;
|
lastDeliveredByteTimestamp = mspMote.getCPU().cycles;
|
||||||
if (byteFromMoteDelay < 0) {
|
|
||||||
byteFromMoteDelay = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setChanged();
|
this.setChanged();
|
||||||
this.notifyObservers();
|
this.notifyObservers();
|
||||||
|
|
||||||
// Feed to application level immediately
|
// Feed to application level immediately
|
||||||
boolean finished = tr1001PacketConverter.fromTR1001ToCoojaAccumulated(byteFromMote);
|
boolean finished = tr1001PacketConverter.fromTR1001ToCoojaAccumulated(tr1001ByteFromMote);
|
||||||
if (finished) {
|
if (finished) {
|
||||||
/* Transmission finished - deliver packet immediately */
|
/* Transmission finished - deliver packet immediately */
|
||||||
if (tr1001PacketConverter.accumulatedConversionIsOk()) {
|
if (tr1001PacketConverter.accumulatedConversionIsOk()) {
|
||||||
packetFromMote = tr1001PacketConverter.getAccumulatedConvertedData();
|
packetFromMote = tr1001PacketConverter.getAccumulatedConvertedCoojaPacket();
|
||||||
} else {
|
|
||||||
packetFromMote = new byte[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Notify observers of new prepared packet */
|
/* Notify observers of new prepared packet */
|
||||||
/*logger.debug("----- MSP DELIVERED PACKET -----");*/
|
/*logger.debug("----- MSP DELIVERED PACKET -----");*/
|
||||||
lastEvent = RadioEvent.PACKET_TRANSMITTED;
|
lastEvent = RadioEvent.PACKET_TRANSMITTED;
|
||||||
this.setChanged();
|
this.setChanged();
|
||||||
this.notifyObservers();
|
this.notifyObservers();
|
||||||
|
}
|
||||||
|
|
||||||
// Reset counters and wait for next packet
|
// Reset counters and wait for next packet
|
||||||
outgoingDataLength = 0;
|
outgoingDataLength = 0;
|
||||||
|
@ -387,13 +377,7 @@ public class TR1001Radio extends Radio implements USARTListener, ByteRadio {
|
||||||
// Detect transmission end due to inactivity
|
// Detect transmission end due to inactivity
|
||||||
if (isTransmitting() && ticksSinceLastSend > 4) {
|
if (isTransmitting() && ticksSinceLastSend > 4) {
|
||||||
/* Dropping packet due to inactivity */
|
/* Dropping packet due to inactivity */
|
||||||
packetFromMote = new byte[0];
|
packetFromMote = null;
|
||||||
|
|
||||||
/* Notify observers of new empty packet */
|
|
||||||
logger.warn("----- DELIVERED MSP NULL PACKET -----");
|
|
||||||
lastEvent = RadioEvent.PACKET_TRANSMITTED;
|
|
||||||
this.setChanged();
|
|
||||||
this.notifyObservers();
|
|
||||||
|
|
||||||
// Reset counters and wait for next packet
|
// Reset counters and wait for next packet
|
||||||
outgoingDataLength = 0;
|
outgoingDataLength = 0;
|
||||||
|
|
Loading…
Reference in a new issue