diff --git a/src/main/resources/barometer.xml b/src/main/resources/barometer.xml
index 9f9521b..663f445 100644
--- a/src/main/resources/barometer.xml
+++ b/src/main/resources/barometer.xml
@@ -1,6 +1,7 @@
Millibars
+ 0
@@ -21,4 +22,4 @@
-
\ No newline at end of file
+
diff --git a/src/main/resources/rain.xml b/src/main/resources/rain.xml
index dba12d8..2a10ac8 100644
--- a/src/main/resources/rain.xml
+++ b/src/main/resources/rain.xml
@@ -1,6 +1,7 @@
- in/hr
+ mm/hr
+ 0
@@ -9,12 +10,16 @@
AVERAGE
+
+ mmhr
+ rainRate,25.4,*
+
-
- rainRate
- #FF0000
+
+ mmhr
+ #0000FF
-
+
-
\ No newline at end of file
+
diff --git a/src/main/resources/windDir.xml b/src/main/resources/windDir.xml
index 01d83fb..d286b4d 100644
--- a/src/main/resources/windDir.xml
+++ b/src/main/resources/windDir.xml
@@ -1,6 +1,8 @@
Degrees from North
+ 0
+ 360
@@ -17,4 +19,4 @@
-
\ No newline at end of file
+
diff --git a/src/main/scala/uk/org/floop/msc/wview/DataCollector.scala b/src/main/scala/uk/org/floop/msc/wview/DataCollector.scala
index d1f23d3..0f064e6 100644
--- a/src/main/scala/uk/org/floop/msc/wview/DataCollector.scala
+++ b/src/main/scala/uk/org/floop/msc/wview/DataCollector.scala
@@ -1,10 +1,13 @@
package uk.org.floop.msc.wview
import scala.actors.Actor
+import scala.actors.Actor._
import scala.collection.mutable.ListBuffer
-import java.net.{InetSocketAddress, SocketTimeoutException}
-import java.io.IOException
+import net.liftweb.http.LiftRules
+
+import java.net.{InetSocketAddress, SocketTimeoutException, Socket}
+import java.io.{IOException, DataInputStream}
import java.nio.channels.{SocketChannel, ClosedByInterruptException}
import java.nio.ByteBuffer
import java.util.Date
@@ -14,84 +17,57 @@
object DataCollector extends Actor {
def act() {
- var continue = true
var holdoff = 1000
- while (continue) {
- var sc: SocketChannel = null
+ LiftRules.addUnloadHook(() => continue)
+ while(true) {
+ var sock: Socket = null
try {
var startFramePos = 0
var readPos = 0
var packetPos = 0
val values = new ListBuffer[Pair[String, Any]]()
- val sa = new InetSocketAddress("10.79.0.6", 11011)
- sc = SocketChannel.open()
- sc.socket.setSoTimeout(30000)
- sc.connect(sa)
- val bb = ByteBuffer.allocate(4096)
-
- while (sc.read(bb) > 0) {
- holdoff = 1000
- if (startFramePos < 8) { // still reading start frame
- while ((startFramePos < 8) && (readPos < bb.position)) {
- if (bb.get(readPos) == LoopPacket.START_FRAME(startFramePos)) {
- readPos += 1
- startFramePos += 1
- } else { // start frame doesn't match; rewind
- readPos = readPos - startFramePos + 1
- startFramePos = 0
- }
- }
- }
- if (startFramePos == 8) {
- while ((packetPos < LoopPacket.fields.length) &&
- (readPos <= (bb.position - VALUE_TYPE.sizeof(LoopPacket.fields(packetPos)._1)))) {
- LoopPacket.fields(packetPos) match {
- case (VALUE_TYPE.FLOAT, field) => values += (field, bb.getFloat(readPos))
- case (VALUE_TYPE.USHORT, field) => values += (field, bb.getShort(readPos))
- case (VALUE_TYPE.TIME_T, field) => values += (field, bb.getInt(readPos) match {
- case 0 => None
- case x => Some(new Date(x.toLong * 1000))
- })
- case (VALUE_TYPE.SHORT, field) => values += (field, bb.getShort(readPos))
- case (VALUE_TYPE.UCHAR, field) => values += (field, bb.get(readPos))
- }
- readPos += VALUE_TYPE.sizeof(LoopPacket.fields(packetPos)._1)
- packetPos += 1
- }
- if (packetPos == LoopPacket.fields.length) { // read entire loop packet
- DataStore ! StorePacket(values.toList)
- values.clear()
- packetPos = 0
+ sock = new Socket("10.79.0.6", 11011)
+ sock.setSoTimeout(30000)
+ var dis = new DataInputStream(sock.getInputStream)
+ while (true) {
+ while (startFramePos < 8) {
+ if (dis.readByte() == LoopPacket.START_FRAME(startFramePos)) {
+ startFramePos = startFramePos + 1
+ } else {
startFramePos = 0
- if (readPos == bb.position) { // just reset the buffer
- bb.clear()
- } else { // move remaining bytes back to start
- System.arraycopy(bb.array, readPos, bb.array, 0, bb.position - readPos)
- bb.position(bb.position - readPos)
- }
- readPos = 0
}
}
- }
- println("DataCollector: empty read, restarting.")
- Thread.sleep(holdoff)
- if (holdoff < 60000) {
- holdoff = holdoff * 2
+ packetPos = 0
+ while (packetPos < LoopPacket.fields.length) {
+ LoopPacket.fields(packetPos) match {
+ case (VALUE_TYPE.FLOAT, field) => values += (field, dis.readFloat())
+ case (VALUE_TYPE.USHORT, field) => values += (field, dis.readShort())
+ case (VALUE_TYPE.TIME_T, field) => values += (field, dis.readInt() match {
+ case 0 => None
+ case x => Some(new Date(x.toLong * 1000))
+ })
+ case (VALUE_TYPE.SHORT, field) => values += (field, dis.readShort())
+ case (VALUE_TYPE.UCHAR, field) => values += (field, dis.readChar())
+ }
+ packetPos = packetPos + 1
+ }
+ startFramePos = 0
+ DataStore ! StorePacket(values.toList)
+ values.clear()
+ holdoff = 1000
}
} catch {
- case ex: ClosedByInterruptException =>
- continue = false // some other thread interrupted us, so don't continue
- println("DataCollector interrupted, closing down.")
- case ex: IOException => // includes SocketTimeoutException
- // could occur in sc.open or sc.read, either way, close up but continue (re-open, etc.)
+ case ex: IOException => // includes timeout
println("DataCollector exception: " + ex)
Thread.sleep(holdoff)
if (holdoff < 60000) {
holdoff = holdoff * 2
}
} finally {
- sc.close()
+ if ((sock != null) && (!sock.isClosed)) {
+ sock.close()
+ }
}
}
}