Skip to content
Merged
Changes from all 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: 5 additions & 1 deletion G7SensorKit/G7CGMManager/G7Sensor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ public final class G7Sensor: G7BluetoothManagerDelegate {

/// Used to detect connections that do not authenticate, signalling possible sensor switchover
private var pendingAuth: Bool = false
/// The sensor answers on control only within an authenticated session.
private var controlResponseOnCurrentLink = false
/// The last fresh pairing ended without the sensor confirming its Bluetooth bond.
private var lastPairingBondUnconfirmed = false

Expand Down Expand Up @@ -759,12 +761,13 @@ public final class G7Sensor: G7BluetoothManagerDelegate {
// In direct mode we authenticate ourselves and the sensor drops the
// link at the end of every reading cycle, so this would fire
// constantly; session end is read from the algorithm state instead.
if mode == .eavesdropping, pendingAuth, wasRemoteDisconnect {
if mode == .eavesdropping, pendingAuth, wasRemoteDisconnect, !controlResponseOnCurrentLink {
suspectedEndOfSession = true // Normal disconnect without auth is likely that G7 app stopped this session
} else {
suspectedEndOfSession = false
}
pendingAuth = false
controlResponseOnCurrentLink = false
backfillRequestPending = false

delegateQueue.async {
Expand Down Expand Up @@ -865,6 +868,7 @@ public final class G7Sensor: G7BluetoothManagerDelegate {
func bluetoothManager(_ manager: G7BluetoothManager, peripheralManager: G7PeripheralManager, didReceiveControlResponse response: Data) {

guard response.count > 0 else { return }
controlResponseOnCurrentLink = true

log.default("Received control response: %{public}@", response.hexadecimalString)
delegateQueue.async {
Expand Down