Skip to content

Commit 0c80001

Browse files
authored
Merge pull request #166 from ps2/dev
Release 0.7.0
2 parents eb054a3 + 7372237 commit 0c80001

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1656
-183
lines changed

Cartfile.resolved

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github "loudnate/Crypto" "e0ef5b498f2c373d676135dabf5d1803b8558509"
1+
github "loudnate/Crypto" "13fee45175b88629aeabe60b4b4fc3daf86fa0a3"

MinimedKit/Extensions/NSDateComponents.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ extension NSDateComponents {
1313
convenience init(mySentryBytes: [UInt8]) {
1414
self.init()
1515

16-
hour = Int(mySentryBytes[0])
17-
minute = Int(mySentryBytes[1])
18-
second = Int(mySentryBytes[2])
16+
hour = Int(mySentryBytes[0] & 0b00011111)
17+
minute = Int(mySentryBytes[1] & 0b00111111)
18+
second = Int(mySentryBytes[2] & 0b00111111)
1919
year = Int(mySentryBytes[3]) + 2000
20-
month = Int(mySentryBytes[4])
21-
day = Int(mySentryBytes[5])
20+
month = Int(mySentryBytes[4] & 0b00001111)
21+
day = Int(mySentryBytes[5] & 0b00011111)
2222

2323
calendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)
2424
}

MinimedKit/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>0.6.0</string>
18+
<string>0.7.0</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

MinimedKit/Messages/MySentryPumpStatusMessageBody.swift

+9
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ public enum SensorReading {
7676
}
7777
}
7878

79+
public enum ClockType {
80+
case TwentyFourHour
81+
case TwelveHour
82+
}
83+
7984

