Dana drivers refactor

This commit is contained in:
Milos Kozak 2020-01-12 23:43:44 +01:00
parent 6bc2d9eef5
commit faaa659b3d
239 changed files with 5999 additions and 7228 deletions

View file

@ -149,7 +149,7 @@ public class CareportalEvent implements DataPointWithLabelInterface, Interval {
CareportalEvent event = list.get(i);
if (event.date <= time && event.date > (time - T.mins(5).msecs())) {
if (L.isEnabled(L.DATABASE))
log.debug("Found event for time: " + DateUtil.dateAndTimeFullString(time) + " " + event.toString());
log.debug("Found event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString());
return true;
}
}

View file

@ -236,12 +236,12 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
if (zeroDurationOnly) {
if (event.durationInMinutes == 0) {
if (L.isEnabled(L.DATABASE))
log.debug("Found ProfileSwitch event for time: " + DateUtil.dateAndTimeFullString(time) + " " + event.toString());
log.debug("Found ProfileSwitch event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString());
return true;
}
} else {
if (L.isEnabled(L.DATABASE))
log.debug("Found ProfileSwitch event for time: " + DateUtil.dateAndTimeFullString(time) + " " + event.toString());
log.debug("Found ProfileSwitch event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString());
return true;
}
}

View file

@ -44,6 +44,7 @@ interface AppComponent : AndroidInjector<MainApp> {
fun injectCommandInsightSetTBROverNotification(commandInsightSetTBROverNotification: CommandInsightSetTBROverNotification)
fun injectCommandLoadEvents(commandLoadEvents: CommandLoadEvents)
fun injectCommandLoadHistory(commandLoadHistory: CommandLoadHistory)
fun injectCommandLoadTDDs(commandLoadTDDs: CommandLoadTDDs)
fun injectCommandReadStatus(commandReadStatus: CommandReadStatus)
fun injectCommandSetProfile(commandSetProfile: CommandSetProfile)
fun injectCommandCommandSMBBolus(commandSMBBolus: CommandSMBBolus)
@ -51,6 +52,7 @@ interface AppComponent : AndroidInjector<MainApp> {
fun injectCommandStopPump(commandStopPump: CommandStopPump)
fun injectCommandTempBasalAbsolute(commandTempBasalAbsolute: CommandTempBasalAbsolute)
fun injectCommandTempBasalPercent(commandTempBasalPercent: CommandTempBasalPercent)
fun injectCommandSetUserSettings(commandSetUserSettings: CommandSetUserSettings)
fun injectObjective0(objective0: Objective0)
fun injectObjective1(objective1: Objective1)

View file

@ -63,11 +63,13 @@ open class AppModule {
@Provides
@Singleton
fun provideAAPSLogger(): AAPSLogger {
return if (BuildConfig.DEBUG) {
return AAPSLoggerProduction()
/* if (BuildConfig.DEBUG) {
AAPSLoggerDebug()
} else {
AAPSLoggerProduction()
}
*/
}
@Module
@ -85,6 +87,7 @@ open class AppModule {
@ContributesAndroidInjector fun commandLoadEventsInjector(): CommandLoadEvents
@ContributesAndroidInjector fun commandLoadHistoryInjector(): CommandLoadHistory
@ContributesAndroidInjector fun commandLoadTDDsInjector(): CommandLoadTDDs
@ContributesAndroidInjector fun commandReadStatusInjector(): CommandReadStatus
@ContributesAndroidInjector fun commandSetProfileInjector(): CommandSetProfile
@ContributesAndroidInjector fun commandCommandSMBBolusInjector(): CommandSMBBolus
@ -92,6 +95,7 @@ open class AppModule {
@ContributesAndroidInjector fun commandStopPumpInjector(): CommandStopPump
@ContributesAndroidInjector fun commandTempBasalAbsoluteInjector(): CommandTempBasalAbsolute
@ContributesAndroidInjector fun commandTempBasalPercentInjector(): CommandTempBasalPercent
@ContributesAndroidInjector fun commandSetUserSettingsInjector(): CommandSetUserSettings
@ContributesAndroidInjector fun objective0Injector(): Objective0
@ContributesAndroidInjector fun objective1Injector(): Objective1

View file

@ -4,7 +4,10 @@ import dagger.Module
import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.plugins.general.nsclient.services.NSClientService
import info.nightscout.androidaps.plugins.general.persistentNotification.DummyService
import info.nightscout.androidaps.plugins.pump.danaR.services.DanaRExecutionService
import info.nightscout.androidaps.plugins.pump.danaRKorean.services.DanaRKoreanExecutionService
import info.nightscout.androidaps.plugins.pump.danaRS.services.DanaRSService
import info.nightscout.androidaps.plugins.pump.danaRv2.services.DanaRv2ExecutionService
import info.nightscout.androidaps.services.AlarmSoundService
import info.nightscout.androidaps.services.DataService
import info.nightscout.androidaps.services.LocationService
@ -19,4 +22,7 @@ abstract class ServicesModule {
@ContributesAndroidInjector abstract fun contributesLocationService(): LocationService
@ContributesAndroidInjector abstract fun contributesNSClientService(): NSClientService
@ContributesAndroidInjector abstract fun contributesDanaRSService(): DanaRSService
@ContributesAndroidInjector abstract fun contributesDanaRv2ExecutionService(): DanaRv2ExecutionService
@ContributesAndroidInjector abstract fun contributesDanaRExecutionService(): DanaRExecutionService
@ContributesAndroidInjector abstract fun contributesDanaRKoreanExecutionService(): DanaRKoreanExecutionService
}

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.dialogs
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.text.Editable
@ -41,6 +42,7 @@ class InsulinDialog : DialogFragmentWithDate() {
@Inject lateinit var profileFunction: ProfileFunction
@Inject lateinit var commandQueue: CommandQueueProvider
@Inject lateinit var activePlugin: ActivePluginProvider
@Inject lateinit var ctx: Context
companion object {
private const val PLUS1_DEFAULT = 0.5
@ -176,12 +178,12 @@ class InsulinDialog : DialogFragmentWithDate() {
commandQueue.bolus(detailedBolusInfo, object : Callback() {
override fun run() {
if (!result.success) {
val i = Intent(context, ErrorHelperActivity::class.java)
val i = Intent(ctx, ErrorHelperActivity::class.java)
i.putExtra("soundid", R.raw.boluserror)
i.putExtra("status", result.comment)
i.putExtra("title", resourceHelper.gs(R.string.treatmentdeliveryerror))
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context?.startActivity(i)
ctx.startActivity(i)
}
}
})

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.dialogs
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
@ -32,6 +33,7 @@ class TempBasalDialog : DialogFragmentWithDate() {
@Inject lateinit var profileFunction: ProfileFunction
@Inject lateinit var activePlugin: ActivePluginProvider
@Inject lateinit var commandQueue: CommandQueueProvider
@Inject lateinit var ctx: Context
private var isPercentPump = true
@ -103,12 +105,12 @@ class TempBasalDialog : DialogFragmentWithDate() {
val callback: Callback = object : Callback() {
override fun run() {
if (!result.success) {
val i = Intent(context, ErrorHelperActivity::class.java)
val i = Intent(ctx, ErrorHelperActivity::class.java)
i.putExtra("soundid", R.raw.boluserror)
i.putExtra("status", result.comment)
i.putExtra("title", resourceHelper.gs(R.string.tempbasaldeliveryerror))
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context?.startActivity(i)
ctx.startActivity(i)
}
}
}

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.dialogs
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.text.Editable
@ -36,6 +37,7 @@ class TreatmentDialog : DialogFragmentWithDate() {
@Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var activePlugin: ActivePluginProvider
@Inject lateinit var commandQueue: CommandQueueProvider
@Inject lateinit var ctx: Context
private val textWatcher: TextWatcher = object : TextWatcher {
override fun afterTextChanged(s: Editable) {}
@ -118,12 +120,12 @@ class TreatmentDialog : DialogFragmentWithDate() {
commandQueue.bolus(detailedBolusInfo, object : Callback() {
override fun run() {
if (!result.success) {
val i = Intent(context, ErrorHelperActivity::class.java)
val i = Intent(ctx, ErrorHelperActivity::class.java)
i.putExtra("soundid", R.raw.boluserror)
i.putExtra("status", result.comment)
i.putExtra("title", resourceHelper.gs(R.string.treatmentdeliveryerror))
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context?.startActivity(i)
ctx.startActivity(i)
}
}
})

View file

@ -96,7 +96,7 @@ class OpenAPSAMAFragment : DaggerFragment() {
openapsma_scriptdebugdata.text = determineBasalAdapterAMAJS.scriptDebug
}
if (openAPSAMAPlugin.lastAPSRun != 0L) {
openapsma_lastrun.text = DateUtil.dateAndTimeFullString(openAPSAMAPlugin.lastAPSRun)
openapsma_lastrun.text = DateUtil.dateAndTimeString(openAPSAMAPlugin.lastAPSRun)
}
openAPSAMAPlugin.lastAutosensResult?.let {
openapsma_autosensdata.text = JSONFormatter.format(it.json())

View file

@ -99,7 +99,7 @@ class OpenAPSSMBFragment : DaggerFragment() {
}
}
if (openAPSSMBPlugin.lastAPSRun != 0L) {
openapsma_lastrun.text = DateUtil.dateAndTimeFullString(openAPSSMBPlugin.lastAPSRun)
openapsma_lastrun.text = DateUtil.dateAndTimeString(openAPSSMBPlugin.lastAPSRun)
}
openAPSSMBPlugin.lastAutosensResult?.let {
openapsma_autosensdata.text = JSONFormatter.format(it.json())

View file

@ -475,7 +475,6 @@ public class ConfigBuilderPlugin extends PluginBase implements ActivePluginProvi
}
private void confirmPumpPluginActivation(@NonNull PluginBase changedPlugin, boolean newState, @Nullable FragmentActivity activity, @NonNull PluginType type) {
if (type == PluginType.PUMP) {
boolean allowHardwarePump = sp.getBoolean("allow_hardware_pump", false);
if (allowHardwarePump || activity == null) {
performPluginSwitch(changedPlugin, newState, type);
@ -489,14 +488,11 @@ public class ConfigBuilderPlugin extends PluginBase implements ActivePluginProvi
aapsLogger.debug(LTag.PUMP, "User does not allow switching to HW pump!");
});
}
} else {
performPluginSwitch(changedPlugin, newState, type);
}
}
private void performPluginSwitch(PluginBase changedPlugin, boolean enabled, @NonNull PluginType type) {
setPluginEnabled(type, enabled);
setFragmentVisible(type, enabled);
changedPlugin.setPluginEnabled(type, enabled);
changedPlugin.setFragmentVisible(type, enabled);
processOnEnabledCategoryChanged(changedPlugin, type);
storeSettings("CheckedCheckboxEnabled");
rxBus.send(new EventRebuildTabs());

View file

@ -64,7 +64,8 @@ class ActionStringHandler @Inject constructor(
private val danaRPlugin: DanaRPlugin,
private val danaRKoreanPlugin: DanaRKoreanPlugin,
private val danaRv2Plugin: DanaRv2Plugin,
private val danaRSPlugin: DanaRSPlugin
private val danaRSPlugin: DanaRSPlugin,
private val danaRPump: DanaRPump
) {
private val TIMEOUT = 65 * 1000
@ -321,7 +322,7 @@ class ActionStringHandler @Inject constructor(
message += "Today: " + DecimalFormatter.to2Decimal(tdd) + "U " + (DecimalFormatter.to0Decimal(100 * tdd / refTDD) + "%") + "\n"
message += "\n"
} else if (pump != null && pump is DanaRPlugin) {
val tdd = DanaRPump.getInstance().dailyTotalUnits
val tdd = danaRPump.dailyTotalUnits
message += "Today: " + DecimalFormatter.to2Decimal(tdd) + "U " + (DecimalFormatter.to0Decimal(100 * tdd / refTDD) + "%") + "\n"
message += "\n"
}

View file

@ -444,7 +444,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
if (limitDataToOldestAvailable) {
getBGDataFrom = Math.max(oldestDataAvailable, (long) (from - T.hours(1).msecs() * (24 + dia)));
if (getBGDataFrom == oldestDataAvailable)
getAapsLogger().debug(LTag.AUTOSENS, "Limiting data to oldest available temps: " + DateUtil.dateAndTimeFullString(oldestDataAvailable));
getAapsLogger().debug(LTag.AUTOSENS, "Limiting data to oldest available temps: " + DateUtil.dateAndTimeString(oldestDataAvailable));
} else
getBGDataFrom = (long) (from - T.hours(1).msecs() * (24 + dia));
return getBGDataFrom;
@ -807,10 +807,10 @@ public class IobCobCalculatorPlugin extends PluginBase {
synchronized (dataLock) {
// clear up 5 min back for proper COB calculation
long time = ev.getTime() - 5 * 60 * 1000L;
getAapsLogger().debug(LTag.AUTOSENS, "Invalidating cached data to: " + DateUtil.dateAndTimeFullString(time));
getAapsLogger().debug(LTag.AUTOSENS, "Invalidating cached data to: " + DateUtil.dateAndTimeString(time));
for (int index = iobTable.size() - 1; index >= 0; index--) {
if (iobTable.keyAt(index) > time) {
getAapsLogger().debug(LTag.AUTOSENS, "Removing from iobTable: " + DateUtil.dateAndTimeFullString(iobTable.keyAt(index)));
getAapsLogger().debug(LTag.AUTOSENS, "Removing from iobTable: " + DateUtil.dateAndTimeString(iobTable.keyAt(index)));
iobTable.removeAt(index);
} else {
break;
@ -818,7 +818,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
}
for (int index = autosensDataTable.size() - 1; index >= 0; index--) {
if (autosensDataTable.keyAt(index) > time) {
getAapsLogger().debug(LTag.AUTOSENS, "Removing from autosensDataTable: " + DateUtil.dateAndTimeFullString(autosensDataTable.keyAt(index)));
getAapsLogger().debug(LTag.AUTOSENS, "Removing from autosensDataTable: " + DateUtil.dateAndTimeString(autosensDataTable.keyAt(index)));
autosensDataTable.removeAt(index);
} else {
break;
@ -826,7 +826,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
}
for (int index = basalDataTable.size() - 1; index >= 0; index--) {
if (basalDataTable.keyAt(index) > time) {
getAapsLogger().debug(LTag.AUTOSENS, "Removing from basalDataTable: " + DateUtil.dateAndTimeFullString(basalDataTable.keyAt(index)));
getAapsLogger().debug(LTag.AUTOSENS, "Removing from basalDataTable: " + DateUtil.dateAndTimeString(basalDataTable.keyAt(index)));
basalDataTable.removeAt(index);
} else {
break;

View file

@ -28,6 +28,7 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.PumpPluginBase;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.common.ManufacturerType;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
@ -57,8 +58,13 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
protected boolean useExtendedBoluses = false;
public PumpDescription pumpDescription = new PumpDescription();
protected DanaRPump danaRPump;
protected AbstractDanaRPlugin(ResourceHelper resourceHelper, AAPSLogger aapsLogger, CommandQueueProvider commandQueue) {
protected AbstractDanaRPlugin(
DanaRPump danaRPump,
ResourceHelper resourceHelper,
AAPSLogger aapsLogger,
CommandQueueProvider commandQueue) {
super(new PluginDescription()
.mainType(PluginType.PUMP)
.fragmentClass(DanaRFragment.class.getName())
@ -68,11 +74,12 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
.description(R.string.description_pump_dana_r),
aapsLogger, resourceHelper, commandQueue
);
this.danaRPump = danaRPump;
}
@Override
public boolean isSuspended() {
return DanaRPump.getInstance().pumpSuspended;
return danaRPump.getPumpSuspended();
}
@Override
@ -121,13 +128,12 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
public boolean isThisProfileSet(Profile profile) {
if (!isInitialized())
return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS
DanaRPump pump = DanaRPump.getInstance();
if (pump.pumpProfiles == null)
if (danaRPump.getPumpProfiles() == null)
return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS
int basalValues = pump.basal48Enable ? 48 : 24;
int basalIncrement = pump.basal48Enable ? 30 * 60 : 60 * 60;
int basalValues = danaRPump.getBasal48Enable() ? 48 : 24;
int basalIncrement = danaRPump.getBasal48Enable() ? 30 * 60 : 60 * 60;
for (int h = 0; h < basalValues; h++) {
Double pumpValue = pump.pumpProfiles[pump.activeProfile][h];
Double pumpValue = danaRPump.getPumpProfiles()[danaRPump.getActiveProfile()][h];
Double profileValue = profile.getBasalTimeFromMidnight(h * basalIncrement);
if (Math.abs(pumpValue - profileValue) > getPumpDescription().basalStep) {
if (L.isEnabled(L.PUMP))
@ -140,22 +146,22 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
@Override
public long lastDataTime() {
return DanaRPump.getInstance().lastConnection;
return danaRPump.getLastConnection();
}
@Override
public double getBaseBasalRate() {
return DanaRPump.getInstance().currentBasal;
return danaRPump.getCurrentBasal();
}
@Override
public double getReservoirLevel() {
return DanaRPump.getInstance().reservoirRemainingUnits;
return danaRPump.getReservoirRemainingUnits();
}
@Override
public int getBatteryLevel() {
return DanaRPump.getInstance().batteryRemaining;
return danaRPump.getBatteryRemaining();
}
@Override
@ -169,7 +175,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
@NonNull @Override
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
DanaRPump pump = DanaRPump.getInstance();
DanaRPump pump = danaRPump;
PumpEnactResult result = new PumpEnactResult();
percent = ConstraintChecker.getInstance().applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
if (percent < 0) {
@ -189,8 +195,8 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
result.success = true;
result.isTempCancel = false;
result.comment = MainApp.gs(R.string.virtualpump_resultok);
result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent;
result.duration = pump.getTempBasalRemainingMin();
result.percent = pump.getTempBasalPercent();
result.isPercent = true;
if (L.isEnabled(L.PUMP))
log.debug("setTempBasalPercent: Correct value already set");
@ -198,13 +204,13 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
}
int durationInHours = Math.max(durationInMinutes / 60, 1);
boolean connectionOK = sExecutionService.tempBasal(percent, durationInHours);
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
if (connectionOK && pump.isTempBasalInProgress() && pump.getTempBasalPercent() == percent) {
result.enacted = true;
result.success = true;
result.comment = MainApp.gs(R.string.virtualpump_resultok);
result.isTempCancel = false;
result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent;
result.duration = pump.getTempBasalRemainingMin();
result.percent = pump.getTempBasalPercent();
result.isPercent = true;
if (L.isEnabled(L.PUMP))
log.debug("setTempBasalPercent: OK");
@ -219,7 +225,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
@NonNull @Override
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
DanaRPump pump = DanaRPump.getInstance();
DanaRPump pump = danaRPump;
insulin = ConstraintChecker.getInstance().applyExtendedBolusConstraints(new Constraint<>(insulin)).value();
// needs to be rounded
int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
@ -231,24 +237,24 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
result.enacted = false;
result.success = true;
result.comment = MainApp.gs(R.string.virtualpump_resultok);
result.duration = pump.extendedBolusRemainingMinutes;
result.absolute = pump.extendedBolusAbsoluteRate;
result.duration = pump.getExtendedBolusRemainingMinutes();
result.absolute = pump.getExtendedBolusAbsoluteRate();
result.isPercent = false;
result.isTempCancel = false;
if (L.isEnabled(L.PUMP))
log.debug("setExtendedBolus: Correct extended bolus already set. Current: " + pump.extendedBolusAmount + " Asked: " + insulin);
log.debug("setExtendedBolus: Correct extended bolus already set. Current: " + pump.getExtendedBolusAmount() + " Asked: " + insulin);
return result;
}
boolean connectionOK = sExecutionService.extendedBolus(insulin, durationInHalfHours);
if (connectionOK && pump.isExtendedInProgress && Math.abs(pump.extendedBolusAmount - insulin) < getPumpDescription().extendedBolusStep) {
if (connectionOK && pump.isExtendedInProgress() && Math.abs(pump.getExtendedBolusAmount() - insulin) < getPumpDescription().extendedBolusStep) {
result.enacted = true;
result.success = true;
result.comment = MainApp.gs(R.string.virtualpump_resultok);
result.isTempCancel = false;
result.duration = pump.extendedBolusRemainingMinutes;
result.absolute = pump.extendedBolusAbsoluteRate;
result.duration = pump.getExtendedBolusRemainingMinutes();
result.absolute = pump.getExtendedBolusAbsoluteRate();
if (!SP.getBoolean("danar_useextended", false))
result.bolusDelivered = pump.extendedBolusAmount;
result.bolusDelivered = pump.getExtendedBolusAmount();
result.isPercent = false;
if (L.isEnabled(L.PUMP))
log.debug("setExtendedBolus: OK");
@ -270,7 +276,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
result.enacted = true;
result.isTempCancel = true;
}
if (!DanaRPump.getInstance().isExtendedInProgress) {
if (!danaRPump.isExtendedInProgress()) {
result.success = true;
result.comment = MainApp.gs(R.string.virtualpump_resultok);
if (L.isEnabled(L.PUMP))
@ -288,8 +294,8 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
public void connect(String from) {
if (sExecutionService != null) {
sExecutionService.connect();
pumpDescription.basalStep = DanaRPump.getInstance().basalStep;
pumpDescription.bolusStep = DanaRPump.getInstance().bolusStep;
pumpDescription.basalStep = danaRPump.getBasalStep();
pumpDescription.bolusStep = danaRPump.getBolusStep();
}
}
@ -317,16 +323,16 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
public void getPumpStatus() {
if (sExecutionService != null) {
sExecutionService.getPumpStatus();
pumpDescription.basalStep = DanaRPump.getInstance().basalStep;
pumpDescription.bolusStep = DanaRPump.getInstance().bolusStep;
pumpDescription.basalStep = danaRPump.getBasalStep();
pumpDescription.bolusStep = danaRPump.getBolusStep();
}
}
@NonNull @Override
public JSONObject getJSONStatus(Profile profile, String profilename) {
DanaRPump pump = DanaRPump.getInstance();
DanaRPump pump = danaRPump;
long now = System.currentTimeMillis();
if (pump.lastConnection + 5 * 60 * 1000L < System.currentTimeMillis()) {
if (pump.getLastConnection() + 5 * 60 * 1000L < System.currentTimeMillis()) {
return null;
}
JSONObject pumpjson = new JSONObject();
@ -334,14 +340,13 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
JSONObject status = new JSONObject();
JSONObject extended = new JSONObject();
try {
battery.put("percent", pump.batteryRemaining);
status.put("status", pump.pumpSuspended ? "suspended" : "normal");
status.put("timestamp", DateUtil.toISOString(pump.lastConnection));
battery.put("percent", pump.getBatteryRemaining());
status.put("status", pump.getPumpSuspended() ? "suspended" : "normal");
status.put("timestamp", DateUtil.toISOString(pump.getLastConnection()));
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
extended.put("PumpIOB", pump.iob);
if (pump.lastBolusTime != 0) {
extended.put("LastBolus", DateUtil.dateAndTimeFullString(pump.lastBolusTime));
extended.put("LastBolusAmount", pump.lastBolusAmount);
if (pump.getLastBolusTime() != 0) {
extended.put("LastBolus", DateUtil.dateAndTimeString(pump.getLastBolusTime()));
extended.put("LastBolusAmount", pump.getLastBolusAmount());
}
TemporaryBasal tb = TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(now);
if (tb != null) {
@ -364,7 +369,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
pumpjson.put("battery", battery);
pumpjson.put("status", status);
pumpjson.put("extended", extended);
pumpjson.put("reservoir", (int) pump.reservoirRemainingUnits);
pumpjson.put("reservoir", (int) pump.getReservoirRemainingUnits());
pumpjson.put("clock", DateUtil.toISOString(new Date()));
} catch (JSONException e) {
log.error("Unhandled exception", e);
@ -379,7 +384,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
@NonNull @Override
public String serialNumber() {
return DanaRPump.getInstance().serialNumber;
return danaRPump.getSerialNumber();
}
@NonNull @Override
@ -402,7 +407,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
@Override
public Constraint<Double> applyBasalConstraints(Constraint<Double> absoluteRate, Profile profile) {
absoluteRate.setIfSmaller(DanaRPump.getInstance().maxBasal, String.format(MainApp.gs(R.string.limitingbasalratio), DanaRPump.getInstance().maxBasal, MainApp.gs(R.string.pumplimit)), this);
absoluteRate.setIfSmaller(danaRPump.getMaxBasal(), String.format(MainApp.gs(R.string.limitingbasalratio), danaRPump.getMaxBasal(), MainApp.gs(R.string.pumplimit)), this);
return absoluteRate;
}
@ -416,7 +421,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
@Override
public Constraint<Double> applyBolusConstraints(Constraint<Double> insulin) {
insulin.setIfSmaller(DanaRPump.getInstance().maxBolus, String.format(MainApp.gs(R.string.limitingbolus), DanaRPump.getInstance().maxBolus, MainApp.gs(R.string.pumplimit)), this);
insulin.setIfSmaller(danaRPump.getMaxBolus(), String.format(MainApp.gs(R.string.limitingbolus), danaRPump.getMaxBolus(), MainApp.gs(R.string.pumplimit)), this);
return insulin;
}
@ -432,15 +437,15 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
// Reply for sms communicator
@NonNull public String shortStatus(boolean veryShort) {
DanaRPump pump = DanaRPump.getInstance();
DanaRPump pump = danaRPump;
String ret = "";
if (pump.lastConnection != 0) {
Long agoMsec = System.currentTimeMillis() - pump.lastConnection;
if (pump.getLastConnection() != 0) {
Long agoMsec = System.currentTimeMillis() - pump.getLastConnection();
int agoMin = (int) (agoMsec / 60d / 1000d);
ret += "LastConn: " + agoMin + " minago\n";
}
if (pump.lastBolusTime != 0) {
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
if (pump.getLastBolusTime() != 0) {
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.getLastBolusAmount()) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.getLastBolusTime()) + "\n";
}
TemporaryBasal activeTemp = TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis());
if (activeTemp != null) {
@ -451,10 +456,10 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
ret += "Extended: " + activeExtendedBolus.toString() + "\n";
}
if (!veryShort) {
ret += "TDD: " + DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U\n";
ret += "TDD: " + DecimalFormatter.to0Decimal(pump.getDailyTotalUnits()) + " / " + pump.getMaxDailyTotalUnits() + " U\n";
}
ret += "Reserv: " + DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + "U\n";
ret += "Batt: " + pump.batteryRemaining + "\n";
ret += "Reserv: " + DecimalFormatter.to0Decimal(pump.getReservoirRemainingUnits()) + "U\n";
ret += "Batt: " + pump.getBatteryRemaining() + "\n";
return ret;
}
// TODO: daily total constraint

View file

@ -43,6 +43,7 @@ class DanaRFragment : DaggerFragment() {
@Inject lateinit var commandQueue: CommandQueueProvider
@Inject lateinit var activePlugin: ActivePluginProvider
@Inject lateinit var danaRKoreanPlugin: DanaRKoreanPlugin
@Inject lateinit var danaRPump: DanaRPump
@Inject lateinit var resourceHelper: ResourceHelper
private var disposable: CompositeDisposable = CompositeDisposable()
@ -70,9 +71,9 @@ class DanaRFragment : DaggerFragment() {
danar_history.setOnClickListener { startActivity(Intent(context, DanaRHistoryActivity::class.java)) }
danar_viewprofile.setOnClickListener {
fragmentManager?.let { fragmentManager ->
val profile = DanaRPump.getInstance().createConvertedProfile()?.getDefaultProfile()
val profile = danaRPump.createConvertedProfile()?.getDefaultProfile()
?: return@let
val profileName = DanaRPump.getInstance().createConvertedProfile()?.getDefaultProfileName()
val profileName = danaRPump.createConvertedProfile()?.getDefaultProfileName()
?: return@let
val args = Bundle()
args.putLong("time", DateUtil.now())
@ -89,7 +90,7 @@ class DanaRFragment : DaggerFragment() {
danar_user_options.setOnClickListener { startActivity(Intent(context, DanaRUserOptionsActivity::class.java)) }
danar_btconnection.setOnClickListener {
aapsLogger.debug(LTag.PUMP, "Clicked connect to pump")
DanaRPump.getInstance().lastConnection = 0
danaRPump.lastConnection = 0
commandQueue.readStatus("Clicked connect to pump", null)
}
}
@ -150,7 +151,7 @@ class DanaRFragment : DaggerFragment() {
@Synchronized
internal fun updateGUI() {
if (danar_dailyunits == null) return
val pump = DanaRPump.getInstance()
val pump = danaRPump
val plugin: PumpInterface = activePlugin.activePump
if (pump.lastConnection != 0L) {
val agoMsec = System.currentTimeMillis() - pump.lastConnection

View file

@ -51,15 +51,6 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
private final TreatmentsPlugin treatmentsPlugin;
private final SP sp;
private static DanaRPlugin plugin = null;
@Deprecated
public static DanaRPlugin getPlugin() {
if (plugin == null)
throw new IllegalStateException("Accessing DanaRPlugin before first instantiation");
return plugin;
}
@Inject
public DanaRPlugin(
AAPSLogger aapsLogger,
@ -69,10 +60,10 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
ConstraintChecker constraintChecker,
TreatmentsPlugin treatmentsPlugin,
SP sp,
CommandQueueProvider commandQueue
CommandQueueProvider commandQueue,
DanaRPump danaRPump
) {
super(resourceHelper, aapsLogger, commandQueue);
plugin = this;
super(danaRPump, resourceHelper, aapsLogger, commandQueue);
this.aapsLogger = aapsLogger;
this.rxBus = rxBus;
this.mainApp = maiApp;
@ -153,8 +144,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
@Override
public boolean isInitialized() {
DanaRPump pump = DanaRPump.getInstance();
return pump.lastConnection > 0 && pump.isExtendedBolusEnabled && pump.maxBasal > 0 && pump.isPasswordOK();
return danaRPump.getLastConnection() > 0 && danaRPump.isExtendedBolusEnabled() && danaRPump.getMaxBasal() > 0 && danaRPump.isPasswordOK();
}
@Override
@ -208,8 +198,6 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
//if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
// connect("setTempBasalAbsolute old data");
//}
DanaRPump pump = DanaRPump.getInstance();
PumpEnactResult result = new PumpEnactResult();
absoluteRate = constraintChecker.applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
@ -305,16 +293,16 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
extendedRateToSet = Round.roundTo(extendedRateToSet, pumpDescription.extendedBolusStep * 2); // *2 because of halfhours
// What is current rate of extended bolusing in u/h?
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Extended bolus in progress: " + (activeExtended != null) + " rate: " + pump.extendedBolusAbsoluteRate + "U/h duration remaining: " + pump.extendedBolusRemainingMinutes + "min");
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Extended bolus in progress: " + (activeExtended != null) + " rate: " + danaRPump.getExtendedBolusAbsoluteRate()+ "U/h duration remaining: " + danaRPump.getExtendedBolusRemainingMinutes() + "min");
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Rate to set: " + extendedRateToSet + "U/h");
// Compare with extended rate in progress
if (activeExtended != null && Math.abs(pump.extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
if (activeExtended != null && Math.abs(danaRPump.getExtendedBolusAbsoluteRate() - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
// correct extended already set
result.success = true;
result.absolute = pump.extendedBolusAbsoluteRate;
result.absolute = danaRPump.getExtendedBolusAbsoluteRate();
result.enacted = false;
result.duration = pump.extendedBolusRemainingMinutes;
result.duration = danaRPump.getExtendedBolusRemainingMinutes();
result.isPercent = false;
result.isTempCancel = false;
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Correct extended already set");
@ -368,7 +356,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
result.enacted = true;
result.isTempCancel = true;
}
if (!DanaRPump.getInstance().isTempBasalInProgress) {
if (!danaRPump.isTempBasalInProgress()) {
result.success = true;
result.isTempCancel = true;
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);

View file

@ -1,252 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.text.DecimalFormat;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 04.07.2016.
*/
public class DanaRPump {
private static Logger log = LoggerFactory.getLogger(L.PUMP);
private static DanaRPump instance = null;
public static DanaRPump getInstance() {
if (instance == null) instance = new DanaRPump();
return instance;
}
public static void reset() {
log.debug("DanaRPump reset");
instance = null;
}
public static final int UNITS_MGDL = 0;
public static final int UNITS_MMOL = 1;
public static final int DELIVERY_PRIME = 0x01;
public static final int DELIVERY_STEP_BOLUS = 0x02;
public static final int DELIVERY_BASAL = 0x04;
public static final int DELIVERY_EXT_BOLUS = 0x08;
public static final String PROFILE_PREFIX = "DanaR-";
// v2 history entries
public static final int TEMPSTART = 1;
public static final int TEMPSTOP = 2;
public static final int EXTENDEDSTART = 3;
public static final int EXTENDEDSTOP = 4;
public static final int BOLUS = 5;
public static final int DUALBOLUS = 6;
public static final int DUALEXTENDEDSTART = 7;
public static final int DUALEXTENDEDSTOP = 8;
public static final int SUSPENDON = 9;
public static final int SUSPENDOFF = 10;
public static final int REFILL = 11;
public static final int PRIME = 12;
public static final int PROFILECHANGE = 13;
public static final int CARBS = 14;
public static final int PRIMECANNULA = 15;
public long lastConnection = 0;
public long lastSettingsRead = 0;
// Info
public String serialNumber = "";
public long shippingDate = 0;
public String shippingCountry = "";
public boolean isNewPump = true;
public int password = -1;
public long pumpTime = 0;
public static final int DOMESTIC_MODEL = 0x01;
public static final int EXPORT_MODEL = 0x03;
public int model = 0;
public int protocol = 0;
public int productCode = 0;
public boolean isConfigUD;
public boolean isExtendedBolusEnabled;
public boolean isEasyModeEnabled;
// Status
public boolean pumpSuspended;
public boolean calculatorEnabled;
public double dailyTotalUnits;
public double dailyTotalBolusUnits = 0; // RS only
public double dailyTotalBasalUnits = 0; // RS only
public int maxDailyTotalUnits;
public double bolusStep = 0.1;
public double basalStep = 0.1;
public double iob;
public double reservoirRemainingUnits;
public int batteryRemaining;
public boolean bolusBlocked;
public long lastBolusTime = 0;
public double lastBolusAmount;
public double currentBasal;
public boolean isTempBasalInProgress;
public int tempBasalPercent;
public int tempBasalRemainingMin;
public int tempBasalTotalSec;
public long tempBasalStart;
public boolean isDualBolusInProgress;
public boolean isExtendedInProgress;
public int extendedBolusMinutes;
public double extendedBolusAmount;
public double extendedBolusAbsoluteRate;
public int extendedBolusSoFarInMinutes;
public long extendedBolusStart;
public int extendedBolusRemainingMinutes;
public double extendedBolusDeliveredSoFar; //RS only
// Profile
public int units;
public int easyBasalMode;
public boolean basal48Enable = false;
public int currentCIR;
public double currentCF;
public double currentAI;
public double currentTarget;
public int currentAIDR;
public int morningCIR;
public double morningCF;
public int afternoonCIR;
public double afternoonCF;
public int eveningCIR;
public double eveningCF;
public int nightCIR;
public double nightCF;
public int activeProfile = 0;
public double[][] pumpProfiles = null;
//Limits
public double maxBolus;
public double maxBasal;
// DanaRS specific
public String rs_password = "";
// User settings
public int timeDisplayType;
public int buttonScrollOnOff;
public int beepAndAlarm;
public int lcdOnTimeSec;
public int backlightOnTimeSec;
public int selectedLanguage;
public int shutdownHour;
public int lowReservoirRate;
public int cannulaVolume;
public int refillAmount;
public byte[] userOptionsFrompump;
public double initialBolusAmount;
// Bolus settings
public int bolusCalculationOption;
public int missedBolusConfig;
public String getUnits() {
return units == UNITS_MGDL ? Constants.MGDL : Constants.MMOL;
}
public ProfileStore createConvertedProfile() {
JSONObject json = new JSONObject();
JSONObject store = new JSONObject();
JSONObject profile = new JSONObject();
// Morning / 6:0010:59
// Afternoon / 11:0016:59
// Evening / 17:0021:59
// Night / 22:005:59
try {
json.put("defaultProfile", PROFILE_PREFIX + (activeProfile + 1));
json.put("store", store);
profile.put("dia", Constants.defaultDIA);
JSONArray carbratios = new JSONArray();
carbratios.put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", nightCIR));
carbratios.put(new JSONObject().put("time", "06:00").put("timeAsSeconds", 6 * 3600).put("value", morningCIR));
carbratios.put(new JSONObject().put("time", "11:00").put("timeAsSeconds", 11 * 3600).put("value", afternoonCIR));
carbratios.put(new JSONObject().put("time", "14:00").put("timeAsSeconds", 17 * 3600).put("value", eveningCIR));
carbratios.put(new JSONObject().put("time", "22:00").put("timeAsSeconds", 22 * 3600).put("value", nightCIR));
profile.put("carbratio", carbratios);
JSONArray sens = new JSONArray();
sens.put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", nightCF));
sens.put(new JSONObject().put("time", "06:00").put("timeAsSeconds", 6 * 3600).put("value", morningCF));
sens.put(new JSONObject().put("time", "11:00").put("timeAsSeconds", 11 * 3600).put("value", afternoonCF));
sens.put(new JSONObject().put("time", "17:00").put("timeAsSeconds", 17 * 3600).put("value", eveningCF));
sens.put(new JSONObject().put("time", "22:00").put("timeAsSeconds", 22 * 3600).put("value", nightCF));
profile.put("sens", sens);
JSONArray basals = new JSONArray();
int basalValues = basal48Enable ? 48 : 24;
int basalIncrement = basal48Enable ? 30 * 60 : 60 * 60;
for (int h = 0; h < basalValues; h++) {
String time;
DecimalFormat df = new DecimalFormat("00");
if (basal48Enable) {
time = df.format((long) h / 2) + ":" + df.format(30 * (h % 2));
} else {
time = df.format(h) + ":00";
}
basals.put(new JSONObject().put("time", time).put("timeAsSeconds", h * basalIncrement).put("value", pumpProfiles[activeProfile][h]));
}
profile.put("basal", basals);
profile.put("target_low", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", currentTarget)));
profile.put("target_high", new JSONArray().put(new JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", currentTarget)));
profile.put("units", units == UNITS_MGDL ? Constants.MGDL : Constants.MMOL);
store.put(PROFILE_PREFIX + (activeProfile + 1), profile);
} catch (JSONException e) {
log.error("Unhandled exception", e);
} catch (Exception e) {
return null;
}
return new ProfileStore(json);
}
public double[] buildDanaRProfileRecord(Profile nsProfile) {
double[] record = new double[24];
for (Integer hour = 0; hour < 24; hour++) {
//Some values get truncated to the next lower one.
// -> round them to two decimals and make sure we are a small delta larger (that will get truncated)
double value = Math.round(100d * nsProfile.getBasalTimeFromMidnight((Integer) (hour * 60 * 60))) / 100d + 0.00001;
if (L.isEnabled(L.PUMP))
log.debug("NS basal value for " + hour + ":00 is " + value);
record[hour] = value;
}
return record;
}
public boolean isPasswordOK() {
if (password != -1 && password != SP.getInt(R.string.key_danar_password, -1)) {
return false;
}
return true;
}
}

View file

@ -0,0 +1,218 @@
package info.nightscout.androidaps.plugins.pump.danaR
import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.data.ProfileStore
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.utils.sharedPreferences.SP
import org.json.JSONArray
import org.json.JSONException
import org.json.JSONObject
import java.text.DecimalFormat
import javax.inject.Inject
import javax.inject.Singleton
/**
* Created by mike on 04.07.2016.
*/
@Singleton
class DanaRPump @Inject constructor(
private val aapsLogger: AAPSLogger,
private val sp: SP
) {
var lastConnection: Long = 0
var lastSettingsRead: Long = 0
// Info
var serialNumber = ""
var shippingDate: Long = 0
var shippingCountry = ""
var isNewPump = true
var password = -1
var pumpTime: Long = 0
var model = 0
var protocol = 0
var productCode = 0
var isConfigUD = false
var isExtendedBolusEnabled = false
var isEasyModeEnabled = false
// Status
var pumpSuspended = false
var calculatorEnabled = false
var dailyTotalUnits = 0.0
var dailyTotalBolusUnits = 0.0 // RS only
var dailyTotalBasalUnits = 0.0 // RS only
var maxDailyTotalUnits = 0
var bolusStep = 0.1
var basalStep = 0.1
var iob = 0.0
var reservoirRemainingUnits = 0.0
var batteryRemaining = 0
var bolusBlocked = false
var lastBolusTime: Long = 0
var lastBolusAmount = 0.0
var currentBasal = 0.0
var isTempBasalInProgress = false
var tempBasalPercent = 0
var tempBasalRemainingMin = 0
var tempBasalTotalSec = 0
var tempBasalStart: Long = 0
var isDualBolusInProgress = false
var isExtendedInProgress = false
var extendedBolusMinutes = 0
var extendedBolusAmount = 0.0
var extendedBolusAbsoluteRate = 0.0
var extendedBolusSoFarInMinutes = 0
var extendedBolusStart: Long = 0
var extendedBolusRemainingMinutes = 0
var extendedBolusDeliveredSoFar = 0.0 //RS only = 0.0
// Profile
var units = 0
var easyBasalMode = 0
var basal48Enable = false
var currentCIR = 0
var currentCF = 0.0
var currentAI = 0.0
var currentTarget = 0.0
var currentAIDR = 0
var morningCIR = 0
var morningCF = 0.0
var afternoonCIR = 0
var afternoonCF = 0.0
var eveningCIR = 0
var eveningCF = 0.0
var nightCIR = 0
var nightCF = 0.0
var activeProfile = 0
//var pumpProfiles = arrayOf<Array<Double>>()
var pumpProfiles : Array<Array<Double>>? = null
//Limits
var maxBolus = 0.0
var maxBasal = 0.0
// DanaRS specific
var rsPassword = ""
// User settings
var timeDisplayType = 0
var buttonScrollOnOff = 0
var beepAndAlarm = 0
var lcdOnTimeSec = 0
var backlightOnTimeSec = 0
var selectedLanguage = 0
var shutdownHour = 0
var lowReservoirRate = 0
var cannulaVolume = 0
var refillAmount = 0
var userOptionsFrompump: ByteArray? = null
var initialBolusAmount = 0.0
// Bolus settings
var bolusCalculationOption = 0
var missedBolusConfig = 0
fun getUnits(): String {
return if (units == UNITS_MGDL) Constants.MGDL else Constants.MMOL
}
fun createConvertedProfile(): ProfileStore? {
pumpProfiles?.let {
val json = JSONObject()
val store = JSONObject()
val profile = JSONObject()
// Morning / 6:0010:59
// Afternoon / 11:0016:59
// Evening / 17:0021:59
// Night / 22:005:59
try {
json.put("defaultProfile", PROFILE_PREFIX + (activeProfile + 1))
json.put("store", store)
profile.put("dia", Constants.defaultDIA)
val carbratios = JSONArray()
carbratios.put(JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", nightCIR))
carbratios.put(JSONObject().put("time", "06:00").put("timeAsSeconds", 6 * 3600).put("value", morningCIR))
carbratios.put(JSONObject().put("time", "11:00").put("timeAsSeconds", 11 * 3600).put("value", afternoonCIR))
carbratios.put(JSONObject().put("time", "14:00").put("timeAsSeconds", 17 * 3600).put("value", eveningCIR))
carbratios.put(JSONObject().put("time", "22:00").put("timeAsSeconds", 22 * 3600).put("value", nightCIR))
profile.put("carbratio", carbratios)
val sens = JSONArray()
sens.put(JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", nightCF))
sens.put(JSONObject().put("time", "06:00").put("timeAsSeconds", 6 * 3600).put("value", morningCF))
sens.put(JSONObject().put("time", "11:00").put("timeAsSeconds", 11 * 3600).put("value", afternoonCF))
sens.put(JSONObject().put("time", "17:00").put("timeAsSeconds", 17 * 3600).put("value", eveningCF))
sens.put(JSONObject().put("time", "22:00").put("timeAsSeconds", 22 * 3600).put("value", nightCF))
profile.put("sens", sens)
val basals = JSONArray()
val basalValues = if (basal48Enable) 48 else 24
val basalIncrement = if (basal48Enable) 30 * 60 else 60 * 60
for (h in 0 until basalValues) {
var time: String
val df = DecimalFormat("00")
time = if (basal48Enable) {
df.format(h.toLong() / 2) + ":" + df.format(30 * (h % 2).toLong())
} else {
df.format(h.toLong()) + ":00"
}
basals.put(JSONObject().put("time", time).put("timeAsSeconds", h * basalIncrement).put("value", it[activeProfile][h]))
}
profile.put("basal", basals)
profile.put("target_low", JSONArray().put(JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", currentTarget)))
profile.put("target_high", JSONArray().put(JSONObject().put("time", "00:00").put("timeAsSeconds", 0).put("value", currentTarget)))
profile.put("units", if (units == UNITS_MGDL) Constants.MGDL else Constants.MMOL)
store.put(PROFILE_PREFIX + (activeProfile + 1), profile)
} catch (e: JSONException) {
aapsLogger.error("Unhandled exception", e)
} catch (e: Exception) {
return null
}
return ProfileStore(json)
}
return null
}
fun buildDanaRProfileRecord(nsProfile: Profile): Array<Double> {
val record = Array(24){ 0.0}
for (hour in 0..23) {
//Some values get truncated to the next lower one.
// -> round them to two decimals and make sure we are a small delta larger (that will get truncated)
val value = Math.round(100.0 * nsProfile.getBasalTimeFromMidnight((hour * 60 * 60))) / 100.0 + 0.00001
aapsLogger.debug(LTag.PUMP, "NS basal value for $hour:00 is $value")
record[hour] = value
}
return record
}
val isPasswordOK: Boolean
get() = !(password != -1 && password != sp.getInt(R.string.key_danar_password, -1))
fun reset() {
aapsLogger.debug(LTag.PUMP, "DanaRPump reset")
lastConnection = 0
}
companion object {
const val UNITS_MGDL = 0
const val UNITS_MMOL = 1
const val DELIVERY_PRIME = 0x01
const val DELIVERY_STEP_BOLUS = 0x02
const val DELIVERY_BASAL = 0x04
const val DELIVERY_EXT_BOLUS = 0x08
const val PROFILE_PREFIX = "DanaR-"
// v2 history entries
const val TEMPSTART = 1
const val TEMPSTOP = 2
const val EXTENDEDSTART = 3
const val EXTENDEDSTOP = 4
const val BOLUS = 5
const val DUALBOLUS = 6
const val DUALEXTENDEDSTART = 7
const val DUALEXTENDEDSTOP = 8
const val SUSPENDON = 9
const val SUSPENDOFF = 10
const val REFILL = 11
const val PRIME = 12
const val PROFILECHANGE = 13
const val CARBS = 14
const val PRIMECANNULA = 15
const val DOMESTIC_MODEL = 0x01
const val EXPORT_MODEL = 0x03
}
}

View file

@ -31,10 +31,12 @@ public class SerialIOThread extends AbstractSerialIOThread {
private MessageBase processedMessage;
private MessageHashTableBase hashTable;
private DanaRPump danaRPump;
public SerialIOThread(BluetoothSocket rfcommSocket, MessageHashTableBase hashTable) {
public SerialIOThread(BluetoothSocket rfcommSocket, MessageHashTableBase hashTable, DanaRPump danaRPump) {
super();
this.hashTable = hashTable;
this.danaRPump = danaRPump;
mRfCommSocket = rfcommSocket;
try {
@ -172,7 +174,7 @@ public class SerialIOThread extends AbstractSerialIOThread {
if (L.isEnabled(L.PUMPBTCOMM))
log.error("Reply not received " + message.getMessageName());
if (message.getCommand() == 0xF0F1) {
DanaRPump.getInstance().isNewPump = false;
danaRPump.setNewPump(false);
if (L.isEnabled(L.PUMPCOMM))
log.debug("Old firmware detected");
}

View file

@ -39,6 +39,7 @@ class DanaRUserOptionsActivity : NoSplashAppCompatActivity() {
@Inject lateinit var danaRSPlugin: DanaRSPlugin
@Inject lateinit var danaRPlugin: DanaRPlugin
@Inject lateinit var danaRv2Plugin: DanaRv2Plugin
@Inject lateinit var danaRPump: DanaRPump
@Inject lateinit var commandQueue: CommandQueueProvider
private val disposable = CompositeDisposable()
@ -69,24 +70,23 @@ class DanaRUserOptionsActivity : NoSplashAppCompatActivity() {
setContentView(R.layout.danar_user_options_activity)
save_user_options.setOnClickListener { onSaveClick() }
val pump = DanaRPump.getInstance()
if (L.isEnabled(L.PUMP))
aapsLogger.debug(LTag.PUMP,
"UserOptionsLoaded:" + (System.currentTimeMillis() - pump.lastConnection) / 1000 + " s ago"
+ "\ntimeDisplayType:" + pump.timeDisplayType
+ "\nbuttonScroll:" + pump.buttonScrollOnOff
+ "\ntimeDisplayType:" + pump.timeDisplayType
+ "\nlcdOnTimeSec:" + pump.lcdOnTimeSec
+ "\nbackLight:" + pump.backlightOnTimeSec
+ "\npumpUnits:" + pump.units
+ "\nlowReservoir:" + pump.lowReservoirRate)
"UserOptionsLoaded:" + (System.currentTimeMillis() - danaRPump.lastConnection) / 1000 + " s ago"
+ "\ntimeDisplayType:" + danaRPump.timeDisplayType
+ "\nbuttonScroll:" + danaRPump.buttonScrollOnOff
+ "\ntimeDisplayType:" + danaRPump.timeDisplayType
+ "\nlcdOnTimeSec:" + danaRPump.lcdOnTimeSec
+ "\nbackLight:" + danaRPump.backlightOnTimeSec
+ "\npumpUnits:" + danaRPump.units
+ "\nlowReservoir:" + danaRPump.lowReservoirRate)
danar_screentimeout.setParams(pump.lcdOnTimeSec.toDouble(), 5.0, 240.0, 5.0, DecimalFormat("1"), false, save_user_options)
danar_backlight.setParams(pump.backlightOnTimeSec.toDouble(), 1.0, 60.0, 1.0, DecimalFormat("1"), false, save_user_options)
danar_shutdown.setParams(pump.shutdownHour.toDouble(), 0.0, 24.0, 1.0, DecimalFormat("1"), true, save_user_options)
danar_lowreservoir.setParams(pump.lowReservoirRate.toDouble(), 10.0, 60.0, 10.0, DecimalFormat("10"), false, save_user_options)
when (pump.beepAndAlarm) {
danar_screentimeout.setParams(danaRPump.lcdOnTimeSec.toDouble(), 5.0, 240.0, 5.0, DecimalFormat("1"), false, save_user_options)
danar_backlight.setParams(danaRPump.backlightOnTimeSec.toDouble(), 1.0, 60.0, 1.0, DecimalFormat("1"), false, save_user_options)
danar_shutdown.setParams(danaRPump.shutdownHour.toDouble(), 0.0, 24.0, 1.0, DecimalFormat("1"), true, save_user_options)
danar_lowreservoir.setParams(danaRPump.lowReservoirRate.toDouble(), 10.0, 60.0, 10.0, DecimalFormat("10"), false, save_user_options)
when (danaRPump.beepAndAlarm) {
0x01 -> danar_pumpalarm_sound.isChecked = true
0x02 -> danar_pumpalarm_vibrate.isChecked = true
0x11 -> danar_pumpalarm_both.isChecked = true
@ -106,54 +106,51 @@ class DanaRUserOptionsActivity : NoSplashAppCompatActivity() {
danar_beep.isChecked = true
}
}
if (pump.lastSettingsRead == 0L)
if (danaRPump.lastSettingsRead == 0L)
aapsLogger.error(LTag.PUMP, "No settings loaded from pump!") else setData()
}
fun setData() {
val pump = DanaRPump.getInstance()
// in DanaRS timeDisplay values are reversed
danar_timeformat.isChecked = !isRS() && pump.timeDisplayType != 0 || isRS() && pump.timeDisplayType == 0
danar_buttonscroll.isChecked = pump.buttonScrollOnOff != 0
danar_beep.isChecked = pump.beepAndAlarm > 4
danar_screentimeout.value = pump.lcdOnTimeSec.toDouble()
danar_backlight.value = pump.backlightOnTimeSec.toDouble()
danar_units.isChecked = pump.getUnits() == Constants.MMOL
danar_shutdown.value = pump.shutdownHour.toDouble()
danar_lowreservoir.value = pump.lowReservoirRate.toDouble()
danar_timeformat.isChecked = !isRS() && danaRPump.timeDisplayType != 0 || isRS() && danaRPump.timeDisplayType == 0
danar_buttonscroll.isChecked = danaRPump.buttonScrollOnOff != 0
danar_beep.isChecked = danaRPump.beepAndAlarm > 4
danar_screentimeout.value = danaRPump.lcdOnTimeSec.toDouble()
danar_backlight.value = danaRPump.backlightOnTimeSec.toDouble()
danar_units.isChecked = danaRPump.getUnits() == Constants.MMOL
danar_shutdown.value = danaRPump.shutdownHour.toDouble()
danar_lowreservoir.value = danaRPump.lowReservoirRate.toDouble()
}
private fun onSaveClick() {
//exit if pump is not DanaRS, DanaR, or DanaR with upgraded firmware
if (!isRS() && !isDanaR() && !isDanaRv2()) return
val pump = DanaRPump.getInstance()
if (isRS()) // displayTime on RS is reversed
pump.timeDisplayType = if (danar_timeformat.isChecked) 0 else 1
danaRPump.timeDisplayType = if (danar_timeformat.isChecked) 0 else 1
else
pump.timeDisplayType = if (danar_timeformat.isChecked) 1 else 0
danaRPump.timeDisplayType = if (danar_timeformat.isChecked) 1 else 0
pump.buttonScrollOnOff = if (danar_buttonscroll.isChecked) 1 else 0
pump.beepAndAlarm = when {
danaRPump.buttonScrollOnOff = if (danar_buttonscroll.isChecked) 1 else 0
danaRPump.beepAndAlarm = when {
danar_pumpalarm_sound.isChecked -> 1
danar_pumpalarm_vibrate.isChecked -> 2
danar_pumpalarm_both.isChecked -> 3
else -> 1
}
if (danar_beep.isChecked) pump.beepAndAlarm += 4
if (danar_beep.isChecked) danaRPump.beepAndAlarm += 4
// step is 5 seconds, 5 to 240
pump.lcdOnTimeSec = min(max(danar_screentimeout.value.toInt() / 5 * 5, 5), 240)
danaRPump.lcdOnTimeSec = min(max(danar_screentimeout.value.toInt() / 5 * 5, 5), 240)
// 1 to 60
pump.backlightOnTimeSec = min(max(danar_backlight.value.toInt(), 1), 60)
danaRPump.backlightOnTimeSec = min(max(danar_backlight.value.toInt(), 1), 60)
pump.units = if (danar_units.isChecked) 1 else 0
danaRPump.units = if (danar_units.isChecked) 1 else 0
pump.shutdownHour = min(danar_shutdown.value.toInt(), 24)
danaRPump.shutdownHour = min(danar_shutdown.value.toInt(), 24)
// 10 to 50
pump.lowReservoirRate = min(max(danar_lowreservoir.value.toInt() * 10 / 10, 10), 50)
danaRPump.lowReservoirRate = min(max(danar_lowreservoir.value.toInt() * 10 / 10, 10), 50)
commandQueue.setUserOptions(object : Callback() {
override fun run() {

View file

@ -1,8 +1,31 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper
import java.util.*
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class MessageHashTableR @Inject constructor(
aapsLogger: AAPSLogger,
rxBus: RxBusWrapper,
resourceHelper: ResourceHelper,
danaRPump: DanaRPump,
danaRPlugin: DanaRPlugin,
danaRKoreanPlugin: DanaRKoreanPlugin,
configBuilderPlugin: ConfigBuilderPlugin,
commandQueue: CommandQueueProvider,
activePlugin: ActivePluginProvider
) : MessageHashTableBase {
object MessageHashTableR : MessageHashTableBase {
var messages: HashMap<Int, MessageBase> = HashMap()
init {
@ -10,15 +33,16 @@ object MessageHashTableR : MessageHashTableBase {
put(MsgBolusStart()) // 0x0102 CMD_MEALINS_START_DATA
put(MsgBolusStartWithSpeed()) // 0x0104 CMD_MEALINS_START_DATA_SPEED
put(MsgBolusProgress()) // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS
put(MsgStatusProfile()) // 0x0204 CMD_PUMP_CALCULATION_SETTING
put(MsgStatusTempBasal()) // 0x0205 CMD_PUMP_EXERCISE_MODE
put(MsgStatusBolusExtended()) // 0x0207 CMD_PUMP_EXPANS_INS_I
put(MsgStatusBasic()) // 0x020A CMD_PUMP_INITVIEW_I
put(MsgStatus()) // 0x020B CMD_PUMP_STATUS
put(MsgInitConnStatusTime()) // 0x0301 CMD_PUMPINIT_TIME_INFO
put(MsgInitConnStatusBolus()) // 0x0302 CMD_PUMPINIT_BOLUS_INFO
put(MsgInitConnStatusBasic()) // 0x0303 CMD_PUMPINIT_INIT_INFO
put(MsgInitConnStatusOption()) // 0x0304 CMD_PUMPINIT_OPTION
put(MsgStatusProfile(aapsLogger, danaRPump)) // 0x0204 CMD_PUMP_CALCULATION_SETTING
put(MsgStatusTempBasal(aapsLogger, danaRPump, activePlugin)) // 0x0205 CMD_PUMP_EXERCISE_MODE
put(MsgStatusBolusExtended(aapsLogger, danaRPump, activePlugin)) // 0x0207 CMD_PUMP_EXPANS_INS_I
put(MsgStatusBasic(aapsLogger, danaRPump)) // 0x020A CMD_PUMP_INITVIEW_I
put(MsgStatus(aapsLogger, danaRPump)) // 0x020B CMD_PUMP_STATUS
// 0x0301 CMD_PUMPINIT_TIME_INFO
put(MsgInitConnStatusTime(aapsLogger, rxBus, resourceHelper, danaRPump, danaRPlugin, danaRKoreanPlugin, configBuilderPlugin, commandQueue))
put(MsgInitConnStatusBolus(aapsLogger, rxBus, resourceHelper, danaRPump)) // 0x0302 CMD_PUMPINIT_BOLUS_INFO
put(MsgInitConnStatusBasic(aapsLogger, danaRPump)) // 0x0303 CMD_PUMPINIT_INIT_INFO
put(MsgInitConnStatusOption(aapsLogger, rxBus, resourceHelper, danaRPump, activePlugin)) // 0x0304 CMD_PUMPINIT_OPTION
put(MsgSetTempBasalStart()) // 0x0401 CMD_PUMPSET_EXERCISE_S
put(MsgSetCarbsEntry()) // 0x0402 CMD_PUMPSET_HIS_S
put(MsgSetTempBasalStop()) // 0x0403 CMD_PUMPSET_EXERCISE_STOP
@ -37,26 +61,29 @@ object MessageHashTableR : MessageHashTableBase {
put(MsgHistorySuspend()) // 0x3109 CMD_HISTORY_SUSPEND
put(MsgHistoryBasalHour()) // 0x310A CMD_HISTORY_BASAL_HOUR
put(MsgHistoryDone()) // 0x31F1 CMD_HISTORY_DONT_USED
put(MsgSettingBasal()) // 0x3202 CMD_SETTING_V_BASAL_INS_I
put(MsgSettingMeal()) // 0x3203 CMD_SETTING_V_MEAL_SETTING_I
put(MsgSettingProfileRatios()) // 0x3204 CMD_SETTING_V_CCC_I
put(MsgSettingMaxValues()) // 0x3205 CMD_SETTING_V_MAX_VALUE_I
put(MsgSettingBasalProfileAll()) // 0x3206 CMD_SETTING_V_BASAL_PROFILE_ALL
put(MsgSettingShippingInfo()) // 0x3207 CMD_SETTING_V_SHIPPING_I
put(MsgSettingGlucose()) // 0x3209 CMD_SETTING_V_GLUCOSEandEASY
put(MsgSettingPumpTime()) // 0x320A CMD_SETTING_V_TIME_I
put(MsgSettingUserOptions()) // 0x320B CMD_SETTING_V_USER_OPTIONS
put(MsgSettingActiveProfile()) // 0x320C CMD_SETTING_V_PROFILE_NUMBER
put(MsgSettingProfileRatiosAll()) // 0x320D CMD_SETTING_V_CIR_CF_VALUE
// 0x3202 CMD_SETTING_V_BASAL_INS_I
put(MsgSettingBasal(aapsLogger, danaRPump, danaRPlugin))
// 0x3203 CMD_SETTING_V_MEAL_SETTING_I
put(MsgSettingMeal(aapsLogger, rxBus, resourceHelper, danaRPump, danaRKoreanPlugin))
put(MsgSettingProfileRatios(aapsLogger, danaRPump)) // 0x3204 CMD_SETTING_V_CCC_I
put(MsgSettingMaxValues(aapsLogger, danaRPump)) // 0x3205 CMD_SETTING_V_MAX_VALUE_I
put(MsgSettingBasalProfileAll(aapsLogger, danaRPump)) // 0x3206 CMD_SETTING_V_BASAL_PROFILE_ALL
put(MsgSettingShippingInfo(aapsLogger, danaRPump)) // 0x3207 CMD_SETTING_V_SHIPPING_I
put(MsgSettingGlucose(aapsLogger, danaRPump)) // 0x3209 CMD_SETTING_V_GLUCOSEandEASY
put(MsgSettingPumpTime(aapsLogger, danaRPump)) // 0x320A CMD_SETTING_V_TIME_I
put(MsgSettingUserOptions(aapsLogger, danaRPump)) // 0x320B CMD_SETTING_V_USER_OPTIONS
put(MsgSettingActiveProfile(aapsLogger, danaRPump)) // 0x320C CMD_SETTING_V_PROFILE_NUMBER
put(MsgSettingProfileRatiosAll(aapsLogger, danaRPump)) // 0x320D CMD_SETTING_V_CIR_CF_VALUE
put(MsgSetSingleBasalProfile()) // 0x3302 CMD_SETTING_BASAL_INS_S
put(MsgSetBasalProfile()) // 0x3306 CMD_SETTING_BASAL_PROFILE_S
put(MsgSetUserOptions()) // 0x330B CMD_SETTING_USER_OPTIONS_S
put(MsgSetUserOptions(aapsLogger, danaRPump)) // 0x330B CMD_SETTING_USER_OPTIONS_S
put(MsgSetActivateBasalProfile()) // 0x330C CMD_SETTING_PROFILE_NUMBER_S
put(MsgHistoryAllDone()) // 0x41F1 CMD_HISTORY_ALL_DONE
put(MsgHistoryAll()) // 0x41F2 CMD_HISTORY_ALL
put(MsgHistoryNewDone()) // 0x42F1 CMD_HISTORY_NEW_DONE
put(MsgHistoryNew()) // 0x42F2 CMD_HISTORY_NEW
put(MsgCheckValue()) // 0xF0F1 CMD_PUMP_CHECK_VALUE
// 0xF0F1 CMD_PUMP_CHECK_VALUE
put(MsgCheckValue(aapsLogger, danaRPump, danaRPlugin))
}
override fun put(message: MessageBase) {

View file

@ -1,46 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 30.06.2016.
*/
public class MsgCheckValue extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgCheckValue() {
SetCommand(0xF0F1);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
@Override
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
pump.isNewPump = true;
if (L.isEnabled(L.PUMPCOMM))
log.debug("New firmware confirmed");
pump.model = intFromBuff(bytes, 0, 1);
pump.protocol = intFromBuff(bytes, 1, 1);
pump.productCode = intFromBuff(bytes, 2, 1);
if (pump.model != DanaRPump.EXPORT_MODEL) {
DanaRPlugin.getPlugin().disconnect("Wrong Model");
log.debug("Wrong model selected");
}
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Model: " + String.format("%02X ", pump.model));
log.debug("Protocol: " + String.format("%02X ", pump.protocol));
log.debug("Product Code: " + String.format("%02X ", pump.productCode));
}
}
}

View file

@ -0,0 +1,33 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
class MsgCheckValue(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump,
private val danaRPlugin: DanaRPlugin
) : MessageBase() {
init {
SetCommand(0xF0F1)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
danaRPump.isNewPump = true
aapsLogger.debug(LTag.PUMPCOMM, "New firmware confirmed")
danaRPump.model = intFromBuff(bytes, 0, 1)
danaRPump.protocol = intFromBuff(bytes, 1, 1)
danaRPump.productCode = intFromBuff(bytes, 2, 1)
if (danaRPump.model != DanaRPump.EXPORT_MODEL) {
danaRPlugin.disconnect("Wrong Model")
aapsLogger.debug(LTag.PUMPCOMM, "Wrong model selected")
}
aapsLogger.debug(LTag.PUMPCOMM, "Model: " + String.format("%02X ", danaRPump.model))
aapsLogger.debug(LTag.PUMPCOMM, "Protocol: " + String.format("%02X ", danaRPump.protocol))
aapsLogger.debug(LTag.PUMPCOMM, "Product Code: " + String.format("%02X ", danaRPump.productCode))
}
}

View file

@ -1,70 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class MsgInitConnStatusBasic extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgInitConnStatusBasic() {
SetCommand(0x0303);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
@Override
public void handleMessage(byte[] bytes) {
if (bytes.length - 10 < 21) {
return;
}
DanaRPump pump = DanaRPump.getInstance();
pump.pumpSuspended = intFromBuff(bytes, 0, 1) == 1;
pump.calculatorEnabled = intFromBuff(bytes, 1, 1) == 1;
pump.dailyTotalUnits = intFromBuff(bytes, 2, 3) / 750d;
pump.maxDailyTotalUnits = intFromBuff(bytes, 5, 2) / 100;
pump.reservoirRemainingUnits = intFromBuff(bytes, 7, 3) / 750d;
pump.bolusBlocked = intFromBuff(bytes, 10, 1) == 1;
pump.currentBasal = intFromBuff(bytes, 11, 2) / 100d;
pump.tempBasalPercent = intFromBuff(bytes, 13, 1);
pump.isExtendedInProgress = intFromBuff(bytes, 14, 1) == 1;
pump.isTempBasalInProgress = intFromBuff(bytes, 15, 1) == 1;
int statusBasalUDOption = intFromBuff(bytes, 16, 1);
pump.isDualBolusInProgress = intFromBuff(bytes, 17, 1) == 1;
double extendedBolusRate = intFromBuff(bytes, 18, 2) / 100d;
pump.batteryRemaining = intFromBuff(bytes, 20, 1);
try {
int bolusConfig = intFromBuff(bytes, 21, 1);
boolean deliveryPrime = (bolusConfig & DanaRPump.DELIVERY_PRIME) != 0;
boolean deliveryStepBolus = (bolusConfig & DanaRPump.DELIVERY_STEP_BOLUS) != 0;
boolean deliveryBasal = (bolusConfig & DanaRPump.DELIVERY_BASAL) != 0;
boolean deliveryExtBolus = (bolusConfig & DanaRPump.DELIVERY_EXT_BOLUS) != 0;
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Delivery prime: " + deliveryPrime);
log.debug("Delivery step bolus: " + deliveryStepBolus);
log.debug("Delivery basal: " + deliveryBasal);
log.debug("Delivery ext bolus: " + deliveryExtBolus);
}
} catch (Exception e) {
log.error("Unhadled exception", e);
}
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Pump suspended: " + pump.pumpSuspended);
log.debug("Calculator enabled: " + pump.calculatorEnabled);
log.debug("Daily total units: " + pump.dailyTotalUnits);
log.debug("Max daily total units: " + pump.maxDailyTotalUnits);
log.debug("Reservoir remaining units: " + pump.reservoirRemainingUnits);
log.debug("Bolus blocked: " + pump.bolusBlocked);
log.debug("Current basal: " + pump.currentBasal);
log.debug("Current temp basal percent: " + pump.tempBasalPercent);
log.debug("Is extended bolus running: " + pump.isExtendedInProgress);
log.debug("statusBasalUDOption: " + statusBasalUDOption);
log.debug("Is dual bolus running: " + pump.isDualBolusInProgress);
log.debug("Extended bolus rate: " + extendedBolusRate);
log.debug("Battery remaining: " + pump.batteryRemaining);
}
}
}

View file

@ -0,0 +1,58 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
class MsgInitConnStatusBasic(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump
) : MessageBase() {
init {
SetCommand(0x0303)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
if (bytes.size - 10 < 21) {
return
}
danaRPump.pumpSuspended = intFromBuff(bytes, 0, 1) == 1
danaRPump.calculatorEnabled = intFromBuff(bytes, 1, 1) == 1
danaRPump.dailyTotalUnits = intFromBuff(bytes, 2, 3) / 750.0
danaRPump.maxDailyTotalUnits = intFromBuff(bytes, 5, 2) / 100
danaRPump.reservoirRemainingUnits = intFromBuff(bytes, 7, 3) / 750.0
danaRPump.bolusBlocked = intFromBuff(bytes, 10, 1) == 1
danaRPump.currentBasal = intFromBuff(bytes, 11, 2) / 100.0
danaRPump.tempBasalPercent = intFromBuff(bytes, 13, 1)
danaRPump.isExtendedInProgress = intFromBuff(bytes, 14, 1) == 1
danaRPump.isTempBasalInProgress = intFromBuff(bytes, 15, 1) == 1
val statusBasalUDOption = intFromBuff(bytes, 16, 1)
danaRPump.isDualBolusInProgress = intFromBuff(bytes, 17, 1) == 1
val extendedBolusRate = intFromBuff(bytes, 18, 2) / 100.0
danaRPump.batteryRemaining = intFromBuff(bytes, 20, 1)
val bolusConfig = intFromBuff(bytes, 21, 1)
val deliveryPrime = bolusConfig and DanaRPump.DELIVERY_PRIME != 0
val deliveryStepBolus = bolusConfig and DanaRPump.DELIVERY_STEP_BOLUS != 0
val deliveryBasal = bolusConfig and DanaRPump.DELIVERY_BASAL != 0
val deliveryExtBolus = bolusConfig and DanaRPump.DELIVERY_EXT_BOLUS != 0
aapsLogger.debug(LTag.PUMPCOMM, "Delivery prime: $deliveryPrime")
aapsLogger.debug(LTag.PUMPCOMM, "Delivery step bolus: $deliveryStepBolus")
aapsLogger.debug(LTag.PUMPCOMM, "Delivery basal: $deliveryBasal")
aapsLogger.debug(LTag.PUMPCOMM, "Delivery ext bolus: $deliveryExtBolus")
aapsLogger.debug(LTag.PUMPCOMM, "Pump suspended: " + danaRPump.pumpSuspended)
aapsLogger.debug(LTag.PUMPCOMM, "Calculator enabled: " + danaRPump.calculatorEnabled)
aapsLogger.debug(LTag.PUMPCOMM, "Daily total units: " + danaRPump.dailyTotalUnits)
aapsLogger.debug(LTag.PUMPCOMM, "Max daily total units: " + danaRPump.maxDailyTotalUnits)
aapsLogger.debug(LTag.PUMPCOMM, "Reservoir remaining units: " + danaRPump.reservoirRemainingUnits)
aapsLogger.debug(LTag.PUMPCOMM, "Bolus blocked: " + danaRPump.bolusBlocked)
aapsLogger.debug(LTag.PUMPCOMM, "Current basal: " + danaRPump.currentBasal)
aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal percent: " + danaRPump.tempBasalPercent)
aapsLogger.debug(LTag.PUMPCOMM, "Is extended bolus running: " + danaRPump.isExtendedInProgress)
aapsLogger.debug(LTag.PUMPCOMM, "statusBasalUDOption: $statusBasalUDOption")
aapsLogger.debug(LTag.PUMPCOMM, "Is dual bolus running: " + danaRPump.isDualBolusInProgress)
aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus rate: $extendedBolusRate")
aapsLogger.debug(LTag.PUMPCOMM, "Battery remaining: " + danaRPump.batteryRemaining)
}
}

View file

@ -1,54 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 28.05.2016.
*/
public class MsgInitConnStatusBolus extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgInitConnStatusBolus() {
SetCommand(0x0302);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
@Override
public void handleMessage(byte[] bytes) {
if (bytes.length - 10 > 12) {
failed = true;
return;
}
DanaRPump pump = DanaRPump.getInstance();
int bolusConfig = intFromBuff(bytes, 0, 1);
pump.isExtendedBolusEnabled = (bolusConfig & 0x01) != 0;
pump.bolusStep = intFromBuff(bytes, 1, 1) / 100d;
pump.maxBolus = intFromBuff(bytes, 2, 2) / 100d;
//int bolusRate = intFromBuff(bytes, 4, 8);
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Is Extended bolus enabled: " + pump.isExtendedBolusEnabled);
log.debug("Bolus increment: " + pump.bolusStep);
log.debug("Bolus max: " + pump.maxBolus);
}
if (!pump.isExtendedBolusEnabled) {
Notification notification = new Notification(Notification.EXTENDED_BOLUS_DISABLED, MainApp.gs(R.string.danar_enableextendedbolus), Notification.URGENT);
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
} else {
RxBus.Companion.getINSTANCE().send(new EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED));
}
}
}

View file

@ -0,0 +1,45 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.R
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.utils.resources.ResourceHelper
class MsgInitConnStatusBolus(
private val aapsLogger: AAPSLogger,
private val rxBus: RxBusWrapper,
private val resourceHelper: ResourceHelper,
private val danaRPump: DanaRPump
) : MessageBase() {
init {
SetCommand(0x0302)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
if (bytes.size - 10 > 12) {
failed = true
return
}
val bolusConfig = intFromBuff(bytes, 0, 1)
danaRPump.isExtendedBolusEnabled = bolusConfig and 0x01 != 0
danaRPump.bolusStep = intFromBuff(bytes, 1, 1) / 100.0
danaRPump.maxBolus = intFromBuff(bytes, 2, 2) / 100.0
//int bolusRate = intFromBuff(bytes, 4, 8);
aapsLogger.debug(LTag.PUMPCOMM, "Is Extended bolus enabled: " + danaRPump.isExtendedBolusEnabled)
aapsLogger.debug(LTag.PUMPCOMM, "Bolus increment: " + danaRPump.bolusStep)
aapsLogger.debug(LTag.PUMPCOMM, "Bolus max: " + danaRPump.maxBolus)
if (!danaRPump.isExtendedBolusEnabled) {
val notification = Notification(Notification.EXTENDED_BOLUS_DISABLED, resourceHelper.gs(R.string.danar_enableextendedbolus), Notification.URGENT)
rxBus.send(EventNewNotification(notification))
} else {
rxBus.send(EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED))
}
}
}

View file

@ -1,59 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 28.05.2016.
*/
public class MsgInitConnStatusOption extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgInitConnStatusOption() {
SetCommand(0x0304);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
@Override
public void handleMessage(byte[] bytes) {
int status1224Clock = intFromBuff(bytes, 0, 1);
int isStatusButtonScroll = intFromBuff(bytes, 1, 1);
int soundVibration = intFromBuff(bytes, 2, 1);
int glucoseUnit = intFromBuff(bytes, 3, 1);
int lcdTimeout = intFromBuff(bytes, 4, 1);
int backlightgTimeout = intFromBuff(bytes, 5, 1);
int languageOption = intFromBuff(bytes, 6, 1);
int lowReservoirAlarmBoundary = intFromBuff(bytes, 7, 1);
//int none = intFromBuff(bytes, 8, 1);
if (bytes.length >= 21) {
DanaRPump.getInstance().password = intFromBuff(bytes, 9, 2) ^ 0x3463;
if (L.isEnabled(L.PUMPCOMM))
log.debug("Pump password: " + DanaRPump.getInstance().password);
} else {
failed = true;
}
if (!DanaRPump.getInstance().isPasswordOK()) {
Notification notification = new Notification(Notification.WRONG_PUMP_PASSWORD, MainApp.gs(R.string.wrongpumppassword), Notification.URGENT);
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
} else {
RxBus.Companion.getINSTANCE().send(new EventDismissNotification(Notification.WRONG_PUMP_PASSWORD));
}
// This is last message of initial sequence
if (ConfigBuilderPlugin.getPlugin().getActivePump() != null)
ConfigBuilderPlugin.getPlugin().getActivePump().finishHandshaking();
}
}

View file

@ -0,0 +1,52 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.utils.resources.ResourceHelper
class MsgInitConnStatusOption(
private val aapsLogger: AAPSLogger,
private val rxBus: RxBusWrapper,
private val resourceHelper: ResourceHelper,
private val danaRPump: DanaRPump,
private val activePlugin: ActivePluginProvider
) : MessageBase() {
init {
SetCommand(0x0304)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
//val status1224Clock = intFromBuff(bytes, 0, 1)
//val isStatusButtonScroll = intFromBuff(bytes, 1, 1)
//val soundVibration = intFromBuff(bytes, 2, 1)
//val glucoseUnit = intFromBuff(bytes, 3, 1)
//val lcdTimeout = intFromBuff(bytes, 4, 1)
//val backlightgTimeout = intFromBuff(bytes, 5, 1)
//val languageOption = intFromBuff(bytes, 6, 1)
//val lowReservoirAlarmBoundary = intFromBuff(bytes, 7, 1)
//int none = intFromBuff(bytes, 8, 1);
if (bytes.size >= 21) {
danaRPump.password = intFromBuff(bytes, 9, 2) xor 0x3463
aapsLogger.debug(LTag.PUMPCOMM, "Pump password: " + danaRPump.password)
} else {
failed = true
}
if (!danaRPump.isPasswordOK) {
val notification = Notification(Notification.WRONG_PUMP_PASSWORD, resourceHelper.gs(R.string.wrongpumppassword), Notification.URGENT)
rxBus.send(EventNewNotification(notification))
} else {
rxBus.send(EventDismissNotification(Notification.WRONG_PUMP_PASSWORD))
}
// This is last message of initial sequence
activePlugin.activePump.finishHandshaking()
}
}

View file

@ -1,66 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventRebuildTabs;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.utils.DateUtil;
public class MsgInitConnStatusTime extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgInitConnStatusTime() {
SetCommand(0x0301);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
@Override
public void handleMessage(byte[] bytes) {
if (bytes.length - 10 > 7) {
Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.gs(R.string.pumpdrivercorrected), Notification.NORMAL);
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
DanaRPlugin.getPlugin().disconnect("Wrong Model");
log.error("Wrong model selected. Switching to Korean DanaR");
DanaRKoreanPlugin.getPlugin().setPluginEnabled(PluginType.PUMP, true);
DanaRKoreanPlugin.getPlugin().setFragmentVisible(PluginType.PUMP, true);
DanaRPlugin.getPlugin().setPluginEnabled(PluginType.PUMP, false);
DanaRPlugin.getPlugin().setFragmentVisible(PluginType.PUMP, false);
DanaRPump.reset(); // mark not initialized
//If profile coming from pump, switch it as well
if (DanaRPlugin.getPlugin().isEnabled(PluginType.PROFILE)) {
(DanaRPlugin.getPlugin()).setPluginEnabled(PluginType.PROFILE, false);
(DanaRKoreanPlugin.getPlugin()).setPluginEnabled(PluginType.PROFILE, true);
}
ConfigBuilderPlugin.getPlugin().storeSettings("ChangingDanaDriver");
RxBus.Companion.getINSTANCE().send(new EventRebuildTabs());
ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
failed = false;
return;
} else {
failed = true;
}
long time = dateTimeSecFromBuff(bytes, 0);
int versionCode = intFromBuff(bytes, 6, 1);
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Pump time: " + DateUtil.dateAndTimeFullString(time));
log.debug("Version code: " + versionCode);
}
}
}

View file

@ -0,0 +1,60 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.EventRebuildTabs
import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.resources.ResourceHelper
class MsgInitConnStatusTime(
private val aapsLogger: AAPSLogger,
private val rxBus: RxBusWrapper,
private val resourceHelper: ResourceHelper,
private val danaRPump: DanaRPump,
private val danaRPlugin: DanaRPlugin,
private val danaRKoreanPlugin: DanaRKoreanPlugin,
private val configBuilderPlugin: ConfigBuilderPlugin,
private val commandQueue: CommandQueueProvider
) : MessageBase() {
init {
SetCommand(0x0301)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
if (bytes.size - 10 > 7) {
val notification = Notification(Notification.WRONG_DRIVER, resourceHelper.gs(R.string.pumpdrivercorrected), Notification.NORMAL)
rxBus.send(EventNewNotification(notification))
danaRPlugin.disconnect("Wrong Model")
aapsLogger.debug(LTag.PUMPCOMM, "Wrong model selected. Switching to Korean DanaR")
danaRKoreanPlugin.setPluginEnabled(PluginType.PUMP, true)
danaRKoreanPlugin.setFragmentVisible(PluginType.PUMP, true)
danaRPlugin.setPluginEnabled(PluginType.PUMP, false)
danaRPlugin.setFragmentVisible(PluginType.PUMP, false)
danaRPump.reset() // mark not initialized
//If profile coming from pump, switch it as well
configBuilderPlugin.storeSettings("ChangingDanaDriver")
rxBus.send(EventRebuildTabs())
commandQueue.readStatus("PumpDriverChange", null) // force new connection
failed = false
return
} else {
failed = true
}
val time = dateTimeSecFromBuff(bytes, 0)
val versionCode = intFromBuff(bytes, 6, 1)
aapsLogger.debug(LTag.PUMPCOMM, "Pump time: " + DateUtil.dateAndTimeString(time))
aapsLogger.debug(LTag.PUMPCOMM, "Version code: $versionCode")
}
}

View file

@ -20,7 +20,7 @@ public class MsgSetBasalProfile extends MessageBase {
}
// index 0-3
public MsgSetBasalProfile(byte index, double[] values) {
public MsgSetBasalProfile(byte index, Double[] values) {
this();
AddParamByte(index);
for (Integer i = 0; i < 24; i++) {

View file

@ -18,7 +18,7 @@ public class MsgSetSingleBasalProfile extends MessageBase {
}
// index 0-3
public MsgSetSingleBasalProfile(double[] values) {
public MsgSetSingleBasalProfile(Double[] values) {
this();
for (Integer i = 0; i < 24; i++) {
AddParamInt((int) (values[i] * 100));

View file

@ -1,54 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 05.07.2016.
*/
public class MsgSetUserOptions extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public boolean done;
public MsgSetUserOptions() {
SetCommand(0x330B);
DanaRPump pump = DanaRPump.getInstance();
if (pump.userOptionsFrompump == null) {
// No options set -> Exitting
log.error("NO USER OPTIONS LOADED EXITTING!");
return;
}
pump.userOptionsFrompump[0] = (byte) (pump.timeDisplayType == 1 ? 0 : 1);
pump.userOptionsFrompump[1] = (byte) pump.buttonScrollOnOff;
pump.userOptionsFrompump[2] = (byte) pump.beepAndAlarm;
pump.userOptionsFrompump[3] = (byte) pump.lcdOnTimeSec;
pump.userOptionsFrompump[4] = (byte) pump.backlightOnTimeSec;
pump.userOptionsFrompump[5] = (byte) pump.selectedLanguage;
pump.userOptionsFrompump[8] = (byte) pump.units;
pump.userOptionsFrompump[9] = (byte) pump.shutdownHour;
pump.userOptionsFrompump[27] = (byte) pump.lowReservoirRate;
for (int i = 0; i < pump.userOptionsFrompump.length; i++) {
AddParamByte(pump.userOptionsFrompump[i]);
}
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
int result = intFromBuff(bytes, 0, 1);
if (result != 1) {
failed = true;
if (L.isEnabled(L.PUMPCOMM))
log.debug("Setting user options: " + result + " FAILED!!!");
} else {
if (L.isEnabled(L.PUMPCOMM))
log.debug("Setting user options: " + result);
}
}
}

View file

@ -0,0 +1,43 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
class MsgSetUserOptions(
private val aapsLogger: AAPSLogger,
danaRPump: DanaRPump
) : MessageBase() {
init {
SetCommand(0x330B)
if (danaRPump.userOptionsFrompump == null) {
// No options set -> Exiting
aapsLogger.debug(LTag.PUMPCOMM, "NO USER OPTIONS LOADED EXITING!")
} else {
danaRPump.userOptionsFrompump!![0] = (if (danaRPump.timeDisplayType == 1) 0 else 1).toByte()
danaRPump.userOptionsFrompump!![1] = danaRPump.buttonScrollOnOff.toByte()
danaRPump.userOptionsFrompump!![2] = danaRPump.beepAndAlarm.toByte()
danaRPump.userOptionsFrompump!![3] = danaRPump.lcdOnTimeSec.toByte()
danaRPump.userOptionsFrompump!![4] = danaRPump.backlightOnTimeSec.toByte()
danaRPump.userOptionsFrompump!![5] = danaRPump.selectedLanguage.toByte()
danaRPump.userOptionsFrompump!![8] = danaRPump.units.toByte()
danaRPump.userOptionsFrompump!![9] = danaRPump.shutdownHour.toByte()
danaRPump.userOptionsFrompump!![27] = danaRPump.lowReservoirRate.toByte()
for (element in danaRPump.userOptionsFrompump!!) {
AddParamByte(element)
}
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
}
override fun handleMessage(bytes: ByteArray) {
val result = intFromBuff(bytes, 0, 1)
if (result != 1) {
failed = true
aapsLogger.debug(LTag.PUMPCOMM, "Setting user options: $result FAILED!!!")
} else {
aapsLogger.debug(LTag.PUMPCOMM, "Setting user options: $result")
}
}
}

View file

@ -1,27 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 05.07.2016.
*/
public class MsgSettingActiveProfile extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgSettingActiveProfile() {
SetCommand(0x320C);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
DanaRPump.getInstance().activeProfile = intFromBuff(bytes, 0, 1);
if (L.isEnabled(L.PUMPCOMM))
log.debug("Active profile number: " + DanaRPump.getInstance().activeProfile);
}
}

View file

@ -0,0 +1,22 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
class MsgSettingActiveProfile(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump
) : MessageBase() {
init {
SetCommand(0x320C)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
danaRPump.activeProfile = intFromBuff(bytes, 0, 1)
aapsLogger.debug(LTag.PUMPCOMM, "Active profile number: " + danaRPump.activeProfile)
}
}

View file

@ -1,39 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Locale;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 05.07.2016.
*/
public class MsgSettingBasal extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgSettingBasal() {
SetCommand(0x3202);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
if (pump.pumpProfiles == null) pump.pumpProfiles = new double[4][];
pump.pumpProfiles[pump.activeProfile] = new double[24];
for (int index = 0; index < 24; index++) {
int basal = intFromBuff(bytes, 2 * index, 2);
if (basal < DanaRPlugin.getPlugin().pumpDescription.basalMinimumRate) basal = 0;
pump.pumpProfiles[pump.activeProfile][index] = basal / 100d;
}
if (L.isEnabled(L.PUMPCOMM))
for (int index = 0; index < 24; index++) {
log.debug("Basal " + String.format(Locale.ENGLISH, "%02d", index) + "h: " + pump.pumpProfiles[pump.activeProfile][index]);
}
}
}

View file

@ -0,0 +1,31 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import java.util.*
class MsgSettingBasal(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump,
private val danaRPlugin: DanaRPlugin
) : MessageBase() {
init {
SetCommand(0x3202)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
danaRPump.pumpProfiles = Array(4) {Array(48) {0.0} }
for (index in 0..23) {
var basal = intFromBuff(bytes, 2 * index, 2)
if (basal < danaRPlugin.pumpDescription.basalMinimumRate) basal = 0
danaRPump.pumpProfiles!![danaRPump.activeProfile][index] = basal / 100.0
}
for (index in 0..23) {
aapsLogger.debug(LTag.PUMPCOMM, "Basal " + String.format(Locale.ENGLISH, "%02d", index) + "h: " + danaRPump.pumpProfiles!![danaRPump.activeProfile][index])
}
}
}

View file

@ -1,84 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Locale;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 05.07.2016.
* <p/>
* <p/>
* THIS IS BROKEN IN PUMP... SENDING ONLY 1 PROFILE
*/
public class MsgSettingBasalProfileAll extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgSettingBasalProfileAll() {
SetCommand(0x3206);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
if (pump.basal48Enable) {
pump.pumpProfiles = new double[4][];
for (int profile = 0; profile < 4; profile++) {
int position = intFromBuff(bytes, 107 * profile, 1);
pump.pumpProfiles[position] = new double[48];
for (int index = 0; index < 48; index++) {
int basal = intFromBuff(bytes, 107 * profile + 2 * index + 1, 2);
if (basal < 10) basal = 0;
pump.pumpProfiles[position][index] = basal / 100d;
}
}
} else {
pump.pumpProfiles = new double[4][];
for (int profile = 0; profile < 4; profile++) {
int position = intFromBuff(bytes, 49 * profile, 1);
pump.pumpProfiles[position] = new double[24];
for (int index = 0; index < 24; index++) {
int basal = intFromBuff(bytes, 59 * profile + 2 * index + 1, 2);
if (basal < 10) basal = 0;
if (L.isEnabled(L.PUMPCOMM))
log.debug("position " + position + " index " + index);
pump.pumpProfiles[position][index] = basal / 100d;
}
}
}
if (L.isEnabled(L.PUMPCOMM)) {
if (pump.basal48Enable) {
for (int profile = 0; profile < 4; profile++) {
for (int index = 0; index < 48; index++) {
try {
log.debug("Basal profile " + profile + ": " + String.format(Locale.ENGLISH, "%02d", index) + "h: " + pump.pumpProfiles[profile][index]);
} catch (Exception e){
log.error("Unhandled exception" , e);
}
}
}
} else {
for (int profile = 0; profile < 4; profile++) {
for (int index = 0; index < 24; index++) {
//this is absurd pump.pumpProfiles[profile][index] returns nullPointerException
try {
log.debug("Basal profile " + profile + ": " +
String.format(Locale.ENGLISH, "%02d", (index / 2)) +
":" + String.format(Locale.ENGLISH, "%02d", (index % 2) * 30) + " : " +
pump.pumpProfiles[profile][index]);
} catch (Exception e){
log.error("Unhandled exception" , e);
}
}
}
}
}
}
}

View file

@ -0,0 +1,64 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import java.util.*
/**
* Created by mike on 05.07.2016.
*
*
*
*
* THIS IS BROKEN IN PUMP... SENDING ONLY 1 PROFILE
*/
class MsgSettingBasalProfileAll(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump
) : MessageBase() {
override fun handleMessage(bytes: ByteArray) {
danaRPump.pumpProfiles = Array(4) { Array(48) { 0.0 } }
if (danaRPump.basal48Enable) {
for (profile in 0..3) {
val position = intFromBuff(bytes, 107 * profile, 1)
for (index in 0..47) {
var basal = intFromBuff(bytes, 107 * profile + 2 * index + 1, 2)
if (basal < 10) basal = 0
danaRPump.pumpProfiles!![position][index] = basal / 100.0
}
}
} else {
for (profile in 0..3) {
val position = intFromBuff(bytes, 49 * profile, 1)
for (index in 0..23) {
var basal = intFromBuff(bytes, 59 * profile + 2 * index + 1, 2)
if (basal < 10) basal = 0
aapsLogger.debug(LTag.PUMPCOMM, "position $position index $index")
danaRPump.pumpProfiles!![position][index] = basal / 100.0
}
}
}
if (danaRPump.basal48Enable) {
for (profile in 0..3) {
for (index in 0..47) {
aapsLogger.debug(LTag.PUMPCOMM, "Basal profile " + profile + ": " + String.format(Locale.ENGLISH, "%02d", index) + "h: " + danaRPump.pumpProfiles!![profile][index])
}
}
} else {
for (profile in 0..3) {
for (index in 0..23) { //this is absurd danaRPump.pumpProfiles[profile][index] returns nullPointerException
aapsLogger.debug(LTag.PUMPCOMM, "Basal profile " + profile + ": " + String.format(Locale.ENGLISH, "%02d", index / 2) +
":" + String.format(Locale.ENGLISH, "%02d", index % 2 * 30) + " : " +
danaRPump.pumpProfiles!![profile][index])
}
}
}
}
init {
SetCommand(0x3206)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
}

View file

@ -1,31 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 05.07.2016.
*/
public class MsgSettingGlucose extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgSettingGlucose() {
SetCommand(0x3209);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
pump.units = intFromBuff(bytes, 0, 1);
pump.easyBasalMode = intFromBuff(bytes, 1, 1);
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Pump units: " + (pump.units == DanaRPump.UNITS_MGDL ? "MGDL" : "MMOL"));
log.debug("Easy basal mode: " + pump.easyBasalMode);
}
}
}

View file

@ -0,0 +1,26 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
/**
* Created by mike on 05.07.2016.
*/
class MsgSettingGlucose(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump
) : MessageBase() {
init {
SetCommand(0x3209)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
danaRPump.units = intFromBuff(bytes, 0, 1)
danaRPump.easyBasalMode = intFromBuff(bytes, 1, 1)
aapsLogger.debug(LTag.PUMPCOMM, "Pump units: " + if (danaRPump.units == DanaRPump.UNITS_MGDL) "MGDL" else "MMOL")
aapsLogger.debug(LTag.PUMPCOMM, "Easy basal mode: " + danaRPump.easyBasalMode)
}
}

View file

@ -1,35 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 05.07.2016.
*/
public class MsgSettingMaxValues extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgSettingMaxValues() {
SetCommand(0x3205);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
pump.maxBolus = intFromBuff(bytes, 0, 2) / 100d;
pump.maxBasal = intFromBuff(bytes, 2, 2) / 100d;
pump.maxDailyTotalUnits = intFromBuff(bytes, 4, 2) / 100;
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Max bolus: " + pump.maxBolus);
log.debug("Max basal: " + pump.maxBasal);
log.debug("Total daily max units: " + pump.maxDailyTotalUnits);
}
}
}

View file

@ -0,0 +1,25 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
class MsgSettingMaxValues(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump
) : MessageBase() {
init {
SetCommand(0x3205)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
danaRPump.maxBolus = intFromBuff(bytes, 0, 2) / 100.0
danaRPump.maxBasal = intFromBuff(bytes, 2, 2) / 100.0
danaRPump.maxDailyTotalUnits = intFromBuff(bytes, 4, 2) / 100
aapsLogger.debug(LTag.PUMPCOMM, "Max bolus: " + danaRPump.maxBolus)
aapsLogger.debug(LTag.PUMPCOMM, "Max basal: " + danaRPump.maxBasal)
aapsLogger.debug(LTag.PUMPCOMM, "Total daily max units: " + danaRPump.maxDailyTotalUnits)
}
}

View file

@ -1,68 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
/**
* Created by mike on 13.12.2016.
*/
public class MsgSettingMeal extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgSettingMeal() {
SetCommand(0x3203);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
pump.basalStep = intFromBuff(bytes, 0, 1) / 100d;
pump.bolusStep = intFromBuff(bytes, 1, 1) / 100d;
boolean bolusEnabled = intFromBuff(bytes, 2, 1) == 1;
int melodyTime = intFromBuff(bytes, 3, 1);
int blockTime = intFromBuff(bytes, 4, 1);
pump.isConfigUD = intFromBuff(bytes, 5, 1) == 1;
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Basal step: " + pump.basalStep);
log.debug("Bolus step: " + pump.bolusStep);
log.debug("Bolus enabled: " + bolusEnabled);
log.debug("Melody time: " + melodyTime);
log.debug("Block time: " + blockTime);
log.debug("Is Config U/d: " + pump.isConfigUD);
}
// DanaRKorean is not possible to set to 0.01 but it works when controlled from AAPS
if (DanaRKoreanPlugin.getPlugin().isEnabled(PluginType.PUMP)) {
pump.basalStep = 0.01d;
}
if (pump.basalStep != 0.01d) {
Notification notification = new Notification(Notification.WRONGBASALSTEP, MainApp.gs(R.string.danar_setbasalstep001), Notification.URGENT);
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
} else {
RxBus.Companion.getINSTANCE().send(new EventDismissNotification(Notification.WRONGBASALSTEP));
}
if (pump.isConfigUD) {
Notification notification = new Notification(Notification.UD_MODE_ENABLED, MainApp.gs(R.string.danar_switchtouhmode), Notification.URGENT);
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
} else {
RxBus.Companion.getINSTANCE().send(new EventDismissNotification(Notification.UD_MODE_ENABLED));
}
}
}

View file

@ -0,0 +1,58 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper
class MsgSettingMeal(
private val aapsLogger: AAPSLogger,
private val rxBus: RxBusWrapper,
private val resourceHelper: ResourceHelper,
private val danaRPump: DanaRPump,
private val danaRKoreanPlugin: DanaRKoreanPlugin
) : MessageBase() {
init {
SetCommand(0x3203)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
danaRPump.basalStep = intFromBuff(bytes, 0, 1) / 100.0
danaRPump.bolusStep = intFromBuff(bytes, 1, 1) / 100.0
val bolusEnabled = intFromBuff(bytes, 2, 1) == 1
val melodyTime = intFromBuff(bytes, 3, 1)
val blockTime = intFromBuff(bytes, 4, 1)
danaRPump.isConfigUD = intFromBuff(bytes, 5, 1) == 1
aapsLogger.debug(LTag.PUMPCOMM, "Basal step: " + danaRPump.basalStep)
aapsLogger.debug(LTag.PUMPCOMM, "Bolus step: " + danaRPump.bolusStep)
aapsLogger.debug(LTag.PUMPCOMM, "Bolus enabled: $bolusEnabled")
aapsLogger.debug(LTag.PUMPCOMM, "Melody time: $melodyTime")
aapsLogger.debug(LTag.PUMPCOMM, "Block time: $blockTime")
aapsLogger.debug(LTag.PUMPCOMM, "Is Config U/d: " + danaRPump.isConfigUD)
// DanaRKorean is not possible to set to 0.01 but it works when controlled from AAPS
if (danaRKoreanPlugin.isEnabled(PluginType.PUMP)) {
danaRPump.basalStep = 0.01
}
if (danaRPump.basalStep != 0.01) {
val notification = Notification(Notification.WRONGBASALSTEP, resourceHelper.gs(R.string.danar_setbasalstep001), Notification.URGENT)
rxBus.send(EventNewNotification(notification))
} else {
rxBus.send(EventDismissNotification(Notification.WRONGBASALSTEP))
}
if (danaRPump.isConfigUD) {
val notification = Notification(Notification.UD_MODE_ENABLED, resourceHelper.gs(R.string.danar_switchtouhmode), Notification.URGENT)
rxBus.send(EventNewNotification(notification))
} else {
rxBus.send(EventDismissNotification(Notification.UD_MODE_ENABLED))
}
}
}

View file

@ -1,46 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 05.07.2016.
*/
public class MsgSettingProfileRatios extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgSettingProfileRatios() {
SetCommand(0x3204);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
if (pump.units == DanaRPump.UNITS_MGDL) {
pump.currentCIR = intFromBuff(bytes, 0, 2);
pump.currentCF = intFromBuff(bytes, 2, 2);
pump.currentAI = intFromBuff(bytes, 4, 2) / 100d;
pump.currentTarget = intFromBuff(bytes, 6, 2);
pump.currentAIDR = intFromBuff(bytes, 8, 1);
} else {
pump.currentCIR = intFromBuff(bytes, 0, 2);
pump.currentCF = intFromBuff(bytes, 2, 2) / 100d;
pump.currentAI = intFromBuff(bytes, 4, 2) / 100d;
pump.currentTarget = intFromBuff(bytes, 6, 2) / 100d;
pump.currentAIDR = intFromBuff(bytes, 8, 1);
}
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Pump units (saved): " + (pump.units == DanaRPump.UNITS_MGDL ? "MGDL" : "MMOL"));
log.debug("Current pump CIR: " + pump.currentCIR);
log.debug("Current pump CF: " + pump.currentCF);
log.debug("Current pump AI: " + pump.currentAI);
log.debug("Current pump target: " + pump.currentTarget);
log.debug("Current pump AIDR: " + pump.currentAIDR);
}
}
}

View file

@ -0,0 +1,38 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
class MsgSettingProfileRatios(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump
) : MessageBase() {
init {
SetCommand(0x3204)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
if (danaRPump.units == DanaRPump.UNITS_MGDL) {
danaRPump.currentCIR = intFromBuff(bytes, 0, 2)
danaRPump.currentCF = intFromBuff(bytes, 2, 2).toDouble()
danaRPump.currentAI = intFromBuff(bytes, 4, 2) / 100.0
danaRPump.currentTarget = intFromBuff(bytes, 6, 2).toDouble()
danaRPump.currentAIDR = intFromBuff(bytes, 8, 1)
} else {
danaRPump.currentCIR = intFromBuff(bytes, 0, 2)
danaRPump.currentCF = intFromBuff(bytes, 2, 2) / 100.0
danaRPump.currentAI = intFromBuff(bytes, 4, 2) / 100.0
danaRPump.currentTarget = intFromBuff(bytes, 6, 2) / 100.0
danaRPump.currentAIDR = intFromBuff(bytes, 8, 1)
}
aapsLogger.debug(LTag.PUMPCOMM, "Pump units (saved): " + if (danaRPump.units == DanaRPump.UNITS_MGDL) "MGDL" else "MMOL")
aapsLogger.debug(LTag.PUMPCOMM, "Current pump CIR: " + danaRPump.currentCIR)
aapsLogger.debug(LTag.PUMPCOMM, "Current pump CF: " + danaRPump.currentCF)
aapsLogger.debug(LTag.PUMPCOMM, "Current pump AI: " + danaRPump.currentAI)
aapsLogger.debug(LTag.PUMPCOMM, "Current pump target: " + danaRPump.currentTarget)
aapsLogger.debug(LTag.PUMPCOMM, "Current pump AIDR: " + danaRPump.currentAIDR)
}
}

View file

@ -1,55 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 05.07.2016.
*/
public class MsgSettingProfileRatiosAll extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgSettingProfileRatiosAll() {
SetCommand(0x320D);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
if (pump.units == DanaRPump.UNITS_MGDL) {
pump.morningCIR = intFromBuff(bytes, 0, 2);
pump.morningCF = intFromBuff(bytes, 2, 2);
pump.afternoonCIR = intFromBuff(bytes, 4, 2);
pump.afternoonCF = intFromBuff(bytes, 6, 2);
pump.eveningCIR = intFromBuff(bytes, 8, 2);
pump.eveningCF = intFromBuff(bytes, 10, 2);
pump.nightCIR = intFromBuff(bytes, 12, 2);
pump.nightCF = intFromBuff(bytes, 14, 2);
} else {
pump.morningCIR = intFromBuff(bytes, 0, 2);
pump.morningCF = intFromBuff(bytes, 2, 2) / 100d;
pump.afternoonCIR = intFromBuff(bytes, 4, 2);
pump.afternoonCF = intFromBuff(bytes, 6, 2) / 100d;
pump.eveningCIR = intFromBuff(bytes, 8, 2);
pump.eveningCF = intFromBuff(bytes, 10, 2) / 100d;
pump.nightCIR = intFromBuff(bytes, 12, 2);
pump.nightCF = intFromBuff(bytes, 14, 2) / 100d;
}
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Pump units: " + (pump.units == DanaRPump.UNITS_MGDL ? "MGDL" : "MMOL"));
log.debug("Current pump morning CIR: " + pump.morningCIR);
log.debug("Current pump morning CF: " + pump.morningCF);
log.debug("Current pump afternoon CIR: " + pump.afternoonCIR);
log.debug("Current pump afternoon CF: " + pump.afternoonCF);
log.debug("Current pump evening CIR: " + pump.eveningCIR);
log.debug("Current pump evening CF: " + pump.eveningCF);
log.debug("Current pump night CIR: " + pump.nightCIR);
log.debug("Current pump night CF: " + pump.nightCF);
}
}
}

View file

@ -0,0 +1,47 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
class MsgSettingProfileRatiosAll(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump
) : MessageBase() {
init {
SetCommand(0x320D)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
if (danaRPump.units == DanaRPump.UNITS_MGDL) {
danaRPump.morningCIR = intFromBuff(bytes, 0, 2)
danaRPump.morningCF = intFromBuff(bytes, 2, 2).toDouble()
danaRPump.afternoonCIR = intFromBuff(bytes, 4, 2)
danaRPump.afternoonCF = intFromBuff(bytes, 6, 2).toDouble()
danaRPump.eveningCIR = intFromBuff(bytes, 8, 2)
danaRPump.eveningCF = intFromBuff(bytes, 10, 2).toDouble()
danaRPump.nightCIR = intFromBuff(bytes, 12, 2)
danaRPump.nightCF = intFromBuff(bytes, 14, 2).toDouble()
} else {
danaRPump.morningCIR = intFromBuff(bytes, 0, 2)
danaRPump.morningCF = intFromBuff(bytes, 2, 2) / 100.0
danaRPump.afternoonCIR = intFromBuff(bytes, 4, 2)
danaRPump.afternoonCF = intFromBuff(bytes, 6, 2) / 100.0
danaRPump.eveningCIR = intFromBuff(bytes, 8, 2)
danaRPump.eveningCF = intFromBuff(bytes, 10, 2) / 100.0
danaRPump.nightCIR = intFromBuff(bytes, 12, 2)
danaRPump.nightCF = intFromBuff(bytes, 14, 2) / 100.0
}
aapsLogger.debug(LTag.PUMPCOMM, "Pump units: " + if (danaRPump.units == DanaRPump.UNITS_MGDL) "MGDL" else "MMOL")
aapsLogger.debug(LTag.PUMPCOMM, "Current pump morning CIR: " + danaRPump.morningCIR)
aapsLogger.debug(LTag.PUMPCOMM, "Current pump morning CF: " + danaRPump.morningCF)
aapsLogger.debug(LTag.PUMPCOMM, "Current pump afternoon CIR: " + danaRPump.afternoonCIR)
aapsLogger.debug(LTag.PUMPCOMM, "Current pump afternoon CF: " + danaRPump.afternoonCF)
aapsLogger.debug(LTag.PUMPCOMM, "Current pump evening CIR: " + danaRPump.eveningCIR)
aapsLogger.debug(LTag.PUMPCOMM, "Current pump evening CF: " + danaRPump.eveningCF)
aapsLogger.debug(LTag.PUMPCOMM, "Current pump night CIR: " + danaRPump.nightCIR)
aapsLogger.debug(LTag.PUMPCOMM, "Current pump night CF: " + danaRPump.nightCF)
}
}

View file

@ -1,43 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.utils.DateUtil;
public class MsgSettingPumpTime extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgSettingPumpTime() {
SetCommand(0x320A);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
long time =
new Date(
100 + intFromBuff(bytes, 5, 1),
intFromBuff(bytes, 4, 1) - 1,
intFromBuff(bytes, 3, 1),
intFromBuff(bytes, 2, 1),
intFromBuff(bytes, 1, 1),
intFromBuff(bytes, 0, 1)
).getTime();
if (L.isEnabled(L.PUMPCOMM))
log.debug("Pump time: " + DateUtil.dateAndTimeFullString(time) + " Phone time: " + new Date());
DanaRPump.getInstance().pumpTime = time;
}
@Override
public void handleMessageNotReceived() {
DanaRPump.getInstance().pumpTime = 0;
}
}

View file

@ -0,0 +1,35 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.utils.DateUtil
import java.util.*
class MsgSettingPumpTime(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump
) : MessageBase() {
init {
SetCommand(0x320A)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
val time = Date(
100 + intFromBuff(bytes, 5, 1),
intFromBuff(bytes, 4, 1) - 1,
intFromBuff(bytes, 3, 1),
intFromBuff(bytes, 2, 1),
intFromBuff(bytes, 1, 1),
intFromBuff(bytes, 0, 1)
).time
aapsLogger.debug(LTag.PUMPCOMM, "Pump time: " + DateUtil.dateAndTimeString(time) + " Phone time: " + Date())
danaRPump.pumpTime = time
}
override fun handleMessageNotReceived() {
danaRPump.pumpTime = 0
}
}

View file

@ -1,33 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 05.07.2016.
*/
public class MsgSettingShippingInfo extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgSettingShippingInfo() {
SetCommand(0x3207);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
pump.serialNumber = stringFromBuff(bytes, 0, 10);
pump.shippingDate = dateFromBuff(bytes, 10);
pump.shippingCountry = asciiStringFromBuff(bytes, 13, 3);
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Serial number: " + pump.serialNumber);
log.debug("Shipping date: " + pump.shippingDate);
log.debug("Shipping country: " + pump.shippingCountry);
}
}
}

View file

@ -0,0 +1,25 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
class MsgSettingShippingInfo(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump
) : MessageBase() {
init {
SetCommand(0x3207)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
danaRPump.serialNumber = stringFromBuff(bytes, 0, 10)
danaRPump.shippingDate = dateFromBuff(bytes, 10)
danaRPump.shippingCountry = asciiStringFromBuff(bytes, 13, 3)
aapsLogger.debug(LTag.PUMPCOMM, "Serial number: " + danaRPump.serialNumber)
aapsLogger.debug(LTag.PUMPCOMM, "Shipping date: " + danaRPump.shippingDate)
aapsLogger.debug(LTag.PUMPCOMM, "Shipping country: " + danaRPump.shippingCountry)
}
}

View file

@ -1,70 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by Rumen Georgiev on 6/11/2018.
*/
public class MsgSettingUserOptions extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgSettingUserOptions() {
SetCommand(0x320B);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] packet) {
DanaRPump pump = DanaRPump.getInstance();
byte[] bytes = getDataBytes(packet, 0, packet.length - 10);
pump.userOptionsFrompump = Arrays.copyOf(bytes, bytes.length);// saving pumpDataBytes to use it in MsgSetUserOptions
for(int pos=0; pos < bytes.length; pos++) {
log.debug("[" + pos + "]" + bytes[pos]);
}
pump.timeDisplayType = bytes[0] == (byte) 1 ? 0 : 1; // 1 -> 24h 0 -> 12h
pump.buttonScrollOnOff = bytes[1] == (byte) 1 ? 1 : 0; // 1 -> ON, 0-> OFF
pump.beepAndAlarm = bytes[2]; // 1 -> Sound on alarm 2-> Vibrate on alarm 3-> Both on alarm 5-> Sound + beep 6-> vibrate + beep 7-> both + beep Beep adds 4
pump.lcdOnTimeSec = bytes[3] & 255;
pump.backlightOnTimeSec = bytes[4] & 255;
pump.selectedLanguage = bytes[5]; // on DanaRv2 is that needed ?
pump.units = bytes[8];
pump.shutdownHour = bytes[9];
pump.lowReservoirRate = bytes[32] & 255;
/* int selectableLanguage1 = bytes[10];
int selectableLanguage2 = bytes[11];
int selectableLanguage3 = bytes[12];
int selectableLanguage4 = bytes[13];
int selectableLanguage5 = bytes[14];
*/
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("timeDisplayType: " + pump.timeDisplayType);
log.debug("Button scroll: " + pump.buttonScrollOnOff);
log.debug("BeepAndAlarm: " + pump.beepAndAlarm);
log.debug("screen timeout: " + pump.lcdOnTimeSec);
log.debug("Backlight: " + pump.backlightOnTimeSec);
log.debug("Selected language: " + pump.selectedLanguage);
log.debug("Units: " + pump.getUnits());
log.debug("Shutdown: " + pump.shutdownHour);
log.debug("Low reservoir: " + pump.lowReservoirRate);
}
}
public static byte[] getDataBytes(byte[] bytes, int start, int len) {
if (bytes == null) {
return null;
}
byte[] ret = new byte[len];
System.arraycopy(bytes, start + 6, ret, 0, len);
return ret;
}
}

View file

@ -0,0 +1,59 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import java.util.*
class MsgSettingUserOptions(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump
) : MessageBase() {
init {
SetCommand(0x320B)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(packet: ByteArray) {
val bytes = getDataBytes(packet, packet.size - 10)
danaRPump.userOptionsFrompump = Arrays.copyOf(bytes, bytes!!.size) // saving pumpDataBytes to use it in MsgSetUserOptions
for (pos in bytes.indices) {
aapsLogger.debug(LTag.PUMPCOMM, "[" + pos + "]" + bytes[pos])
}
danaRPump.timeDisplayType = if (bytes[0] == 1.toByte()) 0 else 1 // 1 -> 24h 0 -> 12h
danaRPump.buttonScrollOnOff = if (bytes[1] == 1.toByte()) 1 else 0 // 1 -> ON, 0-> OFF
danaRPump.beepAndAlarm = bytes[2].toInt() // 1 -> Sound on alarm 2-> Vibrate on alarm 3-> Both on alarm 5-> Sound + beep 6-> vibrate + beep 7-> both + beep Beep adds 4
danaRPump.lcdOnTimeSec = bytes[3].toInt() and 255
danaRPump.backlightOnTimeSec = bytes[4].toInt() and 255
danaRPump.selectedLanguage = bytes[5].toInt() // on DanaRv2 is that needed ?
danaRPump.units = bytes[8].toInt()
danaRPump.shutdownHour = bytes[9].toInt()
danaRPump.lowReservoirRate = bytes[32].toInt() and 255
/* int selectableLanguage1 = bytes[10];
int selectableLanguage2 = bytes[11];
int selectableLanguage3 = bytes[12];
int selectableLanguage4 = bytes[13];
int selectableLanguage5 = bytes[14];
*/
aapsLogger.debug(LTag.PUMPCOMM, "timeDisplayType: " + danaRPump.timeDisplayType)
aapsLogger.debug(LTag.PUMPCOMM, "Button scroll: " + danaRPump.buttonScrollOnOff)
aapsLogger.debug(LTag.PUMPCOMM, "BeepAndAlarm: " + danaRPump.beepAndAlarm)
aapsLogger.debug(LTag.PUMPCOMM, "screen timeout: " + danaRPump.lcdOnTimeSec)
aapsLogger.debug(LTag.PUMPCOMM, "BackLight: " + danaRPump.backlightOnTimeSec)
aapsLogger.debug(LTag.PUMPCOMM, "Selected language: " + danaRPump.selectedLanguage)
aapsLogger.debug(LTag.PUMPCOMM, "Units: " + danaRPump.getUnits())
aapsLogger.debug(LTag.PUMPCOMM, "Shutdown: " + danaRPump.shutdownHour)
aapsLogger.debug(LTag.PUMPCOMM, "Low reservoir: " + danaRPump.lowReservoirRate)
}
private fun getDataBytes(bytes: ByteArray?, len: Int): ByteArray? {
if (bytes == null) {
return null
}
val ret = ByteArray(len)
System.arraycopy(bytes, 6, ret, 0, len)
return ret
}
}

View file

@ -1,41 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class MsgStatus extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgStatus() {
SetCommand(0x020B);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
pump.dailyTotalUnits = intFromBuff(bytes, 0, 3) / 750d;
pump.isExtendedInProgress = intFromBuff(bytes, 3, 1) == 1;
pump.extendedBolusMinutes = intFromBuff(bytes, 4, 2);
pump.extendedBolusAmount = intFromBuff(bytes, 6, 2) / 100d;
Double lastBolusAmount = intFromBuff(bytes, 13, 2) / 100d;
if (lastBolusAmount != 0d) {
pump.lastBolusTime = dateTimeFromBuff(bytes, 8);
pump.lastBolusAmount = lastBolusAmount;
}
pump.iob = intFromBuff(bytes, 15, 2) / 100d;
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Daily total: " + pump.dailyTotalUnits);
log.debug("Is extended bolus running: " + pump.isExtendedInProgress);
log.debug("Extended bolus min: " + pump.extendedBolusMinutes);
log.debug("Extended bolus amount: " + pump.extendedBolusAmount);
log.debug("Last bolus time: " + pump.lastBolusTime);
log.debug("Last bolus amount: " + pump.lastBolusAmount);
log.debug("IOB: " + pump.iob);
}
}
}

View file

@ -0,0 +1,37 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
class MsgStatus(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump
) : MessageBase() {
init {
SetCommand(0x020B)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
danaRPump.dailyTotalUnits = intFromBuff(bytes, 0, 3) / 750.0
danaRPump.isExtendedInProgress = intFromBuff(bytes, 3, 1) == 1
danaRPump.extendedBolusMinutes = intFromBuff(bytes, 4, 2)
danaRPump.extendedBolusAmount = intFromBuff(bytes, 6, 2) / 100.0
val lastBolusAmount = intFromBuff(bytes, 13, 2) / 100.0
if (lastBolusAmount != 0.0) {
danaRPump.lastBolusTime = dateTimeFromBuff(bytes, 8)
danaRPump.lastBolusAmount = lastBolusAmount
}
danaRPump.iob = intFromBuff(bytes, 15, 2) / 100.0
aapsLogger.debug(LTag.PUMPCOMM, "Daily total: " + danaRPump.dailyTotalUnits)
aapsLogger.debug(LTag.PUMPCOMM, "Is extended bolus running: " + danaRPump.isExtendedInProgress)
aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus min: " + danaRPump.extendedBolusMinutes)
aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus amount: " + danaRPump.extendedBolusAmount)
aapsLogger.debug(LTag.PUMPCOMM, "Last bolus time: " + danaRPump.lastBolusTime)
aapsLogger.debug(LTag.PUMPCOMM, "Last bolus amount: " + danaRPump.lastBolusAmount)
aapsLogger.debug(LTag.PUMPCOMM, "IOB: " + danaRPump.iob)
}
}

View file

@ -1,48 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class MsgStatusBasic extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgStatusBasic() {
SetCommand(0x020A);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
pump.pumpSuspended = intFromBuff(bytes, 0, 1) == 1;
pump.calculatorEnabled = intFromBuff(bytes, 1, 1) == 1;
pump.dailyTotalUnits = intFromBuff(bytes, 2, 3) / 750d;
pump.maxDailyTotalUnits = intFromBuff(bytes, 5, 2) / 100;
pump.reservoirRemainingUnits = intFromBuff(bytes, 7, 3) / 750d;
pump.bolusBlocked = intFromBuff(bytes, 10, 1) == 1;
pump.currentBasal = intFromBuff(bytes, 11, 2) / 100d;
// removed. info taken from tempstatus message
//pump.tempBasalPercent = intFromBuff(bytes, 13, 1);
//pump.isExtendedInProgress = intFromBuff(bytes, 14, 1) == 1;
//pump.isTempBasalInProgress = intFromBuff(bytes, 15, 1) == 1;
pump.batteryRemaining = intFromBuff(bytes, 20, 1);
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Pump suspended: " + pump.pumpSuspended);
log.debug("Calculator enabled: " + pump.calculatorEnabled);
log.debug("Daily total units: " + pump.dailyTotalUnits);
log.debug("Max daily total units: " + pump.maxDailyTotalUnits);
log.debug("Reservoir remaining units: " + pump.reservoirRemainingUnits);
log.debug("Bolus blocked: " + pump.bolusBlocked);
log.debug("Current basal: " + pump.currentBasal);
//log.debug("Current temp basal percent: " + pump.tempBasalPercent);
//log.debug("Is extended bolus running: " + pump.isExtendedInProgress);
//log.debug("Is temp basal running: " + pump.isTempBasalInProgress);
}
}
}

View file

@ -0,0 +1,41 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
class MsgStatusBasic(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump
) : MessageBase() {
init {
SetCommand(0x020A)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
danaRPump.pumpSuspended = intFromBuff(bytes, 0, 1) == 1
danaRPump.calculatorEnabled = intFromBuff(bytes, 1, 1) == 1
danaRPump.dailyTotalUnits = intFromBuff(bytes, 2, 3) / 750.0
danaRPump.maxDailyTotalUnits = intFromBuff(bytes, 5, 2) / 100
danaRPump.reservoirRemainingUnits = intFromBuff(bytes, 7, 3) / 750.0
danaRPump.bolusBlocked = intFromBuff(bytes, 10, 1) == 1
danaRPump.currentBasal = intFromBuff(bytes, 11, 2) / 100.0
// removed. info taken from tempstatus message
//pump.tempBasalPercent = intFromBuff(bytes, 13, 1);
//pump.isExtendedInProgress = intFromBuff(bytes, 14, 1) == 1;
//pump.isTempBasalInProgress = intFromBuff(bytes, 15, 1) == 1;
danaRPump.batteryRemaining = intFromBuff(bytes, 20, 1)
aapsLogger.debug(LTag.PUMPCOMM, "Pump suspended: " + danaRPump.pumpSuspended)
aapsLogger.debug(LTag.PUMPCOMM, "Calculator enabled: " + danaRPump.calculatorEnabled)
aapsLogger.debug(LTag.PUMPCOMM, "Daily total units: " + danaRPump.dailyTotalUnits)
aapsLogger.debug(LTag.PUMPCOMM, "Max daily total units: " + danaRPump.maxDailyTotalUnits)
aapsLogger.debug(LTag.PUMPCOMM, "Reservoir remaining units: " + danaRPump.reservoirRemainingUnits)
aapsLogger.debug(LTag.PUMPCOMM, "Bolus blocked: " + danaRPump.bolusBlocked)
aapsLogger.debug(LTag.PUMPCOMM, "Current basal: " + danaRPump.currentBasal)
//aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal percent: " + pump.tempBasalPercent);
//aapsLogger.debug(LTag.PUMPCOMM, "Is extended bolus running: " + pump.isExtendedInProgress);
//aapsLogger.debug(LTag.PUMPCOMM, "Is temp basal running: " + pump.isTempBasalInProgress);
}
}

View file

@ -1,106 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import androidx.annotation.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil;
public class MsgStatusBolusExtended extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgStatusBolusExtended() {
SetCommand(0x0207);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
boolean isExtendedInProgress = intFromBuff(bytes, 0, 1) == 1;
int extendedBolusHalfHours = intFromBuff(bytes, 1, 1);
int extendedBolusMinutes = extendedBolusHalfHours * 30;
double extendedBolusAmount = intFromBuff(bytes, 2, 2) / 100d;
int extendedBolusSoFarInSecs = intFromBuff(bytes, 4, 3);
// This is available only on korean, but not needed now
// int extendedBolusDeliveryPulse = intFromBuff(bytes, 7, 2);
// int isEasyUIUserSleep = intFromBuff(bytes, 9, 1);
int extendedBolusSoFarInMinutes = extendedBolusSoFarInSecs / 60;
double extendedBolusAbsoluteRate = isExtendedInProgress ? extendedBolusAmount / extendedBolusMinutes * 60 : 0d;
long extendedBolusStart = isExtendedInProgress ? getDateFromSecAgo(extendedBolusSoFarInSecs) : 0;
int extendedBolusRemainingMinutes = extendedBolusMinutes - extendedBolusSoFarInMinutes;
DanaRPump pump = DanaRPump.getInstance();
pump.isExtendedInProgress = isExtendedInProgress;
pump.extendedBolusMinutes = extendedBolusMinutes;
pump.extendedBolusAmount = extendedBolusAmount;
pump.extendedBolusSoFarInMinutes = extendedBolusSoFarInMinutes;
pump.extendedBolusAbsoluteRate = extendedBolusAbsoluteRate;
pump.extendedBolusStart = extendedBolusStart;
pump.extendedBolusRemainingMinutes = extendedBolusRemainingMinutes;
updateExtendedBolusInDB();
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Is extended bolus running: " + isExtendedInProgress);
log.debug("Extended bolus min: " + extendedBolusMinutes);
log.debug("Extended bolus amount: " + extendedBolusAmount);
log.debug("Extended bolus so far in minutes: " + extendedBolusSoFarInMinutes);
log.debug("Extended bolus absolute rate: " + extendedBolusAbsoluteRate);
log.debug("Extended bolus start: " + DateUtil.dateAndTimeFullString(extendedBolusStart));
log.debug("Extended bolus remaining minutes: " + extendedBolusRemainingMinutes);
}
}
@NonNull
private long getDateFromSecAgo(int tempBasalAgoSecs) {
return (long) (Math.ceil(System.currentTimeMillis() / 1000d) - tempBasalAgoSecs) * 1000;
}
public static void updateExtendedBolusInDB() {
TreatmentsInterface treatmentsInterface = TreatmentsPlugin.getPlugin();
DanaRPump pump = DanaRPump.getInstance();
long now = System.currentTimeMillis();
ExtendedBolus extendedBolus = treatmentsInterface.getExtendedBolusFromHistory(System.currentTimeMillis());
if (extendedBolus != null) {
if (pump.isExtendedInProgress) {
if (extendedBolus.absoluteRate() != pump.extendedBolusAbsoluteRate) {
// Close current extended
ExtendedBolus exStop = new ExtendedBolus(pump.extendedBolusStart - 1000);
exStop.source = Source.USER;
treatmentsInterface.addToHistoryExtendedBolus(exStop);
// Create new
ExtendedBolus newExtended = new ExtendedBolus()
.date(pump.extendedBolusStart)
.insulin(pump.extendedBolusAmount)
.durationInMinutes(pump.extendedBolusMinutes)
.source(Source.USER);
treatmentsInterface.addToHistoryExtendedBolus(newExtended);
}
} else {
// Close curent temp basal
ExtendedBolus exStop = new ExtendedBolus(now)
.source(Source.USER);
treatmentsInterface.addToHistoryExtendedBolus(exStop);
}
} else {
if (pump.isExtendedInProgress) {
// Create new
ExtendedBolus newExtended = new ExtendedBolus()
.date(pump.extendedBolusStart)
.insulin(pump.extendedBolusAmount)
.durationInMinutes(pump.extendedBolusMinutes)
.source(Source.USER);
treatmentsInterface.addToHistoryExtendedBolus(newExtended);
}
}
}
}

View file

@ -0,0 +1,91 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.db.ExtendedBolus
import info.nightscout.androidaps.db.Source
import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.utils.DateUtil
import kotlin.math.ceil
class MsgStatusBolusExtended(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump,
private val activePlugin: ActivePluginProvider
) : MessageBase() {
init {
SetCommand(0x0207)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
val isExtendedInProgress = intFromBuff(bytes, 0, 1) == 1
val extendedBolusHalfHours = intFromBuff(bytes, 1, 1)
val extendedBolusMinutes = extendedBolusHalfHours * 30
val extendedBolusAmount = intFromBuff(bytes, 2, 2) / 100.0
val extendedBolusSoFarInSecs = intFromBuff(bytes, 4, 3)
// This is available only on korean, but not needed now
// int extendedBolusDeliveryPulse = intFromBuff(bytes, 7, 2);
// int isEasyUIUserSleep = intFromBuff(bytes, 9, 1);
val extendedBolusSoFarInMinutes = extendedBolusSoFarInSecs / 60
val extendedBolusAbsoluteRate = if (isExtendedInProgress) extendedBolusAmount / extendedBolusMinutes * 60 else 0.0
val extendedBolusStart = if (isExtendedInProgress) getDateFromSecAgo(extendedBolusSoFarInSecs) else 0
val extendedBolusRemainingMinutes = extendedBolusMinutes - extendedBolusSoFarInMinutes
danaRPump.isExtendedInProgress = isExtendedInProgress
danaRPump.extendedBolusMinutes = extendedBolusMinutes
danaRPump.extendedBolusAmount = extendedBolusAmount
danaRPump.extendedBolusSoFarInMinutes = extendedBolusSoFarInMinutes
danaRPump.extendedBolusAbsoluteRate = extendedBolusAbsoluteRate
danaRPump.extendedBolusStart = extendedBolusStart
danaRPump.extendedBolusRemainingMinutes = extendedBolusRemainingMinutes
updateExtendedBolusInDB()
aapsLogger.debug(LTag.PUMPCOMM, "Is extended bolus running: $isExtendedInProgress")
aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus min: $extendedBolusMinutes")
aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus amount: $extendedBolusAmount")
aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus so far in minutes: $extendedBolusSoFarInMinutes")
aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus absolute rate: $extendedBolusAbsoluteRate")
aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus start: " + DateUtil.dateAndTimeString(extendedBolusStart))
aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus remaining minutes: $extendedBolusRemainingMinutes")
}
private fun getDateFromSecAgo(tempBasalAgoSecs: Int): Long {
return (ceil(System.currentTimeMillis() / 1000.0) - tempBasalAgoSecs).toLong() * 1000
}
private fun updateExtendedBolusInDB() {
val now = System.currentTimeMillis()
val extendedBolus = activePlugin.activeTreatments.getExtendedBolusFromHistory(System.currentTimeMillis())
if (extendedBolus != null) {
if (danaRPump.isExtendedInProgress) {
if (extendedBolus.absoluteRate() != danaRPump.extendedBolusAbsoluteRate) { // Close current extended
val exStop = ExtendedBolus(danaRPump.extendedBolusStart - 1000)
exStop.source = Source.USER
activePlugin.activeTreatments.addToHistoryExtendedBolus(exStop)
// Create new
val newExtended = ExtendedBolus()
.date(danaRPump.extendedBolusStart)
.insulin(danaRPump.extendedBolusAmount)
.durationInMinutes(danaRPump.extendedBolusMinutes)
.source(Source.USER)
activePlugin.activeTreatments.addToHistoryExtendedBolus(newExtended)
}
} else {
// Close current temp basal
val exStop = ExtendedBolus(now)
.source(Source.USER)
activePlugin.activeTreatments.addToHistoryExtendedBolus(exStop)
}
} else {
if (danaRPump.isExtendedInProgress) { // Create new
val newExtended = ExtendedBolus()
.date(danaRPump.extendedBolusStart)
.insulin(danaRPump.extendedBolusAmount)
.durationInMinutes(danaRPump.extendedBolusMinutes)
.source(Source.USER)
activePlugin.activeTreatments.addToHistoryExtendedBolus(newExtended)
}
}
}
}

View file

@ -1,44 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
/**
* Created by mike on 05.07.2016.
*/
public class MsgStatusProfile extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgStatusProfile() {
SetCommand(0x0204);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
if (pump.units == DanaRPump.UNITS_MGDL) {
pump.currentCIR = intFromBuff(bytes, 0, 2);
pump.currentCF = intFromBuff(bytes, 2, 2);
pump.currentAI = intFromBuff(bytes, 4, 2) / 100d;
pump.currentTarget = intFromBuff(bytes, 6, 2);
} else {
pump.currentCIR = intFromBuff(bytes, 0, 2);
pump.currentCF = intFromBuff(bytes, 2, 2) / 100d;
pump.currentAI = intFromBuff(bytes, 4, 2) / 100d;
pump.currentTarget = intFromBuff(bytes, 6, 2) / 100d;
}
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Pump units (saved): " + (pump.units == DanaRPump.UNITS_MGDL ? "MGDL" : "MMOL"));
log.debug("Current pump CIR: " + pump.currentCIR);
log.debug("Current pump CF: " + pump.currentCF);
log.debug("Current pump AI: " + pump.currentAI);
log.debug("Current pump target: " + pump.currentTarget);
log.debug("Current pump AIDR: " + pump.currentAIDR);
}
}
}

View file

@ -0,0 +1,36 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
class MsgStatusProfile(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump
) : MessageBase() {
init {
SetCommand(0x0204)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
if (danaRPump.units == DanaRPump.UNITS_MGDL) {
danaRPump.currentCIR = intFromBuff(bytes, 0, 2)
danaRPump.currentCF = intFromBuff(bytes, 2, 2).toDouble()
danaRPump.currentAI = intFromBuff(bytes, 4, 2) / 100.0
danaRPump.currentTarget = intFromBuff(bytes, 6, 2).toDouble()
} else {
danaRPump.currentCIR = intFromBuff(bytes, 0, 2)
danaRPump.currentCF = intFromBuff(bytes, 2, 2) / 100.0
danaRPump.currentAI = intFromBuff(bytes, 4, 2) / 100.0
danaRPump.currentTarget = intFromBuff(bytes, 6, 2) / 100.0
}
aapsLogger.debug(LTag.PUMPCOMM, "Pump units (saved): " + if (danaRPump.units == DanaRPump.UNITS_MGDL) "MGDL" else "MMOL")
aapsLogger.debug(LTag.PUMPCOMM, "Current pump CIR: " + danaRPump.currentCIR)
aapsLogger.debug(LTag.PUMPCOMM, "Current pump CF: " + danaRPump.currentCF)
aapsLogger.debug(LTag.PUMPCOMM, "Current pump AI: " + danaRPump.currentAI)
aapsLogger.debug(LTag.PUMPCOMM, "Current pump target: " + danaRPump.currentTarget)
aapsLogger.debug(LTag.PUMPCOMM, "Current pump AIDR: " + danaRPump.currentAIDR)
}
}

View file

@ -1,96 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm;
import androidx.annotation.NonNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
public class MsgStatusTempBasal extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgStatusTempBasal() {
SetCommand(0x0205);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
boolean isTempBasalInProgress = (intFromBuff(bytes, 0, 1) & 0x01) == 0x01;
boolean isAPSTempBasalInProgress = (intFromBuff(bytes, 0, 1) & 0x02) == 0x02;
int tempBasalPercent = intFromBuff(bytes, 1, 1);
if (tempBasalPercent > 200) tempBasalPercent = (tempBasalPercent - 200) * 10;
int tempBasalTotalSec;
if (intFromBuff(bytes, 2, 1) == 150) tempBasalTotalSec = 15 * 60;
else if (intFromBuff(bytes, 2, 1) == 160) tempBasalTotalSec = 30 * 60;
else tempBasalTotalSec = intFromBuff(bytes, 2, 1) * 60 * 60;
int tempBasalRunningSeconds = intFromBuff(bytes, 3, 3);
int tempBasalRemainingMin = (tempBasalTotalSec - tempBasalRunningSeconds) / 60;
long tempBasalStart = isTempBasalInProgress ? getDateFromTempBasalSecAgo(tempBasalRunningSeconds) : 0;
DanaRPump pump = DanaRPump.getInstance();
pump.isTempBasalInProgress = isTempBasalInProgress;
pump.tempBasalPercent = tempBasalPercent;
pump.tempBasalRemainingMin = tempBasalRemainingMin;
pump.tempBasalTotalSec = tempBasalTotalSec;
pump.tempBasalStart = tempBasalStart;
updateTempBasalInDB();
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Is temp basal running: " + isTempBasalInProgress);
log.debug("Is APS temp basal running: " + isAPSTempBasalInProgress);
log.debug("Current temp basal percent: " + tempBasalPercent);
log.debug("Current temp basal remaining min: " + tempBasalRemainingMin);
log.debug("Current temp basal total sec: " + tempBasalTotalSec);
log.debug("Current temp basal start: " + tempBasalStart);
}
}
@NonNull
private long getDateFromTempBasalSecAgo(int tempBasalAgoSecs) {
return (long) (Math.ceil(System.currentTimeMillis() / 1000d) - tempBasalAgoSecs) * 1000;
}
public static void updateTempBasalInDB() {
DanaRPump danaRPump = DanaRPump.getInstance();
long now = System.currentTimeMillis();
if (TreatmentsPlugin.getPlugin().isInHistoryRealTempBasalInProgress()) {
TemporaryBasal tempBasal = TreatmentsPlugin.getPlugin().getRealTempBasalFromHistory(System.currentTimeMillis());
if (danaRPump.isTempBasalInProgress) {
if (tempBasal.percentRate != danaRPump.tempBasalPercent) {
// Close current temp basal
TemporaryBasal tempStop = new TemporaryBasal().date(danaRPump.tempBasalStart - 1000).source(Source.USER);
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop);
// Create new
TemporaryBasal newTempBasal = new TemporaryBasal()
.date(danaRPump.tempBasalStart)
.percent(danaRPump.tempBasalPercent)
.duration(danaRPump.tempBasalTotalSec / 60)
.source(Source.USER);
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(newTempBasal);
}
} else {
// Close current temp basal
TemporaryBasal tempStop = new TemporaryBasal().date(now).source(Source.USER);
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop);
}
} else {
if (danaRPump.isTempBasalInProgress) {
// Create new
TemporaryBasal newTempBasal = new TemporaryBasal()
.date(danaRPump.tempBasalStart)
.percent(danaRPump.tempBasalPercent)
.duration(danaRPump.tempBasalTotalSec / 60)
.source(Source.USER);
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(newTempBasal);
}
}
}
}

View file

@ -0,0 +1,80 @@
package info.nightscout.androidaps.plugins.pump.danaR.comm
import info.nightscout.androidaps.db.Source
import info.nightscout.androidaps.db.TemporaryBasal
import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import kotlin.math.ceil
class MsgStatusTempBasal(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump,
private val activePlugin: ActivePluginProvider
) : MessageBase() {
init {
SetCommand(0x0205)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
val isTempBasalInProgress = intFromBuff(bytes, 0, 1) and 0x01 == 0x01
val isAPSTempBasalInProgress = intFromBuff(bytes, 0, 1) and 0x02 == 0x02
var tempBasalPercent = intFromBuff(bytes, 1, 1)
if (tempBasalPercent > 200) tempBasalPercent = (tempBasalPercent - 200) * 10
val tempBasalTotalSec: Int = if (intFromBuff(bytes, 2, 1) == 150) 15 * 60 else if (intFromBuff(bytes, 2, 1) == 160) 30 * 60 else intFromBuff(bytes, 2, 1) * 60 * 60
val tempBasalRunningSeconds = intFromBuff(bytes, 3, 3)
val tempBasalRemainingMin = (tempBasalTotalSec - tempBasalRunningSeconds) / 60
val tempBasalStart = if (isTempBasalInProgress) getDateFromTempBasalSecAgo(tempBasalRunningSeconds) else 0
danaRPump.isTempBasalInProgress = isTempBasalInProgress
danaRPump.tempBasalPercent = tempBasalPercent
danaRPump.tempBasalRemainingMin = tempBasalRemainingMin
danaRPump.tempBasalTotalSec = tempBasalTotalSec
danaRPump.tempBasalStart = tempBasalStart
updateTempBasalInDB()
aapsLogger.debug(LTag.PUMPCOMM, "Is temp basal running: $isTempBasalInProgress")
aapsLogger.debug(LTag.PUMPCOMM, "Is APS temp basal running: $isAPSTempBasalInProgress")
aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal percent: $tempBasalPercent")
aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal remaining min: $tempBasalRemainingMin")
aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal total sec: $tempBasalTotalSec")
aapsLogger.debug(LTag.PUMPCOMM, "Current temp basal start: $tempBasalStart")
}
private fun getDateFromTempBasalSecAgo(tempBasalAgoSecs: Int): Long {
return (ceil(System.currentTimeMillis() / 1000.0) - tempBasalAgoSecs).toLong() * 1000
}
private fun updateTempBasalInDB() {
val now = System.currentTimeMillis()
if (activePlugin.activeTreatments.isInHistoryRealTempBasalInProgress) {
val tempBasal = activePlugin.activeTreatments.getRealTempBasalFromHistory(System.currentTimeMillis())
if (danaRPump.isTempBasalInProgress) {
if (tempBasal.percentRate != danaRPump.tempBasalPercent) { // Close current temp basal
val tempStop = TemporaryBasal().date(danaRPump.tempBasalStart - 1000).source(Source.USER)
activePlugin.activeTreatments.addToHistoryTempBasal(tempStop)
// Create new
val newTempBasal = TemporaryBasal()
.date(danaRPump.tempBasalStart)
.percent(danaRPump.tempBasalPercent)
.duration(danaRPump.tempBasalTotalSec / 60)
.source(Source.USER)
activePlugin.activeTreatments.addToHistoryTempBasal(newTempBasal)
}
} else { // Close current temp basal
val tempStop = TemporaryBasal().date(now).source(Source.USER)
activePlugin.activeTreatments.addToHistoryTempBasal(tempStop)
}
} else {
if (danaRPump.isTempBasalInProgress) { // Create new
val newTempBasal = TemporaryBasal()
.date(danaRPump.tempBasalStart)
.percent(danaRPump.tempBasalPercent)
.duration(danaRPump.tempBasalTotalSec / 60)
.source(Source.USER)
activePlugin.activeTreatments.addToHistoryTempBasal(newTempBasal)
}
}
}
}

View file

@ -17,6 +17,7 @@ import java.io.IOException;
import java.util.Set;
import java.util.UUID;
import dagger.android.DaggerService;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
@ -48,7 +49,7 @@ import info.nightscout.androidaps.utils.ToastUtils;
* Created by mike on 28.01.2018.
*/
public abstract class AbstractDanaRExecutionService extends Service {
public abstract class AbstractDanaRExecutionService extends DaggerService {
protected Logger log = LoggerFactory.getLogger(L.PUMP);
protected String mDevName;

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.pump.danaR.services;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.IntentFilter;
import android.os.Binder;
import android.os.SystemClock;
@ -8,8 +9,9 @@ import android.os.SystemClock;
import java.io.IOException;
import java.util.Date;
import javax.inject.Inject;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult;
@ -19,15 +21,18 @@ import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventProfileNeedsUpdate;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.interfaces.CommandQueueProvider;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
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.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.plugins.pump.danaR.SerialIOThread;
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
@ -61,28 +66,42 @@ import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusBasic;
import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusBolusExtended;
import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusTempBasal;
import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus;
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.queue.commands.Command;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
public class DanaRExecutionService extends AbstractDanaRExecutionService {
@Inject AAPSLogger aapsLogger;
@Inject RxBusWrapper rxBus;
@Inject ResourceHelper resourceHelper;
@Inject DanaRPump danaRPump;
@Inject DanaRPlugin danaRPlugin;
@Inject DanaRKoreanPlugin danaRKoreanPlugin;
@Inject ConfigBuilderPlugin configBuilderPlugin;
@Inject CommandQueueProvider commandQueue;
@Inject Context context;
@Inject MessageHashTableR messageHashTableR;
@Inject ActivePluginProvider activePlugin;
private CompositeDisposable disposable = new CompositeDisposable();
public DanaRExecutionService() {
mBinder = new LocalBinder();
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
}
@Override
public void onCreate() {
super.onCreate();
disposable.add(RxBus.Companion.getINSTANCE()
mBinder = new LocalBinder();
context.registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
disposable.add(rxBus
.toObservable(EventPreferenceChange.class)
.observeOn(Schedulers.io())
.subscribe(event -> {
@ -90,16 +109,15 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
mSerialIOThread.disconnect("EventPreferenceChange");
}, exception -> FabricPrivacy.getInstance().logException(exception))
);
disposable.add(RxBus.Companion.getINSTANCE()
disposable.add(rxBus
.toObservable(EventAppExit.class)
.observeOn(Schedulers.io())
.subscribe(event -> {
if (L.isEnabled(L.PUMP))
log.debug("EventAppExit received");
if (mSerialIOThread != null)
mSerialIOThread.disconnect("Application exit");
MainApp.instance().getApplicationContext().unregisterReceiver(receiver);
context.unregisterReceiver(receiver);
stopSelf();
}, exception -> FabricPrivacy.getInstance().logException(exception))
);
@ -143,9 +161,9 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
if (mSerialIOThread != null) {
mSerialIOThread.disconnect("Recreate SerialIOThread");
}
mSerialIOThread = new SerialIOThread(mRfcommSocket, MessageHashTableR.INSTANCE);
mSerialIOThread = new SerialIOThread(mRfcommSocket, messageHashTableR, danaRPump);
mHandshakeInProgress = true;
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.HANDSHAKING, 0));
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.HANDSHAKING, 0));
}
mConnectionInProgress = false;
@ -153,16 +171,15 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
}
public void getPumpStatus() {
DanaRPump danaRPump = DanaRPump.getInstance();
try {
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpstatus)));
MsgStatus statusMsg = new MsgStatus();
MsgStatusBasic statusBasicMsg = new MsgStatusBasic();
MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal();
MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended();
MsgCheckValue checkValue = new MsgCheckValue();
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpstatus)));
MsgStatus statusMsg = new MsgStatus(aapsLogger, danaRPump);
MsgStatusBasic statusBasicMsg = new MsgStatusBasic(aapsLogger, danaRPump);
MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal(aapsLogger, danaRPump, activePlugin);
MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended(aapsLogger, danaRPump, activePlugin);
MsgCheckValue checkValue = new MsgCheckValue(aapsLogger, danaRPump, danaRPlugin);
if (danaRPump.isNewPump) {
if (danaRPump.isNewPump()) {
mSerialIOThread.sendMessage(checkValue);
if (!checkValue.received) {
return;
@ -171,72 +188,71 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
mSerialIOThread.sendMessage(statusMsg);
mSerialIOThread.sendMessage(statusBasicMsg);
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingtempbasalstatus)));
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingtempbasalstatus)));
mSerialIOThread.sendMessage(tempStatusMsg);
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingextendedbolusstatus)));
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingextendedbolusstatus)));
mSerialIOThread.sendMessage(exStatusMsg);
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingbolusstatus)));
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingbolusstatus)));
long now = System.currentTimeMillis();
danaRPump.lastConnection = now;
danaRPump.setLastConnection(now);
Profile profile = ProfileFunctions.getInstance().getProfile();
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
if (profile != null && Math.abs(danaRPump.currentBasal - profile.getBasal()) >= pump.getPumpDescription().basalStep) {
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings)));
mSerialIOThread.sendMessage(new MsgSettingBasal());
if (!pump.isThisProfileSet(profile) && !ConfigBuilderPlugin.getPlugin().getCommandQueue().isRunning(Command.CommandType.BASAL_PROFILE)) {
RxBus.Companion.getINSTANCE().send(new EventProfileNeedsUpdate());
if (profile != null && Math.abs(danaRPump.getCurrentBasal() - profile.getBasal()) >= danaRPlugin.getPumpDescription().basalStep) {
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpsettings)));
mSerialIOThread.sendMessage(new MsgSettingBasal(aapsLogger, danaRPump, danaRPlugin));
if (!danaRPlugin.isThisProfileSet(profile) && !commandQueue.isRunning(Command.CommandType.BASAL_PROFILE)) {
rxBus.send(new EventProfileNeedsUpdate());
}
}
if (danaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !pump.isInitialized()) {
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings)));
mSerialIOThread.sendMessage(new MsgSettingShippingInfo());
mSerialIOThread.sendMessage(new MsgSettingActiveProfile());
mSerialIOThread.sendMessage(new MsgSettingMeal());
mSerialIOThread.sendMessage(new MsgSettingBasal());
if (danaRPump.getLastSettingsRead() + 60 * 60 * 1000L < now || !danaRPlugin.isInitialized()) {
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpsettings)));
mSerialIOThread.sendMessage(new MsgSettingShippingInfo(aapsLogger, danaRPump));
mSerialIOThread.sendMessage(new MsgSettingActiveProfile(aapsLogger, danaRPump));
mSerialIOThread.sendMessage(new MsgSettingMeal(aapsLogger, rxBus, resourceHelper, danaRPump, danaRKoreanPlugin));
mSerialIOThread.sendMessage(new MsgSettingBasal(aapsLogger, danaRPump, danaRPlugin));
//0x3201
mSerialIOThread.sendMessage(new MsgSettingMaxValues());
mSerialIOThread.sendMessage(new MsgSettingGlucose());
mSerialIOThread.sendMessage(new MsgSettingActiveProfile());
mSerialIOThread.sendMessage(new MsgSettingProfileRatios());
mSerialIOThread.sendMessage(new MsgSettingProfileRatiosAll());
mSerialIOThread.sendMessage(new MsgSettingUserOptions());
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime)));
mSerialIOThread.sendMessage(new MsgSettingPumpTime());
if (danaRPump.pumpTime == 0) {
mSerialIOThread.sendMessage(new MsgSettingMaxValues(aapsLogger, danaRPump));
mSerialIOThread.sendMessage(new MsgSettingGlucose(aapsLogger, danaRPump));
mSerialIOThread.sendMessage(new MsgSettingActiveProfile(aapsLogger, danaRPump));
mSerialIOThread.sendMessage(new MsgSettingProfileRatios(aapsLogger, danaRPump));
mSerialIOThread.sendMessage(new MsgSettingProfileRatiosAll(aapsLogger, danaRPump));
mSerialIOThread.sendMessage(new MsgSettingUserOptions(aapsLogger, danaRPump));
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumptime)));
mSerialIOThread.sendMessage(new MsgSettingPumpTime(aapsLogger, danaRPump));
if (danaRPump.getPumpTime() == 0) {
// initial handshake was not successfull
// deinitialize pump
danaRPump.lastConnection = 0;
danaRPump.lastSettingsRead = 0;
RxBus.Companion.getINSTANCE().send(new EventDanaRNewStatus());
RxBus.Companion.getINSTANCE().send(new EventInitializationChanged());
danaRPump.setLastConnection(0);
danaRPump.setLastSettingsRead(0);
rxBus.send(new EventDanaRNewStatus());
rxBus.send(new EventInitializationChanged());
return;
}
long timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
long timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L;
if (L.isEnabled(L.PUMP))
log.debug("Pump time difference: " + timeDiff + " seconds");
if (Math.abs(timeDiff) > 10) {
mSerialIOThread.sendMessage(new MsgSetTime(new Date()));
mSerialIOThread.sendMessage(new MsgSettingPumpTime());
timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
mSerialIOThread.sendMessage(new MsgSettingPumpTime(aapsLogger, danaRPump));
timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L;
if (L.isEnabled(L.PUMP))
log.debug("Pump time difference: " + timeDiff + " seconds");
}
danaRPump.lastSettingsRead = now;
danaRPump.setLastSettingsRead(now);
}
RxBus.Companion.getINSTANCE().send(new EventDanaRNewStatus());
RxBus.Companion.getINSTANCE().send(new EventInitializationChanged());
rxBus.send(new EventDanaRNewStatus());
rxBus.send(new EventInitializationChanged());
//NSUpload.uploadDeviceStatus();
if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
if (danaRPump.getDailyTotalUnits() > danaRPump.getMaxDailyTotalUnits() * Constants.dailyLimitWarning) {
if (L.isEnabled(L.PUMP))
log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits);
log.debug("Approaching daily limit: " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits());
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.gs(R.string.approachingdailylimit), Notification.URGENT);
RxBus.Companion.getINSTANCE().send(new EventNewNotification(reportFail));
NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U");
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT);
rxBus.send(new EventNewNotification(reportFail));
NSUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits() + "U");
lastApproachingDailyLimit = System.currentTimeMillis();
}
}
@ -246,44 +262,43 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
}
public boolean tempBasal(int percent, int durationInHours) {
DanaRPump danaRPump = DanaRPump.getInstance();
if (!isConnected()) return false;
if (danaRPump.isTempBasalInProgress) {
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal)));
if (danaRPump.isTempBasalInProgress()) {
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
SystemClock.sleep(500);
}
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.settingtempbasal)));
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours));
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
mSerialIOThread.sendMessage(new MsgStatusTempBasal(aapsLogger, danaRPump, activePlugin));
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
return true;
}
public boolean tempBasalStop() {
if (!isConnected()) return false;
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal)));
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
mSerialIOThread.sendMessage(new MsgStatusTempBasal(aapsLogger, danaRPump, activePlugin));
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
return true;
}
public boolean extendedBolus(double insulin, int durationInHalfHours) {
if (!isConnected()) return false;
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.settingextendedbolus)));
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingextendedbolus)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
mSerialIOThread.sendMessage(new MsgStatusBolusExtended(aapsLogger, danaRPump, activePlugin));
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
return true;
}
public boolean extendedBolusStop() {
if (!isConnected()) return false;
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingextendedbolus)));
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingextendedbolus)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
mSerialIOThread.sendMessage(new MsgStatusBolusExtended(aapsLogger, danaRPump, activePlugin));
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
return true;
}
@ -293,7 +308,6 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
}
public boolean bolus(double amount, int carbs, long carbtime, final Treatment t) {
DanaRPump danaRPump = DanaRPump.getInstance();
if (!isConnected()) return false;
if (BolusProgressDialog.stopPressed) return false;
@ -357,23 +371,23 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
while (System.currentTimeMillis() < expectedEnd) {
long waitTime = expectedEnd - System.currentTimeMillis();
bolusingEvent.setStatus(String.format(MainApp.gs(R.string.waitingforestimatedbolusend), waitTime / 1000));
RxBus.Companion.getINSTANCE().send(bolusingEvent);
bolusingEvent.setStatus(String.format(resourceHelper.gs(R.string.waitingforestimatedbolusend), waitTime / 1000));
rxBus.send(bolusingEvent);
SystemClock.sleep(1000);
}
final Object o = new Object();
synchronized (o) {
ConfigBuilderPlugin.getPlugin().getCommandQueue().independentConnect("bolusingInterrupted", new Callback() {
commandQueue.independentConnect("bolusingInterrupted", new Callback() {
@Override
public void run() {
if (danaRPump.lastBolusTime > System.currentTimeMillis() - 60 * 1000L) { // last bolus max 1 min old
t.insulin = danaRPump.lastBolusAmount;
if (danaRPump.getLastBolusTime() > System.currentTimeMillis() - 60 * 1000L) { // last bolus max 1 min old
t.insulin = danaRPump.getLastBolusAmount();
if (L.isEnabled(L.PUMP))
log.debug("Used bolus amount from history: " + danaRPump.lastBolusAmount);
log.debug("Used bolus amount from history: " + danaRPump.getLastBolusAmount());
} else {
if (L.isEnabled(L.PUMP))
log.debug("Bolus amount in history too old: " + DateUtil.dateAndTimeFullString(danaRPump.lastBolusTime));
log.debug("Bolus amount in history too old: " + DateUtil.dateAndTimeString(danaRPump.getLastBolusTime()));
}
synchronized (o) {
o.notify();
@ -387,7 +401,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
}
}
} else {
ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("bolusOK", null);
commandQueue.readStatus("bolusOK", null);
}
}
return !start.failed;
@ -411,17 +425,16 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
}
public boolean updateBasalsInPump(final Profile profile) {
DanaRPump danaRPump = DanaRPump.getInstance();
if (!isConnected()) return false;
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.updatingbasalrates)));
double[] basal = DanaRPump.getInstance().buildDanaRProfileRecord(profile);
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.updatingbasalrates)));
Double[] basal = danaRPump.buildDanaRProfileRecord(profile);
MsgSetBasalProfile msgSet = new MsgSetBasalProfile((byte) 0, basal);
mSerialIOThread.sendMessage(msgSet);
MsgSetActivateBasalProfile msgActivate = new MsgSetActivateBasalProfile((byte) 0);
mSerialIOThread.sendMessage(msgActivate);
danaRPump.lastSettingsRead = 0; // force read full settings
danaRPump.setLastSettingsRead(0); // force read full settings
getPumpStatus();
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
return true;
}
@ -429,7 +442,7 @@ public class DanaRExecutionService extends AbstractDanaRExecutionService {
if (!isConnected())
return new PumpEnactResult().success(false);
SystemClock.sleep(300);
MsgSetUserOptions msg = new MsgSetUserOptions();
MsgSetUserOptions msg = new MsgSetUserOptions(aapsLogger, danaRPump);
mSerialIOThread.sendMessage(msg);
SystemClock.sleep(200);
return new PumpEnactResult().success(!msg.failed);

View file

@ -53,19 +53,11 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
private final TreatmentsPlugin treatmentsPlugin;
private final SP sp;
private static DanaRKoreanPlugin plugin = null;
@Deprecated
public static DanaRKoreanPlugin getPlugin() {
if (plugin == null)
throw new IllegalStateException("Accessing DanaRKoreanPlugin before first instantiation");
return plugin;
}
@Inject
public DanaRKoreanPlugin(
AAPSLogger aapsLogger,
RxBusWrapper rxBus,
DanaRPump danaRPump,
MainApp maiApp,
ResourceHelper resourceHelper,
ConstraintChecker constraintChecker,
@ -74,8 +66,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
CommandQueueProvider commandQueue
) {
super(resourceHelper, aapsLogger, commandQueue);
plugin = this;
super(danaRPump, resourceHelper, aapsLogger, commandQueue);
this.aapsLogger = aapsLogger;
this.rxBus = rxBus;
this.mainApp = maiApp;
@ -156,8 +147,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
@Override
public boolean isInitialized() {
DanaRPump pump = DanaRPump.getInstance();
return pump.lastConnection > 0 && pump.maxBasal > 0 && !pump.isConfigUD && !pump.isEasyModeEnabled && pump.isExtendedBolusEnabled && pump.isPasswordOK();
return danaRPump.getLastConnection() > 0 && danaRPump.getMaxBasal() > 0 && !danaRPump.isConfigUD() && !danaRPump.isEasyModeEnabled() && danaRPump.isExtendedBolusEnabled() && danaRPump.isPasswordOK();
}
@Override
@ -211,8 +201,6 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
//if (pump.lastConnection.getTime() + 30 * 60 * 1000L < System.currentTimeMillis()) {
// connect("setTempBasalAbsolute old data");
//}
DanaRPump pump = DanaRPump.getInstance();
PumpEnactResult result = new PumpEnactResult();
absoluteRate = constraintChecker.applyBasalConstraints(new Constraint<>(absoluteRate), profile).value();
@ -308,16 +296,16 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
extendedRateToSet = Round.roundTo(extendedRateToSet, pumpDescription.extendedBolusStep * 2); // *2 because of halfhours
// What is current rate of extended bolusing in u/h?
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Extended bolus in progress: " + (activeExtended != null) + " rate: " + pump.extendedBolusAbsoluteRate + "U/h duration remaining: " + pump.extendedBolusRemainingMinutes + "min");
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Extended bolus in progress: " + (activeExtended != null) + " rate: " + danaRPump.getExtendedBolusAbsoluteRate() + "U/h duration remaining: " + danaRPump.getExtendedBolusRemainingMinutes() + "min");
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Rate to set: " + extendedRateToSet + "U/h");
// Compare with extended rate in progress
if (activeExtended != null && Math.abs(pump.extendedBolusAbsoluteRate - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
if (activeExtended != null && Math.abs(danaRPump.getExtendedBolusAbsoluteRate() - extendedRateToSet) < getPumpDescription().extendedBolusStep) {
// correct extended already set
result.success = true;
result.absolute = pump.extendedBolusAbsoluteRate;
result.absolute = danaRPump.getExtendedBolusAbsoluteRate();
result.enacted = false;
result.duration = pump.extendedBolusRemainingMinutes;
result.duration = danaRPump.getExtendedBolusRemainingMinutes();
result.isPercent = false;
result.isTempCancel = false;
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Correct extended already set");
@ -371,7 +359,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
result.enacted = true;
result.isTempCancel = true;
}
if (!DanaRPump.getInstance().isTempBasalInProgress) {
if (!danaRPump.isTempBasalInProgress()) {
result.success = true;
result.isTempCancel = true;
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);

View file

@ -0,0 +1,79 @@
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm
import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaR.comm.*
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper
import java.util.*
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class MessageHashTableRKorean @Inject constructor(
aapsLogger: AAPSLogger,
rxBus: RxBusWrapper,
resourceHelper: ResourceHelper,
danaRPump: DanaRPump,
danaRPlugin: DanaRPlugin,
danaRKoreanPlugin: DanaRKoreanPlugin,
configBuilderPlugin: ConfigBuilderPlugin,
commandQueue: CommandQueueProvider,
activePlugin: ActivePluginProvider
) : MessageHashTableBase {
var messages: HashMap<Int, MessageBase> = HashMap()
init {
put(MsgBolusStop()) // 0x0101 CMD_MEALINS_STOP
put(MsgBolusStart()) // 0x0102 CMD_MEALINS_START_DATA
put(MsgBolusProgress()) // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS
put(MsgStatusProfile(aapsLogger, danaRPump)) // 0x0204 CMD_PUMP_CALCULATION_SETTING
put(MsgStatusTempBasal(aapsLogger, danaRPump, activePlugin)) // 0x0205 CMD_PUMP_EXERCISE_MODE
put(MsgStatusBolusExtended(aapsLogger, danaRPump, activePlugin)) // 0x0207 CMD_PUMP_EXPANS_INS_I
put(MsgStatusBasic_k(aapsLogger, danaRPump)) // 0x020A CMD_PUMP_INITVIEW_I
put(MsgStatus_k(aapsLogger, danaRPump)) // 0x020B CMD_PUMP_STATUS
put(MsgInitConnStatusTime_k(aapsLogger, rxBus, resourceHelper, danaRPump, danaRPlugin, danaRKoreanPlugin, configBuilderPlugin, commandQueue)) // 0x0301 CMD_PUMPINIT_TIME_INFO
put(MsgInitConnStatusBolus_k(aapsLogger, rxBus, resourceHelper, danaRPump, activePlugin)) // 0x0302 CMD_PUMPINIT_BOLUS_INFO
put(MsgInitConnStatusBasic_k(aapsLogger, rxBus, resourceHelper, danaRPump)) // 0x0303 CMD_PUMPINIT_INIT_INFO
put(MsgSetTempBasalStart()) // 0x0401 CMD_PUMPSET_EXERCISE_S
put(MsgSetCarbsEntry()) // 0x0402 CMD_PUMPSET_HIS_S
put(MsgSetTempBasalStop()) // 0x0403 CMD_PUMPSET_EXERCISE_STOP
put(MsgSetExtendedBolusStop()) // 0x0406 CMD_PUMPSET_EXPANS_INS_STOP
put(MsgSetExtendedBolusStart()) // 0x0407 CMD_PUMPSET_EXPANS_INS_S
put(MsgError()) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS
put(MsgPCCommStart()) // 0x3001 CMD_CONNECT
put(MsgPCCommStop()) // 0x3002 CMD_DISCONNECT
put(MsgHistoryBolus()) // 0x3101 CMD_HISTORY_MEAL_INS
put(MsgHistoryDailyInsulin()) // 0x3102 CMD_HISTORY_DAY_INS
put(MsgHistoryGlucose()) // 0x3104 CMD_HISTORY_GLUCOSE
put(MsgHistoryAlarm()) // 0x3105 CMD_HISTORY_ALARM
put(MsgHistoryCarbo()) // 0x3107 CMD_HISTORY_CARBOHY
put(MsgSettingBasal_k(aapsLogger, danaRPump, danaRKoreanPlugin)) // 0x3202 CMD_SETTING_V_BASAL_INS_I
put(MsgSettingMeal(aapsLogger, rxBus, resourceHelper, danaRPump, danaRKoreanPlugin)) // 0x3203 CMD_SETTING_V_MEAL_SETTING_I
put(MsgSettingProfileRatios(aapsLogger, danaRPump)) // 0x3204 CMD_SETTING_V_CCC_I
put(MsgSettingMaxValues(aapsLogger, danaRPump)) // 0x3205 CMD_SETTING_V_MAX_VALUE_I
put(MsgSettingBasalProfileAll_k(aapsLogger, danaRPump)) // 0x3206 CMD_SETTING_V_BASAL_PROFILE_ALL
put(MsgSettingShippingInfo(aapsLogger, danaRPump)) // 0x3207 CMD_SETTING_V_SHIPPING_I
put(MsgSettingGlucose(aapsLogger, danaRPump)) // 0x3209 CMD_SETTING_V_GLUCOSEandEASY
put(MsgSettingPumpTime(aapsLogger, danaRPump)) // 0x320A CMD_SETTING_V_TIME_I
put(MsgSetSingleBasalProfile()) // 0x3302 CMD_SETTING_BASAL_INS_S
put(MsgHistoryAll()) // 0x41F2 CMD_HISTORY_ALL
put(MsgHistoryNewDone()) // 0x42F1 CMD_HISTORY_NEW_DONE
put(MsgHistoryNew()) // 0x42F2 CMD_HISTORY_NEW
put(MsgCheckValue_k(aapsLogger, danaRPump, danaRKoreanPlugin)) // 0xF0F1 CMD_PUMP_CHECK_VALUE
}
override fun put(message: MessageBase) {
messages[message.command] = message
}
override fun findMessage(command: Int): MessageBase {
return messages[command] ?: MessageBase()
}
}

View file

@ -1,56 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm
import info.nightscout.androidaps.plugins.pump.danaR.comm.*
import java.util.*
object MessageHashTableRkorean : MessageHashTableBase {
var messages: HashMap<Int, MessageBase> = HashMap()
init {
put(MsgBolusStop()) // 0x0101 CMD_MEALINS_STOP
put(MsgBolusStart()) // 0x0102 CMD_MEALINS_START_DATA
put(MsgBolusProgress()) // 0x0202 CMD_PUMP_THIS_REMAINDER_MEAL_INS
put(MsgStatusProfile()) // 0x0204 CMD_PUMP_CALCULATION_SETTING
put(MsgStatusTempBasal()) // 0x0205 CMD_PUMP_EXERCISE_MODE
put(MsgStatusBolusExtended()) // 0x0207 CMD_PUMP_EXPANS_INS_I
put(MsgStatusBasic_k()) // 0x020A CMD_PUMP_INITVIEW_I
put(MsgStatus_k()) // 0x020B CMD_PUMP_STATUS
put(MsgInitConnStatusTime_k()) // 0x0301 CMD_PUMPINIT_TIME_INFO
put(MsgInitConnStatusBolus_k()) // 0x0302 CMD_PUMPINIT_BOLUS_INFO
put(MsgInitConnStatusBasic_k()) // 0x0303 CMD_PUMPINIT_INIT_INFO
put(MsgSetTempBasalStart()) // 0x0401 CMD_PUMPSET_EXERCISE_S
put(MsgSetCarbsEntry()) // 0x0402 CMD_PUMPSET_HIS_S
put(MsgSetTempBasalStop()) // 0x0403 CMD_PUMPSET_EXERCISE_STOP
put(MsgSetExtendedBolusStop()) // 0x0406 CMD_PUMPSET_EXPANS_INS_STOP
put(MsgSetExtendedBolusStart()) // 0x0407 CMD_PUMPSET_EXPANS_INS_S
put(MsgError()) // 0x0601 CMD_PUMPOWAY_SYSTEM_STATUS
put(MsgPCCommStart()) // 0x3001 CMD_CONNECT
put(MsgPCCommStop()) // 0x3002 CMD_DISCONNECT
put(MsgHistoryBolus()) // 0x3101 CMD_HISTORY_MEAL_INS
put(MsgHistoryDailyInsulin()) // 0x3102 CMD_HISTORY_DAY_INS
put(MsgHistoryGlucose()) // 0x3104 CMD_HISTORY_GLUCOSE
put(MsgHistoryAlarm()) // 0x3105 CMD_HISTORY_ALARM
put(MsgHistoryCarbo()) // 0x3107 CMD_HISTORY_CARBOHY
put(MsgSettingBasal_k()) // 0x3202 CMD_SETTING_V_BASAL_INS_I
put(MsgSettingMeal()) // 0x3203 CMD_SETTING_V_MEAL_SETTING_I
put(MsgSettingProfileRatios()) // 0x3204 CMD_SETTING_V_CCC_I
put(MsgSettingMaxValues()) // 0x3205 CMD_SETTING_V_MAX_VALUE_I
put(MsgSettingBasalProfileAll_k()) // 0x3206 CMD_SETTING_V_BASAL_PROFILE_ALL
put(MsgSettingShippingInfo()) // 0x3207 CMD_SETTING_V_SHIPPING_I
put(MsgSettingGlucose()) // 0x3209 CMD_SETTING_V_GLUCOSEandEASY
put(MsgSettingPumpTime()) // 0x320A CMD_SETTING_V_TIME_I
put(MsgSetSingleBasalProfile()) // 0x3302 CMD_SETTING_BASAL_INS_S
put(MsgHistoryAll()) // 0x41F2 CMD_HISTORY_ALL
put(MsgHistoryNewDone()) // 0x42F1 CMD_HISTORY_NEW_DONE
put(MsgHistoryNew()) // 0x42F2 CMD_HISTORY_NEW
put(MsgCheckValue_k()) // 0xF0F1 CMD_PUMP_CHECK_VALUE
}
override fun put(message: MessageBase) {
messages[message.command] = message
}
override fun findMessage(command: Int): MessageBase {
return messages[command] ?: MessageBase()
}
}

View file

@ -1,46 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
/**
* Created by mike on 30.06.2016.
*/
public class MsgCheckValue_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgCheckValue_k() {
SetCommand(0xF0F1);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
@Override
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
pump.isNewPump = true;
if (L.isEnabled(L.PUMP))
log.debug("New firmware confirmed");
pump.model = intFromBuff(bytes, 0, 1);
pump.protocol = intFromBuff(bytes, 1, 1);
pump.productCode = intFromBuff(bytes, 2, 1);
if (pump.model != DanaRPump.DOMESTIC_MODEL) {
DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model");
log.error("Wrong model selected");
}
if (L.isEnabled(L.PUMP)) {
log.debug("Model: " + String.format("%02X ", pump.model));
log.debug("Protocol: " + String.format("%02X ", pump.protocol));
log.debug("Product Code: " + String.format("%02X ", pump.productCode));
}
}
}

View file

@ -0,0 +1,35 @@
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin
class MsgCheckValue_k(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump,
private val danaRKoreanPlugin: DanaRKoreanPlugin
) : MessageBase() {
init {
SetCommand(0xF0F1)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
danaRPump.isNewPump = true
aapsLogger.debug(LTag.PUMPCOMM, "New firmware confirmed")
danaRPump.model = intFromBuff(bytes, 0, 1)
danaRPump.protocol = intFromBuff(bytes, 1, 1)
danaRPump.productCode = intFromBuff(bytes, 2, 1)
if (danaRPump.model != DanaRPump.DOMESTIC_MODEL) {
danaRKoreanPlugin.disconnect("Wrong Model")
aapsLogger.debug(LTag.PUMPCOMM, "Wrong model selected")
}
aapsLogger.debug(LTag.PUMPCOMM, "Model: " + String.format("%02X ", danaRPump.model))
aapsLogger.debug(LTag.PUMPCOMM, "Protocol: " + String.format("%02X ", danaRPump.protocol))
aapsLogger.debug(LTag.PUMPCOMM, "Product Code: " + String.format("%02X ", danaRPump.productCode))
}
}

View file

@ -1,58 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
public class MsgInitConnStatusBasic_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgInitConnStatusBasic_k() {
SetCommand(0x0303);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
@Override
public void handleMessage(byte[] bytes) {
if (bytes.length - 10 > 6) {
return;
}
DanaRPump pump = DanaRPump.getInstance();
pump.pumpSuspended = intFromBuff(bytes, 0, 1) == 1;
int isUtilityEnable = intFromBuff(bytes, 1, 1);
pump.isEasyModeEnabled = intFromBuff(bytes, 2, 1) == 1;
int easyUIMode = intFromBuff(bytes, 3, 1);
pump.password = intFromBuff(bytes, 4, 2) ^ 0x3463;
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("isStatusSuspendOn: " + pump.pumpSuspended);
log.debug("isUtilityEnable: " + isUtilityEnable);
log.debug("Is EasyUI Enabled: " + pump.isEasyModeEnabled);
log.debug("easyUIMode: " + easyUIMode);
log.debug("Pump password: " + pump.password);
}
if (pump.isEasyModeEnabled) {
Notification notification = new Notification(Notification.EASYMODE_ENABLED, MainApp.gs(R.string.danar_disableeasymode), Notification.URGENT);
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
} else {
RxBus.Companion.getINSTANCE().send(new EventDismissNotification(Notification.EASYMODE_ENABLED));
}
if (!DanaRPump.getInstance().isPasswordOK()) {
Notification notification = new Notification(Notification.WRONG_PUMP_PASSWORD, MainApp.gs(R.string.wrongpumppassword), Notification.URGENT);
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
} else {
RxBus.Companion.getINSTANCE().send(new EventDismissNotification(Notification.WRONG_PUMP_PASSWORD));
}
}
}

View file

@ -0,0 +1,53 @@
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm
import info.nightscout.androidaps.R
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase
import info.nightscout.androidaps.utils.resources.ResourceHelper
class MsgInitConnStatusBasic_k(
private val aapsLogger: AAPSLogger,
private val rxBus: RxBusWrapper,
private val resourceHelper: ResourceHelper,
private val danaRPump: DanaRPump
) : MessageBase() {
init {
SetCommand(0x0303)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
if (bytes.size - 10 > 6) {
return
}
danaRPump.pumpSuspended = intFromBuff(bytes, 0, 1) == 1
val isUtilityEnable = intFromBuff(bytes, 1, 1)
danaRPump.isEasyModeEnabled = intFromBuff(bytes, 2, 1) == 1
val easyUIMode = intFromBuff(bytes, 3, 1)
danaRPump.password = intFromBuff(bytes, 4, 2) xor 0x3463
aapsLogger.debug(LTag.PUMPCOMM, "isStatusSuspendOn: " + danaRPump.pumpSuspended)
aapsLogger.debug(LTag.PUMPCOMM, "isUtilityEnable: $isUtilityEnable")
aapsLogger.debug(LTag.PUMPCOMM, "Is EasyUI Enabled: " + danaRPump.isEasyModeEnabled)
aapsLogger.debug(LTag.PUMPCOMM, "easyUIMode: $easyUIMode")
aapsLogger.debug(LTag.PUMPCOMM, "Pump password: " + danaRPump.password)
if (danaRPump.isEasyModeEnabled) {
val notification = Notification(Notification.EASYMODE_ENABLED, resourceHelper.gs(R.string.danar_disableeasymode), Notification.URGENT)
rxBus.send(EventNewNotification(notification))
} else {
rxBus.send(EventDismissNotification(Notification.EASYMODE_ENABLED))
}
if (!danaRPump.isPasswordOK) {
val notification = Notification(Notification.WRONG_PUMP_PASSWORD, resourceHelper.gs(R.string.wrongpumppassword), Notification.URGENT)
rxBus.send(EventNewNotification(notification))
} else {
rxBus.send(EventDismissNotification(Notification.WRONG_PUMP_PASSWORD))
}
}
}

View file

@ -1,61 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
/**
* Created by mike on 28.05.2016.
*/
public class MsgInitConnStatusBolus_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgInitConnStatusBolus_k() {
SetCommand(0x0302);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
@Override
public void handleMessage(byte[] bytes) {
if (bytes.length - 10 < 13) {
return;
}
DanaRPump pump = DanaRPump.getInstance();
int bolusConfig = intFromBuff(bytes, 0, 1);
pump.isExtendedBolusEnabled = (bolusConfig & 0x01) != 0;
pump.bolusStep = intFromBuff(bytes, 1, 1) / 100d;
pump.maxBolus = intFromBuff(bytes, 2, 2) / 100d;
//int bolusRate = intFromBuff(bytes, 4, 8);
int deliveryStatus = intFromBuff(bytes, 12, 1);
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Is Extended bolus enabled: " + pump.isExtendedBolusEnabled);
log.debug("Bolus increment: " + pump.bolusStep);
log.debug("Bolus max: " + pump.maxBolus);
log.debug("Delivery status: " + deliveryStatus);
}
if (!pump.isExtendedBolusEnabled) {
Notification notification = new Notification(Notification.EXTENDED_BOLUS_DISABLED, MainApp.gs(R.string.danar_enableextendedbolus), Notification.URGENT);
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
} else {
RxBus.Companion.getINSTANCE().send(new EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED));
}
// This is last message of initial sequence
if (ConfigBuilderPlugin.getPlugin().getActivePump() != null)
ConfigBuilderPlugin.getPlugin().getActivePump().finishHandshaking();
}
}

View file

@ -0,0 +1,51 @@
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase
import info.nightscout.androidaps.utils.resources.ResourceHelper
class MsgInitConnStatusBolus_k(
private val aapsLogger: AAPSLogger,
private val rxBus: RxBusWrapper,
private val resourceHelper: ResourceHelper,
private val danaRPump: DanaRPump,
private val activePlugin: ActivePluginProvider
) : MessageBase() {
init {
SetCommand(0x0302)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
if (bytes.size - 10 < 13) {
return
}
val bolusConfig = intFromBuff(bytes, 0, 1)
danaRPump.isExtendedBolusEnabled = bolusConfig and 0x01 != 0
danaRPump.bolusStep = intFromBuff(bytes, 1, 1) / 100.0
danaRPump.maxBolus = intFromBuff(bytes, 2, 2) / 100.0
//int bolusRate = intFromBuff(bytes, 4, 8);
val deliveryStatus = intFromBuff(bytes, 12, 1)
aapsLogger.debug(LTag.PUMPCOMM, "Is Extended bolus enabled: " + danaRPump.isExtendedBolusEnabled)
aapsLogger.debug(LTag.PUMPCOMM, "Bolus increment: " + danaRPump.bolusStep)
aapsLogger.debug(LTag.PUMPCOMM, "Bolus max: " + danaRPump.maxBolus)
aapsLogger.debug(LTag.PUMPCOMM, "Delivery status: $deliveryStatus")
if (!danaRPump.isExtendedBolusEnabled) {
val notification = Notification(Notification.EXTENDED_BOLUS_DISABLED, resourceHelper.gs(R.string.danar_enableextendedbolus), Notification.URGENT)
rxBus.send(EventNewNotification(notification))
} else {
rxBus.send(EventDismissNotification(Notification.EXTENDED_BOLUS_DISABLED))
}
// This is last message of initial sequence
activePlugin.activePump.finishHandshaking()
}
}

View file

@ -1,71 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventRebuildTabs;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.utils.DateUtil;
public class MsgInitConnStatusTime_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgInitConnStatusTime_k() {
SetCommand(0x0301);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
@Override
public void handleMessage(byte[] bytes) {
if (bytes.length - 10 < 10) {
Notification notification = new Notification(Notification.WRONG_DRIVER, MainApp.gs(R.string.pumpdrivercorrected), Notification.NORMAL);
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
DanaRKoreanPlugin.getPlugin().disconnect("Wrong Model");
log.error("Wrong model selected. Switching to export DanaR");
DanaRKoreanPlugin.getPlugin().setPluginEnabled(PluginType.PUMP, false);
DanaRKoreanPlugin.getPlugin().setFragmentVisible(PluginType.PUMP, false);
DanaRPlugin.getPlugin().setPluginEnabled(PluginType.PUMP, true);
DanaRPlugin.getPlugin().setFragmentVisible(PluginType.PUMP, true);
DanaRPump.reset(); // mark not initialized
//If profile coming from pump, switch it as well
if (DanaRKoreanPlugin.getPlugin().isEnabled(PluginType.PROFILE)) {
(DanaRKoreanPlugin.getPlugin()).setPluginEnabled(PluginType.PROFILE, false);
(DanaRPlugin.getPlugin()).setPluginEnabled(PluginType.PROFILE, true);
}
ConfigBuilderPlugin.getPlugin().storeSettings("ChangingKoreanDanaDriver");
RxBus.Companion.getINSTANCE().send(new EventRebuildTabs());
ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("PumpDriverChange", null); // force new connection
return;
}
long time = dateTimeSecFromBuff(bytes, 0);
int versionCode1 = intFromBuff(bytes, 6, 1);
int versionCode2 = intFromBuff(bytes, 7, 1);
int versionCode3 = intFromBuff(bytes, 8, 1);
int versionCode4 = intFromBuff(bytes, 9, 1);
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Pump time: " + DateUtil.dateAndTimeFullString(time));
log.debug("Version code1: " + versionCode1);
log.debug("Version code2: " + versionCode2);
log.debug("Version code3: " + versionCode3);
log.debug("Version code4: " + versionCode4);
}
}
}

