Skip to content

Commit

Permalink
update message shown to user for Bluetooth issues
Browse files Browse the repository at this point in the history
  • Loading branch information
marionbarker committed Apr 21, 2024
1 parent cb0c0c4 commit 35d5bcb
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions OmniBLE/PumpManager/PodCommsSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ extension PodCommsError: LocalizedError {
let faultDescription = String(describing: fault.faultEventCode)
return String(format: LocalizedString("Pod Fault: %1$@", comment: "Format string for pod fault code"), faultDescription)
case .commsError(let error):
if isVerboseBluetoothCommsError(error) {
return LocalizedString("Possible Bluetooth issue", comment: "Error description for possible bluetooth issue")
}
return error.localizedDescription
case .unacknowledgedMessage(_, let error):
return error.localizedDescription
Expand Down Expand Up @@ -136,7 +139,10 @@ extension PodCommsError: LocalizedError {
return LocalizedString("Resume delivery", comment: "Recovery suggestion when pod is suspended")
case .podFault:
return nil
case .commsError:
case .commsError(let error):
if isVerboseBluetoothCommsError(error) {
return LocalizedString("Try adjusting pod position or toggle Bluetooth off and then on in iPhone Settings.", comment: "Recovery suggestion for possible bluetooth issue")
}
return nil
case .unacknowledgedMessage:
return nil
Expand Down Expand Up @@ -173,6 +179,28 @@ extension PodCommsError: LocalizedError {
return false
}
}

public func isVerboseBluetoothCommsError(_ error: Error) -> Bool {
if let peripheralManagerError = error as? PeripheralManagerError {
switch peripheralManagerError {
case .cbPeripheralError:
print("### Verbose Bluetooth comms error: \(peripheralManagerError.localizedDescription)")
return true
default:
break
}
}
if let podProtocolError = error as? PodProtocolError {
switch podProtocolError {
case .invalidLTKKey, .pairingException, .messageIOException, .couldNotParseMessageException:
print("### Verbose Bluetooth comms error: \(podProtocolError.localizedDescription)")
return true
default:
break
}
}
return false
}
}

public protocol PodCommsSessionDelegate: AnyObject {
Expand Down Expand Up @@ -247,7 +275,9 @@ public class PodCommsSession {
/// - PodCommsError.unexpectedResponse
/// - PodCommsError.rejectedMessage
/// - PodCommsError.nonceResyncFailed
/// - MessageError
/// - PodCommsError.commsError.MessageError
/// - PodCommsError.commsError.PeripheralManagerError
/// - PodCommsError.commsError.PodProtocolError
func send<T: MessageBlock>(_ messageBlocks: [MessageBlock], beepBlock: MessageBlock? = nil, expectFollowOnMessage: Bool = false) throws -> T {

var triesRemaining = 2 // Retries only happen for nonce resync
Expand Down

0 comments on commit 35d5bcb

Please sign in to comment.