- fixed problem with TDD

- added new command/action for Reset RileyLink (not working yet)
- added Hardware encoding for RileyLink
This commit is contained in:
Andy Rozman 2019-05-05 17:22:10 +01:00
parent cff20f78c8
commit 2ae7d0a292
18 changed files with 222 additions and 244 deletions

View file

@ -101,11 +101,11 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 25
targetSdkVersion 26
multiDexEnabled true
versionCode 1500
// dev_version: 2.3.1-dev
version "medtronic-0.9.6-SNAPSHOT"
version "medtronic-0.9.7-SNAPSHOT"
buildConfigField "String", "VERSION", '"' + version + '"'
buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"'
buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"'
@ -261,6 +261,7 @@ dependencies {
implementation "uk.com.robust-it:cloning:1.9.9"
implementation 'org.mozilla:rhino:1.7.7.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.jakewharton:butterknife:${butterknifeVersion}"
annotationProcessor "com.jakewharton:butterknife-compiler:${butterknifeVersion}"
@ -282,7 +283,6 @@ dependencies {
androidTestImplementation "org.mockito:mockito-core:2.8.47"
androidTestImplementation "com.google.dexmaker:dexmaker:${dexmakerVersion}"
androidTestImplementation "com.google.dexmaker:dexmaker-mockito:${dexmakerVersion}"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
task unzip(type: Copy) {

View file

@ -542,14 +542,13 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
GregorianCalendar gc = new GregorianCalendar();
gc.add(Calendar.DAY_OF_YEAR, (-1) * days);
Date d = new Date(gc.get(Calendar.YEAR), gc.get(Calendar.MONTH), gc.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
Date d = new Date((gc.get(Calendar.YEAR)-1900), gc.get(Calendar.MONTH), gc.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
try {
QueryBuilder<TDD, String> queryBuilder = getDaoTDD().queryBuilder();
queryBuilder.orderBy("date", false);
Where<TDD, String> where = queryBuilder.where();
where.ge("date", d.getTime());
queryBuilder.limit(10L);
PreparedQuery<TDD> preparedQuery = queryBuilder.prepare();
tddList = getDaoTDD().query(preparedQuery);
} catch (SQLException e) {

View file

@ -273,10 +273,8 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
this.pumpCustomActions.put(MainApp.gs(customAction.getName()), customAction);
this.pumpCustomButtons.add(btn);
}
}
}
@ -292,7 +290,6 @@ public class ActionsFragment extends SubscriberFragment implements View.OnClickL
}
pumpCustomButtons.clear();
pumpCustomActions.clear();
}

View file

@ -24,6 +24,9 @@ public class CustomAction {
this(nameResourceId, actionType, iconResourceId, true);
}
public CustomAction(int nameResourceId, CustomActionType actionType, boolean enabled) {
this(nameResourceId, actionType, R.drawable.icon_actions_profileswitch, enabled);
}
public CustomAction(int nameResourceId, CustomActionType actionType, int iconResourceId, boolean enabled) {
this.name = nameResourceId;

View file

@ -7,7 +7,13 @@ import org.slf4j.LoggerFactory;
import android.os.SystemClock;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.Reset;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.ResetRadioConfig;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.RileyLinkCommand;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.SendAndListen;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command.SetHardwareEncoding;
@ -23,10 +29,15 @@ import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.Rile
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkFirmwareVersion;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkTargetFrequency;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.operations.BLECommOperationResult;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.HexDump;
import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil;
import info.nightscout.androidaps.plugins.pump.common.utils.ThreadUtil;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCustomActionType;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
import info.nightscout.androidaps.utils.SP;
/**
* Created by geoff on 5/26/16.
@ -84,6 +95,12 @@ public class RFSpy {
bleVersion = getVersion();
firmwareVersion = getFirmwareVersion();
RileyLinkUtil.setFirmwareVersion(firmwareVersion);
if (RileyLinkFirmwareVersion.isSameVersion(firmwareVersion, RileyLinkFirmwareVersion.Version2AndHigher)) {
if (RileyLinkUtil.getRileyLinkServiceData().targetDevice == RileyLinkTargetDevice.MedtronicPump) {
//MedtronicPumpPlugin.getPlugin().setEnableCustomAction(MedtronicCustomActionType.ResetRileyLink, true);
}
}
}
@ -278,9 +295,6 @@ public class RFSpy {
}
// FIXME: to be able to work with Omnipod we need to support preamble extensions so we should create a class for the
// SnedAndListen RL command
// To avoid snedAndListen command assembly magic
public RFSpyResponse transmitThenReceive(RadioPacket pkt, byte sendChannel, byte repeatCount, byte delay_ms,
byte listenChannel, int timeout_ms, byte retryCount, Integer extendPreamble_ms) {
@ -305,7 +319,7 @@ public class RFSpy {
updateRegister(CC111XRegister.freq0, (byte)(value & 0xff));
updateRegister(CC111XRegister.freq1, (byte)((value >> 8) & 0xff));
updateRegister(CC111XRegister.freq2, (byte)((value >> 16) & 0xff));
LOG.warn("Set frequency to {}", freqMHz);
LOG.info("Set frequency to {}", freqMHz);
configureRadioForRegion(RileyLinkUtil.getRileyLinkTargetFrequency());
}
@ -314,8 +328,6 @@ public class RFSpy {
private void configureRadioForRegion(RileyLinkTargetFrequency frequency) {
// we update registers only on first run, or if region changed
if (selectedTargetFrequency == frequency)
return;
switch (frequency) {
case Medtronic_WorldWide: {
@ -386,11 +398,15 @@ public class RFSpy {
private void setMedtronicEncoding() {
// FIXME
if (RileyLinkFirmwareVersion.isSameVersion(this.firmwareVersion, RileyLinkFirmwareVersion.Version2AndHigher)) {
// check settings if RileyLink_4b6b is enabled, and then check if we have version 2.2 or higher, if both
// are yes then we set encoding on RileyLink and set it in RileyLinkUtil.
if (SP.getString(MedtronicConst.Prefs.Encoding, "None").equals(MainApp.gs(R.string.medtronic_pump_encoding_4b6b_rileylink))) {
setSoftwareEncoding(RileyLinkEncodingType.FourByteSixByteRileyLink);
RileyLinkUtil.setEncoding(RileyLinkEncodingType.FourByteSixByteRileyLink);
}
}
LOG.debug("Set Encoding for Medtronic: " + RileyLinkUtil.getEncoding().name());
}
@ -419,4 +435,20 @@ public class RFSpy {
updateRegister(CC111XRegister.mdmcfg4, (byte)(chanbw | drate_e));
}
public RFSpyResponse resetRileyLinkDevice() {
// FIXME not working correctly yet
RFSpyResponse resp = null;
try {
resp = writeToData(new Reset(), EXPECTED_MAX_BLUETOOTH_LATENCY_MS);
if (isLogEnabled())
LOG.debug("Reset command send, response: {}", resp);
} catch (Exception e) {
e.toString();
}
return resp;
}
private boolean isLogEnabled() {
return L.isEnabled(L.PUMPCOMM);
}
}

View file

@ -0,0 +1,22 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkCommandType;
public class Reset extends RileyLinkCommand {
public Reset() {
super();
}
@Override
public RileyLinkCommandType getCommandType() {
return RileyLinkCommandType.Reset;
}
@Override
public byte[] getRaw() {
return super.getRawSimple();
}
}

View file

@ -0,0 +1,22 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.command;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.defs.RileyLinkCommandType;
public class ResetRadioConfig extends RileyLinkCommand {
public ResetRadioConfig() {
super();
}
@Override
public RileyLinkCommandType getCommandType() {
return RileyLinkCommandType.ResetRadioConfig;
}
@Override
public byte[] getRaw() {
return super.getRawSimple();
}
}

View file

@ -0,0 +1,35 @@
package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.ble.RFSpy;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.data.ServiceTransport;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicFragment;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.service.RileyLinkMedtronicService;
/**
* Created by geoff on 7/16/16.
*/
public class ResetRileyLinkTask extends PumpTask {
private static final String TAG = "ResetRileyLinkTask";
public ResetRileyLinkTask() {
}
public ResetRileyLinkTask(ServiceTransport transport) {
super(transport);
}
@Override
public void run() {
MedtronicFragment.refreshButtonEnabled(false);
MedtronicPumpPlugin.isBusy = true;
RileyLinkMedtronicService.getInstance().resetRileyLinkDevice();
MedtronicPumpPlugin.isBusy = false;
MedtronicFragment.refreshButtonEnabled(true);
}
}

View file

@ -116,9 +116,9 @@ public class DateTimeUtil {
long atechDateTime = 0L;
atechDateTime += date.getYear() * 10000000000L;
atechDateTime += date.getMonth() * 100000000L;
atechDateTime += date.getDay() * 1000000L;
atechDateTime += (date.getYear() + 1900) * 10000000000L;
atechDateTime += (date.getMonth() +1) * 100000000L;
atechDateTime += date.getDate() * 1000000L;
atechDateTime += date.getHours() * 10000L;
atechDateTime += date.getMinutes() * 100L;
atechDateTime += date.getSeconds();

View file

@ -48,6 +48,7 @@ import info.nightscout.androidaps.plugins.pump.common.defs.PumpDriverState;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkConst;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkServiceState;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ResetRileyLinkTask;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.ServiceTaskExecutor;
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.tasks.WakeAndTuneTask;
import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
@ -767,8 +768,7 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
long time = System.currentTimeMillis() + (bolusTime * 1000);
this.busyTimestamps.add(time);
this.customActionClearBolusBlock.setEnabled(true);
refreshCustomActionsList();
setEnableCustomAction(MedtronicCustomActionType.ClearBolusBlock, true);
}
return new PumpEnactResult().success(true) //
@ -1315,7 +1315,6 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
LOG.info(getLogPrefix() + "Basal Profile was set: " + response);
if (response) {
// medtronicHistoryData.setBasalProfileChanged();
return new PumpEnactResult().success(true).enacted(true);
} else {
return new PumpEnactResult().success(response).enacted(response) //
@ -1378,14 +1377,17 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
MedtronicCustomActionType.WakeUpAndTune);
private CustomAction customActionClearBolusBlock = new CustomAction(
R.string.medtronic_custom_action_clear_bolus_block, MedtronicCustomActionType.ClearBolusBlock);
R.string.medtronic_custom_action_clear_bolus_block, MedtronicCustomActionType.ClearBolusBlock, false);
private CustomAction customActionReset = new CustomAction(
R.string.medtronic_custom_action_reset_rileylink, MedtronicCustomActionType.ResetRileyLink, false);
@Override
public List<CustomAction> getCustomActions() {
if (customActions == null) {
this.customActions = Arrays.asList(customActionWakeUpAndTune, customActionClearBolusBlock);
this.customActions = Arrays.asList(customActionWakeUpAndTune, customActionClearBolusBlock, customActionReset);
}
return this.customActions;
@ -1410,6 +1412,10 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
}
break;
case ResetRileyLink: {
ServiceTaskExecutor.startTask(new ResetRileyLinkTask());
} break;
default:
break;
}
@ -1421,4 +1427,17 @@ public class MedtronicPumpPlugin extends PumpPluginAbstract implements PumpInter
MainApp.bus().post(new EventCustomActionsChanged());
}
public void setEnableCustomAction(MedtronicCustomActionType customAction, boolean isEnabled) {
if (customAction == MedtronicCustomActionType.ClearBolusBlock) {
this.customActionClearBolusBlock.setEnabled(isEnabled);
} else if (customAction == MedtronicCustomActionType.ResetRileyLink) {
this.customActionReset.setEnabled(isEnabled);
}
refreshCustomActionsList();
}
}