View file

@ -0,0 +1,64 @@
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm
import info.nightscout.androidaps.R
import info.nightscout.androidaps.events.EventRebuildTabs
import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.interfaces.PluginType
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.resources.ResourceHelper
class MsgInitConnStatusTime_k(
private val aapsLogger: AAPSLogger,
private val rxBus: RxBusWrapper,
private val resourceHelper: ResourceHelper,
private val danaRPump: DanaRPump,
private val danaRPlugin: DanaRPlugin,
private val danaRKoreanPlugin: DanaRKoreanPlugin,
private val configBuilderPlugin: ConfigBuilderPlugin,
private val commandQueue: CommandQueueProvider
) : MessageBase() {
init {
SetCommand(0x0301)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
if (bytes.size - 10 < 10) {
val notification = Notification(Notification.WRONG_DRIVER, resourceHelper.gs(R.string.pumpdrivercorrected), Notification.NORMAL)
rxBus.send(EventNewNotification(notification))
danaRKoreanPlugin.disconnect("Wrong Model")
aapsLogger.debug(LTag.PUMPCOMM, "Wrong model selected. Switching to export DanaR")
danaRKoreanPlugin.setPluginEnabled(PluginType.PUMP, false)
danaRKoreanPlugin.setFragmentVisible(PluginType.PUMP, false)
danaRPlugin.setPluginEnabled(PluginType.PUMP, true)
danaRPlugin.setFragmentVisible(PluginType.PUMP, true)
danaRPump.reset() // mark not initialized
//If profile coming from pump, switch it as well
configBuilderPlugin.storeSettings("ChangingKoreanDanaDriver")
rxBus.send(EventRebuildTabs())
commandQueue.readStatus("PumpDriverChange", null) // force new connection
return
}
val time = dateTimeSecFromBuff(bytes, 0)
val versionCode1 = intFromBuff(bytes, 6, 1)
val versionCode2 = intFromBuff(bytes, 7, 1)
val versionCode3 = intFromBuff(bytes, 8, 1)
val versionCode4 = intFromBuff(bytes, 9, 1)
aapsLogger.debug(LTag.PUMPCOMM, "Pump time: " + DateUtil.dateAndTimeString(time))
aapsLogger.debug(LTag.PUMPCOMM, "Version code1: $versionCode1")
aapsLogger.debug(LTag.PUMPCOMM, "Version code2: $versionCode2")
aapsLogger.debug(LTag.PUMPCOMM, "Version code3: $versionCode3")
aapsLogger.debug(LTag.PUMPCOMM, "Version code4: $versionCode4")
}
}

