RS: better handle error state

This commit is contained in:
Milos Kozak 2020-11-07 12:30:39 +01:00
parent 9e5da8aad9
commit 7a41ef5eed
5 changed files with 32 additions and 19 deletions

View file

@ -28,6 +28,7 @@ class MsgSettingPumpTime(
} }
override fun handleMessageNotReceived() { override fun handleMessageNotReceived() {
super.handleMessageNotReceived()
danaPump.resetPumpTime() danaPump.resetPumpTime()
} }
} }

View file

@ -38,6 +38,9 @@ public class DanaRS_Packet {
injector.androidInjector().inject(this); injector.androidInjector().inject(this);
} }
public boolean success() {
return !failed;
}
public void setReceived() { public void setReceived() {
received = true; received = true;
} }
@ -74,6 +77,7 @@ public class DanaRS_Packet {
} }
public void handleMessageNotReceived() { public void handleMessageNotReceived() {
failed = true;
} }
public String getFriendlyName() { public String getFriendlyName() {
@ -194,7 +198,7 @@ public class DanaRS_Packet {
@TargetApi(Build.VERSION_CODES.KITKAT) @TargetApi(Build.VERSION_CODES.KITKAT)
public String asciiStringFromBuff(byte[] buff, int offset, int length) { public static String asciiStringFromBuff(byte[] buff, int offset, int length) {
byte[] strbuff = new byte[length]; byte[] strbuff = new byte[length];
System.arraycopy(buff, offset, strbuff, 0, length); System.arraycopy(buff, offset, strbuff, 0, length);
return new String(strbuff, StandardCharsets.UTF_8); return new String(strbuff, StandardCharsets.UTF_8);

View file

@ -31,6 +31,7 @@ class DanaRS_Packet_Option_Get_Pump_Time(
} }
override fun handleMessageNotReceived() { override fun handleMessageNotReceived() {
super.handleMessageNotReceived()
danaPump.resetPumpTime() danaPump.resetPumpTime()
} }

View file

@ -32,6 +32,7 @@ class DanaRS_Packet_Option_Get_Pump_UTC_And_TimeZone(
} }
override fun handleMessageNotReceived() { override fun handleMessageNotReceived() {
super.handleMessageNotReceived()
danaPump.resetPumpTime() danaPump.resetPumpTime()
} }

View file

@ -235,12 +235,13 @@ class DanaRSService : DaggerService() {
lastHistoryFetched = if (danaPump.lastEventTimeLoaded != 0L) danaPump.lastEventTimeLoaded - T.mins(1).msecs() else 0 lastHistoryFetched = if (danaPump.lastEventTimeLoaded != 0L) danaPump.lastEventTimeLoaded - T.mins(1).msecs() else 0
aapsLogger.debug(LTag.PUMPCOMM, "Events loaded") aapsLogger.debug(LTag.PUMPCOMM, "Events loaded")
danaPump.lastConnection = System.currentTimeMillis() danaPump.lastConnection = System.currentTimeMillis()
return PumpEnactResult(injector).success(true) return PumpEnactResult(injector).success(msg.success())
} }
fun setUserSettings(): PumpEnactResult { fun setUserSettings(): PumpEnactResult {
sendMessage(DanaRS_Packet_Option_Set_User_Option(injector)) val message = DanaRS_Packet_Option_Set_User_Option(injector)
return PumpEnactResult(injector).success(true) sendMessage(message)
return PumpEnactResult(injector).success(message.success())
} }
fun bolus(insulin: Double, carbs: Int, carbTime: Long, t: Treatment): Boolean { fun bolus(insulin: Double, carbs: Int, carbTime: Long, t: Treatment): Boolean {
@ -333,12 +334,13 @@ class DanaRSService : DaggerService() {
SystemClock.sleep(500) SystemClock.sleep(500)
} }
rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal))) rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal)))
sendMessage(DanaRS_Packet_Basal_Set_Temporary_Basal(injector, percent, durationInHours)) val msgTBR = DanaRS_Packet_Basal_Set_Temporary_Basal(injector, percent, durationInHours)
sendMessage(msgTBR)
SystemClock.sleep(200) SystemClock.sleep(200)
sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(injector)) sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(injector))
loadEvents() loadEvents()
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING))
return true return msgTBR.success()
} }
fun highTempBasal(percent: Int): Boolean { fun highTempBasal(percent: Int): Boolean {
@ -348,11 +350,12 @@ class DanaRSService : DaggerService() {
SystemClock.sleep(500) SystemClock.sleep(500)
} }
rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal))) rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal)))
sendMessage(DanaRS_Packet_APS_Basal_Set_Temporary_Basal(injector, percent)) val msgTBR = DanaRS_Packet_APS_Basal_Set_Temporary_Basal(injector, percent)
sendMessage(msgTBR)
sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(injector)) sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(injector))
loadEvents() loadEvents()
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING))
return true return msgTBR.success()
} }
fun tempBasalShortDuration(percent: Int, durationInMinutes: Int): Boolean { fun tempBasalShortDuration(percent: Int, durationInMinutes: Int): Boolean {
@ -366,42 +369,46 @@ class DanaRSService : DaggerService() {
SystemClock.sleep(500) SystemClock.sleep(500)
} }
rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal))) rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal)))
sendMessage(DanaRS_Packet_APS_Basal_Set_Temporary_Basal(injector, percent)) val msgTBR = DanaRS_Packet_APS_Basal_Set_Temporary_Basal(injector, percent)
sendMessage(msgTBR)
sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(injector)) sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(injector))
loadEvents() loadEvents()
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING))
return true return msgTBR.success()
} }
fun tempBasalStop(): Boolean { fun tempBasalStop(): Boolean {
if (!isConnected) return false if (!isConnected) return false
rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal))) rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal)))
sendMessage(DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(injector)) val msgCancel = DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(injector)
sendMessage(msgCancel)
sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(injector)) sendMessage(DanaRS_Packet_Basal_Get_Temporary_Basal_State(injector))
loadEvents() loadEvents()
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING))
return true return msgCancel.success()
} }
fun extendedBolus(insulin: Double, durationInHalfHours: Int): Boolean { fun extendedBolus(insulin: Double, durationInHalfHours: Int): Boolean {
if (!isConnected) return false if (!isConnected) return false
rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.settingextendedbolus))) rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.settingextendedbolus)))
sendMessage(DanaRS_Packet_Bolus_Set_Extended_Bolus(injector, insulin, durationInHalfHours)) val msgExtended = DanaRS_Packet_Bolus_Set_Extended_Bolus(injector, insulin, durationInHalfHours)
sendMessage(msgExtended)
SystemClock.sleep(200) SystemClock.sleep(200)
sendMessage(DanaRS_Packet_Bolus_Get_Extended_Bolus_State(injector)) sendMessage(DanaRS_Packet_Bolus_Get_Extended_Bolus_State(injector))
loadEvents() loadEvents()
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING))
return true return msgExtended.success()
} }
fun extendedBolusStop(): Boolean { fun extendedBolusStop(): Boolean {
if (!isConnected) return false if (!isConnected) return false
rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingextendedbolus))) rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingextendedbolus)))
sendMessage(DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel(injector)) val msgStop = DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel(injector)
sendMessage(msgStop)
sendMessage(DanaRS_Packet_Bolus_Get_Extended_Bolus_State(injector)) sendMessage(DanaRS_Packet_Bolus_Get_Extended_Bolus_State(injector))
loadEvents() loadEvents()
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING))
return true return msgStop.success()
} }
fun updateBasalsInPump(profile: Profile): Boolean { fun updateBasalsInPump(profile: Profile): Boolean {
@ -418,7 +425,7 @@ class DanaRSService : DaggerService() {
} }
readPumpStatus() readPumpStatus()
rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)) rxBus.send(EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING))
return true return msgSet.success()
} }
fun loadHistory(type: Byte): PumpEnactResult { fun loadHistory(type: Byte): PumpEnactResult {
@ -446,8 +453,7 @@ class DanaRSService : DaggerService() {
SystemClock.sleep(200) SystemClock.sleep(200)
sendMessage(DanaRS_Packet_General_Set_History_Upload_Mode(injector, 0)) sendMessage(DanaRS_Packet_General_Set_History_Upload_Mode(injector, 0))
} }
result.success = true result.success = msg?.success() ?: false
result.comment = "OK"
return result return result
} }