check for future timestamp while loading history (RS,Rv2)

This commit is contained in:
Milos Kozak 2018-10-28 11:24:59 +01:00
parent 512ceceeb8
commit 05dcb58f0a
3 changed files with 31 additions and 24 deletions

View file

@ -45,6 +45,12 @@ public class DanaRS_Packet_APS_History_Events extends DanaRS_Packet {
public DanaRS_Packet_APS_History_Events(long from) {
this();
GregorianCalendar cal = new GregorianCalendar();
if (from > DateUtil.now()) {
log.debug("Asked to load from the future");
from = 0;
}
if (from != 0)
cal.setTimeInMillis(from);
else

View file

@ -26,23 +26,30 @@ public class MsgHistoryEvents_v2 extends MessageBase {
public static long lastEventTimeLoaded = 0;
public MsgHistoryEvents_v2() {
this(0);
}
public MsgHistoryEvents_v2(long from) {
SetCommand(0xE003);
if (from > DateUtil.now()) {
log.debug("Asked to load from the future");
from = 0;
}
if (from == 0) {
AddParamByte((byte) 0);
AddParamByte((byte) 1);
AddParamByte((byte) 1);
AddParamByte((byte) 0);
AddParamByte((byte) 0);
} else {
GregorianCalendar gfrom = new GregorianCalendar();
gfrom.setTimeInMillis(from);
AddParamDate(gfrom);
done = false;
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");
}
public MsgHistoryEvents_v2() {
SetCommand(0xE003);
AddParamByte((byte) 0);
AddParamByte((byte) 1);
AddParamByte((byte) 1);
AddParamByte((byte) 0);
AddParamByte((byte) 0);
done = false;
if (L.isEnabled(L.PUMPCOMM))
log.debug("New message");

View file

@ -465,16 +465,10 @@ public class DanaRv2ExecutionService extends AbstractDanaRExecutionService {
if (!isConnected())
return new PumpEnactResult().success(false);
SystemClock.sleep(300);
MsgHistoryEvents_v2 msg;
if (lastHistoryFetched == 0) {
msg = new MsgHistoryEvents_v2();
if (L.isEnabled(L.PUMP))
log.debug("Loading complete event history");
} else {
msg = new MsgHistoryEvents_v2(lastHistoryFetched);
MsgHistoryEvents_v2 msg = new MsgHistoryEvents_v2(lastHistoryFetched);
if (L.isEnabled(L.PUMP))
log.debug("Loading event history from: " + DateUtil.dateAndTimeFullString(lastHistoryFetched));
}
mSerialIOThread.sendMessage(msg);
while (!msg.done && mRfcommSocket.isConnected()) {
SystemClock.sleep(100);