Don't read past history events when pump is newly paired.
This commit is contained in:
parent
e4fd293027
commit
baac836d64
1 changed files with 10 additions and 14 deletions
|
@ -1057,11 +1057,7 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
startMessage.setDirection(HistoryReadingDirection.BACKWARD);
|
startMessage.setDirection(HistoryReadingDirection.BACKWARD);
|
||||||
startMessage.setOffset(0xFFFFFFFF);
|
startMessage.setOffset(0xFFFFFFFF);
|
||||||
connectionService.requestMessage(startMessage).await();
|
connectionService.requestMessage(startMessage).await();
|
||||||
for (int i = 0; i < 50; i++) {
|
historyEvents = connectionService.requestMessage(new ReadHistoryEventsMessage()).await().getHistoryEvents();
|
||||||
List<HistoryEvent> newEvents = connectionService.requestMessage(new ReadHistoryEventsMessage()).await().getHistoryEvents();
|
|
||||||
if (newEvents.size() == 0) break;
|
|
||||||
historyEvents.addAll(newEvents);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
StartReadingHistoryMessage startMessage = new StartReadingHistoryMessage();
|
StartReadingHistoryMessage startMessage = new StartReadingHistoryMessage();
|
||||||
startMessage.setDirection(HistoryReadingDirection.FORWARD);
|
startMessage.setDirection(HistoryReadingDirection.FORWARD);
|
||||||
|
@ -1073,7 +1069,15 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
historyEvents.addAll(newEvents);
|
historyEvents.addAll(newEvents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
processHistoryEvents(pumpSerial, historyEvents);
|
Collections.sort(historyEvents);
|
||||||
|
Collections.reverse(historyEvents);
|
||||||
|
if (historyOffset != null) processHistoryEvents(pumpSerial, historyEvents);
|
||||||
|
if (historyEvents.size() > 0) {
|
||||||
|
historyOffset = new InsightHistoryOffset();
|
||||||
|
historyOffset.pumpSerial = pumpSerial;
|
||||||
|
historyOffset.offset = historyEvents.get(0).getEventPosition();
|
||||||
|
MainApp.getDbHelper().createOrUpdate(historyOffset);
|
||||||
|
}
|
||||||
} catch (AppLayerErrorException e) {
|
} catch (AppLayerErrorException e) {
|
||||||
log.info("Exception while reading history: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
log.info("Exception while reading history: " + e.getClass().getCanonicalName() + " (" + e.getErrorCode() + ")");
|
||||||
} catch (InsightException e) {
|
} catch (InsightException e) {
|
||||||
|
@ -1097,8 +1101,6 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
}
|
}
|
||||||
|
|
||||||
private void processHistoryEvents(String serial, List<HistoryEvent> historyEvents) {
|
private void processHistoryEvents(String serial, List<HistoryEvent> historyEvents) {
|
||||||
Collections.sort(historyEvents);
|
|
||||||
Collections.reverse(historyEvents);
|
|
||||||
List<TemporaryBasal> temporaryBasals = new ArrayList<>();
|
List<TemporaryBasal> temporaryBasals = new ArrayList<>();
|
||||||
List<InsightPumpID> pumpStartedEvents = new ArrayList<>();
|
List<InsightPumpID> pumpStartedEvents = new ArrayList<>();
|
||||||
for (HistoryEvent historyEvent : historyEvents)
|
for (HistoryEvent historyEvent : historyEvents)
|
||||||
|
@ -1121,12 +1123,6 @@ public class LocalInsightPlugin extends PluginBase implements PumpInterface, Con
|
||||||
Collections.sort(temporaryBasals, (o1, o2) -> (int) (o1.date - o2.date));
|
Collections.sort(temporaryBasals, (o1, o2) -> (int) (o1.date - o2.date));
|
||||||
for (TemporaryBasal temporaryBasal : temporaryBasals)
|
for (TemporaryBasal temporaryBasal : temporaryBasals)
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal);
|
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(temporaryBasal);
|
||||||
if (historyEvents.size() > 0) {
|
|
||||||
InsightHistoryOffset historyOffset = new InsightHistoryOffset();
|
|
||||||
historyOffset.pumpSerial = serial;
|
|
||||||
historyOffset.offset = historyEvents.get(0).getEventPosition();
|
|
||||||
MainApp.getDbHelper().createOrUpdate(historyOffset);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean processHistoryEvent(String serial, List<TemporaryBasal> temporaryBasals, List<InsightPumpID> pumpStartedEvents, HistoryEvent event) {
|
private boolean processHistoryEvent(String serial, List<TemporaryBasal> temporaryBasals, List<InsightPumpID> pumpStartedEvents, HistoryEvent event) {
|
||||||
|
|
Loading…
Reference in a new issue