JournalEntryInsulinMarkerPumpEvent.swift 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // JournalEntryInsulinMarkerPumpEvent.swift
  3. // RileyLink
  4. //
  5. // Created by Pete Schwamb on 7/16/16.
  6. // Copyright © 2016 Pete Schwamb. All rights reserved.
  7. //
  8. import Foundation
  9. public struct JournalEntryInsulinMarkerPumpEvent: TimestampedPumpEvent {
  10. public let length: Int
  11. public let rawData: Data
  12. public let timestamp: DateComponents
  13. public let amount: Double
  14. public init?(availableData: Data, pumpModel: PumpModel) {
  15. length = 8
  16. guard length <= availableData.count else {
  17. return nil
  18. }
  19. rawData = availableData.subdata(in: 0..<length)
  20. timestamp = DateComponents(pumpEventData: availableData, offset: 2)
  21. let lowBits = rawData[1]
  22. let highBits = rawData[4]
  23. amount = Double((Int(highBits & 0b1100000) << 3) + Int(lowBits)) / 10.0
  24. }
  25. public var dictionaryRepresentation: [String: Any] {
  26. return [
  27. "_type": "JournalEntryInsulinMarker",
  28. "amount": amount,
  29. ]
  30. }
  31. }