Skip to content

Commit 4c13ed4

Browse files
authored
Merge pull request #186 from ps2/dev
v0.8.0
2 parents 45b422f + 3fefcc9 commit 4c13ed4

Some content is hidden

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

42 files changed

+1007
-207
lines changed

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.7.1</string>
18+
<string>0.8.0</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

MinimedKit/MessageType.swift

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public enum MessageType: UInt8 {
2828
case GetPumpModel = 0x8d
2929
case ReadTempBasal = 0x98
3030
case ReadSettings = 0xc0
31+
case ReadPumpStatus = 0xce
3132

3233
var bodyType: MessageBody.Type {
3334
switch self {
@@ -59,6 +60,8 @@ public enum MessageType: UInt8 {
5960
return GetBatteryCarelinkMessageBody.self
6061
case .ReadRemainingInsulin:
6162
return ReadRemainingInsulinMessageBody.self
63+
case .ReadPumpStatus:
64+
return ReadPumpStatusMessageBody.self
6265
default:
6366
return UnknownMessageBody.self
6467
}

MinimedKit/Messages/GetBatteryCarelinkMessageBody.swift

+20-8
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,37 @@
88

99
import Foundation
1010

11+
public enum BatteryStatus {
12+
case Low
13+
case Normal
14+
case Unknown(rawVal: UInt8)
15+
16+
init(statusByte: UInt8) {
17+
switch statusByte {
18+
case 1:
19+
self = .Low
20+
case 0:
21+
self = .Normal
22+
default:
23+
self = .Unknown(rawVal: statusByte)
24+
}
25+
}
26+
}
27+
1128
public class GetBatteryCarelinkMessageBody: CarelinkLongMessageBody {
12-
public let status: String
29+
public let status: BatteryStatus
1330
public let volts: Double
1431

1532
public required init?(rxData: NSData) {
1633
guard rxData.length == self.dynamicType.length else {
17-
status = ""
1834
volts = 0
35+
status = .Unknown(rawVal: 0)
1936
super.init(rxData: rxData)
2037
return nil
2138
}
2239

2340
volts = Double(Int(rxData[2] as UInt8) << 8 + Int(rxData[3] as UInt8)) / 100.0
24-
25-
if rxData[1] as UInt8 > 0 {
26-
status = "Low"
27-
} else {
28-
status = "Normal"
29-
}
41+
status = BatteryStatus(statusByte: rxData[1] as UInt8)
3042

3143
super.init(rxData: rxData)
3244
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// ReadPumpStatusMessageBody.swift
3+
// RileyLink
4+
//
5+
// Created by Pete Schwamb on 7/31/16.
6+
// Copyright © 2016 Pete Schwamb. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public class ReadPumpStatusMessageBody: CarelinkLongMessageBody {
12+
13+
public let bolusing: Bool
14+
public let suspended: Bool
15+
16+
public required init?(rxData: NSData) {
17+
guard rxData.length == self.dynamicType.length else {
18+
return nil
19+
}
20+
21+
bolusing = (rxData[2] as UInt8) > 0
22+
suspended = (rxData[3] as UInt8) > 0
23+
24+
super.init(rxData: rxData)
25+
}
26+
27+
}

MinimedKit/Messages/ReadRemainingInsulinMessageBody.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright © 2016 Pete Schwamb. All rights reserved.
77
//
88

9-
import UIKit
9+
import Foundation
1010

1111
public class ReadRemainingInsulinMessageBody: CarelinkLongMessageBody {
1212

MinimedKit/PumpEventType.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public enum PumpEventType: UInt8 {
6969
case DeleteOtherDeviceID = 0x82
7070
case ChangeCaptureEventEnable = 0x83
7171

72-
var eventType: PumpEvent.Type {
72+
public var eventType: PumpEvent.Type {
7373
switch self {
7474
case .BolusNormal:
7575
return BolusNormalPumpEvent.self

MinimedKit/PumpEvents/ChangeTimePumpEvent.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public struct ChangeTimePumpEvent: TimestampedPumpEvent {
3030
oldTimestamp = NSDateComponents(pumpEventData: availableData, offset: 2)
3131
timestamp = NSDateComponents(pumpEventData: availableData, offset: 9)
3232
}
33-
33+
3434
public var dictionaryRepresentation: [String: AnyObject] {
3535
return [
3636
"_type": "ChangeTime",

MinimedKit/PumpEvents/PumpAlarmPumpEvent.swift

+35-4
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,41 @@
88

99
import Foundation
1010

11+
public enum PumpAlarmType {
12+
case BatteryOutLimitExceeded
13+
case NoDelivery
14+
case BatteryDepleted
15+
case DeviceReset
16+
case ReprogramError
17+
case EmptyReservoir
18+
case UnknownType(rawType: UInt8)
19+
20+
init(rawType: UInt8) {
21+
switch rawType {
22+
case 3:
23+
self = .BatteryOutLimitExceeded
24+
case 4:
25+
self = .NoDelivery
26+
case 5:
27+
self = .BatteryDepleted
28+
case 16:
29+
self = .DeviceReset
30+
case 61:
31+
self = .ReprogramError
32+
case 62:
33+
self = .EmptyReservoir
34+
default:
35+
self = .UnknownType(rawType: rawType)
36+
}
37+
}
38+
}
39+
1140
public struct PumpAlarmPumpEvent: TimestampedPumpEvent {
1241
public let length: Int
1342
public let rawData: NSData
1443
public let timestamp: NSDateComponents
15-
let rawType: Int
16-
44+
public let alarmType: PumpAlarmType
45+
1746
public init?(availableData: NSData, pumpModel: PumpModel) {
1847
length = 9
1948

@@ -23,14 +52,16 @@ public struct PumpAlarmPumpEvent: TimestampedPumpEvent {
2352

2453
rawData = availableData[0..<length]
2554

26-
rawType = Int(availableData[1] as UInt8)
55+
alarmType = PumpAlarmType(rawType: availableData[1] as UInt8)
56+
2757
timestamp = NSDateComponents(pumpEventData: availableData, offset: 4)
2858
}
2959

3060
public var dictionaryRepresentation: [String: AnyObject] {
61+
3162
return [
3263
"_type": "AlarmPump",
33-
"rawType": rawType,
64+
"alarm": "\(self.alarmType)",
3465
]
3566
}
3667
}

MinimedKitTests/HistoryPageTests.swift

+15
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,21 @@ class HistoryPageTests: XCTestCase {
316316
XCTAssertEqual(NSDateComponents(gregorianYear: 2016, month: 7, day: 15, hour: 20, minute: 2, second: 20), alarm.timestamp)
317317
}
318318

319+
func testPumpAlarms() throws {
320+
let pumpModel = PumpModel.Model723
321+
322+
let page = try HistoryPage(pageData: NSData(hexadecimalString: "5c0800b8c11ce0c101013c013c00000059eb567a1033004bf5165a100016014bf5165a10330079cc175a1000160179cc175a10330079e0175a1000160179e0175a10330b70ef175a1000160170ef175a10061503680040600107060a2084004060010706110411114040a1070c150a4600010706050309004040a1071a0005410001070c0505410001071a0119410001076400304100010764001e4200010717003542000107180040c0001b10070000000001870000006e01870500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000021004fc0001b10030000000056c1201b107b0079c1001b1000440033006cc7005b100016016cc7005b10330068dc005b1000160168dc005b10338568e1005b1000160168e1005b1033c56aeb005b100016016aeb005b1033b168f0005b1000160168f0005b1033b968f5005b1000160168f5005b1033be68fa005b1000160168fa005b1033bc69c3015b1000160169c3015b1033c169c8015b1000160169c8015b1033b868cd015b1000160168cd015b1033ae69d2015b1000160169d2015b1033ad69d7015b1000160169d7015b1033c368dc015b1000160168dc015b1033c868e1015b1000160168e1015b1033c169e6015b1000160169e6015b1033b668eb015b1000160168eb015b1033be68f0015b1000160168f0015b1033a468f5015b1000160168f5015b1033ab68fa015b1000160168fa015b1033a869c3025b1000160169c3025b10338968c8025b1000160168c8025b10336c68cd025b1000160168cd025b10336469d2025b1000160169d2025b10336d68d7025b1000160168d7025b10337a68dc025b1000160168dc025b10338968e1025b1000160168e1025b10339968e6025b1000160168e6025b10339268eb025b1000160168eb025b10338168f0025b1000160168f0025b10338369f5025b1000160169f5025b10337768fa025b1000160168fa025b10337668c3035b1000160168c3035b10338068c8035b1000160168c8035b10336768cd035b1000160168cd035b10330069d2035b1000160069d2035b107b0069d2031b10004400336968d7035b1000160168d7035b10338668dc035b1000160168dc035b10337b6ae1035b100016016ae1035b10338668e6035b1000160168e6035b10339668eb035b1000160168eb035b1033c069f0035b1000160169f0035b1033b769f5035b1000160169f5035b10339c69fa035b1000160169fa035b10330068c3045b1000160068c3045b107b0068c3041b10004400338368d2045b1000160168d2045b1033ac68d7045b1000160168d7045b10338769dc045b1000160169dc045b10335f68e1045b1000160168e1045b10330069e6045b1000160069e6045b100000000000bf1d")!, pumpModel: pumpModel)
323+
let events = page.events
319324

325+
XCTAssertEqual(125, events.count)
320326

327+
let alarm = events[9] as! PumpAlarmPumpEvent
328+
XCTAssertEqual("UnknownType(21)", "\(alarm.alarmType)")
329+
XCTAssertEqual(NSDateComponents(gregorianYear: 2007, month: 1, day: 1, hour: 0, minute: 0, second: 0), alarm.timestamp)
330+
331+
let batteryDepletedAlarm = events[13] as! PumpAlarmPumpEvent
332+
XCTAssertEqual("BatteryDepleted", "\(batteryDepletedAlarm.alarmType)")
333+
XCTAssertEqual(NSDateComponents(gregorianYear: 2007, month: 1, day: 1, hour: 0, minute: 0, second: 0), batteryDepletedAlarm.timestamp)
334+
335+
}
321336
}

MinimedKitTests/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>BNDL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>0.7.1</string>
18+
<string>0.8.0</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// BatteryStatus.swift
3+
// RileyLink
4+
//
5+
// Created by Pete Schwamb on 7/28/16.
6+
// Copyright © 2016 Pete Schwamb. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public enum BatteryIndicator: String {
12+
case Low = "low"
13+
case Normal = "normal"
14+
}
15+
16+
public struct BatteryStatus {
17+
let percent: Int?
18+
let voltage: Double?
19+
let status: BatteryIndicator?
20+
21+
public init(percent: Int? = nil, voltage: Double? = nil, status: BatteryIndicator? = nil) {
22+
self.percent = percent
23+
self.voltage = voltage
24+
self.status = status
25+
}
26+
27+
public var dictionaryRepresentation: [String: AnyObject] {
28+
var rval = [String: AnyObject]()
29+
30+
if let percent = percent {
31+
rval["percent"] = percent
32+
}
33+
if let voltage = voltage {
34+
rval["voltage"] = voltage
35+
}
36+
37+
if let status = status {
38+
rval["status"] = status.rawValue
39+
}
40+
41+
return rval
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// COBStatus.swift
3+
// RileyLink
4+
//
5+
// Created by Pete Schwamb on 8/2/16.
6+
// Copyright © 2016 Pete Schwamb. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public struct COBStatus {
12+
let cob: Double
13+
let timestamp: NSDate
14+
15+
public init(cob: Double, timestamp: NSDate) {
16+
self.cob = cob // grams
17+
self.timestamp = timestamp
18+
}
19+
20+
public var dictionaryRepresentation: [String: AnyObject] {
21+
22+
var rval = [String: AnyObject]()
23+
24+
rval["timestamp"] = TimeFormat.timestampStrFromDate(timestamp)
25+
rval["cob"] = cob
26+
27+
return rval
28+
}
29+
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// DeviceStatus.swift
3+
// RileyLink
4+
//
5+
// Created by Pete Schwamb on 7/26/16.
6+
// Copyright © 2016 Pete Schwamb. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public struct DeviceStatus {
12+
let device: String
13+
let timestamp: NSDate
14+
let pumpStatus: PumpStatus?
15+
let uploaderStatus: UploaderStatus?
16+
let loopStatus: LoopStatus?
17+
18+
public init(device: String, timestamp: NSDate, pumpStatus: PumpStatus? = nil, uploaderStatus: UploaderStatus? = nil, loopStatus: LoopStatus? = nil) {
19+
self.device = device
20+
self.timestamp = timestamp
21+
self.pumpStatus = pumpStatus
22+
self.uploaderStatus = uploaderStatus
23+
self.loopStatus = loopStatus
24+
}
25+
26+
public var dictionaryRepresentation: [String: AnyObject] {
27+
var rval = [String: AnyObject]()
28+
29+
rval["device"] = device
30+
rval["created_at"] = TimeFormat.timestampStrFromDate(timestamp)
31+
32+
if let pump = pumpStatus {
33+
rval["pump"] = pump.dictionaryRepresentation
34+
}
35+
36+
if let uploader = uploaderStatus {
37+
rval["uploader"] = uploader.dictionaryRepresentation
38+
}
39+
40+
if let loop = loopStatus {
41+
// Would like to change this to avoid confusion about whether or not this was uploaded from Loop or openaps
42+
rval["openaps"] = loop.dictionaryRepresentation
43+
}
44+
45+
return rval
46+
}
47+
}
48+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// IOBStatus.swift
3+
// RileyLink
4+
//
5+
// Created by Pete Schwamb on 7/28/16.
6+
// Copyright © 2016 Pete Schwamb. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public struct IOBStatus {
12+
let timestamp: NSDate
13+
let iob: Double? // basal iob + bolus iob: can be negative
14+
let basalIOB: Double? // does not include bolus iob
15+
16+
public init(timestamp: NSDate, iob: Double? = nil, basalIOB: Double? = nil) {
17+
self.timestamp = timestamp
18+
self.iob = iob
19+
self.basalIOB = basalIOB
20+
}
21+
22+
public var dictionaryRepresentation: [String: AnyObject] {
23+
24+
var rval = [String: AnyObject]()
25+
26+
rval["timestamp"] = TimeFormat.timestampStrFromDate(timestamp)
27+
28+
if let iob = iob {
29+
rval["iob"] = iob
30+
}
31+
32+
if let basalIOB = basalIOB {
33+
rval["basaliob"] = basalIOB
34+
}
35+
36+
return rval
37+
}
38+
}

0 commit comments

Comments
 (0)