8085
/**
8186
Describes a status message sent periodically from the pump to any paired MySentry devices
@@ -113,6 +118,7 @@ public struct MySentryPumpStatusMessageBody: MessageBody, DictionaryRepresentabl
113118
public let previousGlucose: SensorReading
114119
public let sensorAgeHours: Int
115120
public let sensorRemainingHours: Int
121+
public let clockType: ClockType
116122

117123
public let nextSensorCalibrationDateComponents: NSDateComponents?
118124

@@ -129,6 +135,9 @@ public struct MySentryPumpStatusMessageBody: MessageBody, DictionaryRepresentabl
129135

130136
let pumpDateComponents = NSDateComponents(mySentryBytes: rxData[2...7])
131137

138+
let hourByte: UInt8 = rxData[2]
139+
clockType = ((hourByte & 0b10000000) > 0) ? .TwentyFourHour : .TwelveHour
140+
132141
guard let calendar = pumpDateComponents.calendar where pumpDateComponents.isValidDateInCalendar(calendar) else {
133142
return nil
134143
}

MinimedKit/PumpEventType.swift

+8-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ public enum PumpEventType: UInt8 {
3737
case Questionable3b = 0x3b
3838
case ChangeParadigmLinkID = 0x3c
3939
case BGReceived = 0x3f
40+
case JournalEntryMealMarker = 0x40
4041
case JournalEntryExerciseMarker = 0x41
42+
case JournalEntryInsulinMarker = 0x42
43+
case JournalEntryOtherMarker = 0x43
4144
case ChangeSensorSetup2 = 0x50
4245
case ChangeSensorRateOfChangeAlertSetup = 0x56
4346
case ChangeBolusScrollStepSize = 0x57
@@ -124,6 +127,10 @@ public enum PumpEventType: UInt8 {
124127
return BGReceivedPumpEvent.self
125128
case .JournalEntryExerciseMarker:
126129
return JournalEntryExerciseMarkerPumpEvent.self
130+
case .JournalEntryInsulinMarker:
131+
return JournalEntryInsulinMarkerPumpEvent.self
132+
case .JournalEntryMealMarker:
133+
return JournalEntryMealMarkerPumpEvent.self
127134
case .ChangeSensorSetup2:
128135
return ChangeSensorSetup2PumpEvent.self
129136
case .ChangeSensorRateOfChangeAlertSetup:
@@ -181,7 +188,7 @@ public enum PumpEventType: UInt8 {
181188
case .SelectBasalProfile:
182189
return SelectBasalProfilePumpEvent.self
183190
default:
184-
return UnknownPumpEvent.self
191+
return PlaceholderPumpEvent.self
185192
}
186193
}
187194
}

MinimedKit/PumpEvents/AlarmSensorPumpEvent.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public struct AlarmSensorPumpEvent: TimestampedPumpEvent {
2222

2323
rawData = availableData[0..<length]
2424

25-
timestamp = NSDateComponents(pumpEventData: availableData, offset: 2)
25+
timestamp = NSDateComponents(pumpEventData: availableData, offset: 3)
2626
}
2727

2828
public var dictionaryRepresentation: [String: AnyObject] {

MinimedKit/PumpEvents/CalBGForPHPumpEvent.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public struct CalBGForPHPumpEvent: TimestampedPumpEvent {
2828
}
2929

3030
timestamp = NSDateComponents(pumpEventData: availableData, offset: 2)
31-
amount = ((d(6) & 0b10000000) << 1) + d(1)
31+
amount = ((d(4) & 0b10000000) << 2) + ((d(6) & 0b10000000) << 1) + d(1)
3232
}
3333

3434
public var dictionaryRepresentation: [String: AnyObject] {

MinimedKit/PumpEvents/ChangeTimeFormatPumpEvent.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public struct ChangeTimeFormatPumpEvent: TimestampedPumpEvent {
1212
public let length: Int
1313
public let rawData: NSData
1414
public let timestamp: NSDateComponents
15-
15+
public let timeFormat: String
16+
1617
public init?(availableData: NSData, pumpModel: PumpModel) {
1718
length = 7
1819

@@ -23,11 +24,18 @@ public struct ChangeTimeFormatPumpEvent: TimestampedPumpEvent {
2324
rawData = availableData[0..<length]
2425

2526
timestamp = NSDateComponents(pumpEventData: availableData, offset: 2)
27+
28+
func d(idx:Int) -> Int {
29+
return Int(availableData[idx] as UInt8)
30+
}
31+
32+
timeFormat = d(1) == 1 ? "24hr" : "am_pm"
2633
}
2734

2835
public var dictionaryRepresentation: [String: AnyObject] {
2936
return [
3037
"_type": "ChangeTimeFormat",
38+
"timeFormat": timeFormat,
3139
]
3240
}
3341
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
9+
import Foundation
10+
11+
public struct JournalEntryInsulinMarkerPumpEvent: TimestampedPumpEvent {
12+
public let length: Int
13+
public let rawData: NSData
14+
public let timestamp: NSDateComponents
15+
public let amount: Double
16+
17+
public init?(availableData: NSData, pumpModel: PumpModel) {
18+
length = 8
19+
20+
guard length <= availableData.length else {
21+
return nil
22+
}
23+
24+
rawData = availableData[0..<length]
25+
26+
timestamp = NSDateComponents(pumpEventData: availableData, offset: 2)
27+
28+
let lowBits = rawData[1] as UInt8
29+
let highBits = rawData[4] as UInt8
30+
amount = Double((Int(highBits & 0b1100000) << 3) + Int(lowBits)) / 10.0
31+
}
32+
33+
public var dictionaryRepresentation: [String: AnyObject] {
34+
return [
35+
"_type": "JournalEntryInsulinMarker",
36+
"amount": amount,
37+
]
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// JournalEntryMealMarkerPumpEvent.swift
3+
// RileyLink
4+
//
5+
// Created by Pete Schwamb on 7/14/16.
6+
// Copyright © 2016 Pete Schwamb. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public struct JournalEntryMealMarkerPumpEvent: TimestampedPumpEvent {
12+
public let length: Int
13+
public let rawData: NSData
14+
public let timestamp: NSDateComponents
15+
public let carbohydrates: Double
16+
public let carbUnits: CarbUnits
17+
18+
public enum CarbUnits: String {
19+
case Exchanges
20+
case Grams
21+
}
22+
23+
public init?(availableData: NSData, pumpModel: PumpModel) {
24+
length = 9
25+
26+
let useExchangesBit = ((availableData[8] as UInt8) >> 1) & 0b1
27+
carbUnits = (useExchangesBit != 0) ? .Exchanges : .Grams
28+
29+
let carbHighBit = (availableData[8] as UInt8) & 0b1
30+
let carbLowBits = availableData[7] as UInt8
31+
32+
if carbUnits == .Exchanges {
33+
carbohydrates = Double(carbLowBits) / 10.0
34+
} else {
35+
carbohydrates = Double(Int(carbHighBit) << 8 + Int(carbLowBits))
36+
}
37+
38+
guard length <= availableData.length else {
39+
return nil
40+
}
41+
42+
rawData = availableData[0..<length]
43+
44+
timestamp = NSDateComponents(pumpEventData: availableData, offset: 2)
45+
}
46+
47+
public var dictionaryRepresentation: [String: AnyObject] {
48+
return [
49+
"_type": "JournalEntryMealMarker",
50+
"carbohydrates": carbohydrates,
51+
"carbUnits": carbUnits.rawValue,
52+
]
53+
}
54+
}

MinimedKit/PumpEvents/UnknownPumpEvent.swift MinimedKit/PumpEvents/PlaceholderPumpEvent.swift

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// UnknownPumpEvent.swift
2+
// PlaceholderPumpEvent.swift
33
// RileyLink
44
//
55
// Created by Nate Racklyeft on 6/20/16.
@@ -9,7 +9,7 @@
99
import Foundation
1010

1111

12-
public struct UnknownPumpEvent: TimestampedPumpEvent {
12+
public struct PlaceholderPumpEvent: TimestampedPumpEvent {
1313
public let length: Int
1414
public let rawData: NSData
1515
public let timestamp: NSDateComponents
@@ -20,15 +20,21 @@ public struct UnknownPumpEvent: TimestampedPumpEvent {
2020
guard length <= availableData.length else {
2121
return nil
2222
}
23-
23+
2424
rawData = availableData[0..<length]
25-
2625
timestamp = NSDateComponents(pumpEventData: availableData, offset: 2)
2726
}
2827

2928
public var dictionaryRepresentation: [String: AnyObject] {
29+
let name: String
30+
if let type = PumpEventType(rawValue: rawData[0] as UInt8) {
31+
name = String(type).componentsSeparatedByString(".").last!
32+
} else {
33+
name = "UnknownPumpEvent(\(rawData[0] as UInt8))"
34+
}
35+
3036
return [
31-
"_type": "UnknownPumpEvent(\(rawData[0] as UInt8))",
37+
"_type": name,
3238
]
3339
}
3440
}

MinimedKit/PumpEvents/PumpEvent.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Foundation
1111
public protocol PumpEvent : DictionaryRepresentable {
1212

1313
init?(availableData: NSData, pumpModel: PumpModel)
14-
14+
1515
var rawData: NSData {
1616
get
1717
}

MinimedKit/PumpModel.swift

+17-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ public enum PumpModel: String {
2626
case Model751 = "751"
2727
case Model554 = "554"
2828
case Model754 = "754"
29-
30-
var generation: Int {
29+
30+
private var size: Int {
31+
return Int(rawValue)! / 100
32+
}
33+
34+
private var generation: Int {
3135
return Int(rawValue)! % 100
3236
}
3337

@@ -46,6 +50,17 @@ public enum PumpModel: String {
4650
public var strokesPerUnit: Int {
4751
return (generation >= 23) ? 40 : 10
4852
}
53+
54+
var reservoirCapacity: Int {
55+
switch size {
56+
case 5:
57+
return 176
58+
case 7:
59+
return 300
60+
default:
61+
fatalError("Unknown reservoir capacity for PumpModel.\(self)")
62+
}
63+
}
4964
}
5065

5166

0 commit comments

Comments
 (0)