Skip to content

Commit

Permalink
Ensure that event name sequence matches decocare output
Browse files Browse the repository at this point in the history
In writing this test and the code that passed the test, I encountered a
strange mismatch from decocare. Decocare had more sgv entries, but they
had values of 0. Additional discovery and discussion led to a change in
decocare: openaps/decocare#11
  • Loading branch information
tmecklem committed Oct 18, 2016
1 parent 64a377b commit 6bda586
Show file tree
Hide file tree
Showing 20 changed files with 647 additions and 1 deletion.
59 changes: 59 additions & 0 deletions MinimedKit/GlucoseEventType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// GlucoseEventType.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public enum GlucoseEventType: UInt8 {
case dataEnd = 0x01
case sensorWeakSignal = 0x02
case sensorCal = 0x03
case fokko7 = 0x07
case sensorTimestamp = 0x08
case batteryChange = 0x0a
case sensorStatus = 0x0b
case dateTimeChange = 0x0c
case sensorSync = 0x0d
case calBGForGH = 0x0e
case sensorCalFactor = 0x0f
case tenSomething = 0x10
case nineteenSomething = 0x13
case glucoseSensorDataEvent

public var eventType: GlucoseEvent.Type {
switch self {
case .dataEnd:
return DataEndGlucoseEvent.self
case .sensorWeakSignal:
return SensorWeakSignalGlucoseEvent.self
case .sensorCal:
return SensorCalGlucoseEvent.self
case .fokko7:
return Fokko7GlucoseEvent.self
case .sensorTimestamp:
return SensorTimestampGlucoseEvent.self
case .batteryChange:
return BatteryChangeGlucoseEvent.self
case .sensorStatus:
return SensorStatusGlucoseEvent.self
case .dateTimeChange:
return DateTimeChangeGlucoseEvent.self
case .sensorSync:
return SensorSyncGlucoseEvent.self
case .calBGForGH:
return CalBGForGHGlucoseEvent.self
case .sensorCalFactor:
return SensorCalFactorGlucoseEvent.self
case .tenSomething:
return TenSomethingGlucoseEvent.self
case .nineteenSomething:
return NineteenSomethingGlucoseEvent.self
case .glucoseSensorDataEvent:
return GlucoseSensorDataGlucoseEvent.self
}
}
}
30 changes: 30 additions & 0 deletions MinimedKit/GlucoseEvents/BatteryChangeGlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// BatteryChangeGlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public struct BatteryChangeGlucoseEvent : GlucoseEvent {
public let length: Int
public let rawData: Data

public init?(availableData: Data, pumpModel: PumpModel) {
length = 5

guard length <= availableData.count else {
return nil
}

rawData = availableData.subdata(in: 0..<length)
}

public var dictionaryRepresentation: [String: Any] {
return [
"name": "BatteryChange",
]
}
}
30 changes: 30 additions & 0 deletions MinimedKit/GlucoseEvents/CalBGForGHGlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// CalBGForGHGlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public struct CalBGForGHGlucoseEvent : GlucoseEvent {
public let length: Int
public let rawData: Data

public init?(availableData: Data, pumpModel: PumpModel) {
length = 6

guard length <= availableData.count else {
return nil
}

rawData = availableData.subdata(in: 0..<length)
}

public var dictionaryRepresentation: [String: Any] {
return [
"name": "CalBGForGH",
]
}
}
31 changes: 31 additions & 0 deletions MinimedKit/GlucoseEvents/DataEndGlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// DataEndGlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public struct DataEndGlucoseEvent : RelativeTimestampedGlucoseEvent {
public let length: Int
public let rawData: Data

public init?(availableData: Data, pumpModel: PumpModel) {
length = 1

guard length <= availableData.count else {
return nil
}

rawData = availableData.subdata(in: 0..<length)
}

public var dictionaryRepresentation: [String: Any] {
return [
"name": "DataEnd",
]
}
}

30 changes: 30 additions & 0 deletions MinimedKit/GlucoseEvents/DateTimeChangeGlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// DateTimeChangeGlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public struct DateTimeChangeGlucoseEvent : GlucoseEvent {
public let length: Int
public let rawData: Data

