- fixes for Bolus problems

This commit is contained in:
Andy Rozman 2019-04-12 21:20:09 +01:00
parent ad17c66b1b
commit c7f6eb79f0
7 changed files with 210 additions and 355 deletions

View file

@ -65,7 +65,7 @@ android {
multiDexEnabled true multiDexEnabled true
versionCode 1500 versionCode 1500
// dev_version: 2.2.3-dev // dev_version: 2.2.3-dev
version "medtronic-0.9.2-SNAPSHOT" version "medtronic-0.9.3-SNAPSHOT"
buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "VERSION", '"' + version + '"'
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"' buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"'

View file

@ -19,17 +19,14 @@ 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.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.general.careportal.CareportalPlugin;
import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin;
import info.nightscout.androidaps.plugins.insulin.InsulinOrefFreePeakPlugin;
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin; import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin; import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin;
import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin;
import info.nightscout.androidaps.plugins.general.careportal.CareportalPlugin;
import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin;
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin;
import info.nightscout.androidaps.plugins.general.wear.WearPlugin;
import info.nightscout.androidaps.plugins.general.xdripStatusline.StatuslinePlugin;
import info.nightscout.androidaps.plugins.insulin.InsulinOrefFreePeakPlugin;
import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin; import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin; import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin; import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin;
@ -42,16 +39,17 @@ import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref0Plugin; import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref0Plugin;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin; import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin;
import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin; import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin;
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin;
import info.nightscout.androidaps.plugins.source.SourceDexcomG5Plugin; import info.nightscout.androidaps.plugins.source.SourceDexcomG5Plugin;
import info.nightscout.androidaps.plugins.general.wear.WearPlugin;
import info.nightscout.androidaps.plugins.general.xdripStatusline.StatuslinePlugin;
import info.nightscout.androidaps.utils.LocaleHelper; import info.nightscout.androidaps.utils.LocaleHelper;
import info.nightscout.androidaps.utils.OKDialog; import info.nightscout.androidaps.utils.OKDialog;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
public class PreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener { public class PreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
MyPreferenceFragment myPreferenceFragment; MyPreferenceFragment myPreferenceFragment;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -63,7 +61,6 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this); PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
} }
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
MainApp.bus().post(new EventPreferenceChange(key)); MainApp.bus().post(new EventPreferenceChange(key));
@ -71,21 +68,18 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
String lang = sharedPreferences.getString("language", "en"); String lang = sharedPreferences.getString("language", "en");
LocaleHelper.setLocale(getApplicationContext(), lang); LocaleHelper.setLocale(getApplicationContext(), lang);
MainApp.bus().post(new EventRefreshGui(true)); MainApp.bus().post(new EventRefreshGui(true));
// recreate() does not update language so better close settings //recreate() does not update language so better close settings
finish(); finish();
} }
if (key.equals("short_tabtitles")) { if (key.equals("short_tabtitles")) {
MainApp.bus().post(new EventRefreshGui()); MainApp.bus().post(new EventRefreshGui());
} }
if (key.equals(MainApp.gs(R.string.key_openapsama_useautosens)) if (key.equals(MainApp.gs(R.string.key_openapsama_useautosens)) && SP.getBoolean(R.string.key_openapsama_useautosens, false)) {
&& SP.getBoolean(R.string.key_openapsama_useautosens, false)) { OKDialog.show(this, MainApp.gs(R.string.configbuilder_sensitivity), MainApp.gs(R.string.sensitivity_warning), null);
OKDialog.show(this, MainApp.gs(R.string.configbuilder_sensitivity),
MainApp.gs(R.string.sensitivity_warning), null);
} }
updatePrefSummary(myPreferenceFragment.getPreference(key)); updatePrefSummary(myPreferenceFragment.getPreference(key));
} }
private static void updatePrefSummary(Preference pref) { private static void updatePrefSummary(Preference pref) {
if (pref instanceof ListPreference) { if (pref instanceof ListPreference) {
ListPreference listPref = (ListPreference) pref; ListPreference listPref = (ListPreference) pref;
@ -100,14 +94,12 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
} else if (editTextPref.getText() != null) { } else if (editTextPref.getText() != null) {
((EditTextPreference) pref).setDialogMessage(editTextPref.getDialogMessage()); ((EditTextPreference) pref).setDialogMessage(editTextPref.getDialogMessage());
pref.setSummary(editTextPref.getText()); pref.setSummary(editTextPref.getText());
} else if (pref.getKey().contains("smscommunicator_allowednumbers") } else if (pref.getKey().contains("smscommunicator_allowednumbers") && TextUtils.isEmpty(editTextPref.getText().trim())) {
&& TextUtils.isEmpty(editTextPref.getText().trim())) {
pref.setSummary(MainApp.gs(R.string.smscommunicator_allowednumbers_summary)); pref.setSummary(MainApp.gs(R.string.smscommunicator_allowednumbers_summary));
} }
} }
} }
public static void initSummary(Preference p) { public static void initSummary(Preference p) {
if (p instanceof PreferenceGroup) { if (p instanceof PreferenceGroup) {
PreferenceGroup pGrp = (PreferenceGroup) p; PreferenceGroup pGrp = (PreferenceGroup) p;
@ -120,23 +112,19 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
} }
public static class MyPreferenceFragment extends PreferenceFragment { public static class MyPreferenceFragment extends PreferenceFragment {
private Integer id; private Integer id;
@Override @Override
public void setArguments(Bundle args) { public void setArguments(Bundle args) {
super.setArguments(args); super.setArguments(args);
id = args.getInt("id"); id = args.getInt("id");
} }
void addPreferencesFromResourceIfEnabled(PluginBase p, PluginType type) { void addPreferencesFromResourceIfEnabled(PluginBase p, PluginType type) {
if (p.isEnabled(type) && p.getPreferencesId() != -1) if (p.isEnabled(type) && p.getPreferencesId() != -1)
addPreferencesFromResource(p.getPreferencesId()); addPreferencesFromResource(p.getPreferencesId());
} }
@Override @Override
public void onCreate(final Bundle savedInstanceState) { public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -168,8 +156,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
} }
addPreferencesFromResourceIfEnabled(SensitivityAAPSPlugin.getPlugin(), PluginType.SENSITIVITY); addPreferencesFromResourceIfEnabled(SensitivityAAPSPlugin.getPlugin(), PluginType.SENSITIVITY);
addPreferencesFromResourceIfEnabled(SensitivityWeightedAveragePlugin.getPlugin(), addPreferencesFromResourceIfEnabled(SensitivityWeightedAveragePlugin.getPlugin(), PluginType.SENSITIVITY);
PluginType.SENSITIVITY);
addPreferencesFromResourceIfEnabled(SensitivityOref0Plugin.getPlugin(), PluginType.SENSITIVITY); addPreferencesFromResourceIfEnabled(SensitivityOref0Plugin.getPlugin(), PluginType.SENSITIVITY);
addPreferencesFromResourceIfEnabled(SensitivityOref1Plugin.getPlugin(), PluginType.SENSITIVITY); addPreferencesFromResourceIfEnabled(SensitivityOref1Plugin.getPlugin(), PluginType.SENSITIVITY);
@ -207,16 +194,12 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
} }
if (Config.NSCLIENT) { if (Config.NSCLIENT) {
PreferenceScreen scrnAdvancedSettings = (PreferenceScreen) findPreference(getString(R.string.key_advancedsettings)); PreferenceScreen scrnAdvancedSettings = (PreferenceScreen)findPreference(getString(R.string.key_advancedsettings));
if (scrnAdvancedSettings != null) { if (scrnAdvancedSettings != null) {
scrnAdvancedSettings scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_res_warning)));
.removePreference(getPreference(getString(R.string.key_statuslights_res_warning))); scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_res_critical)));
scrnAdvancedSettings scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_bat_warning)));
.removePreference(getPreference(getString(R.string.key_statuslights_res_critical))); scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_bat_critical)));
scrnAdvancedSettings
.removePreference(getPreference(getString(R.string.key_statuslights_bat_warning)));
scrnAdvancedSettings
.removePreference(getPreference(getString(R.string.key_statuslights_bat_critical)));
scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_show_statuslights))); scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_show_statuslights)));
} }
} }
@ -224,14 +207,12 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
initSummary(getPreferenceScreen()); initSummary(getPreferenceScreen());
} }
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
outState.putInt("id", id); outState.putInt("id", id);
} }
public Preference getPreference(String key) { public Preference getPreference(String key) {
return findPreference(key); return findPreference(key);
} }

