Skip to content

Instantly share code, notes, and snippets.

@dunmatt
Created March 22, 2016 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dunmatt/0dbb4180141500c6bdd0 to your computer and use it in GitHub Desktop.
Save dunmatt/0dbb4180141500c6bdd0 to your computer and use it in GitHub Desktop.
This is a simple app to demonstrate connecting to the Mass Destruction telemetry stream and parsing the stream format.
import org.zeromq.ZMQ
case class TelemetryDatum(robotId: Int, x: Double, y: Double, theta: Double) {}
object TelemetryDatum {
def apply(d: String): TelemetryDatum = {
val arr = d.trim.split(" ")
TelemetryDatum(arr(0).toInt, arr(1).toDouble, arr(2).toDouble, arr(3).toDouble)
}
}
object Main extends App {
val context = ZMQ.context(1)
val subscriber = context.socket(ZMQ.SUB)
subscriber.connect("tcp://172.16.10.214:5555") // TODO: make this a command line parameter
subscriber.subscribe(Array.empty[Byte])
(0 until 100).foreach { _ =>
val raw = new String(subscriber.recv(0))
println(TelemetryDatum(raw))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment