SensorCalGlucoseEvent.swift 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //
  2. // SensorCalGlucoseEvent.swift
  3. // RileyLink
  4. //
  5. // Created by Timothy Mecklem on 10/16/16.
  6. // Copyright © 2016 Pete Schwamb. All rights reserved.
  7. //
  8. import Foundation
  9. public struct SensorCalGlucoseEvent: RelativeTimestampedGlucoseEvent {
  10. public let length: Int
  11. public let rawData: Data
  12. public let timestamp: DateComponents
  13. private let calibrationType: 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 0x00:
  25. calibrationType = "meter_bg_now"
  26. case 0x01:
  27. calibrationType = "waiting"
  28. case 0x02:
  29. calibrationType = "cal_error"
  30. default:
  31. calibrationType = "unknown"
  32. }
  33. timestamp = relativeTimestamp
  34. }
  35. public var dictionaryRepresentation: [String: Any] {
  36. return [
  37. "name": "SensorCal",
  38. "calibrationType": calibrationType
  39. ]
  40. }
  41. }