View file

@ -357,11 +357,6 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
case UnknownBasePacket:
return RecordDecodeStatus.Error;
// case Andy0d:
// case Andy58:
// case Andy90:
default: {
LOG.debug("Not supported: " + entry.getEntryType());
@ -379,50 +374,13 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
entry.addDecodedData("Raw Data", ByteUtil.getHex(entry.getRawData()));
LOG.debug("{} - {}", entry.getEntryType().name(), ByteUtil.getHex(entry.getRawData()));
LOG.debug("{}", entry);
// byte[] data = new byte[] {
// 0x6D, (byte)0xA2, (byte)0x92, 0x05, 0x0C, 0x00, (byte)0xE8, 0x00, 0x00, 0x00, 0x00, 0x03, 0x18, 0x02,
// (byte)0xD4, 0x5B, 0x00, 0x44, 0x09, 0x00, 0x00, 0x00, 0x44, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// 0x44, 0x64, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0C, 0x00, (byte)0xE8, 0x00, 0x00, 0x00 };
// basal 18.1, bolus 1.7 manual = 1.7
// bg avg, bg low hi, number Bgs,
// Sen Avg, Sen Lo/Hi, Sens Cal/Data = 0/0,
// Insulin=19.8, Basal, Bolus, Carbs,
// Bolus=1.7, Fodd, Corr, Manual=1.7,
// Num bOlus=1, food/corr, Food+corr, manual bolus=1
//LOG.debug("{} - {}", entry.getEntryType().name(), ByteUtil.getHex(entry.getRawData()));
//LOG.debug("{}", entry);
DailyTotalsDTO totals = new DailyTotalsDTO(entry);
// System.out.println("Totals:" + totals);
// if (entry.getEntryType() == PumpHistoryEntryType.DailyTotals522) {
//
// // Daily
//
// byte body[] = entry.getBody();
// System.out.println("Totoals 522");
//
// for (int i = 0; i < body.length - 1; i++) {
//
// int j = ByteUtil.toInt(body[i], body[i + 1]);
//
// System.out.println(String.format(
// "index: %d, number=%d, del/40=%.3f, del/10=%.3f, singular=%d, sing_hex=%s", i, j, j / 40.0d,
// j / 10.0d, body[i], ByteUtil.getHex(body[i])));
//
// }
//
// }
entry.addDecodedData("Object", totals);
System.out.println("" + totals.toString());
// FIXME displayable
return RecordDecodeStatus.OK;
}
@ -444,29 +402,10 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
}
// private void decodeCalBGForPH(PumpHistoryEntry entry) {
// int high = (entry.getDatetime()[4] & 0x80) >> 7;
// int bg = bitUtils.toInt(high, getUnsignedInt(entry.getHead()[0]));
//
// writeData(PumpBaseType.AdditionalData, PumpAdditionalDataType.BloodGlucose, "" + bg, entry.getATechDate());
// }
// masks = [ ( 0x80, 7), (0x40, 6), (0x20, 5), (0x10, 4) ]
// nibbles = [ ]
// for mask, shift in masks:
// nibbles.append( ( (year & mask) >> shift ) )
// return nibbles
// FIXME
private void decodeChangeTime(PumpHistoryEntry entry) {
if (changeTimeRecord == null)
return;
// String timeChange = String.format(PumpEventType.DateTimeChanged.getValueTemplate(),
// this.changeTimeRecord.getATechDate().getDateTimeString(), entry.getATechDate().getDateTimeString());
// writeData(PumpBaseType.Event, PumpEventType.DateTimeChanged, timeChange, entry.getATechDate());
entry.setDisplayableValue(entry.getDateTimeString());
this.changeTimeRecord = null;
@ -481,25 +420,11 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
}
// FIXME 554 ?
private void decodeEndResultTotals(PumpHistoryEntry entry) {
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;
entry.addDecodedData("Totals", totals);
entry.setDisplayableValue(getFormattedValue(totals, 3));
// this.writeData(PumpBaseType.Report, PumpReport.InsulinTotalDay, getFormattedFloat(totals, 2),
// entry.getATechDate());
}
public static String getFormattedValue(float value, int decimals) {
return String.format(Locale.ENGLISH, "%." + decimals + "f", value);
}
// FIXME
private RecordDecodeStatus decodeBasalProfileStart(PumpHistoryEntry entry) {
byte[] body = entry.getBody();
// int bodyOffset = headerSize + timestampSize;
@ -523,7 +448,6 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
entry.setDisplayableValue(getFormattedFloat(rate, 3));
return RecordDecodeStatus.OK;
}
}
@ -760,7 +684,7 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
ByteUtil.getHex(entry.getRawData()), entry);
}
if (entry.getEntryType() == PumpHistoryEntryType.EndResultTotals) {
if (isEndResults(entry.getEntryType())) {
hour = 23;
minutes = 59;
seconds = 59;
@ -775,6 +699,15 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder<PumpHis
}
private boolean isEndResults(PumpHistoryEntryType entryType) {
return (entryType == PumpHistoryEntryType.EndResultTotals ||
entryType == PumpHistoryEntryType.DailyTotals515 ||
entryType == PumpHistoryEntryType.DailyTotals522 ||
entryType == PumpHistoryEntryType.DailyTotals523);
}
private int fix2DigitYear(int year) {
if (year > 90) {
year += 1900;

View file

@ -40,9 +40,11 @@ import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.ClockDTO;
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.DailyTotalsDTO;
import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.medtronic.driver.MedtronicPumpStatus;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicConst;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.SP;
//import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
@ -57,12 +59,11 @@ public class MedtronicHistoryData {
private List<PumpHistoryEntry> allHistory = null;
private List<PumpHistoryEntry> newHistory = null;
// private LocalDateTime previousLastHistoryRecordTime;
private Long lastHistoryRecordTime;
private boolean isInit = false;
private Gson gsonPretty;
private List<PumpHistoryEntry> fakeTBRs;
//private List<PumpHistoryEntry> fakeTBRs;
DatabaseHelper databaseHelper = MainApp.getDbHelper();
@ -137,10 +138,8 @@ public class MedtronicHistoryData {
} else {
newHistory2.add(pumpHistoryEntry);
}
}
}
}
TBRs = preProcessTBRs(TBRs);
@ -170,13 +169,17 @@ public class MedtronicHistoryData {
this.allHistory.add(pumpHistoryEntry);
}
if (pumpHistoryEntry.isAfter(pheLast.atechDateTime)) {
if (pumpHistoryEntry.atechDateTime!=null && pumpHistoryEntry.isAfter(pheLast.atechDateTime)) {
pheLast = pumpHistoryEntry;
}
}
if (pheLast==null) // if we don't have any valid record we don't do the filtering and setting
return;
this.setLastHistoryRecordTime(pheLast.atechDateTime);
SP.putLong(MedtronicConst.Statistics.LastPumpHistoryEntry, pheLast.atechDateTime);
LocalDateTime dt = null;
@ -212,12 +215,10 @@ public class MedtronicHistoryData {
}
this.newHistory.clear();
}
public boolean hasRelevantConfigurationChanged() {
return getStateFromFilteredList( //
PumpHistoryEntryType.ChangeBasalPattern, //
PumpHistoryEntryType.ClearSettings, //
@ -301,7 +302,6 @@ public class MedtronicHistoryData {
}
return newAndAll2;
}
@ -369,16 +369,13 @@ public class MedtronicHistoryData {
ClockDTO pumpTime;
public void processTDDs(List<PumpHistoryEntry> tddsIn) {
private void processTDDs(List<PumpHistoryEntry> tddsIn) {
List<PumpHistoryEntry> tdds = filterTDDs(tddsIn);
// /pumpTime = MedtronicUtil.getPumpTime();
LOG.error(getLogPrefix() + "TDDs found: {}.\n{}", tdds.size(), gsonPretty.toJson(tdds));
LOG.error(getLogPrefix() + "TDDs found: {}. Not processed.\n{}", tdds.size(), gsonPretty.toJson(tdds));
// FIXME tdd
List<TDD> tddsDb = MainApp.getDbHelper().getTDDs(); // .getTDDsForLastXDays(3);
List<TDD> tddsDb = databaseHelper.getTDDsForLastXDays(3);
for (PumpHistoryEntry tdd : tdds) {
@ -386,28 +383,27 @@ public class MedtronicHistoryData {
DailyTotalsDTO totalsDTO = (DailyTotalsDTO) tdd.getDecodedData().get("Object");
LOG.debug("DailtyTotals: {}", totalsDTO);
//LOG.debug("DailyTotals: {}", totalsDTO);
if (tddDbEntry == null) {
TDD tddNew = new TDD();
totalsDTO.setTDD(tddNew);
LOG.debug("TDD-Add: {}", tddNew);
LOG.debug("TDD Add: {}", tddNew);
MainApp.getDbHelper().createOrUpdateTDD(tddNew);
databaseHelper.createOrUpdateTDD(tddNew);
} else {
if (!totalsDTO.doesEqual(tddDbEntry)) {
totalsDTO.setTDD(tddDbEntry);
LOG.debug("TDD-Edit: {}", tddDbEntry);
LOG.debug("TDD Edit: {}", tddDbEntry);
MainApp.getDbHelper().createOrUpdateTDD(tddDbEntry);
databaseHelper.createOrUpdateTDD(tddDbEntry);
}
}
}
}
@ -673,14 +669,9 @@ public class MedtronicHistoryData {
String.format("%d", temporaryBasalDb.percentRate), //
temporaryBasalDb.isAbsolute ? "U/h" : "%", //
temporaryBasalDb.durationInMinutes);
}
// TODO needs to be implemented
public void processSuspends(List<PumpHistoryEntry> treatments) {
@ -723,16 +714,9 @@ public class MedtronicHistoryData {
LocalDateTime ldt = DateTimeUtil.toLocalDateTime(atechDateTime);
// LOG.debug("TOE. Time of Entry: " + atechDateTime);
// LOG.debug("TOE. Clock Pump: " + pumpTime.pumpTime.toString("HH:mm:ss"));
// LOG.debug("TOE. LocalTime: " + pumpTime.localDeviceTime.toString("HH:mm:ss"));
// LOG.debug("TOE. Difference(s): " + pumpTime.timeDifference);
ldt = ldt.plusSeconds(pumpTime.timeDifference);
ldt = ldt.millisOfSecond().setCopy(000);
// LOG.debug("TOE. New Time Of Entry: " + ldt.toString("HH:mm:ss"));
LOG.debug("tryToGetByLocalTime: [TimeOfEntry={}, ClockPump={}, LocalTime={}, DifferenceSec={}, "
+ "NewTimeOfEntry={}, time={}", atechDateTime, pumpTime.pumpTime.toString("HH:mm:ss"),
pumpTime.localDeviceTime.toString("HH:mm:ss"), pumpTime.timeDifference, ldt.toString("HH:mm:ss"), ldt
@ -747,6 +731,10 @@ public class MedtronicHistoryData {
long dt = Long.MAX_VALUE;
PumpHistoryEntry currentTreatment = null;
if (isCollectionEmpty(treatments)) {
return 10; // default return of 10 minutes
}
for (PumpHistoryEntry treatment : treatments) {
if (treatment.atechDateTime < dt) {
@ -755,8 +743,6 @@ public class MedtronicHistoryData {
}
}
// LOG.debug("Oldest entry: {}, pumpTimeDifference={}", dt, this.pumpTime.timeDifference);
LocalDateTime oldestEntryTime = null;
try {
@ -769,9 +755,9 @@ public class MedtronicHistoryData {
}
} catch (Exception ex) {
LOG.error("Problem decoding date from last record: {}" + currentTreatment);
return 10; // default return of 10 minutes
}
LocalDateTime now = new LocalDateTime();
Minutes minutes = Minutes.minutesBetween(oldestEntryTime, now);
@ -781,22 +767,9 @@ public class MedtronicHistoryData {
this.pumpTime.timeDifference, oldestEntryTime, now, minutes.getMinutes());
return minutes.getMinutes();
}
// private void processTreatments(List<PumpHistoryEntry> treatments) {
//
// // FIXME bolus and tbr
//
// LOG.error(getLogPrefix() + "Treatments found: {}. Not processed.\n", treatments.size());
//
// //MainApp.getDbHelper().getTDDsForLastXDays()
//
// MedtronicHistoryData.showLogs(null, gsonInstancePretty.toJson(treatments));
//
// }
private PumpHistoryEntryType getTDDType() {
if (MedtronicUtil.getMedtronicPumpModel() == null) {
@ -823,40 +796,9 @@ public class MedtronicHistoryData {
return PumpHistoryEntryType.EndResultTotals;
}
}
}
/*
* entryType == PumpHistoryEntryType.Bolus || // Treatments
* entryType == PumpHistoryEntryType.TempBasalRate || //
* entryType == PumpHistoryEntryType.TempBasalDuration || //
*
* entryType == PumpHistoryEntryType.Prime || // Pump Status Change
* entryType == PumpHistoryEntryType.PumpSuspend || //
* entryType == PumpHistoryEntryType.PumpResume || //
* entryType == PumpHistoryEntryType.Rewind || //
* entryType == PumpHistoryEntryType.NoDeliveryAlarm || // no delivery
* entryType == PumpHistoryEntryType.BasalProfileStart || //
*
* entryType == PumpHistoryEntryType.ChangeTime || // Time Change
* entryType == PumpHistoryEntryType.NewTimeSet || //
*
* entryType == PumpHistoryEntryType.SelectBasalProfile || // Configuration
* entryType == PumpHistoryEntryType.ClearSettings || //
* entryType == PumpHistoryEntryType.SaveSettings || //
* entryType == PumpHistoryEntryType.ChangeMaxBolus || //
* entryType == PumpHistoryEntryType.ChangeMaxBasal || //
* entryType == PumpHistoryEntryType.ChangeTempBasalType || //
*
* entryType == PumpHistoryEntryType.ChangeBasalProfile_NewProfile || // Basal profile
*
* entryType == PumpHistoryEntryType.DailyTotals512 || // Daily Totals
* entryType == PumpHistoryEntryType.DailyTotals522 || //
* entryType == PumpHistoryEntryType.DailyTotals523 || //
* entryType == PumpHistoryEntryType.EndResultTotals
*/
public boolean hasBasalProfileChanged() {
List<PumpHistoryEntry> filteredItems = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile);
@ -864,14 +806,11 @@ public class MedtronicHistoryData {
LOG.debug("hasBasalProfileChanged. Items: " + filteredItems);
return (filteredItems.size() > 0);
}
public void processLastBasalProfileChange(MedtronicPumpStatus mdtPumpStatus) {
// FIXME
List<PumpHistoryEntry> filteredItems = getFilteredItems(PumpHistoryEntryType.ChangeBasalProfile_NewProfile);
LOG.debug("processLastBasalProfileChange. Items: " + filteredItems);
@ -897,23 +836,12 @@ public class MedtronicHistoryData {
BasalProfile basalProfile = (BasalProfile) newProfile.getDecodedData().get("Object");
mdtPumpStatus.basalsByHour = basalProfile.getProfilesByHour();
}
// boolean profileChanged = ((filteredItems.size() - basalProfileChangedInternally) > 0);
// LOG.error("Profile changed:" + profileChanged);
// this.basalProfileChangedInternally = 0;
// return profileChanged;
}
public boolean hasPumpTimeChanged() {
return getStateFromFilteredList(PumpHistoryEntryType.NewTimeSet, //
PumpHistoryEntryType.ChangeTime);
}
@ -957,27 +885,7 @@ public class MedtronicHistoryData {
private List<PumpHistoryEntry> getFilteredItems(PumpHistoryEntryType... entryTypes) {
return getFilteredItems(this.newHistory, entryTypes);
}
// private List<PumpHistoryEntry> getFilteredListByPreviousLastRecord(PumpHistoryEntryType... entryTypes) {
// return getFilteredListByTime(this.previousLastHistoryRecordTime, entryTypes);
// }
private List<PumpHistoryEntry> getFilteredListByLastRecord(PumpHistoryEntryType... entryTypes) {
return getFilteredListByTime(this.lastHistoryRecordTime, entryTypes);
}
private List<PumpHistoryEntry> getFilteredListByTime(Long lastRecordTime, PumpHistoryEntryType... entryTypes) {
if (lastRecordTime == null) {
return getFilteredItems(entryTypes);
} else {
return getFilteredItems(lastRecordTime, entryTypes);
}
}
@ -994,14 +902,6 @@ public class MedtronicHistoryData {
}
private List<PumpHistoryEntry> getFilteredItems(Long dateTime, PumpHistoryEntryType... entryTypes) {
PumpHistoryResult phr = new PumpHistoryResult(null, dateTime);
return getFilteredItems(phr.getValidEntries(), entryTypes);
}
private List<PumpHistoryEntry> getFilteredItems(List<PumpHistoryEntry> inList, PumpHistoryEntryType... entryTypes) {
// LOG.debug("InList: " + inList.size());
@ -1027,7 +927,6 @@ public class MedtronicHistoryData {
// LOG.debug("OutList: " + outList.size());
return outList;
}
@ -1036,14 +935,6 @@ public class MedtronicHistoryData {
}
// public List<PumpHistoryEntry> getNewHistoryEntries() {
// return this.newHistory;
// }
// public void setBasalProfileChanged() {
// this.basalProfileChangedInternally++;
// }
private String getLogPrefix() {
return "MedtronicHistoryData::";
}

View file

@ -108,8 +108,6 @@ public class DailyTotalsDTO {
this.insulinTotal = totals;
entry.addDecodedData("Totals", totals);
// entry.setDisplayableValue(getFormattedValue(totals, 3));
}
@ -136,7 +134,6 @@ public class DailyTotalsDTO {
k, j1, k1, k / 40.0d, j1 / 40.0d, k1 / 40.0d));
}
}
@ -178,8 +175,7 @@ public class DailyTotalsDTO {
// Bolus=1.7[18,19], Fodd, Corr, Manual=1.7[27,28],
// Num bOlus=1, food/corr, Food+corr, manual bolus=1
LOG.debug("522: {}", toString());
//LOG.debug("522: {}", toString());
}
@ -207,7 +203,6 @@ public class DailyTotalsDTO {
// Delivery Stats: Manual = 0.95, #Manual=5
//LOG.debug("523: {}", toString());
}

View file

@ -198,8 +198,8 @@ public class MedtronicPumpStatus extends PumpStatus {
this.isFrequencyUS = pumpFrequency.equals(frequencies[0]);
RileyLinkTargetFrequency newTargetFrequency = this.isFrequencyUS ? //
RileyLinkTargetFrequency.Medtronic_US
: RileyLinkTargetFrequency.Medtronic_WorldWide;
RileyLinkTargetFrequency.Medtronic_US
: RileyLinkTargetFrequency.Medtronic_WorldWide;
if (targetFrequency != newTargetFrequency) {
RileyLinkUtil.setRileyLinkTargetFrequency(newTargetFrequency);

View file

@ -123,6 +123,11 @@ public class RileyLinkMedtronicService extends RileyLinkService {
}
public void resetRileyLinkDevice() {
rfspy.resetRileyLinkDevice();
}
@Override
public RileyLinkCommunicationManager getDeviceCommunicationManager() {
return this.medtronicCommunicationManager;

View file

@ -17,6 +17,7 @@ public class MedtronicConst {
public static final String MaxBolus = PrefPrefix + "max_bolus";
public static final String MaxBasal = PrefPrefix + "max_basal";
public static final String BolusDelay = PrefPrefix + "bolus_delay";
public static final String Encoding = PrefPrefix + "encoding";
}
public class Statistics {

View file

@ -1354,11 +1354,12 @@
<string name="medtronic_pump_encoding">Medtronic Encoding</string>
<string name="medtronic_pump_frequency_us_ca">US &amp; Canada (916 MHz)</string>
<string name="medtronic_pump_frequency_worldwide">Worldwide (868 Mhz)</string>
<string name="medtronic_pump_encoding_4b6b_local">Local 4b6b Encoding</string>
<string name="medtronic_pump_encoding_4b6b_rileylink">RileyLink 4b6b Encoding</string>
<string name="medtronic_pump_encoding_4b6b_local">Software 4b6b Encoding</string>
<string name="medtronic_pump_encoding_4b6b_rileylink">Hardware 4b6b Encoding</string>
<string name="rileylink_mac_address">RileyLink MAC Address</string>
<string name="medtronic_custom_action_wake_and_tune">Wake and Tune Up</string>
<string name="medtronic_custom_action_clear_bolus_block">Clear Bolus Block</string>
<string name="medtronic_custom_action_reset_rileylink">Reset RileyLink</string>
<!-- RL BLE Scanning -->
<string name="rileylink_scanner_scan_scan">SCAN</string>

View file

@ -0,0 +1,23 @@
package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump;
import org.junit.Assert;
import org.junit.Test;
/**
* Created by andy on 4/9/19.
*/
public class PumpHistoryEntryUTest {
@Test
public void checkIsAfter() {
long dateObject = 20191010000000L;
long queryObject = 20191009000000L;
PumpHistoryEntry phe = new PumpHistoryEntry();
phe.atechDateTime = dateObject;
Assert.assertTrue(phe.isAfter(queryObject));
}
}