aboutsummaryrefslogtreecommitdiff
path: root/vfd-main/app/plugins/UavClientConnection.scala
blob: 76975e1f16b722eae935fb00039107ef2d00fa7b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package plugins

import akka.actor.Actor
import akka.actor.ActorLogging
import akka.actor.ActorRef
import akka.actor.actorRef2Scala
import vfd.uav.Connection
import akka.util.ByteString

/**
 * Interfaces traffic from a websocket with a connection to a UAV.
 */
class UavClientConnection(websocket: ActorRef, uav: ActorRef) extends Actor with ActorLogging {

  override def preStart = {
    uav ! Connection.Register
  }

  def receive = {

    case Connection.Received(bstr) =>
      websocket ! bstr.toArray

    case Connection.Closed(msg) =>
      log.warning(msg)
      context stop self
      
    case fromClient: Array[Byte] =>
      uav ! Connection.Send(ByteString(fromClient))

  }

}