Skip to content
Snippets Groups Projects
Commit af2cbc72 authored by Lennart Goedhart's avatar Lennart Goedhart
Browse files

Fix #55.

Code cleanup (remove unneeded brackets).
Added support for Temp Basal Rates.
parent c5f91833
No related branches found
No related tags found
No related merge requests found
...@@ -68,48 +68,47 @@ public class PumpStatusResponseMessage extends MedtronicSendMessageResponseMessa ...@@ -68,48 +68,47 @@ public class PumpStatusResponseMessage extends MedtronicSendMessageResponseMessa
Log.d(TAG, "PAYLOAD: " + outputString); Log.d(TAG, "PAYLOAD: " + outputString);
} }
// Status Flags // Status Flags
suspended = ((statusBuffer.get(0x03) & 0x01) != 0x00); suspended = (statusBuffer.get(0x03) & 0x01) != 0x00;
bolusing = ((statusBuffer.get(0x03) & 0x02) != 0x00); bolusing = (statusBuffer.get(0x03) & 0x02) != 0x00;
deliveringInsulin = ((statusBuffer.get(0x03) & 0x10) != 0x00); deliveringInsulin = (statusBuffer.get(0x03) & 0x10) != 0x00;
tempBasalActive = ((statusBuffer.get(0x03) & 0x20) != 0x00); tempBasalActive = (statusBuffer.get(0x03) & 0x20) != 0x00;
cgmActive = ((statusBuffer.get(0x03) & 0x40) != 0x00); cgmActive = (statusBuffer.get(0x03) & 0x40) != 0x00;
// Active basal pattern // Active basal pattern
activeBasalPattern = (statusBuffer.get(0x1a)); activeBasalPattern = statusBuffer.get(0x1a);
// Normal basal rate // Normal basal rate
long rawNormalBasal = statusBuffer.getInt(0x1b); long rawNormalBasal = statusBuffer.getInt(0x1b);
basalRate = (new BigDecimal(rawNormalBasal / 10000f).setScale(3, BigDecimal.ROUND_HALF_UP).floatValue()); basalRate = new BigDecimal(rawNormalBasal / 10000f).setScale(3, BigDecimal.ROUND_HALF_UP).floatValue();
// Temp basal rate // Temp basal rate
// TODO - need to figure this one out long rawTempBasal = statusBuffer.getShort(0x21) & 0x0000ffff;
//long rawTempBasal = statusBuffer.getShort(0x21) & 0x0000ffff; tempBasalRate = new BigDecimal(rawTempBasal / 10000f).setScale(3, BigDecimal.ROUND_HALF_UP).floatValue();
//pumpRecord.setTempBasalRate(new BigDecimal(rawTempBasal / 10000f).setScale(3, BigDecimal.ROUND_HALF_UP).floatValue());
// Temp basal percentage // Temp basal percentage
tempBasalPercentage = (statusBuffer.get(0x23)); tempBasalPercentage = statusBuffer.get(0x23);
// Temp basal minutes remaining // Temp basal minutes remaining
tempBasalMinutesRemaining = ((short) (statusBuffer.getShort(0x24) & 0x0000ffff)); tempBasalMinutesRemaining = (short) (statusBuffer.getShort(0x24) & 0x0000ffff);
// Units of insulin delivered as basal today // Units of insulin delivered as basal today
// TODO - is this basal? Do we have a total Units delivered elsewhere? // TODO - is this basal? Do we have a total Units delivered elsewhere?
basalUnitsDeliveredToday = (statusBuffer.getInt(0x26)); basalUnitsDeliveredToday = statusBuffer.getInt(0x26);
// Pump battery percentage // Pump battery percentage
batteryPercentage = ((statusBuffer.get(0x2a))); batteryPercentage = statusBuffer.get(0x2a);
// Reservoir amount // Reservoir amount
long rawReservoirAmount = statusBuffer.getInt(0x2b); long rawReservoirAmount = statusBuffer.getInt(0x2b);
reservoirAmount = (new BigDecimal(rawReservoirAmount / 10000f).setScale(3, BigDecimal.ROUND_HALF_UP).floatValue()); reservoirAmount = new BigDecimal(rawReservoirAmount / 10000f).setScale(3, BigDecimal.ROUND_HALF_UP).floatValue();
// Amount of insulin left in pump (in minutes) // Amount of insulin left in pump (in minutes)
byte insulinHours = statusBuffer.get(0x2f); byte insulinHours = statusBuffer.get(0x2f);
byte insulinMinutes = statusBuffer.get(0x30); byte insulinMinutes = statusBuffer.get(0x30);
minutesOfInsulinRemaining = ((short) ((insulinHours * 60) + insulinMinutes)); minutesOfInsulinRemaining = (short) ((insulinHours * 60) + insulinMinutes);
// Active insulin // Active insulin
long rawActiveInsulin = statusBuffer.getShort(0x33) & 0x0000ffff; long rawActiveInsulin = statusBuffer.getInt(0x31);
activeInsulin = new BigDecimal(rawActiveInsulin / 10000f).setScale(3, BigDecimal.ROUND_HALF_UP).floatValue(); activeInsulin = new BigDecimal(rawActiveInsulin / 10000f).setScale(3, BigDecimal.ROUND_HALF_UP).floatValue();
// CGM SGV // CGM SGV
...@@ -119,11 +118,11 @@ public class PumpStatusResponseMessage extends MedtronicSendMessageResponseMessa ...@@ -119,11 +118,11 @@ public class PumpStatusResponseMessage extends MedtronicSendMessageResponseMessa
sgv = 0; sgv = 0;
rtc = 0; rtc = 0;
offset = 0; offset = 0;
cgmTrend = (PumpStatusEvent.CGM_TREND.NOT_SET); cgmTrend = PumpStatusEvent.CGM_TREND.NOT_SET;
} else { } else {
rtc = statusBuffer.getInt(0x37) & 0x00000000ffffffffL; rtc = statusBuffer.getInt(0x37) & 0x00000000ffffffffL;
offset = statusBuffer.getInt(0x3b); offset = statusBuffer.getInt(0x3b);
cgmTrend = (PumpStatusEvent.CGM_TREND.fromMessageByte(statusBuffer.get(0x40))); cgmTrend = PumpStatusEvent.CGM_TREND.fromMessageByte(statusBuffer.get(0x40));
} }
// SGV Date // SGV Date
...@@ -133,19 +132,20 @@ public class PumpStatusResponseMessage extends MedtronicSendMessageResponseMessa ...@@ -133,19 +132,20 @@ public class PumpStatusResponseMessage extends MedtronicSendMessageResponseMessa
// Predictive low suspend // Predictive low suspend
// TODO - there is more status info in this byte other than just a boolean yes/no // TODO - there is more status info in this byte other than just a boolean yes/no
lowSuspendActive = (statusBuffer.get(0x3f) != 0); lowSuspendActive = statusBuffer.get(0x3f) != 0;
// Recent Bolus Wizard BGL // Recent Bolus Wizard BGL
recentBolusWizard = (statusBuffer.get(0x48) != 0); recentBolusWizard = statusBuffer.get(0x48) != 0;
bolusWizardBGL = (statusBuffer.getShort(0x49) & 0x0000ffff); // In mg/DL bolusWizardBGL = statusBuffer.getShort(0x49) & 0x0000ffff; // In mg/DL
} }
/** /**
* update pumpRecord with data read from pump * update pumpRecord with data read from pump
* *
* @param pumpRecord * @param pumpRecord
* @param pumpOffset
*/ */
public void updatePumpRecord(PumpStatusEvent pumpRecord) { public void updatePumpRecord(PumpStatusEvent pumpRecord, long pumpOffset) {
// Status Flags // Status Flags
pumpRecord.setSuspended(suspended); pumpRecord.setSuspended(suspended);
pumpRecord.setBolusing(bolusing); pumpRecord.setBolusing(bolusing);
...@@ -159,6 +159,9 @@ public class PumpStatusResponseMessage extends MedtronicSendMessageResponseMessa ...@@ -159,6 +159,9 @@ public class PumpStatusResponseMessage extends MedtronicSendMessageResponseMessa
// Normal basal rate // Normal basal rate
pumpRecord.setBasalRate(basalRate); pumpRecord.setBasalRate(basalRate);
// Temp basal rate
pumpRecord.setTempBasalRate(tempBasalRate);
// Temp basal percentage // Temp basal percentage
pumpRecord.setTempBasalPercentage(tempBasalPercentage); pumpRecord.setTempBasalPercentage(tempBasalPercentage);
...@@ -185,7 +188,7 @@ public class PumpStatusResponseMessage extends MedtronicSendMessageResponseMessa ...@@ -185,7 +188,7 @@ public class PumpStatusResponseMessage extends MedtronicSendMessageResponseMessa
// SGV Date // SGV Date
pumpRecord.setCgmTrend(cgmTrend); pumpRecord.setCgmTrend(cgmTrend);
pumpRecord.setEventDate(new Date(sgvDate.getTime() - pumpRecord.getPumpTimeOffset())); pumpRecord.setEventDate(new Date(sgvDate.getTime() - pumpOffset));
// Predictive low suspend // Predictive low suspend
// TODO - there is more status info in this byte other than just a boolean yes/no // TODO - there is more status info in this byte other than just a boolean yes/no
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment