implemented new mote type interfaces

This commit is contained in:
fros4943 2009-03-11 14:12:18 +00:00
parent adf1489cda
commit 1ca67916a4
3 changed files with 146 additions and 160 deletions

View file

@ -26,22 +26,16 @@
* 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: MicaZMote.java,v 1.2 2009/02/24 07:49:42 joxe Exp $ * $Id: MicaZMote.java,v 1.3 2009/03/11 14:12:19 fros4943 Exp $
*/ */
package se.sics.cooja.avrmote; package se.sics.cooja.avrmote;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.net.URL;
import java.util.Collection; import java.util.Collection;
import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import java.util.Random; import java.util.Random;
import java.util.Vector; import java.util.Vector;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
import se.sics.cooja.GUI;
import se.sics.cooja.Mote; import se.sics.cooja.Mote;
import se.sics.cooja.MoteInterface; import se.sics.cooja.MoteInterface;
import se.sics.cooja.MoteInterfaceHandler; import se.sics.cooja.MoteInterfaceHandler;
@ -56,8 +50,6 @@ import avrora.sim.*;
import avrora.sim.platform.*; import avrora.sim.platform.*;
import avrora.sim.mcu.*; import avrora.sim.mcu.*;
import avrora.core.*; import avrora.core.*;
import avrora.sim.radio.*;
import avrora.sim.util.SimUtil;
/** /**
@ -97,7 +89,7 @@ public class MicaZMote implements Mote {
public MicaZ getMicaZ() { public MicaZ getMicaZ() {
return micaZ; return micaZ;
} }
public MicaZMote() { public MicaZMote() {
mySimulation = null; mySimulation = null;
myCpu = null; myCpu = null;
@ -111,7 +103,7 @@ public class MicaZMote implements Mote {
protected void initMote() { protected void initMote() {
if (myMoteType != null) { if (myMoteType != null) {
initEmulator(myMoteType.getELFFile()); initEmulator(myMoteType.getContikiFirmwareFile().getName());
myMoteInterfaceHandler = createMoteInterfaceHandler(); myMoteInterfaceHandler = createMoteInterfaceHandler();
} }
} }
@ -126,7 +118,7 @@ public class MicaZMote implements Mote {
return true; return true;
} }
public Simulation getSimulation() { public Simulation getSimulation() {
return mySimulation; return mySimulation;
} }
@ -140,7 +132,7 @@ public class MicaZMote implements Mote {
* *
* @param fileELF ELF file * @param fileELF ELF file
* @param cpu MSP430 cpu * @param cpu MSP430 cpu
* @throws Exception * @throws Exception
*/ */
protected void prepareMote(String file) throws Exception { protected void prepareMote(String file) throws Exception {
program = new LoadableProgram(file); program = new LoadableProgram(file);
@ -242,7 +234,7 @@ public class MicaZMote implements Mote {
getType().setIdentifier(element.getText()); getType().setIdentifier(element.getText());
try { try {
prepareMote(myMoteType.getELFFile()); prepareMote(myMoteType.getContikiFirmwareFile().getName());
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -275,7 +267,7 @@ public class MicaZMote implements Mote {
Random random = new Random(); /* Do not use main random generator for positioning */ Random random = new Random(); /* Do not use main random generator for positioning */
motePosition.setCoordinates(random.nextDouble()*100, random.nextDouble()*100, random.nextDouble()*100); motePosition.setCoordinates(random.nextDouble()*100, random.nextDouble()*100, random.nextDouble()*100);
moteInterfaceHandler.addInterface(motePosition); moteInterfaceHandler.addInterface(motePosition);
// Add LED interface // Add LED interface
moteInterfaceHandler.addInterface(new MicaZLED(micaZ)); moteInterfaceHandler.addInterface(new MicaZLED(micaZ));
// Add Radio interface // Add Radio interface
@ -283,7 +275,7 @@ public class MicaZMote implements Mote {
// Add Radio interface // Add Radio interface
moteInterfaceHandler.addInterface(new MicaClock(this)); moteInterfaceHandler.addInterface(new MicaClock(this));
return moteInterfaceHandler; return moteInterfaceHandler;
} }

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: MicaZMoteType.java,v 1.1 2009/02/22 16:45:01 joxe Exp $ * $Id: MicaZMoteType.java,v 1.2 2009/03/11 14:12:18 fros4943 Exp $
*/ */
package se.sics.cooja.avrmote; package se.sics.cooja.avrmote;
@ -53,7 +53,7 @@ public class MicaZMoteType implements MoteType {
public static final String target = "micaz"; public static final String target = "micaz";
public static final String targetNice = "MicaZ"; public static final String targetNice = "MicaZ";
protected static String getTargetFileExtension(String target) { protected static String getTargetFileExtension(String target) {
return "." + target; return "." + target;
} }
@ -65,7 +65,7 @@ public class MicaZMoteType implements MoteType {
private String description = null; private String description = null;
/* If source file is defined, (re)compilation is performed */ /* If source file is defined, (re)compilation is performed */
private String fileFirmware = null; private File fileFirmware = null;
private File fileSource = null; private File fileSource = null;
private String compileCommand = null; private String compileCommand = null;
@ -85,37 +85,31 @@ public class MicaZMoteType implements MoteType {
this.description = description; this.description = description;
} }
/** public Class<? extends MoteInterface>[] getMoteInterfaceClasses() {
* Set ELF file. logger.fatal("Not implemented");
* return null;
* @param file
* ELF file
*/
public void setELFFile(File file) {
this.fileFirmware = file.getAbsolutePath();
} }
/** public void setMoteInterfaceClasses(Class<? extends MoteInterface>[] classes) {
* Set compile command. logger.fatal("Not implemented");
* }
* @param command
* Compile command public void setContikiFirmwareFile(File file) {
*/ this.fileFirmware = file;
public void setCompileCommand(String command) { }
public void setCompileCommands(String command) {
this.compileCommand = command; this.compileCommand = command;
} }
/** public File getContikiFirmwareFile() {
* @return ELF file
*/
public String getELFFile() {
return fileFirmware; return fileFirmware;
} }
/** /**
* @return Compile command * @return Compile command
*/ */
public String getCompileCommand() { public String getCompileCommands() {
return compileCommand; return compileCommand;
} }
@ -124,14 +118,14 @@ public class MicaZMoteType implements MoteType {
* *
* @param file Source file * @param file Source file
*/ */
public void setSourceFile(File file) { public void setContikiSourceFile(File file) {
fileSource = file; fileSource = file;
} }
/** /**
* @return Source file * @return Source file
*/ */
public File getSourceFile() { public File getContikiSourceFile() {
return fileSource; return fileSource;
} }
@ -212,7 +206,7 @@ public class MicaZMoteType implements MoteType {
setDescription(targetNice + " Mote Type #" + getIdentifier()); setDescription(targetNice + " Mote Type #" + getIdentifier());
} }
if (getSourceFile() != null) { if (getContikiSourceFile() != null) {
compileFromSource = true; compileFromSource = true;
} }
@ -223,9 +217,9 @@ public class MicaZMoteType implements MoteType {
if (visAvailable) { if (visAvailable) {
boolean success = compiler.showDialog(GUI.getTopParentContainer(), this); boolean success = compiler.showDialog(GUI.getTopParentContainer(), this);
if (success) { if (success) {
setSourceFile(compiler.getSourceFile()); setContikiSourceFile(compiler.getSourceFile());
setELFFile(compiler.getOutputFile()); setContikiFirmwareFile(compiler.getOutputFile());
setCompileCommand(compiler.getLastCompileCommand()); setCompileCommands(compiler.getLastCompileCommand());
return true; return true;
} else { } else {
return false; return false;
@ -233,7 +227,7 @@ public class MicaZMoteType implements MoteType {
} else { } else {
MessageList compilationOutput = new MessageList(); MessageList compilationOutput = new MessageList();
try { try {
compiler.compileFirmware(getSourceFile(), null, null, compilationOutput, compiler.compileFirmware(getContikiSourceFile(), null, null, compilationOutput,
true); true);
} catch (Exception e) { } catch (Exception e) {
@ -255,9 +249,9 @@ public class MicaZMoteType implements MoteType {
throw newException; throw newException;
} }
setSourceFile(compiler.getSourceFile()); setContikiSourceFile(compiler.getSourceFile());
setELFFile(compiler.getOutputFile()); setContikiFirmwareFile(compiler.getOutputFile());
setCompileCommand(compiler.getLastCompileCommand()); setCompileCommands(compiler.getLastCompileCommand());
return true; return true;
} }
@ -269,12 +263,12 @@ public class MicaZMoteType implements MoteType {
// Check dependency files // Check dependency files
File elfFile = null; File elfFile = null;
if (getELFFile() != null) { if (getContikiFirmwareFile() != null) {
elfFile = new File(getELFFile()); elfFile = new File(getContikiFirmwareFile().getName());
} }
if (elfFile == null || !elfFile.exists()) { if (elfFile == null || !elfFile.exists()) {
if (!visAvailable) { if (!visAvailable) {
throw new MoteTypeCreationException("ELF file does not exist: " + getELFFile()); throw new MoteTypeCreationException("ELF file does not exist: " + getContikiFirmwareFile());
} }
JFileChooser fc = new JFileChooser(); JFileChooser fc = new JFileChooser();
@ -334,8 +328,8 @@ public class MicaZMoteType implements MoteType {
logger.fatal("Selected file \"" + selectedFile + "\" does not exist"); logger.fatal("Selected file \"" + selectedFile + "\" does not exist");
return false; return false;
} }
setELFFile(fc.getSelectedFile()); setContikiFirmwareFile(fc.getSelectedFile());
} else { } else {
return false; return false;
} }
@ -385,7 +379,7 @@ public class MicaZMoteType implements MoteType {
this.target = target; this.target = target;
} }
private String getCompileCommand(String filename) { private String getCompileCommands(String filename) {
if (customizedCompileCommand != null) { if (customizedCompileCommand != null) {
return customizedCompileCommand; return customizedCompileCommand;
} }
@ -451,7 +445,7 @@ public class MicaZMoteType implements MoteType {
compileButton.setEnabled(true); compileButton.setEnabled(true);
createButton.setEnabled(false); createButton.setEnabled(false);
compileCommandTextField.setText(getCompileCommand(name)); compileCommandTextField.setText(getCompileCommands(name));
compileButton.requestFocusInWindow(); compileButton.requestFocusInWindow();
break; break;
@ -481,7 +475,7 @@ public class MicaZMoteType implements MoteType {
final String filenameNoExtension = sourceFile.getName().substring(0, final String filenameNoExtension = sourceFile.getName().substring(0,
sourceFile.getName().length() - 2); sourceFile.getName().length() - 2);
final String command = getCompileCommand(filenameNoExtension); final String command = getCompileCommands(filenameNoExtension);
logger.info("-- Compiling AVR/MicaZ Firmware --"); logger.info("-- Compiling AVR/MicaZ Firmware --");
compileFirmware(command, sourceFile, filenameNoExtension + getTargetFileExtension(target), compileFirmware(command, sourceFile, filenameNoExtension + getTargetFileExtension(target),
@ -771,8 +765,8 @@ public class MicaZMoteType implements MoteType {
label.setPreferredSize(new Dimension(LABEL_WIDTH, LABEL_HEIGHT)); label.setPreferredSize(new Dimension(LABEL_WIDTH, LABEL_HEIGHT));
sourceTextField.setText(""); sourceTextField.setText("");
if (moteType.getSourceFile() != null) { if (moteType.getContikiSourceFile() != null) {
sourceTextField.setText(moteType.getSourceFile().getAbsolutePath()); sourceTextField.setText(moteType.getContikiSourceFile().getAbsolutePath());
} }
sourceTextField.setColumns(25); sourceTextField.setColumns(25);
@ -958,7 +952,7 @@ public class MicaZMoteType implements MoteType {
}); });
updateDialog(DialogState.NO_SOURCE); updateDialog(DialogState.NO_SOURCE);
if (moteType.getSourceFile() != null) { if (moteType.getContikiSourceFile() != null) {
updateDialog(DialogState.SELECTED_SOURCE); updateDialog(DialogState.SELECTED_SOURCE);
if (customizedCompileCommand != null && !customizedCompileCommand.equals("")) { if (customizedCompileCommand != null && !customizedCompileCommand.equals("")) {
compileCommandTextField.setText(customizedCompileCommand); compileCommandTextField.setText(customizedCompileCommand);
@ -1000,7 +994,7 @@ public class MicaZMoteType implements MoteType {
smallPane = new JPanel(new BorderLayout()); smallPane = new JPanel(new BorderLayout());
label = new JLabel("ELF file"); label = new JLabel("ELF file");
smallPane.add(BorderLayout.WEST, label); smallPane.add(BorderLayout.WEST, label);
File elfFile = new File(getELFFile()); File elfFile = getContikiFirmwareFile();
label = new JLabel(elfFile.getName()); label = new JLabel(elfFile.getName());
label.setToolTipText(elfFile.getPath()); label.setToolTipText(elfFile.getPath());
smallPane.add(BorderLayout.EAST, label); smallPane.add(BorderLayout.EAST, label);
@ -1010,9 +1004,9 @@ public class MicaZMoteType implements MoteType {
smallPane = new JPanel(new BorderLayout()); smallPane = new JPanel(new BorderLayout());
label = new JLabel("Source file"); label = new JLabel("Source file");
smallPane.add(BorderLayout.WEST, label); smallPane.add(BorderLayout.WEST, label);
if (getSourceFile() != null) { if (getContikiSourceFile() != null) {
label = new JLabel(getSourceFile().getName()); label = new JLabel(getContikiSourceFile().getName());
label.setToolTipText(getSourceFile().getPath()); label.setToolTipText(getContikiSourceFile().getPath());
} else { } else {
label = new JLabel("[not specified]"); label = new JLabel("[not specified]");
} }
@ -1075,9 +1069,9 @@ public class MicaZMoteType implements MoteType {
} else { } else {
// ELF file // ELF file
element = new Element("elf"); element = new Element("elf");
File file = new File(fileFirmware); File file = fileFirmware;
file = GUI.stripAbsoluteContikiPath(file); file = GUI.stripAbsoluteContikiPath(file);
fileFirmware = file.getAbsolutePath(); fileFirmware = file;
element.setText(file.getPath().replaceAll("\\\\", "/")); element.setText(file.getPath().replaceAll("\\\\", "/"));
config.add(element); config.add(element);
} }
@ -1100,7 +1094,7 @@ public class MicaZMoteType implements MoteType {
} else if (name.equals("command")) { } else if (name.equals("command")) {
compileCommand = element.getText(); compileCommand = element.getText();
} else if (name.equals("elf")) { } else if (name.equals("elf")) {
fileFirmware = new File(element.getText()).getAbsolutePath(); fileFirmware = new File(element.getText());
} else { } else {
logger.fatal("Unrecognized entry in loaded configuration: " + name); logger.fatal("Unrecognized entry in loaded configuration: " + name);
throw new MoteTypeCreationException( throw new MoteTypeCreationException(
@ -1118,7 +1112,7 @@ public class MicaZMoteType implements MoteType {
if (GUI.isVisualizedInApplet()) { if (GUI.isVisualizedInApplet()) {
String firmware = GUI.getExternalToolsSetting("MICAZ_FIRMWARE", ""); String firmware = GUI.getExternalToolsSetting("MICAZ_FIRMWARE", "");
if (!firmware.equals("")) { if (!firmware.equals("")) {
setELFFile(new File(firmware)); setContikiFirmwareFile(new File(firmware));
JOptionPane.showMessageDialog(GUI.getTopParentContainer(), JOptionPane.showMessageDialog(GUI.getTopParentContainer(),
"Creating mote type from precompiled firmware: " + firmware, "Creating mote type from precompiled firmware: " + firmware,
"Compiled firmware file available", JOptionPane.INFORMATION_MESSAGE); "Compiled firmware file available", JOptionPane.INFORMATION_MESSAGE);

View file

@ -1,92 +1,92 @@
/* /*
* Copyright (c) 2009, Swedish Institute of Computer Science. * Copyright (c) 2009, Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
* 1. Redistributions of source code must retain the above copyright * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright * 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors * 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 * may be used to endorse or promote products derived from this software
* without specific prior written permission. * without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * 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 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id: MicaClock.java,v 1.1 2009/02/24 07:49:42 joxe Exp $ * $Id: MicaClock.java,v 1.2 2009/03/11 14:12:19 fros4943 Exp $
*/ */
package se.sics.cooja.avrmote.interfaces; package se.sics.cooja.avrmote.interfaces;
import java.util.Collection; import java.util.Collection;
import javax.swing.JPanel; import javax.swing.JPanel;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
import se.sics.cooja.*; import se.sics.cooja.*;
import se.sics.cooja.avrmote.MicaZMote; import se.sics.cooja.avrmote.MicaZMote;
import se.sics.cooja.interfaces.Clock; import se.sics.cooja.interfaces.Clock;
/** /**
* @author Fredrik Österlind, Joakim Eriksson * @author Fredrik Osterlind, Joakim Eriksson
*/ */
@ClassDescription("Cycle clock") @ClassDescription("Cycle clock")
public class MicaClock extends Clock { public class MicaClock extends Clock {
private static Logger logger = Logger.getLogger(MicaClock.class); private static Logger logger = Logger.getLogger(MicaClock.class);
private MicaZMote myMote; private MicaZMote myMote;
public MicaClock(MicaZMote mote) { public MicaClock(MicaZMote mote) {
myMote = mote; myMote = mote;
} }
public void setTime(long newTime) { public void setTime(long newTime) {
logger.fatal("Can't change emulated CPU time"); logger.fatal("Can't change emulated CPU time");
} }
public long getTime() { public long getTime() {
int time = (int) ((myMote.cycleCounter) / MicaZMote.NR_CYCLES_PER_MSEC); int time = (int) ((myMote.cycleCounter) / MicaZMote.NR_CYCLES_PER_MSEC);
return time > 0 ? time : 0; return time > 0 ? time : 0;
} }
public void setDrift(int drift) { public void setDrift(int drift) {
myMote.cycleDrift = MicaZMote.NR_CYCLES_PER_MSEC * drift; myMote.cycleDrift = MicaZMote.NR_CYCLES_PER_MSEC * drift;
} }
public int getDrift() { public int getDrift() {
return (int) (myMote.cycleDrift / MicaZMote.NR_CYCLES_PER_MSEC); return (int) (myMote.cycleDrift / MicaZMote.NR_CYCLES_PER_MSEC);
} }
public JPanel getInterfaceVisualizer() { public JPanel getInterfaceVisualizer() {
return null; return null;
} }
public void releaseInterfaceVisualizer(JPanel panel) { public void releaseInterfaceVisualizer(JPanel panel) {
} }
public double energyConsumption() { public double energyConsumption() {
return 0; return 0;
} }
public Collection<Element> getConfigXML() { public Collection<Element> getConfigXML() {
return null; return null;
} }
public void setConfigXML(Collection<Element> configXML, boolean visAvailable) { public void setConfigXML(Collection<Element> configXML, boolean visAvailable) {
} }
} }