wordaround for logicdata timestamp overflow #1563 (#2562)

Co-authored-by: Andrei <andreikagit@users.noreply.github.com>
This commit is contained in:
andreika-git 2021-04-16 15:03:11 +03:00 committed by GitHub
parent d612210d9b
commit 3cdac69fef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 1 deletions

View File

@ -11,11 +11,14 @@ import java.util.List;
public class CompositeParser {
private static final Logging log = Logging.getLogging(CompositeParser.class);
// 1 second
private static final int maxDeltaTime = 1000000;
public static List<CompositeEvent> parse(byte[] response) {
ByteBuffer byteBuffer = ByteBuffer.wrap(response);
byteBuffer.order(ByteOrder.BIG_ENDIAN);
int ptr = 1;
int curTime = 0, prevTime = 0;
List<CompositeEvent> events = new ArrayList<>();
@ -34,7 +37,18 @@ public class CompositeParser {
ptr += Fields.COMPOSITE_PACKET_SIZE;
events.add(new CompositeEvent(timestamp, primaryTrigger, secondaryTrigger, trg, sync, coil, injector));
// 'timestamp' is an integer type for now, and sadly, but it overflows...
// this is an attempt of temporary workaround
int dt = timestamp - prevTime;
// we allow time to increment only in small amounts.
// so if any time discontinuities occur, we jump 1 sec.
if (dt < 0 || dt > maxDeltaTime)
dt = maxDeltaTime;
// we want to catch integer overflows here
curTime = Math.addExact(curTime, dt);
prevTime = timestamp;
events.add(new CompositeEvent(curTime, primaryTrigger, secondaryTrigger, trg, sync, coil, injector));
}
return events;
}