View file

@ -1,76 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Locale;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
/**
* Created by mike on 05.07.2016.
* <p/>
* <p/>
* THIS IS BROKEN IN PUMP... SENDING ONLY 1 PROFILE
*/
public class MsgSettingBasalProfileAll_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgSettingBasalProfileAll_k() {
SetCommand(0x3206);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
if (pump.basal48Enable) {
pump.pumpProfiles = new double[4][];
for (int profile = 0; profile < 4; profile++) {
int position = intFromBuff(bytes, 107 * profile, 1);
pump.pumpProfiles[position] = new double[48];
for (int index = 0; index < 48; index++) {
int basal = intFromBuff(bytes, 107 * profile + 2 * index + 1, 2);
if (basal < 10) basal = 0;
pump.pumpProfiles[position][index] = basal / 100 / 24d; // in units/day
}
}
} else {
pump.pumpProfiles = new double[4][];
for (int profile = 0; profile < 4; profile++) {
int position = intFromBuff(bytes, 49 * profile, 1);
log.debug("position " + position);
pump.pumpProfiles[position] = new double[24];
for (int index = 0; index < 24; index++) {
int basal = intFromBuff(bytes, 59 * profile + 2 * index + 1, 2);
if (basal < 10) basal = 0;
log.debug("position " + position + " index " + index);
pump.pumpProfiles[position][index] = basal / 100 / 24d; // in units/day
}
}
}
if (L.isEnabled(L.PUMPCOMM)) {
if (pump.basal48Enable) {
for (int profile = 0; profile < 4; profile++) {
for (int index = 0; index < 24; index++) {
log.debug("Basal profile " + profile + ": " + String.format(Locale.ENGLISH, "%02d", index) + "h: " + pump.pumpProfiles[profile][index]);
}
}
} else {
for (int profile = 0; profile < 4; profile++) {
for (int index = 0; index < 48; index++) {
log.debug("Basal profile " + profile + ": " +
String.format(Locale.ENGLISH, "%02d", (index / 2)) +
":" + String.format(Locale.ENGLISH, "%02d", (index % 2) * 30) + " : " +
pump.pumpProfiles[profile][index]);
}
}
}
}
}
}

