From e4e892bc49513cb6a9ea444aa78331e31fe8b7f3 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Mon, 4 Oct 2010 08:14:55 +0000 Subject: [PATCH] added methods for saving radio connections to file from test scripts, as suggested on the develop mailing list --- .../se/sics/cooja/plugins/RadioLogger.java | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/plugins/RadioLogger.java b/tools/cooja/java/se/sics/cooja/plugins/RadioLogger.java index cad32e8f6..b448ce043 100644 --- a/tools/cooja/java/se/sics/cooja/plugins/RadioLogger.java +++ b/tools/cooja/java/se/sics/cooja/plugins/RadioLogger.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: RadioLogger.java,v 1.36 2010/08/13 10:03:58 fros4943 Exp $ + * $Id: RadioLogger.java,v 1.37 2010/10/04 08:14:55 fros4943 Exp $ */ package se.sics.cooja.plugins; @@ -581,7 +581,7 @@ public class RadioLogger extends VisPlugin { return true; } - private static class RadioConnectionLog { + private class RadioConnectionLog { long startTime; long endTime; RadioConnection connection; @@ -589,9 +589,20 @@ public class RadioLogger extends VisPlugin { String data = null; String tooltip = null; + + public String toString() { + if (data == null) { + RadioLogger.this.prepareDataString(this); + } + return + Long.toString(startTime / Simulation.MILLISECOND) + "\t" + + connection.getSource().getMote().getID() + "\t" + + getDestString(this) + "\t" + + data; + } } - private String getDestString(RadioConnectionLog c) { + private static String getDestString(RadioConnectionLog c) { Radio[] dests = c.connection.getDestinations(); if (dests.length == 0) { return "-"; @@ -824,4 +835,18 @@ public class RadioLogger extends VisPlugin { repaint(); } }; + + public String getConnectionsString() { + StringBuilder sb = new StringBuilder(); + RadioConnectionLog[] cs = connections.toArray(new RadioConnectionLog[0]); + for(RadioConnectionLog c: cs) { + sb.append(c.toString() + "\n"); + } + return sb.toString(); + }; + + public void saveConnectionsToFile(String fileName) { + StringUtils.saveToFile(new File(fileName), getConnectionsString()); + }; + }