diff --git a/examples/src/OpenDis7Examples/AllPduReceiver.java b/examples/src/OpenDis7Examples/AllPduReceiver.java index 101cde4519ba2917829753b1edf69e3dfba21765..3b495874e268a6903d1f88e4973650165573aa96 100644 --- a/examples/src/OpenDis7Examples/AllPduReceiver.java +++ b/examples/src/OpenDis7Examples/AllPduReceiver.java @@ -5,7 +5,7 @@ import java.io.*; import edu.nps.moves.dis7.*; import edu.nps.moves.dis7.enumerations.*; -import edu.nps.moves.dis7.util.*; +import edu.nps.moves.dis7.utilities.*; import java.util.ArrayList; public class AllPduReceiver diff --git a/examples/src/OpenDis7Examples/AllPduSender.java b/examples/src/OpenDis7Examples/AllPduSender.java index 7c2a4f6f0edb8f4e4588a4f8d14756b184208f08..e0153fa0514699020a43521ce11e335de74b959f 100755 --- a/examples/src/OpenDis7Examples/AllPduSender.java +++ b/examples/src/OpenDis7Examples/AllPduSender.java @@ -382,7 +382,7 @@ public class AllPduSender { VariableDatum newVariableDatum = new VariableDatum(); newVariableDatum.setVariableDatumValue (comment.getBytes()); // conversion - newVariableDatum.setVariableDatumLength(comment.getBytes().length * 8); // bits, not bytes, see spec and javadoc + newVariableDatum.setVariableDatumLengthInBits(comment.getBytes().length * 8); // bits, not bytes, see spec and javadoc // alternatively, you do not need to set this and the marshaller will figure it out from the byte array // (see javadoc for VariableDatum.setVariableDatumLength()) payloadList.add(newVariableDatum); diff --git a/examples/src/OpenDis7Examples/EspduReceiver.java b/examples/src/OpenDis7Examples/EspduReceiver.java index d98d61bca43d68d5ce4bf15dee4eb5b61fd08cfd..81eb4183d1f63d9b5bd8a7c51ed60de94d807e6f 100755 --- a/examples/src/OpenDis7Examples/EspduReceiver.java +++ b/examples/src/OpenDis7Examples/EspduReceiver.java @@ -5,7 +5,7 @@ import java.net.*; import java.util.*; import edu.nps.moves.dis7.*; -import edu.nps.moves.dis7.util.*; +import edu.nps.moves.dis7.utilities.*; /** * Receives PDUs from the network in IEEE DIS format. @@ -54,11 +54,9 @@ public class EspduReceiver List<Pdu> pduBundle = pduFactory.getPdusFromBundle(packet.getData(),packet.getLength()); if (pduBundle.size() > 1) System.out.println("Bundle size is " + pduBundle.size()); - Iterator iterator = pduBundle.iterator(); - - while (iterator.hasNext()) - { - Pdu aPdu = (Pdu)iterator.next(); + + // end iterator loop through PDU bundle + for (Pdu aPdu : pduBundle) { String receiptMessage = "received PDU type " + aPdu.getPduType().getValue() + "=" + aPdu.getPduType().name() + " " + aPdu.getClass().getName(); if (aPdu instanceof EntityStatePdu) { @@ -80,7 +78,7 @@ public class EspduReceiver { System.out.println(receiptMessage); } - } // end iterator loop through PDU bundle + } } // end while } // end try block catch (IOException e) diff --git a/examples/src/OpenDis7Examples/EspduSender.java b/examples/src/OpenDis7Examples/EspduSender.java index 41e77d4e27b2defd01e15e7e5fee2f52f4050994..c3c94b94f6570c9dab832ce84575ada26d621a98 100644 --- a/examples/src/OpenDis7Examples/EspduSender.java +++ b/examples/src/OpenDis7Examples/EspduSender.java @@ -5,10 +5,7 @@ import java.net.*; import java.util.*; import edu.nps.moves.dis7.*; -import edu.nps.moves.dis7.util.*; -import edu.nps.moves.dis7.enumerations.Country; -import edu.nps.moves.dis7.enumerations.EntityKind; -import edu.nps.moves.dis7.enumerations.PlatformDomain; +import edu.nps.moves.dis7.utilities.*; /** * Creates and sends ESPDUs in IEEE binary format. Adapted from OpenDIS library @@ -48,16 +45,16 @@ public class EspduSender */ public static void main(String args[]) { - System.out.println("DisExamplesOpenDis7.EspduSender started..."); + System.out.println("DisExamplesOpenDis7.EspduSender started..."); - // Default settings. These are used if no system properties are set. - // If system properties are passed in, these are overridden later. - NetworkMode networkMode = NetworkMode.BROADCAST; - InetAddress address = null; // must be initialized, even if null - int port = DEFAULT_MULTICAST_PORT; - MulticastSocket socket = null; // must be initialized to avoid later error, even if null; - EntityStatePdu espdu = new EntityStatePdu(); - DisTime disTime = new DisTime(); + // Default settings. These are used if no system properties are set. + // If system properties are passed in, these are overridden later. + NetworkMode networkMode = NetworkMode.BROADCAST; + InetAddress address = null; // must be initialized, even if null + int port = DEFAULT_MULTICAST_PORT; + MulticastSocket socket = null; // must be initialized to avoid later error, even if null; + EntityStatePdu espdu = new EntityStatePdu(); + DisTime disTime = new DisTime(); // ICBM coordinates for my office double latitude = 36.595517; @@ -212,7 +209,7 @@ public class EspduSender // The x and y values will change, but the z value should not. //lon = lon + (double)((double)idx / 100000.0); //System.out.println("lla=" + lat + "," + lon + ", 0.0"); - double direction = Math.pow((double) (-1.0), (double) (index)); + double direction = Math.pow(-1.0, (index)); longitude = longitude + (direction * 0.00006); double disCoordinates[] = CoordinateConversions.getXYZfromLatLonDegrees(latitude, longitude, 1.0); @@ -260,24 +257,20 @@ public class EspduSender byte[] fireArray = firePdu.marshal(); broadcastAddresses = getBroadcastAddresses(); - Iterator iterator = broadcastAddresses.iterator(); - while (iterator.hasNext()) - { - InetAddress broadcast = (InetAddress) iterator.next(); - if (espduArray.length > 0) - { - System.out.println("Sending espdu datagram packet to " + broadcast); - packet = new DatagramPacket(espduArray, espduArray.length, broadcast, port); - socket.send(packet); - } - // TODO experiment with these! 8) - if (fireArray.length > 0) - { - System.out.println("Sending fire datagram packet to " + broadcast); - packet = new DatagramPacket(fireArray, fireArray.length, broadcast, port); // alternate - socket.send(packet); - } - } + for (InetAddress broadcast : broadcastAddresses) { + if (espduArray.length > 0) + { + System.out.println("Sending espdu datagram packet to " + broadcast); + packet = new DatagramPacket(espduArray, espduArray.length, broadcast, port); + socket.send(packet); + } + // TODO experiment with these! 8) + if (fireArray.length > 0) + { + System.out.println("Sending fire datagram packet to " + broadcast); + packet = new DatagramPacket(fireArray, fireArray.length, broadcast, port); // alternate + socket.send(packet); + } } // Send every 1 second within loop. Otherwise all this will be all over in a fraction of a second. Thread.sleep(1000); // msec @@ -318,22 +311,19 @@ public class EspduSender if (anInterface.isUp()) { - Iterator iterator = anInterface.getInterfaceAddresses().iterator(); - while (iterator.hasNext()) - { - InterfaceAddress anAddress = (InterfaceAddress) iterator.next(); - if ((anAddress == null || anAddress.getAddress().isLinkLocalAddress())) - { - continue; - } - - //System.out.println("Getting broadcast address for " + anAddress); - InetAddress broadcastAddress = anAddress.getBroadcast(); - if (broadcastAddress != null) - { - broadcastAddresses.add(broadcastAddress); - } - } + for (InterfaceAddress anAddress : anInterface.getInterfaceAddresses()) { + if ((anAddress == null || anAddress.getAddress().isLinkLocalAddress())) + { + continue; + } + + //System.out.println("Getting broadcast address for " + anAddress); + InetAddress broadcastAddress = anAddress.getBroadcast(); + if (broadcastAddress != null) + { + broadcastAddresses.add(broadcastAddress); + } + } } } } diff --git a/examples/src/OpenDis7Examples/PduListenerSaver.java b/examples/src/OpenDis7Examples/PduListenerSaver.java index a64184e8dd6bc15af2877bb0ce5fa362bd9ed49f..226081ce0ac49e2f9630d14f4ae776a6a40fb2f7 100644 --- a/examples/src/OpenDis7Examples/PduListenerSaver.java +++ b/examples/src/OpenDis7Examples/PduListenerSaver.java @@ -4,22 +4,23 @@ */ package OpenDis7Examples; -import edu.nps.moves.dis7.util.playerrecorder.Recorder; +import edu.nps.moves.dis7.utilities.DisThreadedNetIF; +import edu.nps.moves.dis7.utilities.stream.PduRecorder; import java.io.IOException; import java.util.Scanner; -/** +/** Class to leverage the {@link edu.nps.moves.dis7.utilities.stream.PduRecorder} + * with PDU log saving console controls for resume, pause and quit. + * * PduSaver.java created on Aug 21, 2019 * MOVES Institute Naval Postgraduate School, Monterey, CA, USA www.nps.edu * * @author Mike Bailey, jmbailey@nps.edu * @version $Id$ */ -public class PduListenerSaver // TODO promote to open-dis7 library? +public class PduListenerSaver { - private final static String DEFAULT_OUTPUTDIR = "pduLog"; - private final static String MCAST_ADDR = "239.1.2.3"; - private final static int DIS_PORT = 3000; + private final static String DEFAULT_OUTPUTDIR = "./pduLog"; private enum mystate { @@ -30,10 +31,8 @@ public class PduListenerSaver // TODO promote to open-dis7 library? public static void main(String[] args) { String outDir = DEFAULT_OUTPUTDIR; - String mcast = MCAST_ADDR; - int port = DIS_PORT; - - System.out.println("DisExamplesOpenDis7.PduListenerSaver started..."); + String mcast = DisThreadedNetIF.DEFAULT_MCAST_GROUP; + int port = DisThreadedNetIF.DEFAULT_DIS_PORT; switch (args.length) { case 0: @@ -47,43 +46,36 @@ public class PduListenerSaver // TODO promote to open-dis7 library? port = Integer.parseInt(args[2]); break; default: - System.err.println("Usage: PduListener() or PduListener(\"outputdir\") or PduListener(\"outputdir\",\"multicast address\", ipPort"); + System.err.println("Usage: PduListenerSaver() or PduListenerSaver(\"outputdir\") or PduListenerSaver(\"outputdir\",\"multicast address\", ipPort"); System.exit(1); } System.out.println("Beginning pdu save to directory " + outDir); try { - Recorder recorder = new Recorder(outDir, mcast, port); - - recorder.startResume(); + PduRecorder recorder = new PduRecorder(outDir, mcast, port); // assumes save mystate state = mystate.RUNNING; - System.out.println("* recorder.startResume(), state=RUNNING, recording in progress..."); Scanner scan = new Scanner(System.in); while (true) { - System.out.println("Warning: you must quit when complete, otherwise recorded PDUs are lost!"); - System.out.println("Type p/enter to pause, r/enter to resume, q/enter to stop recording, save and quit"); + System.out.println("Type p/enter to pause, r/enter to resume, q/enter to quit"); String line = scan.nextLine(); if (line.equalsIgnoreCase("p") && state == mystate.RUNNING) { recorder.stopPause(); state = mystate.PAUSED; - System.out.println("* recorder.stopPause(), state=PAUSED, recording paused..."); } else if (line.equalsIgnoreCase("r") && state == mystate.PAUSED) { recorder.startResume(); state = mystate.RUNNING; - System.out.println("* recorder.startResume(), state=RUNNING, recording in progress..."); } else if (line.equalsIgnoreCase("q")) { recorder.end(); - System.out.println("* recorder.end(), recording complete."); break; } } System.out.println("Ending pdu save to "+recorder.getLogFile()); } catch (IOException ex) { - System.err.println("*** Exception: " + ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage()); + System.err.println("Exception: " + ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage()); } } } diff --git a/examples/src/OpenDis7Examples/PduReaderPlayer.java b/examples/src/OpenDis7Examples/PduReaderPlayer.java index 93515a581c3533c2ae797b20999fdf54db9f7c3e..463075f98ca613aef77317012028243d0fb890c9 100644 --- a/examples/src/OpenDis7Examples/PduReaderPlayer.java +++ b/examples/src/OpenDis7Examples/PduReaderPlayer.java @@ -4,12 +4,15 @@ */ package OpenDis7Examples; -import edu.nps.moves.dis7.util.playerrecorder.Player; -import java.io.File; +import edu.nps.moves.dis7.utilities.DisThreadedNetIF; +import edu.nps.moves.dis7.utilities.stream.PduPlayer; import java.io.IOException; +import java.nio.file.Path; import java.util.Scanner; -/** +/** Class to leverage the {@link edu.nps.moves.dis7.utilities.stream.PduPlayer} + * with PDU log playback console controls for resume, pause and quit. + * * PduSaver.java created on Aug 21, 2019 * MOVES Institute Naval Postgraduate School, Monterey, CA, USA www.nps.edu * @@ -18,9 +21,7 @@ import java.util.Scanner; */ public class PduReaderPlayer { - private final static String DEFAULT_OUTPUTDIR = "pduLog"; - private final static String MCAST_ADDR = "239.1.2.3"; - private final static int DIS_PORT = 3000; + private final static String DEFAULT_OUTPUTDIR = "./pduLog"; private enum mystate { @@ -31,31 +32,33 @@ public class PduReaderPlayer public static void main(String[] args) { String outDir = DEFAULT_OUTPUTDIR; - String mcast = MCAST_ADDR; - int port = DIS_PORT; - - System.out.println("DisExamplesOpenDis7.PduReaderPlayer started..."); + String mcast = DisThreadedNetIF.DEFAULT_MCAST_GROUP; + int port = DisThreadedNetIF.DEFAULT_DIS_PORT; + boolean sendToNet = false; switch (args.length) { case 0: break; case 1: outDir = args[0]; + sendToNet = Boolean.valueOf(args[1]); break; case 3: outDir = args[0]; mcast = args[1]; port = Integer.parseInt(args[2]); + sendToNet = Boolean.valueOf(args[3]); break; default: - System.err.println("Usage: PduReaderPlayer() or PduReaderPlayer(\"outputdir\") or PduReaderPlayer(\"outputdir\",\"multicast address\", ipPort"); + System.err.println("Usage: PduReaderPlayer() or " + + "PduReaderPlayer(\"outputdir\", \"sendToNet true/false\") or " + + "PduReaderPlayer(\"outputdir\", \"multicast address\", \"ipPort\", \"sendToNet true/false\""); System.exit(1); } System.out.println("Beginning pdu playback from directory " + outDir); try { - Player player = new Player(mcast, port, new File(outDir).toPath()); - player.startResume(); + PduPlayer pduPlayer = new PduPlayer(mcast, port, Path.of(outDir), sendToNet); mystate state = mystate.RUNNING; Scanner scan = new Scanner(System.in); @@ -63,21 +66,19 @@ public class PduReaderPlayer System.out.println("Type p/enter to pause, r/enter to resume, q/enter to quit"); String line = scan.nextLine(); if (line.equalsIgnoreCase("p") && state == mystate.RUNNING) { - player.stopPause(); + pduPlayer.stopPause(); state = mystate.PAUSED; } else if (line.equalsIgnoreCase("r") && state == mystate.PAUSED) { - player.startResume(); + pduPlayer.startResume(); state = mystate.RUNNING; } else if (line.equalsIgnoreCase("q")) { - player.end(); + pduPlayer.end(); break; } } - System.out.println("Ending pdu files playback for directory " + outDir); - System.out.println("DisExamplesOpenDis7.PduReaderPlayer complete."); - System.exit(0); // not sure why this is necessary with Netbeans... + System.out.println("Ending pdu playback from "+outDir); } catch (IOException ex) { System.err.println("Exception: " + ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage());