Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a way to connect to an already running instance of mavsdk server #211

Merged
merged 1 commit into from
Jun 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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