diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework3/Fisher/ExampleSimulationProgramFisher.java b/assignments/src/MV3500Cohort2021JulySeptember/homework3/Fisher/ExampleSimulationProgramFisher.java index 203500b18d10c72f973fbfbc2427da75f7442abf..fb4b1ee95a7077e6883f835467d4b4efd3fd94ed 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework3/Fisher/ExampleSimulationProgramFisher.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework3/Fisher/ExampleSimulationProgramFisher.java @@ -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 diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework3/Frank/FrankAssisgmentThreeSimulationWireShark.pdf b/assignments/src/MV3500Cohort2021JulySeptember/homework3/Frank/FrankAssisgmentThreeSimulationWireShark.pdf new file mode 100644 index 0000000000000000000000000000000000000000..d1521da6db4dfd68f0304ba45b50b3826990a6ea Binary files /dev/null and b/assignments/src/MV3500Cohort2021JulySeptember/homework3/Frank/FrankAssisgmentThreeSimulationWireShark.pdf differ diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework3/Frank/PduCaptureLog9.dislog b/assignments/src/MV3500Cohort2021JulySeptember/homework3/Frank/PduCaptureLog9.dislog new file mode 100644 index 0000000000000000000000000000000000000000..8f9a5d932bf28f4510ce9946aadb85463d544538 --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework3/Frank/PduCaptureLog9.dislog @@ -0,0 +1,19 @@ +# Start, ENCODING_PLAINTEXT, 20210903_081736, DIS capture file, .\pduLog\PduCaptureLog9.dislog +[0,0,0,0,0,0,0,0],[7,1,1,1,74,-12,49,-59,0,-112,40,0,0,1,0,13,0,25,0,0,1,1,0,-31,1,1,1,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-63,68,-88,22,93,-11,3,30,-63,80,-101,96,51,-37,-21,-34,65,76,-38,101,8,67,-70,62,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] # DisPduType 01 ENTITY_STATE +[0,0,0,0,6,70,51,-28],[7,1,2,2,74,-12,87,13,0,96,40,0,0,2,0,3,0,0,0,2,0,3,0,0,0,2,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] # DisPduType 02 FIRE +[0,0,0,0,12,-24,92,104],[7,1,22,5,75,28,-50,-5,0,32,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,-81,-46,0,0,1,8,77,86,51,53,48,48,32,70,114,97,110,107,65,115,115,105,103,110,109,101,110,116,51,83,105,109,117,108,97,116,105,111,110,0,0,0,0,0,0,0,0,0,-81,-46,0,0,0,-80,114,117,110,83,105,109,117,108,97,116,105,111,110,40,41,32,108,111,111,112,32,49,0,0] # DisPduType 22 COMMENT +[0,0,0,0,-118,-23,-42,120],[7,1,1,1,74,-12,49,-59,0,-112,40,0,0,1,0,13,0,25,0,0,1,1,0,-31,1,1,1,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-63,68,-88,31,-35,-11,3,30,-63,80,-101,114,-13,-37,-21,-34,65,76,-38,101,8,67,-70,62,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] # DisPduType 01 ENTITY_STATE +[0,0,0,0,-111,89,-4,64],[7,1,2,2,74,-12,87,13,0,96,40,0,0,2,0,3,0,0,0,2,0,3,0,0,0,2,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] # DisPduType 02 FIRE +[0,0,0,0,-105,-51,-31,4],[7,1,22,5,75,71,71,-115,0,32,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,-81,-46,0,0,1,8,77,86,51,53,48,48,32,70,114,97,110,107,65,115,115,105,103,110,109,101,110,116,51,83,105,109,117,108,97,116,105,111,110,0,0,0,0,0,0,0,0,0,-81,-46,0,0,0,-80,114,117,110,83,105,109,117,108,97,116,105,111,110,40,41,32,108,111,111,112,32,50,0,0] # DisPduType 22 COMMENT +[0,0,0,1,22,32,-73,-4],[7,1,1,1,74,-12,49,-59,0,-112,40,0,0,1,0,13,0,25,0,0,1,1,0,-31,1,1,1,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-63,68,-88,41,93,-11,3,30,-63,80,-101,-123,-77,-37,-21,-34,65,76,-38,101,8,67,-70,62,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] # DisPduType 01 ENTITY_STATE +[0,0,0,1,28,-103,18,40],[7,1,2,2,74,-12,87,13,0,96,40,0,0,2,0,3,0,0,0,2,0,3,0,0,0,2,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] # DisPduType 02 FIRE +[0,0,0,1,35,22,-49,60],[7,1,22,5,75,113,-50,25,0,32,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,-81,-46,0,0,1,8,77,86,51,53,48,48,32,70,114,97,110,107,65,115,115,105,103,110,109,101,110,116,51,83,105,109,117,108,97,116,105,111,110,0,0,0,0,0,0,0,0,0,-81,-46,0,0,0,-80,114,117,110,83,105,109,117,108,97,116,105,111,110,40,41,32,108,111,111,112,32,51,0,0] # DisPduType 22 COMMENT +[0,0,0,1,41,-121,33,40],[7,1,62,10,74,-12,87,13,0,32,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,3,-87,-128,0,0,1,-72,77,49,32,65,98,114,97,109,115,32,65,99,113,117,105,114,101,115,32,84,97,114,103,101,116,32,45,32,84,54,50,32,119,105,116,104,32,105,110,32,102,105,114,105,110,103,32,100,105,115,116,97,110,99,101,0] # DisPduType 62 COMMENT_RELIABLE +[0,0,0,1,-89,-38,-69,112],[7,1,1,1,74,-12,49,-59,0,-112,40,0,0,1,0,13,0,25,0,0,1,1,0,-31,1,1,1,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-63,68,-88,50,-35,-11,3,30,-63,80,-101,-104,115,-37,-21,-34,65,76,-38,101,8,67,-70,62,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] # DisPduType 01 ENTITY_STATE +[0,0,0,1,-82,51,97,-104],[7,1,2,2,74,-12,87,13,0,96,40,0,0,2,0,3,0,0,0,2,0,3,0,0,0,2,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] # DisPduType 02 FIRE +[0,0,0,1,-76,-84,14,-8],[7,1,22,5,75,-98,71,77,0,32,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,-81,-46,0,0,1,8,77,86,51,53,48,48,32,70,114,97,110,107,65,115,115,105,103,110,109,101,110,116,51,83,105,109,117,108,97,116,105,111,110,0,0,0,0,0,0,0,0,0,-81,-46,0,0,0,-80,114,117,110,83,105,109,117,108,97,116,105,111,110,40,41,32,108,111,111,112,32,52,0,0] # DisPduType 22 COMMENT +[0,0,0,2,50,-55,-62,108],[7,1,1,1,74,-12,49,-59,0,-112,40,0,0,1,0,13,0,25,0,0,1,1,0,-31,1,1,1,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-63,68,-88,60,93,-11,3,30,-63,80,-101,-85,51,-37,-21,-34,65,76,-38,101,8,67,-70,62,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] # DisPduType 01 ENTITY_STATE +[0,0,0,2,57,58,-37,-12],[7,1,2,2,74,-12,87,13,0,96,40,0,0,2,0,3,0,0,0,2,0,3,0,0,0,2,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,-31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] # DisPduType 02 FIRE +[0,0,0,2,63,-78,116,-60],[7,1,22,5,75,-56,-65,-33,0,32,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,-81,-46,0,0,1,8,77,86,51,53,48,48,32,70,114,97,110,107,65,115,115,105,103,110,109,101,110,116,51,83,105,109,117,108,97,116,105,111,110,0,0,0,0,0,0,0,0,0,-81,-46,0,0,0,-80,114,117,110,83,105,109,117,108,97,116,105,111,110,40,41,32,108,111,111,112,32,53,0,0] # DisPduType 22 COMMENT +[0,0,0,2,70,54,59,40],[7,1,22,5,75,-54,-69,-39,0,32,40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,9,90,-90,0,0,1,8,77,86,51,53,48,48,32,70,114,97,110,107,65,115,115,105,103,110,109,101,110,116,51,83,105,109,117,108,97,116,105,111,110,0,0,0,0,0,0,0,0,9,90,-90,0,0,1,48,114,117,110,83,105,109,117,108,97,116,105,111,110,40,41,32,99,111,109,112,108,101,116,101,100,32,115,117,99,99,101,115,115,102,117,108,108,121,0,0] # DisPduType 22 COMMENT +# Finish, ENCODING_PLAINTEXT, 20210903_081746, DIS capture file, .\pduLog\PduCaptureLog9.dislog diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework3/Lentz/assignment_3_walkthrough.ipynb b/assignments/src/MV3500Cohort2021JulySeptember/homework3/Lentz/assignment_3_walkthrough.ipynb index b917e4dd644af15a01475fa8105317cd9d707edf..abcf668fe4aef7f6f49f7c7960466290a9def6e5 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework3/Lentz/assignment_3_walkthrough.ipynb +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework3/Lentz/assignment_3_walkthrough.ipynb @@ -703,7 +703,7 @@ "# next we \n", "def send(lat, lon, alt):\n", " pdu = EntityStatePdu()\n", - " pdu.entityID.entityID = 42\n", + " pdu.entityID.entityID = 1.2.225.85.11.5\n", " pdu.entityID.siteID = 17\n", " pdu.entityID.applicationID = 23\n", "\n", diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework3/McNeely/ExampleSimulationProgramMcNeely.java b/assignments/src/MV3500Cohort2021JulySeptember/homework3/McNeely/ExampleSimulationProgramMcNeely.java index 56337a2abd717aedba8541df8b1fd275ec311a3c..b58ba263b14b51c4e275080be861f0b471b236f2 100644 --- a/assignments/src/MV3500Cohort2021JulySeptember/homework3/McNeely/ExampleSimulationProgramMcNeely.java +++ b/assignments/src/MV3500Cohort2021JulySeptember/homework3/McNeely/ExampleSimulationProgramMcNeely.java @@ -86,7 +86,7 @@ public class ExampleSimulationProgramMcNeely // make your reports: narrative code for CommentPdu here (set all to empty strings to avoid sending) narrativeMessage1 = "MV3500 ExampleSimulationProgram"; narrativeMessage2 = "runSimulation() loop " + loopCount; - narrativeMessage3 = "Well... there it is."; // intentionally blank for testing + narrativeMessage3 = "Well... there it is."; //In the great words of Jeff Goldblum // your loop termination condition goes here if (loopCount > 4) // for example diff --git a/assignments/src/MV3500Cohort2021JulySeptember/homework4/Frank/CPT Justin J.docx b/assignments/src/MV3500Cohort2021JulySeptember/homework4/Frank/CPT Justin J.docx new file mode 100644 index 0000000000000000000000000000000000000000..d9ed9fb5cb775c5b7f36fc3a7b07910b80c15b89 Binary files /dev/null and b/assignments/src/MV3500Cohort2021JulySeptember/homework4/Frank/CPT Justin J.docx differ diff --git a/assignments/src/MV3500Cohort2021JulySeptember/projects/Fisher/.gitkeep b/assignments/src/MV3500Cohort2021JulySeptember/projects/Fisher/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/assignments/src/MV3500Cohort2021JulySeptember/projects/Fisher/MV3500ProjectFisher.java b/assignments/src/MV3500Cohort2021JulySeptember/projects/Fisher/MV3500ProjectFisher.java new file mode 100644 index 0000000000000000000000000000000000000000..ccb55e6530dad4afd4b2b6675c2ce49b5ae7f93a --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/projects/Fisher/MV3500ProjectFisher.java @@ -0,0 +1,453 @@ +/** + * Copyright (c) 2008-2021, 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 + * + * This Program is a modified version of ExampleSimulationProgramFisher in order to see the + * verbose plain text pdu log. I was unable to figure out the issue in my original code, + * so I just copied the example and pasted my additions into this file. + * + * @author adfis + */ +package MV3500Cohort2021JulySeptember.projects.Fisher; + +import edu.nps.moves.dis7.enumerations.*; // match any +import edu.nps.moves.dis7.pdus.*; // match any of the PDU classes, easier than listing individually +import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface; +import edu.nps.moves.dis7.utilities.PduFactory; +import edu.nps.moves.dis7.utilities.stream.PduRecorder; +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** The purpose of this program is to provide an easily modifiable example simulation program + * that includes DIS-capable entities doing tasks and reporting them to the network. + * Default settings include PDU recording turned on by default. + */ +public class MV3500ProjectFisher +{ + 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 = "./src./MV3500Cohort2021JulySeptember./projects./Fisher./pdulogs"; + + /** + * This runSimulationLoops() method is for you, a + * programmer-modifiable method for defining and running a new simulation of interest. + * Welcome! Other parts of this program handle bookkeeping and plumbing tasks so that + * you can focus on your model entities and activities. + * Expandable support includes DIS EntityStatePdu, FirePdu and CommentPdu all available for + * modification and sending in a simulation loop. + * Continuous improvement efforts seek to make this program as easy and straightforward + * as possible for DIS simulationists to use and adapt. + * All of the other methods are setup, teardown and configuration that you may find + * interesting, even helpful, but don't really have to worry about. + */ + @SuppressWarnings("SleepWhileInLoop") // yes we do that + public void runSimulationLoops () + { + try + { + /** seconds for real-time execution (not simulation time, which may or may not be the same) */ + 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 + boolean simulationComplete = false; // sentinel variable as termination condition,, are we done yet? + + // TODO reset clock to zero each time for consistent outputs + + // Your model setup: define participants. who's who in this zoo? + // Assuming you keep track of entity objects... here is some support for for Entity 1. + + // create PDU objects and set their values. + EntityID entityID_1 = new EntityID(); + entityID_1.setEntityID(1); // made-up example ID; + // create PDU objects and set their values. + EntityID entityID_2 = new EntityID(); + entityID_2.setEntityID(2); + // TODO someday, use enumerations; is there a unique site triplet for MOVES Institute? + EntityType entityType_1 = new EntityType(); + entityType_1.setCountry(Country.UNITED_STATES_OF_AMERICA_USA); // 225 = USA + entityType_1.setEntityKind(EntityKind.PLATFORM); + entityType_1.setCategory(6); //Small wheeled utility vehicle + entityType_1.setSubCategory(30); // JLTV + entityType_1.setSpecific(37); // Up armored with M240 + EntityStatePdu entityStatePdu_1 = pduFactory.makeEntityStatePdu(); + Vector3Float pEntityLinearVelocity = new Vector3Float(); + pEntityLinearVelocity.setX(1); + pEntityLinearVelocity.setY(0); + pEntityLinearVelocity.setZ(0); + entityStatePdu_1.setEntityLinearVelocity(pEntityLinearVelocity); + entityStatePdu_1.setEntityID(entityID_1); + entityStatePdu_1.getEntityLocation().setX(0).setY(0).setZ(0); + entityStatePdu_1.setForceId(ForceID.FRIENDLY); + entityStatePdu_1.setEntityType(entityType_1); + + EntityType entityType_2 = new EntityType(); + entityType_2.setCountry(Country.AFGHANISTAN_AFG); + entityType_2.setEntityKind(EntityKind.LIFE_FORM); + entityType_2.setCategory(1); // civilian male with cellphone + entityType_2.setSubCategory(171); // personal electronic + entityType_2.setSubCategory(1); // cell phone + + EntityStatePdu entityStatePdu_2 = pduFactory.makeEntityStatePdu(); + entityStatePdu_2.setEntityID(entityID_2); + entityStatePdu_2.getEntityLocation().setX(10).setY(0).setZ(100); + entityStatePdu_2.setForceId(ForceID.OPPOSING); + entityStatePdu_2.setEntityType(entityType_2); + + + FirePdu firePdu_1a = pduFactory.makeFirePdu(); // for entity 1 first weapon (if any) + // should we customize this munition? what is it for your simulation? + EntityType fireType = new EntityType(); + MunitionDescriptor fireDescriptor = new MunitionDescriptor(); + fireType.setCountry(Country.UNITED_STATES_OF_AMERICA_USA); + fireType.setEntityKind(EntityKind.PLATFORM); + fireType.setCategory(11); //US Army + fireType.setSubCategory(35); //Machine gun + fireType.setSpecific(59); //M240 + firePdu_1a.setFiringEntityID(entityID_1); + firePdu_1a.setTargetEntityID(entityID_2); + firePdu_1a.setRange(1000.0f); // range 1000m + fireDescriptor.setMunitionType(fireType); + fireDescriptor.setRate(200); //rate 200 rounds per minute + Vector3Float pVelocity = new Vector3Float(); + pVelocity.setX(0.0f); + pVelocity.setY(0.0f); + pVelocity.setZ(100.0f); + firePdu_1a.setVelocity(pVelocity); + firePdu_1a.setDescriptor(fireDescriptor); + + // TODO simulation management PDUs for startup, planning to design special class support + MunitionDescriptor pDescriotor = new MunitionDescriptor(); + pDescriotor.setWarhead(MunitionDescriptorWarhead.HE_FRAGMENTATION); //High explosive frag + pDescriotor.setQuantity(2); + pDescriotor.setFuse(MunitionDescriptorFuse.COMMAND_ELECTRONIC_REMOTELY_SET); //command detonated + DetonationPdu detonationPdu = pduFactory.makeDetonationPdu(); + detonationPdu.setDescriptor(pDescriotor); + detonationPdu.getLocationInWorldCoordinates().setX(10).setY(0).setZ(0); + detonationPdu.setExplodingEntityID(entityID_1).setSourceEntityID(entityID_2).setTargetEntityID(entityID_1); + detonationPdu.setDetonationResult(DetonationResult.ENTITY_PROXIMATE_DETONATION); + + + + // loop the simulation while allowed, programmer can set additional conditions to break out and finish + while (simulationLoopCount < SIMULATION_MAX_LOOP_COUNT) // are we done yet? + { + simulationLoopCount++; // good practice: increment loop counter as first action in that loop + + // ============================================================================================= + // * your own simulation code starts here! * + // ============================================================================================= + + // are there any other variables to modify at the beginning of your loop? + + // compute a track, update an ESPDU, whatever it is that your model is doing... + + // Where is my entity? Insert changes in position; this sample only changes X position. + entityStatePdu_1.getEntityLocation().setX(entityStatePdu_1.getEntityLocation().getX() + 1.0); // 1m per timestep + + // decide whether to fire, and then update the firePdu. Hmmm, you might want a target to shoort at! + + // etc. etc. your code goes here for your simulation of interest + + // something happens between my simulation entities, la de da de da... + System.out.println ("Entity 1 is moving a 1m per timestep in the x direction"); + + + // make your reports: narrative code for CommentPdu here (set all to empty strings to avoid sending) + narrativeMessage1 = "Entity 1 (friendly) on the move on route 1"; + //narrativeMessage2 = "runSimulation() loop " + simulationLoopCount; + //narrativeMessage3 = "this is working!"; // intentionally blank for testing + + // your loop termination condition goes here + if (simulationLoopCount > 11) // for example + { + simulationComplete = true; + } + // ============================================================================================= + // * your own simulation code is finished here! * + // ============================================================================================= + + // 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((long)(SIMULATION_LOOP_DURATION_SECONDS * 1000)); // seconds * (1000 msec/sec) = milliseconds + System.out.println ("... [Pausing for " + SIMULATION_LOOP_DURATION_SECONDS + " seconds]"); + + // 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"); + //sendAllPdusForLoopTimestep(entityStatePdu_1, timeStepComment, narrativeMessage1); + sendSinglePdu(entityStatePdu_1); // me too i.e. 2! + System.out.println ("... [PDUs successfully sent for this loop]"); + + int contactCounter = 0; + if (entityStatePdu_1.getEntityLocation().getX() == 10) + { + sendSinglePdu(detonationPdu); + sendCommentPdu(otherComment, "IED detonated near Entity 1"); + while (contactCounter < 4) + { + contactCounter++; + sendSinglePdu(entityStatePdu_2); + sendSinglePdu(firePdu_1a); + sendCommentPdu(otherComment, "Entity 2 is hit"); + } + } + + // =============================== + // loop now finished, check whether to terminate if simulation complete, otherwise continue + if (simulationComplete || (simulationLoopCount > 10000)) // for example; including fail-safe condition is good + { + //sendSinglePdu(detonationPdu); + System.out.println ("... [Termination condition met, simulationComplete=" + simulationComplete + "]"); // ", final loopCount=" + loopCount + + break; + } + } // end of simulation loop + + narrativeMessage2 = "runSimulation() completed successfully"; // all done + sendCommentPdu(otherComment, "Entity has been neutralized. Simulation over."); + //sendCommentPdu(narrativeComment, narrativeMessage1, narrativeMessage2, narrativeMessage3); + System.out.println ("... [final CommentPdu successfully sent for simulation]"); + // TODO simulation management PDUs + } + catch (InterruptedException iex) // handle any exception that your code might choose to provoke! + { + Logger.getLogger(MV3500ProjectFisher.class.getName()).log(Level.SEVERE, null, iex); + } + } + /* **************************** infrastructure code, modification is seldom needed ************************* */ + + String narrativeMessage1 = new String(); + String narrativeMessage2 = new String(); + String narrativeMessage3 = new String(); + + /* VariableRecordType enumerations have potential use with CommentPdu logs */ + /* TODO contrast to EntityType */ + VariableRecordType descriptionComment = VariableRecordType.DESCRIPTION; + VariableRecordType narrativeComment = VariableRecordType.COMPLETE_EVENT_REPORT; + VariableRecordType statusComment = VariableRecordType.APPLICATION_STATUS; + VariableRecordType timeStepComment = VariableRecordType.APPLICATION_TIMESTEP; + VariableRecordType otherComment = VariableRecordType.OTHER; + + /** + * Output prefix to identify this class, helps with logging + */ + private final static String TRACE_PREFIX = "[" + MV3500ProjectFisher.class.getName() + "] "; + + // class variables + PduFactory pduFactory = new PduFactory(); + DisThreadedNetworkInterface disNetworkInterface; + DisThreadedNetworkInterface.PduListener pduListener; + Pdu receivedPdu; + PduRecorder pduRecorder; + + /** + * Constructor design goal: additional built-in initialization conveniences can go here + * to keep student efforts focused on the runSimulation() method. + */ + public MV3500ProjectFisher() + { + // Constructor is under consideration. Constructor is not currently needed. + } + + /** + * Utility Constructor that allows your example simulation program to override default network address and port + * @param address network address to use + * @param port corresponding network port to use + */ + public MV3500ProjectFisher(String address, int port) + { + setNetworkAddress(address); + + setNetworkPort(port); + } + + /** + * @return the networkAddress + */ + public String getNetworkAddress() + { + return networkAddress; + } + + /** + * @param newNetworkAddress the networkAddress to set + */ + public final void setNetworkAddress(String newNetworkAddress) + { + MV3500ProjectFisher.networkAddress = newNetworkAddress; + } + + /** + * @return the networkPort + */ + public int getNetworkPort() + { + return networkPort; + } + + /** + * @param newNetworkPort the networkPort to set + */ + public final void setNetworkPort(int newNetworkPort) + { + MV3500ProjectFisher.networkPort = newNetworkPort; + } + + /** + * Initialize network interface, choosing best available network interface + */ + public void setUpNetworkInterface() + { + disNetworkInterface = new DisThreadedNetworkInterface(getNetworkAddress(), getNetworkPort()); + disNetworkInterface.setDescriptor ("MV3500ProjectFisher pdu looping"); + + System.out.println("Network confirmation:" + + " address=" + disNetworkInterface.getAddress()+ // disNetworkInterface.getMulticastGroup() + + " port=" + disNetworkInterface.getPort()); // + disNetworkInterface.getDisPort()); + pduListener = (Pdu newPdu) -> { + receivedPdu = newPdu; + } /** Callback handler for listener */ ; + disNetworkInterface.addListener(pduListener); + + String outputDirectory = DEFAULT_OUTPUT_DIRECTORY; + System.out.println("Beginning pdu save to directory " + outputDirectory); + pduRecorder = new PduRecorder(outputDirectory, getNetworkAddress(), getNetworkPort()); // assumes save + pduRecorder.setDescriptor ("MV3500ProjectFisher pduRecorder"); + pduRecorder.start(); // begin running + } + + /** All done, release network resources */ + public void tearDownNetworkInterface() + { + pduRecorder.stop(); + + disNetworkInterface.removeListener(pduListener); + + disNetworkInterface.close(); +// disNetworkInterface.kill(); // renamed as close(), deprecated +// disNetworkInterface = null; // making sure no possibility of zombie process remaining... + } + + /** + * Send a single Protocol Data Unit (PDU) of any type + * @param pdu the pdu to send + */ + private void sendSinglePdu(Pdu pdu) + { + try + { + disNetworkInterface.send(pdu); + Thread.sleep(100); // TODO consider refactoring the wait logic and moving externally + } + catch (InterruptedException ex) + { + System.err.println(this.getClass().getName() + " Error sending PDU: " + ex.getLocalizedMessage()); + System.exit(1); + } + } + + /** + * Send Comment PDU + * @see <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html">Passing Information to a Method or a Constructor</a> Arbitrary Number of Arguments + * @param commentType enumeration value describing purpose of the narrative comment + * @param comments String array of narrative comments + */ + public void sendCommentPdu(VariableRecordType commentType, + // vararg... variable-length set of String comments can optionally follow + String... comments) + { + sendAllPdusForLoopTimestep (null, commentType, comments); + } + + /** + * Send EntityState, Fire, Comment PDUs that got updated for this loop, reflecting state of current simulation timestep. + * @see <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html">Passing Information to a Method or a Constructor</a> Arbitrary Number of Arguments + * @param entityStatePdu the ESPDU to send, if any + * @param commentType enumeration value describing purpose of the narrative comment + * @param comments String array of narrative comments + */ + public void sendAllPdusForLoopTimestep(EntityStatePdu entityStatePdu, VariableRecordType commentType, + // vararg... variable-length set of String comments can optionally follow + String... comments) + { + if (entityStatePdu != null) + sendSinglePdu(entityStatePdu); + + //if (firePdu != null) + // sendSinglePdu(firePdu); // bang + + if ((comments != null) && (comments.length > 0)) + { + ArrayList<String> newCommentsList = new ArrayList<>(); + for (String comment : comments) + { + if (!comment.isEmpty()) + { + newCommentsList.add(comment); // OK found something to send + } + } + if (!newCommentsList.isEmpty()) + { + if (commentType == null) + commentType = otherComment; // fallback value otherComment + // now build the commentPdu from these string inputs, thus constructing a narrative entry + CommentPdu commentPdu = pduFactory.makeCommentPdu(commentType, newCommentsList.toArray(new String[0])); // comments); + sendSinglePdu(commentPdu); + if (isVerboseComments()) + System.out.println("*** [Narrative comment sent: " + commentType.name() + "] " + newCommentsList.toString()); + } + } + } + + /** + * Main method is first executed when a program instance is loaded. + * @see <a href="https://docs.oracle.com/javase/tutorial/getStarted/application/index.html">Java Tutorials: A Closer Look at the "Hello World!" Application</a> + * @param args command-line arguments are an array of optional String parameters that are passed from execution environment during invocation + */ + public static void main(String[] args) + { + System.out.println(TRACE_PREFIX + "started..."); + + MV3500ProjectFisher thisProgram = new MV3500ProjectFisher(); // creates instance + + // initial execution: can handle args array of initialization arguments here + if (args.length == 2) + { + if ((args[0] != null) && !args[0].isEmpty()) + thisProgram.setNetworkAddress(args[0]); + + if ((args[1] != null) && !args[1].isEmpty()) + thisProgram.setNetworkPort(Integer.parseInt(args[1])); + } + else if (args.length != 0) + { + System.err.println("Usage: " + thisProgram.getClass().getName() + " [address port]"); + System.exit(-1); + } + // OK here we go... + + thisProgram.setUpNetworkInterface(); + + thisProgram.runSimulationLoops (); // ... your simulation execution code goes in there ... + + thisProgram.tearDownNetworkInterface(); // make sure no processes are left lingering + + System.out.println(TRACE_PREFIX + "complete."); // report successful completion + } + + /** + * @return whether verboseComments mode is enabled + */ + public boolean isVerboseComments() { + return verboseComments; + } + + /** + * @param newVerboseComments whether verboseComments mode is enabled + */ + public void setVerboseComments(boolean newVerboseComments) { + this.verboseComments = newVerboseComments; + } +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/projects/Fisher/README b/assignments/src/MV3500Cohort2021JulySeptember/projects/Fisher/README new file mode 100644 index 0000000000000000000000000000000000000000..fb73844fe4364e1d9683fc82736fa61da66c53f2 --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/projects/Fisher/README @@ -0,0 +1,9 @@ +The program I have designed is branching off of Homework 3 to expand the scenario a bit and add some more +PDUs to be utilized. + +My scenario starts with a US vehicle (JLTV) starting at (0,0,0) and moving on a straight line route to (10,0,0). +While on the route, the unit is struck by a command detonated IED by a civilain male with a cell phone at +coordinates (10,0,100). Upon being struck, the friendly unit fires at the enemy with an M240 machine gun with a +range of 1100m firing at the rapid rate (200 rounds per minute). + +After a few seconds of firing, the threat has been neutralized and the simulation ends. diff --git a/assignments/src/MV3500Cohort2021JulySeptember/projects/Lentz/.gitkeep b/assignments/src/MV3500Cohort2021JulySeptember/projects/Lentz/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/assignments/src/MV3500Cohort2021JulySeptember/projects/Lentz/README.md b/assignments/src/MV3500Cohort2021JulySeptember/projects/Lentz/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d71401cfbccbd29be1f025ff60d7d662598b661b --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/projects/Lentz/README.md @@ -0,0 +1,78 @@ +## Final Course Project + + In this project, we use several techniques and concepts to simulate software-defined transmitter/receiver systems through an aviation rf receiver use case. This version of the project plays a passive role. The SDR component is an RF receiver node to collect and transform broadcast messages into DIS messages to produce a 'home aviation spotter' awareness system. + +The system is composed of a few parts: +A software-defined radio setup [1] with a compiled FPGA image and PDU transmitter source code [2] to receive ADS-B data [3]. +A conversion model for transforming message traffic in the DIS PDU Entity State messages. +A watch system to visualize DIS broadcasts and alerts when variables are within tolerance for conditions of interest. + +This project's overview and [technical walkthrough videos are available here](https://youtu.be/e7BWm0TBmFk?t=4) [4]. + + +<figure class="video_container"> + <iframe src="https://youtu.be/e7BWm0TBmFk?t=4" frameborder="0" allowfullscreen="true"> </iframe> +</figure> + + + +The captured [ADSB Entity State PDU data is available here](https://drive.google.com/file/d/1KCuFVBYzKMHhdhrRL40G5zzu1c6ivymz/view?usp=sharing) . The presentation slides are in mv3500_Project_Lentz.pdf and the technical details from the technical walkthrough video follow. + + +### install gnu radio using conda +'conda config --env --add channels conda-forge' +'conda config --env --set channel_priority strict' +'conda create --name rf_pdu python=3.8' +'conda activate rf_pdu' +'conda install --yes gnuradio=3.8.1' +### when not needed +conda env remove --name rf_pdu + +### install opendis +'git clone https://github.com/open-dis/open-dis-python.git' +'cd open-dis-python' +'pip install .' + + +### pull the Ettus Research repo and configure the Linux rules using the following steps +'git clone https://github.com/EttusResearch/uhd.git' +'cd uhd/host/utils' +'sudo cp uhd-usrp.rules /etc/udev/rules.d/.' +'sudo udevadm control --reload-rules' +'sudo udevadm trigger' + + +### clone, build, and run +'git clone https://github.com/ricklentz/gr-adsb' +'mkdir build' +'cmake -DCMAKE_INSTALL_PREFIX=~/anaconda3/envs/rf_pdu ../' +'make' +'sudo make install' +'cd ..' +'cd examples' + + +### ensure the UHD device is connected to the source node +'sudo uhd_find_devices' + +### make sure the device fpga images are available e.g. +'python ~/anaconda3/envs/rf_pdu/lib/uhd/utils/uhd_images_downloader.py' + + + +### build the adsb_rx.grc graph using grcc +'cd ~/Github/gr-adsb/examples/' +'grcc adsb_rx.py' + +### and run the compiled flowgraph or +'python adsb_rx.py' + +### build and run with the gnuradio-companion +'gnuradio-companion adsb_rx.grc' + +### References +[1 Ettus Research SDR FPGAs](https://www.ettus.com/all-products/ub210-kit/) +[2 Project Source Code](https://github.com/ricklentz/gr-adsb) +[3 ADSB Nextgen Program](https://www.faa.gov/nextgen/programs/adsb/) +[4 Project Overview and Technical Walkthrough](https://youtu.be/e7BWm0TBmFk?t=4). + diff --git a/assignments/src/MV3500Cohort2021JulySeptember/projects/Lentz/mv3500_Project_Lentz.pdf b/assignments/src/MV3500Cohort2021JulySeptember/projects/Lentz/mv3500_Project_Lentz.pdf new file mode 100644 index 0000000000000000000000000000000000000000..ceee623b505602c20dd0a9132725fa2ee8c01d91 Binary files /dev/null and b/assignments/src/MV3500Cohort2021JulySeptember/projects/Lentz/mv3500_Project_Lentz.pdf differ diff --git a/assignments/src/MV3500Cohort2021JulySeptember/projects/McneelyLeckieProject/McneelyLeckieReceiver.java b/assignments/src/MV3500Cohort2021JulySeptember/projects/McneelyLeckieProject/McneelyLeckieReceiver.java new file mode 100644 index 0000000000000000000000000000000000000000..02b4a19ac705628714942b287e526375bf83217a --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/projects/McneelyLeckieProject/McneelyLeckieReceiver.java @@ -0,0 +1,153 @@ + + +package MV3500Cohort2021JulySeptember.projects.McneelyLeckieProject; + +import edu.nps.moves.dis.CommentPdu; +import edu.nps.moves.dis.OneByteChunk; +import edu.nps.moves.dis.Pdu; +import edu.nps.moves.dis.VariableDatum; +import edu.nps.moves.disenum.PduType; +import edu.nps.moves.disutil.PduFactory; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.InetAddress; +import java.net.MulticastSocket; +import java.util.ArrayList; + +/** + * + * @author Justin Mcneely + * @author Jacob Leckie + */ + + +public class McneelyLeckieReceiver { + + /** socket parameter of interest */ + public static final int MULTICAST_PORT = 3000; + /** socket parameter of interest */ + public static final String MULTICAST_GROUP = "239.1.2.15"; +// public static final String MULTICAST_GROUP = "192.168.1.247"; + /** socket parameter of interest */ + static final boolean USE_FAST_ESPDU = false; + + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ + @SuppressWarnings("deprecation") + public static void main(String[] args) + { + + PduFactory factory; + try + { + + // This is a java/IPv6 problem. You should also add it to the + // arguments used to start the app, eg -Djava.net.preferIPv4Stack=true + // set in the "run" section of preferences. Also, typically + // netbeans must be restarted after these settings. + // https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache + //System.setProperty("java.net.preferIPv4Stack", "true"); + //System.out.println("DisExamples.PduReceiver started..."); + + /*MulticastSocket multicastSocket = new MulticastSocket(DESTINATION_PORT); + multicastSocket.setTimeToLive(TTL); + InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + System.out.println(multicastAddress); + // Join group useful on receiving side + multicastSocket.joinGroup(multicastAddress); + // You can join multiple groups here*/ + System.setProperty("java.net.preferIPv4Stack", "true"); + System.out.println("DisExamples.PduReceiver started... ORDER RECIEVED!"); + + MulticastSocket socket = new MulticastSocket (MULTICAST_PORT); + InetAddress address = InetAddress.getByName(MULTICAST_GROUP); + socket.joinGroup(address); + + factory = new PduFactory(); + + int count = 0; + int partsAvail = 6; + int partsSent = 0; + + while(true) + { + + byte[] packetArray = new byte[1500]; + DatagramPacket packet = new DatagramPacket(packetArray, packetArray.length); + + socket.receive(packet); + + Pdu pdu = factory.createPdu (packet.getData()); + if (pdu != null) + { + short pduType = pdu.getPduType(); + String pduTypeName = pdu.getClass().getName(); + short protocolFamily = pdu.getProtocolFamily(); // TODO get string enumeration + + if(pdu.getPduTypeEnum() == PduType.COMMENT){ + CommentPdu cPdu = (CommentPdu)pdu; + @SuppressWarnings("unchecked") + ArrayList<VariableDatum> payload = (ArrayList)cPdu.getVariableDatums(); + VariableDatum payloadWrapper = payload.get(0); + @SuppressWarnings("unchecked") + ArrayList<OneByteChunk> oBC = (ArrayList)payloadWrapper.getVariableData(); + + //byte[] imageByte = new byte[100000]; + + /*for(int i = 0; i < oBC.size(); i++){ + imageByte[i] = oBC.get(i).getOtherParameters()[0]; + } + + ByteArrayInputStream bais = new ByteArrayInputStream(imageByte); + BufferedImage bimage = ImageIO.read(bais); + //image = bimage; + JFrame frame = new JFrame(); + frame.setSize(300, 300); + //JLabel label = new JLabel(new ImageIcon(image)); + //frame.add(label); + frame.setVisible(true); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);*/ + } + count++; + + if(count >= 1){ + partsAvail-=1; + partsSent+=1; + } + System.out.println("Marine Aircraft Logistics Squadron 29: Wolverines!"); + System.out.println("Status Update: " + count + " NSN ID: 1874542689"); + + StringBuilder message = new StringBuilder(); + message.append("received DIS PDU: "); + + message.append("pduType "); + if (pduType <= 1500) { + message.append(" "); + message.append(pduType).append(" ").append(pduTypeName); + message.append(", protocolFamily=").append(protocolFamily); + System.out.println(message.toString()); + } + + } + else System.out.println("received packet but pdu is null, packet.getData().length=" + packet.getData().length + ", error..."); + System.out.println("______________________________________________________"); + + ByteArrayInputStream bais = new ByteArrayInputStream(packet.getData()); +// DataInputStream dis = new DataInputStream(bais); + //float firstNumber = dis.readInt(); + //float secondNumber = dis.readInt(); + //float thirdNumber = dis.readInt(); + + + } + } + catch(IOException e) + { + System.out.println(e); + } + } + +} diff --git a/assignments/src/MV3500Cohort2021JulySeptember/projects/McneelyLeckieProject/McneelyLeckieSender.java b/assignments/src/MV3500Cohort2021JulySeptember/projects/McneelyLeckieProject/McneelyLeckieSender.java new file mode 100644 index 0000000000000000000000000000000000000000..366991a8232159603e1b2a2b5ddfd331e7af35ae --- /dev/null +++ b/assignments/src/MV3500Cohort2021JulySeptember/projects/McneelyLeckieProject/McneelyLeckieSender.java @@ -0,0 +1,200 @@ + +package MV3500Cohort2021JulySeptember.projects.McneelyLeckieProject; + +import edu.nps.moves.dis.CommentPdu; +import edu.nps.moves.dis.EntityStatePdu; +import edu.nps.moves.dis.OneByteChunk; +import edu.nps.moves.dis.Pdu; +import edu.nps.moves.dis.ResupplyOfferPdu; +import edu.nps.moves.dis.ResupplyReceivedPdu; +import edu.nps.moves.dis.ServiceRequestPdu; +import edu.nps.moves.dis.VariableDatum; +import edu.nps.moves.disenum.PduType; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.InetAddress; +import java.net.MulticastSocket; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.List; + + +/** + * + * @author Justin Mcneely + * @author Jacob Leckie + */ + + +public class McneelyLeckieSender { + + /** Default multicast group address we send on. */ + public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.15"; + /** socket parameter of interest */ + public static final int DESTINATION_PORT = 1717; + /** Default multicast port used, matches Wire-shark DIS capture default */ + public static final int DEFAULT_MULTICAST_PORT = 3000; + + + private int port; + InetAddress multicastAddress; + + /** Object constructor + * @param port TCP port of interest + * @param multicast address of interest */ + public McneelyLeckieSender (int port, String multicast) + { + try + { + System.setProperty("java.net.preferIPv4Stack", "true"); + this.port = port; + multicastAddress = InetAddress.getByName(multicast); + //MulticastSocket multicastSocket = new MulticastSocket(1718); + //multicastSocket.setTimeToLive(TTL); + InetAddress multicastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + System.out.println(multicastAddress); + // Join group useful on receiving side + //multicastSocket.joinGroup(multicastAddress); + // You can join multiple groups here + if (!multicastAddress.isMulticastAddress()) + { + System.out.println("Not a multicast address: " + multicast); + } + } + catch (UnknownHostException e) { + System.out.println("Unable to open socket: " + e); + } + } + + /** + * Run the program + */ + @SuppressWarnings("deprecation") + public void run() + { + System.out.println("DisExamples.PduSender started..."); + try { + + List<Pdu> generatedPdus = new ArrayList<>(); + MulticastSocket multicastSocket = new MulticastSocket(1718); + //multicastSocket.setTimeToLive(TTL); + //InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS); + System.out.println(multicastAddress); + // Join group useful on receiving side + multicastSocket.joinGroup(multicastAddress); + // You can join multiple groups here + + // Loop through all the enumerated PDU types, create a PDU for each type, + // and add that PDU to a list. + for (PduType pdu : PduType.values()) { + Pdu aPdu = null; + + switch (pdu) // using enumeration values from edu.nps.moves.disenum.* + { + case ENTITY_STATE: + aPdu = new EntityStatePdu(); + break; + + case COMMENT: + aPdu = new CommentPdu(); + CommentPdu cPdu = (CommentPdu)aPdu; + + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + byte[] buffer; + buffer = baos.toByteArray(); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, multicastAddress, DESTINATION_PORT); +// System.out.println("Sending Request"); + for(int idx = 0; idx <= 6; idx++) + { + multicastSocket.send(packet); +// Thread.sleep(2000); // Send 100, one per second + System.out.println("Sending Request"); + System.out.println("Sent multicast DIS PDU packet " + idx + " of 6"); + } + ArrayList<VariableDatum> payload = new ArrayList<>(); + ArrayList<OneByteChunk> payloadWrapper = new ArrayList<>(); + VariableDatum variableDatum = new VariableDatum(); + + + + variableDatum.setVariableData(payloadWrapper); + + payload.add(variableDatum); + cPdu.setVariableDatums(payload); + break; + + case SERVICE_REQUEST: + aPdu = new ServiceRequestPdu(); + break; + + case RESUPPLY_OFFER: + aPdu = new ResupplyOfferPdu(); + break; + + case RESUPPLY_RECEIVED: + aPdu = new ResupplyReceivedPdu(); + break; + + default: +// System.out.print("PDU of type " + pdu + " not supported, created or sent "); +// System.out.println(); + } + if (aPdu != null) + { + generatedPdus.add(aPdu); + } + } + + // Sort the created PDUs by class name +// Collections.sort(generatedPdus, new ClassNameComparator()); + + + // Send the PDUs we created + InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); + MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); + socket.joinGroup(localMulticastAddress); + + for (int idx = 0; idx < generatedPdus.size(); idx++) + { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + byte[] buffer; + + Pdu aPdu = generatedPdus.get(idx); + + aPdu.marshal(dos); + + buffer = baos.toByteArray(); + DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); + socket.send(packet); + System.out.println("Sent PDU of type " + aPdu.getClass().getName()); + } + + } catch (IOException e) + { + System.out.println(e); + } + } + + /** + * Program invocation, execution starts here + * @param args command-line arguments + */ + public static void main(String args[]) + { + if (args.length == 2) { + McneelyLeckieSender sender = new McneelyLeckieSender(Integer.parseInt(args[0]), args[1]); + sender.run(); + } else { + System.out.println("Usage: PduSender <port> <multicast group>"); + System.out.println("Default: PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); + McneelyLeckieSender sender = new McneelyLeckieSender(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); + sender.run(); + } + } + +}