rewriting mote interfaces for faster simulation execution.
log interface
This commit is contained in:
parent
960f32f3d4
commit
86c3ea9bc8
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
||||
* Copyright (c) 2008, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: ContikiLog.java,v 1.5 2008/10/03 15:18:48 fros4943 Exp $
|
||||
* $Id: ContikiLog.java,v 1.6 2008/10/28 10:28:38 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.contikimote.interfaces;
|
||||
|
@ -40,11 +40,12 @@ import org.jdom.Element;
|
|||
import se.sics.cooja.*;
|
||||
import se.sics.cooja.contikimote.ContikiMoteInterface;
|
||||
import se.sics.cooja.interfaces.Log;
|
||||
|
||||
import se.sics.cooja.interfaces.PolledAfterActiveTicks;
|
||||
|
||||
/**
|
||||
* The class Log is an abstract interface to a mote's logging output. It needs
|
||||
* read access to the following core variables:
|
||||
* Log mote interface. Captures both log_message(,) and printf(..).
|
||||
*
|
||||
* Contiki variables:
|
||||
* <ul>
|
||||
* <li>char simLoggedFlag
|
||||
* (1=mote has new outgoing log messages, else no new)
|
||||
|
@ -53,18 +54,18 @@ import se.sics.cooja.interfaces.Log;
|
|||
* <li>byte[] simLoggedData (data of new log messages)
|
||||
* </ul>
|
||||
* <p>
|
||||
* Dependency core interfaces are:
|
||||
*
|
||||
* Core interface:
|
||||
* <ul>
|
||||
* <li>simlog_interface
|
||||
* </ul>
|
||||
* <p>
|
||||
* This observable is changed and notifies observers whenever a log message has
|
||||
* been received from the core (checked after each tick). The public method
|
||||
* getLastLogMessage gives access to the last log message.
|
||||
*
|
||||
* @author Fredrik Osterlind
|
||||
* This observable notifies at new mote log output.
|
||||
*
|
||||
* @author Fredrik Österlind
|
||||
*/
|
||||
public class ContikiLog extends Log implements ContikiMoteInterface {
|
||||
public class ContikiLog extends Log implements ContikiMoteInterface, PolledAfterActiveTicks {
|
||||
private static Logger logger = Logger.getLogger(ContikiLog.class);
|
||||
private Mote mote = null;
|
||||
private SectionMoteMemory moteMem = null;
|
||||
|
@ -87,10 +88,6 @@ public class ContikiLog extends Log implements ContikiMoteInterface {
|
|||
return new String[] { "simlog_interface" };
|
||||
}
|
||||
|
||||
public void doActionsBeforeTick() {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
public void doActionsAfterTick() {
|
||||
if (moteMem.getByteValueOf("simLoggedFlag") == 1) {
|
||||
int totalLength = moteMem.getIntValueOf("simLoggedLength");
|
||||
|
@ -103,8 +100,8 @@ public class ContikiLog extends Log implements ContikiMoteInterface {
|
|||
moteMem.setByteValueOf("simLoggedFlag", (byte) 0);
|
||||
moteMem.setIntValueOf("simLoggedLength", 0);
|
||||
|
||||
String fullMessage[] = String.valueOf(chars).split("\n");
|
||||
for (String message: fullMessage) {
|
||||
String messages[] = String.valueOf(chars).split("\n");
|
||||
for (String message: messages) {
|
||||
lastLogMessage = message;
|
||||
|
||||
this.setChanged();
|
||||
|
@ -127,13 +124,13 @@ public class ContikiLog extends Log implements ContikiMoteInterface {
|
|||
if (lastLogMessage == null) {
|
||||
logTextPane.setText("");
|
||||
} else {
|
||||
logTextPane.append(lastLogMessage);
|
||||
logTextPane.append(lastLogMessage + "\n");
|
||||
}
|
||||
|
||||
Observer observer;
|
||||
this.addObserver(observer = new Observer() {
|
||||
public void update(Observable obs, Object obj) {
|
||||
logTextPane.append(lastLogMessage);
|
||||
logTextPane.append(lastLogMessage + "\n");
|
||||
logTextPane.setCaretPosition(logTextPane.getDocument().getLength());
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue