[0.3] RELEASE
- WakeAndTune fixed, it runs in separate thread (in task) - Fixed Frequency scan results - fixing connection statuses - postprocessing fixed/extended with MedtronicUIResponseType - Basal profile fixes
This commit is contained in:
parent
594012aab6
commit
88b75d3496
|
@ -71,7 +71,7 @@ android {
|
|||
targetSdkVersion 25
|
||||
multiDexEnabled true
|
||||
versionCode 1500
|
||||
version "2.0g-medtronic-0.3.1-snapshot"
|
||||
version "2.0g-medtronic-0.3"
|
||||
buildConfigField "String", "VERSION", '"' + version + '"'
|
||||
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
|
||||
buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"'
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
package info.nightscout.androidaps;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.danlew.android.joda.JodaTimeAndroid;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import android.app.Application;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.BroadcastReceiver;
|
||||
|
@ -20,14 +28,6 @@ import com.squareup.otto.Bus;
|
|||
import com.squareup.otto.LoggingBus;
|
||||
import com.squareup.otto.ThreadEnforcer;
|
||||
|
||||
import net.danlew.android.joda.JodaTimeAndroid;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import info.nightscout.androidaps.data.ConstraintChecker;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
|
@ -44,8 +44,9 @@ import info.nightscout.androidaps.plugins.Insulin.InsulinOrefFreePeakPlugin;
|
|||
import info.nightscout.androidaps.plugins.Insulin.InsulinOrefRapidActingPlugin;
|
||||
import info.nightscout.androidaps.plugins.Insulin.InsulinOrefUltraRapidActingPlugin;
|
||||
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.Maintenance.MaintenancePlugin;
|
||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||
import info.nightscout.androidaps.plugins.Maintenance.LoggerUtils;
|
||||
import info.nightscout.androidaps.plugins.Maintenance.MaintenancePlugin;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientPlugin;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.receivers.AckAlarmReceiver;
|
||||
|
@ -88,11 +89,10 @@ import info.nightscout.androidaps.receivers.KeepAliveReceiver;
|
|||
import info.nightscout.androidaps.receivers.NSAlarmReceiver;
|
||||
import info.nightscout.androidaps.services.Intents;
|
||||
import info.nightscout.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.plugins.Maintenance.LoggerUtils;
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
|
||||
|
||||
public class MainApp extends Application {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(L.CORE);
|
||||
private static KeepAliveReceiver keepAliveReceiver;
|
||||
|
||||
|
@ -116,6 +116,7 @@ public class MainApp extends Application {
|
|||
public static boolean devBranch;
|
||||
public static boolean engineeringMode;
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
@ -157,7 +158,8 @@ public class MainApp extends Application {
|
|||
// Register all tabs in app here
|
||||
pluginsList.add(OverviewPlugin.getPlugin());
|
||||
pluginsList.add(IobCobCalculatorPlugin.getPlugin());
|
||||
if (Config.ACTION) pluginsList.add(ActionsFragment.getPlugin());
|
||||
if (Config.ACTION)
|
||||
pluginsList.add(ActionsFragment.getPlugin());
|
||||
pluginsList.add(InsulinOrefRapidActingPlugin.getPlugin());
|
||||
pluginsList.add(InsulinOrefUltraRapidActingPlugin.getPlugin());
|
||||
pluginsList.add(InsulinOrefFreePeakPlugin.getPlugin());
|
||||
|
@ -165,35 +167,50 @@ public class MainApp extends Application {
|
|||
pluginsList.add(SensitivityAAPSPlugin.getPlugin());
|
||||
pluginsList.add(SensitivityWeightedAveragePlugin.getPlugin());
|
||||
pluginsList.add(SensitivityOref1Plugin.getPlugin());
|
||||
if (Config.PUMPDRIVERS) pluginsList.add(DanaRPlugin.getPlugin());
|
||||
if (Config.PUMPDRIVERS) pluginsList.add(DanaRKoreanPlugin.getPlugin());
|
||||
if (Config.PUMPDRIVERS) pluginsList.add(DanaRv2Plugin.getPlugin());
|
||||
if (Config.PUMPDRIVERS) pluginsList.add(DanaRSPlugin.getPlugin());
|
||||
if (Config.PUMPDRIVERS)
|
||||
pluginsList.add(DanaRPlugin.getPlugin());
|
||||
if (Config.PUMPDRIVERS)
|
||||
pluginsList.add(DanaRKoreanPlugin.getPlugin());
|
||||
if (Config.PUMPDRIVERS)
|
||||
pluginsList.add(DanaRv2Plugin.getPlugin());
|
||||
if (Config.PUMPDRIVERS)
|
||||
pluginsList.add(DanaRSPlugin.getPlugin());
|
||||
pluginsList.add(CareportalPlugin.getPlugin());
|
||||
if (Config.PUMPDRIVERS && engineeringMode)
|
||||
pluginsList.add(InsightPlugin.getPlugin()); // <-- Enable Insight plugin here
|
||||
if (Config.PUMPDRIVERS) pluginsList.add(ComboPlugin.getPlugin());
|
||||
if (Config.PUMPDRIVERS && engineeringMode)
|
||||
pluginsList.add(MedtronicPumpPlugin.getPlugin());
|
||||
if (Config.MDI) pluginsList.add(MDIPlugin.getPlugin());
|
||||
if (Config.PUMPDRIVERS)
|
||||
pluginsList.add(ComboPlugin.getPlugin());
|
||||
if (Config.PUMPDRIVERS && engineeringMode)
|
||||
pluginsList.add(MedtronicPumpPlugin.getPlugin());
|
||||
if (Config.MDI)
|
||||
pluginsList.add(MDIPlugin.getPlugin());
|
||||
pluginsList.add(VirtualPumpPlugin.getPlugin());
|
||||
if (Config.APS) pluginsList.add(LoopPlugin.getPlugin());
|
||||
if (Config.APS) pluginsList.add(OpenAPSMAPlugin.getPlugin());
|
||||
if (Config.APS) pluginsList.add(OpenAPSAMAPlugin.getPlugin());
|
||||
if (Config.APS) pluginsList.add(OpenAPSSMBPlugin.getPlugin());
|
||||
if (Config.APS)
|
||||
pluginsList.add(LoopPlugin.getPlugin());
|
||||
if (Config.APS)
|
||||
pluginsList.add(OpenAPSMAPlugin.getPlugin());
|
||||
if (Config.APS)
|
||||
pluginsList.add(OpenAPSAMAPlugin.getPlugin());
|
||||
if (Config.APS)
|
||||
pluginsList.add(OpenAPSSMBPlugin.getPlugin());
|
||||
pluginsList.add(NSProfilePlugin.getPlugin());
|
||||
if (Config.OTHERPROFILES) pluginsList.add(SimpleProfilePlugin.getPlugin());
|
||||
if (Config.OTHERPROFILES) pluginsList.add(LocalProfilePlugin.getPlugin());
|
||||
if (Config.OTHERPROFILES)
|
||||
pluginsList.add(SimpleProfilePlugin.getPlugin());
|
||||
if (Config.OTHERPROFILES)
|
||||
pluginsList.add(LocalProfilePlugin.getPlugin());
|
||||
pluginsList.add(TreatmentsPlugin.getPlugin());
|
||||
if (Config.SAFETY) pluginsList.add(SafetyPlugin.getPlugin());
|
||||
if (Config.APS) pluginsList.add(ObjectivesPlugin.getPlugin());
|
||||
if (Config.SAFETY)
|
||||
pluginsList.add(SafetyPlugin.getPlugin());
|
||||
if (Config.APS)
|
||||
pluginsList.add(ObjectivesPlugin.getPlugin());
|
||||
pluginsList.add(SourceXdripPlugin.getPlugin());
|
||||
pluginsList.add(SourceNSClientPlugin.getPlugin());
|
||||
pluginsList.add(SourceMM640gPlugin.getPlugin());
|
||||
pluginsList.add(SourceGlimpPlugin.getPlugin());
|
||||
pluginsList.add(SourceDexcomG5Plugin.getPlugin());
|
||||
pluginsList.add(SourcePoctechPlugin.getPlugin());
|
||||
if (Config.SMSCOMMUNICATORENABLED) pluginsList.add(SmsCommunicatorPlugin.getPlugin());
|
||||
if (Config.SMSCOMMUNICATORENABLED)
|
||||
pluginsList.add(SmsCommunicatorPlugin.getPlugin());
|
||||
pluginsList.add(FoodPlugin.getPlugin());
|
||||
|
||||
pluginsList.add(WearPlugin.initPlugin(this));
|
||||
|
@ -219,6 +236,7 @@ public class MainApp extends Application {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private void registerLocalBroadcastReceiver() {
|
||||
lbm = LocalBroadcastManager.getInstance(this);
|
||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_TREATMENT));
|
||||
|
@ -234,23 +252,28 @@ public class MainApp extends Application {
|
|||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_DEVICESTATUS));
|
||||
lbm.registerReceiver(dataReceiver, new IntentFilter(Intents.ACTION_NEW_CAL));
|
||||
|
||||
//register alarms
|
||||
// register alarms
|
||||
lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_ALARM));
|
||||
lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_ANNOUNCEMENT));
|
||||
lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_CLEAR_ALARM));
|
||||
lbm.registerReceiver(alarmReciever, new IntentFilter(Intents.ACTION_URGENT_ALARM));
|
||||
|
||||
//register ack alarm
|
||||
// register ack alarm
|
||||
lbm.registerReceiver(ackAlarmReciever, new IntentFilter(Intents.ACTION_ACK_ALARM));
|
||||
|
||||
//register dbaccess
|
||||
// register dbaccess
|
||||
lbm.registerReceiver(dbAccessReciever, new IntentFilter(Intents.ACTION_DATABASE));
|
||||
}
|
||||
|
||||
|
||||
private void setBTReceiver() {
|
||||
|
||||
// SP.putDouble(RileyLinkConst.Prefs.LastGoodDeviceFrequency, null);
|
||||
// SP.remove(RileyLinkConst.Prefs.LastGoodDeviceFrequency);
|
||||
|
||||
// RileyLink framework needs to know, when BT was reconnected, so that we can reconnect to RL device
|
||||
btReceiver = new BroadcastReceiver() {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
|
@ -286,11 +309,13 @@ public class MainApp extends Application {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void stopKeepAliveService() {
|
||||
if (keepAliveReceiver != null)
|
||||
KeepAliveReceiver.cancelAlarm(this);
|
||||
}
|
||||
|
||||
|
||||
public static void subscribe(Object subscriber) {
|
||||
try {
|
||||
bus().register(subscriber);
|
||||
|
@ -299,6 +324,7 @@ public class MainApp extends Application {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static void unsubscribe(Object subscriber) {
|
||||
try {
|
||||
bus().unregister(subscriber);
|
||||
|
@ -307,34 +333,42 @@ public class MainApp extends Application {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static Bus bus() {
|
||||
return sBus;
|
||||
}
|
||||
|
||||
|
||||
public static String gs(int id) {
|
||||
return sResources.getString(id);
|
||||
}
|
||||
|
||||
|
||||
public static String gs(int id, Object... args) {
|
||||
return sResources.getString(id, args);
|
||||
}
|
||||
|
||||
|
||||
public static String gq(@PluralsRes int id, int quantity, Object... args) {
|
||||
return sResources.getQuantityString(id, quantity, args);
|
||||
}
|
||||
|
||||
|
||||
public static int gc(int id) {
|
||||
return sResources.getColor(id);
|
||||
}
|
||||
|
||||
|
||||
public static MainApp instance() {
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
|
||||
public static DatabaseHelper getDbHelper() {
|
||||
return sDatabaseHelper;
|
||||
}
|
||||
|
||||
|
||||
public static void closeDbHelper() {
|
||||
if (sDatabaseHelper != null) {
|
||||
sDatabaseHelper.close();
|
||||
|
@ -342,18 +376,22 @@ public class MainApp extends Application {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static ConfigBuilderPlugin getConfigBuilder() {
|
||||
return sConfigBuilder;
|
||||
}
|
||||
|
||||
|
||||
public static ConstraintChecker getConstraintChecker() {
|
||||
return sConstraintsChecker;
|
||||
}
|
||||
|
||||
|
||||
public static ArrayList<PluginBase> getPluginsList() {
|
||||
return pluginsList;
|
||||
}
|
||||
|
||||
|
||||
public static ArrayList<PluginBase> getSpecificPluginsList(PluginType type) {
|
||||
ArrayList<PluginBase> newList = new ArrayList<>();
|
||||
|
||||
|
@ -368,6 +406,7 @@ public class MainApp extends Application {
|
|||
return newList;
|
||||
}
|
||||
|
||||
|
||||
public static ArrayList<PluginBase> getSpecificPluginsVisibleInList(PluginType type) {
|
||||
ArrayList<PluginBase> newList = new ArrayList<>();
|
||||
|
||||
|
@ -383,6 +422,7 @@ public class MainApp extends Application {
|
|||
return newList;
|
||||
}
|
||||
|
||||
|
||||
public static ArrayList<PluginBase> getSpecificPluginsListByInterface(Class interfaceClass) {
|
||||
ArrayList<PluginBase> newList = new ArrayList<>();
|
||||
|
||||
|
@ -397,6 +437,7 @@ public class MainApp extends Application {
|
|||
return newList;
|
||||
}
|
||||
|
||||
|
||||
public static ArrayList<PluginBase> getSpecificPluginsVisibleInListByInterface(Class interfaceClass, PluginType type) {
|
||||
ArrayList<PluginBase> newList = new ArrayList<>();
|
||||
|
||||
|
@ -412,12 +453,13 @@ public class MainApp extends Application {
|
|||
return newList;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public static <T extends PluginBase> T getSpecificPlugin(Class<T> pluginClass) {
|
||||
if (pluginsList != null) {
|
||||
for (PluginBase p : pluginsList) {
|
||||
if (pluginClass.isAssignableFrom(p.getClass()))
|
||||
return (T) p;
|
||||
return (T)p;
|
||||
}
|
||||
} else {
|
||||
log.error("pluginsList=null");
|
||||
|
@ -425,16 +467,19 @@ public class MainApp extends Application {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isEngineeringModeOrRelease() {
|
||||
if (!Config.APS)
|
||||
return true;
|
||||
return engineeringMode || !devBranch;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isDev() {
|
||||
return devBranch;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onTerminate() {
|
||||
if (L.isEnabled(L.CORE))
|
||||
|
|
|
@ -210,13 +210,14 @@ public abstract class RileyLinkCommunicationManager {
|
|||
|
||||
byte[] pumpMsgContent = createPumpMessageContent(RLMessageType.ReadSimpleData);
|
||||
RFSpyResponse resp = rfspy.transmitThenReceive(new RadioPacket(pumpMsgContent), (byte)0, (byte)0,
|
||||
(byte)0, (byte)0, SCAN_TIMEOUT, (byte)0);
|
||||
(byte)0, (byte)0, 500, (byte)0);
|
||||
if (resp.wasTimeout()) {
|
||||
LOG.error("scanForPump: Failed to find pump at frequency {}", frequencies[i]);
|
||||
} else if (resp.looksLikeRadioPacket()) {
|
||||
RadioResponse radioResponse = new RadioResponse(resp.getRaw());
|
||||
if (radioResponse.isValid()) {
|
||||
sumRSSI += radioResponse.rssi;
|
||||
trial.rssiList.add(radioResponse.rssi);
|
||||
trial.successes++;
|
||||
} else {
|
||||
LOG.warn("Failed to parse radio response: " + ByteUtil.shortHexString(resp.getRaw()));
|
||||
|
@ -227,17 +228,23 @@ public abstract class RileyLinkCommunicationManager {
|
|||
trial.tries++;
|
||||
}
|
||||
sumRSSI += -99.0 * (trial.tries - trial.successes);
|
||||
trial.averageRSSI = (double)(sumRSSI) / (double)(trial.tries);
|
||||
trial.averageRSSI2 = (double)(sumRSSI) / (double)(trial.tries);
|
||||
|
||||
trial.calculateAverage();
|
||||
|
||||
results.trials.add(trial);
|
||||
}
|
||||
|
||||
results.dateTime = System.currentTimeMillis();
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder("Scan results:\n");
|
||||
|
||||
for (int k = 0; k < results.trials.size(); k++) {
|
||||
FrequencyTrial one = results.trials.get(k);
|
||||
|
||||
stringBuilder.append(String.format("Scan Result[%s]: Freq=%s, avg RSSI = %s\n", "" + k, ""
|
||||
+ one.frequencyMHz, "" + one.averageRSSI));
|
||||
+ one.frequencyMHz, "" + one.averageRSSI + ", RSSIs =" + one.rssiList + ", averageRSSI_Old="
|
||||
+ one.averageRSSI2));
|
||||
}
|
||||
|
||||
LOG.debug(stringBuilder.toString());
|
||||
|
@ -248,6 +255,7 @@ public abstract class RileyLinkCommunicationManager {
|
|||
results.bestFrequencyMHz = bestTrial.frequencyMHz;
|
||||
if (bestTrial.successes > 0) {
|
||||
rfspy.setBaseFrequency(results.bestFrequencyMHz);
|
||||
LOG.debug("Best frequency found: " + results.bestFrequencyMHz);
|
||||
return results.bestFrequencyMHz;
|
||||
} else {
|
||||
LOG.error("No pump response during scan.");
|
||||
|
|
|
@ -2,25 +2,21 @@ package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by geoff on 5/30/16.
|
||||
* changed by Andy 10/20/18
|
||||
*/
|
||||
public class FrequencyScanResults {
|
||||
|
||||
public ArrayList<FrequencyTrial> trials = new ArrayList<>();
|
||||
public List<FrequencyTrial> trials = new ArrayList<>();
|
||||
public double bestFrequencyMHz = 0.0;
|
||||
public long dateTime;
|
||||
|
||||
|
||||
public void sort() {
|
||||
Collections.sort(trials, new Comparator<FrequencyTrial>() {
|
||||
|
||||
@Override
|
||||
public int compare(FrequencyTrial trial1, FrequencyTrial trial2) {
|
||||
return trial1.averageRSSI.compareTo(trial2.averageRSSI);
|
||||
}
|
||||
});
|
||||
Collections.sort(trials, (trial1, trial2) -> trial1.averageRSSI.compareTo(trial2.averageRSSI));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.ble.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by geoff on 5/30/16.
|
||||
* changed by Andy 10/20/18
|
||||
*/
|
||||
public class FrequencyTrial {
|
||||
|
||||
|
@ -9,4 +13,23 @@ public class FrequencyTrial {
|
|||
public int successes = 0;
|
||||
public Double averageRSSI = 0.0;
|
||||
public double frequencyMHz = 0.0;
|
||||
public List<Integer> rssiList = new ArrayList<>();
|
||||
public double averageRSSI2;
|
||||
|
||||
|
||||
public void calculateAverage() {
|
||||
int sum = 0;
|
||||
int count = 0;
|
||||
for (Integer rssi : rssiList) {
|
||||
sum += Math.abs(rssi);
|
||||
count++;
|
||||
}
|
||||
|
||||
double avg = (sum / (count * 1.0d));
|
||||
|
||||
if (count != 0)
|
||||
this.averageRSSI = avg * (-1);
|
||||
else
|
||||
this.averageRSSI = -99.0d;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,9 @@ import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks.
|
|||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks.InitializePumpManagerTask;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks.ServiceTask;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks.ServiceTaskExecutor;
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks.WakeAndTuneTask;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.PumpDeviceState;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
/**
|
||||
|
@ -177,7 +180,8 @@ public abstract class RileyLinkService extends Service {
|
|||
} else if (action.equals(RileyLinkConst.IPC.MSG_PUMP_tunePump) || //
|
||||
action.equals(RileyLinkConst.IPC.MSG_PUMP_quickTune)) {
|
||||
if (getRileyLinkTargetDevice().isTuneUpEnabled()) {
|
||||
doTuneUpDevice();
|
||||
// doTuneUpDevice();
|
||||
ServiceTaskExecutor.startTask(new WakeAndTuneTask());
|
||||
}
|
||||
} else if (action.startsWith("MSG_PUMP_")) {
|
||||
handlePumpSpecificIntents(intent);
|
||||
|
@ -387,6 +391,7 @@ public abstract class RileyLinkService extends Service {
|
|||
public void doTuneUpDevice() {
|
||||
|
||||
RileyLinkUtil.setServiceState(RileyLinkServiceState.TuneUpDevice);
|
||||
MedtronicUtil.setPumpDeviceState(PumpDeviceState.Sleeping);
|
||||
|
||||
double lastGoodFrequency = 0.0d;
|
||||
|
||||
|
@ -426,6 +431,8 @@ public abstract class RileyLinkService extends Service {
|
|||
// error tuning pump, pump not present ??
|
||||
RileyLinkUtil
|
||||
.setServiceState(RileyLinkServiceState.PumpConnectorError, RileyLinkError.TuneUpOfDeviceFailed);
|
||||
} else {
|
||||
RileyLinkUtil.setServiceState(RileyLinkServiceState.PumpConnectorReady);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -436,6 +443,8 @@ public abstract class RileyLinkService extends Service {
|
|||
this.rileyLinkBLE.disconnect();
|
||||
rileyLinkServiceData.rileylinkAddress = null;
|
||||
}
|
||||
|
||||
RileyLinkUtil.setServiceState(RileyLinkServiceState.BluetoothReady);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.tasks;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpCommon.hw.rileylink.service.data.ServiceTransport;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.MedtronicFragment;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.service.RileyLinkMedtronicService;
|
||||
|
||||
/**
|
||||
|
@ -22,7 +23,9 @@ public class WakeAndTuneTask extends PumpTask {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
MedtronicFragment.refreshButtonEnabled(false);
|
||||
RileyLinkMedtronicService.getInstance().doTuneUpDevice();
|
||||
MedtronicFragment.refreshButtonEnabled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.Date;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.joda.time.LocalDateTime;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -489,8 +490,13 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
|
|||
|
||||
Double[] basalsByHour = getMDTPumpStatus().basalsByHour;
|
||||
|
||||
LOG.debug("Basals by hour: " + (basalsByHour == null ? "null" : StringUtils.join(basalsByHour, " ")));
|
||||
|
||||
int index = 0;
|
||||
|
||||
if (basalsByHour == null)
|
||||
return true;
|
||||
|
||||
for (Profile.BasalValue basalValue : profile.getBasalValues()) {
|
||||
|
||||
int hour = basalValue.timeAsSeconds / (60 * 60);
|
||||
|
|
|
@ -144,6 +144,8 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
if (valid) {
|
||||
if (state == PumpDeviceState.PumpUnreachable)
|
||||
MedtronicUtil.setPumpDeviceState(PumpDeviceState.WakingUp);
|
||||
else
|
||||
MedtronicUtil.setPumpDeviceState(PumpDeviceState.Sleeping);
|
||||
|
||||
if (firstConnection)
|
||||
checkFirstConnectionTime();
|
||||
|
@ -680,7 +682,7 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
|
||||
public BasalProfile getBasalProfile_Old() {
|
||||
|
||||
Object responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.GetBasalProfileA);
|
||||
Object responseObject = sendAndGetResponseWithCheck(MedtronicCommandType.GetBasalProfileSTD);
|
||||
|
||||
return responseObject == null ? null : (BasalProfile)responseObject;
|
||||
}
|
||||
|
@ -748,15 +750,18 @@ public class MedtronicCommunicationManager extends RileyLinkCommunicationManager
|
|||
errorMessage = check;
|
||||
}
|
||||
|
||||
Object dataResponse = medtronicConverter.convertResponse(commandType, data);
|
||||
BasalProfile basalProfile = (BasalProfile)medtronicConverter.convertResponse(commandType, data);
|
||||
|
||||
LOG.debug("Converted response for {} is {}.", commandType.name(), dataResponse);
|
||||
LOG.debug("Converted response for {} is {}.", commandType.name(), basalProfile);
|
||||
|
||||
MedtronicUtil.setPumpDeviceState(PumpDeviceState.Sleeping);
|
||||
|
||||
return (BasalProfile)dataResponse;
|
||||
return basalProfile;
|
||||
}
|
||||
|
||||
LOG.warn("Error reading profile in max retries.");
|
||||
MedtronicUtil.setPumpDeviceState(PumpDeviceState.Sleeping);
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.data.dto.BasalProfile;
|
|||
import info.nightscout.androidaps.plugins.PumpMedtronic.data.dto.BatteryStatusDTO;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.data.dto.PumpSettingDTO;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicNotificationType;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicUIResponseType;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.driver.MedtronicPumpStatus;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil;
|
||||
|
||||
|
@ -36,16 +37,24 @@ public class MedtronicUIPostprocessor {
|
|||
// where responses won't be directly used
|
||||
public void postProcessData(MedtronicUITask uiTask) {
|
||||
|
||||
if (!uiTask.haveData()) {
|
||||
LOG.error("Error reading data [{}]: {}", uiTask.commandType, uiTask.errorDescription);
|
||||
return;
|
||||
}
|
||||
// if (!uiTask.haveData()) {
|
||||
// LOG.error("Error reading data [{}]: {}", uiTask.commandType, uiTask.errorDescription);
|
||||
// return;
|
||||
// }
|
||||
|
||||
switch (uiTask.commandType) {
|
||||
|
||||
case GetBasalProfileSTD: {
|
||||
BasalProfile basalProfile = (BasalProfile)uiTask.returnData;
|
||||
pumpStatus.basalsByHour = basalProfile.getProfilesByHour();
|
||||
|
||||
Double[] profilesByHour = basalProfile.getProfilesByHour();
|
||||
|
||||
if (profilesByHour != null) {
|
||||
pumpStatus.basalsByHour = profilesByHour;
|
||||
} else {
|
||||
uiTask.responseType = MedtronicUIResponseType.Error;
|
||||
uiTask.errorDescription = "No profile found.";
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicCommandTyp
|
|||
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.MedtronicUIResponseType;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.defs.PumpDeviceState;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.events.EventMedtronicDeviceStatusChange;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.events.EventMedtronicPumpValuesChanged;
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil;
|
||||
|
||||
/**
|
||||
|
@ -24,9 +25,9 @@ public class MedtronicUITask {
|
|||
public MedtronicCommandType commandType;
|
||||
public Object returnData;
|
||||
String errorDescription;
|
||||
boolean invalid = false;
|
||||
// boolean invalid = false;
|
||||
private Object[] parameters;
|
||||
private boolean received;
|
||||
// private boolean received;
|
||||
MedtronicUIResponseType responseType;
|
||||
|
||||
|
||||
|
@ -117,7 +118,7 @@ public class MedtronicUITask {
|
|||
|
||||
case SetBasalProfileSTD:
|
||||
case SetBasalProfileA: {
|
||||
|
||||
// returnData = communicationManager.setBasalProfile(profile);
|
||||
// Float amount = getAmount();
|
||||
//
|
||||
// if (amount != null) {
|
||||
|
@ -139,19 +140,18 @@ public class MedtronicUITask {
|
|||
|
||||
default: {
|
||||
LOG.warn("This commandType is not supported (yet) - {}.", commandType);
|
||||
invalid = true;
|
||||
// invalid = true;
|
||||
responseType = MedtronicUIResponseType.Invalid;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (responseType != null) {
|
||||
if (responseType == null) {
|
||||
if (returnData == null) {
|
||||
if (!invalid)
|
||||
errorDescription = communicationManager.getErrorResponse();
|
||||
received = true;
|
||||
errorDescription = communicationManager.getErrorResponse();
|
||||
this.responseType = MedtronicUIResponseType.Error;
|
||||
} else {
|
||||
received = true;
|
||||
this.responseType = MedtronicUIResponseType.Data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,21 +202,20 @@ public class MedtronicUITask {
|
|||
EventMedtronicDeviceStatusChange statusChange;
|
||||
LOG.warn("@@@ In execute. {}", commandType);
|
||||
|
||||
// should never happen
|
||||
if (invalid) {
|
||||
if (responseType == MedtronicUIResponseType.Data) {
|
||||
postprocessor.postProcessData(this);
|
||||
}
|
||||
|
||||
if (responseType == MedtronicUIResponseType.Invalid) {
|
||||
statusChange = new EventMedtronicDeviceStatusChange(PumpDeviceState.ErrorWhenCommunicating,
|
||||
"Unsupported command in MedtronicUITask");
|
||||
MainApp.bus().post(statusChange);
|
||||
}
|
||||
|
||||
if (errorDescription != null) {
|
||||
} else if (responseType == MedtronicUIResponseType.Error) {
|
||||
statusChange = new EventMedtronicDeviceStatusChange(PumpDeviceState.ErrorWhenCommunicating,
|
||||
errorDescription);
|
||||
MainApp.bus().post(statusChange);
|
||||
}
|
||||
|
||||
if (returnData != null) {
|
||||
postprocessor.postProcessData(this);
|
||||
} else {
|
||||
MainApp.bus().post(new EventMedtronicPumpValuesChanged());
|
||||
}
|
||||
|
||||
MedtronicUtil.getPumpStatus().setLastCommunicationToNow();
|
||||
|
@ -226,6 +225,6 @@ public class MedtronicUITask {
|
|||
|
||||
|
||||
public boolean hasData() {
|
||||
return (returnData != null);
|
||||
return (responseType == MedtronicUIResponseType.Data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,16 +64,13 @@ public class BasalProfile {
|
|||
return false;
|
||||
}
|
||||
|
||||
// if we have just one entry through all day it looks like just length 1
|
||||
if (data.length == 1) {
|
||||
data = MedtronicUtil.createByteArray(data[0], (byte)0, (byte)0);
|
||||
}
|
||||
|
||||
// int len = Math.min(MAX_RAW_DATA_SIZE, data.length);
|
||||
mRawData = data;
|
||||
// System.arraycopy(data, 0, mRawData, 0, len);
|
||||
if (DEBUG_BASALPROFILE) {
|
||||
LOG.debug(String.format("setRawData: copied raw data buffer of %d bytes.", data.length));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -159,7 +156,7 @@ public class BasalProfile {
|
|||
public List<BasalProfileEntry> getEntries() {
|
||||
List<BasalProfileEntry> entries = new ArrayList<>();
|
||||
|
||||
if (mRawData[2] == 0x3f) {
|
||||
if (mRawData == null || mRawData[2] == 0x3f) {
|
||||
LOG.warn("Raw Data is empty.");
|
||||
return entries; // an empty list
|
||||
}
|
||||
|
@ -212,11 +209,14 @@ public class BasalProfile {
|
|||
}
|
||||
|
||||
|
||||
// TODO extend to be done by half hour
|
||||
public Double[] getProfilesByHour() {
|
||||
|
||||
List<BasalProfileEntry> entries = getEntries();
|
||||
|
||||
if (entries.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Double[] basalByHour = new Double[24];
|
||||
|
||||
for (int i = 0; i < entries.size(); i++) {
|
||||
|
@ -261,4 +261,9 @@ public class BasalProfile {
|
|||
public byte[] getRawData() {
|
||||
return this.mRawData;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return getBasalProfileAsString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -226,7 +226,7 @@ public class MedtronicPumpStatus extends PumpStatus {
|
|||
|
||||
private boolean startService() {
|
||||
|
||||
LOG.debug("MedtronicPumpStatus::startService");
|
||||
// LOG.debug("MedtronicPumpStatus::startService");
|
||||
|
||||
if (serialChanged && !inPreInit && MedtronicUtil.getMedtronicService() != null) {
|
||||
MedtronicUtil.getMedtronicService().setPumpIDString(this.serialNumber); // short operation
|
||||
|
|
|
@ -2,6 +2,7 @@ package info.nightscout.androidaps.plugins.PumpMedtronic.data.dto;
|
|||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil;
|
||||
|
@ -10,15 +11,16 @@ import info.nightscout.androidaps.plugins.PumpMedtronic.util.MedtronicUtil;
|
|||
* Created by andy on 6/16/18.
|
||||
*/
|
||||
public class BasalProfileUTest {
|
||||
|
||||
@Test
|
||||
public void getProfilesByHour() throws Exception {
|
||||
|
||||
BasalProfile basalProfile = new BasalProfile();
|
||||
byte[] data = { //
|
||||
0x48, 0x00, 0x00, 0x40, 0x00, 0x02, 0x38, 0x00, 0x04, 0x3A, 0x00, 0x06, 0x32, 0x00, 0x0C, 0x26, 0x00, //
|
||||
0x10, 0x2E, 0x00, 0x14, 0x32, 0x00, 0x18, 0x26, 0x00, 0x1A, 0x1A, 0x00, 0x20, 0x14, 0x00, 0x2A, 0x00, //
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
0x48, 0x00, 0x00, 0x40, 0x00, 0x02, 0x38, 0x00, 0x04, 0x3A, 0x00, 0x06, 0x32, 0x00, 0x0C, 0x26, 0x00, //
|
||||
0x10, 0x2E, 0x00, 0x14, 0x32, 0x00, 0x18, 0x26, 0x00, 0x1A, 0x1A, 0x00, 0x20, 0x14, 0x00, 0x2A, 0x00, //
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
basalProfile.setRawData(data);
|
||||
|
||||
|
@ -51,4 +53,23 @@ public class BasalProfileUTest {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProfileByDay2() {
|
||||
BasalProfile basalProfile = new BasalProfile();
|
||||
byte[] data = { //
|
||||
0x32, 0x00, 0x00, 0x2C, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
basalProfile.setRawData(data);
|
||||
|
||||
Double[] profilesByHour = basalProfile.getProfilesByHour();
|
||||
|
||||
System.out.println("Basals by hour: "
|
||||
+ (profilesByHour == null ? "null" : StringUtils.join(profilesByHour, " ")));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue