Skip to content

Unacknowledged command handling#16

Merged
ps2 merged 5 commits into
devfrom
unacknowledged-commands
Feb 17, 2022
Merged

Unacknowledged command handling#16
ps2 merged 5 commits into
devfrom
unacknowledged-commands

Conversation

@ps2
Copy link
Copy Markdown

@ps2 ps2 commented Feb 13, 2022

This PR implements the OmniBLE portions of the unacknowledged command handling system in Loop dev.

Upon any failure where Loop has both sent an insulin delivery affecting command, and not heard back whether the pod received it, Loop will be in a mode of uncertain delivery. Loop will not dose further in this mode until communications are restored, and Loop has determined if the pod heard the previous message.

It does this by recording the message sequence number of the last sent command, and checking the last command sequence field that is returned in status responses from the pod when comms are restored. If they match, then Loop knows the pod received the command, and will update its state to match. If the sequence does not match, then Loop will consider the command to not have been received by the pod, and Loop state will remain as if the command were not issued.

This all happens automatically; there are some visual screens to let the user know what's going on in this mode, but it's possible that the problem will arise and be resolved without any user action. This is what should happen in most cases, and is a big improvement over previous handling, where we just marked these commands as uncertain.

If communications cannot be restored, the user can use the onscreen modal to deactivate/discard the pod. In this case Loop will resolve the unacknowledged commands in a way that assumes the greatest amount of insulin delivery, to err in the direction of hyperglycemia instead of hypoglycemia. For example, an uncertain bolus will be assumed to have been successful, while a suspend will be assumed to have failed.

}

struct MessageSendSuccess: MessageResult {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to see the MessageResult protocol, the MessageSendFailure, and the MessageSendSuccess structs go away. I had prototyped a simpler way to do this using no return type for sendMessage() which throws on errors, but this won't be needed with this approach using a SendMessageResult return.

}

if let isLowTemp = rawValue["isLowTemp"] as? Bool {
self.isHighTemp = isLowTemp
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this odd looking code is correct, a comment would be helpful.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thanks; refactoring error.

"scheduledCertainty": scheduledCertainty.rawValue,
"automatic": automatic
"automatic": automatic,
"isLowTemp": isHighTemp,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto. Not sure if is a mistake or being done on purpose.

throw IllegalResponseException(responseType, response)
}
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that there was some special stuff added added to Dash messaging for dealing with alerts at a higher level that this commented out code that is being deleted is referencing. Has this new Dash alert system been investigated at all?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you're referring to, or what this code was doing. If you have any clues, let me know.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this again, this commented out code is taken from the Kotlin code here: https://github.com/nightscout/AndroidAPS/blob/master/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Session.kt. This used to be the place in AAPS where they were checking for an unexpected fault (alarm) response or a nak response from the pod. This checking has since apparently moved elsewhere for AAPS. For Loop this handling is handled at the next level up in PodCommSessions.send() as it was for Eros. So there is no problem removing this commented out code which isn't helpful or useful (and I agree that it would be good to do).

The special stuff for dealing with alerts that I had originally thought might be related was something completely different that I looked like was for dealing with the 8 pod alerts & the reminder beeps at a different level from what I remembered from some time back now. When I did some quick searches in the AAPS code, I couldn't find anything that looked like what I remember. This might have been something I saw in the decompiled PDM source which I can no longer find online. In any case, what I am remembering has nothing to do with this particular code being deleted.


import Foundation
import LoopKit
import OmniKit
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this import be avoided? I am hoping that eventually all the code in OmniBLE/OmnipodCommon can be made into a separate Framework that can be shared between OmniKit and OmniBLE. With some more work, it might be possible to share even more code between OmniKit and OmniBLE.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

@ps2 ps2 merged commit b29d453 into dev Feb 17, 2022
@ps2 ps2 deleted the unacknowledged-commands branch April 11, 2022 15:48
loopkitdev pushed a commit to loopkitdev/OmniBLE that referenced this pull request Mar 12, 2026
loopkitdev pushed a commit to loopkitdev/OmniBLE that referenced this pull request Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants