Dana: cleanup

This commit is contained in:
Milos Kozak 2022-12-11 21:36:30 +01:00
parent 3bb7c331d7
commit 0da75f1d69
6 changed files with 13 additions and 23 deletions

View file

@ -55,7 +55,7 @@ class DanaPump @Inject constructor(
var lastConnection: Long = 0 var lastConnection: Long = 0
var lastSettingsRead: Long = 0 var lastSettingsRead: Long = 0
@JvmField var lastHistoryFetched: Long = 0 @JvmField var readHistoryFrom: Long = 0 // start next history read from this timestamp
@JvmField var historyDoneReceived: Boolean = false // true when last history message is received @JvmField var historyDoneReceived: Boolean = false // true when last history message is received
// Info // Info
@ -410,7 +410,7 @@ class DanaPump @Inject constructor(
aapsLogger.debug(LTag.PUMP, "DanaRPump reset") aapsLogger.debug(LTag.PUMP, "DanaRPump reset")
lastConnection = 0 lastConnection = 0
lastSettingsRead = 0 lastSettingsRead = 0
lastHistoryFetched = 0 readHistoryFrom = 0
} }
fun modelFriendlyName(): String = fun modelFriendlyName(): String =

View file

@ -57,8 +57,6 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
private final TemporaryBasalStorage temporaryBasalStorage; private final TemporaryBasalStorage temporaryBasalStorage;
private final FabricPrivacy fabricPrivacy; private final FabricPrivacy fabricPrivacy;
public long lastEventTimeLoaded = 0;
@Inject @Inject
public DanaRv2Plugin( public DanaRv2Plugin(
HasAndroidInjector injector, HasAndroidInjector injector,

View file

@ -277,7 +277,7 @@ class MsgHistoryEventsV2 constructor(
status = "UNKNOWN " + dateUtil.timeString(datetime) status = "UNKNOWN " + dateUtil.timeString(datetime)
} }
} }
if (datetime > danaRv2Plugin.lastEventTimeLoaded) danaRv2Plugin.lastEventTimeLoaded = datetime if (datetime > danaPump.lastEventTimeLoaded) danaPump.lastEventTimeLoaded = datetime
rxBus.send(EventPumpStatusChanged(rh.gs(info.nightscout.pump.dana.R.string.processinghistory) + ": " + status)) rxBus.send(EventPumpStatusChanged(rh.gs(info.nightscout.pump.dana.R.string.processinghistory) + ": " + status))
} }
} }

View file

@ -346,7 +346,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
MsgSetHistoryEntry_v2 msgSetHistoryEntry_v2 = new MsgSetHistoryEntry_v2(injector, MsgSetHistoryEntry_v2 msgSetHistoryEntry_v2 = new MsgSetHistoryEntry_v2(injector,
DanaPump.HistoryEntry.CARBS.getValue(), carbtime, carbs, 0); DanaPump.HistoryEntry.CARBS.getValue(), carbtime, carbs, 0);
mSerialIOThread.sendMessage(msgSetHistoryEntry_v2); mSerialIOThread.sendMessage(msgSetHistoryEntry_v2);
danaPump.lastHistoryFetched = Math.min(danaPump.lastHistoryFetched, carbtime - T.Companion.mins(1).msecs()); danaPump.readHistoryFrom = Math.min(danaPump.readHistoryFrom, carbtime - T.Companion.mins(1).msecs());
if (!msgSetHistoryEntry_v2.isReceived() || msgSetHistoryEntry_v2.getFailed()) if (!msgSetHistoryEntry_v2.isReceived() || msgSetHistoryEntry_v2.getFailed())
uiInteraction.runAlarm(rh.gs(info.nightscout.pump.dana.R.string.carbs_store_error), rh.gs(info.nightscout.core.ui.R.string.error), info.nightscout.core.ui.R.raw.boluserror); uiInteraction.runAlarm(rh.gs(info.nightscout.pump.dana.R.string.carbs_store_error), rh.gs(info.nightscout.core.ui.R.string.error), info.nightscout.core.ui.R.raw.boluserror);
} }
@ -418,7 +418,7 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
MsgSetHistoryEntry_v2 msgSetHistoryEntry_v2 = new MsgSetHistoryEntry_v2(injector, MsgSetHistoryEntry_v2 msgSetHistoryEntry_v2 = new MsgSetHistoryEntry_v2(injector,
DanaPump.HistoryEntry.CARBS.getValue(), time, amount, 0); DanaPump.HistoryEntry.CARBS.getValue(), time, amount, 0);
mSerialIOThread.sendMessage(msgSetHistoryEntry_v2); mSerialIOThread.sendMessage(msgSetHistoryEntry_v2);
danaPump.lastHistoryFetched = Math.min(danaPump.lastHistoryFetched, time - T.Companion.mins(1).msecs()); danaPump.readHistoryFrom = Math.min(danaPump.readHistoryFrom, time - T.Companion.mins(1).msecs());
return true; return true;
} }
@ -433,18 +433,17 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
if (!isConnected()) if (!isConnected())
return new PumpEnactResult(injector).success(false); return new PumpEnactResult(injector).success(false);
SystemClock.sleep(300); SystemClock.sleep(300);
MsgHistoryEventsV2 msg = new MsgHistoryEventsV2(injector, danaPump.lastHistoryFetched); MsgHistoryEventsV2 msg = new MsgHistoryEventsV2(injector, danaPump.readHistoryFrom);
aapsLogger.debug(LTag.PUMP, "Loading event history from: " + dateUtil.dateAndTimeString(danaPump.lastHistoryFetched)); aapsLogger.debug(LTag.PUMP, "Loading event history from: " + dateUtil.dateAndTimeString(danaPump.readHistoryFrom));
mSerialIOThread.sendMessage(msg); mSerialIOThread.sendMessage(msg);
while (!danaPump.historyDoneReceived && mRfcommSocket.isConnected()) { while (!danaPump.historyDoneReceived && mRfcommSocket.isConnected()) {
SystemClock.sleep(100); SystemClock.sleep(100);
} }
SystemClock.sleep(200); SystemClock.sleep(200);
if (danaRv2Plugin.lastEventTimeLoaded != 0) if (danaPump.getLastEventTimeLoaded() != 0) danaPump.readHistoryFrom = danaPump.getLastEventTimeLoaded() - T.Companion.mins(1).msecs();
danaPump.lastHistoryFetched = danaRv2Plugin.lastEventTimeLoaded - T.Companion.mins(1).msecs();
else else
danaPump.lastHistoryFetched = 0; danaPump.readHistoryFrom = 0;
danaPump.setLastConnection(System.currentTimeMillis()); danaPump.setLastConnection(System.currentTimeMillis());
return new PumpEnactResult(injector).success(true); return new PumpEnactResult(injector).success(true);
} }

