-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #405 from ps2/dev
Release 2.0.2
- Loading branch information
Showing
42 changed files
with
555 additions
and
85 deletions.
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
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,27 @@ | ||
// | ||
// ChangeMaxBasalRateMessageBody.swift | ||
// MinimedKit | ||
// | ||
// Copyright © 2018 Pete Schwamb. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
public class ChangeMaxBasalRateMessageBody: CarelinkLongMessageBody { | ||
|
||
static let multiplier: Double = 40 | ||
|
||
public convenience init?(maxBasalUnitsPerHour: Double) { | ||
guard maxBasalUnitsPerHour >= 0 && maxBasalUnitsPerHour <= 35 else { | ||
return nil | ||
} | ||
|
||
let ticks = UInt16(maxBasalUnitsPerHour * type(of: self).multiplier) | ||
var data = Data(bytes: [UInt8(clamping: ticks.bitWidth / 8)]) | ||
data.appendBigEndian(ticks) | ||
|
||
self.init(rxData: data) | ||
} | ||
|
||
} |
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 @@ | ||
// | ||
// ChangeMaxBolusMessageBody.swift | ||
// MinimedKit | ||
// | ||
// Copyright © 2018 Pete Schwamb. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
public class ChangeMaxBolusMessageBody: CarelinkLongMessageBody { | ||
|
||
static let multiplier: Double = 10 | ||
|
||
public convenience init?(maxBolusUnits: Double) { | ||
guard maxBolusUnits >= 0 && maxBolusUnits <= 25 else { | ||
return nil | ||
} | ||
|
||
let ticks = UInt8(maxBolusUnits * type(of: self).multiplier) | ||
var data = Data(bytes: [UInt8(clamping: ticks.bitWidth / 8)]) | ||
data.appendBigEndian(ticks) | ||
|
||
self.init(rxData: data) | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
MinimedKit/Messages/ChangeRemoteControlIDMessageBody.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,30 @@ | ||
// | ||
// ChangeRemoteControlIDMessageBody.swift | ||
// MinimedKit | ||
// | ||
// Copyright © 2018 Pete Schwamb. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
public class ChangeRemoteControlIDMessageBody: CarelinkLongMessageBody { | ||
public convenience init?(id: Data? = nil, index: Int) { | ||
guard index < 3 else { | ||
return nil | ||
} | ||
|
||
var rxData = Data(repeating: 0x2d, count: 8) // 2d signifies a deletion | ||
rxData[0] = 0x07 // length | ||
rxData[1] = UInt8(clamping: index) | ||
|
||
if let id = id { | ||
for (index, byte) in id.enumerated() { | ||
rxData[2 + index] = 0b00110000 + byte | ||
} | ||
} | ||
|
||
self.init(rxData: rxData) | ||
} | ||
|
||
} |
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,44 @@ | ||
// | ||
// ReadRemoteControlIDsMessageBody.swift | ||
// MinimedKit | ||
// | ||
// Copyright © 2018 Pete Schwamb. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
private let idSize = 6 | ||
|
||
public class ReadRemoteControlIDsMessageBody: CarelinkLongMessageBody { | ||
public let ids: [Data] | ||
|
||
public required init?(rxData: Data) { | ||
guard rxData.count == type(of: self).length else { | ||
return nil | ||
} | ||
|
||
var ids: [Data] = [] | ||
|
||
remotes: for index in stride(from: 0, to: 3, by: 1) { | ||
let start = (index * idSize + 1) | ||
let end = start + idSize | ||
|
||
var remoteID = Data(capacity: idSize) | ||
|
||
for byte in rxData[start..<end] { | ||
let isEnabled = (byte & 0b00010000) == 0b00010000 | ||
guard isEnabled else { | ||
continue remotes | ||
} | ||
|
||
remoteID.append(byte & 0xf) | ||
} | ||
|
||
ids.append(remoteID) | ||
} | ||
|
||
self.ids = ids | ||
|
||
super.init(rxData: rxData) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
MinimedKit/Messages/SetRemoteControlEnabledMessageBody.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 @@ | ||
// | ||
// SetRemoteControlEnabledMessageBody.swift | ||
// MinimedKit | ||
// | ||
// Copyright © 2018 Pete Schwamb. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
public class SetRemoteControlEnabledMessageBody: CarelinkLongMessageBody { | ||
public convenience init(enabled: Bool) { | ||
self.init(rxData: Data(bytes: [1, enabled ? 1 : 0]))! | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
MinimedKitTests/Messages/ChangeMaxBasalRateMessageBodyTests.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,36 @@ | ||
// | ||
// ChangeMaxBasalRateMessageBodyTests.swift | ||
// MinimedKitTests | ||
// | ||
// Copyright © 2018 Pete Schwamb. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import MinimedKit | ||
|
||
class ChangeMaxBasalRateMessageBodyTests: XCTestCase { | ||
|
||
func testMaxBasalRate() { | ||
var body = ChangeMaxBasalRateMessageBody(maxBasalUnitsPerHour: 6.4)! | ||
|
||
XCTAssertEqual(Data(hexadecimalString: "0201000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")!, body.txData, body.txData.hexadecimalString) | ||
|
||
body = ChangeMaxBasalRateMessageBody(maxBasalUnitsPerHour: 4.0)! | ||
|
||
XCTAssertEqual(Data(hexadecimalString: "0200A00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")!, body.txData, body.txData.hexadecimalString) | ||
} | ||
|
||
func testMaxBasalRateRounded() { | ||
let body = ChangeMaxBasalRateMessageBody(maxBasalUnitsPerHour: 9.115)! | ||
|
||
XCTAssertEqual(Data(hexadecimalString: "02016c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")!, body.txData, body.txData.hexadecimalString) | ||
|
||
|
||
} | ||
|
||
func testMaxBasalRateOutOfRange() { | ||
XCTAssertNil(ChangeMaxBasalRateMessageBody(maxBasalUnitsPerHour: -1)) | ||
XCTAssertNil(ChangeMaxBasalRateMessageBody(maxBasalUnitsPerHour: 36)) | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
MinimedKitTests/Messages/ChangeMaxBolusMessageBodyTests.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,30 @@ | ||
// | ||
// ChangeMaxBolusMessageBodyTests.swift | ||
// MinimedKitTests | ||
// | ||
// Copyright © 2018 Pete Schwamb. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import MinimedKit | ||
|
||
class ChangeMaxBolusMessageBodyTests: XCTestCase { | ||
|
||
func testMaxBolus() { | ||
let body = ChangeMaxBolusMessageBody(maxBolusUnits: 6.4)! | ||
|
||
XCTAssertEqual(Data(hexadecimalString: "0140000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")!, body.txData, body.txData.hexadecimalString) | ||
} | ||
|
||
func testMaxBolusRounded() { | ||
let body = ChangeMaxBolusMessageBody(maxBolusUnits: 2.25)! | ||
|
||
XCTAssertEqual(Data(hexadecimalString: "0116000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")!, body.txData, body.txData.hexadecimalString) | ||
} | ||
|
||
func testMaxBolusOutOfRange() { | ||
XCTAssertNil(ChangeMaxBolusMessageBody(maxBolusUnits: -1)) | ||
XCTAssertNil(ChangeMaxBolusMessageBody(maxBolusUnits: 26)) | ||
} | ||
|
||
} |
Oops, something went wrong.