View file

@ -0,0 +1,66 @@
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase
import java.util.*
/**
* Created by mike on 05.07.2016.
*
*
*
*
* THIS IS BROKEN IN PUMP... SENDING ONLY 1 PROFILE
*/
class MsgSettingBasalProfileAll_k(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump
) : MessageBase() {
init {
SetCommand(0x3206)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
danaRPump.pumpProfiles = Array(4) { Array(48) { 0.0 } }
if (danaRPump.basal48Enable) {
for (profile in 0..3) {
val position = intFromBuff(bytes, 107 * profile, 1)
for (index in 0..47) {
var basal = intFromBuff(bytes, 107 * profile + 2 * index + 1, 2)
if (basal < 10) basal = 0
danaRPump.pumpProfiles!![position][index] = basal / 100 / 24.0 // in units/day
}
}
} else {
for (profile in 0..3) {
val position = intFromBuff(bytes, 49 * profile, 1)
aapsLogger.debug(LTag.PUMPCOMM, "position $position")
for (index in 0..23) {
var basal = intFromBuff(bytes, 59 * profile + 2 * index + 1, 2)
if (basal < 10) basal = 0
aapsLogger.debug(LTag.PUMPCOMM, "position $position index $index")
danaRPump.pumpProfiles!![position][index] = basal / 100 / 24.0 // in units/day
}
}
}
if (danaRPump.basal48Enable) {
for (profile in 0..3) {
for (index in 0..23) {
aapsLogger.debug(LTag.PUMPCOMM, "Basal profile " + profile + ": " + String.format(Locale.ENGLISH, "%02d", index) + "h: " + danaRPump.pumpProfiles!![profile][index])
}
}
} else {
for (profile in 0..3) {
for (index in 0..47) {
aapsLogger.debug(LTag.PUMPCOMM, "Basal profile " + profile + ": " + String.format(Locale.ENGLISH, "%02d", index / 2) +
":" + String.format(Locale.ENGLISH, "%02d", index % 2 * 30) + " : " +
danaRPump.pumpProfiles!![profile][index])
}
}
}
}
}

