diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java index 3ebdeaf414..9e06bbb600 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/Dialogs/CalibrationDialog.java @@ -23,7 +23,7 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.client.data.NSProfile; import info.nightscout.utils.PlusMinusEditText; -import info.nightscout.utils.XripCalibrations; +import info.nightscout.utils.XdripCalibrations; public class CalibrationDialog extends DialogFragment implements View.OnClickListener { private static Logger log = LoggerFactory.getLogger(CalibrationDialog.class); @@ -71,7 +71,7 @@ public class CalibrationDialog extends DialogFragment implements View.OnClickLis switch (view.getId()) { case R.id.overview_calibration_okbutton: final Double bg = bgText.getValue(); - XripCalibrations.confirmAndSendCalibration(bg, parentContext); + XdripCalibrations.confirmAndSendCalibration(bg, parentContext); dismiss(); break; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java index 7197eb99b2..8133350720 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SmsCommunicator/SmsCommunicatorPlugin.java @@ -38,6 +38,7 @@ import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventSmsCommuni import info.nightscout.client.data.NSProfile; import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.SafeParse; +import info.nightscout.utils.XdripCalibrations; /** * Created by mike on 05.08.2016. @@ -63,6 +64,7 @@ public class SmsCommunicatorPlugin implements PluginBase { String confirmCode; double bolusRequested = 0d; double tempBasal = 0d; + double calibrationRequested = 0d; public Sms(SmsMessage message) { phoneNumber = message.getOriginatingAddress(); @@ -94,6 +96,7 @@ public class SmsCommunicatorPlugin implements PluginBase { Sms cancelTempBasalWaitingForConfirmation = null; Sms tempBasalWaitingForConfirmation = null; Sms bolusWaitingForConfirmation = null; + Sms calibrationWaitingForConfirmation = null; Date lastRemoteBolusTime = new Date(0); ArrayList messages = new ArrayList<>(); @@ -121,7 +124,7 @@ public class SmsCommunicatorPlugin implements PluginBase { @Override public String getNameShort() { String name = MainApp.sResources.getString(R.string.smscommunicator_shortname); - if (!name.trim().isEmpty()){ + if (!name.trim().isEmpty()) { //only if translation exists return name; } @@ -366,6 +369,23 @@ public class SmsCommunicatorPlugin implements PluginBase { } } break; + case "CAL": + if (splited.length > 1) { + amount = SafeParse.stringToDouble(splited[1]); + boolean remoteCommandsAllowed = sharedPreferences.getBoolean("smscommunicator_remotecommandsallowed", false); + if (amount > 0d && remoteCommandsAllowed) { + passCode = generatePasscode(); + reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_calibrationreplywithcode), amount, passCode); + receivedSms.processed = true; + resetWaitingMessages(); + sendSMS(calibrationWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode)); + calibrationWaitingForConfirmation.calibrationRequested = amount; + } else { + reply = MainApp.sResources.getString(R.string.smscommunicator_remotecalibrationnotallowed); + sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); + } + } + break; default: // expect passCode here if (bolusWaitingForConfirmation != null && !bolusWaitingForConfirmation.processed && bolusWaitingForConfirmation.confirmCode.equals(splited[0]) && new Date().getTime() - bolusWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) { @@ -419,6 +439,17 @@ public class SmsCommunicatorPlugin implements PluginBase { sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); } } + } else if (calibrationWaitingForConfirmation != null && !calibrationWaitingForConfirmation.processed && + calibrationWaitingForConfirmation.confirmCode.equals(splited[0]) && new Date().getTime() - calibrationWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) { + calibrationWaitingForConfirmation.processed = true; + boolean result = XdripCalibrations.sendIntent(calibrationWaitingForConfirmation.calibrationRequested); + if (result) { + reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_calibrationsent)); + sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date())); + } else { + reply = MainApp.sResources.getString(R.string.smscommunicator_calibrationfailed); + sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date())); + } } else { sendSMS(new Sms(receivedSms.phoneNumber, MainApp.sResources.getString(R.string.smscommunicator_unknowncommand), new Date())); } @@ -471,6 +502,7 @@ public class SmsCommunicatorPlugin implements PluginBase { tempBasalWaitingForConfirmation = null; cancelTempBasalWaitingForConfirmation = null; bolusWaitingForConfirmation = null; + calibrationWaitingForConfirmation = null; } public static String stripAccents(String s) { diff --git a/app/src/main/java/info/nightscout/utils/XripCalibrations.java b/app/src/main/java/info/nightscout/utils/XdripCalibrations.java similarity index 91% rename from app/src/main/java/info/nightscout/utils/XripCalibrations.java rename to app/src/main/java/info/nightscout/utils/XdripCalibrations.java index 078a3e08b0..338304d790 100644 --- a/app/src/main/java/info/nightscout/utils/XripCalibrations.java +++ b/app/src/main/java/info/nightscout/utils/XdripCalibrations.java @@ -23,8 +23,8 @@ import info.nightscout.client.data.NSProfile; * Created by mike on 10.02.2017. */ -public class XripCalibrations { - private static Logger log = LoggerFactory.getLogger(XripCalibrations.class); +public class XdripCalibrations { + private static Logger log = LoggerFactory.getLogger(XdripCalibrations.class); public static void confirmAndSendCalibration(final Double bg, Context parentContext) { if (parentContext != null) { @@ -43,7 +43,7 @@ public class XripCalibrations { } } - private static boolean sendIntent(Double bg) { + public static boolean sendIntent(Double bg) { final NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); Context context = MainApp.instance().getApplicationContext(); @@ -62,6 +62,7 @@ public class XripCalibrations { return false; } else { ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.calibrationsent)); + log.debug(MainApp.sResources.getString(R.string.calibrationsent)); return true; } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 816b74c648..5e95e021ca 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -253,6 +253,7 @@ Allowed phone numbers +XXXXXXXXXX;+YYYYYYYYYY To deliver bolus %.2fU reply with code %s + To send calibration %.2fU reply with code %s Bolus failed Bolus %.2fU delivered successfully Bolus %.2fU delivered successfully @@ -484,4 +485,7 @@ Send calibration %.1f to xDrip? xDrip+ not installed Calibration sent to xDrip + Remote calibration not allowed + Calibration sent + xDrip is not receiving calibrations diff --git a/wear/wear.iml b/wear/wear.iml index 3128c10a22..02e7cacb1f 100644 --- a/wear/wear.iml +++ b/wear/wear.iml @@ -106,14 +106,6 @@ - - - - - - - - @@ -122,6 +114,15 @@ + + + + + + + + + @@ -134,10 +135,14 @@ + + + +