rewriting mote interfaces for faster simulation execution.
cfs interface
This commit is contained in:
parent
ed9063719f
commit
f9d2581e06
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
* Copyright (c) 2008, 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
|
||||||
|
@ -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: ContikiCFS.java,v 1.4 2007/01/09 10:05:19 fros4943 Exp $
|
* $Id: ContikiCFS.java,v 1.5 2008/10/28 09:53:23 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.contikimote.interfaces;
|
package se.sics.cooja.contikimote.interfaces;
|
||||||
|
@ -38,18 +38,17 @@ import java.awt.event.ActionListener;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
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.contikimote.ContikiMoteInterface;
|
import se.sics.cooja.contikimote.ContikiMoteInterface;
|
||||||
|
import se.sics.cooja.interfaces.PolledAfterActiveTicks;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class represents a Contiki filesystem, for example an EEPROM or external
|
* Contiki FileSystem (CFS) interface (such as external flash).
|
||||||
* flash memory.
|
|
||||||
*
|
*
|
||||||
* It needs read/write access to the following core variables:
|
* Contiki variables:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>char[] simCFSData
|
* <li>char[] simCFSData
|
||||||
* <li>char simCFSChanged (1=filesystem has been altered)
|
* <li>char simCFSChanged (1=filesystem has been altered)
|
||||||
|
@ -57,21 +56,21 @@ import se.sics.cooja.contikimote.ContikiMoteInterface;
|
||||||
* <li>int simCFSWritten (bytes written to filesystem)
|
* <li>int simCFSWritten (bytes written to filesystem)
|
||||||
* </ul>
|
* </ul>
|
||||||
* <p>
|
* <p>
|
||||||
* Dependency core interfaces are:
|
*
|
||||||
|
* Core interface:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>cfs_interface
|
* <li>cfs_interface
|
||||||
* </ul>
|
* </ul>
|
||||||
* <p>
|
* <p>
|
||||||
* This observable is changed and notifies observers whenever the filesystem has
|
* This observable notifies when the filesystem is used (read/write).
|
||||||
* been read from or written to.
|
|
||||||
*
|
*
|
||||||
* @author Fredrik Osterlind
|
* @author Fredrik Österlind
|
||||||
*/
|
*/
|
||||||
@ClassDescription("Filesystem")
|
@ClassDescription("Filesystem (CFS)")
|
||||||
public class ContikiCFS extends MoteInterface implements ContikiMoteInterface {
|
public class ContikiCFS extends MoteInterface implements ContikiMoteInterface, PolledAfterActiveTicks {
|
||||||
private static Logger logger = Logger.getLogger(ContikiCFS.class);
|
private static Logger logger = Logger.getLogger(ContikiCFS.class);
|
||||||
|
|
||||||
public int FILESYSTEM_SIZE = 60*1024;
|
public int FILESYSTEM_SIZE = 60*1024; /* Configure me */
|
||||||
|
|
||||||
private Mote mote = null;
|
private Mote mote = null;
|
||||||
private SectionMoteMemory moteMem = null;
|
private SectionMoteMemory moteMem = null;
|
||||||
|
@ -110,9 +109,11 @@ public class ContikiCFS extends MoteInterface implements ContikiMoteInterface {
|
||||||
return new String[]{"cfs_interface"};
|
return new String[]{"cfs_interface"};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doActionsBeforeTick() {
|
private TimeEvent doneEvent = new TimeEvent(0) {
|
||||||
// Nothing to do
|
public void execute(int t) {
|
||||||
|
myEnergyConsumption = 0.0;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public void doActionsAfterTick() {
|
public void doActionsAfterTick() {
|
||||||
if (moteMem.getByteValueOf("simCFSChanged") == 1) {
|
if (moteMem.getByteValueOf("simCFSChanged") == 1) {
|
||||||
|
@ -129,8 +130,10 @@ public class ContikiCFS extends MoteInterface implements ContikiMoteInterface {
|
||||||
|
|
||||||
this.setChanged();
|
this.setChanged();
|
||||||
this.notifyObservers(mote);
|
this.notifyObservers(mote);
|
||||||
} else
|
|
||||||
myEnergyConsumption = 0.0;
|
/* Reset energy consumption */
|
||||||
|
mote.getSimulation().addEvent(doneEvent, mote.getSimulation().getSimulationTime());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -176,7 +179,7 @@ public class ContikiCFS extends MoteInterface implements ContikiMoteInterface {
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
final JLabel lastTimeLabel = new JLabel("Last change at: [unknown]");
|
final JLabel lastTimeLabel = new JLabel("Last change at: ?");
|
||||||
final JLabel lastReadLabel = new JLabel("Last change read bytes: 0");
|
final JLabel lastReadLabel = new JLabel("Last change read bytes: 0");
|
||||||
final JLabel lastWrittenLabel = new JLabel("Last change wrote bytes: 0");
|
final JLabel lastWrittenLabel = new JLabel("Last change wrote bytes: 0");
|
||||||
final JButton uploadButton = new JButton("Upload binary file");
|
final JButton uploadButton = new JButton("Upload binary file");
|
||||||
|
@ -238,7 +241,7 @@ public class ContikiCFS extends MoteInterface implements ContikiMoteInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Opens a file dialog and returns the contents of the selected fileor null if dialog aborted.
|
* Opens a file dialog and returns the contents of the selected file or null if dialog aborted.
|
||||||
*
|
*
|
||||||
* @param parent Dialog parent, may be null
|
* @param parent Dialog parent, may be null
|
||||||
* @return Binary contents of user selected file
|
* @return Binary contents of user selected file
|
||||||
|
@ -249,12 +252,13 @@ public class ContikiCFS extends MoteInterface implements ContikiMoteInterface {
|
||||||
JFileChooser fileChooser = new JFileChooser();
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
fileChooser.setCurrentDirectory(new java.io.File("."));
|
fileChooser.setCurrentDirectory(new java.io.File("."));
|
||||||
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
|
||||||
fileChooser.setDialogTitle("Select Contiki executable (.ce)");
|
fileChooser.setDialogTitle("Select binary data");
|
||||||
|
|
||||||
if (fileChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
|
if (fileChooser.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
|
||||||
file = fileChooser.getSelectedFile();
|
file = fileChooser.getSelectedFile();
|
||||||
} else
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// Read file data
|
// Read file data
|
||||||
long fileSize = file.length();
|
long fileSize = file.length();
|
||||||
|
|
Loading…
Reference in a new issue