Skip to content
Snippets Groups Projects
Commit 6fa24d76 authored by adfis's avatar adfis
Browse files

Commit of some old/test files for Homework 3 and Project. Not ready to be used yet.

parent 7a8578b8
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,13 @@ import java.util.logging.Logger;
*/
public class ExampleSimulationProgramFisher
{
private boolean verboseComments = true;
static final String NETWORK_ADDRESS_DEFAULT = "239.1.2.3";
static final int NETWORK_PORT_DEFAULT = 3000;
static String networkAddress = NETWORK_ADDRESS_DEFAULT;
static int networkPort = NETWORK_PORT_DEFAULT;
String DEFAULT_OUTPUT_DIRECTORY = "./pduLog";
/**
* This runSimulation() method is for you, a
* programmer-modifiable method for defining and running a new simulation of interest.
......@@ -170,7 +177,7 @@ public class ExampleSimulationProgramFisher
}
/* **************************** infrastructure code, modification is seldom needed ************************* */
private boolean verboseComments = true;
//private boolean verboseComments = true;
String narrativeMessage1 = new String();
String narrativeMessage2 = new String();
String narrativeMessage3 = new String();
......@@ -194,11 +201,12 @@ public class ExampleSimulationProgramFisher
DisThreadedNetworkInterface.PduListener pduListener;
Pdu receivedPdu;
static final String NETWORK_ADDRESS_DEFAULT = "239.1.2.3";
static final int NETWORK_PORT_DEFAULT = 3000;
static String networkAddress = NETWORK_ADDRESS_DEFAULT;
static int networkPort = NETWORK_PORT_DEFAULT;
//static final String NETWORK_ADDRESS_DEFAULT = "239.1.2.3";
//static final int NETWORK_PORT_DEFAULT = 3000;
//static String networkAddress = NETWORK_ADDRESS_DEFAULT;
//static int networkPort = NETWORK_PORT_DEFAULT;
// String DEFAULT_OUTPUT_DIRECTORY = "./pduLog";
/**
* Constructor design goal: additional built-in initialization conveniences can go here
* to keep student efforts focused on the runSimulation() method.
......@@ -403,9 +411,10 @@ public class ExampleSimulationProgramFisher
System.out.println("Beginning pdu save to directory " + outputDirectory);
PduRecorder pduRecorder = new PduRecorder(outputDirectory, networkAddress, networkPort); // assumes save
//
thisProgram.runSimulation (); // ... your simulation execution code goes in there ...
//pduRecorder.end();
pduRecorder.stop();
thisProgram.tearDownNetworkInterface(); // make sure no processes are left lingering
......
package MV3500Cohort2021JulySeptember.projects.Fisher;
import edu.nps.moves.dis7.enumerations.VariableRecordType;
import edu.nps.moves.dis7.pdus.Pdu;
import edu.nps.moves.dis7.utilities.PduFactory;
/**
*
* @author adfis
*/
public class CommentPDUFisherTest {
//BeforeAll
public static void setUpClass()
{
System.out.println("CommentPdusTest");
}
//AfterAll
public static void tearDownClass()
{
}
//BeforeEach
public void setUp()
{
}
//AfterEach
public void tearDown()
{
}
private Pdu receivedPdu;
//Test
public void testRoundTrip()
{
PduFactory factory = new PduFactory();
setUpReceiver();
testOne(factory.makeCommentPdu());
testOne(factory.makeCommentPdu("123_test_string"));
testOne(factory.makeCommentPdu(VariableRecordType.MODEL_TYPE, "456_test with type = modeltype"));
testOne(factory.makeCommentPdu("xyz first message","mno second message", "jkl third message"));
testOne(factory.makeCommentReliablePdu());
testOne(factory.makeCommentReliablePdu("789_test_string"));
testOne(factory.makeCommentReliablePdu(VariableRecordType.ACLS_AIRCRAFT_REPORT, "abc_test with type = acls_aircraft_report"));
testOne(factory.makeCommentReliablePdu("xyz R first message","mno R second message", "jkl R third message"));
}
private void testOne(Pdu pdu)
{
sendPdu(pdu); // will wait a while
assertTrue(receivedPdu != null, "No response from network receive");
assertTrue(compare(pdu,receivedPdu),"Comparison failed");
receivedPdu = null;
}
private void sendPdu(Pdu pdu)
{
try {
Thread.sleep(250l); // make sure receiver is listening
DisNetworking disnet = new DisNetworking();
disnet.sendPdu(pdu);
Thread.sleep(1000l);
}
catch (InterruptedException ex) {
System.err.println("Error sending Multicast: " + ex.getLocalizedMessage());
System.exit(1);
}
}
private boolean compare(Pdu pdu1, Pdu pdu2)
{
return pdu1.equals(pdu2);
}
private void setUpReceiver()
{
Thread rcvThread = new Thread(() -> {
while(true) {
receivedPdu = new DisNetworking().receivePdu(); // blocks
}
});
rcvThread.setPriority(Thread.NORM_PRIORITY);
rcvThread.setDaemon(true);
rcvThread.start();
}
/**
*
* @param args
*/
public static void main(String[] args)
{
//new CommentPdusTest().testRoundTrip();
}
private void assertTrue(boolean b, String no_response_from_network_receive) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private static class CommentPdusTest {
public CommentPdusTest() {
}
//private void testRoundTrip() {
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
// }
}
private static class DisNetworking {
public DisNetworking() {
}
private Pdu receivePdu() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
private void sendPdu(Pdu pdu) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
}
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