Skip to content
Open
Show file tree
Hide file tree
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
18 changes: 14 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,24 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/grpc/grpc-swift", from: "1.0.0"),
.package(url: "https://github.com/ReactiveX/RxSwift.git", from: "6.5.0")
.package(url: "https://github.com/ReactiveX/RxSwift.git", from: "6.5.0"),
.package(url: "https://github.com/apple/swift-protobuf.git", .exact("1.19.0")),
.package(url: "https://github.com/apple/swift-nio.git", .exact("2.40.0")),
.package(url: "https://github.com/apple/swift-nio-extras.git", .exact("1.12.1")),
.package(url: "https://github.com/apple/swift-nio-http2.git", .exact("1.22.0")),
.package(url: "https://github.com/apple/swift-log.git", .exact("1.4.2")),
],
targets: [
.target(name: "Mavsdk",
dependencies: [
"MavsdkServer",
.product(name: "GRPC", package: "grpc-swift"),
.product(name: "RxSwift", package: "RxSwift"),
.product(name: "RxBlocking", package: "RxSwift")
.product(name: "SwiftProtobuf", package: "swift-protobuf"),
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOExtras", package: "swift-nio-extras"),
.product(name: "NIOHTTP2", package: "swift-nio-http2"),
.product(name: "Logging", package: "swift-log"),
],
exclude: [
"proto",
Expand All @@ -47,8 +57,8 @@ let package = Package(
]
),
.binaryTarget(name: "mavsdk_server",
url: "https://github.com/mavlink/MAVSDK/releases/download/v1.4.4/mavsdk_server.xcframework.zip",
checksum: "a8c116952919a415a4d8bf166831f0ba4e87c26f4ba33f07aacec9073bc45be6"),
url: "https://github.com/Esri/MAVSDK-Swift/releases/download/1.2.0-appleSilicone/mavsdk_server.xcframework.zip",
checksum: "6b317ae5c4fece38f877f07457997c23b8012d0685d0f14e7df38665d3000b64"),
.testTarget(name: "MavsdkTests",
dependencies: [
"Mavsdk",
Expand Down
8 changes: 7 additions & 1 deletion Sources/Mavsdk/Drone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import MavsdkServer

public class Drone {
private let scheduler: SchedulerType
private var mavsdkServer: MavsdkServer?
public var mavsdkServer: MavsdkServer?

public var action: Action!
public var calibration: Calibration!
public var camera: Camera!
public var core: Core!
public var failure: Failure!
public var followMe: FollowMe!
public var ftp: Ftp!
public var geofence: Geofence!
Expand All @@ -22,8 +23,10 @@ public class Drone {
public var mocap: Mocap!
public var offboard: Offboard!
public var param: Param!
public var rtk: Rtk!
public var shell: Shell!
public var telemetry: Telemetry!
public var transponder: Transponder!
public var tune: Tune!

public init(scheduler: SchedulerType = ConcurrentDispatchQueueScheduler(qos: .background)) {
Expand Down Expand Up @@ -76,6 +79,7 @@ public class Drone {
self.calibration = Calibration(address: address, port: port, scheduler: scheduler)
self.camera = Camera(address: address, port: port, scheduler: scheduler)
self.core = Core(address: address, port: port, scheduler: scheduler)
self.failure = Failure(address: address, port: port, scheduler: scheduler)
self.followMe = FollowMe(address: address, port: port, scheduler: scheduler)
self.ftp = Ftp(address: address, port: port, scheduler: scheduler)
self.geofence = Geofence(address: address, port: port, scheduler: scheduler)
Expand All @@ -88,8 +92,10 @@ public class Drone {
self.mocap = Mocap(address: address, port: port, scheduler: scheduler)
self.offboard = Offboard(address: address, port: port, scheduler: scheduler)
self.param = Param(address: address, port: port, scheduler: scheduler)
self.rtk = Rtk(address: address, port: port, scheduler: scheduler)
self.shell = Shell(address: address, port: port, scheduler: scheduler)
self.telemetry = Telemetry(address: address, port: port, scheduler: scheduler)
self.transponder = Transponder(address: address, port: port, scheduler: scheduler)
self.tune = Tune(address: address, port: port, scheduler: scheduler)
}

Expand Down
158 changes: 155 additions & 3 deletions Sources/Mavsdk/Generated/Param.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,64 @@ public class Param {
}

/**
Type collecting all integer and float parameters.
Type for custom parameters
*/
public struct CustomParam: Equatable {
public let name: String
public let value: String



/**
Initializes a new `CustomParam`.


- Parameters:

- name: Name of the parameter

- value: Value of the parameter (max len 128 bytes)


*/
public init(name: String, value: String) {
self.name = name
self.value = value
}

internal var rpcCustomParam: Mavsdk_Rpc_Param_CustomParam {
var rpcCustomParam = Mavsdk_Rpc_Param_CustomParam()


rpcCustomParam.name = name




rpcCustomParam.value = value



return rpcCustomParam
}

internal static func translateFromRpc(_ rpcCustomParam: Mavsdk_Rpc_Param_CustomParam) -> CustomParam {
return CustomParam(name: rpcCustomParam.name, value: rpcCustomParam.value)
}

public static func == (lhs: CustomParam, rhs: CustomParam) -> Bool {
return lhs.name == rhs.name
&& lhs.value == rhs.value
}
}

/**
Type collecting all integer, float, and custom parameters.
*/
public struct AllParams: Equatable {
public let intParams: [IntParam]
public let floatParams: [FloatParam]
public let customParams: [CustomParam]



Expand All @@ -176,11 +229,14 @@ public class Param {

- floatParams: Collection of all parameter names and values of type float

- customParams: Collection of all parameter names and values of type custom


*/
public init(intParams: [IntParam], floatParams: [FloatParam]) {
public init(intParams: [IntParam], floatParams: [FloatParam], customParams: [CustomParam]) {
self.intParams = intParams
self.floatParams = floatParams
self.customParams = customParams
}

internal var rpcAllParams: Mavsdk_Rpc_Param_AllParams {
Expand All @@ -195,17 +251,23 @@ public class Param {
rpcAllParams.floatParams = floatParams.map{ $0.rpcFloatParam }




rpcAllParams.customParams = customParams.map{ $0.rpcCustomParam }



return rpcAllParams
}

internal static func translateFromRpc(_ rpcAllParams: Mavsdk_Rpc_Param_AllParams) -> AllParams {
return AllParams(intParams: rpcAllParams.intParams.map{ IntParam.translateFromRpc($0) }, floatParams: rpcAllParams.floatParams.map{ FloatParam.translateFromRpc($0) })
return AllParams(intParams: rpcAllParams.intParams.map{ IntParam.translateFromRpc($0) }, floatParams: rpcAllParams.floatParams.map{ FloatParam.translateFromRpc($0) }, customParams: rpcAllParams.customParams.map{ CustomParam.translateFromRpc($0) })
}

public static func == (lhs: AllParams, rhs: AllParams) -> Bool {
return lhs.intParams == rhs.intParams
&& lhs.floatParams == rhs.floatParams
&& lhs.customParams == rhs.customParams
}
}

Expand Down Expand Up @@ -237,6 +299,8 @@ public class Param {
case paramNameTooLong
/// No system connected.
case noSystem
/// Param value too long (> 128).
case paramValueTooLong
case UNRECOGNIZED(Int)

internal var rpcResult: Mavsdk_Rpc_Param_ParamResult.Result {
Expand All @@ -255,6 +319,8 @@ public class Param {
return .paramNameTooLong
case .noSystem:
return .noSystem
case .paramValueTooLong:
return .paramValueTooLong
case .UNRECOGNIZED(let i):
return .UNRECOGNIZED(i)
}
Expand All @@ -276,6 +342,8 @@ public class Param {
return .paramNameTooLong
case .noSystem:
return .noSystem
case .paramValueTooLong:
return .paramValueTooLong
case .UNRECOGNIZED(let i):
return .UNRECOGNIZED(i)
}
Expand Down Expand Up @@ -495,6 +563,90 @@ public class Param {
}
}

/**
Get a custom parameter.

If the type is wrong, the result will be `WRONG_TYPE`.

- Parameter name: Name of the parameter

*/
public func getParamCustom(name: String) -> Single<String> {
return Single<String>.create { single in
var request = Mavsdk_Rpc_Param_GetParamCustomRequest()



request.name = name



do {
let response = self.service.getParamCustom(request)


let result = try response.response.wait().paramResult
if (result.result != Mavsdk_Rpc_Param_ParamResult.Result.success) {
single(.failure(ParamError(code: ParamResult.Result.translateFromRpc(result.result), description: result.resultStr)))

return Disposables.create()
}


let value = try response.response.wait().value

single(.success(value))
} catch {
single(.failure(error))
}

return Disposables.create()
}
}

/**
Set a custom parameter.

If the type is wrong, the result will be `WRONG_TYPE`.

- Parameters:
- name: Name of the parameter to set
- value: Value the parameter should be set to

*/
public func setParamCustom(name: String, value: String) -> Completable {
return Completable.create { completable in
var request = Mavsdk_Rpc_Param_SetParamCustomRequest()



request.name = name



request.value = value



do {

let response = self.service.setParamCustom(request)

let result = try response.response.wait().paramResult
if (result.result == Mavsdk_Rpc_Param_ParamResult.Result.success) {
completable(.completed)
} else {
completable(.error(ParamError(code: ParamResult.Result.translateFromRpc(result.result), description: result.resultStr)))
}

} catch {
completable(.error(error))
}

return Disposables.create()
}
}

/**
Get all parameters.

Expand Down
Loading