Merge pull request #2999 from jbr7rr/medtrum-fixes

Medtrum: Skip record if it fails
This commit is contained in:
Milos Kozak 2023-10-29 19:04:53 +01:00 committed by GitHub
commit bb23841289
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 2 deletions

View file

@ -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

View file

@ -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

View file

@ -38,6 +38,7 @@
<string name="pump_is_suspended_day_max">Pump is suspended due to daily max insulin exceeded</string>
<string name="patch_not_active">Patch not activated</string>
<string name="pump_setting_failed">Setting user settings to pump failed!</string>
<string name="pump_sync_error">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.</string>
<!-- overview fragment -->
<string name="ble_status_label">BLE Status</string>