From 9f73ac657639a2c9f692b5295e5324c8bbedc61d Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Mon, 18 Dec 2023 11:28:20 +1100 Subject: [PATCH] OcaApplicationNetwork device side --- .../OCC/ControlClasses/Agents/Agent.swift | 20 +---- .../ApplicationNetwork.swift | 18 ++-- .../Networks/NetworkApplication.swift | 4 +- .../SwiftOCA/OCC/ControlClasses/Root.swift | 20 +++++ .../OCC/ControlClasses/Workers/Worker.swift | 24 +++--- .../OCC/ControlClasses/Agents/Agent.swift | 6 +- .../ApplicationNetwork.swift | 82 +++++++++++++++++++ .../ApplicationNetworks/ControlNetwork.swift | 28 +++++++ .../Workers/BlocksAndMatrices/Block.swift | 6 ++ SwiftOCA.xcodeproj/project.pbxproj | 16 ++++ 10 files changed, 175 insertions(+), 49 deletions(-) create mode 100644 Sources/SwiftOCADevice/OCC/ControlClasses/ApplicationNetworks/ApplicationNetwork.swift create mode 100644 Sources/SwiftOCADevice/OCC/ControlClasses/ApplicationNetworks/ControlNetwork.swift diff --git a/Sources/SwiftOCA/OCC/ControlClasses/Agents/Agent.swift b/Sources/SwiftOCA/OCC/ControlClasses/Agents/Agent.swift index 64d79efc..71521cfc 100644 --- a/Sources/SwiftOCA/OCC/ControlClasses/Agents/Agent.swift +++ b/Sources/SwiftOCA/OCC/ControlClasses/Agents/Agent.swift @@ -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") } @@ -42,13 +30,9 @@ open class OcaAgent: OcaRoot { ) public var owner: OcaProperty.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")) } } } diff --git a/Sources/SwiftOCA/OCC/ControlClasses/ApplicationNetworks/ApplicationNetwork.swift b/Sources/SwiftOCA/OCC/ControlClasses/ApplicationNetworks/ApplicationNetwork.swift index 4fb5c84e..0ae39679 100644 --- a/Sources/SwiftOCA/OCC/ControlClasses/ApplicationNetworks/ApplicationNetwork.swift +++ b/Sources/SwiftOCA/OCC/ControlClasses/ApplicationNetworks/ApplicationNetwork.swift @@ -59,20 +59,16 @@ open class OcaApplicationNetwork: OcaRoot { ) public var errorCode: OcaProperty.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")) + } + } } diff --git a/Sources/SwiftOCA/OCC/ControlClasses/Networks/NetworkApplication.swift b/Sources/SwiftOCA/OCC/ControlClasses/Networks/NetworkApplication.swift index e1cb003e..007e1ce5 100644 --- a/Sources/SwiftOCA/OCC/ControlClasses/Networks/NetworkApplication.swift +++ b/Sources/SwiftOCA/OCC/ControlClasses/Networks/NetworkApplication.swift @@ -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")) } } diff --git a/Sources/SwiftOCA/OCC/ControlClasses/Root.swift b/Sources/SwiftOCA/OCC/ControlClasses/Root.swift index d308fd33..ebd75669 100644 --- a/Sources/SwiftOCA/OCC/ControlClasses/Root.swift +++ b/Sources/SwiftOCA/OCC/ControlClasses/Root.swift @@ -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) + } +} diff --git a/Sources/SwiftOCA/OCC/ControlClasses/Workers/Worker.swift b/Sources/SwiftOCA/OCC/ControlClasses/Workers/Worker.swift index 72532530..ca312789 100644 --- a/Sources/SwiftOCA/OCC/ControlClasses/Workers/Worker.swift +++ b/Sources/SwiftOCA/OCC/ControlClasses/Workers/Worker.swift @@ -53,7 +53,11 @@ open class OcaWorker: OcaRoot { public var latency: OcaProperty.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 @@ -68,7 +72,7 @@ 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 @@ -76,7 +80,7 @@ open class OcaWorker: OcaRoot { } // 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, @@ -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 @@ -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")) + } } } diff --git a/Sources/SwiftOCADevice/OCC/ControlClasses/Agents/Agent.swift b/Sources/SwiftOCADevice/OCC/ControlClasses/Agents/Agent.swift index fca35fc6..58526e8e 100644 --- a/Sources/SwiftOCADevice/OCC/ControlClasses/Agents/Agent.swift +++ b/Sources/SwiftOCADevice/OCC/ControlClasses/Agents/Agent.swift @@ -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) } diff --git a/Sources/SwiftOCADevice/OCC/ControlClasses/ApplicationNetworks/ApplicationNetwork.swift b/Sources/SwiftOCADevice/OCC/ControlClasses/ApplicationNetworks/ApplicationNetwork.swift new file mode 100644 index 00000000..b03b2e67 --- /dev/null +++ b/Sources/SwiftOCADevice/OCC/ControlClasses/ApplicationNetworks/ApplicationNetwork.swift @@ -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) + } + } +} diff --git a/Sources/SwiftOCADevice/OCC/ControlClasses/ApplicationNetworks/ControlNetwork.swift b/Sources/SwiftOCADevice/OCC/ControlClasses/ApplicationNetworks/ControlNetwork.swift new file mode 100644 index 00000000..c4481644 --- /dev/null +++ b/Sources/SwiftOCADevice/OCC/ControlClasses/ApplicationNetworks/ControlNetwork.swift @@ -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 +} diff --git a/Sources/SwiftOCADevice/OCC/ControlClasses/Workers/BlocksAndMatrices/Block.swift b/Sources/SwiftOCADevice/OCC/ControlClasses/Workers/BlocksAndMatrices/Block.swift index e1161d5f..8ae28824 100644 --- a/Sources/SwiftOCADevice/OCC/ControlClasses/Workers/BlocksAndMatrices/Block.swift +++ b/Sources/SwiftOCADevice/OCC/ControlClasses/Workers/BlocksAndMatrices/Block.swift @@ -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 { diff --git a/SwiftOCA.xcodeproj/project.pbxproj b/SwiftOCA.xcodeproj/project.pbxproj index 2373bd82..8dfb0919 100644 --- a/SwiftOCA.xcodeproj/project.pbxproj +++ b/SwiftOCA.xcodeproj/project.pbxproj @@ -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 */; }; @@ -263,6 +265,8 @@ D33A35AC2B2FC29000FEDC43 /* AudioProcessingManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioProcessingManager.swift; sourceTree = ""; }; D33A35AE2B2FC2BB00FEDC43 /* DiagnosticManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiagnosticManager.swift; sourceTree = ""; }; D33A35B02B2FC30500FEDC43 /* LockManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LockManager.swift; sourceTree = ""; }; + D33A35B32B2FC4E500FEDC43 /* ControlNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ControlNetwork.swift; sourceTree = ""; }; + D33A35B52B2FC54C00FEDC43 /* ApplicationNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationNetwork.swift; sourceTree = ""; }; 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 = ""; }; D33B52922A6FD3A7001A1BA7 /* DeviceProperty.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceProperty.swift; sourceTree = ""; }; @@ -536,6 +540,15 @@ path = IORing; sourceTree = ""; }; + D33A35B22B2FC4DC00FEDC43 /* ApplicationNetworks */ = { + isa = PBXGroup; + children = ( + D33A35B32B2FC4E500FEDC43 /* ControlNetwork.swift */, + D33A35B52B2FC54C00FEDC43 /* ApplicationNetwork.swift */, + ); + path = ApplicationNetworks; + sourceTree = ""; + }; D33B52852A6FD190001A1BA7 /* Sources/SwiftOCADevice */ = { isa = PBXGroup; children = ( @@ -570,6 +583,7 @@ D33B528E2A6FD327001A1BA7 /* ControlClasses */ = { isa = PBXGroup; children = ( + D33A35B22B2FC4DC00FEDC43 /* ApplicationNetworks */, D351F2062A72999D008C5513 /* Agents */, D33B528F2A6FD332001A1BA7 /* Root.swift */, D33B52AF2A703AEA001A1BA7 /* Root+Commands.swift */, @@ -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 */,