-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support paged cgm #270
Merged
Merged
Support paged cgm #270
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5ab5243
Add import Foundation to HistoryPage
tmecklem 4db513c
Add GlucosePage and enumeration of event types
tmecklem 64a377b
Add reverseBytes extension to Data
tmecklem 6bda586
Ensure that event name sequence matches decocare output
tmecklem d4ec75c
Decode independent events
tmecklem 0b07ba1
Add event parsing for reference timestamp glucose records
tmecklem 233b98b
Add event parsing for relative timestamp records
tmecklem b64bca6
Add relative timestamps to records when parsing page data
tmecklem 438cc83
Add MessageBody classes for fetching glucose pages
tmecklem 870ade0
Add relevant data to dictionary representations
tmecklem 9209656
Add handling for currently unknown opcodes
tmecklem 06f2917
Add pump ops for fetching recent glucose
tmecklem cf0a853
Fix incorrect matching of unknown glucose events
tmecklem 6ce4626
Remove unnecessary passing of pumpModel
tmecklem f266ebb
Remove timestamp delta allowance and use reference timestamps in check
tmecklem 8f6356f
Skip UnknownGlucoseEvents rather than try to timestamp them
tmecklem 01cdf70
Use reversed() instead of custom reverseBytes()
tmecklem 258f2db
Remove pumpModel from PumpOps
tmecklem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// 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 | ||
|
||
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// 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 let timestamp: DateComponents | ||
|
||
public init?(availableData: Data) { | ||
length = 5 | ||
|
||
guard length <= availableData.count else { | ||
return nil | ||
} | ||
|
||
rawData = availableData.subdata(in: 0..<length) | ||
timestamp = DateComponents(glucoseEventBytes: availableData.subdata(in: 1..<5)) | ||
} | ||
|
||
public var dictionaryRepresentation: [String: Any] { | ||
return [ | ||
"name": "BatteryChange", | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// 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 let timestamp: DateComponents | ||
public let amount: Int | ||
|
||
public init?(availableData: Data) { | ||
length = 6 | ||
|
||
guard length <= availableData.count else { | ||
return nil | ||
} | ||
|
||
func d(_ idx:Int) -> Int { | ||
return Int(availableData[idx] as UInt8) | ||
} | ||
|
||
rawData = availableData.subdata(in: 0..<length) | ||
timestamp = DateComponents(glucoseEventBytes: availableData.subdata(in: 1..<5)) | ||
amount = Int( (UInt16(d(3) & 0b00100000) << 3) | UInt16(d(5)) ) | ||
} | ||
|
||
public var dictionaryRepresentation: [String: Any] { | ||
return [ | ||
"name": "CalBGForGH", | ||
"amount": amount | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// 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 var timestamp: DateComponents | ||
|
||
public init?(availableData: Data) { | ||
length = 1 | ||
|
||
guard length <= availableData.count else { | ||
return nil | ||
} | ||
|
||
rawData = availableData.subdata(in: 0..<length) | ||
timestamp = DateComponents() | ||
} | ||
|
||
public var dictionaryRepresentation: [String: Any] { | ||
return [ | ||
"name": "DataEnd", | ||
] | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// 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 let timestamp: DateComponents | ||
|
||
public init?(availableData: Data) { | ||
length = 5 | ||
|
||
guard length <= availableData.count else { | ||
return nil | ||
} | ||
|
||
rawData = availableData.subdata(in: 0..<length) | ||
timestamp = DateComponents(glucoseEventBytes: availableData.subdata(in: 1..<5)) | ||
} | ||
|
||
public var dictionaryRepresentation: [String: Any] { | ||
return [ | ||
"name": "DateTimeChange", | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// 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 var timestamp: DateComponents | ||
|
||
public init?(availableData: Data) { | ||
length = 2 | ||
|
||
guard length <= availableData.count else { | ||
return nil | ||
} | ||
|
||
rawData = availableData.subdata(in: 0..<length) | ||
timestamp = DateComponents() | ||
} | ||
|
||
public var dictionaryRepresentation: [String: Any] { | ||
return [ | ||
"name": "Fokko-7", | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// GlucoseEvent.swift | ||
// RileyLink | ||
// | ||
// Created by Timothy Mecklem on 10/16/16. | ||
// Copyright © 2016 Pete Schwamb. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol GlucoseEvent : DictionaryRepresentable { | ||
|
||
init?(availableData: Data) | ||
|
||
var rawData: Data { | ||
get | ||
} | ||
|
||
var length: Int { | ||
get | ||
} | ||
|
||
var timestamp: DateComponents { | ||
get | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
MinimedKit/GlucoseEvents/GlucoseSensorDataGlucoseEvent.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// 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 let sgv: Int | ||
public var timestamp: DateComponents | ||
|
||
public init?(availableData: Data) { | ||
length = 1 | ||
|
||
guard length <= availableData.count else { | ||
return nil | ||
} | ||
|
||
rawData = availableData.subdata(in: 0..<length) | ||
sgv = Int(UInt16(availableData[0]) * UInt16(2)) | ||
timestamp = DateComponents() | ||
} | ||
|
||
public var dictionaryRepresentation: [String: Any] { | ||
return [ | ||
"name": "GlucoseSensorData", | ||
"sgv": sgv | ||
] | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
MinimedKit/GlucoseEvents/NineteenSomethingGlucoseEvent.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// 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 var timestamp: DateComponents | ||
|
||
public init?(availableData: Data) { | ||
length = 1 | ||
|
||
guard length <= availableData.count else { | ||
return nil | ||
} | ||
|
||
rawData = availableData.subdata(in: 0..<length) | ||
timestamp = DateComponents() | ||
} | ||
|
||
public var dictionaryRepresentation: [String: Any] { | ||
return [ | ||
"name": "19-Something", | ||
] | ||
} | ||
} | ||
|
15 changes: 15 additions & 0 deletions
15
MinimedKit/GlucoseEvents/ReferenceTimestampedGlucoseEvent.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
|
||
} | ||
|
18 changes: 18 additions & 0 deletions
18
MinimedKit/GlucoseEvents/RelativeTimestampedGlucoseEvent.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// 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 { | ||
|
||
var timestamp: DateComponents { | ||
get set | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a method in the standard library to do this already. See https://developer.apple.com/reference/foundation/data/1780245-reversed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having trouble figuring out what to do with the data structure that reversed() gives me. It's a
ReversedRandomAccessCollection<Data>
, and it looks like I have to use a different Index structure. The change seems to leak all the way through to how I access rawData GlucoseEvent and seems messy. Can you take a look and help me understand how to appropriately use reversed() on the page Data?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use Data(data.reversed()) to create a new reversed data object. There may be ways to work with RandomAccessCollection types, and avoid the copy, but I wasn't able to get that working in my swift playground.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Change made.