DetailedBolusInfoStorage

This commit is contained in:
Milos Kozak 2020-03-11 23:33:05 +01:00
parent e812dd9437
commit 2f527169d9
18 changed files with 365 additions and 392 deletions

View file

@ -1,19 +1,26 @@
package info.nightscout.androidaps.plugins.pump.common.bolusInfo package info.nightscout.androidaps.plugins.pump.common.bolusInfo
import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper import info.nightscout.androidaps.logging.StacktraceLoggerWrapper
import info.nightscout.androidaps.utils.T import info.nightscout.androidaps.utils.T
import java.util.* import java.util.*
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.math.abs import kotlin.math.abs
object DetailedBolusInfoStorage { @Singleton
private val log = StacktraceLoggerWrapper.getLogger(L.PUMP) class DetailedBolusInfoStorage @Inject constructor(
val aapsLogger: AAPSLogger
){
val store = ArrayList<DetailedBolusInfo>() val store = ArrayList<DetailedBolusInfo>()
@Synchronized @Synchronized
fun add(detailedBolusInfo: DetailedBolusInfo) { fun add(detailedBolusInfo: DetailedBolusInfo) {
log.debug("Stored bolus info: $detailedBolusInfo") aapsLogger.debug("Stored bolus info: $detailedBolusInfo")
store.add(detailedBolusInfo) store.add(detailedBolusInfo)
} }
@ -22,11 +29,9 @@ object DetailedBolusInfoStorage {
// Look for info with bolus // Look for info with bolus
for (i in store.indices) { for (i in store.indices) {
val d = store[i] val d = store[i]
if (L.isEnabled(L.PUMP)) aapsLogger.debug(LTag.PUMP, "Existing bolus info: " + store[i])
log.debug("Existing bolus info: " + store[i])
if (bolusTime > d.date - T.mins(1).msecs() && bolusTime < d.date + T.mins(1).msecs() && abs(store[i].insulin - bolus) < 0.01) { if (bolusTime > d.date - T.mins(1).msecs() && bolusTime < d.date + T.mins(1).msecs() && abs(store[i].insulin - bolus) < 0.01) {
if (L.isEnabled(L.PUMP)) aapsLogger.debug(LTag.PUMP, "Using & removing bolus info: ${store[i]}")
log.debug("Using & removing bolus info: ${store[i]}")
store.removeAt(i) store.removeAt(i)
return d return d
} }
@ -35,8 +40,7 @@ object DetailedBolusInfoStorage {
for (i in store.indices) { for (i in store.indices) {
val d = store[i] val d = store[i]
if (bolusTime > d.date - T.mins(1).msecs() && bolusTime < d.date + T.mins(1).msecs() && bolus <= store[i].insulin + 0.01) { if (bolusTime > d.date - T.mins(1).msecs() && bolusTime < d.date + T.mins(1).msecs() && bolus <= store[i].insulin + 0.01) {
if (L.isEnabled(L.PUMP)) aapsLogger.debug(LTag.PUMP, "Using TIME-ONLY & removing bolus info: ${store[i]}")
log.debug("Using TIME-ONLY & removing bolus info: ${store[i]}")
store.removeAt(i) store.removeAt(i)
return d return d
} }
@ -45,15 +49,13 @@ object DetailedBolusInfoStorage {
if (store.size > 0) { if (store.size > 0) {
val d = store[store.size - 1] val d = store[store.size - 1]
if (abs(d.insulin - bolus) < 0.01) { if (abs(d.insulin - bolus) < 0.01) {
if (L.isEnabled(L.PUMP)) aapsLogger.debug(LTag.PUMP, "Using LAST & removing bolus info: $d")
log.debug("Using LAST & removing bolus info: $d")
store.removeAt(store.size - 1) store.removeAt(store.size - 1)
return d return d
} }
} }
//Not found //Not found
if (L.isEnabled(L.PUMP)) aapsLogger.debug(LTag.PUMP, "Bolus info not found")
log.debug("Bolus info not found")
return null return null
} }
} }

View file

@ -79,6 +79,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
private final RxBusWrapper rxBus; private final RxBusWrapper rxBus;
private final CommandQueueProvider commandQueue; private final CommandQueueProvider commandQueue;
private final DanaRPump danaRPump; private final DanaRPump danaRPump;
private final DetailedBolusInfoStorage detailedBolusInfoStorage;
private static DanaRSService danaRSService; private static DanaRSService danaRSService;
@ -110,7 +111,8 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
TreatmentsPlugin treatmentsPlugin, TreatmentsPlugin treatmentsPlugin,
SP sp, SP sp,
CommandQueueProvider commandQueue, CommandQueueProvider commandQueue,
DanaRPump danaRPump DanaRPump danaRPump,
DetailedBolusInfoStorage detailedBolusInfoStorage
) { ) {
super(new PluginDescription() super(new PluginDescription()
.mainType(PluginType.PUMP) .mainType(PluginType.PUMP)
@ -130,6 +132,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
this.sp = sp; this.sp = sp;
this.commandQueue = commandQueue; this.commandQueue = commandQueue;
this.danaRPump = danaRPump; this.danaRPump = danaRPump;
this.detailedBolusInfoStorage = detailedBolusInfoStorage;
pumpDescription.setPumpDescription(PumpType.DanaRS); pumpDescription.setPumpDescription(PumpType.DanaRS);
} }
@ -406,7 +409,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
if (carbTime == 0) carbTime--; // better set 1 min back to prevents clash with insulin if (carbTime == 0) carbTime--; // better set 1 min back to prevents clash with insulin
detailedBolusInfo.carbTime = 0; detailedBolusInfo.carbTime = 0;
DetailedBolusInfoStorage.INSTANCE.add(detailedBolusInfo); // will be picked up on reading history detailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history
Treatment t = new Treatment(); Treatment t = new Treatment();
t.isSMB = detailedBolusInfo.isSMB; t.isSMB = detailedBolusInfo.isSMB;

View file

@ -4,6 +4,7 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
@ -19,7 +20,8 @@ class DanaRSMessageHashTable @Inject constructor(
danaRPump: DanaRPump, danaRPump: DanaRPump,
danaRSPlugin: DanaRSPlugin, danaRSPlugin: DanaRSPlugin,
activePlugin: ActivePluginProvider, activePlugin: ActivePluginProvider,
constraintChecker: ConstraintChecker constraintChecker: ConstraintChecker,
detailedBolusInfoStorage: DetailedBolusInfoStorage
) { ) {
var messages: HashMap<Int, DanaRS_Packet> = HashMap() var messages: HashMap<Int, DanaRS_Packet> = HashMap()
@ -97,7 +99,7 @@ class DanaRSMessageHashTable @Inject constructor(
put(DanaRS_Packet_History_Temporary(aapsLogger, rxBus)) put(DanaRS_Packet_History_Temporary(aapsLogger, rxBus))
// APS // APS
put(DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, 0)) put(DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, 0))
put(DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRSPlugin, 0)) put(DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRSPlugin, detailedBolusInfoStorage, 0))
put(DanaRS_Packet_APS_Set_Event_History(aapsLogger, 0, 0, 0, 0)) put(DanaRS_Packet_APS_Set_Event_History(aapsLogger, 0, 0, 0, 0))
} }
} }

