diff --git a/tools/cooja/java/org/contikios/cooja/Simulation.java b/tools/cooja/java/org/contikios/cooja/Simulation.java index 74f6ed902..3e94c5dda 100644 --- a/tools/cooja/java/org/contikios/cooja/Simulation.java +++ b/tools/cooja/java/org/contikios/cooja/Simulation.java @@ -71,6 +71,7 @@ public class Simulation extends Observable implements Runnable { private long speedLimitLastSimtime; private long speedLimitLastRealtime; + private long lastStartTime; private long currentSimulationTime = 0; private String title = null; @@ -248,7 +249,7 @@ public class Simulation extends Observable implements Runnable { } public void run() { - long lastStartTime = System.currentTimeMillis(); + lastStartTime = System.currentTimeMillis(); logger.info("Simulation main loop started, system time: " + lastStartTime); isRunning = true; speedLimitLastRealtime = System.currentTimeMillis(); @@ -1075,6 +1076,16 @@ public class Simulation extends Observable implements Runnable { return currentSimulationTime / MILLISECOND; } + /** + * Return the actual time value corresponding to an argument which + * is a simulation time value in microseconds. + * + * @return Actual time (microseconds) + */ + public long convertSimTimeToActualTime(long simTime) { + return simTime + lastStartTime * 1000; + } + /** * Changes radio medium of this simulation to the given. * diff --git a/tools/cooja/java/org/contikios/cooja/plugins/RadioLogger.java b/tools/cooja/java/org/contikios/cooja/plugins/RadioLogger.java index 713390212..32c6e4ee9 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/RadioLogger.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/RadioLogger.java @@ -694,8 +694,8 @@ public class RadioLogger extends VisPlugin { StringBuilder verbose = new StringBuilder(); /* default analyzer */ - PacketAnalyzer.Packet packet = new PacketAnalyzer.Packet(data, PacketAnalyzer.MAC_LEVEL); - + PacketAnalyzer.Packet packet = new PacketAnalyzer.Packet(data, PacketAnalyzer.MAC_LEVEL, + simulation.convertSimTimeToActualTime(conn.startTime)); if (analyzePacket(packet, brief, verbose)) { if (packet.hasMoreData()) { byte[] payload = packet.getPayload(); diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java index 29e29262b..a1239d4ab 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/IEEE802154Analyzer.java @@ -69,7 +69,7 @@ public class IEEE802154Analyzer extends PacketAnalyzer { if (pcapExporter != null) { try { - pcapExporter.exportPacketData(packet.getPayload()); + pcapExporter.exportPacketData(packet.getPayload(), packet.getTimestamp()); } catch (IOException e) { logger.error("Could not export PCap data", e); } diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PacketAnalyzer.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PacketAnalyzer.java index 28a548e3c..b58cc3908 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PacketAnalyzer.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PacketAnalyzer.java @@ -18,6 +18,7 @@ public abstract class PacketAnalyzer { int level; /* size = length - consumed bytes at tail */ int size; + long ts; /* in microseconds */ /* L2 addresseses */ byte[] llsender; @@ -25,10 +26,11 @@ public abstract class PacketAnalyzer { byte lastDispatch = 0; - public Packet(byte[] data, int level) { + public Packet(byte[] data, int level, long ts) { this.level = level; this.data = data.clone(); this.size = data.length; + this.ts = ts; } public void consumeBytesStart(int bytes) { @@ -79,6 +81,10 @@ public abstract class PacketAnalyzer { public byte[] getLLReceiver() { return llreceiver; } + + public long getTimestamp() { + return ts; + } }; public abstract boolean matchPacket(Packet packet); diff --git a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PcapExporter.java b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PcapExporter.java index eb9a61690..1857af353 100644 --- a/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PcapExporter.java +++ b/tools/cooja/java/org/contikios/cooja/plugins/analyzers/PcapExporter.java @@ -41,15 +41,15 @@ public class PcapExporter { out = null; } - public void exportPacketData(byte[] data) throws IOException { + public void exportPacketData(byte[] data, long ts) throws IOException { if (out == null) { /* pcap file never set, open default */ openPcap(null); } try { /* pcap packet header */ - out.writeInt((int) (System.currentTimeMillis() / 1000)); - out.writeInt((int) ((System.currentTimeMillis() % 1000) * 1000)); + out.writeInt((int) (ts / 1000000)); + out.writeInt((int) (ts % 1000000)); out.writeInt(data.length); out.writeInt(data.length); /* and the data */