upload OpenAPS Offline
This commit is contained in:
parent
d313df0d19
commit
cd16b71759
|
@ -928,6 +928,28 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void uploadOpenAPSOffline(double durationInMinutes) {
|
||||||
|
try {
|
||||||
|
Context context = MainApp.instance().getApplicationContext();
|
||||||
|
JSONObject data = new JSONObject();
|
||||||
|
data.put("eventType", "OpenAPS Offline");
|
||||||
|
data.put("duration", durationInMinutes);
|
||||||
|
data.put("created_at", DateUtil.toISOString(new Date()));
|
||||||
|
data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString("action", "dbAdd");
|
||||||
|
bundle.putString("collection", "treatments");
|
||||||
|
bundle.putString("data", data.toString());
|
||||||
|
Intent intent = new Intent(Intents.ACTION_DATABASE);
|
||||||
|
intent.putExtras(bundle);
|
||||||
|
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||||
|
context.sendBroadcast(intent);
|
||||||
|
DbLogger.dbAdd(intent, data.toString(), ConfigBuilderPlugin.class);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void uploadTempBasalStartPercent(Integer percent, double durationInMinutes) {
|
public void uploadTempBasalStartPercent(Integer percent, double durationInMinutes) {
|
||||||
try {
|
try {
|
||||||
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||||
|
|
|
@ -352,18 +352,20 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
|
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
|
||||||
if (item.getTitle().equals(MainApp.sResources.getString(R.string.disableloop))) {
|
if (item.getTitle().equals(MainApp.sResources.getString(R.string.disableloop))) {
|
||||||
activeloop.setFragmentEnabled(PluginBase.LOOP, false);
|
activeloop.setFragmentEnabled(PluginBase.LOOP, false);
|
||||||
activeloop.setFragmentVisible(PluginBase.LOOP, false);
|
activeloop.setFragmentVisible(PluginBase.LOOP, false);
|
||||||
MainApp.getConfigBuilder().storeSettings();
|
MainApp.getConfigBuilder().storeSettings();
|
||||||
scheduleUpdateGUI("suspendmenu");
|
scheduleUpdateGUI("suspendmenu");
|
||||||
|
ConfigBuilderPlugin.uploadOpenAPSOffline(60); // upload 60 min, we don;t know real duration
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.enableloop))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.enableloop))) {
|
||||||
activeloop.setFragmentEnabled(PluginBase.LOOP, true);
|
activeloop.setFragmentEnabled(PluginBase.LOOP, true);
|
||||||
activeloop.setFragmentVisible(PluginBase.LOOP, true);
|
activeloop.setFragmentVisible(PluginBase.LOOP, true);
|
||||||
MainApp.getConfigBuilder().storeSettings();
|
MainApp.getConfigBuilder().storeSettings();
|
||||||
scheduleUpdateGUI("suspendmenu");
|
scheduleUpdateGUI("suspendmenu");
|
||||||
|
ConfigBuilderPlugin.uploadOpenAPSOffline(0);
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.resume))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.resume))) {
|
||||||
activeloop.suspendTo(0L);
|
activeloop.suspendTo(0L);
|
||||||
|
@ -377,22 +379,27 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
ConfigBuilderPlugin.uploadOpenAPSOffline(0);
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor1h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor1h))) {
|
||||||
activeloop.suspendTo(new Date().getTime() + 60L * 60 * 1000);
|
activeloop.suspendTo(new Date().getTime() + 60L * 60 * 1000);
|
||||||
scheduleUpdateGUI("suspendmenu");
|
scheduleUpdateGUI("suspendmenu");
|
||||||
|
ConfigBuilderPlugin.uploadOpenAPSOffline(60);
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor2h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor2h))) {
|
||||||
activeloop.suspendTo(new Date().getTime() + 2 * 60L * 60 * 1000);
|
activeloop.suspendTo(new Date().getTime() + 2 * 60L * 60 * 1000);
|
||||||
scheduleUpdateGUI("suspendmenu");
|
scheduleUpdateGUI("suspendmenu");
|
||||||
|
ConfigBuilderPlugin.uploadOpenAPSOffline(120);
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor3h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor3h))) {
|
||||||
activeloop.suspendTo(new Date().getTime() + 3 * 60L * 60 * 1000);
|
activeloop.suspendTo(new Date().getTime() + 3 * 60L * 60 * 1000);
|
||||||
scheduleUpdateGUI("suspendmenu");
|
scheduleUpdateGUI("suspendmenu");
|
||||||
|
ConfigBuilderPlugin.uploadOpenAPSOffline(180);
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor10h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.suspendloopfor10h))) {
|
||||||
activeloop.suspendTo(new Date().getTime() + 10 * 60L * 60 * 1000);
|
activeloop.suspendTo(new Date().getTime() + 10 * 60L * 60 * 1000);
|
||||||
scheduleUpdateGUI("suspendmenu");
|
scheduleUpdateGUI("suspendmenu");
|
||||||
|
ConfigBuilderPlugin.uploadOpenAPSOffline(600);
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor30m))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor30m))) {
|
||||||
activeloop.suspendTo(new Date().getTime() + 30L * 60 * 1000);
|
activeloop.suspendTo(new Date().getTime() + 30L * 60 * 1000);
|
||||||
|
@ -406,6 +413,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
ConfigBuilderPlugin.uploadOpenAPSOffline(30);
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor1h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor1h))) {
|
||||||
activeloop.suspendTo(new Date().getTime() + 1 * 60L * 60 * 1000);
|
activeloop.suspendTo(new Date().getTime() + 1 * 60L * 60 * 1000);
|
||||||
|
@ -419,6 +427,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
ConfigBuilderPlugin.uploadOpenAPSOffline(60);
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor2h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor2h))) {
|
||||||
activeloop.suspendTo(new Date().getTime() + 2 * 60L * 60 * 1000);
|
activeloop.suspendTo(new Date().getTime() + 2 * 60L * 60 * 1000);
|
||||||
|
@ -432,6 +441,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
ConfigBuilderPlugin.uploadOpenAPSOffline(120);
|
||||||
return true;
|
return true;
|
||||||
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor3h))) {
|
} else if (item.getTitle().equals(MainApp.sResources.getString(R.string.disconnectpumpfor3h))) {
|
||||||
activeloop.suspendTo(new Date().getTime() + 3 * 60L * 60 * 1000);
|
activeloop.suspendTo(new Date().getTime() + 3 * 60L * 60 * 1000);
|
||||||
|
@ -445,6 +455,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
ConfigBuilderPlugin.uploadOpenAPSOffline(180);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
import info.nightscout.androidaps.plugins.PumpDanaRKorean.DanaRKoreanPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||||
|
@ -42,6 +43,8 @@ import info.nightscout.utils.SP;
|
||||||
import info.nightscout.utils.SafeParse;
|
import info.nightscout.utils.SafeParse;
|
||||||
import info.nightscout.utils.XdripCalibrations;
|
import info.nightscout.utils.XdripCalibrations;
|
||||||
|
|
||||||
|
import static info.nightscout.androidaps.R.string.profile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 05.08.2016.
|
* Created by mike on 05.08.2016.
|
||||||
*/
|
*/
|
||||||
|
@ -51,11 +54,11 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
private static boolean fragmentEnabled = false;
|
private static boolean fragmentEnabled = false;
|
||||||
private static boolean fragmentVisible = true;
|
private static boolean fragmentVisible = true;
|
||||||
|
|
||||||
final long CONFIRM_TIMEOUT = 5 * 60 * 1000L;
|
private final long CONFIRM_TIMEOUT = 5 * 60 * 1000L;
|
||||||
|
|
||||||
List<String> allowedNumbers = new ArrayList<String>();
|
private List<String> allowedNumbers = new ArrayList<String>();
|
||||||
|
|
||||||
public class Sms {
|
class Sms {
|
||||||
String phoneNumber;
|
String phoneNumber;
|
||||||
String text;
|
String text;
|
||||||
Date date;
|
Date date;
|
||||||
|
@ -69,21 +72,21 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
double calibrationRequested = 0d;
|
double calibrationRequested = 0d;
|
||||||
int duration = 0;
|
int duration = 0;
|
||||||
|
|
||||||
public Sms(SmsMessage message) {
|
Sms(SmsMessage message) {
|
||||||
phoneNumber = message.getOriginatingAddress();
|
phoneNumber = message.getOriginatingAddress();
|
||||||
text = message.getMessageBody();
|
text = message.getMessageBody();
|
||||||
date = new Date(message.getTimestampMillis());
|
date = new Date(message.getTimestampMillis());
|
||||||
received = true;
|
received = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sms(String phoneNumber, String text, Date date) {
|
Sms(String phoneNumber, String text, Date date) {
|
||||||
this.phoneNumber = phoneNumber;
|
this.phoneNumber = phoneNumber;
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.date = date;
|
this.date = date;
|
||||||
sent = true;
|
sent = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sms(String phoneNumber, String text, Date date, String confirmCode) {
|
Sms(String phoneNumber, String text, Date date, String confirmCode) {
|
||||||
this.phoneNumber = phoneNumber;
|
this.phoneNumber = phoneNumber;
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.date = date;
|
this.date = date;
|
||||||
|
@ -96,12 +99,12 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Sms cancelTempBasalWaitingForConfirmation = null;
|
private Sms cancelTempBasalWaitingForConfirmation = null;
|
||||||
Sms tempBasalWaitingForConfirmation = null;
|
private Sms tempBasalWaitingForConfirmation = null;
|
||||||
Sms bolusWaitingForConfirmation = null;
|
private Sms bolusWaitingForConfirmation = null;
|
||||||
Sms calibrationWaitingForConfirmation = null;
|
private Sms calibrationWaitingForConfirmation = null;
|
||||||
Sms suspendWaitingForConfirmation = null;
|
private Sms suspendWaitingForConfirmation = null;
|
||||||
Date lastRemoteBolusTime = new Date(0);
|
private Date lastRemoteBolusTime = new Date(0);
|
||||||
|
|
||||||
ArrayList<Sms> messages = new ArrayList<>();
|
ArrayList<Sms> messages = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -187,7 +190,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isAllowedNumber(String number) {
|
private boolean isAllowedNumber(String number) {
|
||||||
for (String num : allowedNumbers) {
|
for (String num : allowedNumbers) {
|
||||||
if (num.equals(number)) return true;
|
if (num.equals(number)) return true;
|
||||||
}
|
}
|
||||||
|
@ -199,8 +202,8 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
|
|
||||||
Object[] pdus = (Object[]) ev.bundle.get("pdus");
|
Object[] pdus = (Object[]) ev.bundle.get("pdus");
|
||||||
// For every SMS message received
|
// For every SMS message received
|
||||||
for (int i = 0; i < pdus.length; i++) {
|
for (Object pdu : pdus) {
|
||||||
SmsMessage message = SmsMessage.createFromPdu((byte[]) pdus[i]);
|
SmsMessage message = SmsMessage.createFromPdu((byte[]) pdu);
|
||||||
processSms(new Sms(message));
|
processSms(new Sms(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,25 +236,30 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
BgReading actualBG = GlucoseStatus.actualBg();
|
BgReading actualBG = GlucoseStatus.actualBg();
|
||||||
BgReading lastBG = GlucoseStatus.lastBg();
|
BgReading lastBG = GlucoseStatus.lastBg();
|
||||||
|
|
||||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
if (ConfigBuilderPlugin.getActiveProfile() == null || ConfigBuilderPlugin.getActiveProfile().getProfile() == null) {
|
||||||
String units = profile.getUnits();
|
reply = MainApp.sResources.getString(R.string.noprofile);
|
||||||
|
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Long agoMsec = new Date().getTime() - lastBG.timeIndex;
|
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
|
||||||
int agoMin = (int) (agoMsec / 60d / 1000d);
|
String units = profile.getUnits();
|
||||||
|
|
||||||
if (actualBG != null) {
|
if (actualBG != null) {
|
||||||
reply = MainApp.sResources.getString(R.string.sms_actualbg) + " " + actualBG.valueToUnitsToString(units) + ", ";
|
reply = MainApp.sResources.getString(R.string.sms_actualbg) + " " + actualBG.valueToUnitsToString(units) + ", ";
|
||||||
} else if (lastBG != null) {
|
} else if (lastBG != null) {
|
||||||
|
Long agoMsec = new Date().getTime() - lastBG.timeIndex;
|
||||||
|
int agoMin = (int) (agoMsec / 60d / 1000d);
|
||||||
reply = MainApp.sResources.getString(R.string.sms_lastbg) + " " + lastBG.valueToUnitsToString(units) + " " + String.format(MainApp.sResources.getString(R.string.sms_minago), agoMin) + ", ";
|
reply = MainApp.sResources.getString(R.string.sms_lastbg) + " " + lastBG.valueToUnitsToString(units) + " " + String.format(MainApp.sResources.getString(R.string.sms_minago), agoMin) + ", ";
|
||||||
}
|
}
|
||||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||||
if (glucoseStatus != null)
|
if (glucoseStatus != null)
|
||||||
reply += MainApp.sResources.getString(R.string.sms_delta) + " " + NSProfile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units + ", ";
|
reply += MainApp.sResources.getString(R.string.sms_delta) + " " + NSProfile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units + ", ";
|
||||||
|
|
||||||
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOB();
|
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOB();
|
||||||
IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculation().round();
|
IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculation().round();
|
||||||
MainApp.getConfigBuilder().getActiveTempBasals().updateTotalIOB();
|
ConfigBuilderPlugin.getActiveTempBasals().updateTotalIOB();
|
||||||
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTempBasals().getLastCalculation().round();
|
IobTotal basalIob = ConfigBuilderPlugin.getActiveTempBasals().getLastCalculation().round();
|
||||||
|
|
||||||
reply += MainApp.sResources.getString(R.string.sms_iob) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
|
reply += MainApp.sResources.getString(R.string.sms_iob) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
|
||||||
+ MainApp.sResources.getString(R.string.sms_bolus) + " " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
|
+ MainApp.sResources.getString(R.string.sms_bolus) + " " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
|
||||||
|
@ -303,10 +311,11 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
Answers.getInstance().logCustom(new CustomEvent("SMS_Loop_Status"));
|
Answers.getInstance().logCustom(new CustomEvent("SMS_Loop_Status"));
|
||||||
break;
|
break;
|
||||||
case "RESUME":
|
case "RESUME":
|
||||||
final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
|
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
|
||||||
activeloop.suspendTo(0);
|
activeloop.suspendTo(0);
|
||||||
MainApp.bus().post(new EventRefreshGui(false));
|
MainApp.bus().post(new EventRefreshGui(false));
|
||||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_loopresumed));
|
ConfigBuilderPlugin.uploadOpenAPSOffline(0);
|
||||||
|
reply = MainApp.sResources.getString(R.string.smscommunicator_loopresumed);
|
||||||
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||||
Answers.getInstance().logCustom(new CustomEvent("SMS_Loop_Resume"));
|
Answers.getInstance().logCustom(new CustomEvent("SMS_Loop_Resume"));
|
||||||
break;
|
break;
|
||||||
|
@ -453,7 +462,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
PumpInterface pumpInterface = MainApp.getConfigBuilder();
|
PumpInterface pumpInterface = MainApp.getConfigBuilder();
|
||||||
if (pumpInterface != null) {
|
if (pumpInterface != null) {
|
||||||
danaRPlugin = (DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class);
|
danaRPlugin = (DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class);
|
||||||
PumpEnactResult result = pumpInterface.deliverTreatment(MainApp.getConfigBuilder().getActiveInsulin(), bolusWaitingForConfirmation.bolusRequested, 0, null);
|
PumpEnactResult result = pumpInterface.deliverTreatment(ConfigBuilderPlugin.getActiveInsulin(), bolusWaitingForConfirmation.bolusRequested, 0, null);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusdelivered), result.bolusDelivered);
|
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusdelivered), result.bolusDelivered);
|
||||||
if (danaRPlugin != null)
|
if (danaRPlugin != null)
|
||||||
|
@ -494,7 +503,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
danaRPlugin = (DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class);
|
danaRPlugin = (DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class);
|
||||||
PumpEnactResult result = pumpInterface.cancelTempBasal();
|
PumpEnactResult result = pumpInterface.cancelTempBasal();
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_tempbasalcanceled));
|
reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalcanceled);
|
||||||
if (danaRPlugin != null)
|
if (danaRPlugin != null)
|
||||||
reply += "\n" + danaRPlugin.shortStatus(true);
|
reply += "\n" + danaRPlugin.shortStatus(true);
|
||||||
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||||
|
@ -510,7 +519,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
calibrationWaitingForConfirmation.processed = true;
|
calibrationWaitingForConfirmation.processed = true;
|
||||||
boolean result = XdripCalibrations.sendIntent(calibrationWaitingForConfirmation.calibrationRequested);
|
boolean result = XdripCalibrations.sendIntent(calibrationWaitingForConfirmation.calibrationRequested);
|
||||||
if (result) {
|
if (result) {
|
||||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_calibrationsent));
|
reply = MainApp.sResources.getString(R.string.smscommunicator_calibrationsent);
|
||||||
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||||
} else {
|
} else {
|
||||||
reply = MainApp.sResources.getString(R.string.smscommunicator_calibrationfailed);
|
reply = MainApp.sResources.getString(R.string.smscommunicator_calibrationfailed);
|
||||||
|
@ -519,10 +528,11 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
} else if (suspendWaitingForConfirmation != null && !suspendWaitingForConfirmation.processed &&
|
} else if (suspendWaitingForConfirmation != null && !suspendWaitingForConfirmation.processed &&
|
||||||
suspendWaitingForConfirmation.confirmCode.equals(splited[0]) && new Date().getTime() - suspendWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) {
|
suspendWaitingForConfirmation.confirmCode.equals(splited[0]) && new Date().getTime() - suspendWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) {
|
||||||
suspendWaitingForConfirmation.processed = true;
|
suspendWaitingForConfirmation.processed = true;
|
||||||
final LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop();
|
final LoopPlugin activeloop = ConfigBuilderPlugin.getActiveLoop();
|
||||||
activeloop.suspendTo(new Date().getTime() + suspendWaitingForConfirmation.duration * 60L * 1000);
|
activeloop.suspendTo(new Date().getTime() + suspendWaitingForConfirmation.duration * 60L * 1000);
|
||||||
|
ConfigBuilderPlugin.uploadOpenAPSOffline(suspendWaitingForConfirmation.duration * 60);
|
||||||
MainApp.bus().post(new EventRefreshGui(false));
|
MainApp.bus().post(new EventRefreshGui(false));
|
||||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_loopsuspended));
|
reply = MainApp.sResources.getString(R.string.smscommunicator_loopsuspended);
|
||||||
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
sendSMSToAllNumbers(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()));
|
||||||
|
@ -542,14 +552,14 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendSMSToAllNumbers(Sms sms) {
|
private void sendSMSToAllNumbers(Sms sms) {
|
||||||
for (String number : allowedNumbers) {
|
for (String number : allowedNumbers) {
|
||||||
sms.phoneNumber = number;
|
sms.phoneNumber = number;
|
||||||
sendSMS(sms);
|
sendSMS(sms);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendSMS(Sms sms) {
|
private void sendSMS(Sms sms) {
|
||||||
SmsManager smsManager = SmsManager.getDefault();
|
SmsManager smsManager = SmsManager.getDefault();
|
||||||
sms.text = stripAccents(sms.text);
|
sms.text = stripAccents(sms.text);
|
||||||
if (sms.text.length() > 140) sms.text = sms.text.substring(0, 139);
|
if (sms.text.length() > 140) sms.text = sms.text.substring(0, 139);
|
||||||
|
@ -584,7 +594,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
suspendWaitingForConfirmation = null;
|
suspendWaitingForConfirmation = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String stripAccents(String s) {
|
private static String stripAccents(String s) {
|
||||||
s = Normalizer.normalize(s, Normalizer.Form.NFD);
|
s = Normalizer.normalize(s, Normalizer.Form.NFD);
|
||||||
s = s.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "");
|
s = s.replaceAll("[\\p{InCombiningDiacriticalMarks}]", "");
|
||||||
return s;
|
return s;
|
||||||
|
|
Loading…
Reference in a new issue