ANSI E1.59 - 2021《娱乐技术 - 对象变换协议 (OTP)》的 Swift 包 (SPM) 实现。
使用 IPv4/6 (OTP-4, OTP-6, OTP-4/6) 提供 OTP 生产者和消费者组件的完整协议实现。
当前版本:文档编号:CP/2018-1034r5。
下载完整的标准文档。
以下说明将帮助您在本地计算机上启动并运行该项目的副本,以进行开发和测试。有关如何在生产系统上部署该项目的说明,请参阅部署部分。
需要 Swift 5.2
macOS 10.14+, iOS 10+
要将包依赖项添加到您的 Xcode 项目,请选择 File > Swift Packages > Add Package Dependency 并输入存储库 URL
https://github.com/dsmurfin/OTPKit
只需将包依赖项添加到您的 Package.swift 中,并在必要的 targets 中依赖 "OTPKit"
.package(url: "https://github.com/dsmurfin/OTPKit", from: "1.0.0")
]
通过直接添加源文件将 OTPKit 包含在您的项目中,但您可能应该使用依赖项管理器来保持更新。
使用 Swift 导入到您的项目文件中
import OTPKit
完整的文档可以在项目的 wiki 中找到。
OTPKit 完全基于 Grand Central Dispatch (GCD) 且线程安全
它完全在其自身的 GCD DispatchQueue(s) 中运行,并且完全线程安全。 此外,委托方法都异步调用到您选择的 DispatchQueue 上。 这意味着您的 OTP 代码和您的委托/处理代码可以并行操作。
创建生产者
// 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)
启动生产者
// starts the producer transmitting network data
producer.start()
向生产者添加 Point 和 Module
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)
}
注册以接收来自生产者的委托通知
// request producer delegate notifications
producer.setProducerDelegate(self)
创建消费者
// 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)
启动消费者
// starts the consumer transmitting network data
consumer.start()
注册以接收来自生产者的委托通知
// request consumer delegate notifications
consumer.setConsumerDelegate(self)
此软件包已准备好在生产系统中部署。 它也可以用于测试和评估。
我们使用 SemVer 进行版本控制。 有关可用版本,请参见此存储库上的标签。
另请参阅参与此项目的贡献者列表。
此项目已获得 MIT 许可证的许可 - 有关详细信息,请参见LICENSE.md文件