Skip to content

Commit

Permalink
OcaApplicationNetwork device side
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoward committed Dec 18, 2023
1 parent 3c4901e commit 9f73ac6
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 49 deletions.
20 changes: 2 additions & 18 deletions Sources/SwiftOCA/OCC/ControlClasses/Agents/Agent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,6 @@
// limitations under the License.
//

public struct OcaGetPathParameters: Codable, Sendable, OcaParameterCountReflectable {
public static var responseParameterCount: OcaUint8 { 2 }

public var namePath: OcaNamePath
public var oNoPath: OcaONoPath

public init(namePath: OcaNamePath, oNoPath: OcaONoPath) {
self.namePath = namePath
self.oNoPath = oNoPath
}
}

open class OcaAgent: OcaRoot {
override public class var classID: OcaClassID { OcaClassID("1.2") }

Expand All @@ -42,13 +30,9 @@ open class OcaAgent: OcaRoot {
)
public var owner: OcaProperty<OcaONo>.State

var path: (OcaNamePath, OcaONoPath) {
public var path: (OcaNamePath, OcaONoPath) {
get async throws {
let responseParams: OcaGetPathParameters

responseParams = try await sendCommandRrq(methodID: OcaMethodID("2.4"))

return (responseParams.namePath, responseParams.oNoPath)
try await getPath(methodID: OcaMethodID("2.4"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,16 @@ open class OcaApplicationNetwork: OcaRoot {
)
public var errorCode: OcaProperty<OcaUint16>.State

var path: (OcaNamePath, OcaONoPath) {
get async throws {
let responseParams: OcaGetPathParameters

responseParams = try await sendCommandRrq(methodID: OcaMethodID("2.11"))

return (responseParams.namePath, responseParams.oNoPath)
}
}

func control(_ command: OcaApplicationNetworkCommand) async throws {
public func control(_ command: OcaApplicationNetworkCommand) async throws {
try await sendCommandRrq(
methodID: OcaMethodID("2.10"),
parameters: command
)
}

public var path: (OcaNamePath, OcaONoPath) {
get async throws {
try await getPath(methodID: OcaMethodID("2.11"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ open class OcaNetworkApplication: OcaRoot {

public var path: (OcaNamePath, OcaONoPath) {
get async throws {
let responseParams: OcaGetPathParameters
responseParams = try await sendCommandRrq(methodID: OcaMethodID("2.4"))
return (responseParams.namePath, responseParams.oNoPath)
try await getPath(methodID: OcaMethodID("2.4"))
}
}

Expand Down
20 changes: 20 additions & 0 deletions Sources/SwiftOCA/OCC/ControlClasses/Root.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,23 @@ extension OcaRoot: Hashable {
hasher.combine(objectNumber)
}
}

public struct OcaGetPathParameters: Codable, Sendable, OcaParameterCountReflectable {
public static var responseParameterCount: OcaUint8 { 2 }

public var namePath: OcaNamePath
public var oNoPath: OcaONoPath

public init(namePath: OcaNamePath, oNoPath: OcaONoPath) {
self.namePath = namePath
self.oNoPath = oNoPath
}
}

extension OcaRoot {
func getPath(methodID: OcaMethodID) async throws -> (OcaNamePath, OcaONoPath) {
let responseParams: OcaGetPathParameters
responseParams = try await sendCommandRrq(methodID: methodID)
return (responseParams.namePath, responseParams.oNoPath)
}
}
24 changes: 12 additions & 12 deletions Sources/SwiftOCA/OCC/ControlClasses/Workers/Worker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ open class OcaWorker: OcaRoot {
public var latency: OcaProperty<OcaTimeInterval?>.State

// 2.3
func add(port label: OcaString, mode: OcaPortMode, portID: inout OcaPortID) async throws {
public func add(
port label: OcaString,
mode: OcaPortMode,
portID: inout OcaPortID
) async throws {
struct AddPortParameters: Codable {
let label: OcaString
let mode: OcaPortMode
Expand All @@ -68,15 +72,15 @@ open class OcaWorker: OcaRoot {
}

// 2.4
func delete(port id: OcaPortID) async throws {
public func delete(port id: OcaPortID) async throws {
try await sendCommandRrq(
methodID: OcaMethodID("2.4"),
parameter: id
)
}

// 2.6
func get(portID: OcaPortID, name: inout OcaString) async throws {
public func get(portID: OcaPortID, name: inout OcaString) async throws {
try await sendCommandRrq(
methodID: OcaMethodID("2.7"),
parameter: portID,
Expand All @@ -86,7 +90,7 @@ open class OcaWorker: OcaRoot {
}

// 2.7
func set(portID: OcaPortID, name: OcaString) async throws {
public func set(portID: OcaPortID, name: OcaString) async throws {
struct SetPortNameParameters: Codable {
let portID: OcaPortID
let name: OcaString
Expand All @@ -98,13 +102,9 @@ open class OcaWorker: OcaRoot {
)
}

// 2.13
func get(path namePath: inout OcaNamePath, oNoPath: inout OcaONoPath) async throws {
let responseParams: OcaGetPathParameters

responseParams = try await sendCommandRrq(methodID: OcaMethodID("2.13"))

namePath = responseParams.namePath
oNoPath = responseParams.oNoPath
public var path: (OcaNamePath, OcaONoPath) {
get async throws {
try await getPath(methodID: OcaMethodID("2.13"))
}
}
}
6 changes: 1 addition & 5 deletions Sources/SwiftOCADevice/OCC/ControlClasses/Agents/Agent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ public class OcaAgent: OcaRoot, OcaOwnable {
) async throws -> Ocp1Response {
switch command.methodID {
case OcaMethodID("2.4"):
let responseParams = OcaGetPathParameters(
namePath: await rolePath,
oNoPath: await objectNumberPath
)
return try encodeResponse(responseParams)
return try await encodeResponse(path)
default:
return try await super.handleCommand(command, from: controller)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// Copyright (c) 2023 PADL Software Pty Ltd
//
// Licensed under the Apache License, Version 2.0 (the License);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an 'AS IS' BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import SwiftOCA

public class OcaApplicationNetwork: OcaRoot {
override public class var classID: OcaClassID { OcaClassID("1.4") }
override public class var classVersion: OcaClassVersionNumber { 1 }

@OcaDeviceProperty(
propertyID: OcaPropertyID("2.1"),
getMethodID: OcaMethodID("2.1"),
setMethodID: OcaMethodID("2.2")
)
public var label = ""

@OcaDeviceProperty(
propertyID: OcaPropertyID("2.2"),
getMethodID: OcaMethodID("2.3")
)
public var owner = OcaInvalidONo

@OcaDeviceProperty(
propertyID: OcaPropertyID("2.3"),
getMethodID: OcaMethodID("2.4"),
setMethodID: OcaMethodID("2.5")
)
public var serviceID: OcaApplicationNetworkServiceID = .init()

@OcaDeviceProperty(
propertyID: OcaPropertyID("2.4"),
getMethodID: OcaMethodID("2.6"),
setMethodID: OcaMethodID("2.7")
)
public var systemInterfaces = [OcaNetworkSystemInterfaceDescriptor]()

@OcaDeviceProperty(
propertyID: OcaPropertyID("2.5"),
getMethodID: OcaMethodID("2.8")
)
public var state: OcaApplicationNetworkState = .stopped

@OcaDeviceProperty(
propertyID: OcaPropertyID("2.6"),
getMethodID: OcaMethodID("2.8")
)
public var errorCode: OcaUint16 = 0

open func control(_ command: OcaApplicationNetworkCommand) async throws {
throw Ocp1Error.status(.notImplemented)
}

override public func handleCommand(
_ command: Ocp1Command,
from controller: AES70Controller
) async throws -> Ocp1Response {
switch command.methodID {
case OcaMethodID("2.10"):
let params: OcaApplicationNetworkCommand = try decodeCommand(command)
try await ensureWritable(by: controller, command: command)
try await control(params)
return Ocp1Response()
case OcaMethodID("2.11"):
return try await encodeResponse(path)
default:
return try await super.handleCommand(command, from: controller)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Copyright (c) 2023 PADL Software Pty Ltd
//
// Licensed under the Apache License, Version 2.0 (the License);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an 'AS IS' BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import SwiftOCA

public class OcaControlNetwork: OcaApplicationNetwork {
override public class var classID: OcaClassID { OcaClassID("1.4.1") }
override public class var classVersion: OcaClassVersionNumber { 1 }

@OcaDeviceProperty(
propertyID: OcaPropertyID("3.1"),
getMethodID: OcaMethodID("3.1")
)
public var `protocol`: OcaNetworkControlProtocol = .ocp01
}
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,12 @@ public extension OcaRoot {
await makePath(rootObject: self, keyPath: \.role)
}
}

var path: OcaGetPathParameters {
get async {
OcaGetPathParameters(namePath: await rolePath, oNoPath: await objectNumberPath)
}
}
}

private extension OcaRoot {
Expand Down
16 changes: 16 additions & 0 deletions SwiftOCA.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
D33A35AD2B2FC29000FEDC43 /* AudioProcessingManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D33A35AC2B2FC29000FEDC43 /* AudioProcessingManager.swift */; };
D33A35AF2B2FC2BB00FEDC43 /* DiagnosticManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D33A35AE2B2FC2BB00FEDC43 /* DiagnosticManager.swift */; };
D33A35B12B2FC30500FEDC43 /* LockManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D33A35B02B2FC30500FEDC43 /* LockManager.swift */; };
D33A35B42B2FC4E500FEDC43 /* ControlNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = D33A35B32B2FC4E500FEDC43 /* ControlNetwork.swift */; };
D33A35B62B2FC54C00FEDC43 /* ApplicationNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = D33A35B52B2FC54C00FEDC43 /* ApplicationNetwork.swift */; };
D33B528C2A6FD206001A1BA7 /* libSwiftOCA.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = D3E6E1642A3ACA0B00BF7095 /* libSwiftOCA.dylib */; };
D33B52902A6FD332001A1BA7 /* Root.swift in Sources */ = {isa = PBXBuildFile; fileRef = D33B528F2A6FD332001A1BA7 /* Root.swift */; };
D33B52932A6FD3A7001A1BA7 /* DeviceProperty.swift in Sources */ = {isa = PBXBuildFile; fileRef = D33B52922A6FD3A7001A1BA7 /* DeviceProperty.swift */; };
Expand Down Expand Up @@ -263,6 +265,8 @@
D33A35AC2B2FC29000FEDC43 /* AudioProcessingManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioProcessingManager.swift; sourceTree = "<group>"; };
D33A35AE2B2FC2BB00FEDC43 /* DiagnosticManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiagnosticManager.swift; sourceTree = "<group>"; };
D33A35B02B2FC30500FEDC43 /* LockManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LockManager.swift; sourceTree = "<group>"; };
D33A35B32B2FC4E500FEDC43 /* ControlNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ControlNetwork.swift; sourceTree = "<group>"; };
D33A35B52B2FC54C00FEDC43 /* ApplicationNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationNetwork.swift; sourceTree = "<group>"; };
D33B52812A6FD171001A1BA7 /* libSwiftOCADevice.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libSwiftOCADevice.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
D33B528F2A6FD332001A1BA7 /* Root.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Root.swift; sourceTree = "<group>"; };
D33B52922A6FD3A7001A1BA7 /* DeviceProperty.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceProperty.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -536,6 +540,15 @@
path = IORing;
sourceTree = "<group>";
};
D33A35B22B2FC4DC00FEDC43 /* ApplicationNetworks */ = {
isa = PBXGroup;
children = (
D33A35B32B2FC4E500FEDC43 /* ControlNetwork.swift */,
D33A35B52B2FC54C00FEDC43 /* ApplicationNetwork.swift */,
);
path = ApplicationNetworks;
sourceTree = "<group>";
};
D33B52852A6FD190001A1BA7 /* Sources/SwiftOCADevice */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -570,6 +583,7 @@
D33B528E2A6FD327001A1BA7 /* ControlClasses */ = {
isa = PBXGroup;
children = (
D33A35B22B2FC4DC00FEDC43 /* ApplicationNetworks */,
D351F2062A72999D008C5513 /* Agents */,
D33B528F2A6FD332001A1BA7 /* Root.swift */,
D33B52AF2A703AEA001A1BA7 /* Root+Commands.swift */,
Expand Down Expand Up @@ -1352,9 +1366,11 @@
D351F2162A729DFC008C5513 /* PolarityState.swift in Sources */,
D33A35AD2B2FC29000FEDC43 /* AudioProcessingManager.swift in Sources */,
D33B52B02A703AEA001A1BA7 /* Root+Commands.swift in Sources */,
D33A35B42B2FC4E500FEDC43 /* ControlNetwork.swift in Sources */,
D33B52A82A702D29001A1BA7 /* Manager.swift in Sources */,
D33A35AF2B2FC2BB00FEDC43 /* DiagnosticManager.swift in Sources */,
D30644012A76CDDE0063DA65 /* IdentificationSensor.swift in Sources */,
D33A35B62B2FC54C00FEDC43 /* ApplicationNetwork.swift in Sources */,
D351F2142A729D8B008C5513 /* Switch.swift in Sources */,
D351F2052A72780A008C5513 /* PanBalance.swift in Sources */,
D33A35AB2B2FBD0700FEDC43 /* DeviceTimeManager.swift in Sources */,
Expand Down

0 comments on commit 9f73ac6

Please sign in to comment.