View file

@ -1,40 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Locale;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
/**
* Created by mike on 05.07.2016.
*/
public class MsgSettingBasal_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgSettingBasal_k() {
SetCommand(0x3202);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
if (pump.pumpProfiles == null) pump.pumpProfiles = new double[4][];
pump.pumpProfiles[pump.activeProfile] = new double[24];
for (int index = 0; index < 24; index++) {
int basal = intFromBuff(bytes, 2 * index, 2);
if (basal < DanaRKoreanPlugin.getPlugin().pumpDescription.basalMinimumRate) basal = 0;
pump.pumpProfiles[pump.activeProfile][index] = basal / 100d;
}
if (L.isEnabled(L.PUMPCOMM))
for (int index = 0; index < 24; index++) {
log.debug("Basal " + String.format(Locale.ENGLISH, "%02d", index) + "h: " + pump.pumpProfiles[pump.activeProfile][index]);
}
}
}

View file

@ -0,0 +1,32 @@
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin
import java.util.*
class MsgSettingBasal_k(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump,
private val danaRKoreanPlugin: DanaRKoreanPlugin
) : MessageBase() {
init {
SetCommand(0x3202)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
danaRPump.pumpProfiles = Array(4) {Array(48) {0.0} }
for (index in 0..23) {
var basal = intFromBuff(bytes, 2 * index, 2)
if (basal < danaRKoreanPlugin.pumpDescription.basalMinimumRate) basal = 0
danaRPump.pumpProfiles!![danaRPump.activeProfile][index] = basal / 100.0
}
for (index in 0..23)
aapsLogger.debug(LTag.PUMPCOMM, "Basal " + String.format(Locale.ENGLISH, "%02d", index) + "h: " + danaRPump.pumpProfiles!![danaRPump.activeProfile][index])
}
}