public init?(availableData: Data, pumpModel: PumpModel) {
length = 5

guard length <= availableData.count else {
return nil
}

rawData = availableData.subdata(in: 0..<length)
}

public var dictionaryRepresentation: [String: Any] {
return [
"name": "DateTimeChange",
]
}
}
30 changes: 30 additions & 0 deletions MinimedKit/GlucoseEvents/Fokko7GlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Fokko7GlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public struct Fokko7GlucoseEvent : GlucoseEvent {
public let length: Int
public let rawData: Data

public init?(availableData: Data, pumpModel: PumpModel) {
length = 2

guard length <= availableData.count else {
return nil
}

rawData = availableData.subdata(in: 0..<length)
}

public var dictionaryRepresentation: [String: Any] {
return [
"name": "Fokko-7",
]
}
}
30 changes: 30 additions & 0 deletions MinimedKit/GlucoseEvents/GlucoseSensorDataGlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// GlucoseSensorDataGlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public struct GlucoseSensorDataGlucoseEvent : RelativeTimestampedGlucoseEvent {
public let length: Int
public let rawData: Data

public init?(availableData: Data, pumpModel: PumpModel) {
length = 1

guard length <= availableData.count else {
return nil
}

rawData = availableData.subdata(in: 0..<length)
}

public var dictionaryRepresentation: [String: Any] {
return [
"name": "GlucoseSensorData",
]
}
}
31 changes: 31 additions & 0 deletions MinimedKit/GlucoseEvents/NineteenSomethingGlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// NineteenSomethingGlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public struct NineteenSomethingGlucoseEvent : RelativeTimestampedGlucoseEvent {
public let length: Int
public let rawData: Data

public init?(availableData: Data, pumpModel: PumpModel) {
length = 1

guard length <= availableData.count else {
return nil
}

rawData = availableData.subdata(in: 0..<length)
}

public var dictionaryRepresentation: [String: Any] {
return [
"name": "19-Something",
]
}
}

15 changes: 15 additions & 0 deletions MinimedKit/GlucoseEvents/ReferenceTimestampedGlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// ReferenceTimestampedGlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/17/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

/// An event that supplies timestamp information that can be used to calculate a RelativeTimestampedGlucoseEvent
public protocol ReferenceTimestampedGlucoseEvent : GlucoseEvent {

}

14 changes: 14 additions & 0 deletions MinimedKit/GlucoseEvents/RelativeTimestampedGlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// RelativeTimestampedGlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

/// An event that requires timestamp information from a ReferenceTimestampGlucoseEvent
public protocol RelativeTimestampedGlucoseEvent : GlucoseEvent {

}
30 changes: 30 additions & 0 deletions MinimedKit/GlucoseEvents/SensorCalFactorGlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// SensorCalFactorGlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public struct SensorCalFactorGlucoseEvent : ReferenceTimestampedGlucoseEvent {
public let length: Int
public let rawData: Data

public init?(availableData: Data, pumpModel: PumpModel) {
length = 7

guard length <= availableData.count else {
return nil
}

rawData = availableData.subdata(in: 0..<length)
}

public var dictionaryRepresentation: [String: Any] {
return [
"name": "SensorCalFactor",
]
}
}
32 changes: 32 additions & 0 deletions MinimedKit/GlucoseEvents/SensorCalGlucoseEvent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// SensorCalGlucoseEvent.swift
// RileyLink
//
// Created by Timothy Mecklem on 10/16/16.
// Copyright © 2016 Pete Schwamb. All rights reserved.
//

import Foundation

public struct SensorCalGlucoseEvent : RelativeTimestampedGlucoseEvent {
public let length: Int
public let rawData: Data

public init?(availableData: Data, pumpModel: PumpModel) {
length = 2

guard length <= availableData.count else {
return nil
}

rawData = availableData.subdata(in: 0..<length)
}

public var dictionaryRepresentation: [String: Any] {
return [
"name": "SensorCal",
]
}
}


Loading

0 comments on commit 6bda586

Please sign in to comment.