From 90f174509b862cdbb12da7456add07971cc4f478 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Fri, 26 Mar 2010 13:33:40 +0000 Subject: [PATCH] removed previous workaround for already fixed bug in CC2420 CRC --- .../CC2420RadioPacketConverter.java | 49 ++++++------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/CC2420RadioPacketConverter.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/CC2420RadioPacketConverter.java index f6b79215a..6241a325e 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/CC2420RadioPacketConverter.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/CC2420RadioPacketConverter.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: CC2420RadioPacketConverter.java,v 1.15 2010/03/09 10:37:47 nifi Exp $ + * $Id: CC2420RadioPacketConverter.java,v 1.16 2010/03/26 13:33:40 fros4943 Exp $ */ package se.sics.cooja.mspmote.interfaces; @@ -54,7 +54,7 @@ public class CC2420RadioPacketConverter { int pos = 0; byte packetData[] = packet.getPacketData(); byte len; /* total packet minus preamble(4), synch(1) and length(1) */ - WrapperCC2420CRC cc2420CRC = new WrapperCC2420CRC(); + CCITT_CRC cc2420CRC = new CCITT_CRC(); short contikiCRC = 0; /* 4 bytes preamble */ @@ -90,29 +90,29 @@ public class CC2420RadioPacketConverter { /* 4 byte X-MAC: not implemented */ if (WITH_XMAC) { cc2420Data[pos++] = 1; /* TYPE_DATA */ - cc2420CRC.add(1); + cc2420CRC.addBitrev(1); contikiCRC = CRCCoder.crc16Add((byte)0, contikiCRC); cc2420Data[pos++] = 0; - cc2420CRC.add(0); + cc2420CRC.addBitrev(0); contikiCRC = CRCCoder.crc16Add((byte)0, contikiCRC); cc2420Data[pos++] = 0; /* XXX sender: 0.0 */ - cc2420CRC.add(0); + cc2420CRC.addBitrev(0); contikiCRC = CRCCoder.crc16Add((byte)0, contikiCRC); cc2420Data[pos++] = 0; - cc2420CRC.add(0); + cc2420CRC.addBitrev(0); contikiCRC = CRCCoder.crc16Add((byte)0, contikiCRC); cc2420Data[pos++] = 0; /* XXX receiver: 0.0 */ - cc2420CRC.add(0); + cc2420CRC.addBitrev(0); contikiCRC = CRCCoder.crc16Add((byte)0, contikiCRC); cc2420Data[pos++] = 0; - cc2420CRC.add(0); + cc2420CRC.addBitrev(0); contikiCRC = CRCCoder.crc16Add((byte)0, contikiCRC); } /* Payload */ for (byte b : packetData) { contikiCRC = CRCCoder.crc16Add(b, contikiCRC); - cc2420CRC.add(b & 0xFF); + cc2420CRC.addBitrev(b & 0xFF); } System.arraycopy(packetData, 0, cc2420Data, pos, packetData.length); pos += packetData.length; @@ -120,28 +120,25 @@ public class CC2420RadioPacketConverter { /* 2 bytes checksum */ if (WITH_CHECKSUM) { cc2420Data[pos++] = (byte) (contikiCRC & 0xff); - cc2420CRC.add(contikiCRC & 0xFF); + cc2420CRC.addBitrev(contikiCRC & 0xFF); cc2420Data[pos++] = (byte) ((contikiCRC >> 8) & 0xff); - cc2420CRC.add((contikiCRC >> 8) & 0xFF); + cc2420CRC.addBitrev((contikiCRC >> 8) & 0xFF); } /* (TODO) 3 bytes timestamp */ if (WITH_TIMESTAMP) { cc2420Data[pos++] = 0; - cc2420CRC.add(0); + cc2420CRC.addBitrev(0); cc2420Data[pos++] = 0; - cc2420CRC.add(0); + cc2420CRC.addBitrev(0); cc2420Data[pos++] = 0; - cc2420CRC.add(0); + cc2420CRC.addBitrev(0); } /* 2 bytes footer: CC2420's CRC */ if (WITH_FOOTER) { - /* TODO XXX Workaround for (potential) CC2420 bug: - * it excludes the last byte in the CRC */ - int crc = cc2420CRC.getPreviousCRC(); - cc2420Data[pos++] = (byte) ((crc >> 8) & 0xff); - cc2420Data[pos++] = (byte) (crc & 0xff); + cc2420Data[pos++] = (byte) cc2420CRC.getCRCHi(); + cc2420Data[pos++] = (byte) cc2420CRC.getCRCLow(); } byte cc2420DataStripped[] = new byte[pos]; @@ -209,18 +206,4 @@ public class CC2420RadioPacketConverter { return new ConvertedRadioPacket(convertedData, originalData); } - private static class WrapperCC2420CRC extends CCITT_CRC { - int previous = 0; - public WrapperCC2420CRC() { - super(); - } - public int add(int data) { - previous = getCRC(); - return super.add(data); - } - public int getPreviousCRC() { - return previous; - } - } - }