View file

@ -1,41 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
public class MsgStatusBasic_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgStatusBasic_k() {
SetCommand(0x020A);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
double currentBasal = intFromBuff(bytes, 0, 2) / 100d;
int batteryRemaining = intFromBuff(bytes, 2, 1);
double reservoirRemainingUnits = intFromBuff(bytes, 3, 3) / 750d;
double dailyTotalUnits = intFromBuff(bytes, 6, 3) / 750d;
int maxDailyTotalUnits = intFromBuff(bytes, 9, 2) / 100;
pump.dailyTotalUnits = dailyTotalUnits;
pump.maxDailyTotalUnits = maxDailyTotalUnits;
pump.reservoirRemainingUnits = reservoirRemainingUnits;
pump.currentBasal = currentBasal;
pump.batteryRemaining = batteryRemaining;
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Daily total units: " + dailyTotalUnits);
log.debug("Max daily total units: " + maxDailyTotalUnits);
log.debug("Reservoir remaining units: " + reservoirRemainingUnits);
log.debug("Current basal: " + currentBasal);
}
}
}

View file

@ -0,0 +1,34 @@
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase
class MsgStatusBasic_k(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump
) : MessageBase() {
init {
SetCommand(0x020A)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
val currentBasal = intFromBuff(bytes, 0, 2) / 100.0
val batteryRemaining = intFromBuff(bytes, 2, 1)
val reservoirRemainingUnits = intFromBuff(bytes, 3, 3) / 750.0
val dailyTotalUnits = intFromBuff(bytes, 6, 3) / 750.0
val maxDailyTotalUnits = intFromBuff(bytes, 9, 2) / 100
danaRPump.dailyTotalUnits = dailyTotalUnits
danaRPump.maxDailyTotalUnits = maxDailyTotalUnits
danaRPump.reservoirRemainingUnits = reservoirRemainingUnits
danaRPump.currentBasal = currentBasal
danaRPump.batteryRemaining = batteryRemaining
aapsLogger.debug(LTag.PUMPCOMM, "Daily total units: $dailyTotalUnits")
aapsLogger.debug(LTag.PUMPCOMM, "Max daily total units: $maxDailyTotalUnits")
aapsLogger.debug(LTag.PUMPCOMM, "Reservoir remaining units: $reservoirRemainingUnits")
aapsLogger.debug(LTag.PUMPCOMM, "Current basal: $currentBasal")
}
}

View file

@ -1,42 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase;
public class MsgStatus_k extends MessageBase {
private static Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public MsgStatus_k() {
SetCommand(0x020B);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public void handleMessage(byte[] bytes) {
DanaRPump pump = DanaRPump.getInstance();
pump.dailyTotalUnits = intFromBuff(bytes, 0, 3) / 750d;
pump.isExtendedInProgress = intFromBuff(bytes, 3, 1) == 1;
pump.extendedBolusMinutes = intFromBuff(bytes, 4, 2);
pump.extendedBolusAmount = intFromBuff(bytes, 6, 2) / 100d;
double lastBolusAmount = intFromBuff(bytes, 13, 2) / 100d;
// if (lastBolusAmount != 0d) {
// pump.lastBolusTime = dateTimeFromBuff(bytes, 8);
// pump.lastBolusAmount = lastBolusAmount;
// }
pump.iob = intFromBuff(bytes, 15, 2) / 100d;
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Daily total: " + pump.dailyTotalUnits);
log.debug("Is extended bolus running: " + pump.isExtendedInProgress);
log.debug("Extended bolus min: " + pump.extendedBolusMinutes);
log.debug("Extended bolus amount: " + pump.extendedBolusAmount);
// log.debug("Last bolus time: " + pump.lastBolusTime);
// log.debug("Last bolus amount: " + pump.lastBolusAmount);
log.debug("IOB: " + pump.iob);
}
}
}

View file

