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
* 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
* Created : 3 jul 2008
* Updated : $Date: 2008/08/29 09:00:15 $
* $Revision: 1.6 $
* Updated : $Date: 2008/08/29 10:00:23 $
* $Revision: 1.7 $
*/
package se.sics.contiki.collect;
@ -538,7 +538,7 @@ public class CollectServer {
@Override
protected void serialData(String line) {
parseIncomingLine(line);
parseIncomingLine(System.currentTimeMillis(), line);
}
};
@ -569,6 +569,10 @@ public class CollectServer {
if (serialConnection != null) {
serialConnection.close();
}
PrintWriter output = this.sensorDataOutput;
if (output != null) {
output.close();
}
System.exit(0);
}
@ -820,8 +824,8 @@ public class CollectServer {
return false;
}
protected void parseIncomingLine(String line) {
SensorData sensorData = SensorData.parseSensorData(this, line);
protected void parseIncomingLine(long systemTime, String line) {
SensorData sensorData = SensorData.parseSensorData(this, line, systemTime);
if (sensorData != null) {
// Sensor data received
handleSensorData(sensorData);
@ -869,7 +873,7 @@ public class CollectServer {
Node source = sensorData.getNode();
Link link = source.getLink(neighbor);
link.setETX(sensorData.getBestNeighborETX());
link.setLastActive(sensorData.getTime());
link.setLastActive(sensorData.getNodeTime());
}
}
@ -924,6 +928,7 @@ public class CollectServer {
}
if (output != null) {
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
* 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
* Created : 3 jul 2008
* Updated : $Date: 2008/08/29 09:00:15 $
* $Revision: 1.2 $
* Updated : $Date: 2008/08/29 10:00:23 $
* $Revision: 1.3 $
*/
package se.sics.contiki.collect;
@ -168,9 +168,9 @@ public class Node implements Comparable<Node> {
if (sensorDataList.size() > 0) {
SensorData last = sensorDataList.get(sensorDataList.size() - 1);
// TODO should check seqno!
if (data.getTime() <= last.getTime()) {
if (data.getNodeTime() <= last.getNodeTime()) {
// 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);
return false;
}

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* 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
* Created : 3 jul 2008
* Updated : $Date: 2008/08/29 09:00:15 $
* $Revision: 1.3 $
* Updated : $Date: 2008/08/29 10:00:23 $
* $Revision: 1.4 $
*/
package se.sics.contiki.collect;
import java.util.Arrays;
/**
*
@ -47,12 +48,14 @@ public class SensorData implements SensorInfo {
private final Node node;
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.values = values;
this.time = ((values[TIMESTAMP1] << 16) + values[TIMESTAMP2]) * 1000L;
this.nodeTime = ((values[TIMESTAMP1] << 16) + values[TIMESTAMP2]) * 1000L;
this.systemTime = systemTime;
}
public Node getNode() {
@ -71,12 +74,19 @@ public class SensorData implements SensorInfo {
return values.length;
}
public long getTime() {
return time;
public long getNodeTime() {
return nodeTime;
}
public long getSystemTime() {
return systemTime;
}
public String toString() {
StringBuilder sb = new StringBuilder();
if (systemTime > 0L) {
sb.append(systemTime).append(' ');
}
for (int i = 0, n = values.length; i < n; i++) {
if (i > 0) sb.append(' ');
sb.append(values[i]);
@ -85,7 +95,20 @@ public class SensorData implements SensorInfo {
}
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(" ");
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) {
return null;
}
@ -97,7 +120,7 @@ public class SensorData implements SensorInfo {
}
String nodeID = mapNodeID(data[NODE_ID]);
Node node = server.addNode(nodeID);
return new SensorData(node, data);
return new SensorData(node, data, systemTime);
}
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
* 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
* Created : 3 jul 2008
* Updated : $Date: 2008/08/29 08:42:30 $
* $Revision: 1.2 $
* Updated : $Date: 2008/08/29 10:00:23 $
* $Revision: 1.3 $
*/
package se.sics.contiki.collect.gui;
@ -147,7 +147,7 @@ public abstract class TimeChartPanel extends JPanel implements Visualizer {
series.clear();
updateSeries(series, node, groupSize);
} else {
series.addOrUpdate(new Second(new Date(data.getTime())), getSensorDataValue(data));
series.addOrUpdate(new Second(new Date(data.getNodeTime())), getSensorDataValue(data));
}
chartPanel.repaint();
break;
@ -175,7 +175,7 @@ public abstract class TimeChartPanel extends JPanel implements Visualizer {
} else {
for (int i = 0, n = node.getSensorDataCount(); i < n; 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);
@ -204,7 +204,7 @@ public abstract class TimeChartPanel extends JPanel implements Visualizer {
for (int j = 0; j < groupSize; j++) {
SensorData data = node.getSensorData(i);
value += getSensorDataValue(data);
time += data.getTime() / 1000L;
time += data.getNodeTime() / 1000L;
}
series.addOrUpdate(new Second(new Date((time / groupSize) * 1000L)), value / groupSize);
}