From 7cdd8570e8f92e95a0fc44d588c96a37e8a13dea Mon Sep 17 00:00:00 2001 From: Jonas Vautherin Date: Thu, 2 Jun 2022 14:42:28 +0200 Subject: [PATCH] Add a way to connect to an already running instance of mavsdk server --- Sources/Mavsdk/Drone.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Sources/Mavsdk/Drone.swift b/Sources/Mavsdk/Drone.swift index 522cfa8..1117e6a 100644 --- a/Sources/Mavsdk/Drone.swift +++ b/Sources/Mavsdk/Drone.swift @@ -35,6 +35,9 @@ public class Drone { case connectionStopped } + /** + * Create an instance of MavsdkServer and running with `systemAddress`, which is the address of the drone. + */ public func connect(systemAddress: String = "udp://:14540") -> Completable { return Completable.create { completable in self.mavsdkServer = MavsdkServer() @@ -57,6 +60,17 @@ public class Drone { } } + /** + * Connect MAVSDK to an already-running instance of MavsdkServer, locally or somewhere on the network. + */ + public func connect(mavsdkServerAddress: String, mavsdkServerPort: Int32 = 50051) -> Completable { + return Completable.create { completable in + self.initPlugins(address: mavsdkServerAddress, port: mavsdkServerPort) + completable(.completed) + return Disposables.create() + } + } + private func initPlugins(address: String = "localhost", port: Int32 = 50051) { self.action = Action(address: address, port: port, scheduler: scheduler) self.calibration = Calibration(address: address, port: port, scheduler: scheduler)