AcknowledgeAlertCommand.swift 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // AcknowledgeAlertCommand.swift
  3. // OmniKit
  4. //
  5. // Created by Eelke Jager on 18/09/2018.
  6. // Copyright © 2018 Pete Schwamb. All rights reserved.
  7. //
  8. import Foundation
  9. public struct AcknowledgeAlertCommand : NonceResyncableMessageBlock {
  10. // OFF 1 2 3 4 5 6
  11. // 11 05 NNNNNNNN MM
  12. public let blockType: MessageBlockType = .acknowledgeAlert
  13. public let length: UInt8 = 5
  14. public var nonce: UInt32
  15. public let alerts: AlertSet
  16. public init(nonce: UInt32, alerts: AlertSet) {
  17. self.nonce = nonce
  18. self.alerts = alerts
  19. }
  20. public init(encodedData: Data) throws {
  21. if encodedData.count < 7 {
  22. throw MessageBlockError.notEnoughData
  23. }
  24. self.nonce = encodedData[2...].toBigEndian(UInt32.self)
  25. self.alerts = AlertSet(rawValue: encodedData[6])
  26. }
  27. public var data: Data {
  28. var data = Data([
  29. blockType.rawValue,
  30. length
  31. ])
  32. data.appendBigEndian(nonce)
  33. data.append(alerts.rawValue)
  34. return data
  35. }
  36. }