@ -0,0 +1,37 @@
package info.nightscout.androidaps.plugins.pump.danaRKorean.comm
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaR.comm.MessageBase
class MsgStatus_k(
private val aapsLogger: AAPSLogger,
private val danaRPump: DanaRPump
) : MessageBase() {
init {
SetCommand(0x020B)
aapsLogger.debug(LTag.PUMPCOMM, "New message")
}
override fun handleMessage(bytes: ByteArray) {
danaRPump.dailyTotalUnits = intFromBuff(bytes, 0, 3) / 750.0
danaRPump.isExtendedInProgress = intFromBuff(bytes, 3, 1) == 1
danaRPump.extendedBolusMinutes = intFromBuff(bytes, 4, 2)
danaRPump.extendedBolusAmount = intFromBuff(bytes, 6, 2) / 100.0
//val lastBolusAmount = intFromBuff(bytes, 13, 2) / 100.0
//if (lastBolusAmount != 0d) {
// pump.lastBolusTime = dateTimeFromBuff(bytes, 8);
// pump.lastBolusAmount = lastBolusAmount;
//}
danaRPump.iob = intFromBuff(bytes, 15, 2) / 100.0
aapsLogger.debug(LTag.PUMPCOMM, "Daily total: " + danaRPump.dailyTotalUnits)
aapsLogger.debug(LTag.PUMPCOMM, "Is extended bolus running: " + danaRPump.isExtendedInProgress)
aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus min: " + danaRPump.extendedBolusMinutes)
aapsLogger.debug(LTag.PUMPCOMM, "Extended bolus amount: " + danaRPump.extendedBolusAmount)
//aapsLogger.debug(LTag.PUMPCOMM, "Last bolus time: " + pump.lastBolusTime);
//aapsLogger.debug(LTag.PUMPCOMM, "Last bolus amount: " + pump.lastBolusAmount);
aapsLogger.debug(LTag.PUMPCOMM, "IOB: " + danaRPump.iob)
}
}

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.plugins.pump.danaRKorean.services;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.IntentFilter;
import android.os.Binder;
import android.os.SystemClock;
@ -8,8 +9,9 @@ import android.os.SystemClock;
import java.io.IOException;
import java.util.Date;
import javax.inject.Inject;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.PumpEnactResult;
@ -19,14 +21,17 @@ import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventProfileNeedsUpdate;
import info.nightscout.androidaps.events.EventPumpStatusChanged;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.interfaces.CommandQueueProvider;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.plugins.pump.danaR.SerialIOThread;
import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgBolusProgress;
@ -50,7 +55,8 @@ import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusBolusExtended
import info.nightscout.androidaps.plugins.pump.danaR.comm.MsgStatusTempBasal;
import info.nightscout.androidaps.plugins.pump.danaR.events.EventDanaRNewStatus;
import info.nightscout.androidaps.plugins.pump.danaR.services.AbstractDanaRExecutionService;
import info.nightscout.androidaps.plugins.pump.danaRKorean.comm.MessageHashTableRkorean;
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
import info.nightscout.androidaps.plugins.pump.danaRKorean.comm.MessageHashTableRKorean;
import info.nightscout.androidaps.plugins.pump.danaRKorean.comm.MsgCheckValue_k;
import info.nightscout.androidaps.plugins.pump.danaRKorean.comm.MsgSettingBasal_k;
import info.nightscout.androidaps.plugins.pump.danaRKorean.comm.MsgStatusBasic_k;
@ -59,22 +65,34 @@ import info.nightscout.androidaps.queue.commands.Command;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.T;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
@Inject AAPSLogger aapsLogger;
@Inject RxBusWrapper rxBus;
@Inject ResourceHelper resourceHelper;
@Inject DanaRPump danaRPump;
@Inject DanaRPlugin danaRPlugin;
@Inject DanaRKoreanPlugin danaRKoreanPlugin;
@Inject ConfigBuilderPlugin configBuilderPlugin;
@Inject CommandQueueProvider commandQueue;
@Inject Context context;
@Inject MessageHashTableRKorean messageHashTableRKorean;
@Inject ActivePluginProvider activePlugin;
private CompositeDisposable disposable = new CompositeDisposable();
public DanaRKoreanExecutionService() {
mBinder = new LocalBinder();
MainApp.instance().getApplicationContext().registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
}
@Override
public void onCreate() {
super.onCreate();
disposable.add(RxBus.Companion.getINSTANCE()
mBinder = new LocalBinder();
context.registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));
disposable.add(rxBus
.toObservable(EventPreferenceChange.class)
.observeOn(Schedulers.io())
.subscribe(event -> {
@ -82,7 +100,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
mSerialIOThread.disconnect("EventPreferenceChange");
}, exception -> FabricPrivacy.getInstance().logException(exception))
);
disposable.add(RxBus.Companion.getINSTANCE()
disposable.add(rxBus
.toObservable(EventAppExit.class)
.observeOn(Schedulers.io())
.subscribe(event -> {
@ -91,7 +109,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
if (mSerialIOThread != null)
mSerialIOThread.disconnect("Application exit");
MainApp.instance().getApplicationContext().unregisterReceiver(receiver);
context.unregisterReceiver(receiver);
stopSelf();
}, exception -> FabricPrivacy.getInstance().logException(exception))
);
@ -135,9 +153,9 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
if (mSerialIOThread != null) {
mSerialIOThread.disconnect("Recreate SerialIOThread");
}
mSerialIOThread = new SerialIOThread(mRfcommSocket, MessageHashTableRkorean.INSTANCE);
mSerialIOThread = new SerialIOThread(mRfcommSocket, messageHashTableRKorean, danaRPump);
mHandshakeInProgress = true;
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.HANDSHAKING, 0));
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.HANDSHAKING, 0));
}
mConnectionInProgress = false;
@ -145,16 +163,15 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
}
public void getPumpStatus() {
DanaRPump danaRPump = DanaRPump.getInstance();
try {
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpstatus)));
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpstatus)));
//MsgStatus_k statusMsg = new MsgStatus_k();
MsgStatusBasic_k statusBasicMsg = new MsgStatusBasic_k();
MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal();
MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended();
MsgCheckValue_k checkValue = new MsgCheckValue_k();
MsgStatusBasic_k statusBasicMsg = new MsgStatusBasic_k(aapsLogger, danaRPump);
MsgStatusTempBasal tempStatusMsg = new MsgStatusTempBasal(aapsLogger, danaRPump, activePlugin);
MsgStatusBolusExtended exStatusMsg = new MsgStatusBolusExtended(aapsLogger, danaRPump, activePlugin);
MsgCheckValue_k checkValue = new MsgCheckValue_k(aapsLogger, danaRPump, danaRKoreanPlugin);
if (danaRPump.isNewPump) {
if (danaRPump.isNewPump()) {
mSerialIOThread.sendMessage(checkValue);
if (!checkValue.received) {
return;
@ -163,70 +180,69 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
//mSerialIOThread.sendMessage(statusMsg);
mSerialIOThread.sendMessage(statusBasicMsg);
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingtempbasalstatus)));
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingtempbasalstatus)));
mSerialIOThread.sendMessage(tempStatusMsg);
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingextendedbolusstatus)));
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingextendedbolusstatus)));
mSerialIOThread.sendMessage(exStatusMsg);
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingbolusstatus)));
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingbolusstatus)));
long now = System.currentTimeMillis();
danaRPump.lastConnection = now;
danaRPump.setLastConnection(now);
Profile profile = ProfileFunctions.getInstance().getProfile();
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
if (profile != null && Math.abs(danaRPump.currentBasal - profile.getBasal()) >= pump.getPumpDescription().basalStep) {
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings)));
mSerialIOThread.sendMessage(new MsgSettingBasal());
if (!pump.isThisProfileSet(profile) && !ConfigBuilderPlugin.getPlugin().getCommandQueue().isRunning(Command.CommandType.BASAL_PROFILE)) {
RxBus.Companion.getINSTANCE().send(new EventProfileNeedsUpdate());
if (profile != null && Math.abs(danaRPump.getCurrentBasal() - profile.getBasal()) >= danaRKoreanPlugin.getPumpDescription().basalStep) {
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpsettings)));
mSerialIOThread.sendMessage(new MsgSettingBasal(aapsLogger, danaRPump, danaRPlugin));
if (!danaRKoreanPlugin.isThisProfileSet(profile) && !commandQueue.isRunning(Command.CommandType.BASAL_PROFILE)) {
rxBus.send(new EventProfileNeedsUpdate());
}
}
if (danaRPump.lastSettingsRead + 60 * 60 * 1000L < now || !pump.isInitialized()) {
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumpsettings)));
mSerialIOThread.sendMessage(new MsgSettingShippingInfo());
mSerialIOThread.sendMessage(new MsgSettingMeal());
mSerialIOThread.sendMessage(new MsgSettingBasal_k());
if (danaRPump.getLastSettingsRead() + 60 * 60 * 1000L < now || !danaRKoreanPlugin.isInitialized()) {
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumpsettings)));
mSerialIOThread.sendMessage(new MsgSettingShippingInfo(aapsLogger, danaRPump));
mSerialIOThread.sendMessage(new MsgSettingMeal(aapsLogger, rxBus, resourceHelper, danaRPump, danaRKoreanPlugin));
mSerialIOThread.sendMessage(new MsgSettingBasal_k(aapsLogger, danaRPump, danaRKoreanPlugin));
//0x3201
mSerialIOThread.sendMessage(new MsgSettingMaxValues());
mSerialIOThread.sendMessage(new MsgSettingGlucose());
mSerialIOThread.sendMessage(new MsgSettingProfileRatios());
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.gettingpumptime)));
mSerialIOThread.sendMessage(new MsgSettingPumpTime());
if (danaRPump.pumpTime == 0) {
mSerialIOThread.sendMessage(new MsgSettingMaxValues(aapsLogger, danaRPump));
mSerialIOThread.sendMessage(new MsgSettingGlucose(aapsLogger, danaRPump));
mSerialIOThread.sendMessage(new MsgSettingProfileRatios(aapsLogger, danaRPump));
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.gettingpumptime)));
mSerialIOThread.sendMessage(new MsgSettingPumpTime(aapsLogger, danaRPump));
if (danaRPump.getPumpTime() == 0) {
// initial handshake was not successfull
// deinitialize pump
danaRPump.lastConnection = 0;
danaRPump.lastSettingsRead = 0;
RxBus.Companion.getINSTANCE().send(new EventDanaRNewStatus());
RxBus.Companion.getINSTANCE().send(new EventInitializationChanged());
danaRPump.setLastConnection(0);
danaRPump.setLastSettingsRead(0);
rxBus.send(new EventDanaRNewStatus());
rxBus.send(new EventInitializationChanged());
return;
}
long timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
long timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L;
if (L.isEnabled(L.PUMP))
log.debug("Pump time difference: " + timeDiff + " seconds");
if (Math.abs(timeDiff) > 10) {
waitForWholeMinute(); // Dana can set only whole minute
// add 10sec to be sure we are over minute (will be cutted off anyway)
mSerialIOThread.sendMessage(new MsgSetTime(new Date(DateUtil.now() + T.secs(10).msecs())));
mSerialIOThread.sendMessage(new MsgSettingPumpTime());
timeDiff = (danaRPump.pumpTime - System.currentTimeMillis()) / 1000L;
mSerialIOThread.sendMessage(new MsgSettingPumpTime(aapsLogger, danaRPump));
timeDiff = (danaRPump.getPumpTime() - System.currentTimeMillis()) / 1000L;
if (L.isEnabled(L.PUMP))
log.debug("Pump time difference: " + timeDiff + " seconds");
}
danaRPump.lastSettingsRead = now;
danaRPump.setLastSettingsRead(now);
}
RxBus.Companion.getINSTANCE().send(new EventDanaRNewStatus());
RxBus.Companion.getINSTANCE().send(new EventInitializationChanged());
rxBus.send(new EventDanaRNewStatus());
rxBus.send(new EventInitializationChanged());
//NSUpload.uploadDeviceStatus();
if (danaRPump.dailyTotalUnits > danaRPump.maxDailyTotalUnits * Constants.dailyLimitWarning) {
if (danaRPump.getDailyTotalUnits() > danaRPump.getMaxDailyTotalUnits() * Constants.dailyLimitWarning) {
if (L.isEnabled(L.PUMP))
log.debug("Approaching daily limit: " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits);
log.debug("Approaching daily limit: " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits());
if (System.currentTimeMillis() > lastApproachingDailyLimit + 30 * 60 * 1000) {
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, MainApp.gs(R.string.approachingdailylimit), Notification.URGENT);
RxBus.Companion.getINSTANCE().send(new EventNewNotification(reportFail));
NSUpload.uploadError(MainApp.gs(R.string.approachingdailylimit) + ": " + danaRPump.dailyTotalUnits + "/" + danaRPump.maxDailyTotalUnits + "U");
Notification reportFail = new Notification(Notification.APPROACHING_DAILY_LIMIT, resourceHelper.gs(R.string.approachingdailylimit), Notification.URGENT);
rxBus.send(new EventNewNotification(reportFail));
NSUpload.uploadError(resourceHelper.gs(R.string.approachingdailylimit) + ": " + danaRPump.getDailyTotalUnits() + "/" + danaRPump.getMaxDailyTotalUnits() + "U");
lastApproachingDailyLimit = System.currentTimeMillis();
}
}
@ -236,44 +252,43 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
}
public boolean tempBasal(int percent, int durationInHours) {
DanaRPump danaRPump = DanaRPump.getInstance();
if (!isConnected()) return false;
if (danaRPump.isTempBasalInProgress) {
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal)));
if (danaRPump.isTempBasalInProgress()) {
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
SystemClock.sleep(500);
}
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.settingtempbasal)));
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStart(percent, durationInHours));
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
mSerialIOThread.sendMessage(new MsgStatusTempBasal(aapsLogger, danaRPump, activePlugin));
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
return true;
}
public boolean tempBasalStop() {
if (!isConnected()) return false;
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingtempbasal)));
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingtempbasal)));
mSerialIOThread.sendMessage(new MsgSetTempBasalStop());
mSerialIOThread.sendMessage(new MsgStatusTempBasal());
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
mSerialIOThread.sendMessage(new MsgStatusTempBasal(aapsLogger, danaRPump, activePlugin));
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
return true;
}
public boolean extendedBolus(double insulin, int durationInHalfHours) {
if (!isConnected()) return false;
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.settingextendedbolus)));
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.settingextendedbolus)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStart(insulin, (byte) (durationInHalfHours & 0xFF)));
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
mSerialIOThread.sendMessage(new MsgStatusBolusExtended(aapsLogger, danaRPump, activePlugin));
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
return true;
}
public boolean extendedBolusStop() {
if (!isConnected()) return false;
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.stoppingextendedbolus)));
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.stoppingextendedbolus)));
mSerialIOThread.sendMessage(new MsgSetExtendedBolusStop());
mSerialIOThread.sendMessage(new MsgStatusBolusExtended());
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
mSerialIOThread.sendMessage(new MsgStatusBolusExtended(aapsLogger, danaRPump, activePlugin));
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
return true;
}
@ -315,7 +330,7 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
SystemClock.sleep(300);
mBolusingTreatment = null;
ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("bolusOK", null);
commandQueue.readStatus("bolusOK", null);
}
return !start.failed;
@ -339,15 +354,14 @@ public class DanaRKoreanExecutionService extends AbstractDanaRExecutionService {
}
public boolean updateBasalsInPump(final Profile profile) {
DanaRPump danaRPump = DanaRPump.getInstance();
if (!isConnected()) return false;
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(MainApp.gs(R.string.updatingbasalrates)));
double[] basal = DanaRPump.getInstance().buildDanaRProfileRecord(profile);
rxBus.send(new EventPumpStatusChanged(resourceHelper.gs(R.string.updatingbasalrates)));
Double[] basal = danaRPump.buildDanaRProfileRecord(profile);
MsgSetSingleBasalProfile msgSet = new MsgSetSingleBasalProfile(basal);
mSerialIOThread.sendMessage(msgSet);
danaRPump.lastSettingsRead = 0; // force read full settings
danaRPump.setLastSettingsRead(0); // force read full settings
getPumpStatus();
RxBus.Companion.getINSTANCE().send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
rxBus.send(new EventPumpStatusChanged(EventPumpStatusChanged.Status.DISCONNECTING));
return true;
}

View file

