Skip to content

Commit 5c43423

Browse files
authored
Merge pull request #578 from ps2/dev
Release 3.0
2 parents bfcc693 + 697a0cc commit 5c43423

File tree

510 files changed

+27737
-6700
lines changed

Some content is hidden

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

510 files changed

+27737
-6700
lines changed

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ DerivedData
1717
*.ipa
1818
*.xcuserstate
1919
*.xcscmblueprint
20-
project.xcworkspace
2120
.DS_Store
2221
*.log
23-
project.xcworkspace
2422

2523
# CocoaPods
2624
#

.travis.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
language: objective-c
2-
osx_image: xcode10
3-
xcode_project: RileyLink.xcodeproj
4-
xcode_scheme: RileyLink
2+
osx_image: xcode11
3+
4+
before_script:
5+
- carthage bootstrap
6+
57
script:
6-
- xcodebuild -project RileyLink.xcodeproj -scheme RileyLink build -destination 'name=iPhone SE' test
8+
- set -o pipefail && xcodebuild -project RileyLink.xcodeproj -scheme Shared build -destination 'name=iPhone 8' test | xcpretty

Cartfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
github "LoopKit/LoopKit" ~> 2.2
1+
github "LoopKit/LoopKit" ~> 3.0
2+
github "LoopKit/MKRingProgressView" "appex-safe"

Cartfile.resolved

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
github "LoopKit/LoopKit" "v2.2.2"
1+
github "LoopKit/LoopKit" "v3.0"
2+
github "LoopKit/MKRingProgressView" "f548a5c64832be2d37d7c91b5800e284887a2a0a"

Common/Comparable.swift

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// Comparable.swift
3+
// RileyLink
4+
//
5+
// Created by Pete Schwamb on 2/17/19.
6+
// Copyright © 2019 Pete Schwamb. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
extension Comparable {
12+
func clamped(to range: ClosedRange<Self>) -> Self {
13+
if self < range.lowerBound {
14+
return range.lowerBound
15+
} else if self > range.upperBound {
16+
return range.upperBound
17+
} else {
18+
return self
19+
}
20+
}
21+
}

Common/Data.swift

+14-8
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,22 @@ import Foundation
1010

1111

