From 6d20d853f3f7a54131ebd037fd7a9c6d24d48290 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Fri, 19 Jun 2015 16:53:37 +0200 Subject: add prescaler for mock connections to allow slower updates --- vfd-main/app/plugins/UavPlugin.scala | 5 ++-- .../src/main/scala/vfd/uav/MockConnection.scala | 29 ++++++++++++++-------- 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 +} -- cgit v1.2.3