View file

@ -24,6 +24,7 @@ open class DanaRS_Packet_APS_History_Events(
private val resourceHelper: ResourceHelper, private val resourceHelper: ResourceHelper,
private val activePlugin: ActivePluginProvider, private val activePlugin: ActivePluginProvider,
private val danaRSPlugin: DanaRSPlugin, private val danaRSPlugin: DanaRSPlugin,
private val detailedBolusInfoStorage: DetailedBolusInfoStorage,
private var from: Long private var from: Long
) : DanaRS_Packet() { ) : DanaRS_Packet() {
@ -107,7 +108,7 @@ open class DanaRS_Packet_APS_History_Events(
} }
DanaRPump.BOLUS -> { DanaRPump.BOLUS -> {
val detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0) val detailedBolusInfo = detailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0)
?: DetailedBolusInfo() ?: DetailedBolusInfo()
detailedBolusInfo.date = datetime detailedBolusInfo.date = datetime
detailedBolusInfo.source = Source.PUMP detailedBolusInfo.source = Source.PUMP
@ -119,7 +120,7 @@ open class DanaRS_Packet_APS_History_Events(
} }
DanaRPump.DUALBOLUS -> { DanaRPump.DUALBOLUS -> {
val detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0) val detailedBolusInfo = detailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0)
?: DetailedBolusInfo() ?: DetailedBolusInfo()
detailedBolusInfo.date = datetime detailedBolusInfo.date = datetime
detailedBolusInfo.source = Source.PUMP detailedBolusInfo.source = Source.PUMP

View file

@ -33,6 +33,7 @@ import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes; import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes;
import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus; import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus;
@ -101,6 +102,7 @@ public class DanaRSService extends DaggerService {
@Inject DanaRSMessageHashTable danaRSMessageHashTable; @Inject DanaRSMessageHashTable danaRSMessageHashTable;
@Inject ActivePluginProvider activePlugin; @Inject ActivePluginProvider activePlugin;
@Inject ConstraintChecker constraintChecker; @Inject ConstraintChecker constraintChecker;
@Inject DetailedBolusInfoStorage detailedBolusInfoStorage;
private CompositeDisposable disposable = new CompositeDisposable(); private CompositeDisposable disposable = new CompositeDisposable();
@ -198,7 +200,7 @@ public class DanaRSService extends DaggerService {
if (danaRPump.getLastSettingsRead() + 60 * 60 * 1000L < now || !pump.isInitialized()) { if (danaRPump.getLastSettingsRead() + 60 * 60 * 1000L < now || !pump.isInitialized()) {
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpsettings))); rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpsettings)));
bleComm.sendMessage(new DanaRS_Packet_General_Get_Shipping_Information(aapsLogger, danaRPump)); // serial no bleComm.sendMessage(new DanaRS_Packet_General_Get_Shipping_Information(aapsLogger, danaRPump)); // serial no
bleComm.sendMessage(new DanaRS_Packet_General_Get_Pump_Check(aapsLogger,danaRPump, rxBus, resourceHelper)); // firmware bleComm.sendMessage(new DanaRS_Packet_General_Get_Pump_Check(aapsLogger, danaRPump, rxBus, resourceHelper)); // firmware
bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Profile_Number(aapsLogger, danaRPump)); bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Profile_Number(aapsLogger, danaRPump));
bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Bolus_Option(aapsLogger, rxBus, resourceHelper, danaRPump)); // isExtendedEnabled bleComm.sendMessage(new DanaRS_Packet_Bolus_Get_Bolus_Option(aapsLogger, rxBus, resourceHelper, danaRPump)); // isExtendedEnabled
bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Basal_Rate(aapsLogger, rxBus, resourceHelper, danaRPump)); // basal profile, basalStep, maxBasal bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Basal_Rate(aapsLogger, rxBus, resourceHelper, danaRPump)); // basal profile, basalStep, maxBasal
@ -233,7 +235,7 @@ public class DanaRSService extends DaggerService {
// add 10sec to be sure we are over minute (will be cutted off anyway) // add 10sec to be sure we are over minute (will be cutted off anyway)
bleComm.sendMessage(new DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, DateUtil.now() + T.secs(10).msecs())); bleComm.sendMessage(new DanaRS_Packet_Option_Set_Pump_Time(aapsLogger, DateUtil.now() + T.secs(10).msecs()));
} }
bleComm.sendMessage(new DanaRS_Packet_Option_Get_Pump_Time(aapsLogger,danaRPump)); bleComm.sendMessage(new DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump));
timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L; timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L;
aapsLogger.debug(LTag.PUMPCOMM, "Pump time difference: " + timeDiff + " seconds"); aapsLogger.debug(LTag.PUMPCOMM, "Pump time difference: " + timeDiff + " seconds");
} }
@ -271,10 +273,10 @@ public class DanaRSService extends DaggerService {
DanaRS_Packet_APS_History_Events msg; DanaRS_Packet_APS_History_Events msg;
if (lastHistoryFetched == 0) { if (lastHistoryFetched == 0) {
msg = new DanaRS_Packet_APS_History_Events(aapsLogger, rxBus,resourceHelper, activePlugin, danaRSPlugin, 0); msg = new DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRSPlugin, detailedBolusInfoStorage, 0);
aapsLogger.debug(LTag.PUMPCOMM, "Loading complete event history"); aapsLogger.debug(LTag.PUMPCOMM, "Loading complete event history");
} else { } else {
msg = new DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRSPlugin, lastHistoryFetched); msg = new DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRSPlugin, detailedBolusInfoStorage, lastHistoryFetched);
aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + DateUtil.dateAndTimeString(lastHistoryFetched)); aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + DateUtil.dateAndTimeString(lastHistoryFetched));
} }
bleComm.sendMessage(msg); bleComm.sendMessage(msg);
@ -415,7 +417,7 @@ public class DanaRSService extends DaggerService {
SystemClock.sleep(500); SystemClock.sleep(500);
} }
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal))); rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal)));
bleComm.sendMessage(new DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger,percent)); bleComm.sendMessage(new DanaRS_Packet_APS_Basal_Set_Temporary_Basal(aapsLogger, percent));
bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump)); bleComm.sendMessage(new DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump));
loadEvents(); loadEvents();
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING)); rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
@ -476,9 +478,9 @@ public class DanaRSService extends DaggerService {
if (!isConnected()) return false; if (!isConnected()) return false;
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.updatingbasalrates))); rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.updatingbasalrates)));
Double[] basal = danaRPump.buildDanaRProfileRecord(profile); Double[] basal = danaRPump.buildDanaRProfileRecord(profile);
DanaRS_Packet_Basal_Set_Profile_Basal_Rate msgSet = new DanaRS_Packet_Basal_Set_Profile_Basal_Rate(aapsLogger,0, basal); DanaRS_Packet_Basal_Set_Profile_Basal_Rate msgSet = new DanaRS_Packet_Basal_Set_Profile_Basal_Rate(aapsLogger, 0, basal);
bleComm.sendMessage(msgSet); bleComm.sendMessage(msgSet);
DanaRS_Packet_Basal_Set_Profile_Number msgActivate = new DanaRS_Packet_Basal_Set_Profile_Number(aapsLogger,0); DanaRS_Packet_Basal_Set_Profile_Number msgActivate = new DanaRS_Packet_Basal_Set_Profile_Number(aapsLogger, 0);
bleComm.sendMessage(msgActivate); bleComm.sendMessage(msgActivate);
danaRPump.setLastSettingsRead(0); // force read full settings danaRPump.setLastSettingsRead(0); // force read full settings
getPumpStatus(); getPumpStatus();

