Skip to content

Commit

Permalink
Merge pull request #211 from mavlink/add-connect-to-mavsdk-server
Browse files Browse the repository at this point in the history
Add a way to connect to an already running instance of mavsdk server
  • Loading branch information
JonasVautherin authored Jun 2, 2022
2 parents e5dae3e + 7cdd857 commit f50ed82
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Sources/Mavsdk/Drone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit f50ed82

Please sign in to comment.