aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2015-06-19 16:53:37 +0200
committerJakob Odersky <jodersky@gmail.com>2015-06-19 16:55:50 +0200
commit6d20d853f3f7a54131ebd037fd7a9c6d24d48290 (patch)
tree768a08f785dcd13e7014bb756ed130342564f508
parent440b384f95367ec98addd570fc7be265186c8ab2 (diff)
downloadmavigator-6d20d853f3f7a54131ebd037fd7a9c6d24d48290.tar.gz
mavigator-6d20d853f3f7a54131ebd037fd7a9c6d24d48290.tar.bz2
mavigator-6d20d853f3f7a54131ebd037fd7a9c6d24d48290.zip
add prescaler for mock connections to allow slower updates
-rw-r--r--vfd-main/app/plugins/UavPlugin.scala5
-rw-r--r--vfd-uav/src/main/scala/vfd/uav/MockConnection.scala29
2 files changed, 21 insertions, 13 deletions
diff --git a/vfd-main/app/plugins/UavPlugin.scala b/vfd-main/app/plugins/UavPlugin.scala
index 4a484ea..00efb8d 100644
--- a/vfd-main/app/plugins/UavPlugin.scala
+++ b/vfd-main/app/plugins/UavPlugin.scala
@@ -23,7 +23,8 @@ class UavPlugin(app: Application) extends Plugin {
val props = tpe match {
case "mock" =>
val remote = config.flatMap(_.getInt("mock.remote_system_id")).getOrElse(0).toByte
- MockConnection(systemId, compId, remote)
+ val prescaler = config.flatMap(_.getInt("mock.prescaler")).getOrElse(1)
+ MockConnection(systemId, compId, remote, prescaler)
case "serial" =>
val serial = config.flatMap(_.getConfig("serial"))
@@ -44,4 +45,4 @@ class UavPlugin(app: Application) extends Plugin {
def register(websocket: ActorRef): Props = Props(classOf[UavClientConnection], websocket, connection)
-} \ No newline at end of file
+}
diff --git a/vfd-uav/src/main/scala/vfd/uav/MockConnection.scala b/vfd-uav/src/main/scala/vfd/uav/MockConnection.scala
index 9d777ee..d08a8b6 100644
--- a/vfd-uav/src/main/scala/vfd/uav/MockConnection.scala
+++ b/vfd-uav/src/main/scala/vfd/uav/MockConnection.scala
@@ -18,9 +18,15 @@ import scala.concurrent.duration._
import org.mavlink.messages.Message
import vfd.uav.mock.RandomFlightPlan
-class MockConnection(localSystemId: Byte, localComponentId: Byte, remoteSystemId: Byte) extends Actor with ActorLogging with Connection with MavlinkUtil {
+class MockConnection(
+ localSystemId: Byte,
+ localComponentId: Byte,
+ remoteSystemId: Byte,
+ prescaler: Int)
+ extends Actor with ActorLogging with Connection with MavlinkUtil {
+
import Connection._
- import context._
+ import context._
override val systemId = remoteSystemId
override val componentId = remoteSystemId
@@ -36,18 +42,18 @@ class MockConnection(localSystemId: Byte, localComponentId: Byte, remoteSystemId
override def preStart() = {
//increment state
- system.scheduler.schedule(0.01.seconds, 0.01.seconds){plan.tick(0.01)}
+ system.scheduler.schedule(0.01.seconds * prescaler, 0.01.seconds * prescaler){plan.tick(0.01)}
//send messages
- scheduleMessage(0.1.seconds)(plan.position)
- scheduleMessage(0.05.seconds)(plan.attitude)
- scheduleMessage(0.05.seconds)(plan.motors)
- scheduleMessage(0.1.seconds)(plan.distance)
+ scheduleMessage(0.1.seconds * prescaler)(plan.position)
+ scheduleMessage(0.05.seconds * prescaler)(plan.attitude)
+ scheduleMessage(0.05.seconds * prescaler)(plan.motors)
+ scheduleMessage(0.1.seconds * prescaler)(plan.distance)
scheduleMessage(1.seconds)(plan.heartbeat)
//simulate noisy line
- scheduleBytes(0.3.seconds)(MockPackets.invalidCrc)
- scheduleBytes(1.5.seconds)(MockPackets.invalidOverflow)
+ scheduleBytes(0.3.seconds * prescaler)(MockPackets.invalidCrc)
+ scheduleBytes(1.5.seconds * prescaler)(MockPackets.invalidOverflow)
}
def receive = registration
@@ -55,7 +61,8 @@ class MockConnection(localSystemId: Byte, localComponentId: Byte, remoteSystemId
}
object MockConnection {
- def apply(systemId: Byte, componentId: Byte, remoteSystemId: Byte) = Props(classOf[MockConnection], systemId, componentId, remoteSystemId)
+ def apply(systemId: Byte, componentId: Byte, remoteSystemId: Byte, prescaler: Int = 1) =
+ Props(classOf[MockConnection], systemId, componentId, remoteSystemId, prescaler)
}
object MockPackets {
@@ -67,4 +74,4 @@ object MockPackets {
data(1) = -1
data
}
-} \ No newline at end of file
+}