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

View file

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

View file

@ -1,92 +1,92 @@
/*
* Copyright (c) 2009, 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: MicaClock.java,v 1.1 2009/02/24 07:49:42 joxe Exp $
*/
package se.sics.cooja.avrmote.interfaces;
import java.util.Collection;
import javax.swing.JPanel;
import org.apache.log4j.Logger;
import org.jdom.Element;
import se.sics.cooja.*;
import se.sics.cooja.avrmote.MicaZMote;
import se.sics.cooja.interfaces.Clock;
/**
* @author Fredrik Österlind, Joakim Eriksson
*/
@ClassDescription("Cycle clock")
public class MicaClock extends Clock {
private static Logger logger = Logger.getLogger(MicaClock.class);
private MicaZMote myMote;
public MicaClock(MicaZMote mote) {
myMote = mote;
}
public void setTime(long newTime) {
logger.fatal("Can't change emulated CPU time");
}
public long getTime() {
int time = (int) ((myMote.cycleCounter) / MicaZMote.NR_CYCLES_PER_MSEC);
return time > 0 ? time : 0;
}
public void setDrift(int drift) {
myMote.cycleDrift = MicaZMote.NR_CYCLES_PER_MSEC * drift;
}
public int getDrift() {
return (int) (myMote.cycleDrift / MicaZMote.NR_CYCLES_PER_MSEC);
}
public JPanel getInterfaceVisualizer() {
return null;
}
public void releaseInterfaceVisualizer(JPanel panel) {
}
public double energyConsumption() {
return 0;
}
public Collection<Element> getConfigXML() {
return null;
}
public void setConfigXML(Collection<Element> configXML, boolean visAvailable) {
}
}
/*
* Copyright (c) 2009, 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: MicaClock.java,v 1.2 2009/03/11 14:12:19 fros4943 Exp $
*/
package se.sics.cooja.avrmote.interfaces;
import java.util.Collection;
import javax.swing.JPanel;
import org.apache.log4j.Logger;
import org.jdom.Element;
import se.sics.cooja.*;
import se.sics.cooja.avrmote.MicaZMote;
import se.sics.cooja.interfaces.Clock;
/**
* @author Fredrik Osterlind, Joakim Eriksson
*/
@ClassDescription("Cycle clock")
public class MicaClock extends Clock {
private static Logger logger = Logger.getLogger(MicaClock.class);
private MicaZMote myMote;
public MicaClock(MicaZMote mote) {
myMote = mote;
}
public void setTime(long newTime) {
logger.fatal("Can't change emulated CPU time");
}
public long getTime() {
int time = (int) ((myMote.cycleCounter) / MicaZMote.NR_CYCLES_PER_MSEC);
return time > 0 ? time : 0;
}
public void setDrift(int drift) {
myMote.cycleDrift = MicaZMote.NR_CYCLES_PER_MSEC * drift;
}
public int getDrift() {
return (int) (myMote.cycleDrift / MicaZMote.NR_CYCLES_PER_MSEC);
}
public JPanel getInterfaceVisualizer() {
return null;
}
public void releaseInterfaceVisualizer(JPanel panel) {
}
public double energyConsumption() {
return 0;
}
public Collection<Element> getConfigXML() {
return null;
}
public void setConfigXML(Collection<Element> configXML, boolean visAvailable) {
}
}