fix rounding on bolus delivery

This commit is contained in:
Milos Kozak 2018-05-02 22:20:27 +02:00
parent d0e6a2258f
commit e2f28e0ae4
6 changed files with 10 additions and 9 deletions

View file

@ -19,13 +19,13 @@ public class DetailedBolusInfoStorage {
private static Logger log = LoggerFactory.getLogger(DetailedBolusInfoStorage.class);
private static List<DetailedBolusInfo> store = new ArrayList<>();
public static void add(DetailedBolusInfo detailedBolusInfo) {
public static synchronized void add(DetailedBolusInfo detailedBolusInfo) {
log.debug("Stored bolus info: " + detailedBolusInfo);
store.add(detailedBolusInfo);
}
@Nullable
public static DetailedBolusInfo findDetailedBolusInfo(long bolustime) {
public static synchronized DetailedBolusInfo findDetailedBolusInfo(long bolustime) {
DetailedBolusInfo found = null;
for (int i = 0; i < store.size(); i++) {
long infoTime = store.get(i).date;
@ -38,7 +38,7 @@ public class DetailedBolusInfoStorage {
return found;
}
public static void remove(long bolustime) {
public static synchronized void remove(long bolustime) {
for (int i = 0; i < store.size(); i++) {
long infoTime = store.get(i).date;
if (bolustime > infoTime - 60 * 1000 && bolustime < infoTime + 60 * 1000) {

View file

@ -159,7 +159,7 @@ public class DanaRPlugin extends AbstractDanaRPlugin {
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0)
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.carbTime, t);
PumpEnactResult result = new PumpEnactResult();
result.success = connectionOK && detailedBolusInfo.insulin == t.insulin;
result.success = connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep;
result.bolusDelivered = t.insulin;
result.carbsDelivered = detailedBolusInfo.carbs;
if (!result.success)

View file

@ -160,7 +160,7 @@ public class DanaRKoreanPlugin extends AbstractDanaRPlugin {
if (detailedBolusInfo.insulin > 0 || detailedBolusInfo.carbs > 0)
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) detailedBolusInfo.carbs, detailedBolusInfo.carbTime, t);
PumpEnactResult result = new PumpEnactResult();
result.success = connectionOK && detailedBolusInfo.insulin == t.insulin;
result.success = connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep;
result.bolusDelivered = t.insulin;
result.carbsDelivered = detailedBolusInfo.carbs;
if (!result.success)

View file

@ -386,7 +386,7 @@ public class DanaRSPlugin extends PluginBase implements PumpInterface, DanaRInte
if (detailedBolusInfo.insulin > 0 || carbs > 0)
connectionOK = danaRSService.bolus(detailedBolusInfo.insulin, (int) carbs, DateUtil.now() + carbTime * 60 * 1000, t);
PumpEnactResult result = new PumpEnactResult();
result.success = connectionOK && detailedBolusInfo.insulin == t.insulin;
result.success = connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep;
result.bolusDelivered = t.insulin;
result.carbsDelivered = detailedBolusInfo.carbs;
if (!result.success)

View file

@ -53,9 +53,10 @@ public class DanaRS_Packet_Bolus_Set_Step_Bolus_Start extends DanaRS_Packet {
public void handleMessage(byte[] data) {
errorCode = intFromBuff(data, 0, 1);
if (Config.logDanaMessageDetail) {
if (errorCode == 0)
if (errorCode == 0) {
log.debug("Result OK");
else {
failed = false;
} else {
failed = true;
log.error("Result Error: " + errorCode);
}

View file

@ -174,7 +174,7 @@ public class DanaRv2Plugin extends AbstractDanaRPlugin {
if (detailedBolusInfo.insulin > 0 || carbs > 0)
connectionOK = sExecutionService.bolus(detailedBolusInfo.insulin, (int) carbs, DateUtil.now() + carbTime * 60 * 1000, t);
PumpEnactResult result = new PumpEnactResult();
result.success = connectionOK && detailedBolusInfo.insulin == t.insulin;
result.success = connectionOK && Math.abs(detailedBolusInfo.insulin - t.insulin) < pumpDescription.bolusStep;
result.bolusDelivered = t.insulin;
result.carbsDelivered = detailedBolusInfo.carbs;
if (!result.success)