View file

@ -52,6 +52,11 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
private final ConstraintChecker constraintChecker; private final ConstraintChecker constraintChecker;
private final TreatmentsPlugin treatmentsPlugin; private final TreatmentsPlugin treatmentsPlugin;
private final SP sp; private final SP sp;
private final DetailedBolusInfoStorage detailedBolusInfoStorage;
public long lastEventTimeLoaded = 0;
public boolean eventsLoadingDone = false;
@Inject @Inject
public DanaRv2Plugin( public DanaRv2Plugin(
@ -64,8 +69,8 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
ConstraintChecker constraintChecker, ConstraintChecker constraintChecker,
TreatmentsPlugin treatmentsPlugin, TreatmentsPlugin treatmentsPlugin,
SP sp, SP sp,
CommandQueueProvider commandQueue CommandQueueProvider commandQueue,
DetailedBolusInfoStorage detailedBolusInfoStorage
) { ) {
super(injector, danaRPump, resourceHelper, constraintChecker, aapsLogger, commandQueue); super(injector, danaRPump, resourceHelper, constraintChecker, aapsLogger, commandQueue);
this.aapsLogger = aapsLogger; this.aapsLogger = aapsLogger;
@ -75,6 +80,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
this.constraintChecker = constraintChecker; this.constraintChecker = constraintChecker;
this.treatmentsPlugin = treatmentsPlugin; this.treatmentsPlugin = treatmentsPlugin;
this.sp = sp; this.sp = sp;
this.detailedBolusInfoStorage = detailedBolusInfoStorage;
getPluginDescription().description(R.string.description_pump_dana_r_v2); getPluginDescription().description(R.string.description_pump_dana_r_v2);
useExtendedBoluses = false; useExtendedBoluses = false;
@ -177,7 +183,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
if (carbTime == 0) carbTime--; // better set 1 man back to prevent clash with insulin if (carbTime == 0) carbTime--; // better set 1 man back to prevent clash with insulin
detailedBolusInfo.carbTime = 0; detailedBolusInfo.carbTime = 0;
DetailedBolusInfoStorage.INSTANCE.add(detailedBolusInfo); // will be picked up on reading history detailedBolusInfoStorage.add(detailedBolusInfo); // will be picked up on reading history
Treatment t = new Treatment(); Treatment t = new Treatment();
t.isSMB = detailedBolusInfo.isSMB; t.isSMB = detailedBolusInfo.isSMB;

View file

@ -6,11 +6,13 @@ import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaR.comm.* import info.nightscout.androidaps.plugins.pump.danaR.comm.*
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin
import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
import java.util.* import java.util.*
import javax.inject.Inject import javax.inject.Inject
@ -28,7 +30,9 @@ class MessageHashTableRv2 @Inject constructor(
danaRv2Plugin: DanaRv2Plugin, danaRv2Plugin: DanaRv2Plugin,
configBuilderPlugin: ConfigBuilderPlugin, configBuilderPlugin: ConfigBuilderPlugin,
commandQueue: CommandQueueProvider, commandQueue: CommandQueueProvider,
activePlugin: ActivePluginProvider activePlugin: ActivePluginProvider,
detailedBolusInfoStorage: DetailedBolusInfoStorage,
treatmentsPlugin: TreatmentsPlugin
) : MessageHashTableBase { ) : MessageHashTableBase {
var messages: HashMap<Int, MessageBase> = HashMap() var messages: HashMap<Int, MessageBase> = HashMap()
@ -87,7 +91,7 @@ class MessageHashTableRv2 @Inject constructor(
put(MsgCheckValue_v2(aapsLogger, rxBus, resourceHelper, danaRPump, danaRPlugin, danaRKoreanPlugin, danaRv2Plugin, configBuilderPlugin, commandQueue)) // 0xF0F1 CMD_PUMP_CHECK_VALUE put(MsgCheckValue_v2(aapsLogger, rxBus, resourceHelper, danaRPump, danaRPlugin, danaRKoreanPlugin, danaRv2Plugin, configBuilderPlugin, commandQueue)) // 0xF0F1 CMD_PUMP_CHECK_VALUE
put(MsgStatusAPS_v2(aapsLogger, danaRPump)) // 0xE001 CMD_PUMPSTATUS_APS put(MsgStatusAPS_v2(aapsLogger, danaRPump)) // 0xE001 CMD_PUMPSTATUS_APS
put(MsgSetAPSTempBasalStart_v2()) // 0xE002 CMD_PUMPSET_APSTEMP put(MsgSetAPSTempBasalStart_v2()) // 0xE002 CMD_PUMPSET_APSTEMP
put(MsgHistoryEvents_v2()) // 0xE003 CMD_GET_HISTORY put(MsgHistoryEvents_v2(aapsLogger, resourceHelper, detailedBolusInfoStorage, danaRv2Plugin, rxBus, treatmentsPlugin)) // 0xE003 CMD_GET_HISTORY
put(MsgSetHistoryEntry_v2()) // 0xE004 CMD_SET_HISTORY_ENTRY put(MsgSetHistoryEntry_v2()) // 0xE004 CMD_SET_HISTORY_ENTRY
} }

View file

@ -1,206 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRv2.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.GregorianCalendar;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil;
public class MsgHistoryEvents_v2 extends MessageBase {
private Logger log = StacktraceLoggerWrapper.getLogger(L.PUMPCOMM);
public boolean done;
public static long lastEventTimeLoaded = 0;
public MsgHistoryEvents_v2() {
this(0);
}
public MsgHistoryEvents_v2(long from) {
SetCommand(0xE003);
if (from > DateUtil.now()) {
log.debug("Asked to load from the future");
from = 0;
}
if (from == 0) {
AddParamByte((byte) 0);
AddParamByte((byte) 1);
AddParamByte((byte) 1);
AddParamByte((byte) 0);
AddParamByte((byte) 0);
} else {
GregorianCalendar gfrom = new GregorianCalendar();
gfrom.setTimeInMillis(from);
AddParamDate(gfrom);
}
done = false;
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
@Override
public void handleMessage(byte[] bytes) {
byte recordCode = (byte) intFromBuff(bytes, 0, 1);
// Last record
if (recordCode == (byte) 0xFF) {
done = true;
return;
}
long datetime = dateTimeSecFromBuff(bytes, 1); // 6 bytes
int param1 = intFromBuff(bytes, 7, 2);
int param2 = intFromBuff(bytes, 9, 2);
TemporaryBasal temporaryBasal = new TemporaryBasal()
.date(datetime)
.source(Source.PUMP)
.pumpId(datetime);
ExtendedBolus extendedBolus = new ExtendedBolus()
.date(datetime)
.source(Source.PUMP)
.pumpId(datetime);
String status = "";
switch (recordCode) {
case DanaRPump.TEMPSTART:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT TEMPSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Ratio: " + param1 + "% Duration: " + param2 + "min");
temporaryBasal.percentRate = param1;
temporaryBasal.durationInMinutes = param2;
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal);
status = "TEMPSTART " + DateUtil.timeString(datetime);
break;
case DanaRPump.TEMPSTOP:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT TEMPSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime));
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal);
status = "TEMPSTOP " + DateUtil.timeString(datetime);
break;
case DanaRPump.EXTENDEDSTART:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT EXTENDEDSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
extendedBolus.insulin = param1 / 100d;
extendedBolus.durationInMinutes = param2;
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
status = "EXTENDEDSTART " + DateUtil.timeString(datetime);
break;
case DanaRPump.EXTENDEDSTOP:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT EXTENDEDSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
status = "EXTENDEDSTOP " + DateUtil.timeString(datetime);
break;
case DanaRPump.BOLUS:
DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.INSTANCE.findDetailedBolusInfo(datetime, param1 / 100d);
if (detailedBolusInfo == null) {
detailedBolusInfo = new DetailedBolusInfo();
}
detailedBolusInfo.date = datetime;
detailedBolusInfo.source = Source.PUMP;
detailedBolusInfo.pumpId = datetime;
detailedBolusInfo.insulin = param1 / 100d;
boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
if (L.isEnabled(L.PUMPCOMM))
log.debug((newRecord ? "**NEW** " : "") + "EVENT BOLUS (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
status = "BOLUS " + DateUtil.timeString(datetime);
break;
case DanaRPump.DUALBOLUS:
detailedBolusInfo = DetailedBolusInfoStorage.INSTANCE.findDetailedBolusInfo(datetime, param1 / 100d);
if (detailedBolusInfo == null) {
detailedBolusInfo = new DetailedBolusInfo();
}
detailedBolusInfo.date = datetime;
detailedBolusInfo.source = Source.PUMP;
detailedBolusInfo.pumpId = datetime;
detailedBolusInfo.insulin = param1 / 100d;
newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);
if (L.isEnabled(L.PUMPCOMM))
log.debug((newRecord ? "**NEW** " : "") + "EVENT DUALBOLUS (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + (param1 / 100d) + "U Duration: " + param2 + "min");
status = "DUALBOLUS " + DateUtil.timeString(datetime);
break;
case DanaRPump.DUALEXTENDEDSTART:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT DUALEXTENDEDSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + (param1 / 100d) + "U Duration: " + param2 + "min");
extendedBolus.insulin = param1 / 100d;
extendedBolus.durationInMinutes = param2;
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
status = "DUALEXTENDEDSTART " + DateUtil.timeString(datetime);
break;
case DanaRPump.DUALEXTENDEDSTOP:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + (param1 / 100d) + "U RealDuration: " + param2 + "min");
TreatmentsPlugin.getPlugin().addToHistoryExtendedBolus(extendedBolus);
status = "DUALEXTENDEDSTOP " + DateUtil.timeString(datetime);
break;
case DanaRPump.SUSPENDON:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT SUSPENDON (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")");
status = "SUSPENDON " + DateUtil.timeString(datetime);
break;
case DanaRPump.SUSPENDOFF:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT SUSPENDOFF (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")");
status = "SUSPENDOFF " + DateUtil.timeString(datetime);
break;
case DanaRPump.REFILL:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT REFILL (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100d + "U");
status = "REFILL " + DateUtil.timeString(datetime);
break;
case DanaRPump.PRIME:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT PRIME (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100d + "U");
status = "PRIME " + DateUtil.timeString(datetime);
break;
case DanaRPump.PROFILECHANGE:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT PROFILECHANGE (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " No: " + param1 + " CurrentRate: " + (param2 / 100d) + "U/h");
status = "PROFILECHANGE " + DateUtil.timeString(datetime);
break;
case DanaRPump.CARBS:
DetailedBolusInfo emptyCarbsInfo = new DetailedBolusInfo();
emptyCarbsInfo.carbs = param1;
emptyCarbsInfo.date = datetime;
emptyCarbsInfo.source = Source.PUMP;
emptyCarbsInfo.pumpId = datetime;
newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(emptyCarbsInfo, false);
if (L.isEnabled(L.PUMPCOMM))
log.debug((newRecord ? "**NEW** " : "") + "EVENT CARBS (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Carbs: " + param1 + "g");
status = "CARBS " + DateUtil.timeString(datetime);
break;
default:
if (L.isEnabled(L.PUMPCOMM))
log.debug("Event: " + recordCode + " " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Param1: " + param1 + " Param2: " + param2);
status = "UNKNOWN " + DateUtil.timeString(datetime);
break;
}
if (datetime > lastEventTimeLoaded)
lastEventTimeLoaded = datetime;
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.processinghistory) + ": " + status));
}
}

