move pass 1

This commit is contained in:
Milos Kozak 2020-05-08 14:59:30 +02:00
parent 61a077542c
commit 040c76d839
175 changed files with 349 additions and 287 deletions

View file

@ -41,7 +41,6 @@ import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin
import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin

View file

@ -4,6 +4,7 @@ import dagger.Module
import dagger.android.ContributesAndroidInjector
import info.nightscout.androidaps.MainActivity
import info.nightscout.androidaps.activities.*
import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.historyBrowser.HistoryBrowseActivity
import info.nightscout.androidaps.plugins.general.maintenance.activities.LogSettingActivity
import info.nightscout.androidaps.plugins.general.maintenance.activities.PrefImportListActivity

View file

@ -41,7 +41,6 @@ import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin
import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin
import info.nightscout.androidaps.plugins.pump.mdi.MDIPlugin
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin
import info.nightscout.androidaps.plugins.pump.omnipod.OmnipodPumpPlugin
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin

View file

@ -41,9 +41,11 @@ import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
import info.nightscout.androidaps.interfaces.CommandQueueProvider;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.LoopInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.ProfileFunction;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.AAPSLogger;
@ -53,7 +55,6 @@ import info.nightscout.androidaps.plugins.aps.loop.events.EventLoopUpdateGui;
import info.nightscout.androidaps.plugins.aps.loop.events.EventNewOpenLoopNotification;
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
import info.nightscout.androidaps.interfaces.ProfileFunction;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.wear.ActionStringHandler;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
@ -65,15 +66,15 @@ import info.nightscout.androidaps.queue.commands.Command;
import info.nightscout.androidaps.receivers.ReceiverStatusStore;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.HardLimits;
import info.nightscout.androidaps.utils.T;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
import info.nightscout.androidaps.utils.HardLimits;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
@Singleton
public class LoopPlugin extends PluginBase {
public class LoopPlugin extends PluginBase implements LoopInterface {
private final HasAndroidInjector injector;
private final SP sp;
private final RxBusWrapper rxBus;
@ -89,6 +90,7 @@ public class LoopPlugin extends PluginBase {
private final IobCobCalculatorPlugin iobCobCalculatorPlugin;
private final ReceiverStatusStore receiverStatusStore;
private final FabricPrivacy fabricPrivacy;
private final NSUpload nsUpload;
private final HardLimits hardLimits;
private CompositeDisposable disposable = new CompositeDisposable();
@ -101,21 +103,15 @@ public class LoopPlugin extends PluginBase {
private boolean isSuperBolus;
private boolean isDisconnected;
public class LastRun {
public APSResult request = null;
public APSResult constraintsProcessed = null;
public PumpEnactResult tbrSetByPump = null;
public PumpEnactResult smbSetByPump = null;
public String source = null;
public long lastAPSRun = DateUtil.now();
public long lastTBREnact = 0;
public long lastSMBEnact = 0;
public long lastTBRRequest = 0;
public long lastSMBRequest = 0;
public long lastOpenModeAccept;
@Nullable public LastRun lastRun = null;
@Nullable @Override public LastRun getLastRun() {
return lastRun;
}
@Nullable public LastRun lastRun = null;
@Override public void setLastRun(@Nullable LastRun lastRun) {
this.lastRun = lastRun;
}
@Inject
public LoopPlugin(
@ -135,6 +131,7 @@ public class LoopPlugin extends PluginBase {
IobCobCalculatorPlugin iobCobCalculatorPlugin,
ReceiverStatusStore receiverStatusStore,
FabricPrivacy fabricPrivacy,
NSUpload nsUpload,
HardLimits hardLimits
) {
super(new PluginDescription()
@ -161,6 +158,7 @@ public class LoopPlugin extends PluginBase {
this.iobCobCalculatorPlugin = iobCobCalculatorPlugin;
this.receiverStatusStore = receiverStatusStore;
this.fabricPrivacy = fabricPrivacy;
this.nsUpload = nsUpload;
this.hardLimits = hardLimits;
loopSuspendedTill = sp.getLong("loopSuspendedTill", 0L);
@ -292,7 +290,7 @@ public class LoopPlugin extends PluginBase {
return true;
}
public boolean isLGS(){
public boolean isLGS() {
Constraint<Boolean> closedLoopEnabled = constraintChecker.isClosedLoopAllowed();
Double MaxIOBallowed = constraintChecker.getMaxIOBAllowed().value();
String APSmode = sp.getString(R.string.key_aps_mode, "open");
@ -403,18 +401,18 @@ public class LoopPlugin extends PluginBase {
}
if (lastRun == null) lastRun = new LastRun();
lastRun.request = result;
lastRun.constraintsProcessed = resultAfterConstraints;
lastRun.lastAPSRun = DateUtil.now();
lastRun.source = ((PluginBase) usedAPS).getName();
lastRun.tbrSetByPump = null;
lastRun.smbSetByPump = null;
lastRun.lastTBREnact = 0;
lastRun.lastTBRRequest = 0;
lastRun.lastSMBEnact = 0;
lastRun.lastSMBRequest = 0;
lastRun.setRequest(result);
lastRun.setConstraintsProcessed(resultAfterConstraints);
lastRun.setLastAPSRun(DateUtil.now());
lastRun.setSource(((PluginBase) usedAPS).getName());
lastRun.setTbrSetByPump(null);
lastRun.setSmbSetByPump(null);
lastRun.setLastTBREnact(0);
lastRun.setLastTBRRequest(0);
lastRun.setLastSMBEnact(0);
lastRun.setLastSMBRequest(0);
NSUpload.uploadDeviceStatus(this, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump(), receiverStatusStore);
nsUpload.uploadDeviceStatus(this, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump(), receiverStatusStore);
if (isSuspended()) {
getAapsLogger().debug(LTag.APS, resourceHelper.gs(R.string.loopsuspended));
@ -437,27 +435,27 @@ public class LoopPlugin extends PluginBase {
final PumpEnactResult waiting = new PumpEnactResult(getInjector());
waiting.queued = true;
if (resultAfterConstraints.tempBasalRequested)
lastRun.tbrSetByPump = waiting;
lastRun.setTbrSetByPump(waiting);
if (resultAfterConstraints.bolusRequested)
lastRun.smbSetByPump = waiting;
lastRun.setSmbSetByPump(waiting);
rxBus.send(new EventLoopUpdateGui());
fabricPrivacy.logCustom("APSRequest");
applyTBRRequest(resultAfterConstraints, profile, new Callback() {
@Override
public void run() {
if (result.enacted || result.success) {
lastRun.tbrSetByPump = result;
lastRun.lastTBRRequest = lastRun.lastAPSRun;
lastRun.lastTBREnact = DateUtil.now();
lastRun.setTbrSetByPump(result);
lastRun.setLastTBRRequest(lastRun.getLastAPSRun());
lastRun.setLastTBREnact(DateUtil.now());
rxBus.send(new EventLoopUpdateGui());
applySMBRequest(resultAfterConstraints, new Callback() {
@Override
public void run() {
//Callback is only called if a bolus was acutally requested
if (result.enacted || result.success) {
lastRun.smbSetByPump = result;
lastRun.lastSMBRequest = lastRun.lastAPSRun;
lastRun.lastSMBEnact = DateUtil.now();
lastRun.setTbrSetByPump(result);
lastRun.setLastTBRRequest(lastRun.getLastAPSRun());
lastRun.setLastTBREnact(DateUtil.now());
} else {
new Thread(() -> {
SystemClock.sleep(1000);
@ -472,8 +470,8 @@ public class LoopPlugin extends PluginBase {
}
});
} else {
lastRun.tbrSetByPump = null;
lastRun.smbSetByPump = null;
lastRun.setTbrSetByPump(null);
lastRun.setSmbSetByPump(null);
}
} else {
if (resultAfterConstraints.isChangeRequested() && allowNotification) {
@ -531,15 +529,15 @@ public class LoopPlugin extends PluginBase {
public void acceptChangeRequest() {
Profile profile = profileFunction.getProfile();
final LoopPlugin lp = this;
applyTBRRequest(lastRun.constraintsProcessed, profile, new Callback() {
applyTBRRequest(lastRun.getConstraintsProcessed(), profile, new Callback() {
@Override
public void run() {
if (result.enacted) {
lastRun.tbrSetByPump = result;
lastRun.lastTBRRequest = lastRun.lastAPSRun;
lastRun.lastTBREnact = DateUtil.now();
lastRun.lastOpenModeAccept = DateUtil.now();
NSUpload.uploadDeviceStatus(lp, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump(), receiverStatusStore);
lastRun.setTbrSetByPump(result);
lastRun.setLastTBRRequest(lastRun.getLastAPSRun());
lastRun.setLastTBREnact(DateUtil.now());
lastRun.setLastOpenModeAccept(DateUtil.now());
nsUpload.uploadDeviceStatus(lp, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump(), receiverStatusStore);
sp.incInt(R.string.key_ObjectivesmanualEnacts);
}
rxBus.send(new EventAcceptOpenLoopChange());
@ -773,6 +771,7 @@ public class LoopPlugin extends PluginBase {
event.eventType = CareportalEvent.OPENAPSOFFLINE;
event.json = data.toString();
MainApp.getDbHelper().createOrUpdate(event);
NSUpload.uploadOpenAPSOffline(event);
nsUpload.uploadOpenAPSOffline(event);
}
}

View file

@ -20,7 +20,6 @@ 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.maintenance.formats.*
import info.nightscout.androidaps.plugins.general.smsCommunicator.otp.OneTimePassword
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.ToastUtils
import info.nightscout.androidaps.utils.alertDialogs.OKDialog

View file

@ -16,6 +16,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.db.DbRequest;
import info.nightscout.androidaps.interfaces.UploadQueueInterface;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
@ -27,7 +28,7 @@ import info.nightscout.androidaps.utils.SP;
/**
* Created by mike on 21.02.2016.
*/
public class UploadQueue {
public class UploadQueue implements UploadQueueInterface {
private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.NSCLIENT);
public static String status() {

View file

@ -14,7 +14,6 @@ import info.nightscout.androidaps.Constants
import info.nightscout.androidaps.MainActivity
import info.nightscout.androidaps.R
import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.db.DatabaseHelper
import info.nightscout.androidaps.events.*
import info.nightscout.androidaps.interfaces.*
import info.nightscout.androidaps.logging.AAPSLogger

View file

@ -485,7 +485,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
getAapsLogger().error("deliverTreatment: Invalid input");
return new PumpEnactResult(getInjector()).success(false).enacted(false)
.bolusDelivered(0d).carbsDelivered(0d)
.comment(getResourceHelper().gs(R.string.danar_invalidinput));
.comment(getResourceHelper().gs(R.string.invalidinput));
} else if (detailedBolusInfo.insulin > 0) {
// bolus needed, ask pump to deliver it
return deliverBolus(detailedBolusInfo);

View file

@ -413,7 +413,7 @@ public abstract class PumpPluginAbstract extends PumpPluginBase implements PumpI
// neither carbs nor bolus requested
aapsLogger.error("deliverTreatment: Invalid input");
return new PumpEnactResult(getInjector()).success(false).enacted(false).bolusDelivered(0d).carbsDelivered(0d)
.comment(getResourceHelper().gs(R.string.danar_invalidinput));
.comment(getResourceHelper().gs(R.string.invalidinput));
} else if (detailedBolusInfo.insulin > 0) {
// bolus needed, ask pump to deliver it
return deliverBolus(detailedBolusInfo);

View file

@ -224,7 +224,7 @@ public abstract class AbstractDanaRPlugin extends PumpPluginBase implements Pump
result.isTempCancel = false;
result.enacted = false;
result.success = false;
result.comment = getResourceHelper().gs(R.string.danar_invalidinput);
result.comment = getResourceHelper().gs(R.string.invalidinput);
getAapsLogger().error("setTempBasalPercent: Invalid input");
return result;
}

View file

@ -180,7 +180,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
result.success = false;
result.bolusDelivered = 0d;
result.carbsDelivered = 0d;
result.comment = resourceHelper.gs(R.string.danar_invalidinput);
result.comment = resourceHelper.gs(R.string.invalidinput);
aapsLogger.error("deliverTreatment: Invalid input");
return result;
}

View file

@ -151,7 +151,7 @@ class DanaRHistoryActivity : NoSplashAppCompatActivity() {
holder.duration.text = DecimalFormatter.to0Decimal(record.recordDuration.toDouble())
holder.alarm.text = record.recordAlarm
when (showingType) {
RecordTypes.RECORD_TYPE_ALARM -> {
RecordTypes.RECORD_TYPE_ALARM -> {
holder.time.visibility = View.VISIBLE
holder.value.visibility = View.VISIBLE
holder.stringValue.visibility = View.GONE
@ -163,7 +163,7 @@ class DanaRHistoryActivity : NoSplashAppCompatActivity() {
holder.alarm.visibility = View.VISIBLE
}
RecordTypes.RECORD_TYPE_BOLUS -> {
RecordTypes.RECORD_TYPE_BOLUS -> {
holder.time.visibility = View.VISIBLE
holder.value.visibility = View.VISIBLE
holder.stringValue.visibility = View.GONE
@ -175,7 +175,7 @@ class DanaRHistoryActivity : NoSplashAppCompatActivity() {
holder.alarm.visibility = View.GONE
}
RecordTypes.RECORD_TYPE_DAILY -> {
RecordTypes.RECORD_TYPE_DAILY -> {
holder.dailyBasal.text = resourceHelper.gs(R.string.formatinsulinunits, record.recordDailyBasal)
holder.dailyBolus.text = resourceHelper.gs(R.string.formatinsulinunits, record.recordDailyBolus)
holder.dailyTotal.text = resourceHelper.gs(R.string.formatinsulinunits, record.recordDailyBolus + record.recordDailyBasal)
@ -191,7 +191,7 @@ class DanaRHistoryActivity : NoSplashAppCompatActivity() {
holder.alarm.visibility = View.GONE
}
RecordTypes.RECORD_TYPE_GLUCOSE -> {
RecordTypes.RECORD_TYPE_GLUCOSE -> {
holder.value.text = Profile.toUnitsString(record.recordValue, record.recordValue * Constants.MGDL_TO_MMOLL, profileFunction.getUnits())
holder.time.visibility = View.VISIBLE
holder.value.visibility = View.VISIBLE
@ -216,7 +216,7 @@ class DanaRHistoryActivity : NoSplashAppCompatActivity() {
holder.alarm.visibility = View.GONE
}
RecordTypes.RECORD_TYPE_SUSPEND -> {
RecordTypes.RECORD_TYPE_SUSPEND -> {
holder.time.visibility = View.VISIBLE
holder.value.visibility = View.GONE
holder.stringValue.visibility = View.VISIBLE

View file

@ -136,7 +136,7 @@ open class MsgHistoryAll(
danaRHistoryRecord.stringRecordValue = strRecordValue
}
17.toByte() -> failed = true
17.toByte() -> failed = true
}
MainApp.getDbHelper().createOrUpdate(danaRHistoryRecord)
rxBus.send(EventDanaRSyncStatus(dateUtil.dateAndTimeString(danaRHistoryRecord.recordDate) + " " + messageType))

View file

@ -182,7 +182,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
result.success = false;
result.bolusDelivered = 0d;
result.carbsDelivered = 0d;
result.comment = resourceHelper.gs(R.string.danar_invalidinput);
result.comment = resourceHelper.gs(R.string.invalidinput);
aapsLogger.error("deliverTreatment: Invalid input");
return result;
}

View file

@ -200,7 +200,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
result.success = false;
result.bolusDelivered = 0d;
result.carbsDelivered = 0d;
result.comment = resourceHelper.gs(R.string.danar_invalidinput);
result.comment = resourceHelper.gs(R.string.invalidinput);
aapsLogger.error("deliverTreatment: Invalid input");
return result;
}
@ -301,7 +301,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
result.isTempCancel = false;
result.enacted = false;
result.success = false;
result.comment = resourceHelper.gs(R.string.danar_invalidinput);
result.comment = resourceHelper.gs(R.string.invalidinput);
aapsLogger.error("setTempBasalPercent: Invalid input");
return result;
}

View file

@ -201,7 +201,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
if (pref.getKey().equals(getResourceHelper().gs(R.string.key_rileylink_mac_address))) {
String value = sp.getStringOrNull(R.string.key_rileylink_mac_address, null);
pref.setSummary(value == null ? getResourceHelper().gs(R.string.rileylink_error_address_not_set_short) : value);
pref.setSummary(value == null ? getResourceHelper().gs(R.string.not_set_short) : value);
}
}

View file

@ -24,7 +24,6 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import dagger.android.HasAndroidInjector;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.activities.ErrorHelperActivity;
import info.nightscout.androidaps.data.DetailedBolusInfo;

View file

@ -75,6 +75,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
private final ResourceHelper resourceHelper;
private final ProfileFunction profileFunction;
private final ActivePluginProvider activePlugin;
private final NSUpload nsUpload;
private final FabricPrivacy fabricPrivacy;
private final DateUtil dateUtil;
@ -101,6 +102,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
SP sp,
ProfileFunction profileFunction,
ActivePluginProvider activePlugin,
NSUpload nsUpload,
FabricPrivacy fabricPrivacy,
DateUtil dateUtil
) {
@ -122,6 +124,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
this.activePlugin = activePlugin;
this.fabricPrivacy = fabricPrivacy;
this.dateUtil = dateUtil;
this.nsUpload = nsUpload;
}
@Override
@ -553,13 +556,13 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
if (newRecordCreated) {
if (extendedBolus.durationInMinutes == 0) {
if (activePlugin.getActivePump().isFakingTempsByExtendedBoluses())
NSUpload.uploadTempBasalEnd(extendedBolus.date, true, extendedBolus.pumpId);
nsUpload.uploadTempBasalEnd(extendedBolus.date, true, extendedBolus.pumpId);
else
NSUpload.uploadExtendedBolusEnd(extendedBolus.date, extendedBolus.pumpId);
nsUpload.uploadExtendedBolusEnd(extendedBolus.date, extendedBolus.pumpId);
} else if (activePlugin.getActivePump().isFakingTempsByExtendedBoluses())
NSUpload.uploadTempBasalStartAbsolute(new TemporaryBasal(extendedBolus), extendedBolus.insulin);
nsUpload.uploadTempBasalStartAbsolute(new TemporaryBasal(extendedBolus), extendedBolus.insulin);
else
NSUpload.uploadExtendedBolus(extendedBolus);
nsUpload.uploadExtendedBolus(extendedBolus);
}
return newRecordCreated;
}
@ -586,11 +589,11 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
boolean newRecordCreated = MainApp.getDbHelper().createOrUpdate(tempBasal);
if (newRecordCreated) {
if (tempBasal.durationInMinutes == 0)
NSUpload.uploadTempBasalEnd(tempBasal.date, false, tempBasal.pumpId);
nsUpload.uploadTempBasalEnd(tempBasal.date, false, tempBasal.pumpId);
else if (tempBasal.isAbsolute)
NSUpload.uploadTempBasalStartAbsolute(tempBasal, null);
nsUpload.uploadTempBasalStartAbsolute(tempBasal, null);
else
NSUpload.uploadTempBasalStartPercent(tempBasal, profileFunction.getProfile(tempBasal.date));
nsUpload.uploadTempBasalStartPercent(tempBasal, profileFunction.getProfile(tempBasal.date));
}
return newRecordCreated;
}
@ -641,7 +644,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
//log.debug("Adding new Treatment record" + carbsTreatment);
}
if (newRecordCreated && detailedBolusInfo.isValid)
NSUpload.uploadTreatmentRecord(detailedBolusInfo);
nsUpload.uploadTreatmentRecord(detailedBolusInfo);
if (!allowUpdate && !creatOrUpdateResult.success) {
getAapsLogger().error("Treatment could not be added to DB", new Exception());
@ -710,7 +713,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
public void addToHistoryTempTarget(TempTarget tempTarget) {
//log.debug("Adding new TemporaryBasal record" + profileSwitch.log());
MainApp.getDbHelper().createOrUpdate(tempTarget);
NSUpload.uploadTempTarget(tempTarget, profileFunction);
nsUpload.uploadTempTarget(tempTarget, profileFunction);
}
@Override
@ -733,7 +736,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
//log.debug("Adding new TemporaryBasal record" + profileSwitch.log());
rxBus.send(new EventDismissNotification(Notification.PROFILE_SWITCH_MISSING));
MainApp.getDbHelper().createOrUpdate(profileSwitch);
NSUpload.uploadProfileSwitch(profileSwitch);
nsUpload.uploadProfileSwitch(profileSwitch);
}
@Override

View file

@ -10,6 +10,7 @@ import androidx.core.app.TaskStackBuilder
import info.nightscout.androidaps.MainActivity
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.interfaces.NotificationHolderInterface
import info.nightscout.androidaps.utils.resources.IconsProvider
import info.nightscout.androidaps.utils.resources.ResourceHelper
import javax.inject.Inject
@ -20,11 +21,11 @@ class NotificationHolder @Inject constructor(
private val resourceHelper: ResourceHelper,
private val context: Context,
private val iconsProvider: IconsProvider
) {
) : NotificationHolderInterface {
val channelID = "AndroidAPS-Ongoing"
val notificationID = 4711
var notification: Notification
override val channelID = "AndroidAPS-Ongoing"
override val notificationID = 4711
override lateinit var notification: Notification
init {
val stackBuilder = TaskStackBuilder.create(context)

View file

@ -1 +0,0 @@
# danars-support-lib

View file

@ -62,7 +62,6 @@
<string name="description_pump_dana_r">Pump integration for DANA Diabecare R pumps</string>
<string name="description_pump_dana_r_korean">Pump integration for domestic DANA Diabecare R pumps</string>
<string name="description_pump_dana_r_v2">Pump integration for DANA Diabecare R pumps with upgraded firmware</string>
<string name="description_pump_dana_rs">Pump integration for DANA Diabecare RS pumps</string>
<string name="description_pump_mdi">Pump integration for people who do multiple daily injections for their diabetes therapy</string>
<string name="description_pump_virtual">Pump integration for pumps which don\'t have any driver yet (Open Loop)</string>
<string name="description_sensitivity_aaps">Sensitivity is calculated the same way like Oref0, but you can specify timeframe to the past. Minimal carb absorption is calculated from max carb absorption time from preferences.</string>
@ -161,7 +160,6 @@
<string name="openapsma_disabled">Plugin is disabled</string>
<string name="constraints_violation">Constraints violation</string>
<string name="treatmentdeliveryerror">Bolus delivery error</string>
<string name="tempbasaldeliveryerror">Tempbasal delivery error</string>
<string name="overview_newtempbasal_basalpercent">Basal value [%]</string>
<string name="setbasalquestion">Accept new temp basal:</string>
<string name="overview_treatment_label">Treatment</string>
@ -283,9 +281,6 @@
<string name="in_directory" comment="placeholder is for exported file path">in directory: %1$s</string>
<string name="danarpump">DanaR</string>
<string name="connecting">Connecting</string>
<string name="connected">Connected</string>
<string name="disconnected">Disconnected</string>
<string name="danar_pump_settings">Dana pump settings</string>
<string name="end_user_license_agreement">End User License Agreement</string>
<string name="end_user_license_agreement_text">MUST NOT BE USED TO MAKE MEDICAL DECISIONS. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.</string>
@ -297,8 +292,6 @@
<string name="danar_iob_label">Pump IOB</string>
<string name="danar_dailyunits">Daily units</string>
<string name="pump_lastbolus_label">Last bolus</string>
<string name="danar_invalidinput">Invalid input data</string>
<string name="danar_valuenotsetproperly">Value not set properly</string>
<string name="reloadprofile">Reload profile</string>
<string name="danar_viewprofile">View profile</string>
<string name="smscommunicator">SMS Communicator</string>
@ -328,7 +321,6 @@
<string name="danarprofile">DanaR profile settings</string>
<string name="danarprofile_dia">DIA [h]</string>
<string name="danarprofile_dia_summary">Duration of Insulin Activity</string>
<string name="failedupdatebasalprofile">Failed to update basal profile</string>
<string name="danar_historyreload">Reload</string>
<string name="uploading">Uploading</string>
<string name="danar_ebolus">E bolus</string>
@ -351,7 +343,6 @@
<string name="danar_history_glucose">Glucose</string>
<string name="danar_history_refill">Refill</string>
<string name="danar_history_syspend">Suspend</string>
<string name="danar_history_connectingfor">Connecting for %1$d s</string>
<string name="danars_password_title">Pump password (v1 only)</string>
<string name="danar_password_title">Pump password</string>
<string name="wrongpumppassword">Wrong pump password!</string>
@ -363,8 +354,6 @@
<string name="occlusion">Occlusion</string>
<string name="overview_bolusprogress_stop">Stop</string>
<string name="overview_bolusprogress_stoppressed">STOP PRESSED</string>
<string name="waitingforpump">Waiting for pump</string>
<string name="overview_bolusprogress_goingtodeliver">Going to deliver %1$.2fU</string>
<string name="youareonallowedlimit">You reached allowed limit</string>
<string name="smscommunicator_loophasbeendisabled">Loop has been disabled</string>
<string name="smscommunicator_loophasbeenenabled">Loop has been enabled</string>
@ -406,11 +395,9 @@
<string name="mealbolus">Meal</string>
<string name="correctionbous">Corr</string>
<string name="actions">Actions</string>
<string name="androidaps_start">AndroidAPS started</string>
<string name="ns_upload_only">NS upload only (disabled sync)</string>
<string name="ns_upload_only_summary">NS upload only. Not effective on SGV unless a local source like xDrip is selected. Not effective on Profiles while NS-Profiles is used.</string>
<string name="pumpNotInitialized">Pump not initialized!</string>
<string name="pumpNotInitializedProfileNotSet">Pump not initialized, profile not set!</string>
<string name="primefill">Prime/Fill</string>
<string name="fillwarning">Please make sure the amount matches the specification of your infusion set!</string>
<string name="othersettings_title">Other</string>
@ -439,7 +426,6 @@
<string name="danarkoreanpump">DanaR Korean</string>
<string name="basal_rate">Basal rate:</string>
<string name="profile_set_failed">Setting of basal profile failed</string>
<string name="profile_set_ok">Basal profile in pump updated</string>
<string name="danar_disableeasymode">Disable EasyUI mode in pump</string>
<string name="danar_enableextendedbolus">Enable extended boluses on pump</string>
<string name="danar_switchtouhmode">Change mode from U/d to U/h on pump</string>
@ -531,7 +517,6 @@
<string name="settingextendedbolus">Setting extended bolus</string>
<string name="stoppingextendedbolus">Stopping extended bolus</string>
<string name="updatingbasalrates">Updating basal rates</string>
<string name="disconnecting">Disconnecting</string>
<string name="executing">Executing</string>
<string name="virtualpump_settings">Virtual pump settings</string>
<string name="virtualpump_uploadstatus_title">Upload status to NS</string>
@ -609,7 +594,6 @@
<string name="treatments_wizard_cob_label">COB</string>
<string name="superbolus">Superbolus</string>
<string name="ns_logappstartedevent">Log app start to NS</string>
<string name="key_ns_logappstartedevent" translatable="false">ns_logappstartedevent</string>
<string name="restartingapp">Exiting application to apply settings.</string>
<string name="danarv2pump">DanaRv2</string>
<string name="configbuilder_insulin_description">Which type of insulin are you using?</string>
@ -751,20 +735,12 @@
<string name="date">Date</string>
<string name="invalid">INVALID</string>
<string name="pairing">Pairing</string>
<string name="key_danars_pairingkey" translatable="false">danars_pairing_key_</string>
<string name="key_danars_v3_randompairingkey" translatable="false">danars_v3_randompairing_key_</string>
<string name="key_danars_v3_pairingkey" translatable="false">danars_v3_pairing_key_</string>
<string name="key_danars_v3_randomsynckey" translatable="false">danars_v3_randomsync_key_</string>
<string name="emptyreservoir">Empty reservoir</string>
<string name="bloodsugarmeasurementalert">Blood sugar measurement alert</string>
<string name="remaininsulinalert">Remaining insulin level</string>
<string name="missedbolus">Missed bolus</string>
<string name="danarspump">DanaRS</string>
<string name="danarspump_shortname">Dana</string>
<string name="selectedpump">Selected pump</string>
<string name="bolusspeed">Bolus speed</string>
<string name="key_danars_bolusspeed" translatable="false">danars_bolusspeed</string>
<string name="danar_setbasalstep001">Set basal step to 0.01 U/h</string>
<string name="serialnumber">Serial number</string>
<string name="key_wizard_include_cob" translatable="false">wizard_include_cob</string>
<string name="key_wizard_include_trend_bg" translatable="false">wizard_include_trend_bg</string>
@ -938,7 +914,6 @@
<string name="nav_historybrowser">History browser</string>
<string name="wear_notifysmb_title">Notify on SMB</string>
<string name="wear_notifysmb_summary">Show SMB on the watch like a standard bolus.</string>
<string name="key_ns_create_announcements_from_errors" translatable="false">ns_create_announcements_from_errors</string>
<string name="ns_create_announcements_from_errors_title">Create announcements from errors</string>
<string name="ns_create_announcements_from_errors_summary">Create Nightscout announcement for error dialogs and local alerts (also viewable in Careportal under Treatments)</string>
<string name="eversense_shortname" translatable="false">EVR</string>
@ -994,20 +969,15 @@
<string name="smbdisabledinpreferences">SMB disabled in preferences</string>
<string name="uamdisabledinpreferences">UAM disabled in preferences</string>
<string name="uamdisabledoref1notselected">UAM disabled because it rely on Oref1 sensitivity plugin</string>
<string name="limitingbasalratio">Limiting max basal rate to %1$.2f U/h because of %2$s</string>
<string name="pumplimit">pump limit</string>
<string name="key_openapsma_max_basal" translatable="false">openapsma_max_basal</string>
<string name="key_openapsama_current_basal_safety_multiplier" translatable="false">openapsama_current_basal_safety_multiplier</string>
<string name="key_openapsama_max_daily_safety_multiplier" translatable="false">openapsama_max_daily_safety_multiplier</string>
<string name="itmustbepositivevalue">it must be positive value</string>
<string name="maxbasalmultiplier">max basal multiplier</string>
<string name="maxdailybasalmultiplier">max daily basal multiplier</string>
<string name="key_openapsma_max_iob" translatable="false">openapsma_max_iob</string>
<string name="smb_frequency_exceeded">A bolus was delivered within the last 3 minutes, skipping SMB</string>
<string name="basal_set_correctly">Basal set correctly</string>
<string name="limitingpercentrate">Limiting max percent rate to %1$d%% because of %2$s</string>
<string name="key_treatmentssafety_maxbolus" translatable="false">treatmentssafety_maxbolus</string>
<string name="limitingbolus">Limiting bolus to %1$.1f U because of %2$s</string>
<string name="limitingextendedbolus">Limiting extended bolus to %1$.1f U because of %2$s</string>
<string name="limitingmaxiob">Limiting max IOB to %1$.1f U because of %2$s</string>
<string name="limitingcarbs">Limiting carbs to %1$d g because of %2$s</string>
@ -1044,7 +1014,6 @@
<string name="nav_setupwizard">Setup Wizard</string>
<string name="setupwizard_finish">FINISH</string>
<string name="setupwizard_language_prompt">Select your language</string>
<string name="boluserrorcode">Asked: %1$.2fU Delivered: %2$.2fU Error code: %3$s</string>
<string name="firstinsulinincrement">First insulin increment</string>
<string name="secondinsulinincrement">Second insulin increment</string>
<string name="thirdinsulinincrement">Third insulin increment</string>
@ -1183,12 +1152,7 @@
<string name="setupwizard_preferred_aps_mode">Preferred APS mode</string>
<string name="treatments_wizard_total_label">Total</string>
<string name="calculation_short">Calc</string>
<string name="handshaking">Handshaking</string>
<string name="sendlogfiles">Send today\'s log files to developers along with this time. Unexpected situation.</string>
<string name="maxbolusviolation">Max bolus violation</string>
<string name="commanderror">Command error</string>
<string name="speederror">Speed error</string>
<string name="insulinlimitviolation">Insulin limit violation</string>
<string name="loop_openmode_min_change">Minimal request change [%]</string>
<string name="loop_openmode_min_change_summary" formatted="false">Open Loop will popup new change request only if change is bigger than this value in %. Default value is 20%</string>
<string name="key_short_tabtitles" translatable="false">short_tabtitles</string>
@ -1521,7 +1485,6 @@
<string name="rileylink_error_tuneup_failed">TuneUp Failed</string>
<string name="rileylink_error_pump_unreachable">Pump unreachable</string>
<string name="rileylink_error_pod_unreachable">Pod unreachable</string>
<string name="rileylink_error_address_not_set_short">Not set</string>
<!-- RL Target Device -->
<string name="rileylink_target_device_medtronic">Medtronic Pump</string>
@ -1636,7 +1599,6 @@
<string name="time_or_timezone_change">Time and/or Timezone change on pump</string>
<string name="nopumpselected">No pump selected</string>
<string name="setupwizard_units_prompt">Select units you want to display values in</string>
<string name="key_ns_uploadlocalprofile" translatable="false">ns_uploadlocalprofile</string>
<string name="ns_ploadlocalprofile">Upload local profile changes to NS</string>
<string name="key_wear_detailediob" translatable="false">wear_detailediob</string>
<string name="key_wear_showbgi" translatable="false">wear_showbgi</string>
@ -1674,7 +1636,6 @@
<string name="randombg_short">BG</string>
<string name="tools">Tools</string>
<string name="show_calculation">Show calcuation</string>
<string name="error">Error</string>
<string name="timeformat12h">12h</string>
<string name="timeformat24h">24h</string>
<string name="automation_event">Automation event</string>
@ -1741,10 +1702,8 @@
<string name="overview_show_predictions">Predictions</string>
<string name="overview_show_deviationslope">Deviation slope</string>
<string name="key_graphconfig" translatable="false">graphconfig</string>
<string name="key_rs_loginsulinchange" translatable="false">rs_loginsulinchange</string>
<string name="rs_loginsulinchange_title">Log reservoir change</string>
<string name="rs_loginsulinchange_summary">Add \"Insulin Change\" event to careportal when detected in history</string>
<string name="key_rs_logcanulachange" translatable="false">rs_logcanulachange</string>
<string name="rs_logcanulachange_title">Log canula change</string>
<string name="rs_logcanulachange_summary">Add \"Site Change\" event to careportal when detected in history</string>
<string name="authorizationfailed">Authorization failed</string>

View file

@ -2,13 +2,11 @@ package info.nightscout.androidaps.plugins.pump.common.bolusInfo
import info.nightscout.androidaps.TestBase
import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.logging.AAPSLogger
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.powermock.modules.junit4.PowerMockRunner
@RunWith(PowerMockRunner::class)

View file

@ -46,6 +46,7 @@ dependencies {
implementation "androidx.preference:preference-ktx:1.1.1"
implementation "androidx.activity:activity:${activityVersion}"
implementation "androidx.activity:activity-ktx:${activityVersion}"
implementation 'com.google.android.material:material:1.1.0'
implementation "com.google.dagger:dagger-android:$dagger_version"
implementation "com.google.dagger:dagger-android-support:$dagger_version"

View file

@ -1,7 +1,7 @@
package info.nightscout.androidaps.activities
import android.os.Bundle
import info.nightscout.androidaps.R
import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.dialogs.ErrorDialog
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
import info.nightscout.androidaps.utils.sharedPreferences.SP
@ -9,6 +9,7 @@ import javax.inject.Inject
class ErrorHelperActivity : DialogAppCompatActivity() {
@Inject lateinit var sp : SP
@Inject lateinit var nsUpload: NSUpload
@Override
override fun onCreate(savedInstanceState: Bundle?) {
@ -21,7 +22,7 @@ class ErrorHelperActivity : DialogAppCompatActivity() {
errorDialog.show(supportFragmentManager, "Error")
if (sp.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) {
NSUpload.uploadError(intent.getStringExtra("status"))
nsUpload.uploadError(intent.getStringExtra("status"))
}
}
}

View file

@ -9,8 +9,8 @@ import android.view.ViewGroup
import android.view.Window
import android.view.WindowManager
import dagger.android.support.DaggerDialogFragment
import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.BolusProgressHelperActivity
import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.events.EventPumpStatusChanged
import info.nightscout.androidaps.interfaces.CommandQueueProvider
import info.nightscout.androidaps.logging.AAPSLogger
@ -71,7 +71,7 @@ class BolusProgressDialog : DaggerDialogFragment() {
savedInstanceState?.let {
amount = it.getDouble("amount")
}
overview_bolusprogress_title.text = resourceHelper.gs(R.string.overview_bolusprogress_goingtodeliver, amount)
overview_bolusprogress_title.text = resourceHelper.gs(R.string.goingtodeliver, amount)
overview_bolusprogress_stop.setOnClickListener {
aapsLogger.debug(LTag.UI, "Stop bolus delivery button pressed")
stopPressed = true

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.dialogs
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
@ -9,9 +10,8 @@ import android.view.ViewGroup
import android.view.Window
import android.view.WindowManager
import dagger.android.support.DaggerDialogFragment
import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.ErrorHelperActivity
import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.services.AlarmSoundService
import kotlinx.android.synthetic.main.dialog_error.*
@ -19,7 +19,6 @@ import javax.inject.Inject
class ErrorDialog : DaggerDialogFragment() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var mainApp: MainApp
var helperActivity: ErrorHelperActivity? = null
var status: String = ""
@ -82,16 +81,16 @@ class ErrorDialog : DaggerDialogFragment() {
private fun startAlarm() {
if (sound != 0) {
val alarm = Intent(mainApp, AlarmSoundService::class.java)
val alarm = Intent(context, AlarmSoundService::class.java)
alarm.putExtra("soundid", sound)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
mainApp.startForegroundService(alarm)
context?.startForegroundService(alarm)
} else {
mainApp.startService(alarm)
context?.startService(alarm)
}
}
}
private fun stopAlarm() =
mainApp.stopService(Intent(mainApp, AlarmSoundService::class.java))
context?.stopService(Intent(context, AlarmSoundService::class.java))
}

View file

@ -1,6 +1,6 @@
package info.nightscout.androidaps.events
import info.nightscout.androidaps.R
import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.utils.resources.ResourceHelper
class EventPumpStatusChanged : EventStatus {
@ -46,7 +46,7 @@ class EventPumpStatusChanged : EventStatus {
// status for startup wizard
override fun getStatus(resourceHelper: ResourceHelper): String {
return when (status) {
Status.CONNECTING -> String.format(resourceHelper.gs(R.string.danar_history_connectingfor), secondsElapsed)
Status.CONNECTING -> String.format(resourceHelper.gs(R.string.connectingfor), secondsElapsed)
Status.HANDSHAKING -> resourceHelper.gs(R.string.handshaking)
Status.CONNECTED -> resourceHelper.gs(R.string.connected)
Status.PERFORMING -> performingAction

View file

@ -3,6 +3,6 @@ package info.nightscout.androidaps.events
import info.nightscout.androidaps.utils.resources.ResourceHelper
// pass string to startup wizard
abstract class EventStatus :Event() {
abstract class EventStatus : Event() {
abstract fun getStatus(resourceHelper: ResourceHelper) : String
}

View file

@ -2,10 +2,13 @@ package info.nightscout.androidaps.interfaces;
import androidx.collection.LongSparseArray;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.data.AutosensData;
public interface IobCobCalculatorInterface {
LongSparseArray<AutosensData> getAutosensDataTable();
IobTotal[] calculateIobArrayInDia(Profile profile);
String lastDataTime();
AutosensData getAutosensData(long toTime);
}

View file

@ -0,0 +1,24 @@
package info.nightscout.androidaps.interfaces
import info.nightscout.androidaps.data.PumpEnactResult
import info.nightscout.androidaps.plugins.aps.loop.APSResult
import info.nightscout.androidaps.utils.DateUtil
interface LoopInterface {
class LastRun {
var request: APSResult? = null
var constraintsProcessed: APSResult? = null
var tbrSetByPump: PumpEnactResult? = null
var smbSetByPump: PumpEnactResult? = null
var source: String? = null
var lastAPSRun = DateUtil.now()
var lastTBREnact: Long = 0
var lastSMBEnact: Long = 0
var lastTBRRequest: Long = 0
var lastSMBRequest: Long = 0
var lastOpenModeAccept: Long = 0
}
var lastRun: LastRun?
}

View file

@ -0,0 +1,10 @@
package info.nightscout.androidaps.interfaces
import android.app.Notification
interface NotificationHolderInterface {
val channelID : String
val notificationID : Int
var notification: Notification
}

View file

@ -0,0 +1,8 @@
package info.nightscout.androidaps.interfaces;
import info.nightscout.androidaps.db.DbRequest;
public interface UploadQueueInterface {
void add(DbRequest dbRequest);
}

View file

@ -1,31 +1,29 @@
package info.nightscout.androidaps.plugins.general.nsclient;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ResolveInfo;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import javax.inject.Singleton;
import info.nightscout.androidaps.core.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.interfaces.ProfileStore;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.db.DbRequest;
@ -33,27 +31,50 @@ import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.ProfileSwitch;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.interfaces.IobCobCalculatorInterface;
import info.nightscout.androidaps.interfaces.LoopInterface;
import info.nightscout.androidaps.interfaces.ProfileFunction;
import info.nightscout.androidaps.interfaces.ProfileStore;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.UploadQueueInterface;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
import info.nightscout.androidaps.plugins.aps.loop.APSResult;
import info.nightscout.androidaps.plugins.aps.loop.DeviceStatus;
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.interfaces.ProfileFunction;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.receivers.ReceiverStatusStore;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.JsonHelper;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
/**
* Created by mike on 26.05.2017.
*/
@Singleton
public class NSUpload {
private static Logger log = StacktraceLoggerWrapper.getLogger(LTag.NSCLIENT);
public static void uploadTempBasalStartAbsolute(TemporaryBasal temporaryBasal, Double originalExtendedAmount) {
private final AAPSLogger aapsLogger;
private final ResourceHelper resourceHelper;
private final SP sp;
private final Context context;
private final UploadQueueInterface uploadQueue;
public NSUpload(
AAPSLogger aapsLogger,
ResourceHelper resourceHelper,
SP sp,
Context context,
UploadQueueInterface uploadQueue
) {
this.aapsLogger = aapsLogger;
this.resourceHelper = resourceHelper;
this.sp = sp;
this.context = context;
this.uploadQueue = uploadQueue;
}
public void uploadTempBasalStartAbsolute(TemporaryBasal temporaryBasal, Double originalExtendedAmount) {
try {
JSONObject data = new JSONObject();
data.put("eventType", CareportalEvent.TEMPBASAL);
@ -63,19 +84,18 @@ public class NSUpload {
if (temporaryBasal.pumpId != 0)
data.put("pumpId", temporaryBasal.pumpId);
data.put("created_at", DateUtil.toISOString(temporaryBasal.date));
data.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
data.put("enteredBy", "openaps://" + "AndroidAPS");
if (originalExtendedAmount != null)
data.put("originalExtendedAmount", originalExtendedAmount); // for back synchronization
UploadQueue.add(new DbRequest("dbAdd", "treatments", data));
uploadQueue.add(new DbRequest("dbAdd", "treatments", data));
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
}
public static void uploadTempBasalStartPercent(TemporaryBasal temporaryBasal, Profile profile) {
public void uploadTempBasalStartPercent(TemporaryBasal temporaryBasal, Profile profile) {
try {
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
boolean useAbsolute = SP.getBoolean("ns_sync_use_absolute", false);
boolean useAbsolute = sp.getBoolean("ns_sync_use_absolute", false);
double absoluteRate = 0;
if (profile != null) {
absoluteRate = profile.getBasal(temporaryBasal.date) * temporaryBasal.percentRate / 100d;
@ -97,31 +117,31 @@ public class NSUpload {
if (temporaryBasal.pumpId != 0)
data.put("pumpId", temporaryBasal.pumpId);
data.put("created_at", DateUtil.toISOString(temporaryBasal.date));
data.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
UploadQueue.add(new DbRequest("dbAdd", "treatments", data));
data.put("enteredBy", "openaps://" + "AndroidAPS");
uploadQueue.add(new DbRequest("dbAdd", "treatments", data));
}
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
}
public static void uploadTempBasalEnd(long time, boolean isFakedTempBasal, long pumpId) {
public void uploadTempBasalEnd(long time, boolean isFakedTempBasal, long pumpId) {
try {
JSONObject data = new JSONObject();
data.put("eventType", CareportalEvent.TEMPBASAL);
data.put("created_at", DateUtil.toISOString(time));
data.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
data.put("enteredBy", "openaps://" + "AndroidAPS");
if (isFakedTempBasal)
data.put("isFakedTempBasal", isFakedTempBasal);
if (pumpId != 0)
data.put("pumpId", pumpId);
UploadQueue.add(new DbRequest("dbAdd", "treatments", data));
uploadQueue.add(new DbRequest("dbAdd", "treatments", data));
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
}
public static void uploadExtendedBolus(ExtendedBolus extendedBolus) {
public void uploadExtendedBolus(ExtendedBolus extendedBolus) {
try {
JSONObject data = new JSONObject();
data.put("eventType", CareportalEvent.COMBOBOLUS);
@ -133,14 +153,14 @@ public class NSUpload {
if (extendedBolus.pumpId != 0)
data.put("pumpId", extendedBolus.pumpId);
data.put("created_at", DateUtil.toISOString(extendedBolus.date));
data.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
UploadQueue.add(new DbRequest("dbAdd", "treatments", data));
data.put("enteredBy", "openaps://" + "AndroidAPS");
uploadQueue.add(new DbRequest("dbAdd", "treatments", data));
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
}
public static void uploadExtendedBolusEnd(long time, long pumpId) {
public void uploadExtendedBolusEnd(long time, long pumpId) {
try {
JSONObject data = new JSONObject();
data.put("eventType", CareportalEvent.COMBOBOLUS);
@ -150,59 +170,59 @@ public class NSUpload {
data.put("enteredinsulin", 0);
data.put("relative", 0);
data.put("created_at", DateUtil.toISOString(time));
data.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
data.put("enteredBy", "openaps://" + "AndroidAPS");
if (pumpId != 0)
data.put("pumpId", pumpId);
UploadQueue.add(new DbRequest("dbAdd", "treatments", data));
uploadQueue.add(new DbRequest("dbAdd", "treatments", data));
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
}
public static void uploadDeviceStatus(LoopPlugin loopPlugin, IobCobCalculatorPlugin iobCobCalculatorPlugin, ProfileFunction profileFunction, PumpInterface pumpInterface, ReceiverStatusStore receiverStatusStore) {
public void uploadDeviceStatus(LoopInterface loopPlugin, IobCobCalculatorInterface iobCobCalculatorPlugin, ProfileFunction profileFunction, PumpInterface pumpInterface, ReceiverStatusStore receiverStatusStore) {
Profile profile = profileFunction.getProfile();
String profileName = profileFunction.getProfileName();
if (profile == null) {
log.error("Profile is null. Skipping upload");
aapsLogger.error("Profile is null. Skipping upload");
return;
}
DeviceStatus deviceStatus = new DeviceStatus();
try {
LoopPlugin.LastRun lastRun = loopPlugin.lastRun;
if (lastRun != null && lastRun.lastAPSRun > System.currentTimeMillis() - 300 * 1000L) {
LoopInterface.LastRun lastRun = loopPlugin.getLastRun();
if (lastRun != null && lastRun.getLastAPSRun() > System.currentTimeMillis() - 300 * 1000L) {
// do not send if result is older than 1 min
APSResult apsResult = lastRun.request;
apsResult.json().put("timestamp", DateUtil.toISOString(lastRun.lastAPSRun));
APSResult apsResult = lastRun.getRequest();
apsResult.json().put("timestamp", DateUtil.toISOString(lastRun.getLastAPSRun()));
deviceStatus.suggested = apsResult.json();
deviceStatus.iob = lastRun.request.iob.json();
deviceStatus.iob.put("time", DateUtil.toISOString(lastRun.lastAPSRun));
deviceStatus.iob = lastRun.getRequest().iob.json();
deviceStatus.iob.put("time", DateUtil.toISOString(lastRun.getLastAPSRun()));
JSONObject requested = new JSONObject();
if (lastRun.tbrSetByPump != null && lastRun.tbrSetByPump.enacted) { // enacted
deviceStatus.enacted = lastRun.request.json();
deviceStatus.enacted.put("rate", lastRun.tbrSetByPump.json(profile).get("rate"));
deviceStatus.enacted.put("duration", lastRun.tbrSetByPump.json(profile).get("duration"));
if (lastRun.getTbrSetByPump() != null && lastRun.getTbrSetByPump().enacted) { // enacted
deviceStatus.enacted = lastRun.getRequest().json();
deviceStatus.enacted.put("rate", lastRun.getTbrSetByPump().json(profile).get("rate"));
deviceStatus.enacted.put("duration", lastRun.getTbrSetByPump().json(profile).get("duration"));
deviceStatus.enacted.put("recieved", true);
requested.put("duration", lastRun.request.duration);
requested.put("rate", lastRun.request.rate);
requested.put("duration", lastRun.getRequest().duration);
requested.put("rate", lastRun.getRequest().rate);
requested.put("temp", "absolute");
deviceStatus.enacted.put("requested", requested);
}
if (lastRun.smbSetByPump != null && lastRun.smbSetByPump.enacted) { // enacted
if (lastRun.getTbrSetByPump() != null && lastRun.getTbrSetByPump().enacted) { // enacted
if (deviceStatus.enacted == null) {
deviceStatus.enacted = lastRun.request.json();
deviceStatus.enacted = lastRun.getRequest().json();
}
deviceStatus.enacted.put("smb", lastRun.smbSetByPump.bolusDelivered);
requested.put("smb", lastRun.request.smb);
deviceStatus.enacted.put("smb", lastRun.getTbrSetByPump().bolusDelivered);
requested.put("smb", lastRun.getRequest().smb);
deviceStatus.enacted.put("requested", requested);
}
} else {
if (L.isEnabled(LTag.NSCLIENT))
log.debug("OpenAPS data too old to upload, sending iob only");
aapsLogger.debug("OpenAPS data too old to upload, sending iob only");
IobTotal[] iob = iobCobCalculatorPlugin.calculateIobArrayInDia(profile);
if (iob.length > 0) {
deviceStatus.iob = iob[0].json();
@ -219,13 +239,13 @@ public class NSUpload {
deviceStatus.uploaderBattery = batteryLevel;
deviceStatus.created_at = DateUtil.toISOString(new Date());
UploadQueue.add(new DbRequest("dbAdd", "devicestatus", deviceStatus.mongoRecord()));
uploadQueue.add(new DbRequest("dbAdd", "devicestatus", deviceStatus.mongoRecord()));
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
}
public static void uploadTreatmentRecord(DetailedBolusInfo detailedBolusInfo) {
public void uploadTreatmentRecord(DetailedBolusInfo detailedBolusInfo) {
JSONObject data = new JSONObject();
try {
data.put("eventType", detailedBolusInfo.eventType);
@ -248,21 +268,21 @@ public class NSUpload {
data.put("notes", detailedBolusInfo.notes);
}
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
uploadCareportalEntryToNS(data);
}
public static void uploadProfileSwitch(ProfileSwitch profileSwitch) {
public void uploadProfileSwitch(ProfileSwitch profileSwitch) {
try {
JSONObject data = getJson(profileSwitch);
uploadCareportalEntryToNS(data);
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
}
public static void uploadTempTarget(TempTarget tempTarget, ProfileFunction profileFunction) {
public void uploadTempTarget(TempTarget tempTarget, ProfileFunction profileFunction) {
try {
JSONObject data = new JSONObject();
data.put("eventType", CareportalEvent.TEMPORARYTARGET);
@ -274,21 +294,21 @@ public class NSUpload {
data.put("units", profileFunction.getUnits());
}
data.put("created_at", DateUtil.toISOString(tempTarget.date));
data.put("enteredBy", MainApp.gs(R.string.app_name));
data.put("enteredBy", "AndroidAPS");
uploadCareportalEntryToNS(data);
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
}
public static void updateProfileSwitch(ProfileSwitch profileSwitch) {
public void updateProfileSwitch(ProfileSwitch profileSwitch) {
try {
JSONObject data = getJson(profileSwitch);
if (profileSwitch._id != null) {
UploadQueue.add(new DbRequest("dbUpdate", "treatments", profileSwitch._id, data));
uploadQueue.add(new DbRequest("dbUpdate", "treatments", profileSwitch._id, data));
}
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
}
@ -305,12 +325,12 @@ public class NSUpload {
data.put("percentage", profileSwitch.percentage);
}
data.put("created_at", DateUtil.toISOString(profileSwitch.date));
data.put("enteredBy", MainApp.gs(R.string.app_name));
data.put("enteredBy", "AndroidAPS");
return data;
}
public static void uploadCareportalEntryToNS(JSONObject data) {
public void uploadCareportalEntryToNS(JSONObject data) {
try {
if (data.has("preBolus") && data.has("carbs")) {
JSONObject prebolus = new JSONObject();
@ -325,48 +345,48 @@ public class NSUpload {
uploadCareportalEntryToNS(prebolus);
}
DbRequest dbr = new DbRequest("dbAdd", "treatments", data);
log.debug("Prepared: " + dbr.log());
UploadQueue.add(dbr);
aapsLogger.debug("Prepared: " + dbr.log());
uploadQueue.add(dbr);
} catch (Exception e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
}
public static void removeCareportalEntryFromNS(String _id) {
UploadQueue.add(new DbRequest("dbRemove", "treatments", _id));
public void removeCareportalEntryFromNS(String _id) {
uploadQueue.add(new DbRequest("dbRemove", "treatments", _id));
}
public static void uploadOpenAPSOffline(CareportalEvent event) {
public void uploadOpenAPSOffline(CareportalEvent event) {
try {
JSONObject data = new JSONObject(event.json);
data.put("created_at", DateUtil.toISOString(event.date));
data.put("enteredBy", "openaps://" + MainApp.gs(R.string.app_name));
UploadQueue.add(new DbRequest("dbAdd", "treatments", data));
data.put("enteredBy", "openaps://" + "AndroidAPS");
uploadQueue.add(new DbRequest("dbAdd", "treatments", data));
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
}
public static void uploadError(String error) {
public void uploadError(String error) {
uploadError(error, new Date());
}
public static void uploadError(String error, Date date) {
public void uploadError(String error, Date date) {
JSONObject data = new JSONObject();
try {
data.put("eventType", "Announcement");
data.put("created_at", DateUtil.toISOString(date));
data.put("enteredBy", SP.getString("careportal_enteredby", MainApp.gs(R.string.app_name)));
data.put("enteredBy", sp.getString("careportal_enteredby", "AndroidAPS"));
data.put("notes", error);
data.put("isAnnouncement", true);
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
UploadQueue.add(new DbRequest("dbAdd", "treatments", data));
uploadQueue.add(new DbRequest("dbAdd", "treatments", data));
}
public static void uploadBg(BgReading reading, String source) {
public void uploadBg(BgReading reading, String source) {
JSONObject data = new JSONObject();
try {
data.put("device", source);
@ -376,56 +396,56 @@ public class NSUpload {
data.put("direction", reading.direction);
data.put("type", "sgv");
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
UploadQueue.add(new DbRequest("dbAdd", "entries", data));
uploadQueue.add(new DbRequest("dbAdd", "entries", data));
}
public static void uploadAppStart() {
if (SP.getBoolean(R.string.key_ns_logappstartedevent, true)) {
public void uploadAppStart() {
if (sp.getBoolean(R.string.key_ns_logappstartedevent, true)) {
JSONObject data = new JSONObject();
try {
data.put("eventType", "Note");
data.put("created_at", DateUtil.toISOString(new Date()));
data.put("notes", MainApp.gs(R.string.androidaps_start) + " - " + Build.MANUFACTURER + " " + Build.MODEL);
data.put("notes", resourceHelper.gs(R.string.androidaps_start) + " - " + Build.MANUFACTURER + " " + Build.MODEL);
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
UploadQueue.add(new DbRequest("dbAdd", "treatments", data));
uploadQueue.add(new DbRequest("dbAdd", "treatments", data));
}
}
public static void uploadProfileStore(JSONObject profileStore) {
if (SP.getBoolean(R.string.key_ns_uploadlocalprofile, false)) {
UploadQueue.add(new DbRequest("dbAdd", "profile", profileStore));
public void uploadProfileStore(JSONObject profileStore) {
if (sp.getBoolean(R.string.key_ns_uploadlocalprofile, false)) {
uploadQueue.add(new DbRequest("dbAdd", "profile", profileStore));
}
}
public static void uploadEvent(String careportalEvent, long time, @Nullable String notes) {
public void uploadEvent(String careportalEvent, long time, @Nullable String notes) {
JSONObject data = new JSONObject();
try {
data.put("eventType", careportalEvent);
data.put("created_at", DateUtil.toISOString(time));
data.put("enteredBy", SP.getString("careportal_enteredby", MainApp.gs(R.string.app_name)));
data.put("enteredBy", sp.getString("careportal_enteredby", "AndroidAPS"));
if (notes != null) {
data.put("notes", notes);
}
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
UploadQueue.add(new DbRequest("dbAdd", "treatments", data));
uploadQueue.add(new DbRequest("dbAdd", "treatments", data));
}
public static void removeFoodFromNS(String _id) {
public void removeFoodFromNS(String _id) {
try {
UploadQueue.add(new DbRequest("dbRemove", "food", _id));
uploadQueue.add(new DbRequest("dbRemove", "food", _id));
} catch (Exception e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
}
public static void sendToXdrip(BgReading bgReading) {
public void sendToXdrip(BgReading bgReading) {
final String XDRIP_PLUS_NS_EMULATOR = "com.eveningoutpost.dexdrip.NS_EMULATOR";
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);
@ -450,22 +470,22 @@ public class NSUpload {
bundle.putString("data", entriesBody.toString());
final Intent intent = new Intent(XDRIP_PLUS_NS_EMULATOR);
intent.putExtras(bundle).addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
MainApp.instance().sendBroadcast(intent);
List<ResolveInfo> receivers = MainApp.instance().getPackageManager().queryBroadcastReceivers(intent, 0);
context.sendBroadcast(intent);
List<ResolveInfo> receivers = context.getPackageManager().queryBroadcastReceivers(intent, 0);
if (receivers.size() < 1) {
log.debug("No xDrip receivers found. ");
aapsLogger.debug("No xDrip receivers found. ");
} else {
log.debug(receivers.size() + " xDrip receivers");
aapsLogger.debug(receivers.size() + " xDrip receivers");
}
} catch (JSONException e) {
log.error("Unhandled exception", e);
aapsLogger.error("Unhandled exception", e);
}
}
public static void createNSTreatment(JSONObject data, ProfileStore profileStore, ProfileFunction profileFunction, long eventTime) {
public void createNSTreatment(JSONObject data, ProfileStore profileStore, ProfileFunction profileFunction, long eventTime) {
if (JsonHelper.safeGetString(data, "eventType", "").equals(CareportalEvent.PROFILESWITCH)) {
ProfileSwitch profileSwitch = profileFunction.prepareProfileSwitch(
profileStore,

View file

@ -2,9 +2,7 @@ package info.nightscout.androidaps.plugins.pump.common.bolusInfo
import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper
import info.nightscout.androidaps.utils.T
import java.util.*
import javax.inject.Inject

View file

@ -6,17 +6,17 @@ import android.media.AudioManager
import android.media.MediaPlayer
import android.os.IBinder
import dagger.android.DaggerService
import info.nightscout.androidaps.R
import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.interfaces.NotificationHolderInterface
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.utils.androidNotification.NotificationHolder
import info.nightscout.androidaps.utils.resources.ResourceHelper
import javax.inject.Inject
class AlarmSoundService : DaggerService() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var resourceHelper: ResourceHelper
@Inject lateinit var notificationHolder: NotificationHolder
@Inject lateinit var notificationHolder: NotificationHolderInterface
private var player: MediaPlayer? = null
private var resourceId = R.raw.error

View file

@ -1,8 +1,5 @@
package info.nightscout.androidaps.utils;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
/**
* class contains useful String functions
*/

View file

@ -7,7 +7,7 @@ import android.text.TextUtils
import android.text.TextWatcher
import android.widget.EditText
import com.google.android.material.textfield.TextInputLayout
import info.nightscout.androidaps.R
import info.nightscout.androidaps.core.R
import info.nightscout.androidaps.utils.textValidator.validators.*
class DefaultEditTextValidator : EditTextValidator {

View file

@ -6,7 +6,7 @@ import android.util.AttributeSet
import androidx.preference.EditTextPreference
import androidx.preference.EditTextPreference.OnBindEditTextListener
import androidx.preference.PreferenceViewHolder
import info.nightscout.androidaps.R
import info.nightscout.androidaps.core.R
class ValidatingEditTextPreference(ctx: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int)
: EditTextPreference(ctx, attrs, defStyleAttr, defStyleRes) {

View file

@ -17,6 +17,34 @@
<string name="key_hypo_target" translatable="false">hypo_target</string>
<string name="key_low_mark" translatable="false">low_mark</string>
<string name="key_high_mark" translatable="false">high_mark</string>
<string name="key_ns_create_announcements_from_errors" translatable="false">ns_create_announcements_from_errors</string>
<string name="key_ns_logappstartedevent" translatable="false">ns_logappstartedevent</string>
<string name="key_ns_uploadlocalprofile" translatable="false">ns_uploadlocalprofile</string>
<!-- General-->
<string name="error">Error</string>
<string name="not_set_short">Not set</string>
<string name="failedupdatebasalprofile">Failed to update basal profile</string>
<string name="profile_set_ok">Basal profile in pump updated</string>
<string name="invalidinput">Invalid input data</string>
<string name="tempbasaldeliveryerror">Tempbasal delivery error</string>
<string name="goingtodeliver">Going to deliver %1$.2fU</string>
<string name="waitingforpump">Waiting for pump</string>
<string name="connectingfor">Connecting for %1$d s</string>
<string name="handshaking">Handshaking</string>
<string name="connecting">Connecting</string>
<string name="connected">Connected</string>
<string name="disconnected">Disconnected</string>
<string name="disconnecting">Disconnecting</string>
<string name="androidaps_start">AndroidAPS started</string>
<!-- Constraints-->
<string name="limitingbasalratio">Limiting max basal rate to %1$.2f U/h because of %2$s</string>
<string name="pumplimit">pump limit</string>
<string name="limitingpercentrate">Limiting max percent rate to %1$d%% because of %2$s</string>
<string name="itmustbepositivevalue">it must be positive value</string>
<string name="limitingbolus">Limiting bolus to %1$.1f U because of %2$s</string>
<string name="pumpNotInitializedProfileNotSet">Pump not initialized, profile not set!</string>
<!-- Dialogs-->
<string name="confirmation">Confirmation</string>

View file

@ -50,9 +50,12 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation "androidx.preference:preference-ktx:1.1.1"
implementation "androidx.activity:activity:${activityVersion}"
implementation "androidx.activity:activity-ktx:${activityVersion}"
// Graphview cannot be upgraded
implementation "com.jjoe64:graphview:4.0.1"
implementation "com.google.dagger:dagger-android:$dagger_version"
implementation "com.google.dagger:dagger-android-support:$dagger_version"

View file

@ -8,8 +8,7 @@ import android.os.IBinder
import android.text.format.DateFormat
import androidx.preference.Preference
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.BuildConfig
import info.nightscout.androidaps.R
import info.nightscout.androidaps.danars.R
import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.data.Profile
import info.nightscout.androidaps.data.PumpEnactResult
@ -34,7 +33,6 @@ import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes
import info.nightscout.androidaps.plugins.pump.danaRS.events.EventDanaRSDeviceChange
import info.nightscout.androidaps.plugins.pump.danaRS.services.DanaRSService
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
import info.nightscout.androidaps.utils.*
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
@ -56,13 +54,14 @@ class DanaRSPlugin @Inject constructor(
resourceHelper: ResourceHelper,
private val constraintChecker: ConstraintChecker,
private val profileFunction: ProfileFunction,
private val treatmentsPlugin: TreatmentsPlugin,
private val activePluginProvider: ActivePluginProvider,
private val sp: SP,
commandQueue: CommandQueueProvider,
private val danaRPump: DanaRPump,
private val detailedBolusInfoStorage: DetailedBolusInfoStorage,
private val fabricPrivacy: FabricPrivacy,
private val dateUtil: DateUtil
private val dateUtil: DateUtil,
private val config: ConfigInterface
) : PumpPluginBase(PluginDescription()
.mainType(PluginType.PUMP)
.fragmentClass(DanaRFragment::class.java.name)
@ -85,7 +84,7 @@ class DanaRSPlugin @Inject constructor(
if (pref.key == resourceHelper.gs(R.string.key_danars_name)) {
val value = sp.getStringOrNull(R.string.key_danars_name, null)
pref.summary = value
?: resourceHelper.gs(R.string.rileylink_error_address_not_set_short)
?: resourceHelper.gs(R.string.not_set_short)
}
}
@ -320,7 +319,7 @@ class DanaRSPlugin @Inject constructor(
0x80 -> error = resourceHelper.gs(R.string.insulinlimitviolation)
}
result.comment = String.format(resourceHelper.gs(R.string.boluserrorcode), detailedBolusInfo.insulin, t.insulin, error)
} else result.comment = resourceHelper.gs(R.string.virtualpump_resultok)
} else result.comment = resourceHelper.gs(R.string.ok)
aapsLogger.debug(LTag.PUMP, "deliverTreatment: OK. Asked: " + detailedBolusInfo.insulin + " Delivered: " + result.bolusDelivered)
result
} else {
@ -328,7 +327,7 @@ class DanaRSPlugin @Inject constructor(
result.success = false
result.bolusDelivered = 0.0
result.carbsDelivered = 0.0
result.comment = resourceHelper.gs(R.string.danar_invalidinput)
result.comment = resourceHelper.gs(R.string.invalidinput)
aapsLogger.error("deliverTreatment: Invalid input")
result
}
@ -348,7 +347,7 @@ class DanaRSPlugin @Inject constructor(
val doHighTemp = absoluteAfterConstrain > baseBasalRate
if (doTempOff) {
// If temp in progress
if (treatmentsPlugin.isTempBasalInProgress) {
if (activePluginProvider.activeTreatments.isTempBasalInProgress) {
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: Stopping temp basal (doTempOff)")
return cancelTempBasal(false)
}
@ -366,7 +365,7 @@ class DanaRSPlugin @Inject constructor(
if (percentRate > 500) // Special high temp 500/15min
percentRate = 500
// Check if some temp is already in progress
val activeTemp = treatmentsPlugin.getTempBasalFromHistory(System.currentTimeMillis())
val activeTemp = activePluginProvider.activeTreatments.getTempBasalFromHistory(System.currentTimeMillis())
if (activeTemp != null) {
aapsLogger.debug(LTag.PUMP, "setTempBasalAbsolute: currently running: $activeTemp")
// Correct basal already set ?
@ -413,18 +412,18 @@ class DanaRSPlugin @Inject constructor(
result.isTempCancel = false
result.enacted = false
result.success = false
result.comment = resourceHelper.gs(R.string.danar_invalidinput)
result.comment = resourceHelper.gs(R.string.invalidinput)
aapsLogger.error("setTempBasalPercent: Invalid input")
return result
}
if (percentAfterConstraint > pumpDescription.maxTempPercent) percentAfterConstraint = pumpDescription.maxTempPercent
val now = System.currentTimeMillis()
val activeTemp = treatmentsPlugin.getTempBasalFromHistory(now)
val activeTemp = activePluginProvider.activeTreatments.getTempBasalFromHistory(now)
if (activeTemp != null && activeTemp.percentRate == percentAfterConstraint && activeTemp.plannedRemainingMinutes > 4 && !enforceNew) {
result.enacted = false
result.success = true
result.isTempCancel = false
result.comment = resourceHelper.gs(R.string.virtualpump_resultok)
result.comment = resourceHelper.gs(R.string.ok)
result.duration = danaRPump.tempBasalRemainingMin
result.percent = danaRPump.tempBasalPercent
result.isPercent = true
@ -442,7 +441,7 @@ class DanaRSPlugin @Inject constructor(
if (connectionOK && danaRPump.isTempBasalInProgress && danaRPump.tempBasalPercent == percentAfterConstraint) {
result.enacted = true
result.success = true
result.comment = resourceHelper.gs(R.string.virtualpump_resultok)
result.comment = resourceHelper.gs(R.string.ok)
result.isTempCancel = false
result.duration = danaRPump.tempBasalRemainingMin
result.percent = danaRPump.tempBasalPercent
@ -463,7 +462,7 @@ class DanaRSPlugin @Inject constructor(
if (connectionOK && danaRPump.isTempBasalInProgress && danaRPump.tempBasalPercent == percent) {
result.enacted = true
result.success = true
result.comment = resourceHelper.gs(R.string.virtualpump_resultok)
result.comment = resourceHelper.gs(R.string.ok)
result.isTempCancel = false
result.duration = danaRPump.tempBasalRemainingMin
result.percent = danaRPump.tempBasalPercent
@ -485,11 +484,11 @@ class DanaRSPlugin @Inject constructor(
val durationInHalfHours = max(durationInMinutes / 30, 1)
insulinAfterConstraint = Round.roundTo(insulinAfterConstraint, pumpDescription.extendedBolusStep)
val result = PumpEnactResult(injector)
val runningEB = treatmentsPlugin.getExtendedBolusFromHistory(System.currentTimeMillis())
val runningEB = activePluginProvider.activeTreatments.getExtendedBolusFromHistory(System.currentTimeMillis())
if (runningEB != null && abs(runningEB.insulin - insulinAfterConstraint) < pumpDescription.extendedBolusStep) {
result.enacted = false
result.success = true
result.comment = resourceHelper.gs(R.string.virtualpump_resultok)
result.comment = resourceHelper.gs(R.string.ok)
result.duration = danaRPump.extendedBolusRemainingMinutes
result.absolute = danaRPump.extendedBolusAbsoluteRate
result.isPercent = false
@ -502,7 +501,7 @@ class DanaRSPlugin @Inject constructor(
if (connectionOK && danaRPump.isExtendedInProgress && abs(danaRPump.extendedBolusAbsoluteRate - insulinAfterConstraint) < pumpDescription.extendedBolusStep) {
result.enacted = true
result.success = true
result.comment = resourceHelper.gs(R.string.virtualpump_resultok)
result.comment = resourceHelper.gs(R.string.ok)
result.isTempCancel = false
result.duration = danaRPump.extendedBolusRemainingMinutes
result.absolute = danaRPump.extendedBolusAbsoluteRate
@ -521,7 +520,7 @@ class DanaRSPlugin @Inject constructor(
@Synchronized
override fun cancelTempBasal(force: Boolean): PumpEnactResult {
val result = PumpEnactResult(injector)
val runningTB = treatmentsPlugin.getTempBasalFromHistory(System.currentTimeMillis())
val runningTB = activePluginProvider.activeTreatments.getTempBasalFromHistory(System.currentTimeMillis())
if (runningTB != null) {
danaRSService?.tempBasalStop()
result.enacted = true
@ -530,7 +529,7 @@ class DanaRSPlugin @Inject constructor(
return if (!danaRPump.isTempBasalInProgress) {
result.success = true
result.isTempCancel = true
result.comment = resourceHelper.gs(R.string.virtualpump_resultok)
result.comment = resourceHelper.gs(R.string.ok)
aapsLogger.debug(LTag.PUMP, "cancelRealTempBasal: OK")
result
} else {
@ -544,7 +543,7 @@ class DanaRSPlugin @Inject constructor(
@Synchronized override fun cancelExtendedBolus(): PumpEnactResult {
val result = PumpEnactResult(injector)
val runningEB = treatmentsPlugin.getExtendedBolusFromHistory(System.currentTimeMillis())
val runningEB = activePluginProvider.activeTreatments.getExtendedBolusFromHistory(System.currentTimeMillis())
if (runningEB != null) {
danaRSService?.extendedBolusStop()
result.enacted = true
@ -552,7 +551,7 @@ class DanaRSPlugin @Inject constructor(
}
return if (!danaRPump.isExtendedInProgress) {
result.success = true
result.comment = resourceHelper.gs(R.string.virtualpump_resultok)
result.comment = resourceHelper.gs(R.string.ok)
aapsLogger.debug(LTag.PUMP, "cancelExtendedBolus: OK")
result
} else {
@ -581,13 +580,13 @@ class DanaRSPlugin @Inject constructor(
extended.put("LastBolus", dateUtil.dateAndTimeString(danaRPump.lastBolusTime))
extended.put("LastBolusAmount", danaRPump.lastBolusAmount)
}
val tb = treatmentsPlugin.getTempBasalFromHistory(now)
val tb = activePluginProvider.activeTreatments.getTempBasalFromHistory(now)
if (tb != null) {
extended.put("TempBasalAbsoluteRate", tb.tempBasalConvertedToAbsolute(now, profile))
extended.put("TempBasalStart", dateUtil.dateAndTimeString(tb.date))
extended.put("TempBasalRemaining", tb.plannedRemainingMinutes)
}
val eb = treatmentsPlugin.getExtendedBolusFromHistory(now)
val eb = activePluginProvider.activeTreatments.getExtendedBolusFromHistory(now)
if (eb != null) {
extended.put("ExtendedBolusAbsoluteRate", eb.absoluteRate())
extended.put("ExtendedBolusStart", dateUtil.dateAndTimeString(eb.date))
@ -636,11 +635,11 @@ class DanaRSPlugin @Inject constructor(
if (danaRPump.lastBolusTime != 0L)
ret += "LastBolus: ${DecimalFormatter.to2Decimal(danaRPump.lastBolusAmount)}U @${DateFormat.format("HH:mm", danaRPump.lastBolusTime)}"
val activeTemp = treatmentsPlugin.getRealTempBasalFromHistory(System.currentTimeMillis())
val activeTemp = activePluginProvider.activeTreatments.getRealTempBasalFromHistory(System.currentTimeMillis())
if (activeTemp != null)
ret += "Temp: ${activeTemp.toStringFull()}"
val activeExtendedBolus = treatmentsPlugin.getExtendedBolusFromHistory(System.currentTimeMillis())
val activeExtendedBolus = activePluginProvider.activeTreatments.getExtendedBolusFromHistory(System.currentTimeMillis())
if (activeExtendedBolus != null)
ret += "Extended: $activeExtendedBolus\n"

View file

@ -2,8 +2,8 @@ package info.nightscout.androidaps.plugins.pump.danaRS.activities
import android.os.Bundle
import android.util.Base64
import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
import info.nightscout.androidaps.danars.R
import info.nightscout.androidaps.events.EventPumpStatusChanged
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
import info.nightscout.androidaps.plugins.pump.danaRS.DanaRSPlugin
@ -56,7 +56,7 @@ class EnterPinActivity : NoSplashAppCompatActivity() {
bleComm.finishV3Pairing()
finish()
}
else OKDialog.show(this, resourceHelper.gs(R.string.error), resourceHelper.gs(R.string.danar_invalidinput))
else OKDialog.show(this, resourceHelper.gs(R.string.error), resourceHelper.gs(R.string.invalidinput))
}
}
cancel.setOnClickListener { finish() }

View file

@ -1,7 +1,7 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm
import dagger.android.HasAndroidInjector
import info.nightscout.androidaps.R
import info.nightscout.androidaps.danars.R
import info.nightscout.androidaps.data.DetailedBolusInfo
import info.nightscout.androidaps.db.CareportalEvent
import info.nightscout.androidaps.db.ExtendedBolus
@ -195,7 +195,7 @@ open class DanaRS_Packet_APS_History_Events(
status = "PRIMECANNULA " + dateUtil.timeString(datetime)
}
else -> {
else -> {
aapsLogger.debug(LTag.PUMPCOMM, "Event: " + recordCode + " " + dateUtil.dateAndTimeString(datetime) + " (" + datetime + ")" + " Param1: " + param1 + " Param2: " + param2)
status = "UNKNOWN " + dateUtil.timeString(datetime)
}

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