@ -52,7 +52,6 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRFragment;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes;
import info.nightscout.androidaps.plugins.pump.danaRS.comm.DanaRS_Packet_Bolus_Set_Step_Bolus_Start;
import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSDeviceChange;
import info.nightscout.androidaps.plugins.pump.danaRS.services.DanaRSService;
import info.nightscout.androidaps.plugins.treatments.Treatment;
@ -79,6 +78,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
private final SP sp;
private final RxBusWrapper rxBus;
private final CommandQueueProvider commandQueue;
private final DanaRPump danaRPump;
private static DanaRSService danaRSService;
@ -87,6 +87,17 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
public static PumpDescription pumpDescription = new PumpDescription();
// Bolus & history handling
public int bolusStartErrorCode; // from start message
public Treatment bolusingTreatment; // actually delivered treatment
public double bolusAmountToBeDelivered = 0.0; // amount to be delivered
public boolean bolusStopped = false; // bolus finished
public boolean bolusStopForced = false; // bolus forced to stop by user
public boolean bolusDone = false; // success end
public long bolusProgressLastTimeStamp = 0; // timestamp of last bolus progress message
public boolean apsHistoryDone = false; // true when last history message is received
public long lastEventTimeLoaded = 0; // timestamp of last received event
@Inject
public DanaRSPlugin(
AAPSLogger aapsLogger,
@ -97,7 +108,8 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
ProfileFunction profileFunction,
TreatmentsPlugin treatmentsPlugin,
SP sp,
CommandQueueProvider commandQueue
CommandQueueProvider commandQueue,
DanaRPump danaRPump
) {
super(new PluginDescription()
.mainType(PluginType.PUMP)
@ -116,6 +128,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
this.treatmentsPlugin = treatmentsPlugin;
this.sp = sp;
this.commandQueue = commandQueue;
this.danaRPump = danaRPump;
pumpDescription.setPumpDescription(PumpType.DanaRS);
}
@ -218,8 +231,8 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
public void getPumpStatus() {
if (danaRSService != null) {
danaRSService.getPumpStatus();
pumpDescription.basalStep = DanaRPump.getInstance().basalStep;
pumpDescription.bolusStep = DanaRPump.getInstance().bolusStep;
pumpDescription.basalStep = danaRPump.getBasalStep();
pumpDescription.bolusStep = danaRPump.getBolusStep();
}
}
@ -245,7 +258,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
@NonNull
@Override
public Constraint<Double> applyBasalConstraints(Constraint<Double> absoluteRate, @NonNull Profile profile) {
absoluteRate.setIfSmaller(DanaRPump.getInstance().maxBasal, resourceHelper.gs(R.string.limitingbasalratio, DanaRPump.getInstance().maxBasal, resourceHelper.gs(R.string.pumplimit)), this);
absoluteRate.setIfSmaller(danaRPump.getMaxBasal(), resourceHelper.gs(R.string.limitingbasalratio, danaRPump.getMaxBasal(), resourceHelper.gs(R.string.pumplimit)), this);
return absoluteRate;
}
@ -262,7 +275,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
@NonNull
@Override
public Constraint<Double> applyBolusConstraints(Constraint<Double> insulin) {
insulin.setIfSmaller(DanaRPump.getInstance().maxBolus, resourceHelper.gs(R.string.limitingbolus, DanaRPump.getInstance().maxBolus, resourceHelper.gs(R.string.pumplimit)), this);
insulin.setIfSmaller(danaRPump.getMaxBolus(), resourceHelper.gs(R.string.limitingbolus, danaRPump.getMaxBolus(), resourceHelper.gs(R.string.pumplimit)), this);
return insulin;
}
@ -276,12 +289,12 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
@Override
public boolean isInitialized() {
return DanaRPump.getInstance().lastConnection > 0 && DanaRPump.getInstance().maxBasal > 0;
return danaRPump.getLastConnection() > 0 && danaRPump.getMaxBasal() > 0;
}
@Override
public boolean isSuspended() {
return DanaRPump.getInstance().pumpSuspended;
return danaRPump.getPumpSuspended();
}
@Override
@ -329,13 +342,12 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
public boolean isThisProfileSet(Profile profile) {
if (!isInitialized())
return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS
DanaRPump pump = DanaRPump.getInstance();
if (pump.pumpProfiles == null)
if (danaRPump.getPumpProfiles() == null)
return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS
int basalValues = pump.basal48Enable ? 48 : 24;
int basalIncrement = pump.basal48Enable ? 30 * 60 : 60 * 60;
int basalValues = danaRPump.getBasal48Enable() ? 48 : 24;
int basalIncrement = danaRPump.getBasal48Enable() ? 30 * 60 : 60 * 60;
for (int h = 0; h < basalValues; h++) {
Double pumpValue = pump.pumpProfiles[pump.activeProfile][h];
Double pumpValue = danaRPump.getPumpProfiles()[danaRPump.getActiveProfile()][h];
Double profileValue = profile.getBasalTimeFromMidnight(h * basalIncrement);
if (Math.abs(pumpValue - profileValue) > getPumpDescription().basalStep) {
getAapsLogger().debug(LTag.PUMP, "Diff found. Hour: " + h + " Pump: " + pumpValue + " Profile: " + profileValue);
@ -347,22 +359,22 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
@Override
public long lastDataTime() {
return DanaRPump.getInstance().lastConnection;
return danaRPump.getLastConnection();
}
@Override
public double getBaseBasalRate() {
return DanaRPump.getInstance().currentBasal;
return danaRPump.getCurrentBasal();
}
@Override
public double getReservoirLevel() {
return DanaRPump.getInstance().reservoirRemainingUnits;
return danaRPump.getReservoirRemainingUnits();
}
@Override
public int getBatteryLevel() {
return DanaRPump.getInstance().batteryRemaining;
return danaRPump.getBatteryRemaining();
}
@NonNull @Override
@ -405,8 +417,8 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
result.bolusDelivered = t.insulin;
result.carbsDelivered = detailedBolusInfo.carbs;
if (!result.success) {
String error = "" + DanaRS_Packet_Bolus_Set_Step_Bolus_Start.errorCode;
switch (DanaRS_Packet_Bolus_Set_Step_Bolus_Start.errorCode) {
String error = "" + bolusStartErrorCode;
switch (bolusStartErrorCode) {
// 4 reported as max bolus violation. Check later
case 0x10:
error = resourceHelper.gs(R.string.maxbolusviolation);
@ -527,7 +539,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
@NonNull @Override
public synchronized PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes, Profile profile, boolean enforceNew) {
DanaRPump pump = DanaRPump.getInstance();
DanaRPump pump = danaRPump;
PumpEnactResult result = new PumpEnactResult();
percent = constraintChecker.applyBasalPercentConstraints(new Constraint<>(percent), profile).value();
if (percent < 0) {
@ -547,8 +559,8 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
result.success = true;
result.isTempCancel = false;
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent;
result.duration = pump.getTempBasalRemainingMin();
result.percent = pump.getTempBasalPercent();
result.isPercent = true;
getAapsLogger().debug(LTag.PUMP, "setTempBasalPercent: Correct value already set");
return result;
@ -560,13 +572,13 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
int durationInHours = Math.max(durationInMinutes / 60, 1);
connectionOK = danaRSService.tempBasal(percent, durationInHours);
}
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
if (connectionOK && pump.isTempBasalInProgress() && pump.getTempBasalPercent() == percent) {
result.enacted = true;
result.success = true;
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
result.isTempCancel = false;
result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent;
result.duration = pump.getTempBasalRemainingMin();
result.percent = pump.getTempBasalPercent();
result.isPercent = true;
getAapsLogger().debug(LTag.PUMP, "setTempBasalPercent: OK");
return result;
@ -579,16 +591,16 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
}
private synchronized PumpEnactResult setHighTempBasalPercent(Integer percent) {
DanaRPump pump = DanaRPump.getInstance();
DanaRPump pump = danaRPump;
PumpEnactResult result = new PumpEnactResult();
boolean connectionOK = danaRSService.highTempBasal(percent);
if (connectionOK && pump.isTempBasalInProgress && pump.tempBasalPercent == percent) {
if (connectionOK && pump.isTempBasalInProgress() && pump.getTempBasalPercent() == percent) {
result.enacted = true;
result.success = true;
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
result.isTempCancel = false;
result.duration = pump.tempBasalRemainingMin;
result.percent = pump.tempBasalPercent;
result.duration = pump.getTempBasalRemainingMin();
result.percent = pump.getTempBasalPercent();
result.isPercent = true;
getAapsLogger().debug(LTag.PUMP, "setHighTempBasalPercent: OK");
return result;
@ -602,7 +614,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
@NonNull @Override
public synchronized PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
DanaRPump pump = DanaRPump.getInstance();
DanaRPump pump = danaRPump;
insulin = constraintChecker.applyExtendedBolusConstraints(new Constraint<>(insulin)).value();
// needs to be rounded
int durationInHalfHours = Math.max(durationInMinutes / 30, 1);
@ -613,22 +625,22 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
result.enacted = false;
result.success = true;
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
result.duration = pump.extendedBolusRemainingMinutes;
result.absolute = pump.extendedBolusAbsoluteRate;
result.duration = pump.getExtendedBolusRemainingMinutes();
result.absolute = pump.getExtendedBolusAbsoluteRate();
result.isPercent = false;
result.isTempCancel = false;
getAapsLogger().debug(LTag.PUMP, "setExtendedBolus: Correct extended bolus already set. Current: " + pump.extendedBolusAmount + " Asked: " + insulin);
getAapsLogger().debug(LTag.PUMP, "setExtendedBolus: Correct extended bolus already set. Current: " + pump.getExtendedBolusAmount() + " Asked: " + insulin);
return result;
}
boolean connectionOK = danaRSService.extendedBolus(insulin, durationInHalfHours);
if (connectionOK && pump.isExtendedInProgress && Math.abs(pump.extendedBolusAbsoluteRate - insulin) < getPumpDescription().extendedBolusStep) {
if (connectionOK && pump.isExtendedInProgress() && Math.abs(pump.getExtendedBolusAbsoluteRate() - insulin) < getPumpDescription().extendedBolusStep) {
result.enacted = true;
result.success = true;
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
result.isTempCancel = false;
result.duration = pump.extendedBolusRemainingMinutes;
result.absolute = pump.extendedBolusAbsoluteRate;
result.bolusDelivered = pump.extendedBolusAmount;
result.duration = pump.getExtendedBolusRemainingMinutes();
result.absolute = pump.getExtendedBolusAbsoluteRate();
result.bolusDelivered = pump.getExtendedBolusAmount();
result.isPercent = false;
getAapsLogger().debug(LTag.PUMP, "setExtendedBolus: OK");
return result;
@ -649,7 +661,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
result.enacted = true;
result.isTempCancel = true;
}
if (!DanaRPump.getInstance().isTempBasalInProgress) {
if (!danaRPump.isTempBasalInProgress()) {
result.success = true;
result.isTempCancel = true;
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
@ -673,7 +685,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
result.enacted = true;
result.isTempCancel = true;
}
if (!DanaRPump.getInstance().isExtendedInProgress) {
if (!danaRPump.isExtendedInProgress()) {
result.success = true;
result.comment = resourceHelper.gs(R.string.virtualpump_resultok);
getAapsLogger().debug(LTag.PUMP, "cancelExtendedBolus: OK");
@ -688,9 +700,9 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
@NonNull @Override
public JSONObject getJSONStatus(Profile profile, String profileName) {
DanaRPump pump = DanaRPump.getInstance();
DanaRPump pump = danaRPump;
long now = System.currentTimeMillis();
if (pump.lastConnection + 5 * 60 * 1000L < System.currentTimeMillis()) {
if (pump.getLastConnection() + 5 * 60 * 1000L < System.currentTimeMillis()) {
return new JSONObject();
}
JSONObject pumpjson = new JSONObject();
@ -698,14 +710,13 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
JSONObject status = new JSONObject();
JSONObject extended = new JSONObject();
try {
battery.put("percent", pump.batteryRemaining);
status.put("status", pump.pumpSuspended ? "suspended" : "normal");
status.put("timestamp", DateUtil.toISOString(pump.lastConnection));
battery.put("percent", pump.getBatteryRemaining());
status.put("status", pump.getPumpSuspended() ? "suspended" : "normal");
status.put("timestamp", DateUtil.toISOString(pump.getLastConnection()));
extended.put("Version", BuildConfig.VERSION_NAME + "-" + BuildConfig.BUILDVERSION);
extended.put("PumpIOB", pump.iob);
if (pump.lastBolusTime != 0) {
extended.put("LastBolus", DateUtil.dateAndTimeFullString(pump.lastBolusTime));
extended.put("LastBolusAmount", pump.lastBolusAmount);
if (pump.getLastBolusTime() != 0) {
extended.put("LastBolus", DateUtil.dateAndTimeString(pump.getLastBolusTime()));
extended.put("LastBolusAmount", pump.getLastBolusAmount());
}
TemporaryBasal tb = treatmentsPlugin.getTempBasalFromHistory(now);
if (tb != null) {
@ -729,7 +740,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
pumpjson.put("battery", battery);
pumpjson.put("status", status);
pumpjson.put("extended", extended);
pumpjson.put("reservoir", (int) pump.reservoirRemainingUnits);
pumpjson.put("reservoir", (int) pump.getReservoirRemainingUnits());
pumpjson.put("clock", DateUtil.toISOString(now));
} catch (JSONException e) {
getAapsLogger().error("Unhandled exception", e);
@ -749,7 +760,7 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
@NonNull @Override
public String serialNumber() {
return DanaRPump.getInstance().serialNumber;
return danaRPump.getSerialNumber();
}
@NonNull @Override
@ -759,15 +770,15 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
@NonNull @Override
public String shortStatus(boolean veryShort) {
DanaRPump pump = DanaRPump.getInstance();
DanaRPump pump = danaRPump;
String ret = "";
if (pump.lastConnection != 0) {
long agoMsec = System.currentTimeMillis() - pump.lastConnection;
if (pump.getLastConnection() != 0) {
long agoMsec = System.currentTimeMillis() - pump.getLastConnection();
int agoMin = (int) (agoMsec / 60d / 1000d);
ret += "LastConn: " + agoMin + " minago\n";
}
if (pump.lastBolusTime != 0) {
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.lastBolusAmount) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.lastBolusTime) + "\n";
if (pump.getLastBolusTime() != 0) {
ret += "LastBolus: " + DecimalFormatter.to2Decimal(pump.getLastBolusAmount()) + "U @" + android.text.format.DateFormat.format("HH:mm", pump.getLastBolusTime()) + "\n";
}
TemporaryBasal activeTemp = treatmentsPlugin.getRealTempBasalFromHistory(System.currentTimeMillis());
if (activeTemp != null) {
@ -778,10 +789,10 @@ public class DanaRSPlugin extends PumpPluginBase implements PumpInterface, DanaR
ret += "Extended: " + activeExtendedBolus.toString() + "\n";
}
if (!veryShort) {
ret += "TDD: " + DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U\n";
ret += "TDD: " + DecimalFormatter.to0Decimal(pump.getDailyTotalUnits()) + " / " + pump.getMaxDailyTotalUnits() + " U\n";
}
ret += "Reserv: " + DecimalFormatter.to0Decimal(pump.reservoirRemainingUnits) + "U\n";
ret += "Batt: " + pump.batteryRemaining + "\n";
ret += "Reserv: " + DecimalFormatter.to0Decimal(pump.getReservoirRemainingUnits()) + "U\n";
ret += "Batt: " + pump.getBatteryRemaining() + "\n";
return ret;
}

View file

@ -1,97 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import java.util.HashMap;
/**
* Created by mike on 28.05.2016.
*/
public class DanaRSMessageHashTable {
public static HashMap<Integer, DanaRS_Packet> messages = null;
static {
if (messages == null) {
messages = new HashMap<>();
put(new DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal());
put(new DanaRS_Packet_Basal_Get_Basal_Rate());
put(new DanaRS_Packet_Basal_Get_Profile_Basal_Rate());
put(new DanaRS_Packet_Basal_Get_Profile_Number());
put(new DanaRS_Packet_Basal_Set_Basal_Rate());
put(new DanaRS_Packet_Basal_Set_Profile_Basal_Rate());
put(new DanaRS_Packet_Basal_Set_Profile_Number());
put(new DanaRS_Packet_Basal_Set_Suspend_Off());
put(new DanaRS_Packet_Basal_Set_Suspend_On());
put(new DanaRS_Packet_Basal_Set_Temporary_Basal());
put(new DanaRS_Packet_Basal_Get_Temporary_Basal_State());
put(new DanaRS_Packet_Bolus_Get_Bolus_Option());
put(new DanaRS_Packet_Bolus_Get_Initial_Bolus());
put(new DanaRS_Packet_Bolus_Get_Calculation_Information());
put(new DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information());
put(new DanaRS_Packet_Bolus_Get_CIR_CF_Array());
put(new DanaRS_Packet_Bolus_Get_Dual_Bolus());
put(new DanaRS_Packet_Bolus_Get_Extended_Bolus());
put(new DanaRS_Packet_Bolus_Get_Extended_Bolus_State());
put(new DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State());
put(new DanaRS_Packet_Bolus_Get_Step_Bolus_Information());
put(new DanaRS_Packet_Bolus_Set_Bolus_Option());
put(new DanaRS_Packet_Bolus_Set_Initial_Bolus());
put(new DanaRS_Packet_Bolus_Set_CIR_CF_Array());
put(new DanaRS_Packet_Bolus_Set_Dual_Bolus());
put(new DanaRS_Packet_Bolus_Set_Extended_Bolus());
put(new DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel());
put(new DanaRS_Packet_Bolus_Set_Step_Bolus_Start());
put(new DanaRS_Packet_Bolus_Set_Step_Bolus_Stop());
put(new DanaRS_Packet_Etc_Keep_Connection());
put(new DanaRS_Packet_Etc_Set_History_Save());
put(new DanaRS_Packet_General_Delivery_Status());
put(new DanaRS_Packet_General_Get_Password());
put(new DanaRS_Packet_General_Initial_Screen_Information());
put(new DanaRS_Packet_Notify_Alarm());
put(new DanaRS_Packet_Notify_Delivery_Complete());
put(new DanaRS_Packet_Notify_Delivery_Rate_Display());
put(new DanaRS_Packet_Notify_Missed_Bolus_Alarm());
put(new DanaRS_Packet_Option_Get_Pump_Time());
put(new DanaRS_Packet_Option_Get_User_Option());
put(new DanaRS_Packet_Option_Set_Pump_Time());
put(new DanaRS_Packet_Option_Set_User_Option());
//put(new DanaRS_Packet_History_());
put(new DanaRS_Packet_History_Alarm());
put(new DanaRS_Packet_History_All_History());
put(new DanaRS_Packet_History_Basal());
put(new DanaRS_Packet_History_Blood_Glucose());
put(new DanaRS_Packet_History_Bolus());
put(new DanaRS_Packet_Review_Bolus_Avg());
put(new DanaRS_Packet_History_Carbohydrate());
put(new DanaRS_Packet_History_Daily());
put(new DanaRS_Packet_General_Get_More_Information());
put(new DanaRS_Packet_General_Get_Pump_Check());
put(new DanaRS_Packet_General_Get_Shipping_Information());
put(new DanaRS_Packet_General_Get_Today_Delivery_Total());
put(new DanaRS_Packet_General_Get_User_Time_Change_Flag());
put(new DanaRS_Packet_History_Prime());
put(new DanaRS_Packet_History_Refill());
put(new DanaRS_Packet_General_Set_History_Upload_Mode());
put(new DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear());
put(new DanaRS_Packet_History_Suspend());
put(new DanaRS_Packet_History_Temporary());
// APS
put(new DanaRS_Packet_APS_Basal_Set_Temporary_Basal());
put(new DanaRS_Packet_APS_History_Events());
put(new DanaRS_Packet_APS_Set_Event_History());
}
}
public static void put(DanaRS_Packet message) {
int command = message.getCommand();
messages.put(command, message);
}
public static DanaRS_Packet findMessage(Integer command) {
if (messages.containsKey(command)) {
return messages.get(command);
} else {
return new DanaRS_Packet();
}
}
}

View file

@ -0,0 +1,103 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import info.nightscout.androidaps.interfaces.ActivePluginProvider
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
import info.nightscout.androidaps.utils.resources.ResourceHelper
import java.util.*
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class DanaRSMessageHashTable @Inject constructor(
aapsLogger: AAPSLogger,
rxBus: RxBusWrapper,
resourceHelper: ResourceHelper,
danaRPump: DanaRPump,
danaRSPlugin: DanaRSPlugin,
activePlugin: ActivePluginProvider,
constraintChecker: ConstraintChecker
) {
var messages: HashMap<Int, DanaRS_Packet> = HashMap()
fun put(message: DanaRS_Packet) {
messages[message.command] = message
}
fun findMessage(command: Int): DanaRS_Packet {
return messages[command] ?: DanaRS_Packet()
}
init {
put(DanaRS_Packet_Basal_Set_Cancel_Temporary_Basal(aapsLogger))
put(DanaRS_Packet_Basal_Get_Basal_Rate(aapsLogger, rxBus, resourceHelper, danaRPump))
put(DanaRS_Packet_Basal_Get_Profile_Basal_Rate(aapsLogger, danaRPump))
put(DanaRS_Packet_Basal_Get_Profile_Number(aapsLogger, danaRPump))
put(DanaRS_Packet_Basal_Set_Basal_Rate(aapsLogger, arrayOf()))
put(DanaRS_Packet_Basal_Set_Profile_Basal_Rate(aapsLogger, 0, arrayOf()))
put(DanaRS_Packet_Basal_Set_Profile_Number(aapsLogger))
put(DanaRS_Packet_Basal_Set_Suspend_Off(aapsLogger))
put(DanaRS_Packet_Basal_Set_Suspend_On(aapsLogger))
put(DanaRS_Packet_Basal_Set_Temporary_Basal(aapsLogger))
put(DanaRS_Packet_Basal_Get_Temporary_Basal_State(aapsLogger, danaRPump))
put(DanaRS_Packet_Bolus_Get_Bolus_Option(aapsLogger, rxBus, resourceHelper, danaRPump))
put(DanaRS_Packet_Bolus_Get_Initial_Bolus(aapsLogger))
put(DanaRS_Packet_Bolus_Get_Calculation_Information(aapsLogger, danaRPump))
put(DanaRS_Packet_Bolus_Get_Carbohydrate_Calculation_Information(aapsLogger, danaRPump))
put(DanaRS_Packet_Bolus_Get_CIR_CF_Array(aapsLogger, danaRPump))
put(DanaRS_Packet_Bolus_Get_Dual_Bolus(aapsLogger, danaRPump))
put(DanaRS_Packet_Bolus_Get_Extended_Bolus(aapsLogger, danaRPump))
put(DanaRS_Packet_Bolus_Get_Extended_Bolus_State(aapsLogger, danaRPump))
put(DanaRS_Packet_Bolus_Get_Extended_Menu_Option_State(aapsLogger, danaRPump))
put(DanaRS_Packet_Bolus_Get_Step_Bolus_Information(aapsLogger, danaRPump))
put(DanaRS_Packet_Bolus_Set_Bolus_Option(aapsLogger))
put(DanaRS_Packet_Bolus_Set_Initial_Bolus(aapsLogger))
put(DanaRS_Packet_Bolus_Set_CIR_CF_Array(aapsLogger))
put(DanaRS_Packet_Bolus_Set_Dual_Bolus(aapsLogger))
put(DanaRS_Packet_Bolus_Set_Extended_Bolus(aapsLogger))
put(DanaRS_Packet_Bolus_Set_Extended_Bolus_Cancel(aapsLogger))
put(DanaRS_Packet_Bolus_Set_Step_Bolus_Start(aapsLogger, danaRSPlugin, constraintChecker))
put(DanaRS_Packet_Bolus_Set_Step_Bolus_Stop(aapsLogger, rxBus, resourceHelper, danaRSPlugin))
put(DanaRS_Packet_Etc_Keep_Connection(aapsLogger))
put(DanaRS_Packet_Etc_Set_History_Save(aapsLogger))
put(DanaRS_Packet_General_Delivery_Status(aapsLogger))
put(DanaRS_Packet_General_Get_Password(aapsLogger, danaRPump))
put(DanaRS_Packet_General_Initial_Screen_Information(aapsLogger, danaRPump))
put(DanaRS_Packet_Notify_Alarm(aapsLogger, resourceHelper))
put(DanaRS_Packet_Notify_Delivery_Complete(aapsLogger, rxBus, resourceHelper, danaRSPlugin))
put(DanaRS_Packet_Notify_Delivery_Rate_Display(aapsLogger, rxBus, resourceHelper, danaRSPlugin))
put(DanaRS_Packet_Notify_Missed_Bolus_Alarm(aapsLogger))
put(DanaRS_Packet_Option_Get_Pump_Time(aapsLogger, danaRPump))
put(DanaRS_Packet_Option_Get_User_Option(aapsLogger, danaRPump))
put(DanaRS_Packet_Option_Set_Pump_Time(aapsLogger))
put(DanaRS_Packet_Option_Set_User_Option(aapsLogger, danaRPump))
//put(new DanaRS_Packet_History_());
put(DanaRS_Packet_History_Alarm(aapsLogger, rxBus))
put(DanaRS_Packet_History_All_History(aapsLogger, rxBus))
put(DanaRS_Packet_History_Basal(aapsLogger, rxBus))
put(DanaRS_Packet_History_Blood_Glucose(aapsLogger, rxBus))
put(DanaRS_Packet_History_Bolus(aapsLogger, rxBus))
put(DanaRS_Packet_Review_Bolus_Avg(aapsLogger))
put(DanaRS_Packet_History_Carbohydrate(aapsLogger, rxBus))
put(DanaRS_Packet_History_Daily(aapsLogger, rxBus))
put(DanaRS_Packet_General_Get_More_Information(aapsLogger, danaRPump))
put(DanaRS_Packet_General_Get_Pump_Check(aapsLogger, danaRPump, rxBus, resourceHelper))
put(DanaRS_Packet_General_Get_Shipping_Information(aapsLogger, danaRPump))
put(DanaRS_Packet_General_Get_Today_Delivery_Total(aapsLogger, danaRPump))
put(DanaRS_Packet_General_Get_User_Time_Change_Flag(aapsLogger))
put(DanaRS_Packet_History_Prime(aapsLogger, rxBus))
put(DanaRS_Packet_History_Refill(aapsLogger, rxBus))
put(DanaRS_Packet_General_Set_History_Upload_Mode(aapsLogger))
put(DanaRS_Packet_General_Set_User_Time_Change_Flag_Clear(aapsLogger))
put(DanaRS_Packet_History_Suspend(aapsLogger, rxBus))
put(DanaRS_Packet_History_Temporary(aapsLogger, rxBus))
// APS
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_Set_Event_History(aapsLogger, 0, 0, 0, 0))
}
}

View file

@ -18,7 +18,7 @@ public class DanaRS_Packet {
protected static final int DATA_START = 2;
private boolean received;
protected boolean failed;
public boolean failed;
protected int type = BleCommandUtil.DANAR_PACKET__TYPE_RESPONSE; // most of the messages, should be changed for others
protected int opCode;

View file

@ -1,98 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L;
public class DanaRS_Packet_APS_Basal_Set_Temporary_Basal extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
int temporaryBasalRatio;
int temporaryBasalDuration;
public int error;
final int PARAM30MIN = 160;
final int PARAM15MIN = 150;
DanaRS_Packet_APS_Basal_Set_Temporary_Basal() {
super();
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__APS_SET_TEMPORARY_BASAL;
}
public DanaRS_Packet_APS_Basal_Set_Temporary_Basal(int percent) {
this();
setParams(percent);
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message: percent: " + percent);
}
protected void setParams(int percent) {
//HARDCODED LIMITS
if (percent < 0) percent = 0;
if (percent > 500) percent = 500;
temporaryBasalRatio = percent;
if (percent < 100) {
temporaryBasalDuration = PARAM30MIN;
if (L.isEnabled(L.PUMPCOMM))
log.debug("APS Temp basal start percent: " + percent + " duration 30 min");
} else {
temporaryBasalDuration = PARAM15MIN;
if (L.isEnabled(L.PUMPCOMM))
log.debug("APS Temp basal start percent: " + percent + " duration 15 min");
}
}
public DanaRS_Packet_APS_Basal_Set_Temporary_Basal(int percent, boolean fifteenMinutes, boolean thirtyMinutes) {
this();
setParams(percent, fifteenMinutes, thirtyMinutes);
}
protected void setParams(int percent, boolean fifteenMinutes, boolean thirtyMinutes) {
//HARDCODED LIMITS
if (percent < 0) percent = 0;
if (percent > 500) percent = 500;
temporaryBasalRatio = percent;
if (thirtyMinutes && percent <= 200) { // 30 min is allowed up to 200%
temporaryBasalDuration = PARAM30MIN;
if (L.isEnabled(L.PUMPCOMM))
log.debug("APS Temp basal start percent: " + percent + " duration 30 min");
} else {
temporaryBasalDuration = PARAM15MIN;
if (L.isEnabled(L.PUMPCOMM))
log.debug("APS Temp basal start percent: " + percent + " duration 15 min");
}
}
@Override
public byte[] getRequestParams() {
byte[] request = new byte[3];
request[0] = (byte) (temporaryBasalRatio & 0xff);
request[1] = (byte) ((temporaryBasalRatio >>> 8) & 0xff);
request[2] = (byte) (temporaryBasalDuration & 0xff);
return request;
}
@Override
public void handleMessage(byte[] data) {
int result = byteArrayToInt(getBytes(data, DATA_START, 1));
if (result != 0) {
failed = true;
if (L.isEnabled(L.PUMPCOMM))
log.debug("Set APS temp basal start result: " + result + " FAILED!!!");
} else {
failed = false;
if (L.isEnabled(L.PUMPCOMM))
log.debug("Set APS temp basal start result: " + result);
}
}
@Override
public String getFriendlyName() {
return "BASAL__APS_SET_TEMPORARY_BASAL";
}
}

View file

@ -0,0 +1,59 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import com.cozmo.danar.util.BleCommandUtil
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
class DanaRS_Packet_APS_Basal_Set_Temporary_Basal(
private val aapsLogger: AAPSLogger,
private var percent: Int
) : DanaRS_Packet() {
var temporaryBasalRatio = 0
var temporaryBasalDuration = 0
var error = 0
init {
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__APS_SET_TEMPORARY_BASAL
aapsLogger.debug(LTag.PUMPCOMM, "New message: percent: $percent")
if (percent < 0) percent = 0
if (percent > 500) percent = 500
temporaryBasalRatio = percent
if (percent < 100) {
temporaryBasalDuration = PARAM30MIN
aapsLogger.debug(LTag.PUMPCOMM, "APS Temp basal start percent: $percent duration 30 min")
} else {
temporaryBasalDuration = PARAM15MIN
aapsLogger.debug(LTag.PUMPCOMM, "APS Temp basal start percent: $percent duration 15 min")
}
}
override fun getRequestParams(): ByteArray {
val request = ByteArray(3)
request[0] = (temporaryBasalRatio and 0xff).toByte()
request[1] = (temporaryBasalRatio ushr 8 and 0xff).toByte()
request[2] = (temporaryBasalDuration and 0xff).toByte()
return request
}
override fun handleMessage(data: ByteArray) {
val result = byteArrayToInt(getBytes(data, DATA_START, 1))
if (result != 0) {
failed = true
aapsLogger.debug(LTag.PUMPCOMM, "Set APS temp basal start result: $result FAILED!!!")
} else {
failed = false
aapsLogger.debug(LTag.PUMPCOMM, "Set APS temp basal start result: $result")
}
}
override fun getFriendlyName(): String {
return "BASAL__APS_SET_TEMPORARY_BASAL"
}
companion object {
const val PARAM30MIN = 160
const val PARAM15MIN = 150
}
}

View file

@ -1,234 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Calendar;
import java.util.Date;
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.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.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil;
public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
private int year = 0;
private int month = 0;
private int day = 0;
private int hour = 0;
private int min = 0;
private int sec = 0;
public static boolean done;
public static long lastEventTimeLoaded = 0;
DanaRS_Packet_APS_History_Events() {
super();
opCode = BleCommandUtil.DANAR_PACKET__OPCODE__APS_HISTORY_EVENTS;
done = false;
}
public DanaRS_Packet_APS_History_Events(long from) {
this();
GregorianCalendar cal = new GregorianCalendar();
if (from > DateUtil.now()) {
log.debug("Asked to load from the future");
from = 0;
}
if (from != 0)
cal.setTimeInMillis(from);
else
cal.set(2000, 0, 1, 0, 0, 0);
year = cal.get(Calendar.YEAR) - 1900 - 100;
month = cal.get(Calendar.MONTH) + 1;
day = cal.get(Calendar.DAY_OF_MONTH);
hour = cal.get(Calendar.HOUR_OF_DAY);
min = cal.get(Calendar.MINUTE);
sec = cal.get(Calendar.SECOND);
if (L.isEnabled(L.PUMPCOMM))
log.debug("Loading event history from: " + new Date(cal.getTimeInMillis()).toLocaleString());
}
@Override
public byte[] getRequestParams() {
byte[] request = new byte[6];
request[0] = (byte) (year & 0xff);
request[1] = (byte) (month & 0xff);
request[2] = (byte) (day & 0xff);
request[3] = (byte) (hour & 0xff);
request[4] = (byte) (min & 0xff);
request[5] = (byte) (sec & 0xff);
return request;
}
@Override
public void handleMessage(byte[] data) {
byte recordCode = (byte) intFromBuff(data, 0, 1);
// Last record
if (recordCode == (byte) 0xFF) {
done = true;
if (L.isEnabled(L.PUMPCOMM))
log.debug("Last record received");
return;
}
long datetime = dateTimeSecFromBuff(data, 1); // 6 bytes
int param1 = ((intFromBuff(data, 7, 1) << 8) & 0xFF00) + (intFromBuff(data, 8, 1) & 0xFF);
int param2 = ((intFromBuff(data, 9, 1) << 8) & 0xFF00) + (intFromBuff(data, 10, 1) & 0xFF);
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.dateAndTimeFullString(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.dateAndTimeFullString(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.dateAndTimeFullString(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.dateAndTimeFullString(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.dateAndTimeFullString(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.dateAndTimeFullString(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.dateAndTimeFullString(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.dateAndTimeFullString(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.dateAndTimeFullString(datetime) + " (" + datetime + ")");
status = "SUSPENDON " + DateUtil.timeString(datetime);
break;
case DanaRPump.SUSPENDOFF:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT SUSPENDOFF (" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")");
status = "SUSPENDOFF " + DateUtil.timeString(datetime);
break;
case DanaRPump.REFILL:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT REFILL (" + recordCode + ") " + DateUtil.dateAndTimeFullString(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.dateAndTimeFullString(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.dateAndTimeFullString(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.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Carbs: " + param1 + "g");
status = "CARBS " + DateUtil.timeString(datetime);
break;
case DanaRPump.PRIMECANNULA:
if (L.isEnabled(L.PUMPCOMM))
log.debug("EVENT PRIMECANNULA(" + recordCode + ") " + DateUtil.dateAndTimeFullString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100d + "U");
status = "PRIMECANNULA " + DateUtil.timeString(datetime);
break;
default:
if (L.isEnabled(L.PUMPCOMM))
log.debug("Event: " + recordCode + " " + DateUtil.dateAndTimeFullString(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));
}
@Override
public String getFriendlyName() {
return "APS_HISTORY_EVENTS";
}
}

View file

@ -0,0 +1,200 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import com.cozmo.danar.util.BleCommandUtil
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.interfaces.ActivePluginProvider
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.findDetailedBolusInfo
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.resources.ResourceHelper
import java.util.*
open class DanaRS_Packet_APS_History_Events(
private val aapsLogger: AAPSLogger,
private val rxBus: RxBusWrapper,
private val resourceHelper: ResourceHelper,
private val activePlugin: ActivePluginProvider,
private val danaRSPlugin: DanaRSPlugin,
private var from: Long
) : DanaRS_Packet() {
private var year = 0
private var month = 0
private var day = 0
private var hour = 0
private var min = 0
private var sec = 0
init {
opCode = BleCommandUtil.DANAR_PACKET__OPCODE__APS_HISTORY_EVENTS
val cal = GregorianCalendar()
if (from > DateUtil.now()) {
aapsLogger.debug(LTag.PUMPCOMM, "Asked to load from the future")
from = 0
}
if (from != 0L) cal.timeInMillis = from else cal[2000, 0, 1, 0, 0] = 0
year = cal[Calendar.YEAR] - 1900 - 100
month = cal[Calendar.MONTH] + 1
day = cal[Calendar.DAY_OF_MONTH]
hour = cal[Calendar.HOUR_OF_DAY]
min = cal[Calendar.MINUTE]
sec = cal[Calendar.SECOND]
aapsLogger.debug(LTag.PUMPCOMM, "Loading event history from: " + DateUtil.dateAndTimeString(cal.timeInMillis))
danaRSPlugin.apsHistoryDone = false
}
override fun getRequestParams(): ByteArray {
val request = ByteArray(6)
request[0] = (year and 0xff).toByte()
request[1] = (month and 0xff).toByte()
request[2] = (day and 0xff).toByte()
request[3] = (hour and 0xff).toByte()
request[4] = (min and 0xff).toByte()
request[5] = (sec and 0xff).toByte()
return request
}
override fun handleMessage(data: ByteArray) {
val recordCode = intFromBuff(data, 0, 1).toByte()
// Last record
if (recordCode == 0xFF.toByte()) {
danaRSPlugin.apsHistoryDone = true
aapsLogger.debug(LTag.PUMPCOMM, "Last record received")
return
}
val datetime = dateTimeSecFromBuff(data, 1) // 6 bytes
val param1 = (intFromBuff(data, 7, 1) shl 8 and 0xFF00) + (intFromBuff(data, 8, 1) and 0xFF)
val param2 = (intFromBuff(data, 9, 1) shl 8 and 0xFF00) + (intFromBuff(data, 10, 1) and 0xFF)
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.PUMPCOMM, "EVENT TEMPSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Ratio: " + param1 + "% Duration: " + param2 + "min")
temporaryBasal.percentRate = param1
temporaryBasal.durationInMinutes = param2
activePlugin.activeTreatments.addToHistoryTempBasal(temporaryBasal)
status = "TEMPSTART " + DateUtil.timeString(datetime)
}
DanaRPump.TEMPSTOP -> {
aapsLogger.debug(LTag.PUMPCOMM, "EVENT TEMPSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime))
activePlugin.activeTreatments.addToHistoryTempBasal(temporaryBasal)
status = "TEMPSTOP " + DateUtil.timeString(datetime)
}
DanaRPump.EXTENDEDSTART -> {
aapsLogger.debug(LTag.PUMPCOMM, "EVENT EXTENDEDSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U Duration: " + param2 + "min")
extendedBolus.insulin = param1 / 100.0
extendedBolus.durationInMinutes = param2
activePlugin.activeTreatments.addToHistoryExtendedBolus(extendedBolus)
status = "EXTENDEDSTART " + DateUtil.timeString(datetime)
}
DanaRPump.EXTENDEDSTOP -> {
aapsLogger.debug(LTag.PUMPCOMM, "EVENT EXTENDEDSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + param1 / 100.0 + "U RealDuration: " + param2 + "min")
activePlugin.activeTreatments.addToHistoryExtendedBolus(extendedBolus)
status = "EXTENDEDSTOP " + DateUtil.timeString(datetime)
}
DanaRPump.BOLUS -> {
val detailedBolusInfo = findDetailedBolusInfo(datetime, param1 / 100.0)
?: DetailedBolusInfo()
detailedBolusInfo.date = datetime
detailedBolusInfo.source = Source.PUMP
detailedBolusInfo.pumpId = datetime
detailedBolusInfo.insulin = param1 / 100.0
val newRecord = activePlugin.activeTreatments.addToHistoryTreatment(detailedBolusInfo, false)
aapsLogger.debug(LTag.PUMPCOMM, (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 = findDetailedBolusInfo(datetime, param1 / 100.0)
?: DetailedBolusInfo()
detailedBolusInfo.date = datetime
detailedBolusInfo.source = Source.PUMP
detailedBolusInfo.pumpId = datetime
detailedBolusInfo.insulin = param1 / 100.0
val newRecord = activePlugin.activeTreatments.addToHistoryTreatment(detailedBolusInfo, false)
aapsLogger.debug(LTag.PUMPCOMM, (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.PUMPCOMM, "EVENT DUALEXTENDEDSTART (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U Duration: " + param2 + "min")
extendedBolus.insulin = param1 / 100.0
extendedBolus.durationInMinutes = param2
activePlugin.activeTreatments.addToHistoryExtendedBolus(extendedBolus)
status = "DUALEXTENDEDSTART " + DateUtil.timeString(datetime)
}
DanaRPump.DUALEXTENDEDSTOP -> {
aapsLogger.debug(LTag.PUMPCOMM, "EVENT DUALEXTENDEDSTOP (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Delivered: " + param1 / 100.0 + "U RealDuration: " + param2 + "min")
activePlugin.activeTreatments.addToHistoryExtendedBolus(extendedBolus)
status = "DUALEXTENDEDSTOP " + DateUtil.timeString(datetime)
}
DanaRPump.SUSPENDON -> {
aapsLogger.debug(LTag.PUMPCOMM, "EVENT SUSPENDON (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")")
status = "SUSPENDON " + DateUtil.timeString(datetime)
}
DanaRPump.SUSPENDOFF -> {
aapsLogger.debug(LTag.PUMPCOMM, "EVENT SUSPENDOFF (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")")
status = "SUSPENDOFF " + DateUtil.timeString(datetime)
}
DanaRPump.REFILL -> {
aapsLogger.debug(LTag.PUMPCOMM, "EVENT REFILL (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U")
status = "REFILL " + DateUtil.timeString(datetime)
}
DanaRPump.PRIME -> {
aapsLogger.debug(LTag.PUMPCOMM, "EVENT PRIME (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U")
status = "PRIME " + DateUtil.timeString(datetime)
}
DanaRPump.PROFILECHANGE -> {
aapsLogger.debug(LTag.PUMPCOMM, "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 = activePlugin.activeTreatments.addToHistoryTreatment(emptyCarbsInfo, false)
aapsLogger.debug(LTag.PUMPCOMM, (if (newRecord) "**NEW** " else "") + "EVENT CARBS (" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Carbs: " + param1 + "g")
status = "CARBS " + DateUtil.timeString(datetime)
}
DanaRPump.PRIMECANNULA -> {
aapsLogger.debug(LTag.PUMPCOMM, "EVENT PRIMECANNULA(" + recordCode + ") " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Amount: " + param1 / 100.0 + "U")
status = "PRIMECANNULA " + DateUtil.timeString(datetime)
}
else -> {
aapsLogger.debug(LTag.PUMPCOMM, "Event: " + recordCode + " " + DateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Param1: " + param1 + " Param2: " + param2)
status = "UNKNOWN " + DateUtil.timeString(datetime)
}
}
if (datetime > danaRSPlugin.lastEventTimeLoaded) danaRSPlugin.lastEventTimeLoaded = datetime
rxBus.send(EventPumpStatusChanged(resourceHelper.gs(R.string.processinghistory) + ": " + status))
}
override fun getFriendlyName(): String {
return "APS_HISTORY_EVENTS"
}
}

View file

@ -1,84 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Calendar;
import java.util.GregorianCalendar;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.utils.DateUtil;
public class DanaRS_Packet_APS_Set_Event_History extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
private int type;
private long time;
private int param1;
private int param2;
public DanaRS_Packet_APS_Set_Event_History() {
super();
opCode = BleCommandUtil.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY;
}
public DanaRS_Packet_APS_Set_Event_History(int type, long time, int param1, int param2) {
this();
this.type = type;
this.time = time;
this.param1 = param1;
this.param2 = param2;
if ((type == DanaRPump.CARBS || type == DanaRPump.BOLUS) && param1 <= 0)
this.param1 = 0;
if (L.isEnabled(L.PUMPCOMM))
log.debug("Set history entry: " + DateUtil.dateAndTimeString(time) + " type: " + type + " param1: " + param1 + " param2: " + param2);
}
@Override
public byte[] getRequestParams() {
GregorianCalendar cal = new GregorianCalendar();
cal.setTimeInMillis(time);
int year = cal.get(Calendar.YEAR) - 1900 - 100;
int month = cal.get(Calendar.MONTH) + 1;
int day = cal.get(Calendar.DAY_OF_MONTH);
int hour = cal.get(Calendar.HOUR_OF_DAY);
int min = cal.get(Calendar.MINUTE);
int sec = cal.get(Calendar.SECOND);
byte[] request = new byte[11];
request[0] = (byte) (type & 0xff);
request[1] = (byte) (year & 0xff);
request[2] = (byte) (month & 0xff);
request[3] = (byte) (day & 0xff);
request[4] = (byte) (hour & 0xff);
request[5] = (byte) (min & 0xff);
request[6] = (byte) (sec & 0xff);
request[7] = (byte) ((param1 >>> 8) & 0xff);
request[8] = (byte) (param1 & 0xff);
request[9] = (byte) ((param2 >>> 8) & 0xff);
request[10] = (byte) (param2 & 0xff);
return request;
}
@Override
public void handleMessage(byte[] data) {
int result = intFromBuff(data, 0, 1);
if (result != 0) {
failed = true;
if (L.isEnabled(L.PUMPCOMM))
log.error("Set history entry result: " + result + " FAILED!!!");
} else {
if (L.isEnabled(L.PUMPCOMM))
log.debug("Set history entry result: " + result);
}
}
@Override
public String getFriendlyName() {
return "APS_SET_EVENT_HISTORY";
}
}

View file

@ -0,0 +1,62 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import com.cozmo.danar.util.BleCommandUtil
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.utils.DateUtil
import java.util.*
class DanaRS_Packet_APS_Set_Event_History(
private val aapsLogger: AAPSLogger,
private var packetType: Int,
private var time: Long,
private var param1: Int,
private var param2: Int
) : DanaRS_Packet() {
init {
opCode = BleCommandUtil.DANAR_PACKET__OPCODE__APS_SET_EVENT_HISTORY
if ((packetType == DanaRPump.CARBS || packetType == DanaRPump.BOLUS) && param1 <= 0) this.param1 = 0
aapsLogger.debug(LTag.PUMPCOMM, "Set history entry: " + DateUtil.dateAndTimeString(time) + " type: " + packetType + " param1: " + param1 + " param2: " + param2)
}
override fun getRequestParams(): ByteArray {
val cal = GregorianCalendar()
cal.timeInMillis = time
val year = cal[Calendar.YEAR] - 1900 - 100
val month = cal[Calendar.MONTH] + 1
val day = cal[Calendar.DAY_OF_MONTH]
val hour = cal[Calendar.HOUR_OF_DAY]
val min = cal[Calendar.MINUTE]
val sec = cal[Calendar.SECOND]
val request = ByteArray(11)
request[0] = (packetType and 0xff).toByte()
request[1] = (year and 0xff).toByte()
request[2] = (month and 0xff).toByte()
request[3] = (day and 0xff).toByte()
request[4] = (hour and 0xff).toByte()
request[5] = (min and 0xff).toByte()
request[6] = (sec and 0xff).toByte()
request[7] = (param1 ushr 8 and 0xff).toByte()
request[8] = (param1 and 0xff).toByte()
request[9] = (param2 ushr 8 and 0xff).toByte()
request[10] = (param2 and 0xff).toByte()
return request
}
override fun handleMessage(data: ByteArray) {
val result = intFromBuff(data, 0, 1)
if (result != 0) {
failed = true
aapsLogger.error(LTag.PUMPCOMM, "Set history entry result: $result FAILED!!!")
} else {
failed = false
aapsLogger.debug(LTag.PUMPCOMM, "Set history entry result: $result")
}
}
override fun getFriendlyName(): String {
return "APS_SET_EVENT_HISTORY"
}
}

View file

@ -1,72 +0,0 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import com.cozmo.danar.util.BleCommandUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Locale;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
public class DanaRS_Packet_Basal_Get_Basal_Rate extends DanaRS_Packet {
private Logger log = LoggerFactory.getLogger(L.PUMPCOMM);
public DanaRS_Packet_Basal_Get_Basal_Rate() {
super();
opCode = BleCommandUtil.DANAR_PACKET__OPCODE_BASAL__GET_BASAL_RATE;
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Requesting basal rates");
}
}
@Override
public void handleMessage(byte[] data) {
DanaRPump pump = DanaRPump.getInstance();
int dataIndex = DATA_START;
int dataSize = 2;
pump.maxBasal = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d;
dataIndex += dataSize;
dataSize = 1;
pump.basalStep = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d;
if (pump.pumpProfiles == null) pump.pumpProfiles = new double[4][];
pump.pumpProfiles[pump.activeProfile] = new double[24];
for (int i = 0, size = 24; i < size; i++) {
dataIndex += dataSize;
dataSize = 2;
pump.pumpProfiles[pump.activeProfile][i] = byteArrayToInt(getBytes(data, dataIndex, dataSize)) / 100d;
}
if (L.isEnabled(L.PUMPCOMM)) {
log.debug("Max basal: " + pump.maxBasal + " U");
log.debug("Basal step: " + pump.basalStep + " U");
for (int index = 0; index < 24; index++)
log.debug("Basal " + String.format(Locale.ENGLISH, "%02d", index) + "h: " + pump.pumpProfiles[pump.activeProfile][index]);
}
if (pump.basalStep != 0.01d) {
failed = true;
Notification notification = new Notification(Notification.WRONGBASALSTEP, MainApp.gs(R.string.danar_setbasalstep001), Notification.URGENT);
RxBus.Companion.getINSTANCE().send(new EventNewNotification(notification));
} else {
RxBus.Companion.getINSTANCE().send(new EventDismissNotification(Notification.WRONGBASALSTEP));
}
}
@Override
public String getFriendlyName() {
return "BASAL__GET_BASAL_RATE";
}
}

Some files were not shown because too many files have changed in this diff Show more