SensorErrorGlucoseEvent.swift 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // SensorErrorGlucoseEvent.swift
  3. // RileyLink
  4. //
  5. // Created by Timothy Mecklem on 12/6/16.
  6. // Copyright © 2016 Pete Schwamb. All rights reserved.
  7. //
  8. import Foundation
  9. public struct SensorErrorGlucoseEvent: RelativeTimestampedGlucoseEvent {
  10. public let length: Int
  11. public let rawData: Data
  12. public let timestamp: DateComponents
  13. private let errorType: String
  14. public init?(availableData: Data, relativeTimestamp: DateComponents) {
  15. length = 2
  16. guard length <= availableData.count else {
  17. return nil
  18. }
  19. func d(_ idx: Int) -> Int {
  20. return Int(availableData[idx])
  21. }
  22. rawData = availableData.subdata(in: 0..<length)
  23. switch d(1) {
  24. case 0x01:
  25. errorType = "end"
  26. default:
  27. errorType = "unknown"
  28. }
  29. timestamp = relativeTimestamp
  30. }
  31. public var dictionaryRepresentation: [String: Any] {
  32. return [
  33. "name": "SensorErrorSignal",
  34. "errorType": errorType
  35. ]
  36. }
  37. }