View file

@ -262,19 +262,13 @@ class DanaRSService : DaggerService() {
return result return result
} }
SystemClock.sleep(1000) SystemClock.sleep(1000)
val msg: DanaRSPacketAPSHistoryEvents val msg = DanaRSPacketAPSHistoryEvents(injector, danaPump.readHistoryFrom)
if (danaPump.lastHistoryFetched == 0L) { aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + dateUtil.dateAndTimeString(danaPump.readHistoryFrom))
msg = DanaRSPacketAPSHistoryEvents(injector, 0)
aapsLogger.debug(LTag.PUMPCOMM, "Loading complete event history")
} else {
msg = DanaRSPacketAPSHistoryEvents(injector, danaPump.lastHistoryFetched)
aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + dateUtil.dateAndTimeString(danaPump.lastHistoryFetched))
}
sendMessage(msg) sendMessage(msg)
while (!danaPump.historyDoneReceived && bleComm.isConnected) { while (!danaPump.historyDoneReceived && bleComm.isConnected) {
SystemClock.sleep(100) SystemClock.sleep(100)
} }
danaPump.lastHistoryFetched = if (danaPump.lastEventTimeLoaded != 0L) danaPump.lastEventTimeLoaded - T.mins(1).msecs() else 0 danaPump.readHistoryFrom = if (danaPump.lastEventTimeLoaded != 0L) danaPump.lastEventTimeLoaded - T.mins(1).msecs() else 0
aapsLogger.debug(LTag.PUMPCOMM, "Events loaded") aapsLogger.debug(LTag.PUMPCOMM, "Events loaded")
rxBus.send(EventPumpStatusChanged(rh.gs(info.nightscout.pump.dana.R.string.gettingpumpstatus))) rxBus.send(EventPumpStatusChanged(rh.gs(info.nightscout.pump.dana.R.string.gettingpumpstatus)))
sendMessage(DanaRSPacketGeneralInitialScreenInformation(injector)) sendMessage(DanaRSPacketGeneralInitialScreenInformation(injector))
@ -305,7 +299,7 @@ class DanaRSService : DaggerService() {
// sendMessage(msg); // sendMessage(msg);
val msgSetHistoryEntryV2 = DanaRSPacketAPSSetEventHistory(injector, DanaPump.HistoryEntry.CARBS.value, carbTime, carbs, 0) val msgSetHistoryEntryV2 = DanaRSPacketAPSSetEventHistory(injector, DanaPump.HistoryEntry.CARBS.value, carbTime, carbs, 0)
sendMessage(msgSetHistoryEntryV2) sendMessage(msgSetHistoryEntryV2)
danaPump.lastHistoryFetched = min(danaPump.lastHistoryFetched, carbTime - T.mins(1).msecs()) danaPump.readHistoryFrom = min(danaPump.readHistoryFrom, carbTime - T.mins(1).msecs())
if (!msgSetHistoryEntryV2.isReceived || msgSetHistoryEntryV2.failed) if (!msgSetHistoryEntryV2.isReceived || msgSetHistoryEntryV2.failed)
uiInteraction.runAlarm(rh.gs(info.nightscout.pump.dana.R.string.carbs_store_error), rh.gs(info.nightscout.core.ui.R.string.error), info.nightscout.core.ui.R.raw.boluserror) uiInteraction.runAlarm(rh.gs(info.nightscout.pump.dana.R.string.carbs_store_error), rh.gs(info.nightscout.core.ui.R.string.error), info.nightscout.core.ui.R.raw.boluserror)
} }

View file

@ -9,7 +9,6 @@
<string name="patch_buzzer_reminders">패치 버저 알림</string> <string name="patch_buzzer_reminders">패치 버저 알림</string>
<string name="time_format_a_h_mm">h:mm a</string> <string name="time_format_a_h_mm">h:mm a</string>
<string name="bolusdelivered">볼루스 %1$.2f U의 주입이 완료되었습니다.</string>
<string name="eopatch_ble_status">BLE 상태</string> <string name="eopatch_ble_status">BLE 상태</string>
<string name="eopatch_serial_number">일련 번호</string> <string name="eopatch_serial_number">일련 번호</string>
<string name="eopatch_lot_number">로트 번호</string> <string name="eopatch_lot_number">로트 번호</string>