GetStatusCommand.swift 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //
  2. // GetStatusCommand.swift
  3. // OmniKit
  4. //
  5. // Created by Pete Schwamb on 10/14/17.
  6. // Copyright © 2017 Pete Schwamb. All rights reserved.
  7. //
  8. import Foundation
  9. public struct GetStatusCommand : MessageBlock {
  10. // OFF 1 2
  11. // Oe 01 TT
  12. public let blockType: MessageBlockType = .getStatus
  13. public let length: UInt8 = 1
  14. public let podInfoType: PodInfoResponseSubType
  15. public init(podInfoType: PodInfoResponseSubType = .normal) {
  16. self.podInfoType = podInfoType
  17. }
  18. public init(encodedData: Data) throws {
  19. if encodedData.count < 3 {
  20. throw MessageBlockError.notEnoughData
  21. }
  22. guard let podInfoType = PodInfoResponseSubType(rawValue: encodedData[2]) else {
  23. throw MessageError.unknownValue(value: encodedData[2], typeDescription: "PodInfoResponseSubType")
  24. }
  25. self.podInfoType = podInfoType
  26. }
  27. public var data: Data {
  28. var data = Data([
  29. blockType.rawValue,
  30. length
  31. ])
  32. data.append(podInfoType.rawValue)
  33. return data
  34. }
  35. }
  36. extension GetStatusCommand: CustomDebugStringConvertible {
  37. public var debugDescription: String {
  38. return "GetStatusCommand(\(podInfoType))"
  39. }
  40. }