From 094e86ca496fcbe28fe23e6190d797bf7691f761 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Tue, 18 Mar 2008 13:34:20 +0000 Subject: [PATCH] cc24240 packet converter (currently no actual conversion is performed due to already stripped cc2420 output) --- .../mspmote/interfaces/CC2420RadioPacket.java | 46 ++++++++++ .../CC2420RadioPacketConverter.java | 71 ++++++++++++++++ .../cooja/mspmote/interfaces/SkyRadio.java | 83 +++++++++++++++---- 3 files changed, 183 insertions(+), 17 deletions(-) create mode 100644 tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/CC2420RadioPacket.java create mode 100644 tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/CC2420RadioPacketConverter.java diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/CC2420RadioPacket.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/CC2420RadioPacket.java new file mode 100644 index 000000000..0385b9d28 --- /dev/null +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/CC2420RadioPacket.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2008, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: CC2420RadioPacket.java,v 1.1 2008/03/18 13:34:29 fros4943 Exp $ + */ + +package se.sics.cooja.mspmote.interfaces; +import se.sics.cooja.RadioPacket; + +public class CC2420RadioPacket implements RadioPacket { + private byte[] data; + + public CC2420RadioPacket(byte[] data) { + this.data = data; + } + + public byte[] getPacketData() { + return data; + } + +} 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 new file mode 100644 index 000000000..7c737042b --- /dev/null +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/CC2420RadioPacketConverter.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2008, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: CC2420RadioPacketConverter.java,v 1.1 2008/03/18 13:34:29 fros4943 Exp $ + */ + +package se.sics.cooja.mspmote.interfaces; + +import org.apache.log4j.Logger; + +import se.sics.cooja.COOJARadioPacket; +import se.sics.cooja.RadioPacket; + +/** + * Converts radio packets between CC24240/Sky and COOJA. + * Handles radio driver specifics such as length header and CRC footer. + * + * @author Fredrik Osterlind + */ +public class CC2420RadioPacketConverter { + private static Logger logger = Logger.getLogger(CC2420RadioPacketConverter.class); + + /* CC2420/802.15.4 packet: PREAMBLE(4) _ SYNCH(2) _ LENGTH(1) _ PAYLOAD(<27) _ CRCFOOTER(2) */ + + /** + * Converts radio packet data from COOJA to CC2420. + * + * @param coojaPacket COOJA packet + * @return CC2420 packet + */ + public static CC2420RadioPacket fromCoojaToCC24240(RadioPacket coojaPacket) { + return new CC2420RadioPacket(coojaPacket.getPacketData()); + } + + /** + * Converts radio packet data from CC24240 to COOJA. + * + * @param cc24240Data CC24240 data + * @param cc24240DataLength CC24240 data length + * @return + */ + public static COOJARadioPacket fromCC2420ToCooja(CC2420RadioPacket cc2420RadioPacket) { + return new COOJARadioPacket(cc2420RadioPacket.getPacketData()); + } + +} diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/SkyRadio.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/SkyRadio.java index 9054c5550..75f7a4eb2 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/SkyRadio.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/SkyRadio.java @@ -1,3 +1,34 @@ +/* + * Copyright (c) 2008, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $Id: SkyRadio.java,v 1.2 2008/03/18 13:34:20 fros4943 Exp $ + */ + package se.sics.cooja.mspmote.interfaces; import java.awt.BorderLayout; @@ -5,22 +36,24 @@ import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.*; - import javax.swing.*; - import org.apache.log4j.Logger; import org.jdom.Element; import se.sics.cooja.*; -import se.sics.cooja.interfaces.PacketRadio; import se.sics.cooja.interfaces.Position; import se.sics.cooja.interfaces.Radio; import se.sics.cooja.mspmote.SkyMote; import se.sics.mspsim.chip.CC2420; import se.sics.mspsim.chip.PacketListener; +/** + * CC2420 to COOJA wrapper. + * + * @author Fredrik Osterlind + */ @ClassDescription("CC2420") -public class SkyRadio extends Radio implements PacketRadio { +public class SkyRadio extends Radio { private static Logger logger = Logger.getLogger(SkyRadio.class); private int lastEventTime = 0; @@ -39,9 +72,13 @@ public class SkyRadio extends Radio implements PacketRadio { private boolean radioOn = true; - private byte[] lastOutgoingPacket = null; + private CC2420RadioPacket lastOutgoingCC2420Packet = null; - private byte[] lastIncomingPacket = null; + private RadioPacket lastIncomingCC2420Packet = null; + + private RadioPacket lastOutgoingPacket = null; + + private RadioPacket lastIncomingPacket = null; //TODO: HW on/off @@ -58,10 +95,20 @@ public class SkyRadio extends Radio implements PacketRadio { } public void transmissionEnded(int[] receivedData) { - lastOutgoingPacket = new byte[receivedData.length]; + byte[] outgoingCC2420Data = new byte[receivedData.length]; for (int i=0; i < receivedData.length; i++) { - lastOutgoingPacket[i] = (byte) receivedData[i]; + outgoingCC2420Data[i] = (byte) receivedData[i]; } + + lastOutgoingCC2420Packet = new CC2420RadioPacket(outgoingCC2420Data); + + lastEventTime = myMote.getSimulation().getSimulationTime(); + lastEvent = RadioEvent.CUSTOM_DATA_TRANSMITTED; + setChanged(); + notifyObservers(); + + lastOutgoingPacket = CC2420RadioPacketConverter.fromCC2420ToCooja(lastOutgoingCC2420Packet); + lastEventTime = myMote.getSimulation().getSimulationTime(); lastEvent = RadioEvent.PACKET_TRANSMITTED; setChanged(); @@ -76,16 +123,17 @@ public class SkyRadio extends Radio implements PacketRadio { } /* Packet radio support */ - public byte[] getLastPacketTransmitted() { + public RadioPacket getLastPacketTransmitted() { return lastOutgoingPacket; } - public byte[] getLastPacketReceived() { + public RadioPacket getLastPacketReceived() { return lastIncomingPacket; } - public void setReceivedPacket(byte[] data) { - lastIncomingPacket = data; + public void setReceivedPacket(RadioPacket packet) { + lastIncomingPacket = packet; + lastIncomingCC2420Packet = CC2420RadioPacketConverter.fromCoojaToCC24240(packet); } /* General radio support */ @@ -122,10 +170,11 @@ public class SkyRadio extends Radio implements PacketRadio { public void signalReceptionEnd() { /* Deliver packet data */ - if (isReceiving && !isInterfered && lastIncomingPacket != null) { - int[] incomingDataInts = new int[lastIncomingPacket.length]; - for (int i=0; i < lastIncomingPacket.length; i++) { - incomingDataInts[i] = lastIncomingPacket[i]; + if (isReceiving && !isInterfered && lastIncomingCC2420Packet != null) { + byte[] packetData = lastIncomingCC2420Packet.getPacketData(); + int[] incomingDataInts = new int[packetData.length]; + for (int i=0; i < packetData.length; i++) { + incomingDataInts[i] = packetData[i]; } cc2420.setIncomingPacket(incomingDataInts); @@ -149,8 +198,8 @@ public class SkyRadio extends Radio implements PacketRadio { isInterfered = true; isReceiving = false; lastIncomingPacket = null; + lastIncomingCC2420Packet = null; cc2420.setCCA(true); - logger.info("[interfered]: CCA true"); lastEventTime = myMote.getSimulation().getSimulationTime(); lastEvent = RadioEvent.RECEPTION_INTERFERED;