From ef6ac855d938b4eb44b494ed5470be527137182b Mon Sep 17 00:00:00 2001 From: fros4943 Date: Mon, 17 Mar 2008 09:54:19 +0000 Subject: [PATCH] remade msp init methods --- .../src/se/sics/cooja/mspmote/ESBMote.java | 11 +++++----- .../src/se/sics/cooja/mspmote/MspMote.java | 21 +++++++++++-------- .../se/sics/cooja/mspmote/MspMoteMemory.java | 4 ++-- .../src/se/sics/cooja/mspmote/SkyMote.java | 8 +++---- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMote.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMote.java index 6c3aebbc4..5e6fff997 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMote.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/ESBMote.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ESBMote.java,v 1.1 2008/02/07 14:53:29 fros4943 Exp $ + * $Id: ESBMote.java,v 1.2 2008/03/17 09:54:19 fros4943 Exp $ */ package se.sics.cooja.mspmote; @@ -52,14 +52,14 @@ public class ESBMote extends MspMote { } public ESBMote(MoteType moteType, Simulation sim) { - super((ESBMoteType) moteType, sim); + super((MspMoteType) moteType, sim); } protected boolean initEmulator(File fileELF) { try { - createCPUAndMemory(fileELF); - - esbNode = new ESBNode(getCPU()); + esbNode = new ESBNode(); + esbNode.setupNodePorts(); + prepareMote(fileELF, esbNode.getCPU()); } catch (Exception e) { logger.fatal("Error when creating ESB mote: " + e); @@ -70,6 +70,7 @@ public class ESBMote extends MspMote { protected MoteInterfaceHandler createMoteInterfaceHandler() { MoteInterfaceHandler moteInterfaceHandler = new MoteInterfaceHandler(); + // Add position interface Position motePosition = new Position(this); Random random = new Random(); diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java index d2b1e38ee..7ee2f115c 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMote.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: MspMote.java,v 1.2 2008/02/11 14:07:38 fros4943 Exp $ + * $Id: MspMote.java,v 1.3 2008/03/17 09:54:19 fros4943 Exp $ */ package se.sics.cooja.mspmote; @@ -60,7 +60,6 @@ public abstract class MspMote implements Mote { private MspMoteType myMoteType = null; private MspMoteMemory myMemory = null; private MoteInterfaceHandler myMoteInterfaceHandler = null; - private ELF myELFModule = null; protected TR1001Radio myRadio = null; /* TODO Only used by ESB (TR1001) */ @@ -103,6 +102,10 @@ public abstract class MspMote implements Mote { return myCpu; } + public void setCPU(MSP430 cpu) { + myCpu = cpu; + } + public MoteMemory getMemory() { return myMemory; } @@ -159,19 +162,19 @@ public abstract class MspMote implements Mote { } /** - * Creates MSP430 CPU object and address memory for current object. - * This method should normally not be called from outside constructor. + * Prepares CPU, memory and ELF module. * * @param fileELF ELF file - * @throws IOException File loading failed + * @param cpu MSP430 cpu + * @throws IOException Preparing mote failed */ - protected void createCPUAndMemory(File fileELF) throws IOException { - myCpu = new MSP430(0); + protected void prepareMote(File fileELF, MSP430 cpu) throws IOException { + myCpu = cpu; myCpu.setMonitorExec(true); int[] memory = myCpu.getMemory(); - myELFModule = ELF.readELF(fileELF.getPath()); + ELF myELFModule = ELF.readELF(fileELF.getPath()); myELFModule.loadPrograms(memory); MapTable map = myELFModule.getMap(); myCpu.getDisAsm().setMap(map); @@ -180,7 +183,7 @@ public abstract class MspMote implements Mote { /* TODO Need new memory type including size and type as well */ /* Create mote address memory */ - ArrayList allEntries = map.getAllEntries(); + MapEntry[] allEntries = map.getAllEntries(); myMemory = new MspMoteMemory(allEntries, myCpu); myCpu.reset(); diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteMemory.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteMemory.java index a276c2fd4..9f699aef2 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteMemory.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/MspMoteMemory.java @@ -24,7 +24,7 @@ * (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: MspMoteMemory.java,v 1.2 2008/02/11 14:07:38 fros4943 Exp $ + * $Id: MspMoteMemory.java,v 1.3 2008/03/17 09:54:19 fros4943 Exp $ */ package se.sics.cooja.mspmote; @@ -43,7 +43,7 @@ public class MspMoteMemory implements MoteMemory, AddressMemory { private MSP430 cpu; - public MspMoteMemory(ArrayList allEntries, MSP430 cpu) { + public MspMoteMemory(MapEntry[] allEntries, MSP430 cpu) { this.mapEntries = new ArrayList(); for (MapEntry entry: allEntries) { diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMote.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMote.java index 996be7f9d..ac097eaa4 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMote.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/SkyMote.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: SkyMote.java,v 1.1 2008/02/11 15:23:10 fros4943 Exp $ + * $Id: SkyMote.java,v 1.2 2008/03/17 09:54:19 fros4943 Exp $ */ package se.sics.cooja.mspmote; @@ -58,9 +58,9 @@ public class SkyMote extends MspMote { protected boolean initEmulator(File fileELF) { try { - createCPUAndMemory(fileELF); - - skyNode = new SkyNode(getCPU(), null); + skyNode = new SkyNode(); + skyNode.setupNodePorts(); + prepareMote(fileELF, skyNode.getCPU()); } catch (Exception e) { logger.fatal("Error when creating Sky mote: " + e);