Skip to content

Commit

Permalink
Merge pull request #578 from ps2/dev
Browse files Browse the repository at this point in the history
Release 3.0
  • Loading branch information
ps2 authored Dec 31, 2019
2 parents bfcc693 + 697a0cc commit 5c43423
Show file tree
Hide file tree
Showing 510 changed files with 27,737 additions and 6,700 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ DerivedData
*.ipa
*.xcuserstate
*.xcscmblueprint
project.xcworkspace
.DS_Store
*.log
project.xcworkspace

# CocoaPods
#
Expand Down
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: objective-c
osx_image: xcode10
xcode_project: RileyLink.xcodeproj
xcode_scheme: RileyLink
osx_image: xcode11

before_script:
- carthage bootstrap

script:
- xcodebuild -project RileyLink.xcodeproj -scheme RileyLink build -destination 'name=iPhone SE' test
- set -o pipefail && xcodebuild -project RileyLink.xcodeproj -scheme Shared build -destination 'name=iPhone 8' test | xcpretty
3 changes: 2 additions & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
github "LoopKit/LoopKit" ~> 2.2
github "LoopKit/LoopKit" ~> 3.0
github "LoopKit/MKRingProgressView" "appex-safe"
3 changes: 2 additions & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
github "LoopKit/LoopKit" "v2.2.2"
github "LoopKit/LoopKit" "v3.0"
github "LoopKit/MKRingProgressView" "f548a5c64832be2d37d7c91b5800e284887a2a0a"
21 changes: 21 additions & 0 deletions Common/Comparable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Comparable.swift
// RileyLink
//
// Created by Pete Schwamb on 2/17/19.
// Copyright © 2019 Pete Schwamb. All rights reserved.
//

import Foundation

extension Comparable {
func clamped(to range: ClosedRange<Self>) -> Self {
if self < range.lowerBound {
return range.lowerBound
} else if self > range.upperBound {
return range.upperBound
} else {
return self
}
}
}
22 changes: 14 additions & 8 deletions Common/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ import Foundation


