From 17aecd912aea647179242bebe44d8f3a2191dbbb Mon Sep 17 00:00:00 2001 From: jbr7rr <> Date: Thu, 22 Jun 2023 16:02:19 +0200 Subject: [PATCH] Remove SynchronizePacket from some operations to improve stability --- .../pump/medtrum/services/MedtrumService.kt | 25 ++++--------------- 1 file changed, 5 insertions(+), 20 deletions(-) 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 39c55b5cca..d39a59ed5a 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 @@ -174,8 +174,6 @@ class MedtrumService : DaggerService(), BLECommCallback { result = sendPacketAndGetResponse(CancelTempBasalPacket(injector)) } if (result) result = sendPacketAndGetResponse(StopPatchPacket(injector)) - // Synchronize after deactivation to get update status - if (result) result = sendPacketAndGetResponse(SynchronizePacket(injector)) return result } @@ -193,19 +191,16 @@ class MedtrumService : DaggerService(), BLECommCallback { } fun loadEvents(): Boolean { - // Send a poll patch, to workaround connection losses? rxBus.send(EventPumpStatusChanged(rh.gs(info.nightscout.pump.medtrum.R.string.gettingpumpstatus))) - var result = sendPacketAndGetResponse(PollPatchPacket(injector)) - // So just do a syncronize to make sure we have the latest data - if (result) result = sendPacketAndGetResponse(SynchronizePacket(injector)) - // Sync records (based on the info we have from the sync) - if (result) result = syncRecords() + val result = syncRecords() if (result) { aapsLogger.debug(LTag.PUMPCOMM, "Events loaded") medtrumPump.lastConnection = System.currentTimeMillis() } else { - aapsLogger.error(LTag.PUMPCOMM, "Failed to sync records") + aapsLogger.error(LTag.PUMPCOMM, "Failed to load events") + // TODO: remove me before release + fabricPrivacy.logMessage("Medtrum LoadEvents: Failed to load events") } return result } @@ -235,7 +230,6 @@ class MedtrumService : DaggerService(), BLECommCallback { } } } - } // Resume suspended pump if (medtrumPump.pumpState in listOf(MedtrumPumpState.LOWBG_SUSPENDED, MedtrumPumpState.PAUSED)) { @@ -293,12 +287,6 @@ class MedtrumService : DaggerService(), BLECommCallback { // Do not call update status directly, reconnection may be needed commandQueue.loadEvents(object : Callback() { override fun run() { - if (this.result.success == false && isConnected == false) { - // Reschedule loadEvents when we lost connection during the command - aapsLogger.warn(LTag.PUMP, "loadEvents failed due to connection loss, rescheduling") - commandQueue.loadEvents(this) - return - } rxBus.send(EventPumpStatusChanged(rh.gs(info.nightscout.pump.medtrum.R.string.gettingbolusstatus))) bolusingEvent.percent = 100 } @@ -366,11 +354,8 @@ class MedtrumService : DaggerService(), BLECommCallback { // Note: medtrum app fetches all records when they sync? if (medtrumPump.syncedSequenceNumber < medtrumPump.currentSequenceNumber) { for (sequence in (medtrumPump.syncedSequenceNumber + 1)..medtrumPump.currentSequenceNumber) { - // Send a poll patch, to workaround connection losses? - result = sendPacketAndGetResponse(PollPatchPacket(injector)) + result = sendPacketAndGetResponse(GetRecordPacket(injector, sequence), COMMAND_SYNC_TIMEOUT_SEC) SystemClock.sleep(100) - // Get our record - if (result) result = sendPacketAndGetResponse(GetRecordPacket(injector, sequence), COMMAND_SYNC_TIMEOUT_SEC) if (result == false) break } }