diff options
author | Jakob Odersky <jodersky@gmail.com> | 2015-12-28 11:54:00 +0100 |
---|---|---|
committer | Jakob Odersky <jakob@odersky.com> | 2016-01-29 13:50:37 -0800 |
commit | 4f4c799a6d9ccf333a3e609a2464e2f317875af7 (patch) | |
tree | 599232dd8c97fa9eb8f3426ea4375216ecadb386 /mavigator-server/src/main/scala/mavigator/settings.scala | |
parent | c77bf21e7f4c197d34d23b2aebe5953a75d099e2 (diff) | |
download | mavigator-4f4c799a6d9ccf333a3e609a2464e2f317875af7.tar.gz mavigator-4f4c799a6d9ccf333a3e609a2464e2f317875af7.tar.bz2 mavigator-4f4c799a6d9ccf333a3e609a2464e2f317875af7.zip |
Rename project and update dependencies
Diffstat (limited to 'mavigator-server/src/main/scala/mavigator/settings.scala')
-rw-r--r-- | mavigator-server/src/main/scala/mavigator/settings.scala | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/mavigator-server/src/main/scala/mavigator/settings.scala b/mavigator-server/src/main/scala/mavigator/settings.scala new file mode 100644 index 0000000..9089c2e --- /dev/null +++ b/mavigator-server/src/main/scala/mavigator/settings.scala @@ -0,0 +1,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) + +} + |