View file

@ -0,0 +1,183 @@
package info.nightscout.androidaps.plugins.pump.danaRv2.comm
import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.db.ExtendedBolus
import info.nightscout.androidaps.db.Source
import info.nightscout.androidaps.db.TemporaryBasal
import info.nightscout.androidaps.events.EventPumpStatusChanged
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase
import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.resources.ResourceHelper
import java.util.*
class MsgHistoryEvents_v2 constructor(
val aapsLogger: AAPSLogger,
val resourceHelper: ResourceHelper,
private val detailedBolusInfoStorage: DetailedBolusInfoStorage,
val danaRv2Plugin: DanaRv2Plugin,
val rxBus: RxBusWrapper,
val treatmentsPlugin: TreatmentsPlugin,
var from: Long = 0
) : MessageBase() {
init {
SetCommand(0xE003)
if (from > DateUtil.now()) {
aapsLogger.error("Asked to load from the future")
from = 0
}
if (from == 0L) {
AddParamByte(0.toByte())
AddParamByte(1.toByte())
AddParamByte(1.toByte())
AddParamByte(0.toByte())
AddParamByte(0.toByte())
} else {
val gfrom = GregorianCalendar()
gfrom.timeInMillis = from
AddParamDate(gfrom)
}
danaRv2Plugin.eventsLoadingDone = false
aapsLogger.debug(LTag.PUMPBTCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
val recordCode = intFromBuff(bytes, 0, 1).toByte()
// Last record
if (recordCode == 0xFF.toByte()) {
danaRv2Plugin.eventsLoadingDone = true
return
}
val datetime = dateTimeSecFromBuff(bytes, 1) // 6 bytes
val param1 = intFromBuff(bytes, 7, 2)
val param2 = intFromBuff(bytes, 9, 2)
val temporaryBasal = TemporaryBasal()
.date(datetime)
.source(Source.PUMP)
.pumpId(datetime)
val extendedBolus = ExtendedBolus()
.date(datetime)
.source(Source.PUMP)
.pumpId(datetime)
val status: String
when (recordCode.toInt()) {
DanaRPump.TEMPSTART -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT TEMPSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Ratio: " + param1 + "% Duration: " + param2 + "min")
temporaryBasal.percentRate = param1
temporaryBasal.durationInMinutes = param2
treatmentsPlugin.addToHistoryTempBasal(temporaryBasal)
status = "TEMPSTART " + DateUtil.timeString(datetime)
}
DanaRPump.TEMPSTOP -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT TEMPSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime))
treatmentsPlugin.addToHistoryTempBasal(temporaryBasal)
status = "TEMPSTOP " + DateUtil.timeString(datetime)
}
DanaRPump.EXTENDEDSTART -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT EXTENDEDSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U Duration: " + param2 + "min")
extendedBolus.insulin = param1 / 100.0
extendedBolus.durationInMinutes = param2
treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus)
status = "EXTENDEDSTART " + DateUtil.timeString(datetime)
}
DanaRPump.EXTENDEDSTOP -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT EXTENDEDSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + param1 / 100.0 + "U RealDuration: " + param2 + "min")
treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus)
status = "EXTENDEDSTOP " + DateUtil.timeString(datetime)
}
DanaRPump.BOLUS -> {
val detailedBolusInfo = detailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0)
?: DetailedBolusInfo()
detailedBolusInfo.date = datetime
detailedBolusInfo.source = Source.PUMP
detailedBolusInfo.pumpId = datetime
detailedBolusInfo.insulin = param1 / 100.0
val newRecord = treatmentsPlugin.addToHistoryTreatment(detailedBolusInfo, false)
aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT BOLUS (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + param1 / 100.0 + "U Duration: " + param2 + "min")
status = "BOLUS " + DateUtil.timeString(datetime)
}
DanaRPump.DUALBOLUS -> {
val detailedBolusInfo = detailedBolusInfoStorage.findDetailedBolusInfo(datetime, param1 / 100.0)
?: DetailedBolusInfo()
detailedBolusInfo.date = datetime
detailedBolusInfo.source = Source.PUMP
detailedBolusInfo.pumpId = datetime
detailedBolusInfo.insulin = param1 / 100.0
val newRecord = treatmentsPlugin.addToHistoryTreatment(detailedBolusInfo, false)
aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT DUALBOLUS (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Bolus: " + param1 / 100.0 + "U Duration: " + param2 + "min")
status = "DUALBOLUS " + DateUtil.timeString(datetime)
}
DanaRPump.DUALEXTENDEDSTART -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT DUALEXTENDEDSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U Duration: " + param2 + "min")
extendedBolus.insulin = param1 / 100.0
extendedBolus.durationInMinutes = param2
treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus)
status = "DUALEXTENDEDSTART " + DateUtil.timeString(datetime)
}
DanaRPump.DUALEXTENDEDSTOP -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + param1 / 100.0 + "U RealDuration: " + param2 + "min")
treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus)
status = "DUALEXTENDEDSTOP " + DateUtil.timeString(datetime)
}
DanaRPump.SUSPENDON -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT SUSPENDON (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")")
status = "SUSPENDON " + DateUtil.timeString(datetime)
}
DanaRPump.SUSPENDOFF -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT SUSPENDOFF (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")")
status = "SUSPENDOFF " + DateUtil.timeString(datetime)
}
DanaRPump.REFILL -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT REFILL (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U")
status = "REFILL " + DateUtil.timeString(datetime)
}
DanaRPump.PRIME -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT PRIME (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U")
status = "PRIME " + DateUtil.timeString(datetime)
}
DanaRPump.PROFILECHANGE -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "EVENT PROFILECHANGE (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " No: " + param1 + " CurrentRate: " + param2 / 100.0 + "U/h")
status = "PROFILECHANGE " + DateUtil.timeString(datetime)
}
DanaRPump.CARBS -> {
val emptyCarbsInfo = DetailedBolusInfo()
emptyCarbsInfo.carbs = param1.toDouble()
emptyCarbsInfo.date = datetime
emptyCarbsInfo.source = Source.PUMP
emptyCarbsInfo.pumpId = datetime
val newRecord = treatmentsPlugin.addToHistoryTreatment(emptyCarbsInfo, false)
aapsLogger.debug(LTag.PUMPBTCOMM, (if (newRecord) "**NEW** " else "") + "EVENT CARBS (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Carbs: " + param1 + "g")
status = "CARBS " + DateUtil.timeString(datetime)
}
else -> {
aapsLogger.debug(LTag.PUMPBTCOMM, "Event: " + recordCode + " " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Param1: " + param1 + " Param2: " + param2)
status = "UNKNOWN " + DateUtil.timeString(datetime)
}
}
if (datetime > danaRv2Plugin.lastEventTimeLoaded) danaRv2Plugin.lastEventTimeLoaded = datetime
rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.processinghistory) + ": " + status))
}
}