extension Data {
func to<T: FixedWidthInteger>(_: T.Type) -> T {
return self.withUnsafeBytes { (bytes: UnsafePointer<T>) in
return T(littleEndian: bytes.pointee)
}
private func toDefaultEndian<T: FixedWidthInteger>(_: T.Type) -> T {
return self.withUnsafeBytes({ (rawBufferPointer: UnsafeRawBufferPointer) -> T in
let bufferPointer = rawBufferPointer.bindMemory(to: T.self)
guard let pointer = bufferPointer.baseAddress else {
return 0
}
return T(pointer.pointee)
})
}

func toBigEndian<T: FixedWidthInteger>(_: T.Type) -> T {
return self.withUnsafeBytes {
return T(bigEndian: $0.pointee)
}
func to<T: FixedWidthInteger>(_ type: T.Type) -> T {
return T(littleEndian: toDefaultEndian(type))
}

func toBigEndian<T: FixedWidthInteger>(_ type: T.Type) -> T {
return T(bigEndian: toDefaultEndian(type))
}

mutating func append<T: FixedWidthInteger>(_ newElement: T) {
Expand Down
40 changes: 0 additions & 40 deletions Common/Locked.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Crypto/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.1.1</string>
<string>3.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
3 changes: 0 additions & 3 deletions Crypto/de.lproj/InfoPlist.strings

This file was deleted.

3 changes: 0 additions & 3 deletions Crypto/es.lproj/InfoPlist.strings

This file was deleted.

3 changes: 0 additions & 3 deletions Crypto/fr.lproj/InfoPlist.strings

This file was deleted.

3 changes: 0 additions & 3 deletions Crypto/it.lproj/InfoPlist.strings

This file was deleted.

3 changes: 0 additions & 3 deletions Crypto/nb.lproj/InfoPlist.strings

This file was deleted.

3 changes: 0 additions & 3 deletions Crypto/nl.lproj/InfoPlist.strings

This file was deleted.

3 changes: 0 additions & 3 deletions Crypto/pl.lproj/InfoPlist.strings

This file was deleted.

3 changes: 0 additions & 3 deletions Crypto/ru.lproj/InfoPlist.strings

This file was deleted.

3 changes: 0 additions & 3 deletions Crypto/zh-Hans.lproj/InfoPlist.strings

This file was deleted.

1 change: 0 additions & 1 deletion MinimedKit/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,3 @@

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

2 changes: 1 addition & 1 deletion MinimedKit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.1.1</string>
<string>3.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
6 changes: 3 additions & 3 deletions MinimedKit/Messages/BolusCarelinkMessageBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import Foundation

public class BolusCarelinkMessageBody: CarelinkLongMessageBody {

public convenience init(units: Double, strokesPerUnit: Int = 10) {
public convenience init(units: Double, insulinBitPackingScale: Int = 10) {

let length: Int
let scrollRate: Int

if strokesPerUnit >= 40 {
if insulinBitPackingScale >= 40 {
length = 2

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

let strokes = Int(units * Double(strokesPerUnit / scrollRate)) * scrollRate
let strokes = Int(units * Double(insulinBitPackingScale / scrollRate)) * scrollRate

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

Expand Down
2 changes: 1 addition & 1 deletion MinimedKit/Messages/ChangeMaxBasalRateMessageBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ChangeMaxBasalRateMessageBody: CarelinkLongMessageBody {

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

data.appendBigEndian(ticks)

Expand Down
7 changes: 6 additions & 1 deletion MinimedKit/Messages/ChangeTimeCarelinkMessageBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ import Foundation
public class ChangeTimeCarelinkMessageBody: CarelinkLongMessageBody {

public convenience init?(dateComponents: DateComponents) {

var calendar = Calendar(identifier: .gregorian)
if let timeZone = dateComponents.timeZone {
calendar.timeZone = timeZone
}

guard dateComponents.isValidDate(in: Calendar(identifier: Calendar.Identifier.gregorian)) else {
guard dateComponents.isValidDate(in: calendar) else {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion MinimedKit/Messages/DataFrameMessageBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class DataFrameMessageBody: CarelinkLongMessageBody {
byte0 |= 0b1000_0000
}

var data = Data(bytes: [byte0])
var data = Data([byte0])
data.append(contents)

return data
Expand Down
2 changes: 1 addition & 1 deletion MinimedKit/Messages/GetBatteryCarelinkMessageBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public enum BatteryStatus {
public enum BatteryStatus: Equatable {
case low
case normal
case unknown(rawVal: UInt8)
Expand Down
27 changes: 27 additions & 0 deletions MinimedKit/Messages/GetPumpFirmwareVersionMessageBody.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// GetPumpFirmwareVersionMessageBody.swift
// MinimedKit
//
// Created by Pete Schwamb on 10/10/18.
// Copyright © 2018 Pete Schwamb. All rights reserved.
//

import Foundation

public class GetPumpFirmwareVersionMessageBody: CarelinkLongMessageBody {
public let version: String

public required init?(rxData: Data) {
let stringEnd = rxData.firstIndex(of: 0) ?? rxData.count
guard rxData.count == type(of: self).length,
let vsn = String(data: rxData.subdata(in: 1..<stringEnd), encoding: String.Encoding.ascii) else {
return nil
}
version = vsn
super.init(rxData: rxData)
}

public required init?(rxData: NSData) {
fatalError("init(rxData:) has not been implemented")
}
}
5 changes: 5 additions & 0 deletions MinimedKit/Messages/MessageType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public enum MessageType: UInt8 {
case selectBasalProfile = 0x4a

case changeTempBasal = 0x4c
case suspendResume = 0x4d

case PumpExperiment_OP80 = 0x50
case setRemoteControlID = 0x51 // CMD_SET_RF_REMOTE_ID
Expand Down Expand Up @@ -141,6 +142,10 @@ public enum MessageType: UInt8 {
return ReadOtherDevicesStatusMessageBody.self
case .readRemoteControlIDs:
return ReadRemoteControlIDsMessageBody.self
case .suspendResume:
return SuspendResumeMessageBody.self
case .readFirmwareVersion:
return GetPumpFirmwareVersionMessageBody.self
default:
return UnknownMessageBody.self
}
Expand Down
1 change: 0 additions & 1 deletion MinimedKit/Messages/Models/BasalSchedule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public struct BasalSchedule {
}
}


extension BasalSchedule {
static let rawValueLength = 192
public typealias RawValue = Data
Expand Down
4 changes: 0 additions & 4 deletions MinimedKit/Messages/Models/TimestampedGlucoseEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ public struct TimestampedGlucoseEvent {
public let glucoseEvent: GlucoseEvent
public let date: Date

public func isMutable(atDate date: Date = Date()) -> Bool {
return false
}

public init(glucoseEvent: GlucoseEvent, date: Date) {
self.glucoseEvent = glucoseEvent
self.date = date
Expand Down
19 changes: 8 additions & 11 deletions MinimedKit/Messages/Models/TimestampedHistoryEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,18 @@ public struct TimestampedHistoryEvent {
public let pumpEvent: PumpEvent
public let date: Date

public func isMutable(atDate date: Date = Date()) -> Bool {
switch pumpEvent {
case let bolus as BolusNormalPumpEvent:
// Square boluses
let deliveryFinishDate = self.date.addingTimeInterval(bolus.deliveryTime)
return deliveryFinishDate.compare(date) == .orderedDescending
default:
return false
}
}

public init(pumpEvent: PumpEvent, date: Date) {
self.pumpEvent = pumpEvent
self.date = date
}

public func isMutable(atDate date: Date = Date(), forPump model: PumpModel) -> Bool {
guard let bolus = self.pumpEvent as? BolusNormalPumpEvent else {
return false
}
let deliveryFinishDate = date.addingTimeInterval(bolus.deliveryTime)
return model.appendsSquareWaveToHistoryOnStartOfDelivery && bolus.type == .square && deliveryFinishDate > date
}
}


Expand Down
2 changes: 1 addition & 1 deletion MinimedKit/Messages/MySentryAckMessageBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public struct MySentryAckMessageBody: MessageBody {

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

return Data(bytes: buffer)
return Data(buffer)
}
}
4 changes: 2 additions & 2 deletions MinimedKit/Messages/MySentryPumpStatusMessageBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ public struct MySentryPumpStatusMessageBody: MessageBody, DictionaryRepresentabl
let batteryRemainingPercent: UInt8 = rxData[14]
self.batteryRemainingPercent = Int(round(Double(batteryRemainingPercent) / 4.0 * 100))

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

glucose = SensorReading(glucose: glucoseValue)
previousGlucose = SensorReading(glucose: previousGlucoseValue)
Expand Down
4 changes: 2 additions & 2 deletions MinimedKit/Messages/PumpMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public struct PumpMessage : CustomStringConvertible {
buffer.append(messageType.rawValue)
buffer.append(contentsOf: messageBody.txData)

return Data(bytes: buffer)
return Data(buffer)
}

public var description: String {
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))
return String(format: "PumpMessage(%1$@, %2$@, %3$@, %4$@)", String(describing: packetType), String(describing: messageType), address.hexadecimalString, self.messageBody.txData.hexadecimalString)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ReadCurrentGlucosePageMessageBody: CarelinkLongMessageBody {
}

self.pageNum = rxData[1..<5
].withUnsafeBytes { UInt32(bigEndian: $0.pointee) }
].toBigEndian(UInt32.self)
self.glucose = Int(rxData[6])
self.isig = Int(rxData[8])

Expand Down
Loading

0 comments on commit 5c43423

Please sign in to comment.