1212
extension Data {
13-
func to<T: FixedWidthInteger>(_: T.Type) -> T {
14-
return self.withUnsafeBytes { (bytes: UnsafePointer<T>) in
15-
return T(littleEndian: bytes.pointee)
16-
}
13+
private func toDefaultEndian<T: FixedWidthInteger>(_: T.Type) -> T {
14+
return self.withUnsafeBytes({ (rawBufferPointer: UnsafeRawBufferPointer) -> T in
15+
let bufferPointer = rawBufferPointer.bindMemory(to: T.self)
16+
guard let pointer = bufferPointer.baseAddress else {
17+
return 0
18+
}
19+
return T(pointer.pointee)
20+
})
1721
}
1822

19-
func toBigEndian<T: FixedWidthInteger>(_: T.Type) -> T {
20-
return self.withUnsafeBytes {
21-
return T(bigEndian: $0.pointee)
22-
}
23+
func to<T: FixedWidthInteger>(_ type: T.Type) -> T {
24+
return T(littleEndian: toDefaultEndian(type))
25+
}
26+
27+
func toBigEndian<T: FixedWidthInteger>(_ type: T.Type) -> T {
28+
return T(bigEndian: toDefaultEndian(type))
2329
}
2430

2531
mutating func append<T: FixedWidthInteger>(_ newElement: T) {

Common/Locked.swift

-40
This file was deleted.

Crypto/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>2.1.1</string>
18+
<string>3.0</string>
1919
<key>CFBundleVersion</key>
2020
<string>$(CURRENT_PROJECT_VERSION)</string>
2121
<key>NSPrincipalClass</key>

Crypto/de.lproj/InfoPlist.strings

-3
This file was deleted.

Crypto/es.lproj/InfoPlist.strings

-3
This file was deleted.

Crypto/fr.lproj/InfoPlist.strings

-3
This file was deleted.

Crypto/it.lproj/InfoPlist.strings

-3
This file was deleted.

Crypto/nb.lproj/InfoPlist.strings

-3
This file was deleted.

Crypto/nl.lproj/InfoPlist.strings

-3
This file was deleted.

Crypto/pl.lproj/InfoPlist.strings

-3
This file was deleted.

Crypto/ru.lproj/InfoPlist.strings

-3
This file was deleted.

Crypto/zh-Hans.lproj/InfoPlist.strings

-3
This file was deleted.

MinimedKit/Base.lproj/Localizable.strings

-1
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,3 @@
9696

9797
/* Describing the worldwide pump region */
9898
"World-Wide" = "World-Wide";
99-

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>2.1.1</string>
18+
<string>3.0</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

MinimedKit/Messages/BolusCarelinkMessageBody.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import Foundation
1111

1212
public class BolusCarelinkMessageBody: CarelinkLongMessageBody {
1313

14-
public convenience init(units: Double, strokesPerUnit: Int = 10) {
14+
public convenience init(units: Double, insulinBitPackingScale: Int = 10) {
1515

1616
let length: Int
1717
let scrollRate: Int
1818

19-
if strokesPerUnit >= 40 {
19+
if insulinBitPackingScale >= 40 {
2020
length = 2
2121

2222
// 40-stroke pumps scroll faster for higher unit values
@@ -33,7 +33,7 @@ public class BolusCarelinkMessageBody: CarelinkLongMessageBody {
3333
scrollRate = 1
3434
}
3535

36-
let strokes = Int(units * Double(strokesPerUnit / scrollRate)) * scrollRate
36+
let strokes = Int(units * Double(insulinBitPackingScale / scrollRate)) * scrollRate
3737

3838
let data = Data(hexadecimalString: String(format: "%02x%0\(2 * length)x", length, strokes))!
3939

MinimedKit/Messages/ChangeMaxBasalRateMessageBody.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class ChangeMaxBasalRateMessageBody: CarelinkLongMessageBody {
1919

2020
let ticks = UInt16(maxBasalUnitsPerHour * type(of: self).multiplier)
2121
let length = UInt8(clamping: ticks.bitWidth / 8)
22-
var data = Data(bytes: [length])
22+
var data = Data([length])
2323

2424
data.appendBigEndian(ticks)
2525

MinimedKit/Messages/ChangeTimeCarelinkMessageBody.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ import Foundation
1212
public class ChangeTimeCarelinkMessageBody: CarelinkLongMessageBody {
1313

1414
public convenience init?(dateComponents: DateComponents) {
15+
16+
var calendar = Calendar(identifier: .gregorian)
17+
if let timeZone = dateComponents.timeZone {
18+
calendar.timeZone = timeZone
19+
}
1520

16-
guard dateComponents.isValidDate(in: Calendar(identifier: Calendar.Identifier.gregorian)) else {
21+
guard dateComponents.isValidDate(in: calendar) else {
1722
return nil
1823
}
1924

MinimedKit/Messages/DataFrameMessageBody.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class DataFrameMessageBody: CarelinkLongMessageBody {
3939
byte0 |= 0b1000_0000
4040
}
4141

42-
var data = Data(bytes: [byte0])
42+
var data = Data([byte0])
4343
data.append(contents)
4444

4545
return data

MinimedKit/Messages/GetBatteryCarelinkMessageBody.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import Foundation
1010

11-
public enum BatteryStatus {
11+
public enum BatteryStatus: Equatable {
1212
case low
1313
case normal
1414
case unknown(rawVal: UInt8)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// GetPumpFirmwareVersionMessageBody.swift
3+
// MinimedKit
4+
//
5+
// Created by Pete Schwamb on 10/10/18.
6+
// Copyright © 2018 Pete Schwamb. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public class GetPumpFirmwareVersionMessageBody: CarelinkLongMessageBody {
12+
public let version: String
13+
14+
public required init?(rxData: Data) {
15+
let stringEnd = rxData.firstIndex(of: 0) ?? rxData.count
16+
guard rxData.count == type(of: self).length,
17+
let vsn = String(data: rxData.subdata(in: 1..<stringEnd), encoding: String.Encoding.ascii) else {
18+
return nil
19+
}
20+
version = vsn
21+
super.init(rxData: rxData)
22+
}
23+
24+
public required init?(rxData: NSData) {
25+
fatalError("init(rxData:) has not been implemented")
26+
}
27+
}

MinimedKit/Messages/MessageType.swift

+5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public enum MessageType: UInt8 {
3232
case selectBasalProfile = 0x4a
3333

3434
case changeTempBasal = 0x4c
35+
case suspendResume = 0x4d
3536

3637
case PumpExperiment_OP80 = 0x50
3738
case setRemoteControlID = 0x51 // CMD_SET_RF_REMOTE_ID
@@ -141,6 +142,10 @@ public enum MessageType: UInt8 {
141142
return ReadOtherDevicesStatusMessageBody.self
142143
case .readRemoteControlIDs:
143144
return ReadRemoteControlIDsMessageBody.self
145+
case .suspendResume:
146+
return SuspendResumeMessageBody.self
147+
case .readFirmwareVersion:
148+
return GetPumpFirmwareVersionMessageBody.self
144149
default:
145150
return UnknownMessageBody.self
146151
}

MinimedKit/Messages/Models/BasalSchedule.swift

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public struct BasalSchedule {
2929
}
3030
}
3131

32-
3332
extension BasalSchedule {
3433
static let rawValueLength = 192
3534
public typealias RawValue = Data

MinimedKit/Messages/Models/TimestampedGlucoseEvent.swift

-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ public struct TimestampedGlucoseEvent {
1212
public let glucoseEvent: GlucoseEvent
1313
public let date: Date
1414

15-
public func isMutable(atDate date: Date = Date()) -> Bool {
16-
return false
17-
}
18-
1915
public init(glucoseEvent: GlucoseEvent, date: Date) {
2016
self.glucoseEvent = glucoseEvent
2117
self.date = date

MinimedKit/Messages/Models/TimestampedHistoryEvent.swift

+8-11
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,18 @@ public struct TimestampedHistoryEvent {
1414
public let pumpEvent: PumpEvent
1515
public let date: Date
1616

17-
public func isMutable(atDate date: Date = Date()) -> Bool {
18-
switch pumpEvent {
19-
case let bolus as BolusNormalPumpEvent:
20-
// Square boluses
21-
let deliveryFinishDate = self.date.addingTimeInterval(bolus.deliveryTime)
22-
return deliveryFinishDate.compare(date) == .orderedDescending
23-
default:
24-
return false
25-
}
26-
}
27-
2817
public init(pumpEvent: PumpEvent, date: Date) {
2918
self.pumpEvent = pumpEvent
3019
self.date = date
3120
}
21+
22+
public func isMutable(atDate date: Date = Date(), forPump model: PumpModel) -> Bool {
23+
guard let bolus = self.pumpEvent as? BolusNormalPumpEvent else {
24+
return false
25+
}
26+
let deliveryFinishDate = date.addingTimeInterval(bolus.deliveryTime)
27+
return model.appendsSquareWaveToHistoryOnStartOfDelivery && bolus.type == .square && deliveryFinishDate > date
28+
}
3229
}
3330

3431

MinimedKit/Messages/MySentryAckMessageBody.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ public struct MySentryAckMessageBody: MessageBody {
4646

4747
buffer.replaceSubrange(5..<5 + responseMessageTypes.count, with: responseMessageTypes.map({ $0.rawValue }))
4848

49-
return Data(bytes: buffer)
49+
return Data(buffer)
5050
}
5151
}

MinimedKit/Messages/MySentryPumpStatusMessageBody.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ public struct MySentryPumpStatusMessageBody: MessageBody, DictionaryRepresentabl
158158
let batteryRemainingPercent: UInt8 = rxData[14]
159159
self.batteryRemainingPercent = Int(round(Double(batteryRemainingPercent) / 4.0 * 100))
160160

161-
let glucoseValue = Int(bigEndianBytes: Data(bytes: [rxData[9], rxData[24] << 7])) >> 7
162-
let previousGlucoseValue = Int(bigEndianBytes: Data(bytes: [rxData[10], rxData[24] << 6])) >> 7
161+
let glucoseValue = Int(bigEndianBytes: Data([rxData[9], rxData[24] << 7])) >> 7
162+
let previousGlucoseValue = Int(bigEndianBytes: Data([rxData[10], rxData[24] << 6])) >> 7
163163

164164
glucose = SensorReading(glucose: glucoseValue)
165165
previousGlucose = SensorReading(glucose: previousGlucoseValue)

MinimedKit/Messages/PumpMessage.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ public struct PumpMessage : CustomStringConvertible {
4444
buffer.append(messageType.rawValue)
4545
buffer.append(contentsOf: messageBody.txData)
4646

47-
return Data(bytes: buffer)
47+
return Data(buffer)
4848
}
4949

5050
public var description: String {
51-
return String(format: LocalizedString("PumpMessage(%1$@, %2$@, %3$@, %4$@)", comment: "The format string describing a pump message. (1: The packet type)(2: The message type)(3: The message address)(4: The message data"), String(describing: packetType), String(describing: messageType), String(describing: address), String(describing: self.messageBody.txData))
51+
return String(format: "PumpMessage(%1$@, %2$@, %3$@, %4$@)", String(describing: packetType), String(describing: messageType), address.hexadecimalString, self.messageBody.txData.hexadecimalString)
5252
}
5353

5454
}

MinimedKit/Messages/ReadCurrentGlucosePageMessageBody.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ReadCurrentGlucosePageMessageBody: CarelinkLongMessageBody {
2020
}
2121

2222
self.pageNum = rxData[1..<5
23-
].withUnsafeBytes { UInt32(bigEndian: $0.pointee) }
23+
].toBigEndian(UInt32.self)
2424
self.glucose = Int(rxData[6])
2525
self.isig = Int(rxData[8])
2626

0 commit comments

Comments
 (0)