View file

@ -36,6 +36,7 @@ import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification; import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress; import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification; import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin; import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump; import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.plugins.pump.danaR.SerialIOThread; import info.nightscout.androidaps.plugins.pump.danaR.SerialIOThread;
@ -77,6 +78,7 @@ import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgSetHistoryEntry_v
import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgStatusBolusExtended_v2; import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgStatusBolusExtended_v2;
import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgStatusTempBasal_v2; import info.nightscout.androidaps.plugins.pump.danaRv2.comm.MsgStatusTempBasal_v2;
import info.nightscout.androidaps.plugins.treatments.Treatment; import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.queue.commands.Command; import info.nightscout.androidaps.queue.commands.Command;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
@ -101,6 +103,8 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
@Inject CommandQueueProvider commandQueue; @Inject CommandQueueProvider commandQueue;
@Inject Context context; @Inject Context context;
@Inject MessageHashTableRv2 messageHashTableRv2; @Inject MessageHashTableRv2 messageHashTableRv2;
@Inject DetailedBolusInfoStorage detailedBolusInfoStorage;
@Inject TreatmentsPlugin treatmentsPlugin;
private CompositeDisposable disposable = new CompositeDisposable(); private CompositeDisposable disposable = new CompositeDisposable();
@ -491,16 +495,16 @@ 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);
MsgHistoryEvents_v2 msg = new MsgHistoryEvents_v2(lastHistoryFetched); MsgHistoryEvents_v2 msg = new MsgHistoryEvents_v2(aapsLogger, resourceHelper, detailedBolusInfoStorage, danaRv2Plugin, rxBus, treatmentsPlugin, lastHistoryFetched);
aapsLogger.debug(LTag.PUMP, "Loading event history from: " + DateUtil.dateAndTimeString(lastHistoryFetched)); aapsLogger.debug(LTag.PUMP, "Loading event history from: " + DateUtil.dateAndTimeString(lastHistoryFetched));
mSerialIOThread.sendMessage(msg); mSerialIOThread.sendMessage(msg);
while (!msg.done && mRfcommSocket.isConnected()) { while (!danaRv2Plugin.eventsLoadingDone && mRfcommSocket.isConnected()) {
SystemClock.sleep(100); SystemClock.sleep(100);
} }
SystemClock.sleep(200); SystemClock.sleep(200);
if (MsgHistoryEvents_v2.lastEventTimeLoaded != 0) if (danaRv2Plugin.lastEventTimeLoaded != 0)
lastHistoryFetched = MsgHistoryEvents_v2.lastEventTimeLoaded - T.mins(1).msecs(); lastHistoryFetched = danaRv2Plugin.lastEventTimeLoaded - T.mins(1).msecs();
else else
lastHistoryFetched = 0; lastHistoryFetched = 0;
danaRPump.setLastConnection(System.currentTimeMillis()); danaRPump.setLastConnection(System.currentTimeMillis());

