SMS code cleanup
This commit is contained in:
parent
53721d5d2c
commit
f30f4cbee2
|
@ -4,6 +4,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
|
|
||||||
|
@ -17,11 +18,13 @@ class AuthRequest {
|
||||||
private long date;
|
private long date;
|
||||||
|
|
||||||
private boolean processed;
|
private boolean processed;
|
||||||
|
private SmsCommunicatorPlugin plugin;
|
||||||
|
|
||||||
AuthRequest(SmsCommunicatorPlugin plugin, Sms requester, String requestText, String confirmCode, SmsAction action) {
|
AuthRequest(SmsCommunicatorPlugin plugin, Sms requester, String requestText, String confirmCode, SmsAction action) {
|
||||||
this.requester = requester;
|
this.requester = requester;
|
||||||
this.confirmCode = confirmCode;
|
this.confirmCode = confirmCode;
|
||||||
this.action = action;
|
this.action = action;
|
||||||
|
this.plugin = plugin;
|
||||||
|
|
||||||
this.date = DateUtil.now();
|
this.date = DateUtil.now();
|
||||||
|
|
||||||
|
@ -37,6 +40,7 @@ class AuthRequest {
|
||||||
if (!confirmCode.equals(codeReceived)) {
|
if (!confirmCode.equals(codeReceived)) {
|
||||||
if (L.isEnabled(L.SMS))
|
if (L.isEnabled(L.SMS))
|
||||||
log.debug("Wrong code");
|
log.debug("Wrong code");
|
||||||
|
plugin.sendSMS(new Sms(requester.phoneNumber, R.string.sms_wrongcode));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (DateUtil.now() - date < Constants.SMS_CONFIRM_TIMEOUT) {
|
if (DateUtil.now() - date < Constants.SMS_CONFIRM_TIMEOUT) {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.general.smsCommunicator;
|
||||||
|
|
||||||
import android.telephony.SmsMessage;
|
import android.telephony.SmsMessage;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
|
|
||||||
class Sms {
|
class Sms {
|
||||||
|
@ -27,6 +28,13 @@ class Sms {
|
||||||
sent = true;
|
sent = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Sms(String phoneNumber, int textId) {
|
||||||
|
this.phoneNumber = phoneNumber;
|
||||||
|
this.text = MainApp.gs(textId);
|
||||||
|
this.date = DateUtil.now();
|
||||||
|
sent = true;
|
||||||
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "SMS from " + phoneNumber + ": " + text;
|
return "SMS from " + phoneNumber + ": " + text;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ import info.nightscout.androidaps.plugins.general.smsCommunicator.events.EventSm
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.queue.Callback;
|
import info.nightscout.androidaps.queue.Callback;
|
||||||
import info.nightscout.androidaps.services.Intents;
|
import info.nightscout.androidaps.services.Intents;
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
import info.nightscout.androidaps.utils.SafeParse;
|
import info.nightscout.androidaps.utils.SafeParse;
|
||||||
|
@ -149,21 +150,99 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String reply = "";
|
|
||||||
|
|
||||||
messages.add(receivedSms);
|
messages.add(receivedSms);
|
||||||
log.debug(receivedSms.toString());
|
log.debug(receivedSms.toString());
|
||||||
|
|
||||||
String[] splited = receivedSms.text.split("\\s+");
|
String[] splitted = receivedSms.text.split("\\s+");
|
||||||
String passCode;
|
|
||||||
boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false);
|
boolean remoteCommandsAllowed = SP.getBoolean(R.string.key_smscommunicator_remotecommandsallowed, false);
|
||||||
|
|
||||||
if (splited.length > 0) {
|
if (splitted.length > 0) {
|
||||||
switch (splited[0].toUpperCase()) {
|
switch (splitted[0].toUpperCase()) {
|
||||||
case "BG":
|
case "BG":
|
||||||
|
processBG(splitted, receivedSms);
|
||||||
|
break;
|
||||||
|
case "LOOP":
|
||||||
|
if (!remoteCommandsAllowed)
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed));
|
||||||
|
else if (splitted.length == 2)
|
||||||
|
processLOOP(splitted, receivedSms);
|
||||||
|
else
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
|
break;
|
||||||
|
case "TREATMENTS":
|
||||||
|
if (splitted.length == 2)
|
||||||
|
processTREATMENTS(splitted, receivedSms);
|
||||||
|
else
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
|
break;
|
||||||
|
case "NSCLIENT":
|
||||||
|
if (splitted.length == 2)
|
||||||
|
processNSCLIENT(splitted, receivedSms);
|
||||||
|
else
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
|
break;
|
||||||
|
case "PUMP":
|
||||||
|
processPUMP(splitted, receivedSms);
|
||||||
|
break;
|
||||||
|
case "BASAL":
|
||||||
|
if (!remoteCommandsAllowed)
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed));
|
||||||
|
else if (splitted.length == 2 || splitted.length == 3)
|
||||||
|
processBASAL(splitted, receivedSms);
|
||||||
|
else
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
|
break;
|
||||||
|
case "EXTENDED":
|
||||||
|
if (!remoteCommandsAllowed)
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed));
|
||||||
|
else if (splitted.length == 3)
|
||||||
|
processEXTENDED(splitted, receivedSms);
|
||||||
|
else
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
|
break;
|
||||||
|
case "BOLUS":
|
||||||
|
if (!remoteCommandsAllowed)
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed));
|
||||||
|
else if (DateUtil.now() - lastRemoteBolusTime.getTime() < Constants.remoteBolusMinDistance)
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotebolusnotallowed));
|
||||||
|
else if (ConfigBuilderPlugin.getPlugin().getActivePump().isSuspended())
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.pumpsuspended));
|
||||||
|
else if (splitted.length == 2)
|
||||||
|
processBOLUS(splitted, receivedSms);
|
||||||
|
else
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
|
break;
|
||||||
|
case "CAL":
|
||||||
|
if (!remoteCommandsAllowed)
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_remotecommandnotallowed));
|
||||||
|
else if (splitted.length == 2)
|
||||||
|
processCAL(splitted, receivedSms);
|
||||||
|
else
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
|
break;
|
||||||
|
default: // expect passCode here
|
||||||
|
//noinspection StatementWithEmptyBody
|
||||||
|
if (!Character.isLetter(splitted[0].charAt(0))) {
|
||||||
|
// user text .... ignore
|
||||||
|
} else if (messageToConfirm != null) {
|
||||||
|
messageToConfirm.action(splitted[0]);
|
||||||
|
messageToConfirm = null;
|
||||||
|
} else
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, MainApp.gs(R.string.smscommunicator_unknowncommand)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MainApp.bus().post(new EventSmsCommunicatorUpdateGui());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private void processBG(String[] splitted, Sms receivedSms) {
|
||||||
BgReading actualBG = DatabaseHelper.actualBg();
|
BgReading actualBG = DatabaseHelper.actualBg();
|
||||||
BgReading lastBG = DatabaseHelper.lastBg();
|
BgReading lastBG = DatabaseHelper.lastBg();
|
||||||
|
|
||||||
|
String reply = "";
|
||||||
|
|
||||||
String units = ProfileFunctions.getInstance().getProfileUnits();
|
String units = ProfileFunctions.getInstance().getProfileUnits();
|
||||||
|
|
||||||
if (actualBG != null) {
|
if (actualBG != null) {
|
||||||
|
@ -188,10 +267,11 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
|
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
||||||
receivedSms.processed = true;
|
receivedSms.processed = true;
|
||||||
break;
|
}
|
||||||
case "LOOP":
|
|
||||||
if (splited.length > 1)
|
private void processLOOP(String[] splitted, Sms receivedSms) {
|
||||||
switch (splited[1].toUpperCase()) {
|
String reply;
|
||||||
|
switch (splitted[1].toUpperCase()) {
|
||||||
case "DISABLE":
|
case "DISABLE":
|
||||||
case "STOP":
|
case "STOP":
|
||||||
LoopPlugin loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class);
|
LoopPlugin loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class);
|
||||||
|
@ -214,8 +294,7 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class);
|
loopPlugin = MainApp.getSpecificPlugin(LoopPlugin.class);
|
||||||
if (loopPlugin != null && !loopPlugin.isEnabled(PluginType.LOOP)) {
|
if (loopPlugin != null && !loopPlugin.isEnabled(PluginType.LOOP)) {
|
||||||
loopPlugin.setPluginEnabled(PluginType.LOOP, true);
|
loopPlugin.setPluginEnabled(PluginType.LOOP, true);
|
||||||
reply = MainApp.gs(R.string.smscommunicator_loophasbeenenabled);
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_loophasbeenenabled));
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
|
||||||
MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_START"));
|
MainApp.bus().post(new EventRefreshOverview("SMS_LOOP_START"));
|
||||||
}
|
}
|
||||||
receivedSms.processed = true;
|
receivedSms.processed = true;
|
||||||
|
@ -244,15 +323,15 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
break;
|
break;
|
||||||
case "SUSPEND":
|
case "SUSPEND":
|
||||||
int duration = 0;
|
int duration = 0;
|
||||||
if (splited.length >= 3)
|
if (splitted.length >= 3)
|
||||||
duration = SafeParse.stringToInt(splited[2]);
|
duration = SafeParse.stringToInt(splitted[2]);
|
||||||
duration = Math.max(0, duration);
|
duration = Math.max(0, duration);
|
||||||
duration = Math.min(180, duration);
|
duration = Math.min(180, duration);
|
||||||
if (duration == 0) {
|
if (duration == 0) {
|
||||||
reply = MainApp.gs(R.string.smscommunicator_wrongduration);
|
reply = MainApp.gs(R.string.smscommunicator_wrongduration);
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
||||||
} else if (remoteCommandsAllowed) {
|
} else {
|
||||||
passCode = generatePasscode();
|
String passCode = generatePasscode();
|
||||||
reply = String.format(MainApp.gs(R.string.smscommunicator_suspendreplywithcode), duration, passCode);
|
reply = String.format(MainApp.gs(R.string.smscommunicator_suspendreplywithcode), duration, passCode);
|
||||||
receivedSms.processed = true;
|
receivedSms.processed = true;
|
||||||
messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(duration) {
|
messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(duration) {
|
||||||
|
@ -278,42 +357,40 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
|
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case "TREATMENTS":
|
|
||||||
if (splited.length > 1)
|
private void processTREATMENTS(String[] splitted, Sms receivedSms) {
|
||||||
switch (splited[1].toUpperCase()) {
|
if (splitted[1].toUpperCase().equals("REFRESH")) {
|
||||||
case "REFRESH":
|
|
||||||
Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
|
Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
|
||||||
TreatmentsPlugin.getPlugin().getService().resetTreatments();
|
TreatmentsPlugin.getPlugin().getService().resetTreatments();
|
||||||
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
|
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
|
||||||
List<ResolveInfo> q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0);
|
List<ResolveInfo> q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0);
|
||||||
reply = "TERATMENTS REFRESH " + q.size() + " receivers";
|
String reply = "TREATMENTS REFRESH " + q.size() + " receivers";
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
||||||
receivedSms.processed = true;
|
receivedSms.processed = true;
|
||||||
break;
|
} else
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case "NSCLIENT":
|
private void processNSCLIENT(String[] splitted, Sms receivedSms) {
|
||||||
if (splited.length > 1)
|
if (splitted[2].toUpperCase().equals("RESTART")) {
|
||||||
switch (splited[1].toUpperCase()) {
|
|
||||||
case "RESTART":
|
|
||||||
Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
|
Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
|
||||||
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
|
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
|
||||||
List<ResolveInfo> q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0);
|
List<ResolveInfo> q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0);
|
||||||
reply = "NSCLIENT RESTART " + q.size() + " receivers";
|
String reply = "NSCLIENT RESTART " + q.size() + " receivers";
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
||||||
receivedSms.processed = true;
|
receivedSms.processed = true;
|
||||||
break;
|
} else
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case "PUMP":
|
@SuppressWarnings("unused")
|
||||||
case "DANAR":
|
private void processPUMP(String[] splitted, Sms receivedSms) {
|
||||||
ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("SMS", new Callback() {
|
ConfigBuilderPlugin.getPlugin().getCommandQueue().readStatus("SMS", new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -330,13 +407,12 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
receivedSms.processed = true;
|
receivedSms.processed = true;
|
||||||
break;
|
}
|
||||||
case "BASAL":
|
|
||||||
if (splited.length > 1) {
|
private void processBASAL(String[] splitted, Sms receivedSms) {
|
||||||
if (splited[1].toUpperCase().equals("CANCEL") || splited[1].toUpperCase().equals("STOP")) {
|
if (splitted[1].toUpperCase().equals("CANCEL") || splitted[1].toUpperCase().equals("STOP")) {
|
||||||
if (remoteCommandsAllowed) {
|
String passCode = generatePasscode();
|
||||||
passCode = generatePasscode();
|
String reply = String.format(MainApp.gs(R.string.smscommunicator_basalstopreplywithcode), passCode);
|
||||||
reply = String.format(MainApp.gs(R.string.smscommunicator_basalstopreplywithcode), passCode);
|
|
||||||
receivedSms.processed = true;
|
receivedSms.processed = true;
|
||||||
messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction() {
|
messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -357,33 +433,27 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else if (splitted[1].endsWith("%")) {
|
||||||
reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
|
int tempBasalPct = SafeParse.stringToInt(StringUtils.removeEnd(splitted[1], "%"));
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
|
||||||
}
|
|
||||||
} else if (splited[1].endsWith("%")) {
|
|
||||||
int tempBasalPct = SafeParse.stringToInt(StringUtils.removeEnd(splited[1], "%"));
|
|
||||||
int duration = 30;
|
int duration = 30;
|
||||||
if (splited.length > 2)
|
if (splitted.length > 2)
|
||||||
duration = SafeParse.stringToInt(splited[2]);
|
duration = SafeParse.stringToInt(splitted[2]);
|
||||||
Profile profile = ProfileFunctions.getInstance().getProfile();
|
final Profile profile = ProfileFunctions.getInstance().getProfile();
|
||||||
if (profile == null) {
|
|
||||||
reply = MainApp.gs(R.string.noprofile);
|
if (profile == null)
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.noprofile));
|
||||||
} else if (tempBasalPct == 0 && !splited[1].equals("0%")) {
|
else if (tempBasalPct == 0 && !splitted[1].equals("0%"))
|
||||||
reply = MainApp.gs(R.string.wrongformat);
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
else if (duration == 0)
|
||||||
} else {
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
|
else {
|
||||||
tempBasalPct = MainApp.getConstraintChecker().applyBasalPercentConstraints(new Constraint<>(tempBasalPct), profile).value();
|
tempBasalPct = MainApp.getConstraintChecker().applyBasalPercentConstraints(new Constraint<>(tempBasalPct), profile).value();
|
||||||
if (remoteCommandsAllowed) {
|
String passCode = generatePasscode();
|
||||||
passCode = generatePasscode();
|
String reply = String.format(MainApp.gs(R.string.smscommunicator_basalpctreplywithcode), tempBasalPct, passCode);
|
||||||
reply = String.format(MainApp.gs(R.string.smscommunicator_basalpctreplywithcode), tempBasalPct, passCode);
|
|
||||||
receivedSms.processed = true;
|
receivedSms.processed = true;
|
||||||
messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(tempBasalPct, duration) {
|
messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(tempBasalPct, duration) {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Profile profile = ProfileFunctions.getInstance().getProfile();
|
|
||||||
if (profile != null)
|
|
||||||
ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalPercent(anInteger, secondInteger, true, profile, new Callback() {
|
ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalPercent(anInteger, secondInteger, true, profile, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -404,31 +474,27 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
|
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Double tempBasal = SafeParse.stringToDouble(splited[1]);
|
Double tempBasal = SafeParse.stringToDouble(splitted[1]);
|
||||||
int duration = 30;
|
int duration = 30;
|
||||||
if (splited.length > 2)
|
if (splitted.length > 2)
|
||||||
duration = SafeParse.stringToInt(splited[2]);
|
duration = SafeParse.stringToInt(splitted[2]);
|
||||||
Profile profile = ProfileFunctions.getInstance().getProfile();
|
final Profile profile = ProfileFunctions.getInstance().getProfile();
|
||||||
if (profile == null) {
|
if (profile == null)
|
||||||
reply = MainApp.gs(R.string.noprofile);
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.noprofile));
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
else if (tempBasal == 0 && !splitted[1].equals("0"))
|
||||||
} else {
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
|
else if (duration == 0)
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
|
else {
|
||||||
tempBasal = MainApp.getConstraintChecker().applyBasalConstraints(new Constraint<>(tempBasal), profile).value();
|
tempBasal = MainApp.getConstraintChecker().applyBasalConstraints(new Constraint<>(tempBasal), profile).value();
|
||||||
if (remoteCommandsAllowed) {
|
String passCode = generatePasscode();
|
||||||
passCode = generatePasscode();
|
String reply = String.format(MainApp.gs(R.string.smscommunicator_basalreplywithcode), tempBasal, passCode);
|
||||||
reply = String.format(MainApp.gs(R.string.smscommunicator_basalreplywithcode), tempBasal, passCode);
|
|
||||||
receivedSms.processed = true;
|
receivedSms.processed = true;
|
||||||
messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(tempBasal, duration) {
|
messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(tempBasal, duration) {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Profile profile = ProfileFunctions.getInstance().getProfile();
|
|
||||||
if (profile != null)
|
|
||||||
ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalAbsolute(aDouble, secondInteger, true, profile, new Callback() {
|
ConfigBuilderPlugin.getPlugin().getCommandQueue().tempBasalAbsolute(aDouble, secondInteger, true, profile, new Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -449,20 +515,14 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
|
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
private void processEXTENDED(String[] splitted, Sms receivedSms) {
|
||||||
case "EXTENDED":
|
if (splitted[1].toUpperCase().equals("CANCEL") || splitted[1].toUpperCase().equals("STOP")) {
|
||||||
if (splited.length > 1) {
|
String passCode = generatePasscode();
|
||||||
if (splited[1].toUpperCase().equals("CANCEL") || splited[1].toUpperCase().equals("STOP")) {
|
String reply = String.format(MainApp.gs(R.string.smscommunicator_extendedstopreplywithcode), passCode);
|
||||||
if (remoteCommandsAllowed) {
|
|
||||||
passCode = generatePasscode();
|
|
||||||
reply = String.format(MainApp.gs(R.string.smscommunicator_extendedstopreplywithcode), passCode);
|
|
||||||
receivedSms.processed = true;
|
receivedSms.processed = true;
|
||||||
messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction() {
|
messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -484,20 +544,14 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
|
Double extended = SafeParse.stringToDouble(splitted[1]);
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
int duration = SafeParse.stringToInt(splitted[2]);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (splited.length < 3) {
|
|
||||||
reply = MainApp.gs(R.string.wrongformat);
|
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
|
||||||
} else {
|
|
||||||
Double extended = SafeParse.stringToDouble(splited[1]);
|
|
||||||
int duration = SafeParse.stringToInt(splited[2]);
|
|
||||||
extended = MainApp.getConstraintChecker().applyExtendedBolusConstraints(new Constraint<>(extended)).value();
|
extended = MainApp.getConstraintChecker().applyExtendedBolusConstraints(new Constraint<>(extended)).value();
|
||||||
if (remoteCommandsAllowed) {
|
if (extended == 0 || duration == 0)
|
||||||
passCode = generatePasscode();
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
reply = String.format(MainApp.gs(R.string.smscommunicator_extendedreplywithcode), extended, duration, passCode);
|
else {
|
||||||
|
String passCode = generatePasscode();
|
||||||
|
String reply = String.format(MainApp.gs(R.string.smscommunicator_extendedreplywithcode), extended, duration, passCode);
|
||||||
receivedSms.processed = true;
|
receivedSms.processed = true;
|
||||||
messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(extended, duration) {
|
messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(extended, duration) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -518,27 +572,17 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
|
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "BOLUS":
|
private void processBOLUS(String[] splitted, Sms receivedSms) {
|
||||||
if (System.currentTimeMillis() - lastRemoteBolusTime.getTime() < Constants.remoteBolusMinDistance) {
|
Double bolus = SafeParse.stringToDouble(splitted[1]);
|
||||||
reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
|
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
|
||||||
} else if (ConfigBuilderPlugin.getPlugin().getActivePump().isSuspended()) {
|
|
||||||
reply = MainApp.gs(R.string.pumpsuspended);
|
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
|
||||||
} else if (splited.length > 1) {
|
|
||||||
Double bolus = SafeParse.stringToDouble(splited[1]);
|
|
||||||
bolus = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(bolus)).value();
|
bolus = MainApp.getConstraintChecker().applyBolusConstraints(new Constraint<>(bolus)).value();
|
||||||
if (bolus > 0d && remoteCommandsAllowed) {
|
if (bolus > 0d) {
|
||||||
passCode = generatePasscode();
|
String passCode = generatePasscode();
|
||||||
reply = String.format(MainApp.gs(R.string.smscommunicator_bolusreplywithcode), bolus, passCode);
|
String reply = String.format(MainApp.gs(R.string.smscommunicator_bolusreplywithcode), bolus, passCode);
|
||||||
receivedSms.processed = true;
|
receivedSms.processed = true;
|
||||||
messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(bolus) {
|
messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction(bolus) {
|
||||||
@Override
|
@Override
|
||||||
|
@ -568,52 +612,28 @@ public class SmsCommunicatorPlugin extends PluginBase {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else
|
||||||
reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
private void processCAL(String[] splitted, Sms receivedSms) {
|
||||||
case "CAL":
|
Double cal = SafeParse.stringToDouble(splitted[1]);
|
||||||
if (splited.length > 1) {
|
if (cal > 0d) {
|
||||||
Double cal = SafeParse.stringToDouble(splited[1]);
|
String passCode = generatePasscode();
|
||||||
if (cal > 0d && remoteCommandsAllowed) {
|
String reply = String.format(MainApp.gs(R.string.smscommunicator_calibrationreplywithcode), cal, passCode);
|
||||||
passCode = generatePasscode();
|
|
||||||
reply = String.format(MainApp.gs(R.string.smscommunicator_calibrationreplywithcode), cal, passCode);
|
|
||||||
receivedSms.processed = true;
|
receivedSms.processed = true;
|
||||||
messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction() {
|
messageToConfirm = new AuthRequest(this, receivedSms, reply, passCode, new SmsAction() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
boolean result = XdripCalibrations.sendIntent(aDouble);
|
boolean result = XdripCalibrations.sendIntent(aDouble);
|
||||||
if (result) {
|
if (result)
|
||||||
String reply = MainApp.gs(R.string.smscommunicator_calibrationsent);
|
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_calibrationsent));
|
||||||
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply));
|
else
|
||||||
} else {
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.smscommunicator_calibrationfailed));
|
||||||
String reply = MainApp.gs(R.string.smscommunicator_calibrationfailed);
|
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else
|
||||||
reply = MainApp.gs(R.string.smscommunicator_remotecommandnotallowed);
|
sendSMS(new Sms(receivedSms.phoneNumber, R.string.wrongformat));
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, reply));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default: // expect passCode here
|
|
||||||
if (!Character.isLetter(splited[0].charAt(0))) {
|
|
||||||
// user text .... ignore
|
|
||||||
} else if (messageToConfirm != null) {
|
|
||||||
messageToConfirm.action(splited[0]);
|
|
||||||
messageToConfirm = null;
|
|
||||||
} else {
|
|
||||||
sendSMS(new Sms(receivedSms.phoneNumber, MainApp.gs(R.string.smscommunicator_unknowncommand)));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MainApp.bus().post(new EventSmsCommunicatorUpdateGui());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendNotificationToAllNumbers(String text) {
|
public void sendNotificationToAllNumbers(String text) {
|
||||||
|
|
|
@ -366,6 +366,7 @@
|
||||||
<string name="valuelimitedto">%1$.2f limited to %2$.2f</string>
|
<string name="valuelimitedto">%1$.2f limited to %2$.2f</string>
|
||||||
<string name="valueoutofrange" formatted="false">Value %s is out of hard limits</string>
|
<string name="valueoutofrange" formatted="false">Value %s is out of hard limits</string>
|
||||||
<string name="smscommunicator_remotecommandnotallowed">Remote command is not allowed</string>
|
<string name="smscommunicator_remotecommandnotallowed">Remote command is not allowed</string>
|
||||||
|
<string name="smscommunicator_remotebolusnotallowed">Remote bolus not available. Try again later.</string>
|
||||||
<string name="smscommunicator_basalreplywithcode">To start basal %1$.2fU/h reply with code %2$s</string>
|
<string name="smscommunicator_basalreplywithcode">To start basal %1$.2fU/h reply with code %2$s</string>
|
||||||
<string name="smscommunicator_extendedreplywithcode">To start extended bolus %1$.2fU for %2$d min reply with code %3$s</string>
|
<string name="smscommunicator_extendedreplywithcode">To start extended bolus %1$.2fU for %2$d min reply with code %3$s</string>
|
||||||
<string name="smscommunicator_basalpctreplywithcode">To start basal %1$d%% reply with code %2$s</string>
|
<string name="smscommunicator_basalpctreplywithcode">To start basal %1$d%% reply with code %2$s</string>
|
||||||
|
@ -1320,6 +1321,7 @@
|
||||||
<string name="storage">internal storage constraint</string>
|
<string name="storage">internal storage constraint</string>
|
||||||
<string name="diskfull">Free at least %1$d MB from internal storage! Loop disabled!</string>
|
<string name="diskfull">Free at least %1$d MB from internal storage! Loop disabled!</string>
|
||||||
<string name="wrongformat">Wrong format</string>
|
<string name="wrongformat">Wrong format</string>
|
||||||
|
<string name="sms_wrongcode">Wrong code. Command cancelled.</string>
|
||||||
<plurals name="objective_days">
|
<plurals name="objective_days">
|
||||||
<item quantity="one">%1$d day</item>
|
<item quantity="one">%1$d day</item>
|
||||||
<item quantity="other">%1$d days</item>
|
<item quantity="other">%1$d days</item>
|
||||||
|
|
Loading…
Reference in a new issue