aboutsummaryrefslogtreecommitdiff
path: root/mavigator-uav/src/main/scala/mavigator/uav/MavlinkUtil.scala.disabled
diff options
context:
space:
mode:
Diffstat (limited to 'mavigator-uav/src/main/scala/mavigator/uav/MavlinkUtil.scala.disabled')
-rw-r--r--mavigator-uav/src/main/scala/mavigator/uav/MavlinkUtil.scala.disabled46
1 files changed, 46 insertions, 0 deletions
diff --git a/mavigator-uav/src/main/scala/mavigator/uav/MavlinkUtil.scala.disabled b/mavigator-uav/src/main/scala/mavigator/uav/MavlinkUtil.scala.disabled
new file mode 100644
index 0000000..0fb56b0
--- /dev/null
+++ b/mavigator-uav/src/main/scala/mavigator/uav/MavlinkUtil.scala.disabled
@@ -0,0 +1,46 @@
+package mavigator.uav
+
+import org.mavlink.Assembler
+import org.mavlink.Packet
+import org.mavlink.Parser
+import org.mavlink.messages.Message
+
+import akka.actor.Actor
+import akka.actor.ActorLogging
+import akka.util.ByteString
+
+/** Provides utilities for actors representing a mavlink connection. */
+trait MavlinkUtil { myself: Actor with ActorLogging =>
+
+ /** Mavlink system ID of this connection. */
+ val systemId: Byte
+
+ /** Mavlink component ID of this connection. */
+ val componentId: Byte
+
+ /** Assembler for creating packets originating from this connection. */
+ private lazy val assembler = new Assembler(systemId, componentId)
+
+ /** Assembles a message into a bytestring representing a packet sent from this connection. */
+ protected def assemble(message: Message): ByteString = {
+ val (messageId, payload) = Message.pack(message)
+ val packet: Packet = assembler.assemble(messageId, payload)
+ ByteString(packet.toArray)
+ }
+
+ /** Parser for messages being sent to the uav. */
+ protected val outgoing: Parser = new Parser(packet => Message.unpack(packet.messageId, packet.payload) match {
+ //TODO handle ping
+ /*
+ case Ping(`systemId`, `componentId`) =>
+ val message = Ack(packet.systemId, packet.componentId)
+ val data = assemble(message)
+ self ! Connection.Received(data)*/
+ case _ => ()
+ })
+
+ /** Parser for messages coming from the uav. */
+ protected val incoming: Parser = new Parser(pckt =>
+ log.debug("incoming message: " + Message.unpack(pckt.messageId, pckt.payload)))
+
+}