Skip to content
Snippets Groups Projects
Commit f5eb765c authored by Brutzman, Don's avatar Brutzman, Don
Browse files

multiple refinements to allow satisfactory subclassing

parent c30e3060
No related branches found
No related tags found
No related merge requests found
...@@ -22,16 +22,29 @@ import java.util.logging.Logger; ...@@ -22,16 +22,29 @@ import java.util.logging.Logger;
*/ */
public class ExampleSimulationProgram public class ExampleSimulationProgram
{ {
private boolean verboseComments = true; protected boolean verboseComments = true;
static final String NETWORK_ADDRESS_DEFAULT = "239.1.2.3"; static final String NETWORK_ADDRESS_DEFAULT = "239.1.2.3";
static final int NETWORK_PORT_DEFAULT = 3000; static final int NETWORK_PORT_DEFAULT = 3000;
static String networkAddress = NETWORK_ADDRESS_DEFAULT; String networkAddress = NETWORK_ADDRESS_DEFAULT;
static int networkPort = NETWORK_PORT_DEFAULT; int networkPort = NETWORK_PORT_DEFAULT;
String DEFAULT_OUTPUT_DIRECTORY = "./pduLog"; String DEFAULT_OUTPUT_DIRECTORY = "./pduLog";
/** seconds for real-time execution (not simulation time, which may or may not be the same) */
double currentTimeStep = 1.0; // seconds
/** initial simulation time */
double initialTime = 0.0;
/** current simulation time */
double simulationTime;
/**
* Output prefix to identify this class (override in subclass), helps with logging
*/
private final static String TRACE_PREFIX = "[" + ExampleSimulationProgram.class.getName() + "] ";
/** /**
* This runSimulationLoops() method is for you, a * This runSimulationLoops() method is for you, a programmer-modifiable code block
* programmer-modifiable method for defining and running a new simulation of interest. * for defining and running a new simulation of interest.
*
* Welcome! Other parts of this program handle bookkeeping and plumbing tasks so that * Welcome! Other parts of this program handle bookkeeping and plumbing tasks so that
* you can focus on your model entities and activities. * you can focus on your model entities and activities.
* Expandable support includes DIS EntityStatePdu, FirePdu and CommentPdu all available for * Expandable support includes DIS EntityStatePdu, FirePdu and CommentPdu all available for
...@@ -45,12 +58,10 @@ public class ExampleSimulationProgram ...@@ -45,12 +58,10 @@ public class ExampleSimulationProgram
public void runSimulationLoops () public void runSimulationLoops ()
{ {
try try
{ {
/** seconds for real-time execution (not simulation time, which may or may not be the same) */ final int SIMULATION_MAX_LOOP_COUNT = 10; // be deliberate out there! also avoid infinite loops.
final double SIMULATION_LOOP_DURATION_SECONDS = 1.0;
final int SIMULATION_MAX_LOOP_COUNT = 10; // be deliberate out out there! also avoid infinite loops.
int simulationLoopCount = 0; // variable, initialized at 0 int simulationLoopCount = 0; // variable, initialized at 0
boolean simulationComplete = false; // sentinel variable as termination condition,, are we done yet? boolean simulationComplete = false; // sentinel variable as termination condition, are we done yet?
// TODO reset clock to zero each time for consistent outputs // TODO reset clock to zero each time for consistent outputs
...@@ -121,8 +132,8 @@ public class ExampleSimulationProgram ...@@ -121,8 +132,8 @@ public class ExampleSimulationProgram
// staying synchronized with timestep: wait duration for elapsed time in this loop // staying synchronized with timestep: wait duration for elapsed time in this loop
// Thread.sleep needs a (long) parameter for milliseconds, which are clumsy to use sometimes // Thread.sleep needs a (long) parameter for milliseconds, which are clumsy to use sometimes
Thread.sleep((long)(SIMULATION_LOOP_DURATION_SECONDS * 1000)); // seconds * (1000 msec/sec) = milliseconds Thread.sleep((long)(currentTimeStep * 1000)); // seconds * (1000 msec/sec) = milliseconds
System.out.println ("... [Pausing for " + SIMULATION_LOOP_DURATION_SECONDS + " seconds]"); System.out.println ("... [Pausing for " + currentTimeStep + " seconds]");
// OK now send the status PDUs for this loop, and then continue // OK now send the status PDUs for this loop, and then continue
System.out.println ("sending PDUs for simulation step " + simulationLoopCount + ", monitor loopback to confirm sent"); System.out.println ("sending PDUs for simulation step " + simulationLoopCount + ", monitor loopback to confirm sent");
...@@ -162,11 +173,6 @@ public class ExampleSimulationProgram ...@@ -162,11 +173,6 @@ public class ExampleSimulationProgram
VariableRecordType statusComment = VariableRecordType.APPLICATION_STATUS; VariableRecordType statusComment = VariableRecordType.APPLICATION_STATUS;
VariableRecordType timeStepComment = VariableRecordType.APPLICATION_TIMESTEP; VariableRecordType timeStepComment = VariableRecordType.APPLICATION_TIMESTEP;
VariableRecordType otherComment = VariableRecordType.OTHER; VariableRecordType otherComment = VariableRecordType.OTHER;
/**
* Output prefix to identify this class, helps with logging
*/
private final static String TRACE_PREFIX = "[" + ExampleSimulationProgram.class.getName() + "] ";
// class variables // class variables
PduFactory pduFactory = new PduFactory(); PduFactory pduFactory = new PduFactory();
...@@ -191,6 +197,8 @@ public class ExampleSimulationProgram ...@@ -191,6 +197,8 @@ public class ExampleSimulationProgram
*/ */
public ExampleSimulationProgram(String address, int port) public ExampleSimulationProgram(String address, int port)
{ {
super(); // if code block is provided
setNetworkAddress(address); setNetworkAddress(address);
setNetworkPort(port); setNetworkPort(port);
...@@ -209,7 +217,7 @@ public class ExampleSimulationProgram ...@@ -209,7 +217,7 @@ public class ExampleSimulationProgram
*/ */
public final void setNetworkAddress(String newNetworkAddress) public final void setNetworkAddress(String newNetworkAddress)
{ {
ExampleSimulationProgram.networkAddress = newNetworkAddress; this.networkAddress = newNetworkAddress;
} }
/** /**
...@@ -225,7 +233,7 @@ public class ExampleSimulationProgram ...@@ -225,7 +233,7 @@ public class ExampleSimulationProgram
*/ */
public final void setNetworkPort(int newNetworkPort) public final void setNetworkPort(int newNetworkPort)
{ {
ExampleSimulationProgram.networkPort = newNetworkPort; this.networkPort = newNetworkPort;
} }
/** /**
...@@ -255,7 +263,7 @@ public class ExampleSimulationProgram ...@@ -255,7 +263,7 @@ public class ExampleSimulationProgram
pduRecorder = new PduRecorder(outputDirectory, getNetworkAddress(), getNetworkPort()); // assumes save pduRecorder = new PduRecorder(outputDirectory, getNetworkAddress(), getNetworkPort()); // assumes save
pduRecorder.setDescriptor ("ExampleSimulationProgram pduRecorder"); pduRecorder.setDescriptor ("ExampleSimulationProgram pduRecorder");
pduRecorder.setEncodingPduLog(PduRecorder.ENCODING_PLAINTEXT); pduRecorder.setEncodingPduLog(PduRecorder.ENCODING_PLAINTEXT);
pduRecorder.setVerbose(true); pduRecorder.setVerbose(true); // either sending, receiving or both
pduRecorder.start(); // begin running pduRecorder.start(); // begin running
} }
...@@ -275,7 +283,7 @@ public class ExampleSimulationProgram ...@@ -275,7 +283,7 @@ public class ExampleSimulationProgram
* Send a single Protocol Data Unit (PDU) of any type * Send a single Protocol Data Unit (PDU) of any type
* @param pdu the pdu to send * @param pdu the pdu to send
*/ */
private void sendSinglePdu(Pdu pdu) protected void sendSinglePdu(Pdu pdu)
{ {
try try
{ {
...@@ -352,11 +360,11 @@ public class ExampleSimulationProgram ...@@ -352,11 +360,11 @@ public class ExampleSimulationProgram
*/ */
public static void main(String[] args) public static void main(String[] args)
{ {
System.out.println(TRACE_PREFIX + "started..."); System.out.println(TRACE_PREFIX + "main() started...");
ExampleSimulationProgram thisProgram = new ExampleSimulationProgram(); // creates instance ExampleSimulationProgram thisProgram = new ExampleSimulationProgram(); // creates instance within static main() method
// initial execution: can handle args array of initialization arguments here // initial execution: handle args array of initialization arguments here
if (args.length == 2) if (args.length == 2)
{ {
if ((args[0] != null) && !args[0].isEmpty()) if ((args[0] != null) && !args[0].isEmpty())
...@@ -367,7 +375,7 @@ public class ExampleSimulationProgram ...@@ -367,7 +375,7 @@ public class ExampleSimulationProgram
} }
else if (args.length != 0) else if (args.length != 0)
{ {
System.err.println("Usage: " + thisProgram.getClass().getName() + " [address port]"); System.err.println("Usage: " + thisProgram.getClass().getSimpleName() + " [address port]");
System.exit(-1); System.exit(-1);
} }
// OK here we go... // OK here we go...
......
...@@ -6,12 +6,12 @@ Updating property file: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\b ...@@ -6,12 +6,12 @@ Updating property file: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\b
Compiling 1 source file to C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\classes Compiling 1 source file to C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\build\classes
compile-single: compile-single:
run-single: run-single:
[OpenDis7Examples.ExampleSimulationProgram] started... [OpenDis7Examples.ExampleSimulationProgram] main() started...
[DisThreadedNetworkInterface] using network interface Intel(R) Wi-Fi 6E AX210 160MHz [DisThreadedNetworkInterface] using network interface Intel(R) Wi-Fi 6E AX210 160MHz
[DisThreadedNetworkInterface] datagramSocket.joinGroup address=239.1.2.3 port=3000 start() complete [DisThreadedNetworkInterface] datagramSocket.joinGroup address=239.1.2.3 port=3000 start() complete
Network confirmation: address=239.1.2.3 port=3000 Network confirmation: address=239.1.2.3 port=3000
Beginning pdu save to directory ./pduLog Beginning pdu save to directory ./pduLog
Recorder log file open: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog.dislog Recorder log file open: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog29.dislog
[DisThreadedNetworkInterface] using network interface Intel(R) Wi-Fi 6E AX210 160MHz [DisThreadedNetworkInterface] using network interface Intel(R) Wi-Fi 6E AX210 160MHz
[DisThreadedNetworkInterface] datagramSocket.joinGroup address=239.1.2.3 port=3000 start() complete [DisThreadedNetworkInterface] datagramSocket.joinGroup address=239.1.2.3 port=3000 start() complete
[PduRecorder ExampleSimulationProgram pduRecorder] listening to IP address 239.1.2.3 on port 3000 [PduRecorder ExampleSimulationProgram pduRecorder] listening to IP address 239.1.2.3 on port 3000
...@@ -25,8 +25,8 @@ sending PDUs for simulation step 1, monitor loopback to confirm sent ...@@ -25,8 +25,8 @@ sending PDUs for simulation step 1, monitor loopback to confirm sent
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 2] DisPduType 02 FIRE, size 96 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 2] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 2] DisPduType 02 FIRE, size 96 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 2] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 3] DisPduType 22 COMMENT, size 104 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 3] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 3] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 3] DisPduType 22 COMMENT, size 104 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 3] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 3] DisPduType 22 COMMENT, size 104 bytes)
*** [Narrative comment sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 1] *** [Narrative comment sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 1]
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 4] DisPduType 01 ENTITY_STATE, size 144 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 4] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 4] DisPduType 01 ENTITY_STATE, size 144 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 4] DisPduType 01 ENTITY_STATE, size 144 bytes)
...@@ -46,15 +46,15 @@ sending PDUs for simulation step 2, monitor loopback to confirm sent ...@@ -46,15 +46,15 @@ sending PDUs for simulation step 2, monitor loopback to confirm sent
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 7] DisPduType 22 COMMENT, size 104 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 7] DisPduType 22 COMMENT, size 104 bytes)
*** [Narrative comment sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 2] *** [Narrative comment sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 2]
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 8] DisPduType 01 ENTITY_STATE, size 144 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 8] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 8] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 8] DisPduType 01 ENTITY_STATE, size 144 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 8] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 8] DisPduType 01 ENTITY_STATE, size 144 bytes)
... [PDUs successfully sent for this loop] ... [PDUs successfully sent for this loop]
... My simulation just did something, no really... ... My simulation just did something, no really...
... [Pausing for 1.0 seconds] ... [Pausing for 1.0 seconds]
sending PDUs for simulation step 3, monitor loopback to confirm sent sending PDUs for simulation step 3, monitor loopback to confirm sent
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 9] DisPduType 01 ENTITY_STATE, size 144 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 9] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 9] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 9] DisPduType 01 ENTITY_STATE, size 144 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 9] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 9] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 10] DisPduType 02 FIRE, size 96 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 10] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 10] DisPduType 02 FIRE, size 96 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 10] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 10] DisPduType 02 FIRE, size 96 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 10] DisPduType 02 FIRE, size 96 bytes)
...@@ -76,8 +76,8 @@ sending PDUs for simulation step 4, monitor loopback to confirm sent ...@@ -76,8 +76,8 @@ sending PDUs for simulation step 4, monitor loopback to confirm sent
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 14] DisPduType 02 FIRE, size 96 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 14] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 14] DisPduType 02 FIRE, size 96 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 14] DisPduType 02 FIRE, size 96 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 15] DisPduType 22 COMMENT, size 104 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 15] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 15] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 15] DisPduType 22 COMMENT, size 104 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 15] DisPduType 22 COMMENT, size 104 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pduRecorder] [receipt 15] DisPduType 22 COMMENT, size 104 bytes)
*** [Narrative comment sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 4] *** [Narrative comment sent: APPLICATION_TIMESTEP] [MV3500 ExampleSimulationProgram, runSimulation() loop 4]
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 16] DisPduType 01 ENTITY_STATE, size 144 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [sending 16] DisPduType 01 ENTITY_STATE, size 144 bytes)
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 16] DisPduType 01 ENTITY_STATE, size 144 bytes) [DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] [receipt 16] DisPduType 01 ENTITY_STATE, size 144 bytes)
...@@ -107,7 +107,6 @@ sending PDUs for simulation step 5, monitor loopback to confirm sent ...@@ -107,7 +107,6 @@ sending PDUs for simulation step 5, monitor loopback to confirm sent
*** [Narrative comment sent: COMPLETE_EVENT_REPORT] [MV3500 ExampleSimulationProgram, runSimulation() completed successfully] *** [Narrative comment sent: COMPLETE_EVENT_REPORT] [MV3500 ExampleSimulationProgram, runSimulation() completed successfully]
... [final CommentPdu successfully sent for simulation] ... [final CommentPdu successfully sent for simulation]
Closing recorder log file: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog.dislog Closing recorder log file: C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\PduCaptureLog29.dislog
[DisThreadedNetworkInterface ExampleSimulationProgram pdu looping] datagramSocket.leaveGroup address=239.1.2.3 port=3000 stop() complete
[OpenDis7Examples.ExampleSimulationProgram] complete. [OpenDis7Examples.ExampleSimulationProgram] complete.
BUILD SUCCESSFUL (total time: 17 seconds) BUILD SUCCESSFUL (total time: 9 seconds)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment