Skip to content

Commit

Permalink
Fix handling of packets with multiple drawings in logs (#98)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pmacalpine authored and Gama11 committed Oct 8, 2016
1 parent bfe9b1a commit 845cdc6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
14 changes: 10 additions & 4 deletions src/rv/comm/drawing/DrawComm.java
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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()) {
Expand All @@ -120,8 +128,6 @@ public void handle(DatagramPacket packet) {
}
return;
} else {
for (DrawCommListener l : listeners)
l.drawCommandReceived(pktData);
cmd.execute();
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/rv/comm/rcssserver/Logfile.java
Expand Up @@ -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);
Expand Down

0 comments on commit 845cdc6

Please sign in to comment.