From 845cdc6a8556d7243aeac293319b4cb37781e7e4 Mon Sep 17 00:00:00 2001 From: Patrick MacAlpine Date: Sat, 8 Oct 2016 06:10:43 -0500 Subject: [PATCH] Fix handling of packets with multiple drawings in logs (#98) Fixing multiple drawings in the same packet to work when playing back roboviz logfiles. Also fixing mistake where multiple draw commands in the same packet would be written out to roboviz logfiles multiple times. --- src/rv/comm/drawing/DrawComm.java | 14 ++++++++++---- src/rv/comm/rcssserver/Logfile.java | 16 +++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/rv/comm/drawing/DrawComm.java b/src/rv/comm/drawing/DrawComm.java index ca48137a..986f34b1 100644 --- a/src/rv/comm/drawing/DrawComm.java +++ b/src/rv/comm/drawing/DrawComm.java @@ -46,8 +46,12 @@ public ReceiveThread(int port) throws SocketException { try { socket = new DatagramSocket(port); } catch (BindException e) { - DebugInfo.println(getClass(), "Unable to bind to draw port " + port - + " - another RoboViz instance is probably already listening on the same port"); + DebugInfo + .println( + getClass(), + "Unable to bind to draw port " + + port + + " - another RoboViz instance is probably already listening on the same port"); running = false; } } @@ -98,6 +102,10 @@ public DrawComm(Viewer viewer, int port) throws SocketException { public void handle(DatagramPacket packet) { byte[] pktData = new byte[packet.getLength()]; System.arraycopy(packet.getData(), packet.getOffset(), pktData, 0, pktData.length); + + for (DrawCommListener l : listeners) + l.drawCommandReceived(pktData); + ByteBuffer buf = ByteBuffer.wrap(pktData); while (buf.hasRemaining()) { @@ -120,8 +128,6 @@ public void handle(DatagramPacket packet) { } return; } else { - for (DrawCommListener l : listeners) - l.drawCommandReceived(pktData); cmd.execute(); } } diff --git a/src/rv/comm/rcssserver/Logfile.java b/src/rv/comm/rcssserver/Logfile.java index 65c78649..d32d3d95 100644 --- a/src/rv/comm/rcssserver/Logfile.java +++ b/src/rv/comm/rcssserver/Logfile.java @@ -238,14 +238,16 @@ public String processDrawCmds(String line) { } ByteBuffer buf = ByteBuffer.wrap(drawCmdBytes); - Command cmd = null; - try { - cmd = Command.parse(buf, viewer); - if (cmd != null) { - cmd.execute(); + while (buf.hasRemaining()) { + Command cmd = null; + try { + cmd = Command.parse(buf, viewer); + if (cmd != null) { + cmd.execute(); + } + } catch (Exception e) { + System.out.println(e); } - } catch (Exception e) { - System.out.println(e); } } line = line.substring(endIndex + 1);