diff options
Diffstat (limited to 'vfd-uav/src/main/scala')
-rw-r--r-- | vfd-uav/src/main/scala/org/mavlink/BufferPayloadReader.scala | 2 | ||||
-rw-r--r-- | vfd-uav/src/main/scala/org/mavlink/package.scala | 4 | ||||
-rw-r--r-- | vfd-uav/src/main/scala/vfd/uav/SerialConnection.scala | 20 |
3 files changed, 20 insertions, 6 deletions
diff --git a/vfd-uav/src/main/scala/org/mavlink/BufferPayloadReader.scala b/vfd-uav/src/main/scala/org/mavlink/BufferPayloadReader.scala index c552a96..9f13bff 100644 --- a/vfd-uav/src/main/scala/org/mavlink/BufferPayloadReader.scala +++ b/vfd-uav/src/main/scala/org/mavlink/BufferPayloadReader.scala @@ -19,7 +19,7 @@ class BufferedPayloadReader(payload: Array[Byte]) extends PayloadReader { } -class BufferedPayloadBuilder(payload: Array[Byte]) extends PayloadBuilder { +class BufferedPayloadWriter(payload: Array[Byte]) extends PayloadWriter { private val buffer = ByteBuffer.wrap(payload) //mavlink uses little endian diff --git a/vfd-uav/src/main/scala/org/mavlink/package.scala b/vfd-uav/src/main/scala/org/mavlink/package.scala index 080648d..87a8add 100644 --- a/vfd-uav/src/main/scala/org/mavlink/package.scala +++ b/vfd-uav/src/main/scala/org/mavlink/package.scala @@ -1,7 +1,9 @@ package org +import scala.language.implicitConversions + package object mavlink { - + implicit def mkReader(bytes: Seq[Byte]): PayloadReader = new BufferedPayloadReader(bytes.toArray) }
\ No newline at end of file diff --git a/vfd-uav/src/main/scala/vfd/uav/SerialConnection.scala b/vfd-uav/src/main/scala/vfd/uav/SerialConnection.scala index 3b08215..306d3dc 100644 --- a/vfd-uav/src/main/scala/vfd/uav/SerialConnection.scala +++ b/vfd-uav/src/main/scala/vfd/uav/SerialConnection.scala @@ -1,13 +1,12 @@ package vfd.uav import java.util.concurrent.TimeUnit.MILLISECONDS - import scala.concurrent.duration.FiniteDuration - +import org.mavlink.Parser +import org.mavlink.messages.Message import com.github.jodersky.flow.Parity import com.github.jodersky.flow.Serial import com.github.jodersky.flow.SerialSettings - import akka.actor.Actor import akka.actor.ActorRef import akka.actor.Props @@ -15,8 +14,9 @@ import akka.actor.Terminated import akka.actor.actorRef2Scala import akka.io.IO import akka.util.ByteString +import akka.actor.ActorLogging -class SerialConnection(id: Byte, heartbeat: Option[FiniteDuration], port: String, settings: SerialSettings) extends Actor with Connection { +class SerialConnection(id: Byte, heartbeat: Option[FiniteDuration], port: String, settings: SerialSettings) extends Actor with ActorLogging with Connection { import context._ val Heartbeat = ByteString( @@ -62,6 +62,15 @@ class SerialConnection(id: Byte, heartbeat: Option[FiniteDuration], port: String */ } + + val parser = new Parser( + pckt => try { + log.info(Message.unpack(pckt).toString()) + } catch { + case err: MatchError => + log.info("unknown message: " + pckt.payload.map(_.formatted("%02x").mkString(" "))) + } + ) def _opened(operator: ActorRef): Receive = { @@ -74,6 +83,9 @@ class SerialConnection(id: Byte, heartbeat: Option[FiniteDuration], port: String context become closed case Serial.Received(bstr) => + for (b <- bstr) { + parser.push(b) + } sendAll(Connection.Received(bstr)) case Connection.Send(bstr) => |