commit
71b6b11993
|
@ -33,12 +33,14 @@ import info.nightscout.androidaps.db.Treatment;
|
|||
import info.nightscout.androidaps.events.EventNewBG;
|
||||
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.DanaR.History.DanaRNSHistorySync;
|
||||
import info.nightscout.androidaps.plugins.NSProfile.NSProfilePlugin;
|
||||
import info.nightscout.androidaps.plugins.Objectives.ObjectivesPlugin;
|
||||
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
|
||||
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS;
|
||||
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientPlugin;
|
||||
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripPlugin;
|
||||
|
@ -91,7 +93,7 @@ public class DataService extends IntentService {
|
|||
// Objectives 0
|
||||
ObjectivesPlugin.bgIsAvailableInNS = true;
|
||||
ObjectivesPlugin.saveProgress();
|
||||
} else if (isNSProfile && Intents.ACTION_NEW_PROFILE.equals(action)){
|
||||
} else if (isNSProfile && Intents.ACTION_NEW_PROFILE.equals(action)) {
|
||||
// always handle Profile if NSProfile is enabled without looking at nsUploadOnly
|
||||
handleNewDataFromNSClient(intent);
|
||||
} else if (!nsUploadOnly &&
|
||||
|
@ -243,21 +245,24 @@ public class DataService extends IntentService {
|
|||
String activeProfile = bundles.getString("activeprofile");
|
||||
String profile = bundles.getString("profile");
|
||||
NSProfile nsProfile = new NSProfile(new JSONObject(profile), activeProfile);
|
||||
if (MainApp.getConfigBuilder() == null) {
|
||||
log.error("Config builder not ready on receive profile");
|
||||
return;
|
||||
}
|
||||
MainApp.bus().post(new EventNewBasalProfile(nsProfile));
|
||||
|
||||
PumpInterface pump = MainApp.getConfigBuilder();
|
||||
if (pump != null) {
|
||||
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
if (SP.getBoolean("syncprofiletopump", false))
|
||||
pump.setNewBasalProfile(nsProfile);
|
||||
if (SP.getBoolean("syncprofiletopump", false)) {
|
||||
if (pump.setNewBasalProfile(nsProfile) == PumpInterface.SUCCESS) {
|
||||
SmsCommunicatorPlugin smsCommunicatorPlugin = (SmsCommunicatorPlugin) MainApp.getSpecificPlugin(SmsCommunicatorPlugin.class);
|
||||
if (smsCommunicatorPlugin != null && smsCommunicatorPlugin.isEnabled(PluginBase.GENERAL)) {
|
||||
smsCommunicatorPlugin.sendNotificationToAllNumbers(MainApp.sResources.getString(R.string.profile_set_ok));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.error("No active pump selected");
|
||||
}
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Received profile: " + activeProfile + " " + profile);
|
||||
MainApp.bus().post(new EventNewBasalProfile(nsProfile));
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -414,7 +419,8 @@ public class DataService extends IntentService {
|
|||
if (trJson.has("eventType")) {
|
||||
treatment.mealBolus = true;
|
||||
if (trJson.get("eventType").equals("Correction Bolus")) treatment.mealBolus = false;
|
||||
if (trJson.get("eventType").equals("Bolus Wizard") && treatment.carbs <= 0) treatment.mealBolus = false;
|
||||
if (trJson.get("eventType").equals("Bolus Wizard") && treatment.carbs <= 0)
|
||||
treatment.mealBolus = false;
|
||||
}
|
||||
treatment.setTimeIndex(treatment.getTimeIndex());
|
||||
try {
|
||||
|
@ -464,7 +470,8 @@ public class DataService extends IntentService {
|
|||
if (trJson.has("eventType")) {
|
||||
treatment.mealBolus = true;
|
||||
if (trJson.get("eventType").equals("Correction Bolus")) treatment.mealBolus = false;
|
||||
if (trJson.get("eventType").equals("Bolus Wizard") && treatment.carbs <= 0) treatment.mealBolus = false;
|
||||
if (trJson.get("eventType").equals("Bolus Wizard") && treatment.carbs <= 0)
|
||||
treatment.mealBolus = false;
|
||||
}
|
||||
treatment.setTimeIndex(treatment.getTimeIndex());
|
||||
try {
|
||||
|
|
|
@ -22,7 +22,10 @@ public interface PumpInterface {
|
|||
boolean isExtendedBoluslInProgress();
|
||||
|
||||
// Upload to pump new basal profile
|
||||
void setNewBasalProfile(NSProfile profile);
|
||||
int SUCCESS = 0;
|
||||
int FAILED = 1;
|
||||
int NOT_NEEDED = 2;
|
||||
int setNewBasalProfile(NSProfile profile);
|
||||
boolean isThisProfileSet(NSProfile profile);
|
||||
|
||||
double getBaseBasalRate(); // base basal rate, not temp basal
|
||||
|
|
|
@ -541,7 +541,6 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
|||
builder.setMessage(confirmText);
|
||||
builder.setPositiveButton(getContext().getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
||||
if (options.executeProfileSwitch) {
|
||||
if (data.has("profile")) {
|
||||
sHandler.post(new Runnable() {
|
||||
|
@ -559,12 +558,15 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
|||
} else {
|
||||
log.error("No active pump selected");
|
||||
}
|
||||
ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -49,6 +49,7 @@ import info.nightscout.androidaps.plugins.Actions.dialogs.NewExtendedBolusDialog
|
|||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.SmsCommunicator.SmsCommunicatorPlugin;
|
||||
import info.nightscout.client.data.DbLogger;
|
||||
import info.nightscout.client.data.NSProfile;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
|
@ -334,7 +335,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setNewBasalProfile(NSProfile profile) {
|
||||
public int setNewBasalProfile(NSProfile profile) {
|
||||
// Compare with pump limits
|
||||
NSProfile.BasalValue[] basalValues = profile.getBasalValues();
|
||||
|
||||
|
@ -342,7 +343,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
if (basalValues[index].value < getPumpDescription().basalMinimumRate) {
|
||||
Notification notification = new Notification(Notification.BASAL_VALUE_BELOW_MINIMUM, MainApp.sResources.getString(R.string.basalvaluebelowminimum), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
return;
|
||||
return FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -350,8 +351,9 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
|||
|
||||
if (isThisProfileSet(profile)) {
|
||||
log.debug("Correct profile already set");
|
||||
return NOT_NEEDED;
|
||||
} else {
|
||||
activePump.setNewBasalProfile(profile);
|
||||
return activePump.setNewBasalProfile(profile);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -218,40 +218,44 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setNewBasalProfile(NSProfile profile) {
|
||||
public int setNewBasalProfile(NSProfile profile) {
|
||||
if (sExecutionService == null) {
|
||||
log.error("setNewBasalProfile sExecutionService is null");
|
||||
return;
|
||||
return FAILED;
|
||||
}
|
||||
if (!isInitialized()) {
|
||||
log.error("setNewBasalProfile not initialized");
|
||||
Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
return;
|
||||
return FAILED;
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
}
|
||||
if (!sExecutionService.updateBasalsInPump(profile)) {
|
||||
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
return FAILED;
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isThisProfileSet(NSProfile profile) {
|
||||
if (!isInitialized())
|
||||
return false;
|
||||
return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS
|
||||
DanaRPump pump = getDanaRPump();
|
||||
int basalValues = pump.basal48Enable ? 48 : 24;
|
||||
int basalIncrement = pump.basal48Enable ? 30 * 60 : 60 * 60;
|
||||
for (int h = 0; h < basalValues; h++) {
|
||||
Double pumpValue = pump.pumpProfiles[pump.activeProfile][h];
|
||||
Double profileValue = profile.getBasal(h * basalIncrement);
|
||||
if (!pumpValue.equals(profileValue))
|
||||
if (!pumpValue.equals(profileValue)) {
|
||||
log.debug("Diff found. Hour: " + h + " Pump: " + pumpValue + " Profile: " + profileValue);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -218,32 +218,34 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setNewBasalProfile(NSProfile profile) {
|
||||
public int setNewBasalProfile(NSProfile profile) {
|
||||
if (sExecutionService == null) {
|
||||
log.error("setNewBasalProfile sExecutionService is null");
|
||||
return;
|
||||
return FAILED;
|
||||
}
|
||||
if (!isInitialized()) {
|
||||
log.error("setNewBasalProfile not initialized");
|
||||
Notification notification = new Notification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED, MainApp.sResources.getString(R.string.pumpNotInitializedProfileNotSet), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
return;
|
||||
return FAILED;
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
}
|
||||
if (!sExecutionService.updateBasalsInPump(profile)) {
|
||||
Notification notification = new Notification(Notification.FAILED_UDPATE_PROFILE, MainApp.sResources.getString(R.string.failedupdatebasalprofile), Notification.URGENT);
|
||||
MainApp.bus().post(new EventNewNotification(notification));
|
||||
return FAILED;
|
||||
} else {
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||
return SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isThisProfileSet(NSProfile profile) {
|
||||
if (!isInitialized())
|
||||
return false;
|
||||
return true; // TODO: not sure what's better. so far TRUE to prevent too many SMS
|
||||
DanaRKoreanPump pump = getDanaRPump();
|
||||
int basalValues = pump.basal48Enable ? 48 : 24;
|
||||
int basalIncrement = pump.basal48Enable ? 30 * 60 : 60 * 60;
|
||||
|
|
|
@ -16,18 +16,26 @@ import java.text.Normalizer;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.Services.Intents;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.DanaR.DanaRPlugin;
|
||||
import info.nightscout.androidaps.plugins.DanaRKorean.DanaRKoreanPlugin;
|
||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
|
||||
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventNewSMS;
|
||||
import info.nightscout.androidaps.plugins.SmsCommunicator.events.EventSmsCommunicatorUpdateGui;
|
||||
import info.nightscout.client.data.NSProfile;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
import info.nightscout.utils.SafeParse;
|
||||
|
||||
/**
|
||||
|
@ -41,6 +49,8 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
|
||||
final long CONFIRM_TIMEOUT = 5 * 60 * 1000L;
|
||||
|
||||
List<String> allowedNumbers = new ArrayList<String>();
|
||||
|
||||
public class Sms {
|
||||
String phoneNumber;
|
||||
String text;
|
||||
|
@ -67,6 +77,14 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
sent = true;
|
||||
}
|
||||
|
||||
public Sms(String phoneNumber, String text, Date date, String confirmCode) {
|
||||
this.phoneNumber = phoneNumber;
|
||||
this.text = text;
|
||||
this.date = date;
|
||||
this.confirmCode = confirmCode;
|
||||
sent = true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "SMS from " + phoneNumber + ": " + text;
|
||||
}
|
||||
|
@ -81,6 +99,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
|
||||
public SmsCommunicatorPlugin() {
|
||||
MainApp.bus().register(this);
|
||||
processSettings(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -123,6 +142,28 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
if (type == GENERAL) this.fragmentVisible = fragmentVisible;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void processSettings(final EventPreferenceChange ev) {
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||
String settings = sharedPreferences.getString("smscommunicator_allowednumbers", "");
|
||||
|
||||
String pattern = ";";
|
||||
|
||||
String[] substrings = settings.split(pattern);
|
||||
for (String number : substrings) {
|
||||
String cleaned = number.replaceAll("\\s+", "");
|
||||
allowedNumbers.add(cleaned);
|
||||
log.debug("Found allowed number: " + cleaned);
|
||||
}
|
||||
}
|
||||
|
||||
boolean isAllowedNumber(String number) {
|
||||
for (String num : allowedNumbers) {
|
||||
if (num.equals(number)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventNewSMS ev) {
|
||||
|
||||
|
@ -135,14 +176,13 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
}
|
||||
|
||||
private void processSms(Sms receivedSms) {
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||
|
||||
if (!isEnabled(PluginBase.GENERAL)) {
|
||||
log.debug("Ignoring SMS. Plugin disabled.");
|
||||
return;
|
||||
}
|
||||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||
String allowedNumbers = sharedPreferences.getString("smscommunicator_allowednumbers", "");
|
||||
|
||||
if (!allowedNumbers.contains(receivedSms.phoneNumber)) {
|
||||
if (!isAllowedNumber(receivedSms.phoneNumber)) {
|
||||
log.debug("Ignoring SMS from: " + receivedSms.phoneNumber + ". Sender not allowed");
|
||||
return;
|
||||
}
|
||||
|
@ -156,10 +196,42 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
Double amount = 0d;
|
||||
Double tempBasal = 0d;
|
||||
String passCode = "";
|
||||
Sms newSms = null;
|
||||
|
||||
if (splited.length > 0) {
|
||||
switch (splited[0].toUpperCase()) {
|
||||
case "BG":
|
||||
BgReading actualBG = MainApp.getDbHelper().actualBg();
|
||||
BgReading lastBG = MainApp.getDbHelper().lastBg();
|
||||
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
String units = profile.getUnits();
|
||||
|
||||
Long agoMsec = new Date().getTime() - lastBG.timeIndex;
|
||||
int agoMin = (int) (agoMsec / 60d / 1000d);
|
||||
|
||||
if (actualBG != null) {
|
||||
reply = MainApp.sResources.getString(R.string.actualbg) + " " + actualBG.valueToUnitsToString(units) + ", ";
|
||||
} else if (lastBG != null) {
|
||||
reply = MainApp.sResources.getString(R.string.lastbg) + " " + lastBG.valueToUnitsToString(units) + " " + agoMin + MainApp.sResources.getString(R.string.minago) + ", ";
|
||||
}
|
||||
DatabaseHelper.GlucoseStatus glucoseStatus = MainApp.getDbHelper().getGlucoseStatusData();
|
||||
if (glucoseStatus != null)
|
||||
reply += MainApp.sResources.getString(R.string.delta) + ": " + NSProfile.toUnitsString(glucoseStatus.delta, glucoseStatus.delta * Constants.MGDL_TO_MMOLL, units) + " " + units + ", ";
|
||||
|
||||
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOB();
|
||||
IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculation().round();
|
||||
if (bolusIob == null) bolusIob = new IobTotal();
|
||||
MainApp.getConfigBuilder().getActiveTempBasals().updateTotalIOB();
|
||||
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTempBasals().getLastCalculation().round();
|
||||
if (basalIob == null) basalIob = new IobTotal();
|
||||
|
||||
reply += MainApp.sResources.getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
|
||||
+ MainApp.sResources.getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
|
||||
+ MainApp.sResources.getString(R.string.basal) + ": " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)";
|
||||
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
receivedSms.processed = true;
|
||||
break;
|
||||
case "LOOP":
|
||||
switch (splited[1].toUpperCase()) {
|
||||
case "STOP":
|
||||
|
@ -167,7 +239,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
if (loopPlugin != null && loopPlugin.isEnabled(PluginBase.LOOP)) {
|
||||
loopPlugin.setFragmentEnabled(PluginBase.LOOP, false);
|
||||
reply = MainApp.sResources.getString(R.string.smscommunicator_loophasbeendisabled);
|
||||
newSms = new Sms(receivedSms.phoneNumber, reply, new Date());
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
}
|
||||
receivedSms.processed = true;
|
||||
break;
|
||||
|
@ -176,7 +248,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
if (loopPlugin != null && !loopPlugin.isEnabled(PluginBase.LOOP)) {
|
||||
loopPlugin.setFragmentEnabled(PluginBase.LOOP, true);
|
||||
reply = MainApp.sResources.getString(R.string.smscommunicator_loophasbeenenabled);
|
||||
newSms = new Sms(receivedSms.phoneNumber, reply, new Date());
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
}
|
||||
receivedSms.processed = true;
|
||||
break;
|
||||
|
@ -188,7 +260,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
} else {
|
||||
reply = MainApp.sResources.getString(R.string.smscommunicator_loopisdisabled);
|
||||
}
|
||||
newSms = new Sms(receivedSms.phoneNumber, reply, new Date());
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
}
|
||||
receivedSms.processed = true;
|
||||
break;
|
||||
|
@ -202,7 +274,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
|
||||
List<ResolveInfo> q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0);
|
||||
reply = "TERATMENTS REFRESH " + q.size() + " receivers";
|
||||
newSms = new Sms(receivedSms.phoneNumber, reply, new Date());
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
receivedSms.processed = true;
|
||||
break;
|
||||
}
|
||||
|
@ -214,16 +286,22 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
|
||||
List<ResolveInfo> q = MainApp.instance().getApplicationContext().getPackageManager().queryBroadcastReceivers(restartNSClient, 0);
|
||||
reply = "NSCLIENT RESTART " + q.size() + " receivers";
|
||||
newSms = new Sms(receivedSms.phoneNumber, reply, new Date());
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
receivedSms.processed = true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "DANAR":
|
||||
DanaRPlugin danaRPlugin = (DanaRPlugin) MainApp.getSpecificPlugin(DanaRPlugin.class);
|
||||
if (danaRPlugin != null && danaRPlugin.isEnabled(PluginBase.PUMP))
|
||||
if (danaRPlugin != null && danaRPlugin.isEnabled(PluginBase.PUMP)) {
|
||||
reply = danaRPlugin.shortStatus();
|
||||
newSms = new Sms(receivedSms.phoneNumber, reply, new Date());
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
}
|
||||
DanaRKoreanPlugin danaRKoreanPlugin = (DanaRKoreanPlugin) MainApp.getSpecificPlugin(DanaRKoreanPlugin.class);
|
||||
if (danaRKoreanPlugin != null && danaRKoreanPlugin.isEnabled(PluginBase.PUMP)) {
|
||||
reply = danaRKoreanPlugin.shortStatus();
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
}
|
||||
receivedSms.processed = true;
|
||||
break;
|
||||
case "BASAL":
|
||||
|
@ -234,13 +312,11 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
passCode = generatePasscode();
|
||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_basalstopreplywithcode), passCode);
|
||||
receivedSms.processed = true;
|
||||
newSms = new Sms(receivedSms.phoneNumber, reply, new Date());
|
||||
newSms.confirmCode = passCode;
|
||||
resetWaitingMessages();
|
||||
cancelTempBasalWaitingForConfirmation = newSms;
|
||||
sendSMS(cancelTempBasalWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode));
|
||||
} else {
|
||||
reply = MainApp.sResources.getString(R.string.remotebasalnotallowed);
|
||||
newSms = new Sms(receivedSms.phoneNumber, reply, new Date());
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
}
|
||||
} else {
|
||||
tempBasal = SafeParse.stringToDouble(splited[1]);
|
||||
|
@ -249,14 +325,12 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
passCode = generatePasscode();
|
||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_basalreplywithcode), tempBasal, passCode);
|
||||
receivedSms.processed = true;
|
||||
newSms = new Sms(receivedSms.phoneNumber, reply, new Date());
|
||||
newSms.tempBasal = tempBasal;
|
||||
newSms.confirmCode = passCode;
|
||||
resetWaitingMessages();
|
||||
tempBasalWaitingForConfirmation = newSms;
|
||||
sendSMS(tempBasalWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode));
|
||||
tempBasalWaitingForConfirmation.tempBasal = tempBasal;
|
||||
} else {
|
||||
reply = MainApp.sResources.getString(R.string.remotebasalnotallowed);
|
||||
newSms = new Sms(receivedSms.phoneNumber, reply, new Date());
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -264,7 +338,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
case "BOLUS":
|
||||
if (new Date().getTime() - lastRemoteBolusTime.getTime() < Constants.remoteBolusMinDistance) {
|
||||
reply = MainApp.sResources.getString(R.string.remotebolusnotallowed);
|
||||
newSms = new Sms(receivedSms.phoneNumber, reply, new Date());
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
} else if (splited.length > 1) {
|
||||
amount = SafeParse.stringToDouble(splited[1]);
|
||||
amount = MainApp.getConfigBuilder().applyBolusConstraints(amount);
|
||||
|
@ -273,14 +347,12 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
passCode = generatePasscode();
|
||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_bolusreplywithcode), amount, passCode);
|
||||
receivedSms.processed = true;
|
||||
newSms = new Sms(receivedSms.phoneNumber, reply, new Date());
|
||||
newSms.bolusRequested = amount;
|
||||
newSms.confirmCode = passCode;
|
||||
resetWaitingMessages();
|
||||
bolusWaitingForConfirmation = newSms;
|
||||
sendSMS(bolusWaitingForConfirmation = new Sms(receivedSms.phoneNumber, reply, new Date(), passCode));
|
||||
bolusWaitingForConfirmation.bolusRequested = amount;
|
||||
} else {
|
||||
reply = MainApp.sResources.getString(R.string.remotebolusnotallowed);
|
||||
newSms = new Sms(receivedSms.phoneNumber, reply, new Date());
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -296,11 +368,12 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
reply = String.format(MainApp.sResources.getString(R.string.bolusdelivered), result.bolusDelivered);
|
||||
if (danaRPlugin != null) reply += "\n" + danaRPlugin.shortStatus();
|
||||
lastRemoteBolusTime = new Date();
|
||||
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
} else {
|
||||
reply = MainApp.sResources.getString(R.string.bolusfailed);
|
||||
if (danaRPlugin != null) reply += "\n" + danaRPlugin.shortStatus();
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
}
|
||||
newSms = new Sms(receivedSms.phoneNumber, reply, new Date());
|
||||
}
|
||||
} else if (tempBasalWaitingForConfirmation != null && !tempBasalWaitingForConfirmation.processed &&
|
||||
tempBasalWaitingForConfirmation.confirmCode.equals(splited[0]) && new Date().getTime() - tempBasalWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) {
|
||||
|
@ -312,11 +385,12 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
if (result.success) {
|
||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_tempbasalset), result.absolute, result.duration);
|
||||
if (danaRPlugin != null) reply += "\n" + danaRPlugin.shortStatus();
|
||||
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
} else {
|
||||
reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalfailed);
|
||||
if (danaRPlugin != null) reply += "\n" + danaRPlugin.shortStatus();
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
}
|
||||
newSms = new Sms(receivedSms.phoneNumber, reply, new Date());
|
||||
}
|
||||
} else if (cancelTempBasalWaitingForConfirmation != null && !cancelTempBasalWaitingForConfirmation.processed &&
|
||||
cancelTempBasalWaitingForConfirmation.confirmCode.equals(splited[0]) && new Date().getTime() - cancelTempBasalWaitingForConfirmation.date.getTime() < CONFIRM_TIMEOUT) {
|
||||
|
@ -328,30 +402,46 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
|||
if (result.success) {
|
||||
reply = String.format(MainApp.sResources.getString(R.string.smscommunicator_tempbasalcanceled));
|
||||
if (danaRPlugin != null) reply += "\n" + danaRPlugin.shortStatus();
|
||||
sendSMSToAllNumbers(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
} else {
|
||||
reply = MainApp.sResources.getString(R.string.smscommunicator_tempbasalcancelfailed);
|
||||
if (danaRPlugin != null) reply += "\n" + danaRPlugin.shortStatus();
|
||||
sendSMS(new Sms(receivedSms.phoneNumber, reply, new Date()));
|
||||
}
|
||||
newSms = new Sms(receivedSms.phoneNumber, reply, new Date());
|
||||
}
|
||||
} else {
|
||||
newSms = 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()));
|
||||
}
|
||||
resetWaitingMessages();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (newSms != null) {
|
||||
SmsManager smsManager = SmsManager.getDefault();
|
||||
newSms.text = stripAccents(newSms.text);
|
||||
if (newSms.text.length() > 140) newSms.text = newSms.text.substring(0, 139);
|
||||
smsManager.sendTextMessage(newSms.phoneNumber, null, newSms.text, null, null);
|
||||
messages.add(newSms);
|
||||
}
|
||||
MainApp.bus().post(new EventSmsCommunicatorUpdateGui());
|
||||
}
|
||||
|
||||
public void sendNotificationToAllNumbers(String text) {
|
||||
for (int i = 0; i < allowedNumbers.size(); i++) {
|
||||
Sms sms = new Sms(allowedNumbers.get(i), text, new Date());
|
||||
sendSMS(sms);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendSMSToAllNumbers(Sms sms) {
|
||||
for (int i = 0; i < allowedNumbers.size(); i++) {
|
||||
sms.phoneNumber = allowedNumbers.get(i);
|
||||
sendSMS(sms);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendSMS(Sms sms) {
|
||||
SmsManager smsManager = SmsManager.getDefault();
|
||||
sms.text = stripAccents(sms.text);
|
||||
if (sms.text.length() > 140) sms.text = sms.text.substring(0, 139);
|
||||
smsManager.sendTextMessage(sms.phoneNumber, null, sms.text, null, null);
|
||||
messages.add(sms);
|
||||
}
|
||||
|
||||
private String generatePasscode() {
|
||||
int startChar1 = 'A'; // on iphone 1st char is uppercase :)
|
||||
String passCode = Character.toString((char) (startChar1 + Math.random() * ('z' - 'a' + 1)));
|
||||
|
|
|
@ -124,8 +124,9 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setNewBasalProfile(NSProfile profile) {
|
||||
public int setNewBasalProfile(NSProfile profile) {
|
||||
// Do nothing here. we are using MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -384,4 +384,6 @@
|
|||
<string name="danar_enableextendedbolus">Enable extended boluses on pump</string>
|
||||
<string name="danar_switchtouhmode">Change mode from U/d to U/h on pump</string>
|
||||
<string name="basalvaluebelowminimum">Basal value below minimum. Profile not set!</string>
|
||||
<string name="actualbg">BG:</string>
|
||||
<string name="lastbg">Last BG:</string>
|
||||
</resources>
|
||||
|
|
|
@ -66,14 +66,6 @@
|
|||
<sourceFolder url="file://$MODULE_DIR$/src/full/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/full/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/full/shaders" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/assets" type="java-test-resource" />
|
||||
|
@ -82,6 +74,14 @@
|
|||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestFull/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/testFull/shaders" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
|
||||
|
@ -123,8 +123,6 @@
|
|||
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.0.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.google.android.gms/play-services-base/7.3.0/jars" />
|
||||
|
@ -133,13 +131,11 @@
|
|||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/me.denley.wearpreferenceactivity/wearpreferenceactivity/0.5.0/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-safeguard" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
|
Loading…
Reference in a new issue