|
|
@@ -216,8 +216,8 @@ extension BLEManager: BluetoothDeviceDelegate {
|
|
|
|
|
|
extension BLEManager {
|
|
|
/// Returns the expected sensor fetch offset as a formatted string ("mm:ss (fetch delay: XX sec)")
|
|
|
- /// for Dexcom devices. The expected offset is computed as the sensor's schedule offset plus the polling delay.
|
|
|
- /// The device’s lastSeen time is used (mod 300) to calculate the effective delay between when the sensor value
|
|
|
+ /// for Dexcom and RileyLink devices. The expected offset is computed as the sensor's schedule offset plus the polling delay.
|
|
|
+ /// The device’s lastSeen time is used (mod cycleDuration) to calculate the effective delay between when the sensor value
|
|
|
/// becomes available and when the fetch is actually triggered.
|
|
|
func expectedSensorFetchOffsetString(for device: BLEDevice) -> String? {
|
|
|
// Determine the device type using your BackgroundRefreshType matching.
|
|
|
@@ -225,8 +225,8 @@ extension BLEManager {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
- // We only calculate this for Dexcom (G7) devices.
|
|
|
- if matchedType == .dexcom {
|
|
|
+ // We calculate this for Dexcom and RileyLink devices.
|
|
|
+ if matchedType == .dexcom || matchedType == .rileyLink {
|
|
|
// Return nil if the sensor schedule offset hasn't been set.
|
|
|
guard let sensorOffset = Storage.shared.sensorScheduleOffset.value else {
|
|
|
return nil
|
|
|
@@ -238,21 +238,25 @@ extension BLEManager {
|
|
|
// T_expected: the time (in seconds) after the sensor reading when the value is available.
|
|
|
let expectedOffset = sensorOffset + pollingDelay
|
|
|
|
|
|
- // Compute the device’s heartbeat offset within the 5-minute (300 sec) cycle.
|
|
|
+ // Determine the cycle duration based on the device type.
|
|
|
+ let cycleDuration: TimeInterval = (matchedType == .rileyLink) ? 60 : 300
|
|
|
+
|
|
|
+ // Compute the device’s heartbeat offset within the appropriate cycle.
|
|
|
let calendar = Calendar(identifier: .gregorian)
|
|
|
let startOfDay = calendar.startOfDay(for: device.lastSeen)
|
|
|
- let heartbeatOffset = device.lastSeen.timeIntervalSince(startOfDay).truncatingRemainder(dividingBy: 300)
|
|
|
+ let heartbeatOffset = device.lastSeen.timeIntervalSince(startOfDay).truncatingRemainder(dividingBy: cycleDuration)
|
|
|
|
|
|
// Calculate effective delay:
|
|
|
// If the heartbeat happens after the sensor value is available, delay = heartbeatOffset - expectedOffset.
|
|
|
// Otherwise, the fetch will occur on the next cycle:
|
|
|
- // delay = (heartbeatOffset + 300) - expectedOffset.
|
|
|
+ // delay = (heartbeatOffset + cycleDuration) - expectedOffset.
|
|
|
let effectiveDelay: TimeInterval = (heartbeatOffset >= expectedOffset)
|
|
|
? (heartbeatOffset - expectedOffset)
|
|
|
- : (heartbeatOffset + 300 - expectedOffset)
|
|
|
+ : (heartbeatOffset + cycleDuration - expectedOffset)
|
|
|
|
|
|
return "\(Int(effectiveDelay)) sec"
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
}
|
|
|
+
|