Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use alternate type 7 getStatus call as per DASH PDM #138

Merged
merged 3 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions OmniBLE/OmnipodCommon/MessageBlocks/PodInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public enum PodInfoResponseSubType: UInt8, Equatable {
case detailedStatus = 0x02 // Returns detailed pod status, returned for most calls after a pod fault
case pulseLogPlus = 0x03 // Returns up to the last 60 pulse log entries plus additional info
case activationTime = 0x05 // Returns pod activation time and possible fault code & fault time
case noSeqStatusResponse = 0x07 // DASH only, returns the normal status response w/o incrementing msg seq #
case noSeqStatus = 0x07 // DASH only, returns the normal status response w/o incrementing msg seq #
case pulseLogRecent = 0x50 // Returns the last 50 pulse log entries
case pulseLogPrevious = 0x51 // Like 0x50, but returns up to the previous 50 entries before the last 50

public var podInfoType: PodInfo.Type {
switch self {
case .normal:
case .normal, .noSeqStatus: // noSeqStatus won't increment the message seq # from the last response
return StatusResponse.self as! PodInfo.Type
case .triggeredAlerts:
return PodInfoTriggeredAlerts.self
Expand All @@ -38,8 +38,6 @@ public enum PodInfoResponseSubType: UInt8, Equatable {
return PodInfoPulseLogPlus.self
case .activationTime:
return PodInfoActivationTime.self
case .noSeqStatusResponse:
return StatusResponse.self as! PodInfo.Type
case .pulseLogRecent:
return PodInfoPulseLogRecent.self
case .pulseLogPrevious:
Expand Down
6 changes: 3 additions & 3 deletions OmniBLE/PumpManager/OmniBLEPumpManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ extension OmniBLEPumpManager {
podComms.runSession(withName: "Resuming pod setup") { (result) in
switch result {
case .success(let session):
let status = try? session.getStatus()
let status = try? session.getStatus(noSeqGetStatus: true)
if status == nil {
self.log.debug("### Pod setup resume getStatus failed, sleeping %d seconds", sleepTime)
sleep(sleepTime)
Expand All @@ -1062,7 +1062,7 @@ extension OmniBLEPumpManager {
do {
switch result {
case .success(let session):
let status = try session.getStatus()
let status = try session.getStatus(noSeqGetStatus: true)
session.dosesForStorage({ (doses) -> Bool in
self.store(doses: doses, in: session)
})
Expand Down Expand Up @@ -2443,7 +2443,7 @@ extension OmniBLEPumpManager: PodCommsDelegate {
podComms.runSession(withName: "Post-connect status fetch") { result in
switch result {
case .success(let session):
let _ = try? session.getStatus()
let _ = try? session.getStatus(noSeqGetStatus: true)
self.silenceAcknowledgedAlerts()
session.dosesForStorage() { (doses) -> Bool in
return self.store(doses: doses, in: session)
Expand Down
17 changes: 13 additions & 4 deletions OmniBLE/PumpManager/PodCommsSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,17 @@ public class PodCommsSession {
// if blocksToSend.contains(where: { $0 as? NonceResyncableMessageBlock != nil }) {
// podState.advanceToNextNonce()
// }

let messageNumber = transport.messageNumber

var sentNonce: UInt32?
var messageNumber = transport.messageNumber
if let getStatusCommand = messageBlocks[0] as? GetStatusCommand,
getStatusCommand.podInfoType == .noSeqStatus
{
// For the special type 7 DASH noSeqStatus getStatus command,
// back up the Omnipod msg # here to its previous value so that
// this message will have same msg # the last received response.
messageNumber = messageNumber == 0 ? 0b1111 : messageNumber - 1
}

while (triesRemaining > 0) {
triesRemaining -= 1
Expand Down Expand Up @@ -865,8 +872,10 @@ public class PodCommsSession {

// Throws PodCommsError
@discardableResult
public func getStatus(beepBlock: MessageBlock? = nil) throws -> StatusResponse {
let statusResponse: StatusResponse = try send([GetStatusCommand()], beepBlock: beepBlock)
public func getStatus(noSeqGetStatus: Bool = false, beepBlock: MessageBlock? = nil) throws -> StatusResponse {
// For noSeqSetStatus, use an alternative DASH noSeqStatus (type 7) request instead of a normal (type 0) request
let statusType: PodInfoResponseSubType = noSeqGetStatus ? .noSeqStatus : .normal
let statusResponse: StatusResponse = try send([GetStatusCommand(podInfoType: statusType)], beepBlock: beepBlock)

if podState.unacknowledgedCommand != nil {
recoverUnacknowledgedCommand(using: statusResponse)
Expand Down