MySentryAlertClearedMessageBody.swift 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //
  2. // MySentryAlertClearedMessageBody.swift
  3. // Naterade
  4. //
  5. // Created by Nathan Racklyeft on 9/6/15.
  6. // Copyright © 2015 Nathan Racklyeft. All rights reserved.
  7. //
  8. import Foundation
  9. /**
  10. Describes message sent immediately from the pump to any paired MySentry devices after a user clears an alert
  11. See: [MinimedRF Class](https://github.com/ps2/minimed_rf/blob/master/lib/minimed_rf/messages/alert_cleared.rb)
  12. ```
  13. a2 594040 02 80 52 14
  14. ```
  15. */
  16. public struct MySentryAlertClearedMessageBody: DecodableMessageBody, DictionaryRepresentable {
  17. public static let length = 2
  18. public let alertType: MySentryAlertType?
  19. private let rxData: Data
  20. public init?(rxData: Data) {
  21. guard rxData.count == type(of: self).length else {
  22. return nil
  23. }
  24. self.rxData = rxData
  25. alertType = MySentryAlertType(rawValue: rxData[1])
  26. }
  27. public var txData: Data {
  28. return rxData
  29. }
  30. public var dictionaryRepresentation: [String: Any] {
  31. return [
  32. "alertType": (alertType != nil ? String(describing: alertType!) : rxData.subdata(in: 1..<2).hexadecimalString),
  33. "cleared": true
  34. ]
  35. }
  36. public var description: String {
  37. return "MySentryAlertCleared(\(String(describing: alertType)))"
  38. }
  39. }