-
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.
Add messages for checking MySentry pairing status (#394)
- Loading branch information
Showing
12 changed files
with
208 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// ReadOtherDevicesIDsMessageBody.swift | ||
// MinimedKit | ||
// | ||
// Copyright © 2018 Pete Schwamb. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
public class ReadOtherDevicesIDsMessageBody: CarelinkLongMessageBody { | ||
|
||
let ids: [Data] | ||
|
||
public required init?(rxData: Data) { | ||
guard rxData.count == type(of: self).length else { | ||
return nil | ||
} | ||
|
||
let count = Int(rxData[1]) | ||
|
||
var ids: [Data] = [] | ||
|
||
for index in stride(from: 0, to: count, by: 1) { | ||
let start = (index * 5 + 3) | ||
let end = start + 4 | ||
|
||
ids.append(rxData.subdata(in: start..<end)) | ||
} | ||
|
||
self.ids = ids | ||
|
||
super.init(rxData: rxData) | ||
} | ||
} | ||
|
||
|
||
// Body[1] is the count Body[3..<7] is the first ID. | ||
// 1f0101 a2105728 00 00000636 036f0040600107062f1dfc004020c107062f0e77000000000000000000000000000000000000000000000000000000000000000000 | ||
// 1f0201 a2105728 00 a2016016 036f0040600107062f1dfc004020c107062f0e77000000000000000000000000000000000000000000000000000000000000000000 |
26 changes: 26 additions & 0 deletions
26
MinimedKit/Messages/ReadOtherDevicesStatusMessageBody.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,26 @@ | ||
// | ||
// ReadOtherDevicesStatusMessageBody.swift | ||
// MinimedKit | ||
// | ||
// Copyright © 2018 Pete Schwamb. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public class ReadOtherDevicesStatusMessageBody: CarelinkLongMessageBody { | ||
public let isEnabled: Bool | ||
|
||
public required init?(rxData: Data) { | ||
guard rxData.count == type(of: self).length else { | ||
return nil | ||
} | ||
|
||
isEnabled = rxData[1] == 1 | ||
|
||
super.init(rxData: rxData) | ||
} | ||
} | ||
|
||
// Body[1] encodes the bool state | ||
// 0200010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | ||
// 0201010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
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
37 changes: 37 additions & 0 deletions
37
MinimedKitTests/Messages/ReadOtherDevicesIDsMessageBodyTests.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,37 @@ | ||
// | ||
// ReadOtherDevicesIDsMessageBodyTests.swift | ||
// MinimedKitTests | ||
// | ||
// Copyright © 2018 Pete Schwamb. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import MinimedKit | ||
|
||
class ReadOtherDevicesIDsMessageBodyTests: XCTestCase { | ||
|
||
func test0IDs() { | ||
let message = PumpMessage(rxData: Data(hexadecimalString: "a7594040f01f0015036800406001070636036f0040600107062f1dfc004020c107062f0e77000000000000000000000000000000000000000000000000000000000000000000")!) | ||
let body = message?.messageBody as! ReadOtherDevicesIDsMessageBody | ||
|
||
XCTAssertEqual(0, body.ids.count) | ||
} | ||
|
||
func test1IDs() { | ||
let message = PumpMessage(rxData: Data(hexadecimalString: "a7594040f01f0101a21057280000000636036f0040600107062f1dfc004020c107062f0e77000000000000000000000000000000000000000000000000000000000000000000")!) | ||
let body = message?.messageBody as! ReadOtherDevicesIDsMessageBody | ||
|
||
XCTAssertEqual(1, body.ids.count) | ||
XCTAssertEqual("a2105728", body.ids[0].hexadecimalString) | ||
} | ||
|
||
func test2IDs() { | ||
let message = PumpMessage(rxData: Data(hexadecimalString: "a7594040f01f0201a210572800a2016016036f0040600107062f1dfc004020c107062f0e77000000000000000000000000000000000000000000000000000000000000000000")!) | ||
let body = message?.messageBody as! ReadOtherDevicesIDsMessageBody | ||
|
||
XCTAssertEqual(2, body.ids.count) | ||
XCTAssertEqual("a2105728", body.ids[0].hexadecimalString) | ||
XCTAssertEqual("a2016016", body.ids[1].hexadecimalString) | ||
} | ||
|
||
} |
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
Oops, something went wrong.