blob: 9089c2e1aebdf1397898fdcd9343282f592e9c71 (
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
package mavigator
import akka.actor.ActorSystem
import akka.actor.Extension
import akka.actor.ExtensionId
import akka.actor.ExtensionIdProvider
import akka.actor.ExtendedActorSystem
import scala.concurrent.duration.Duration
import com.typesafe.config.Config
import java.util.concurrent.TimeUnit
import akka.actor.ActorRef
import akka.actor.Props
import mavigator.uav.MockConnection
import mavigator.uav.SerialConnection
class MavigatorImpl(system: ExtendedActorSystem) extends Extension {
private val config = system.settings.config.getConfig("mavigator")
val interface: String = config.getString("interface")
val port: Int = config.getInt("port")
/** Mavlink system ID identifying the base station */
val systemId: Byte = config.getInt("system_id").toByte
val tpe = config.getString("connection.type")
/** Actor representing a connection channel to UAVs. This actor
* implements the protocol defined in [mavigator.uav.Connection] */
val uav: ActorRef = {
val config = this.config.getConfig("connection")
val tpe = config.getString("type")
val heartbeat = config.getInt("heartbeat")
val compId = config.getString("component_id").toByte
val props = tpe match {
case "mock" =>
val remote = config.getInt("mock.remote_system_id").toByte
val prescaler = config.getInt("mock.prescaler")
MockConnection(systemId, compId, remote, prescaler)
case "serial" =>
val serial = config.getConfig("serial")
SerialConnection(
systemId,
compId,
heartbeat,
serial.getString("port"),
serial.getInt("baud"),
serial.getBoolean("two_stop_bits"),
serial.getInt("parity")
)
case unknown => throw new IllegalArgumentException("Unsupported connection type '" + unknown + "'")
}
system.actorOf(props, name = "uav-connection")
}
}
object Mavigator extends ExtensionId[MavigatorImpl] with ExtensionIdProvider {
override def lookup = Mavigator
override def createExtension(system: ExtendedActorSystem) =
new MavigatorImpl(system)
}
|