View file

@ -1,12 +1,12 @@
package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump; package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil; import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.HexDump; import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
@ -23,7 +23,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
/** /**
* This file was taken from GGC - GNU Gluco Control and modified/extended for AAPS. * This file was taken from GGC - GNU Gluco Control and modified/extended for AAPS.
* * <p>
* Author: Andy {andy.rozman@gmail.com} * Author: Andy {andy.rozman@gmail.com}
*/ */
@ -94,17 +94,17 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
} }
List<Byte> listRawData = new ArrayList<Byte>(); List<Byte> listRawData = new ArrayList<Byte>();
listRawData.add((byte)opCode); listRawData.add((byte) opCode);
if (entryType == PumpHistoryEntryType.UnabsorbedInsulin) { if (entryType == PumpHistoryEntryType.UnabsorbedInsulin) {
int elements = dataClear.get(counter); int elements = dataClear.get(counter);
listRawData.add((byte)elements); listRawData.add((byte) elements);
counter++; counter++;
int els = getUnsignedInt(elements); int els = getUnsignedInt(elements);
for (int k = 0; k < (els - 2); k++) { for (int k = 0; k < (els - 2); k++) {
listRawData.add((byte)dataClear.get(counter)); listRawData.add((byte) dataClear.get(counter));
counter++; counter++;
} }
@ -117,8 +117,8 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
listRawData.add(dataClear.get(counter)); listRawData.add(dataClear.get(counter));
counter++; counter++;
} catch (Exception ex) { } catch (Exception ex) {
LOG.error("OpCode: " + HexDump.getCorrectHexValue((byte)opCode) + ", Invalid package: " LOG.error("OpCode: " + HexDump.getCorrectHexValue((byte) opCode) + ", Invalid package: "
+ HexDump.toHexStringDisplayable(listRawData)); + HexDump.toHexStringDisplayable(listRawData));
// throw ex; // throw ex;
incompletePacket = true; incompletePacket = true;
break; break;
@ -205,7 +205,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
case ChangeBasalPattern: case ChangeBasalPattern:
return RecordDecodeStatus.OK; // Not supported at the moment return RecordDecodeStatus.OK; // Not supported at the moment
// AAPS Implementation - Ignored entries // AAPS Implementation - Ignored entries
case CalBGForPH: case CalBGForPH:
case ChangeRemoteId: case ChangeRemoteId:
case ClearAlarm: case ClearAlarm:
@ -255,9 +255,9 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
case ReadOtherDevicesStatus: case ReadOtherDevicesStatus:
return RecordDecodeStatus.OK; return RecordDecodeStatus.OK;
// case ChangeWatchdogMarriageProfile: // case ChangeWatchdogMarriageProfile:
// case DeleteOtherDeviceID: // case DeleteOtherDeviceID:
// case ChangeCaptureEventEnable: // case ChangeCaptureEventEnable:
case Sensor54: case Sensor54:
case Sensor55: case Sensor55:
case Sensor51: case Sensor51:
@ -287,7 +287,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
LOG.debug(" -- ignored Pump Entry: " + entry); LOG.debug(" -- ignored Pump Entry: " + entry);
return RecordDecodeStatus.Ignored; return RecordDecodeStatus.Ignored;
// **** Implemented records **** // **** Implemented records ****
case DailyTotals522: case DailyTotals522:
case DailyTotals523: case DailyTotals523:
@ -357,11 +357,11 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
case UnknownBasePacket: case UnknownBasePacket:
return RecordDecodeStatus.Error; return RecordDecodeStatus.Error;
// case Andy0d: // case Andy0d:
// case Andy58: // case Andy58:
// case Andy90: // case Andy90:
default: { default: {
LOG.debug("Not supported: " + entry.getEntryType()); LOG.debug("Not supported: " + entry.getEntryType());
@ -483,8 +483,8 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
// FIXME 554 ? // FIXME 554 ?
private void decodeEndResultTotals(PumpHistoryEntry entry) { private void decodeEndResultTotals(PumpHistoryEntry entry) {
float totals = bitUtils.toInt((int)entry.getHead()[0], (int)entry.getHead()[1], (int)entry.getHead()[2], float totals = bitUtils.toInt((int) entry.getHead()[0], (int) entry.getHead()[1], (int) entry.getHead()[2],
(int)entry.getHead()[3], ByteUtil.BitConversion.BIG_ENDIAN) * 0.025f; (int) entry.getHead()[3], ByteUtil.BitConversion.BIG_ENDIAN) * 0.025f;
entry.addDecodedData("Totals", totals); entry.addDecodedData("Totals", totals);
entry.setDisplayableValue(getFormattedValue(totals, 3)); entry.setDisplayableValue(getFormattedValue(totals, 3));
@ -508,13 +508,13 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
int index = body[2]; int index = body[2];
if (MedtronicDeviceType.isSameDevice(MedtronicUtil.getMedtronicPumpModel(), if (MedtronicDeviceType.isSameDevice(MedtronicUtil.getMedtronicPumpModel(),
MedtronicDeviceType.Medtronic_523andHigher)) { MedtronicDeviceType.Medtronic_523andHigher)) {
rate = body[1] * 0.025f; rate = body[1] * 0.025f;
} }
if (rate == null) { if (rate == null) {
LOG.warn("Basal Profile Start (ERROR): offset={}, rate={}, index={}, body_raw={}", offset, rate, index, LOG.warn("Basal Profile Start (ERROR): offset={}, rate={}, index={}, body_raw={}", offset, rate, index,
body); body);
return RecordDecodeStatus.Error; return RecordDecodeStatus.Error;
} else { } else {
// writeData(PumpBaseType.Basal, PumpBasalType.ValueChange, getFormattedFloat(rate, 3), // writeData(PumpBaseType.Basal, PumpBasalType.ValueChange, getFormattedFloat(rate, 3),
@ -535,7 +535,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
float bolus_strokes = 10.0f; float bolus_strokes = 10.0f;
if (MedtronicDeviceType.isSameDevice(MedtronicUtil.getMedtronicPumpModel(), if (MedtronicDeviceType.isSameDevice(MedtronicUtil.getMedtronicPumpModel(),
MedtronicDeviceType.Medtronic_523andHigher)) { MedtronicDeviceType.Medtronic_523andHigher)) {
// https://github.com/ps2/minimed_rf/blob/master/lib/minimed_rf/log_entries/bolus_wizard.rb#L102 // https://github.com/ps2/minimed_rf/blob/master/lib/minimed_rf/log_entries/bolus_wizard.rb#L102
bolus_strokes = 40.0f; bolus_strokes = 40.0f;
@ -546,19 +546,19 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
// carb_ratio (?) = (((self.body[2] & 0x07) << 8) + self.body[3]) / // carb_ratio (?) = (((self.body[2] & 0x07) << 8) + self.body[3]) /
// 10.0s // 10.0s
dto.insulinSensitivity = new Float(body[4]); dto.insulinSensitivity = new Float(body[4]);
dto.bgTargetLow = (int)body[5]; dto.bgTargetLow = (int) body[5];
dto.bgTargetHigh = (int)body[14]; dto.bgTargetHigh = (int) body[14];
dto.correctionEstimate = (((body[9] & 0x38) << 5) + body[6]) / bolus_strokes; dto.correctionEstimate = (((body[9] & 0x38) << 5) + body[6]) / bolus_strokes;
dto.foodEstimate = ((body[7] << 8) + body[8]) / bolus_strokes; dto.foodEstimate = ((body[7] << 8) + body[8]) / bolus_strokes;
dto.unabsorbedInsulin = ((body[10] << 8) + body[11]) / bolus_strokes; dto.unabsorbedInsulin = ((body[10] << 8) + body[11]) / bolus_strokes;
dto.bolusTotal = ((body[12] << 8) + body[13]) / bolus_strokes; dto.bolusTotal = ((body[12] << 8) + body[13]) / bolus_strokes;
} else { } else {
dto.bloodGlucose = (((body[1] & 0x0F) << 8) | entry.getHead()[0]); dto.bloodGlucose = (((body[1] & 0x0F) << 8) | entry.getHead()[0]);
dto.carbs = (int)body[0]; dto.carbs = (int) body[0];
dto.carbRatio = Float.valueOf(body[2]); dto.carbRatio = Float.valueOf(body[2]);
dto.insulinSensitivity = new Float(body[3]); dto.insulinSensitivity = new Float(body[3]);
dto.bgTargetLow = (int)body[4]; dto.bgTargetLow = (int) body[4];
dto.bgTargetHigh = (int)body[12]; dto.bgTargetHigh = (int) body[12];
dto.bolusTotal = body[11] / 10.0f; dto.bolusTotal = body[11] / 10.0f;
dto.foodEstimate = body[6] / 10.0f; dto.foodEstimate = body[6] / 10.0f;
dto.unabsorbedInsulin = body[9] / 10.0f; dto.unabsorbedInsulin = body[9] / 10.0f;
@ -598,7 +598,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
entry.addDecodedData("FixedAmount", fixed); entry.addDecodedData("FixedAmount", fixed);
entry.setDisplayableValue("Amount=" + getFormattedValue(amount, 2) + ", Fixed Amount=" entry.setDisplayableValue("Amount=" + getFormattedValue(amount, 2) + ", Fixed Amount="
+ getFormattedValue(fixed, 2)); + getFormattedValue(fixed, 2));
// amount = (double) (asUINT8(data[4]) << 2) / 40.0; // amount = (double) (asUINT8(data[4]) << 2) / 40.0;
// programmedAmount = (double) (asUINT8(data[2]) << 2) / 40.0; // programmedAmount = (double) (asUINT8(data[2]) << 2) / 40.0;
@ -630,19 +630,19 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
byte[] data = entry.getHead(); byte[] data = entry.getHead();
if (MedtronicDeviceType.isSameDevice(MedtronicUtil.getMedtronicPumpModel(), if (MedtronicDeviceType.isSameDevice(MedtronicUtil.getMedtronicPumpModel(),
MedtronicDeviceType.Medtronic_523andHigher)) { MedtronicDeviceType.Medtronic_523andHigher)) {
bolus.setRequestedAmount(ByteUtil.toInt(data[0], data[1]) / 40.0f); bolus.setRequestedAmount(ByteUtil.toInt(data[0], data[1]) / 40.0d);
bolus.setDeliveredAmount(ByteUtil.toInt(data[2], data[3]) / 40.0f); bolus.setDeliveredAmount(ByteUtil.toInt(data[2], data[3]) / 40.0d);
bolus.setInsulinOnBoard(ByteUtil.toInt(data[4], data[5]) / 40.0f); bolus.setInsulinOnBoard(ByteUtil.toInt(data[4], data[5]) / 40.0d);
bolus.setDuration(data[6] * 30); bolus.setDuration(data[6] * 30);
} else { } else {
bolus.setRequestedAmount(ByteUtil.asUINT8(data[0]) / 10.0f); bolus.setRequestedAmount(ByteUtil.asUINT8(data[0]) / 10.0d);
bolus.setDeliveredAmount(ByteUtil.asUINT8(data[1]) / 10.0f); bolus.setDeliveredAmount(ByteUtil.asUINT8(data[1]) / 10.0d);
bolus.setDuration(ByteUtil.asUINT8(data[2]) * 30); bolus.setDuration(ByteUtil.asUINT8(data[2]) * 30);
} }
bolus.setBolusType((bolus.getDuration() != null && (bolus.getDuration() > 0)) ? PumpBolusType.Extended bolus.setBolusType((bolus.getDuration() != null && (bolus.getDuration() > 0)) ? PumpBolusType.Extended
: PumpBolusType.Normal); : PumpBolusType.Normal);
bolus.setAtechDateTime(entry.atechDateTime); bolus.setAtechDateTime(entry.atechDateTime);
// String dateTime = entry.DT; // String dateTime = entry.DT;
@ -699,7 +699,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
} }
TempBasalPair tbr = new TempBasalPair(tbrRate.getHead()[0], tbrDuration.getHead()[0], (ByteUtil.asUINT8(tbrRate TempBasalPair tbr = new TempBasalPair(tbrRate.getHead()[0], tbrDuration.getHead()[0], (ByteUtil.asUINT8(tbrRate
.getDatetime()[4]) >> 3) == 0); .getDatetime()[4]) >> 3) == 0);
// System.out.println("TBR: amount=" + tbr.getInsulinRate() + ", duration=" + tbr.getDurationMinutes() // System.out.println("TBR: amount=" + tbr.getInsulinRate() + ", duration=" + tbr.getDurationMinutes()
// // + " min. Packed: " + tbr.getValue() // // + " min. Packed: " + tbr.getValue()
@ -729,7 +729,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
int dayOfMonth = dt[3] & 0x1F; int dayOfMonth = dt[3] & 0x1F;
int year = fix2DigitYear(dt[4] & 0x3F); // Assuming this is correct, need to verify. Otherwise this will be int year = fix2DigitYear(dt[4] & 0x3F); // Assuming this is correct, need to verify. Otherwise this will be
// a problem in 2016. // a problem in 2016.
entry.setAtechDateTime(DateTimeUtil.toATechDate(year, month, dayOfMonth, hour, minutes, seconds)); entry.setAtechDateTime(DateTimeUtil.toATechDate(year, month, dayOfMonth, hour, minutes, seconds));
@ -757,7 +757,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
if (dayOfMonth == 32) { if (dayOfMonth == 32) {
// FIXME remove // FIXME remove
LOG.debug("Entry: Day 32 {} = [{}] {}", entry.getEntryType().name(), LOG.debug("Entry: Day 32 {} = [{}] {}", entry.getEntryType().name(),
ByteUtil.getHex(entry.getRawData()), entry); ByteUtil.getHex(entry.getRawData()), entry);
} }
if (entry.getEntryType() == PumpHistoryEntryType.EndResultTotals) { if (entry.getEntryType() == PumpHistoryEntryType.EndResultTotals) {

View file

@ -605,8 +605,6 @@ public class MedtronicHistoryData {
switch (bolusDTO.getBolusType()) { switch (bolusDTO.getBolusType()) {
case Normal: { case Normal: {
// DetailedBolusInfo normalBolus = new DetailedBolusInfo();
DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo(); DetailedBolusInfo detailedBolusInfo = new DetailedBolusInfo();
detailedBolusInfo.date = tryToGetByLocalTime(bolus.atechDateTime); detailedBolusInfo.date = tryToGetByLocalTime(bolus.atechDateTime);
@ -618,10 +616,6 @@ public class MedtronicHistoryData {
bolus.setLinkedObject(detailedBolusInfo); bolus.setLinkedObject(detailedBolusInfo);
// bolus.setLinkedObject(normalBolus);
// TreatmentsPlugin.getPlugin().addToHistoryTreatment(normalBolus, false);
if (L.isEnabled(L.PUMPCOMM)) if (L.isEnabled(L.PUMPCOMM))
LOG.debug("addBolus - [date={},pumpId={}, insulin={}, newRecord={}]", detailedBolusInfo.date, LOG.debug("addBolus - [date={},pumpId={}, insulin={}, newRecord={}]", detailedBolusInfo.date,
detailedBolusInfo.pumpId, detailedBolusInfo.insulin, newRecord); detailedBolusInfo.pumpId, detailedBolusInfo.insulin, newRecord);
@ -652,23 +646,6 @@ public class MedtronicHistoryData {
} else { } else {
boolean old = false;
// if (old) {
// treatment.insulin = bolusDTO.getDeliveredAmount();
// treatment.pumpId = bolus.getPumpId();
// treatment.source = Source.PUMP;
//
// bolus.setLinkedObject(treatment);
//
// TreatmentsPlugin.getPlugin().getService().createOrUpdate(treatment);
//
// LOG.debug("editBolus - [date={},pumpId={}, insulin={}]", treatment.date, treatment.pumpId,
// treatment.insulin);
//
// MainApp.bus().post(new EventTreatmentChange(treatment));
// } else {
DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(treatment.date); DetailedBolusInfo detailedBolusInfo = DetailedBolusInfoStorage.findDetailedBolusInfo(treatment.date);
if (detailedBolusInfo == null) { if (detailedBolusInfo == null) {
detailedBolusInfo = new DetailedBolusInfo(); detailedBolusInfo = new DetailedBolusInfo();
@ -678,6 +655,7 @@ public class MedtronicHistoryData {
detailedBolusInfo.source = Source.PUMP; detailedBolusInfo.source = Source.PUMP;
detailedBolusInfo.pumpId = bolus.getPumpId(); detailedBolusInfo.pumpId = bolus.getPumpId();
detailedBolusInfo.insulin = bolusDTO.getDeliveredAmount(); detailedBolusInfo.insulin = bolusDTO.getDeliveredAmount();
detailedBolusInfo.carbs = treatment.carbs;
boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false); boolean newRecord = TreatmentsPlugin.getPlugin().addToHistoryTreatment(detailedBolusInfo, false);

View file

@ -29,16 +29,16 @@ import info.nightscout.androidaps.plugins.pump.medtronic.defs.PumpBolusType;
public class BolusDTO extends PumpTimeStampedRecord { public class BolusDTO extends PumpTimeStampedRecord {
@Expose @Expose
private Float requestedAmount; private Double requestedAmount;
@Expose @Expose
private Float deliveredAmount; private Double deliveredAmount;
@Expose @Expose
private Float immediateAmount; // when Multiwave this is used private Double immediateAmount; // when Multiwave this is used
@Expose @Expose
private Integer duration; private Integer duration;
@Expose @Expose
private PumpBolusType bolusType; private PumpBolusType bolusType;
private Float insulinOnBoard; private Double insulinOnBoard;
public BolusDTO() { public BolusDTO() {
@ -46,22 +46,22 @@ public class BolusDTO extends PumpTimeStampedRecord {
} }
public Float getRequestedAmount() { public Double getRequestedAmount() {
return requestedAmount; return requestedAmount;
} }
public void setRequestedAmount(Float requestedAmount) { public void setRequestedAmount(Double requestedAmount) {
this.requestedAmount = requestedAmount; this.requestedAmount = requestedAmount;
} }
public Float getDeliveredAmount() { public Double getDeliveredAmount() {
return deliveredAmount; return deliveredAmount;
} }
public void setDeliveredAmount(Float deliveredAmount) { public void setDeliveredAmount(Double deliveredAmount) {
this.deliveredAmount = deliveredAmount; this.deliveredAmount = deliveredAmount;
} }
@ -86,12 +86,12 @@ public class BolusDTO extends PumpTimeStampedRecord {
} }
public Float getInsulinOnBoard() { public Double getInsulinOnBoard() {
return insulinOnBoard; return insulinOnBoard;
} }
public void setInsulinOnBoard(Float insulinOnBoard) { public void setInsulinOnBoard(Double insulinOnBoard) {
this.insulinOnBoard = insulinOnBoard; this.insulinOnBoard = insulinOnBoard;
} }
@ -112,10 +112,10 @@ public class BolusDTO extends PumpTimeStampedRecord {
return getFormattedDecimal(this.deliveredAmount); return getFormattedDecimal(this.deliveredAmount);
} else if (bolusType == PumpBolusType.Extended) { } else if (bolusType == PumpBolusType.Extended) {
return String.format("AMOUNT_SQUARE=%s;DURATION=%s", getFormattedDecimal(this.deliveredAmount), return String.format("AMOUNT_SQUARE=%s;DURATION=%s", getFormattedDecimal(this.deliveredAmount),
getDurationString()); getDurationString());
} else { } else {
return String.format("AMOUNT=%s;AMOUNT_SQUARE=%s;DURATION=%s", getFormattedDecimal(this.immediateAmount), return String.format("AMOUNT=%s;AMOUNT_SQUARE=%s;DURATION=%s", getFormattedDecimal(this.immediateAmount),
getFormattedDecimal(this.deliveredAmount), getDurationString()); getFormattedDecimal(this.deliveredAmount), getDurationString());
} }
} }
@ -131,12 +131,12 @@ public class BolusDTO extends PumpTimeStampedRecord {
} }
public Float getImmediateAmount() { public Double getImmediateAmount() {
return immediateAmount; return immediateAmount;
} }
public void setImmediateAmount(Float immediateAmount) { public void setImmediateAmount(Double immediateAmount) {
this.immediateAmount = immediateAmount; this.immediateAmount = immediateAmount;
} }

View file

@ -108,9 +108,9 @@ public class Treatment implements DataPointWithLabelInterface {
public boolean isDataChanging(Treatment other) { public boolean isDataChanging(Treatment other) {
if (date != other.date) if (date != other.date)
return true; return true;
if (insulin != other.insulin) if (!isSame(insulin, other.insulin))
return true; return true;
if (carbs != other.carbs) if (!isSame(carbs, other.carbs))
return true; return true;
return false; return false;
} }
@ -118,9 +118,9 @@ public class Treatment implements DataPointWithLabelInterface {
public boolean isEqual(Treatment other) { public boolean isEqual(Treatment other) {
if (date != other.date) if (date != other.date)
return false; return false;
if (insulin != other.insulin) if (!isSame(insulin, other.insulin))
return false; return false;
if (carbs != other.carbs) if (!isSame(carbs, other.carbs))
return false; return false;
if (mealBolus != other.mealBolus) if (mealBolus != other.mealBolus)
return false; return false;
@ -136,9 +136,9 @@ public class Treatment implements DataPointWithLabelInterface {
public boolean isEqualWithoutPumpId(Treatment other) { public boolean isEqualWithoutPumpId(Treatment other) {
if (date != other.date) if (date != other.date)
return false; return false;
if (insulin != other.insulin) if (!isSame(insulin, other.insulin))
return false; return false;
if (carbs != other.carbs) if (!isSame(carbs, other.carbs))
return false; return false;
if (mealBolus != other.mealBolus) if (mealBolus != other.mealBolus)
return false; return false;
@ -149,6 +149,11 @@ public class Treatment implements DataPointWithLabelInterface {
return true; return true;
} }
public boolean isSame(Double d1, Double d2) {
double diff = d1 - d2;
return (Math.abs(diff) <= 0.000001);
}
@Nullable @Nullable
public JSONObject getBoluscalc() { public JSONObject getBoluscalc() {
@ -168,12 +173,13 @@ public class Treatment implements DataPointWithLabelInterface {
if (date != other.date) { if (date != other.date) {
return false; return false;
} }
if (insulin != other.insulin) {
if (!isSame(insulin, other.insulin))
return false; return false;
}
if (carbs != other.carbs) { if (!isSame(carbs, other.carbs))
return false; return false;
}
return true; return true;
} }