View file

@ -1,90 +0,0 @@
package info.nightscout.androidaps.plugins.general.smsCommunicator;
import android.telephony.SmsMessage;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import info.AAPSMocker;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
public class SmsActionTest {
String result = "";
@Test
public void doTests() {
SmsAction smsAction = new SmsAction() {
@Override
public void run() {
result = "A";
}
};
smsAction.run();
Assert.assertEquals(result, "A");
smsAction = new SmsAction(1d) {
@Override
public void run() {
result = "B";
}
};
smsAction.run();
Assert.assertEquals(result, "B");
Assert.assertEquals(smsAction.aDouble(), 1d, 0.000001d);
smsAction = new SmsAction(1d, 2) {
@Override
public void run() {
result = "C";
}
};
smsAction.run();
Assert.assertEquals(result, "C");
Assert.assertEquals(smsAction.aDouble(), 1d, 0.000001d);
Assert.assertEquals(smsAction.secondInteger(), 2);
smsAction = new SmsAction("aString", 3) {
@Override
public void run() {
result = "D";
}
};
smsAction.run();
Assert.assertEquals(result, "D");
Assert.assertEquals(smsAction.aString(), "aString");
Assert.assertEquals(smsAction.secondInteger(), 3);
smsAction = new SmsAction(4) {
@Override
public void run() {
result = "E";
}
};
smsAction.run();
Assert.assertEquals(result, "E");
Assert.assertEquals(smsAction.anInteger(), 4);
smsAction = new SmsAction(5, 6) {
@Override
public void run() {
result = "F";
}
};
smsAction.run();
Assert.assertEquals(result, "F");
Assert.assertEquals(smsAction.anInteger(), 5);
Assert.assertEquals(smsAction.secondInteger(), 6);
}
}

View file

@ -0,0 +1,64 @@
package info.nightscout.androidaps.plugins.general.smsCommunicator
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)
class SmsActionTest {
var result = ""
@Test fun doTests() {
var smsAction: SmsAction = object : SmsAction() {
override fun run() {
result = "A"
}
}
smsAction.run()
Assert.assertEquals(result, "A")
smsAction = object : SmsAction(1.0) {
override fun run() {
result = "B"
}
}
smsAction.run()
Assert.assertEquals(result, "B")
Assert.assertEquals(smsAction.aDouble(), 1.0, 0.000001)
smsAction = object : SmsAction(1.0, 2) {
override fun run() {
result = "C"
}
}
smsAction.run()
Assert.assertEquals(result, "C")
Assert.assertEquals(smsAction.aDouble(), 1.0, 0.000001)
Assert.assertEquals(smsAction.secondInteger().toLong(), 2)
smsAction = object : SmsAction("aString", 3) {
override fun run() {
result = "D"
}
}
smsAction.run()
Assert.assertEquals(result, "D")
Assert.assertEquals(smsAction.aString(), "aString")
Assert.assertEquals(smsAction.secondInteger().toLong(), 3)
smsAction = object : SmsAction(4) {
override fun run() {
result = "E"
}
}
smsAction.run()
Assert.assertEquals(result, "E")
Assert.assertEquals(smsAction.anInteger().toLong(), 4)
smsAction = object : SmsAction(5, 6) {
override fun run() {
result = "F"
}
}
smsAction.run()
Assert.assertEquals(result, "F")
Assert.assertEquals(smsAction.anInteger().toLong(), 5)
Assert.assertEquals(smsAction.secondInteger().toLong(), 6)
}
}

View file

