chore(BLE): move connect/duty/announce constants to TransportConfig and reference them

This commit is contained in:
jack
2025-08-25 18:59:47 +02:00
parent 3a8cf4d37f
commit f5a2a1e29a
2 changed files with 12 additions and 6 deletions
+5 -5
View File
@@ -70,7 +70,7 @@ final class BLEService: NSObject {
// Simple announce throttling // Simple announce throttling
private var lastAnnounceSent = Date.distantPast private var lastAnnounceSent = Date.distantPast
private let announceMinInterval: TimeInterval = 1.0 private let announceMinInterval: TimeInterval = TransportConfig.bleAnnounceMinInterval
// Application state tracking (thread-safe) // Application state tracking (thread-safe)
#if os(iOS) #if os(iOS)
@@ -129,8 +129,8 @@ final class BLEService: NSObject {
private var maintenanceCounter = 0 // Track maintenance cycles private var maintenanceCounter = 0 // Track maintenance cycles
// MARK: - Connection budget & scheduling (central role) // MARK: - Connection budget & scheduling (central role)
private let maxCentralLinks = 6 private let maxCentralLinks = TransportConfig.bleMaxCentralLinks
private let connectRateLimitInterval: TimeInterval = 0.5 private let connectRateLimitInterval: TimeInterval = TransportConfig.bleConnectRateLimitInterval
private var lastGlobalConnectAttempt: Date = .distantPast private var lastGlobalConnectAttempt: Date = .distantPast
private struct ConnectionCandidate { private struct ConnectionCandidate {
let peripheral: CBPeripheral let peripheral: CBPeripheral
@@ -147,8 +147,8 @@ final class BLEService: NSObject {
// MARK: - Adaptive scanning duty-cycle // MARK: - Adaptive scanning duty-cycle
private var scanDutyTimer: DispatchSourceTimer? private var scanDutyTimer: DispatchSourceTimer?
private var dutyEnabled: Bool = true private var dutyEnabled: Bool = true
private var dutyOnDuration: TimeInterval = 5 private var dutyOnDuration: TimeInterval = TransportConfig.bleDutyOnDuration
private var dutyOffDuration: TimeInterval = 10 private var dutyOffDuration: TimeInterval = TransportConfig.bleDutyOffDuration
private var dutyActive: Bool = false private var dutyActive: Bool = false
// MARK: - Link capability snapshots (thread-safe via bleQueue) // MARK: - Link capability snapshots (thread-safe via bleQueue)
+7 -1
View File
@@ -18,5 +18,11 @@ enum TransportConfig {
// Timers // Timers
static let networkResetGraceSeconds: TimeInterval = 600 // 10 minutes static let networkResetGraceSeconds: TimeInterval = 600 // 10 minutes
static let basePublicFlushInterval: TimeInterval = 0.08 // ~12.5 fps batching static let basePublicFlushInterval: TimeInterval = 0.08 // ~12.5 fps batching
}
// BLE duty/announce/connect
static let bleConnectRateLimitInterval: TimeInterval = 0.5
static let bleMaxCentralLinks: Int = 6
static let bleDutyOnDuration: TimeInterval = 5.0
static let bleDutyOffDuration: TimeInterval = 10.0
static let bleAnnounceMinInterval: TimeInterval = 1.0
}