Added system time when the sensordata is received at the base station and fixed sensor data log to be flushed.

This commit is contained in:
nifi 2008-08-29 10:00:23 +00:00
parent ec69c1c825
commit 822726f817
4 changed files with 55 additions and 27 deletions

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: CollectServer.java,v 1.6 2008/08/29 09:00:15 nifi Exp $ * $Id: CollectServer.java,v 1.7 2008/08/29 10:00:23 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,8 +34,8 @@
* *
* Authors : Joakim Eriksson, Niclas Finne * Authors : Joakim Eriksson, Niclas Finne
* Created : 3 jul 2008 * Created : 3 jul 2008
* Updated : $Date: 2008/08/29 09:00:15 $ * Updated : $Date: 2008/08/29 10:00:23 $
* $Revision: 1.6 $ * $Revision: 1.7 $
*/ */
package se.sics.contiki.collect; package se.sics.contiki.collect;
@ -538,7 +538,7 @@ public class CollectServer {
@Override @Override
protected void serialData(String line) { protected void serialData(String line) {
parseIncomingLine(line); parseIncomingLine(System.currentTimeMillis(), line);
} }
}; };
@ -569,6 +569,10 @@ public class CollectServer {
if (serialConnection != null) { if (serialConnection != null) {
serialConnection.close(); serialConnection.close();
} }
PrintWriter output = this.sensorDataOutput;
if (output != null) {
output.close();
}
System.exit(0); System.exit(0);
} }
@ -820,8 +824,8 @@ public class CollectServer {
return false; return false;
} }
protected void parseIncomingLine(String line) { protected void parseIncomingLine(long systemTime, String line) {
SensorData sensorData = SensorData.parseSensorData(this, line); SensorData sensorData = SensorData.parseSensorData(this, line, systemTime);
if (sensorData != null) { if (sensorData != null) {
// Sensor data received // Sensor data received
handleSensorData(sensorData); handleSensorData(sensorData);
@ -869,7 +873,7 @@ public class CollectServer {
Node source = sensorData.getNode(); Node source = sensorData.getNode();
Link link = source.getLink(neighbor); Link link = source.getLink(neighbor);
link.setETX(sensorData.getBestNeighborETX()); link.setETX(sensorData.getBestNeighborETX());
link.setLastActive(sensorData.getTime()); link.setLastActive(sensorData.getNodeTime());
} }
} }
@ -924,6 +928,7 @@ public class CollectServer {
} }
if (output != null) { if (output != null) {
output.println(data.toString()); output.println(data.toString());
output.flush();
} }
} }

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: Node.java,v 1.2 2008/08/29 09:00:15 nifi Exp $ * $Id: Node.java,v 1.3 2008/08/29 10:00:23 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,8 +34,8 @@
* *
* Authors : Joakim Eriksson, Niclas Finne * Authors : Joakim Eriksson, Niclas Finne
* Created : 3 jul 2008 * Created : 3 jul 2008
* Updated : $Date: 2008/08/29 09:00:15 $ * Updated : $Date: 2008/08/29 10:00:23 $
* $Revision: 1.2 $ * $Revision: 1.3 $
*/ */
package se.sics.contiki.collect; package se.sics.contiki.collect;
@ -168,9 +168,9 @@ public class Node implements Comparable<Node> {
if (sensorDataList.size() > 0) { if (sensorDataList.size() > 0) {
SensorData last = sensorDataList.get(sensorDataList.size() - 1); SensorData last = sensorDataList.get(sensorDataList.size() - 1);
// TODO should check seqno! // TODO should check seqno!
if (data.getTime() <= last.getTime()) { if (data.getNodeTime() <= last.getNodeTime()) {
// Sensor data already added // Sensor data already added
System.out.println("SensorData: ignoring (time " + (data.getTime() - last.getTime()) System.out.println("SensorData: ignoring (time " + (data.getNodeTime() - last.getNodeTime())
+ "msec): " + data); + "msec): " + data);
return false; return false;
} }

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: SensorData.java,v 1.3 2008/08/29 09:00:15 nifi Exp $ * $Id: SensorData.java,v 1.4 2008/08/29 10:00:23 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,11 +34,12 @@
* *
* Authors : Joakim Eriksson, Niclas Finne * Authors : Joakim Eriksson, Niclas Finne
* Created : 3 jul 2008 * Created : 3 jul 2008
* Updated : $Date: 2008/08/29 09:00:15 $ * Updated : $Date: 2008/08/29 10:00:23 $
* $Revision: 1.3 $ * $Revision: 1.4 $
*/ */
package se.sics.contiki.collect; package se.sics.contiki.collect;
import java.util.Arrays;
/** /**
* *
@ -47,12 +48,14 @@ public class SensorData implements SensorInfo {
private final Node node; private final Node node;
private final int[] values; private final int[] values;
private final long time; private final long nodeTime;
private final long systemTime;
public SensorData(Node node, int[] values) { public SensorData(Node node, int[] values, long systemTime) {
this.node = node; this.node = node;
this.values = values; this.values = values;
this.time = ((values[TIMESTAMP1] << 16) + values[TIMESTAMP2]) * 1000L; this.nodeTime = ((values[TIMESTAMP1] << 16) + values[TIMESTAMP2]) * 1000L;
this.systemTime = systemTime;
} }
public Node getNode() { public Node getNode() {
@ -71,12 +74,19 @@ public class SensorData implements SensorInfo {
return values.length; return values.length;
} }
public long getTime() { public long getNodeTime() {
return time; return nodeTime;
}
public long getSystemTime() {
return systemTime;
} }
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (systemTime > 0L) {
sb.append(systemTime).append(' ');
}
for (int i = 0, n = values.length; i < n; i++) { for (int i = 0, n = values.length; i < n; i++) {
if (i > 0) sb.append(' '); if (i > 0) sb.append(' ');
sb.append(values[i]); sb.append(values[i]);
@ -85,7 +95,20 @@ public class SensorData implements SensorInfo {
} }
public static SensorData parseSensorData(CollectServer server, String line) { public static SensorData parseSensorData(CollectServer server, String line) {
return parseSensorData(server, line, 0);
}
public static SensorData parseSensorData(CollectServer server, String line, long systemTime) {
String[] components = line.split(" "); String[] components = line.split(" ");
if (components.length == SensorData.VALUES_COUNT + 1) {
// Sensor data with system time
try {
systemTime = Long.parseLong(components[0]);
components = Arrays.copyOfRange(components, 1, components.length);
} catch (NumberFormatException e) {
// First column does not seem to be system time
}
}
if (components.length != SensorData.VALUES_COUNT) { if (components.length != SensorData.VALUES_COUNT) {
return null; return null;
} }
@ -97,7 +120,7 @@ public class SensorData implements SensorInfo {
} }
String nodeID = mapNodeID(data[NODE_ID]); String nodeID = mapNodeID(data[NODE_ID]);
Node node = server.addNode(nodeID); Node node = server.addNode(nodeID);
return new SensorData(node, data); return new SensorData(node, data, systemTime);
} }
public static String mapNodeID(int nodeID) { public static String mapNodeID(int nodeID) {

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: TimeChartPanel.java,v 1.2 2008/08/29 08:42:30 nifi Exp $ * $Id: TimeChartPanel.java,v 1.3 2008/08/29 10:00:23 nifi Exp $
* *
* ----------------------------------------------------------------- * -----------------------------------------------------------------
* *
@ -34,8 +34,8 @@
* *
* Authors : Joakim Eriksson, Niclas Finne * Authors : Joakim Eriksson, Niclas Finne
* Created : 3 jul 2008 * Created : 3 jul 2008
* Updated : $Date: 2008/08/29 08:42:30 $ * Updated : $Date: 2008/08/29 10:00:23 $
* $Revision: 1.2 $ * $Revision: 1.3 $
*/ */
package se.sics.contiki.collect.gui; package se.sics.contiki.collect.gui;
@ -147,7 +147,7 @@ public abstract class TimeChartPanel extends JPanel implements Visualizer {
series.clear(); series.clear();
updateSeries(series, node, groupSize); updateSeries(series, node, groupSize);
} else { } else {
series.addOrUpdate(new Second(new Date(data.getTime())), getSensorDataValue(data)); series.addOrUpdate(new Second(new Date(data.getNodeTime())), getSensorDataValue(data));
} }
chartPanel.repaint(); chartPanel.repaint();
break; break;
@ -175,7 +175,7 @@ public abstract class TimeChartPanel extends JPanel implements Visualizer {
} else { } else {
for (int i = 0, n = node.getSensorDataCount(); i < n; i++) { for (int i = 0, n = node.getSensorDataCount(); i < n; i++) {
SensorData data = node.getSensorData(i); SensorData data = node.getSensorData(i);
series.addOrUpdate(new Second(new Date(data.getTime())), getSensorDataValue(data)); series.addOrUpdate(new Second(new Date(data.getNodeTime())), getSensorDataValue(data));
} }
} }
timeSeries.addSeries(series); timeSeries.addSeries(series);
@ -204,7 +204,7 @@ public abstract class TimeChartPanel extends JPanel implements Visualizer {
for (int j = 0; j < groupSize; j++) { for (int j = 0; j < groupSize; j++) {
SensorData data = node.getSensorData(i); SensorData data = node.getSensorData(i);
value += getSensorDataValue(data); value += getSensorDataValue(data);
time += data.getTime() / 1000L; time += data.getNodeTime() / 1000L;
} }
series.addOrUpdate(new Second(new Date((time / groupSize) * 1000L)), value / groupSize); series.addOrUpdate(new Second(new Date((time / groupSize) * 1000L)), value / groupSize);
} }