@ -1,26 +1,27 @@
package info.nightscout.androidaps.plugins.pump.common.bolusInfo package info.nightscout.androidaps.plugins.pump.common.bolusInfo
import info.nightscout.androidaps.MainApp import info.TestBase
import info.nightscout.androidaps.data.DetailedBolusInfo import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.utils.SP
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull import org.junit.Assert.assertNull
import org.junit.Before
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers import org.mockito.Mock
import org.mockito.Mockito
import org.powermock.api.mockito.PowerMockito
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
class DetailedBolusInfoStorageTest { class DetailedBolusInfoStorageTest : TestBase() {
@Mock lateinit var aapsLogger: AAPSLogger
private val info1 = DetailedBolusInfo() private val info1 = DetailedBolusInfo()
private val info2 = DetailedBolusInfo() private val info2 = DetailedBolusInfo()
private val info3 = DetailedBolusInfo() private val info3 = DetailedBolusInfo()
lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage
init { init {
info1.date = 1000000 info1.date = 1000000
info1.insulin = 3.0 info1.insulin = 3.0
@ -30,80 +31,64 @@ class DetailedBolusInfoStorageTest {
info3.insulin = 5.0 info3.insulin = 5.0
} }
@Before
fun prepare() {
detailedBolusInfoStorage = DetailedBolusInfoStorage(aapsLogger)
}
private fun setUp() { private fun setUp() {
DetailedBolusInfoStorage.store.clear() detailedBolusInfoStorage.store.clear()
DetailedBolusInfoStorage.add(info1) detailedBolusInfoStorage.add(info1)
DetailedBolusInfoStorage.add(info2) detailedBolusInfoStorage.add(info2)
DetailedBolusInfoStorage.add(info3) detailedBolusInfoStorage.add(info3)
} }
@Test @Test
fun add() { fun add() {
DetailedBolusInfoStorage.store.clear() detailedBolusInfoStorage.store.clear()
assertEquals(0, DetailedBolusInfoStorage.store.size) assertEquals(0, detailedBolusInfoStorage.store.size)
DetailedBolusInfoStorage.add(info1) detailedBolusInfoStorage.add(info1)
assertEquals(1, DetailedBolusInfoStorage.store.size) assertEquals(1, detailedBolusInfoStorage.store.size)
} }
@Test @Test
@PrepareForTest(MainApp::class, L::class, SP::class)
fun findDetailedBolusInfo() { fun findDetailedBolusInfo() {
prepareMainApp()
prepareSP()
prepareLogging()
// Look for exact bolus // Look for exact bolus
setUp() setUp()
var d: DetailedBolusInfo? = DetailedBolusInfoStorage.findDetailedBolusInfo(1000000, 4.0) var d: DetailedBolusInfo? = detailedBolusInfoStorage.findDetailedBolusInfo(1000000, 4.0)
assertEquals(4.0, d!!.insulin, 0.01) assertEquals(4.0, d!!.insulin, 0.01)
assertEquals(2, DetailedBolusInfoStorage.store.size) assertEquals(2, detailedBolusInfoStorage.store.size)
// Look for exact bolus // Look for exact bolus
setUp() setUp()
d = DetailedBolusInfoStorage.findDetailedBolusInfo(1000000, 3.0) d = detailedBolusInfoStorage.findDetailedBolusInfo(1000000, 3.0)
assertEquals(3.0, d!!.insulin, 0.01) assertEquals(3.0, d!!.insulin, 0.01)
assertEquals(2, DetailedBolusInfoStorage.store.size) assertEquals(2, detailedBolusInfoStorage.store.size)
// With less insulin (bolus not delivered completely). Should return first one matching date // With less insulin (bolus not delivered completely). Should return first one matching date
setUp() setUp()
d = DetailedBolusInfoStorage.findDetailedBolusInfo(1000500, 2.0) d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 2.0)
assertEquals(3.0, d!!.insulin, 0.01) assertEquals(3.0, d!!.insulin, 0.01)
assertEquals(2, DetailedBolusInfoStorage.store.size) assertEquals(2, detailedBolusInfoStorage.store.size)
// With less insulin (bolus not delivered completely). Should return first one matching date // With less insulin (bolus not delivered completely). Should return first one matching date
setUp() setUp()
d = DetailedBolusInfoStorage.findDetailedBolusInfo(1000500, 3.5) d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 3.5)
assertEquals(4.0, d!!.insulin, 0.01) assertEquals(4.0, d!!.insulin, 0.01)
assertEquals(2, DetailedBolusInfoStorage.store.size) assertEquals(2, detailedBolusInfoStorage.store.size)
// With more insulin should return null // With more insulin should return null
setUp() setUp()
d = DetailedBolusInfoStorage.findDetailedBolusInfo(1000500, 4.5) d = detailedBolusInfoStorage.findDetailedBolusInfo(1000500, 4.5)
assertNull(d) assertNull(d)
assertEquals(3, DetailedBolusInfoStorage.store.size) assertEquals(3, detailedBolusInfoStorage.store.size)
// With more than one minute off should return null // With more than one minute off should return null
setUp() setUp()
d = DetailedBolusInfoStorage.findDetailedBolusInfo(1070000, 4.0) d = detailedBolusInfoStorage.findDetailedBolusInfo(1070000, 4.0)
assertNull(d) assertNull(d)
assertEquals(3, DetailedBolusInfoStorage.store.size) assertEquals(3, detailedBolusInfoStorage.store.size)
// Use last, if bolus size is the same // Use last, if bolus size is the same
setUp() setUp()
d = DetailedBolusInfoStorage.findDetailedBolusInfo(1070000, 5.0) d = detailedBolusInfoStorage.findDetailedBolusInfo(1070000, 5.0)
assertEquals(5.0, d!!.insulin, 0.01) assertEquals(5.0, d!!.insulin, 0.01)
assertEquals(2, DetailedBolusInfoStorage.store.size) assertEquals(2, detailedBolusInfoStorage.store.size)
} }
private fun prepareMainApp() {
PowerMockito.mockStatic(MainApp::class.java)
val mainApp = Mockito.mock<MainApp>(MainApp::class.java)
Mockito.`when`(MainApp.instance()).thenReturn(mainApp)
Mockito.`when`(MainApp.gs(ArgumentMatchers.anyInt())).thenReturn("some dummy string")
}
private fun prepareSP() {
PowerMockito.mockStatic(SP::class.java)
}
private fun prepareLogging() {
PowerMockito.mockStatic(L::class.java)
Mockito.`when`(L.isEnabled(Mockito.any())).thenReturn(true)
}
} }

View file

@ -14,6 +14,7 @@ import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSTestBase import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRSTestBase
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.SP import info.nightscout.androidaps.utils.SP
@ -29,7 +30,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(ConstraintChecker::class, RxBusWrapper::class, L::class, SP::class, MainApp::class) @PrepareForTest(ConstraintChecker::class, RxBusWrapper::class, L::class, SP::class, MainApp::class, DetailedBolusInfoStorage::class)
class DanaRSPluginTest : DanaRSTestBase() { class DanaRSPluginTest : DanaRSTestBase() {
@Mock lateinit var context: Context @Mock lateinit var context: Context
@ -38,6 +39,8 @@ class DanaRSPluginTest : DanaRSTestBase() {
@Mock lateinit var profileFunction: ProfileFunction @Mock lateinit var profileFunction: ProfileFunction
@Mock lateinit var treatmentsPlugin: TreatmentsPlugin @Mock lateinit var treatmentsPlugin: TreatmentsPlugin
@Mock lateinit var commandQueue: CommandQueueProvider @Mock lateinit var commandQueue: CommandQueueProvider
@Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage
private lateinit var danaRSPlugin: DanaRSPlugin private lateinit var danaRSPlugin: DanaRSPlugin
lateinit var rxBus: RxBusWrapper lateinit var rxBus: RxBusWrapper
@ -76,6 +79,6 @@ class DanaRSPluginTest : DanaRSTestBase() {
Mockito.`when`(resourceHelper.gs(eq(R.string.limitingpercentrate), anyObject(), anyObject())).thenReturn("limitingpercentrate") Mockito.`when`(resourceHelper.gs(eq(R.string.limitingpercentrate), anyObject(), anyObject())).thenReturn("limitingpercentrate")
rxBus = RxBusWrapper() rxBus = RxBusWrapper()
danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump) danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage)
} }
} }

View file

