diff --git a/build.xml b/build.xml index 87507d6998c87b422709e3fc3623402b5c04f184..9e862e4fb944ec4f2867cea1afe12c7577e4889c 100644 --- a/build.xml +++ b/build.xml @@ -79,15 +79,6 @@ https://blogs.apache.org/netbeans/entry/junit-5-apache-ant-and --> - <target name="pduRecord" depends="compile-test,-pre-test-run"> - <echo message="$work.dir=${work.dir}"/> - <java dir="." - classpath="${run.classpath}" - classname="edu.nps.moves.dis7.util.playerrecorder.Recorder"> - <!-- <arg line="*insert filename*"/> TODO in Recorder --> - </java> - </target> - <target name="test" depends="compile-test,-pre-test-run"> <echo message="$work.dir=${work.dir}"/> <echo message="$run.test.classpath=${run.test.classpath}"/> @@ -105,7 +96,6 @@ </junitreport> </target> - <target name="jar-javadoc" depends="javadoc"> <jar destfile="${basedir}/dist/open-dis7-javadoc.jar" basedir="${basedir}/dist/javadoc"> <manifest> diff --git a/dist/open-dis7-java.jar b/dist/open-dis7-java.jar index 14b31f55bac2e3116faf8fc391f40d21838cb722..370fc70530422b09275b3a00c1e68bad87baa05e 100644 Binary files a/dist/open-dis7-java.jar and b/dist/open-dis7-java.jar differ diff --git a/dist/open-dis7-javadoc.jar b/dist/open-dis7-javadoc.jar deleted file mode 100644 index f9de54854eb6de3176e57ac1252823d645cee781..0000000000000000000000000000000000000000 Binary files a/dist/open-dis7-javadoc.jar and /dev/null differ diff --git a/dist/open-dis7-source.jar b/dist/open-dis7-source.jar deleted file mode 100644 index c9e361f1ebdf3d525ba72f66618f84cc5f695ca2..0000000000000000000000000000000000000000 Binary files a/dist/open-dis7-source.jar and /dev/null differ diff --git a/nbproject/project.properties b/nbproject/project.properties index 223c2dbd7eb6d359f7ea25e04cb3aa631d3cd246..c6a8609ae5a364eab37497b49585beba1ae6d09b 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -101,7 +101,7 @@ jlink.additionalmodules= jlink.additionalparam= jlink.launcher=true jlink.launcher.name=open-dis7-java -main.class=edu.nps.moves.dis7.utilities.playerrecorder.PduPlayer +main.class=edu.nps.moves.dis7.utilities.stream.PduRecorder meta.inf.dir=${src.dir}/META-INF mkdist.disabled=true platform.active=default_platform diff --git a/src/edu/nps/moves/dis7/utilities/stream/PduPlayer.java b/src/edu/nps/moves/dis7/utilities/stream/PduPlayer.java index 5686515b71e0bbdea7986919980546f6943e7f7c..f16251c1c90982eae40f6f7682f14d3dc0699b1b 100644 --- a/src/edu/nps/moves/dis7/utilities/stream/PduPlayer.java +++ b/src/edu/nps/moves/dis7/utilities/stream/PduPlayer.java @@ -20,7 +20,6 @@ import java.util.regex.Pattern; public class PduPlayer { public interface RawListener { - void receiveBytes(byte[] ba); } private Path disLogDirectory; @@ -218,7 +217,7 @@ public class PduPlayer { sleep(sleepTime / 1000000L, (int) (sleepTime % 1000000L)); } - byte[] buffer = null; + byte[] buffer; switch (pduLogEncoding) { case "ENCODING_BASE64": @@ -294,7 +293,7 @@ public class PduPlayer { break; default: - + break; } //ToDo: Is this also necessary for buffershort? If yes, put it inside the switch/Case statement @@ -408,13 +407,12 @@ public class PduPlayer { } /** - * Invocation + * Invocation. Nothing happens, just object creation, then JVM exit * * @param args none supported */ public static void main(String[] args) { try { -// new PduPlayer("230.1.2.3", 3000, new File("./pdulog").toPath()).startResume(); new PduPlayer("230.1.2.3", 3000, new File("./pdulog").toPath()); } catch (IOException ex) { ex.printStackTrace(System.err); diff --git a/src/edu/nps/moves/dis7/utilities/stream/PduReceiver.java b/src/edu/nps/moves/dis7/utilities/stream/PduReceiver.java index 1752027355226b83f4fced3f2dba8e689f85c096..6ea3a2fcb616f1ea5c83f7e79cfe52eeb0f20033 100644 --- a/src/edu/nps/moves/dis7/utilities/stream/PduReceiver.java +++ b/src/edu/nps/moves/dis7/utilities/stream/PduReceiver.java @@ -1,6 +1,20 @@ +/** + * Copyright (c) 2008-2020, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved. + * This work is provided under a BSD open-source license, see project license.html and license.txt + */ package edu.nps.moves.dis7.utilities.stream; +/** An interface for capturing PDU raw data for file logging + * + * @author Mike Bailey, jmbailey@nps.edu + */ public interface PduReceiver { + /** Receives a PDU and writes its raw contents to an output file for later + * playback and inspection. + * + * @param buff the array containing raw PDU data + * @param len the length of the buffer + */ void receivePdu(byte[] buff, int len); } diff --git a/src/edu/nps/moves/dis7/utilities/stream/PduRecorder.java b/src/edu/nps/moves/dis7/utilities/stream/PduRecorder.java index b2edea3df00a447c89ad8592f53ca6b787588d00..5bd35238abd7a458166bc870242bbc71e1874a32 100644 --- a/src/edu/nps/moves/dis7/utilities/stream/PduRecorder.java +++ b/src/edu/nps/moves/dis7/utilities/stream/PduRecorder.java @@ -1,12 +1,10 @@ package edu.nps.moves.dis7.utilities.stream; import com.google.common.primitives.Longs; -import edu.nps.moves.dis7.Pdu; + import edu.nps.moves.dis7.enumerations.DISPDUType; -import edu.nps.moves.dis7.utilities.DisNetworking; import edu.nps.moves.dis7.utilities.DisThreadedNetIF; import edu.nps.moves.dis7.utilities.PduFactory; -import org.apache.commons.io.FilenameUtils; import java.io.BufferedWriter; import java.io.File; @@ -18,6 +16,8 @@ import java.util.Arrays; import java.util.Base64; import java.util.Calendar; +import org.apache.commons.io.FilenameUtils; + public class PduRecorder implements PduReceiver { static String DEFAULT_OUTDIR = "./pdulog"; @@ -223,45 +223,38 @@ public class PduRecorder implements PduReceiver return f; } - /** Invocation - * @param args none supported, TODO offer path/filename + /** Entry point invocation. Saves a PDU output log to ./pduLog. Invoking the + * edu.nps.moves.dis7.examples.PduReaderPlayer will pay these logs back + * + * @param args none supported, TODO offer path/filename */ public static void main(String[] args) { PduFactory factory = new PduFactory(); //default appid, country, etc. - DisNetworking disnet = new DisNetworking(); // default ip and port - - Path path = new File("./pdulog").toPath(); - String filename = "Pdusave"; - + PduRecorder recorder; try { - recorder = new PduRecorder(); + recorder = new PduRecorder(); // default addr, port, output dir + recorder.startResume(); } catch(IOException ex) { System.err.println("Exception creating recorder: "+ex.getLocalizedMessage()); return; } - // self test DISPDUType all[] = DISPDUType.values(); Arrays.stream(all).forEach(typ-> { if(typ != DISPDUType.OTHER) { try { - Pdu pdu = factory.createPdu(typ); - disnet.sendPdu(pdu); + recorder.disnetworking.send(factory.createPdu(typ)); // sleep(100); } catch(Exception ex) { System.err.println("Exception sending Pdu: "+ex.getLocalizedMessage()); } } - }); + }); - System.out.println("Record for 10 seconds..."); // TODO arrrrgh this is awful - sleep(10000); - System.out.println("Recording complete."); - try { recorder.end(); } diff --git a/test/edu/nps/moves/dis7/AllPduRoundTripTest.java b/test/edu/nps/moves/dis7/AllPduRoundTripTest.java index 275926e35184753c12b495bbe40d9b2defe259e8..529a5d8e38eac381547d2b33229307d221e18e1b 100644 --- a/test/edu/nps/moves/dis7/AllPduRoundTripTest.java +++ b/test/edu/nps/moves/dis7/AllPduRoundTripTest.java @@ -62,7 +62,7 @@ public class AllPduRoundTripTest { Throwable ex = null; try { - setupReceiver(); + setupSender(); setupRecorder(); try { Thread.sleep(250L); // these have to be fully setup before continuing @@ -154,7 +154,7 @@ public class AllPduRoundTripTest // TODO is there a more reliable way to determine whether receiver is complete? - shutDownReceiver(); // TODO hopefully this finishes reading the pending buffer before shutting down + shutDownSender(); // TODO hopefully this finishes reading the pending buffer before shutting down shutDownRecorder(); System.out.println("pduReceivedMap.size()=" + pduReceivedMap.size() + ", pduSentMap.size()=" + pduSentMap.size() + @@ -187,7 +187,7 @@ public class AllPduRoundTripTest DisThreadedNetIF disnetworking; PduRecorder recorder; - private void setupReceiver() + private void setupSender() { disnetworking = new DisThreadedNetIF(); disnetworking.addListener(pdu -> { @@ -195,7 +195,7 @@ public class AllPduRoundTripTest }); } - private void shutDownReceiver() + private void shutDownSender() { disnetworking.kill(); }