diff --git a/core/interfaces/src/main/kotlin/app/aaps/core/interfaces/notifications/Notification.kt b/core/interfaces/src/main/kotlin/app/aaps/core/interfaces/notifications/Notification.kt index f9eb549c7b..336b16afe5 100644 --- a/core/interfaces/src/main/kotlin/app/aaps/core/interfaces/notifications/Notification.kt +++ b/core/interfaces/src/main/kotlin/app/aaps/core/interfaces/notifications/Notification.kt @@ -139,6 +139,7 @@ open class Notification { const val PUMP_TIMEZONE_UPDATE_FAILED = 85 const val BLUETOOTH_NOT_SUPPORTED = 86 const val PUMP_WARNING = 87 + const val PUMP_SYNC_ERROR = 88 const val USER_MESSAGE = 1000 diff --git a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt index 887c4c1a95..4d9d52dd38 100644 --- a/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt +++ b/pump/medtrum/src/main/java/info/nightscout/pump/medtrum/services/MedtrumService.kt @@ -559,10 +559,30 @@ class MedtrumService : DaggerService(), BLECommCallback { private fun syncRecords(): Boolean { aapsLogger.debug(LTag.PUMP, "syncRecords: called!, syncedSequenceNumber: ${medtrumPump.syncedSequenceNumber}, currentSequenceNumber: ${medtrumPump.currentSequenceNumber}") var result = true + var failureCount = 0 if (medtrumPump.syncedSequenceNumber < medtrumPump.currentSequenceNumber) { for (sequence in (medtrumPump.syncedSequenceNumber + 1)..medtrumPump.currentSequenceNumber) { - result = sendPacketAndGetResponse(GetRecordPacket(injector, sequence), COMMAND_SYNC_TIMEOUT_SEC) - if (!result) break + val packet = GetRecordPacket(injector, sequence) + result = sendPacketAndGetResponse(packet, COMMAND_SYNC_TIMEOUT_SEC) + if (!result && packet.failed) { + // Record may be broken for unkown reasons, try the next packet if that fails abort + failureCount++ + aapsLogger.error(LTag.PUMPCOMM, "Failed to sync record $sequence, failureCount: $failureCount") + if (failureCount == 1) { + // Show notification to alert user of failure + uiInteraction.addNotificationWithSound( + Notification.PUMP_SYNC_ERROR, + rh.gs(R.string.pump_sync_error), + Notification.URGENT, + app.aaps.core.ui.R.raw.alarm + ) + } else if (failureCount >= 2) { + break + } + } else if (!result) { + // Communication timeout, try again + break + } } } return result diff --git a/pump/medtrum/src/main/res/values/strings.xml b/pump/medtrum/src/main/res/values/strings.xml index f2a283e42f..10e4496dc8 100644 --- a/pump/medtrum/src/main/res/values/strings.xml +++ b/pump/medtrum/src/main/res/values/strings.xml @@ -38,6 +38,7 @@ Pump is suspended due to daily max insulin exceeded Patch not activated Setting user settings to pump failed! + Error while syncing history from pump, a record has been skipped. Check treatment tab to check if bolus is synced correctly. Snooze and if error keep coming back change patch or pumpbase. BLE Status