@ -5,6 +5,7 @@ import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.Constraint import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
@ -18,7 +19,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(ConstraintChecker::class) @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class)
class DanaRSMessageHashTableTest : DanaRSTestBase() { class DanaRSMessageHashTableTest : DanaRSTestBase() {
@Mock lateinit var rxBus: RxBusWrapper @Mock lateinit var rxBus: RxBusWrapper
@ -26,12 +27,13 @@ class DanaRSMessageHashTableTest : DanaRSTestBase() {
@Mock lateinit var danaRSPlugin: DanaRSPlugin @Mock lateinit var danaRSPlugin: DanaRSPlugin
@Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var activePlugin: ActivePluginProvider
@Mock lateinit var constraintChecker: ConstraintChecker @Mock lateinit var constraintChecker: ConstraintChecker
@Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage
@Test @Test
fun runTest() { fun runTest() {
`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) `when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0))
val danaRSMessageHashTable = DanaRSMessageHashTable(aapsLogger, rxBus, resourceHelper, danaRPump, danaRSPlugin, activePlugin, constraintChecker) val danaRSMessageHashTable = DanaRSMessageHashTable(aapsLogger, rxBus, resourceHelper, danaRPump, danaRSPlugin, activePlugin, constraintChecker, detailedBolusInfoStorage)
val forTesting: DanaRS_Packet = DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, 0, 0, 0) val forTesting: DanaRS_Packet = DanaRS_Packet_APS_Set_Event_History(aapsLogger, DanaRPump.CARBS, 0, 0, 0)
val testPacket: DanaRS_Packet = danaRSMessageHashTable.findMessage(forTesting.command) val testPacket: DanaRS_Packet = danaRSMessageHashTable.findMessage(forTesting.command)
Assert.assertEquals(BleCommandUtil.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY.toLong(), testPacket.getOpCode().toLong()) Assert.assertEquals(BleCommandUtil.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY.toLong(), testPacket.getOpCode().toLong())

View file

@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.interfaces.ActivePluginProvider import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
@ -14,18 +15,19 @@ import org.powermock.modules.junit4.PowerMockRunner
import java.util.* import java.util.*
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(RxBusWrapper::class) @PrepareForTest(RxBusWrapper::class, DetailedBolusInfoStorage::class)
class DanaRS_Packet_APS_History_EventsTest : DanaRSTestBase() { class DanaRS_Packet_APS_History_EventsTest : DanaRSTestBase() {
@Mock lateinit var rxBus: RxBusWrapper @Mock lateinit var rxBus: RxBusWrapper
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@Mock lateinit var activePlugin: ActivePluginProvider @Mock lateinit var activePlugin: ActivePluginProvider
@Mock lateinit var danaRSPlugin: DanaRSPlugin @Mock lateinit var danaRSPlugin: DanaRSPlugin
@Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage
@Test fun runTest() { @Test fun runTest() {
val now = DateUtil.now() val now = DateUtil.now()
val testPacket = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRSPlugin, now) val testPacket = DanaRS_Packet_APS_History_Events(aapsLogger, rxBus, resourceHelper, activePlugin, danaRSPlugin, detailedBolusInfoStorage, now)
// test getRequestedParams // test getRequestedParams
val returnedValues = testPacket.requestParams val returnedValues = testPacket.requestParams
val expectedValues = getCalender(now) val expectedValues = getCalender(now)

View file

@ -8,6 +8,7 @@ import info.nightscout.androidaps.interfaces.Constraint
import info.nightscout.androidaps.plugins.bus.RxBusWrapper import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper import info.nightscout.androidaps.utils.resources.ResourceHelper
@ -21,7 +22,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(ConstraintChecker::class) @PrepareForTest(ConstraintChecker::class, DetailedBolusInfoStorage::class)
class DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest : DanaRSTestBase() { class DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest : DanaRSTestBase() {
@Mock lateinit var resourceHelper: ResourceHelper @Mock lateinit var resourceHelper: ResourceHelper
@ -31,6 +32,8 @@ class DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest : DanaRSTestBase() {
@Mock lateinit var commandQueue: CommandQueueProvider @Mock lateinit var commandQueue: CommandQueueProvider
@Mock lateinit var rxBus: RxBusWrapper @Mock lateinit var rxBus: RxBusWrapper
@Mock lateinit var context: Context @Mock lateinit var context: Context
@Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage
private lateinit var danaRSPlugin: DanaRSPlugin private lateinit var danaRSPlugin: DanaRSPlugin
@Test fun runTest() { @Test fun runTest() {
@ -49,7 +52,7 @@ class DanaRS_Packet_Bolus_Set_Step_Bolus_StartTest : DanaRSTestBase() {
@Before @Before
fun mock() { fun mock() {
danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump) danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage)
Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0)) Mockito.`when`(constraintChecker.applyBolusConstraints(anyObject())).thenReturn(Constraint(0.0))
} }
} }

View file

@ -8,6 +8,7 @@ import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.pump.common.bolusInfo.DetailedBolusInfoStorage
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
import info.nightscout.androidaps.plugins.treatments.Treatment import info.nightscout.androidaps.plugins.treatments.Treatment
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
@ -24,7 +25,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class) @RunWith(PowerMockRunner::class)
@PrepareForTest(ConstraintChecker::class, RxBusWrapper::class) @PrepareForTest(ConstraintChecker::class, RxBusWrapper::class, DetailedBolusInfoStorage::class)
class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() { class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() {
@Mock lateinit var defaultValueHelper: DefaultValueHelper @Mock lateinit var defaultValueHelper: DefaultValueHelper
@ -36,6 +37,8 @@ class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() {
@Mock lateinit var commandQueue: CommandQueueProvider @Mock lateinit var commandQueue: CommandQueueProvider
@Mock lateinit var rxBus: RxBusWrapper @Mock lateinit var rxBus: RxBusWrapper
@Mock lateinit var context: Context @Mock lateinit var context: Context
@Mock lateinit var detailedBolusInfoStorage: DetailedBolusInfoStorage
private lateinit var danaRSPlugin: DanaRSPlugin private lateinit var danaRSPlugin: DanaRSPlugin
private var treatmentInjector: HasAndroidInjector = HasAndroidInjector { private var treatmentInjector: HasAndroidInjector = HasAndroidInjector {
@ -67,7 +70,7 @@ class DanaRS_Packet_Notify_Delivery_Rate_DisplayTest : DanaRSTestBase() {
@Before @Before
fun mock() { fun mock() {
danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump) danaRSPlugin = DanaRSPlugin(HasAndroidInjector { AndroidInjector { Unit } }, aapsLogger, rxBus, context, resourceHelper, constraintChecker, profileFunction, treatmentsPlugin, sp, commandQueue, danaRPump, detailedBolusInfoStorage)
danaRSPlugin.bolusingTreatment = Treatment(treatmentInjector) danaRSPlugin.bolusingTreatment = Treatment(treatmentInjector)
} }
} }