A Swift Package (SPM) implementation of ANSI E1.59 - 2021, Entertainment Technology - Object Transform Protocol (OTP).
Provides complete protocol implementations of OTP Producer and Consumer components using IPv4/6 (OTP-4, OTP-6, OTP-4/6).
Current revision: Document Number: CP/2018-1034r5.
Download the full standard document.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
Requires Swift 5.2
macOS 10.14+, iOS 10+
To add the package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter the repository URL:
https://github.com/dsmurfin/OTPKit
Simply add the package dependency to your Package.swift and depend on "OTPKit" in the necessary targets:
.package(url: "https://github.com/dsmurfin/OTPKit", from: "1.0.0")
]
Include OTPKit in your project by adding the source files directly, but you should probably be using a dependency manager to keep up to date.
Import into your project files using Swift:
import OTPKit
Full documentation can be found in the project wiki.
OTPKit is fully Grand Central Dispatch (GCD) based and Thread-Safe
It runs entirely within its own GCD DispatchQueue(s), and is completely thread-safe. Further, the delegate methods are all invoked asynchronously onto a DispatchQueue of your choosing. This means parallel operation of your OTP code, and your delegate/processing code.
Creating a Producer:
// create a new dispatch queue to receive delegate notifications
let queue = DispatchQueue(label: "com.danielmurfin.OTPKit.producerQueue")
// a unique identifier for this producer
let uniqueIdentifier = UUID()
// creates a new IPv4 only producer, which has a default priority of 120, and transmits changes every 10 ms
let producer = OTPProducer(name: "My Producer", cid: uniqueIdentifier, ipMode: ipv4Only, interface: "en0", priority: 120, interval: 10, delegateQueue: Self.delegateQueue)
Starting a Producer:
// starts the producer transmitting network data
producer.start()
Adding a Point and Module to a Producer:
do {
let address = try OTPAddress(1,2,10)
// add a new point using the producer's default priority (120)
try producer.addPoint(with: address, name: "My Point")
// create a new position module with default values
let module = OTPModulePosition()
// add this module to all points with this address
producer.addModule(module, toPoint: address)
} catch let error as OTPPointValidationError {
// handle error
print(error.logDescription)
} catch let error {
// handle unknown error
print(error)
}
Register to receive delegate notifications from Producer:
// request producer delegate notifications
producer.setProducerDelegate(self)
Creating a Consumer:
// create a new dispatch queue to receive delegate notifications
let queue = DispatchQueue(label: "com.danielmurfin.OTPKit.consumerQueue")
// a unique identifier for this consumer
let uniqueIdentifier = UUID()
// observe the position and reference frame modules
let moduleTypes = [OTPModulePosition.self, OTPModuleReferenceFrame.self]
// creates a new IPv6 only consumer which observes systems 1 and 20 and receives delegate notifications a maximum of every 50 ms
let consumer = OTPConsumer(name: "My Consumer", cid: uniqueIdentifier, ipMode: ipv6Only, interface: "en0", moduleTypes: moduleTypes, observedSystems: [1,20], delegateQueue: Self.delegateQueue, delegateInterval: 50)
Starting a Consumer:
// starts the consumer transmitting network data
consumer.start()
Register to receive delegate notifications from Producer:
// request consumer delegate notifications
consumer.setConsumerDelegate(self)
This package is ready for deployment in live systems. It may also be used for testing and evaluation.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Daniel Murfin - Initial work - dsmurfin
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details
- Socket library dependency CocoaSyncSocket
- Includes CwlUtils from [Matt Gallagher] (https://www.cocoawithlove.com)