splitting contiki messages on newlines

This commit is contained in:
fros4943 2008-10-03 10:36:39 +00:00
parent 70a74f624a
commit 52d9bcaed5

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: ContikiLog.java,v 1.2 2007/01/09 10:05:19 fros4943 Exp $ * $Id: ContikiLog.java,v 1.3 2008/10/03 10:36:39 fros4943 Exp $
*/ */
package se.sics.cooja.contikimote.interfaces; package se.sics.cooja.contikimote.interfaces;
@ -96,19 +96,22 @@ public class ContikiLog extends Log implements ContikiMoteInterface {
int totalLength = moteMem.getIntValueOf("simLoggedLength"); int totalLength = moteMem.getIntValueOf("simLoggedLength");
byte[] bytes = moteMem.getByteArray("simLoggedData", totalLength); byte[] bytes = moteMem.getByteArray("simLoggedData", totalLength);
char[] chars = new char[bytes.length]; char[] chars = new char[bytes.length];
for (int i=0; i < chars.length; i++) for (int i=0; i < chars.length; i++) {
chars[i] = (char) bytes[i]; chars[i] = (char) bytes[i];
}
String message = String.valueOf(chars);
lastLogMessage = message;
moteMem.setByteValueOf("simLoggedFlag", (byte) 0); moteMem.setByteValueOf("simLoggedFlag", (byte) 0);
moteMem.setIntValueOf("simLoggedLength", (int) 0); moteMem.setIntValueOf("simLoggedLength", 0);
String fullMessage[] = String.valueOf(chars).split("\n");
for (String message: fullMessage) {
lastLogMessage = message;
this.setChanged(); this.setChanged();
this.notifyObservers(mote); this.notifyObservers(mote);
} }
} }
}
public String getLastLogMessages() { public String getLastLogMessages() {
return lastLogMessage; return lastLogMessage;
@ -121,10 +124,11 @@ public class ContikiLog extends Log implements ContikiMoteInterface {
logTextPane.setOpaque(false); logTextPane.setOpaque(false);
logTextPane.setEditable(false); logTextPane.setEditable(false);
if (lastLogMessage == null) if (lastLogMessage == null) {
logTextPane.setText(""); logTextPane.setText("");
else } else {
logTextPane.append(lastLogMessage); logTextPane.append(lastLogMessage);
}
Observer observer; Observer observer;
this.addObserver(observer = new Observer() { this.addObserver(observer = new Observer() {