Move on to the Scala parts →
See backstory ↓
+-----+-----+-----+-------+--------+-------+---------+-----+
| Stx | Len | Seq | SysID | CompID | MsgID | Payload | CRC |
+-----+-----+-----+-------+--------+-------+---------+-----+
| 1 | 1 | 1 | 1 | 1 | 1 | n | 2 |
+-----+-----+-----+-------+--------+-------+---------+-----+
Common message definitions in XML
Official repository contains bindings for various languages
<message id="0" name="HEARTBEAT">
<description>Description...</description>
<field type="uint8_t" name="type">...</field>
<field type="uint8_t" name="autopilot">...</field>
<field type="uint8_t" name="base_mode">...</field>
<field type="uint32_t" name="custom_mode">...</field>
<field type="uint8_t" name="system_status">...</field>
</message>
Requirement | add Scala | Area |
---|---|---|
Modern, portable UI | Scala.js | frontend |
Web server | Akka Http | backend |
Message streaming | Akka Streams | backend |
sbt mavigator-server/run
//Simple source
val src: Source[Int, _] = Source.tick[Int](100millis, 100millis, 1)
//Nested source
val inc: Source[Int, _] = src.scan(0)(_+_)
//A discrete flow
val flow = Flow[Int].map(_*2)
//Simple sink
val sink = Sink.foreach(println)
//Print all even numbers, ad infinitum
(inc via flow to sink).run()
Serial().watch(Set("/dev/ttyUSB0")).runForeach{ port =>
//replace backend on connection
val multiplexer: Flow[Bytes, Bytes, NotUsed] = setBackend()
//open actual connection to drone
val uav: Flow[Bytes, Bytes, NotUsed] =
Serial().open(port, serialSettings)
(uav join multiplexer).run()
}
Serial()
is a custom Akka extensionpath("/mavlink") {
get {
val fromWebSocket = Flow[Message].collect{
case BinaryMessage.Strict(data) => data
}
val toWebSocket = Flow[Bytes].map{bytes =>
BinaryMessage(bytes)
}
//request connection to multiplexer
val backend: Flow[Bytes, Bytes, NotUsed] = Uav().connect()
handleWebSocketMessages(fromWebSocket via backend via toWebSocket)
}
}
case class Attitude(
timeBootMs: Int,
roll: Float, pitch: Float, yaw: Float,
rollspeed: Float, pitchspeed: Float, yawspeed: Float)
extends Message
Add to dialect definition:
<message id="150" name="STABILITY">
<description>Stability issues</description>
<field type="uint8_t" name="stable">Is it stable?</field>
</message>
git checkout demo1-before
git checkout demo1-after
Mavigator repository:
Project website: