SMS suspend/resume loop
This commit is contained in:
parent
a02da220c9
commit
c5245ae5fd
4 changed files with 72 additions and 33 deletions
|
@ -713,28 +713,6 @@ public class OverviewFragment extends Fragment {
|
|||
apsModeView.setText(MainApp.sResources.getString(R.string.disabledloop));
|
||||
apsModeView.setTextColor(Color.WHITE);
|
||||
}
|
||||
/*
|
||||
apsModeView.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
|
||||
if (activeloop == null) {
|
||||
log.error("no active loop?");
|
||||
return true;
|
||||
} else if (activeloop.isEnabled(PluginBase.LOOP)) {
|
||||
activeloop.setFragmentEnabled(PluginBase.LOOP, false);
|
||||
activeloop.setFragmentVisible(PluginBase.LOOP, false);
|
||||
} else {
|
||||
activeloop.setFragmentEnabled(PluginBase.LOOP, true);
|
||||
activeloop.setFragmentVisible(PluginBase.LOOP, true);
|
||||
}
|
||||
MainApp.getConfigBuilder().storeSettings();
|
||||
MainApp.bus().post(new EventRefreshGui(false));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
apsModeView.setLongClickable(true);
|
||||
*/
|
||||
} else {
|
||||
apsModeView.setVisibility(View.GONE);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import info.nightscout.androidaps.data.IobTotal;
|
|||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin;
|
||||
|
@ -68,6 +69,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
double bolusRequested = 0d;
|
||||
double tempBasal = 0d;
|
||||
double calibrationRequested = 0d;
|
||||
int duration = 0;
|
||||
|
||||
public Sms(SmsMessage message) {
|
||||
phoneNumber = message.getOriginatingAddress();
|
||||
|
@ -100,6 +102,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
Sms tempBasalWaitingForConfirmation = null;
|
||||
Sms bolusWaitingForConfirmation = null;
|
||||
Sms calibrationWaitingForConfirmation = null;
|
||||
Sms suspendWaitingForConfirmation = null;
|
||||
Date lastRemoteBolusTime = new Date(0);
|
||||
|
||||
ArrayList<Sms> messages = new ArrayList<>();
|
||||
|
@ -212,7 +215,9 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
String[] splited = receivedSms.text.split("\\s+");
|
||||
Double amount = 0d;
|
||||
Double tempBasal = 0d;
|
||||
int duration = 0;
|
||||
String passCode = "";
|
||||
boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false);
|
||||
|
||||
if (splited.length > 0) {
|
||||
switch (splited[0].toUpperCase()) {
|
||||
|
@ -250,6 +255,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
break;
|
||||
case "LOOP":
|
||||
switch (splited[1].toUpperCase()) {
|
||||
case "DISABLE":
|
||||
case "STOP":
|
||||
LoopPlugin loopPlugin = (LoopPlugin) MainApp.getSpecificPlugin(LoopPlugin.class);
|
||||
if (loopPlugin != null && loopPlugin.isEnabled(PluginBase.LOOP)) {
|
||||
|
@ -260,6 +266,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
receivedSms.processed = true;
|
||||
Answers.getInstance().logCustom(new CustomEvent("SMS_Loop_Stop"));
|
||||
break;
|
||||
case "ENABLE":
|
||||
case "START":
|
||||
loopPlugin = (LoopPlugin) MainApp.getSpecificPlugin(LoopPlugin.class);
|
||||
if (loopPlugin != null && !loopPlugin.isEnabled(PluginBase.LOOP)) {
|
||||
|
@ -274,7 +281,10 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
loopPlugin = (LoopPlugin) MainApp.getSpecificPlugin(LoopPlugin.class);
|
||||
if (loopPlugin != null) {
|
||||
if (loopPlugin.isEnabled(PluginBase.LOOP)) {
|
||||
reply = MainApp.sResources.getString(R.string.smscommunicator_loopisenabled);
|
||||
if (loopPlugin.isSuspended())
|
||||
reply = String.format(MainApp.sResources.getString(R.string.loopsuspendedfor), loopPlugin.minutesToEndOfSuspend());
|
||||
else
|
||||
reply = MainApp.sResources.getString(R.string.smscommunicator_loopisenabled);
|
||||
} else {
|
||||
reply = MainApp.sResources.getString(R.string.smscommunicator_loopisdisabled);
|
||||
}
|
||||
|
@ -283,6 +293,35 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
receivedSms.processed = true;
|
||||
Answers.getInstance().logCustom(new CustomEvent("SMS_Loop_Status"));
|
||||
break;
|
||||
case "RESUME":
|
||||
final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
|
||||
activeloop.suspendTo(0);
|
||||
MainApp.bus().post(new EventRefreshGui(false));
|
||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_loopresumed));
|
||||
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
Answers.getInstance().logCustom(new CustomEvent("SMS_Loop_Resume"));
|
||||
break;
|
||||
case "SUSPEND":
|
||||
if (splited.length >= 3)
|
||||
duration = SafeParse.stringToInt(splited[2]);
|
||||
duration = Math.max(0, duration);
|
||||
duration = Math.min(180, duration);
|
||||
if (duration == 0) {
|
||||
reply = MainApp.sResources.getString(R.string.smscommunicator_wrongduration);
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
} else if (remoteCommandsAllowed) {
|
||||
passCode = generatePasscode();
|
||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_suspendreplywithcode), duration, passCode);
|
||||
receivedSms.processed = true;
|
||||
resetWaitingMessages();
|
||||
sendSMS(suspendWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode));
|
||||
suspendWaitingForConfirmation.duration = duration;
|
||||
Answers.getInstance().logCustom(new CustomEvent("SMS_Loop_Suspend"));
|
||||
} else {
|
||||
reply = MainApp.sResources.getString(R.string.smscommunicator_remotecommandnotallowed);
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "TREATMENTS":
|
||||
|
@ -328,7 +367,6 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
break;
|
||||
case "BASAL":
|
||||
if (splited.length > 1) {
|
||||
boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false);
|
||||
if (splited[1].toUpperCase().equals("CANCEL") || splited[1].toUpperCase().equals("STOP")) {
|
||||
if (remoteCommandsAllowed) {
|
||||
passCode = generatePasscode();
|
||||
|
@ -366,7 +404,6 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
} else if (splited.length > 1) {
|
||||
amount = SafeParse.stringToDouble(splited[1]);
|
||||
amount = MainApp.getConfigBuilder().applyBolusConstraints(amount);
|
||||
boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false);
|
||||
if (amount > 0d && remoteCommandsAllowed) {
|
||||
passCode = generatePasscode();
|
||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusreplywithcode), amount, passCode);
|
||||
|
@ -384,7 +421,6 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
case "CAL":
|
||||
if (splited.length > 1) {
|
||||
amount = SafeParse.stringToDouble(splited[1]);
|
||||
boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false);
|
||||
if (amount > 0d && remoteCommandsAllowed) {
|
||||
passCode = generatePasscode();
|
||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_calibrationreplywithcode), amount, passCode);
|
||||
|
@ -409,12 +445,14 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
PumpEnactResult result = pumpInterface.deliverTreatment(bolusWaitingForConfirmation.bolusRequested, 0, null);
|
||||
if (result.success) {
|
||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusdelivered), result.bolusDelivered);
|
||||
if (danaRPlugin != null) reply += "\n" + danaRPlugin.shortStatus(true);
|
||||
if (danaRPlugin != null)
|
||||
reply += "\n" + danaRPlugin.shortStatus(true);
|
||||
lastRemoteBolusTime = new Date();
|
||||
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
} else {
|
||||
reply = MainApp.sResources.getString(R.string.smscommunicator_bolusfailed);
|
||||
if (danaRPlugin != null) reply += "\n" + danaRPlugin.shortStatus(true);
|
||||
if (danaRPlugin != null)
|
||||
reply += "\n" + danaRPlugin.shortStatus(true);
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
}
|
||||
}
|
||||
|
@ -427,11 +465,13 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
PumpEnactResult result = pumpInterface.setTempBasalAbsolute(tempBasalWaitingForConfirmation.tempBasal, 30);
|
||||
if (result.success) {
|
||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_tempbasalset), result.absolute, result.duration);
|
||||
if (danaRPlugin != null) reply += "\n" + danaRPlugin.shortStatus(true);
|
||||
if (danaRPlugin != null)
|
||||
reply += "\n" + danaRPlugin.shortStatus(true);
|
||||
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
} else {
|
||||
reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalfailed);
|
||||
if (danaRPlugin != null) reply += "\n" + danaRPlugin.shortStatus(true);
|
||||
if (danaRPlugin != null)
|
||||
reply += "\n" + danaRPlugin.shortStatus(true);
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
}
|
||||
}
|
||||
|
@ -444,11 +484,13 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
PumpEnactResult result = pumpInterface.cancelTempBasal();
|
||||
if (result.success) {
|
||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_tempbasalcanceled));
|
||||
if (danaRPlugin != null) reply += "\n" + danaRPlugin.shortStatus(true);
|
||||
if (danaRPlugin != null)
|
||||
reply += "\n" + danaRPlugin.shortStatus(true);
|
||||
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
} else {
|
||||
reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalcancelfailed);
|
||||
if (danaRPlugin != null) reply += "\n" + danaRPlugin.shortStatus(true);
|
||||
if (danaRPlugin != null)
|
||||
reply += "\n" + danaRPlugin.shortStatus(true);
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
}
|
||||
}
|
||||
|
@ -463,6 +505,14 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
reply = MainApp.sResources.getString(R.string.smscommunicator_calibrationfailed);
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
}
|
||||
} else if (suspendWaitingForConfirmation != null && !suspendWaitingForConfirmation.processed &&
|
||||
suspendWaitingForConfirmation.confirmCode.equals(splited[0]) && new Date().getTime() - suspendWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) {
|
||||
suspendWaitingForConfirmation.processed = true;
|
||||
final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
|
||||
activeloop.suspendTo(new Date().getTime() + suspendWaitingForConfirmation.duration * 60L * 1000);
|
||||
MainApp.bus().post(new EventRefreshGui(false));
|
||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_loopsuspended));
|
||||
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
} else {
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, MainApp.sResources.getString(R.string.smscommunicator_unknowncommand), new Date()));
|
||||
}
|
||||
|
@ -482,7 +532,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
}
|
||||
|
||||
public void sendSMSToAllNumbers(Sms sms) {
|
||||
for (String number: allowedNumbers) {
|
||||
for (String number : allowedNumbers) {
|
||||
sms.phoneNumber = number;
|
||||
sendSMS(sms);
|
||||
}
|
||||
|
@ -517,6 +567,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
cancelTempBasalWaitingForConfirmation = null;
|
||||
bolusWaitingForConfirmation = null;
|
||||
calibrationWaitingForConfirmation = null;
|
||||
suspendWaitingForConfirmation = null;
|
||||
}
|
||||
|
||||
public static String stripAccents(String s) {
|
||||
|
|
|
@ -526,4 +526,9 @@
|
|||
<string name="suspendloopfor2h">Pozastavit smyčku na 2 h</string>
|
||||
<string name="suspendloopfor3h">Pozastavit smyčku na 3 h</string>
|
||||
<string name="disableloop">Zakázat smyčku</string>
|
||||
<string name="smscommunicator_loopresumed">Smyčka obnovena</string>
|
||||
<string name="smscommunicator_loopsuspended">Smyčka pozastavena</string>
|
||||
<string name="smscommunicator_remotecommandnotallowed">Vzdálení příkaz není povolen</string>
|
||||
<string name="smscommunicator_suspendreplywithcode">K pozastavení smyčky na %d minut odpověz SMS s kódem %s</string>
|
||||
<string name="smscommunicator_wrongduration">Chybná doba trvání</string>
|
||||
</resources>
|
||||
|
|
|
@ -329,7 +329,9 @@
|
|||
<string name="openapsma_valuelimitedto" formatted="false">%.2f limited to %.2f</string>
|
||||
<string name="openapsma_valueoutofrange" formatted="false">Value %s is out of hard limits</string>
|
||||
<string name="smscommunicator_remotebasalnotallowed">Remote basal setting is not allowed</string>
|
||||
<string name="smscommunicator_remotecommandnotallowed">Remote command is not allowed</string>
|
||||
<string name="smscommunicator_basalreplywithcode" formatted="false">To start basal %.2fU/h reply with code %s</string>
|
||||
<string name="smscommunicator_suspendreplywithcode" formatted="false">To suspend loop for %d minutes reply with code %s</string>
|
||||
<string name="smscommunicator_tempbasalset" formatted="false">Temp basal %.2fU/h for %d min started successfully</string>
|
||||
<string name="smscommunicator_tempbasalfailed">Temp basal start failed</string>
|
||||
<string name="smscommunicator_basalstopreplywithcode" formatted="false">To stop temp basal reply with code %s</string>
|
||||
|
@ -572,4 +574,7 @@
|
|||
<string name="disconnectpumpfor3h">Disconnect pump for 3 h</string>
|
||||
<string name="disconnectpumpfor10h">Disconnect pump for 10 h</string>
|
||||
<string name="resume">Resume</string>
|
||||
<string name="smscommunicator_wrongduration">Wrong duration</string>
|
||||
<string name="smscommunicator_loopsuspended">Loop suspended</string>
|
||||
<string name="smscommunicator_loopresumed">Loop resumed</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue