payfrit-beacon-ios/PayfritBeacon/Provisioners/ProvisionerProtocol.swift
Schwifty c243235237 fix: connection callback bug + add provisioning diagnostics
BIG FIX: Provisioners were calling centralManager.connect() but
BLEManager is the CBCentralManagerDelegate — provisioners never
received didConnect/didFailToConnect callbacks, so connections
ALWAYS timed out after 5s regardless. This is why provisioning
kept failing. Fixed by:
1. Adding didConnect/didFailToConnect/didDisconnect to BLEManager
2. Provisioners register connection callbacks via bleManager
3. Increased connection timeout from 5s to 10s

DIAGNOSTICS: Added ProvisionLog system so failures show a timestamped
step-by-step log of what happened (with Share button). Every phase
is logged: init, API calls, connect attempts, service discovery,
auth, write commands, and errors.
2026-03-22 23:12:06 +00:00

46 lines
1.7 KiB
Swift

import Foundation
import CoreBluetooth
/// Common protocol for all beacon provisioners
protocol BeaconProvisioner {
/// Connect to the beacon and authenticate
func connect() async throws
/// Write the full beacon configuration
func writeConfig(_ config: BeaconConfig) async throws
/// Disconnect from the beacon
func disconnect()
/// Whether we're currently connected
var isConnected: Bool { get }
/// Optional diagnostic log for tracing provisioning steps
var diagnosticLog: ProvisionLog? { get set }
/// BLE manager reference for connection callbacks
var bleManager: BLEManager? { get set }
}
/// GATT UUIDs shared across provisioner types
enum GATTConstants {
// FFE0 service (KBeacon, DXSmart)
static let ffe0Service = CBUUID(string: "0000FFE0-0000-1000-8000-00805F9B34FB")
static let ffe1Char = CBUUID(string: "0000FFE1-0000-1000-8000-00805F9B34FB")
static let ffe2Char = CBUUID(string: "0000FFE2-0000-1000-8000-00805F9B34FB")
static let ffe3Char = CBUUID(string: "0000FFE3-0000-1000-8000-00805F9B34FB")
// FFF0 service (BlueCharm)
static let fff0Service = CBUUID(string: "0000FFF0-0000-1000-8000-00805F9B34FB")
static let fea0Service = CBUUID(string: "0000FEA0-0000-1000-8000-00805F9B34FB")
// CCCD for enabling notifications
static let cccd = CBUUID(string: "00002902-0000-1000-8000-00805F9B34FB")
// Timeouts (matching Android)
static let connectionTimeout: TimeInterval = 10.0 // Increased from 5s BLE connections can be slow
static let operationTimeout: TimeInterval = 5.0
static let maxRetries = 3
static let retryDelay: TimeInterval = 1.0
static let postFlashDelay: TimeInterval = 3.0
}