Skip to content
Closed
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 @@ -83,6 +83,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 backfill data buffer
private var backfillBuffer: [G7BackfillMessage] = []
Expand Down Expand Up @@ -232,12 +234,13 @@ public final class G7Sensor: G7BluetoothManagerDelegate {
let suspectedEndOfSession: Bool

self.log.info("Sensor disconnected: wasRemoteDisconnect:%{public}@", String(describing: wasRemoteDisconnect))
if pendingAuth, wasRemoteDisconnect {
if pendingAuth, wasRemoteDisconnect, !controlResponseOnCurrentLink {
suspectedEndOfSession = true // Normal disconnect without auth is likely that G7 app stopped this session
} else {
suspectedEndOfSession = false
}
pendingAuth = false
controlResponseOnCurrentLink = false

delegateQueue.async {
self.delegate?.sensorDisconnected(self, suspectedEndOfSession: suspectedEndOfSession)
Expand Down Expand Up @@ -270,6 +273,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)

Expand Down