| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- //
- // DeviceLinkMessageBody.swift
- // RileyLink
- //
- // Created by Pete Schwamb on 2/29/16.
- // Copyright © 2016 Pete Schwamb. All rights reserved.
- //
- import Foundation
- public struct DeviceLinkMessageBody: MessageBody {
-
- public static let length = 5
-
- public let deviceAddress: Data
- public let sequence: UInt8
- let rxData: Data
-
-
- public init?(rxData: Data) {
- self.rxData = rxData
-
- if rxData.count == type(of: self).length {
- self.deviceAddress = rxData.subdata(in: 1..<4)
- sequence = rxData[0] & 0b1111111
- } else {
- return nil
- }
- }
-
- public var txData: Data {
- return rxData
- }
-
- public var dictionaryRepresentation: [String: Any] {
- return [
- "sequence": Int(sequence),
- "deviceAddress": deviceAddress.hexadecimalString,
- ]
- }
-
- }
|