sms calibrations

This commit is contained in:
Milos Kozak 2017-02-10 21:20:55 +01:00
parent 83667be8cc
commit 2e40c7b605
5 changed files with 56 additions and 14 deletions

View file

@ -23,7 +23,7 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.client.data.NSProfile; import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.PlusMinusEditText; import info.nightscout.utils.PlusMinusEditText;
import info.nightscout.utils.XripCalibrations; import info.nightscout.utils.XdripCalibrations;
public class CalibrationDialog extends DialogFragment implements View.OnClickListener { public class CalibrationDialog extends DialogFragment implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(CalibrationDialog.class); private static Logger log = LoggerFactory.getLogger(CalibrationDialog.class);
@ -71,7 +71,7 @@ public class CalibrationDialog extends DialogFragment implements View.OnClickLis
switch (view.getId()) { switch (view.getId()) {
case R.id.overview_calibration_okbutton: case R.id.overview_calibration_okbutton:
final Double bg = bgText.getValue(); final Double bg = bgText.getValue();
XripCalibrations.confirmAndSendCalibration(bg, parentContext); XdripCalibrations.confirmAndSendCalibration(bg, parentContext);
dismiss(); dismiss();
break; break;
} }

View file

@ -38,6 +38,7 @@ import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventSmsCommuni
import info.nightscout.client.data.NSProfile; import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.SafeParse; import info.nightscout.utils.SafeParse;
import info.nightscout.utils.XdripCalibrations;
/** /**
* Created by mike on 05.08.2016. * Created by mike on 05.08.2016.
@ -63,6 +64,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
String confirmCode; String confirmCode;
double bolusRequested = 0d; double bolusRequested = 0d;
double tempBasal = 0d; double tempBasal = 0d;
double calibrationRequested = 0d;
public Sms(SmsMessage message) { public Sms(SmsMessage message) {
phoneNumber = message.getOriginatingAddress(); phoneNumber = message.getOriginatingAddress();
@ -94,6 +96,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
Sms cancelTempBasalWaitingForConfirmation = null; Sms cancelTempBasalWaitingForConfirmation = null;
Sms tempBasalWaitingForConfirmation = null; Sms tempBasalWaitingForConfirmation = null;
Sms bolusWaitingForConfirmation = null; Sms bolusWaitingForConfirmation = null;
Sms calibrationWaitingForConfirmation = null;
Date lastRemoteBolusTime = new Date(0); Date lastRemoteBolusTime = new Date(0);
ArrayList<Sms> messages = new ArrayList<>(); ArrayList<Sms> messages = new ArrayList<>();
@ -121,7 +124,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
@Override @Override
public String getNameShort() { public String getNameShort() {
String name = MainApp.sResources.getString(R.string.smscommunicator_shortname); String name = MainApp.sResources.getString(R.string.smscommunicator_shortname);
if (!name.trim().isEmpty()){ if (!name.trim().isEmpty()) {
//only if translation exists //only if translation exists
return name; return name;
} }
@ -366,6 +369,23 @@ public class SmsCommunicatorPlugin implements PluginBase {
} }
} }
break; 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 default: // expect passCode here
if (bolusWaitingForConfirmation != null && !bolusWaitingForConfirmation.processed && if (bolusWaitingForConfirmation != null && !bolusWaitingForConfirmation.processed &&
bolusWaitingForConfirmation.confirmCode.equals(splited[0]) && new Date().getTime() - bolusWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) { 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())); 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 { } else {
sendSMS(new Sms(receivedSms.phoneNumber, MainApp.sResources.getString(R.string.smscommunicator_unknowncommand), new Date())); 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; tempBasalWaitingForConfirmation = null;
cancelTempBasalWaitingForConfirmation = null; cancelTempBasalWaitingForConfirmation = null;
bolusWaitingForConfirmation = null; bolusWaitingForConfirmation = null;
calibrationWaitingForConfirmation = null;
} }
public static String stripAccents(String s) { public static String stripAccents(String s) {

View file

@ -23,8 +23,8 @@ import info.nightscout.client.data.NSProfile;
* Created by mike on 10.02.2017. * Created by mike on 10.02.2017.
*/ */
public class XripCalibrations { public class XdripCalibrations {
private static Logger log = LoggerFactory.getLogger(XripCalibrations.class); private static Logger log = LoggerFactory.getLogger(XdripCalibrations.class);
public static void confirmAndSendCalibration(final Double bg, Context parentContext) { public static void confirmAndSendCalibration(final Double bg, Context parentContext) {
if (parentContext != null) { 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(); final NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
Context context = MainApp.instance().getApplicationContext(); Context context = MainApp.instance().getApplicationContext();
@ -62,6 +62,7 @@ public class XripCalibrations {
return false; return false;
} else { } else {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.calibrationsent)); ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.sResources.getString(R.string.calibrationsent));
log.debug(MainApp.sResources.getString(R.string.calibrationsent));
return true; return true;
} }
} }

View file

@ -253,6 +253,7 @@
<string name="smscommunicator_allowednumbers">Allowed phone numbers</string> <string name="smscommunicator_allowednumbers">Allowed phone numbers</string>
<string name="smscommunicator_allowednumbers_summary">+XXXXXXXXXX;+YYYYYYYYYY</string> <string name="smscommunicator_allowednumbers_summary">+XXXXXXXXXX;+YYYYYYYYYY</string>
<string name="smscommunicator_bolusreplywithcode" formatted="false">To deliver bolus %.2fU reply with code %s</string> <string name="smscommunicator_bolusreplywithcode" formatted="false">To deliver bolus %.2fU reply with code %s</string>
<string name="smscommunicator_calibrationreplywithcode" formatted="false">To send calibration %.2fU reply with code %s</string>
<string name="smscommunicator_bolusfailed">Bolus failed</string> <string name="smscommunicator_bolusfailed">Bolus failed</string>
<string name="bolusdelivered" formatted="false">Bolus %.2fU delivered successfully</string> <string name="bolusdelivered" formatted="false">Bolus %.2fU delivered successfully</string>
<string name="smscommunicator_bolusdelivered" formatted="false">Bolus %.2fU delivered successfully</string> <string name="smscommunicator_bolusdelivered" formatted="false">Bolus %.2fU delivered successfully</string>
@ -484,4 +485,7 @@
<string name="send_calibration" formatted="false">Send calibration %.1f to xDrip?</string> <string name="send_calibration" formatted="false">Send calibration %.1f to xDrip?</string>
<string name="xdripnotinstalled">xDrip+ not installed</string> <string name="xdripnotinstalled">xDrip+ not installed</string>
<string name="calibrationsent">Calibration sent to xDrip</string> <string name="calibrationsent">Calibration sent to xDrip</string>
<string name="smscommunicator_remotecalibrationnotallowed">Remote calibration not allowed</string>
<string name="smscommunicator_calibrationsent">Calibration sent</string>
<string name="smscommunicator_calibrationfailed">xDrip is not receiving calibrations</string>
</resources> </resources>

View file

@ -106,14 +106,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" /> <sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
@ -122,6 +114,15 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
@ -134,10 +135,14 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/ustwo-clockwise-debug/jars" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/ustwo-clockwise-debug/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" /> <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" /> <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content> </content>