diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageReceiver.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageReceiver.java index 80c12c8e7787b46cfe78e8f129cbb22d9d05748a..38005da451a4fe0a6cb6593400bdb68f915d9832 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageReceiver.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageReceiver.java @@ -5,6 +5,7 @@ */ package MV3500Cohort2018JulySeptember.FinalProject.LoeffelmanSeverson; + import edu.nps.moves.dis.CommentPdu; import edu.nps.moves.dis.EntityID; import edu.nps.moves.dis.EntityStatePdu; @@ -59,6 +60,7 @@ public class LoeffelmanSeversonDISImageReceiver { while (true) // Loop infinitely, receiving datagrams { + //buffer needs to be resized to be able to accept image sizes byte buffer[] = new byte[100000]; // typical MTU size packet = new DatagramPacket(buffer, buffer.length); // reset @@ -72,7 +74,11 @@ public class LoeffelmanSeversonDISImageReceiver { String pduTypeName = pdu.getClass().getName(); short protocolFamily = pdu.getProtocolFamily(); // TODO get string enumeration + //If we receive a comment PDU, we are going to look for a picture specifically if(pdu.getPduTypeEnum() == PduType.COMMENT){ + //Set up data structures, get the list of variableDatums, and + //get the first and only VariableDatum, and the arrayList + //of OneByteChunks from the variableDatum CommentPdu cPdu = (CommentPdu)pdu; ArrayList<VariableDatum> payload = (ArrayList)cPdu.getVariableDatums(); VariableDatum payloadWrapper = payload.get(0); @@ -80,13 +86,19 @@ public class LoeffelmanSeversonDISImageReceiver { byte[] imageByte = new byte[100000]; + //Loop through the arrayList of OneByteChunks and + //populate the byte array representation of the image for(int i = 0; i < oBC.size(); i++){ imageByte[i] = oBC.get(i).getOtherParameters()[0]; } + //Convert that byte array into an input stream and into + //an image using a buffered image reader. ByteArrayInputStream bais = new ByteArrayInputStream(imageByte); BufferedImage bimage = ImageIO.read(bais); image = bimage; + + //Display the image using java swing utilities JFrame frame = new JFrame(); frame.setSize(300, 300); JLabel label = new JLabel(new ImageIcon(image)); diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageSender.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageSender.java index ac4fbc8a02aa194ad9ee3600c726556612223ef1..a6b0f0d438d644d99cd5c65f9688dc2ec7a384fc 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageSender.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/LoeffelmanSeversonDISImageSender.java @@ -108,17 +108,24 @@ public class LoeffelmanSeversonDISImageSender { break; case COMMENT: + //Initialize PDU and image aPdu = new CommentPdu(); CommentPdu cPdu = (CommentPdu)aPdu; BufferedImage image = ImageIO.read(url1); + //Convert image to a byte array ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(image, "png", baos); byte[] buffer; buffer = baos.toByteArray(); + + //Instaniate data structures for holding bytes ArrayList<VariableDatum> payload = new ArrayList<VariableDatum>(); ArrayList<OneByteChunk> payloadWrapper = new ArrayList<OneByteChunk>(); VariableDatum variableDatum = new VariableDatum(); + + //Loop through, create OneByteChunk arrays of size 1 + //and place them in ArrayList of OneByteChunks for(int i = 0; i < buffer.length; i++){ OneByteChunk oBC = new OneByteChunk(); byte[] oneBite = new byte[1]; @@ -127,10 +134,13 @@ public class LoeffelmanSeversonDISImageSender { payloadWrapper.add(oBC); } System.out.println("Sending Picture"); - + + //Add the arrayList of OneByteChunks to the variable datum variableDatum.setVariableData(payloadWrapper); + //Add the variableDatum to the arraylist payload.add(variableDatum); + //Set the variableDatum for the PDU to be sent cPdu.setVariableDatums(payload); break; diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/Networks_Presentation.pptx b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/Networks_Presentation.pptx new file mode 100644 index 0000000000000000000000000000000000000000..36d9faa83e1b54412a11d65882e48720eacfb537 Binary files /dev/null and b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/Networks_Presentation.pptx differ diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/ReadMe.txt b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/ReadMe.txt new file mode 100644 index 0000000000000000000000000000000000000000..480cc9e102cd8d550610f05e2577b2aea89f03f5 --- /dev/null +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/LoeffelmanSeverson/ReadMe.txt @@ -0,0 +1,8 @@ +To run this program run the receiver first, and then run the sender. + +The Sender will send a picture specified by the URL at the top of the try block + +You can change the url to a different image, but keep in mind the image must be smaller then + +100,000 bytes or 100 kb. + diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/FDC Output Log.PNG b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/FDC Output Log.PNG new file mode 100644 index 0000000000000000000000000000000000000000..84a9ab4ed239028340ab06b38c407b0290041a45 Binary files /dev/null and b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/FDC Output Log.PNG differ diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/FDCSendRecieve.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/FDCSendRecieve.java index 0e9bcfc12f7e11c1d9a480e51882962093500872..8c46886b7667ecdff96b2a2249edec92917b94ed 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/FDCSendRecieve.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/FDCSendRecieve.java @@ -43,6 +43,12 @@ public class FDCSendRecieve { } } + /** + * This would be the sending Run method. Takes in several PDUs and for each one has a switch statement ready for it. + * @param pdupass + * @throws UnknownHostException + * @throws IOException + */ public void run(Pdu... pdupass) throws UnknownHostException, IOException { List<Pdu> generatedPdus = new ArrayList<>(); @@ -111,6 +117,13 @@ public class FDCSendRecieve { } } + /** + * Main function takes no specific arguments, but is the recieving portion of the code. Once it hears a specific type of PDU it creates another and sends it to the Run function + * called sender created on line 130 (2nd statement in the main function) + * @param args + * @throws IOException + * @throws InterruptedException + */ public static void main(String[] args) throws IOException, InterruptedException { DisTime disTime = DisTime.getInstance(); @@ -122,9 +135,9 @@ public class FDCSendRecieve { FDCespdu.setMarking(marking); FDCespdu.setExerciseID((short) 1); EntityID FDCID = FDCespdu.getEntityID(); - FDCID.setSite(1); // 0 is apparently not a valid site number, per the spec + FDCID.setSite(1); FDCID.setApplication(1); - FDCID.setEntity(1); //change for each person I think??? - JMF + FDCID.setEntity(1); EntityType entityType = FDCespdu.getEntityType(); // //Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21 @@ -147,12 +160,12 @@ public class FDCSendRecieve { sender.run(FDCespdu); //sends inital here I am and who I am //Set up other players to look for: - EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below + EntityID OBSEntityID = new EntityID(); OBSEntityID.setEntity(2); OBSEntityID.setApplication(1); OBSEntityID.setSite(1); - EntityID TGTEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below + EntityID TGTEntityID = new EntityID(); TGTEntityID.setEntity(3); TGTEntityID.setApplication(1); TGTEntityID.setSite(1); @@ -232,13 +245,14 @@ public class FDCSendRecieve { } if (currentPduType == 16) //Action request { - // Action response is sending a Null PDU, not sure why... + // Action response is sending a Null PDU, not sure why... so we will use the acknowledge pdu instead AcknowledgePdu ack = new AcknowledgePdu(); ack.setExerciseID((short) 1); ack.setRequestID((long) 1); timestamp = disTime.getDisAbsoluteTimestamp(); ack.setTimestamp(timestamp); + //Creating a fire PDU FirePdu fire = new FirePdu(); fire.setExerciseID((short) 1); fire.setFireMissionIndex(1000); @@ -257,7 +271,8 @@ public class FDCSendRecieve { ack.setRequestID((long) 1); timestamp = disTime.getDisAbsoluteTimestamp(); ack.setTimestamp(timestamp); - + + //and the freeze PDU being created to stop everything. StopFreezePdu stop = new StopFreezePdu(); stop.setExerciseID((short) 1); stop.setRequestID((long) 1); @@ -270,10 +285,10 @@ public class FDCSendRecieve { } } } catch (IOException e) { - System.out.println("Problem with FDC.PduReceiver, see exception trace:"); + System.out.println("Problem with FDCSendRecieve, see exception trace:"); System.out.println(e); } finally { - System.out.println("FDC.PduReceiver complete. - OUT!"); + System.out.println("FDC SendReceive complete. - OUT!"); } } diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/FriscoFurrDISCallforFire.pptx b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/FriscoFurrDISCallforFire.pptx new file mode 100644 index 0000000000000000000000000000000000000000..b66d80e0541fcd6b8c180157f7eed91cb21c62b8 Binary files /dev/null and b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/FriscoFurrDISCallforFire.pptx differ diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/OBSSendRecieve1.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/OBSSendRecieve1.java index ca45cda575f52b27114b1f3b462ad0a4f76bf7e9..a4e43022327e295eafccd6c18aa8b3ad07bc4c56 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/OBSSendRecieve1.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/OBSSendRecieve1.java @@ -31,6 +31,11 @@ public class OBSSendRecieve1 { DisTime disTime = DisTime.getInstance(); int transmission =1; + /** + * Constructor just got to construct. + * @param port + * @param multicast + */ public OBSSendRecieve1(int port, String multicast) { this.sentBufferList = new ArrayList<>(); try { @@ -44,6 +49,12 @@ public class OBSSendRecieve1 { } } + /** + * This would be the sending Run method. Takes in several PDUs and for each one has a switch statement ready for it. + * @param pdupass + * @throws UnknownHostException + * @throws IOException + */ public void run(Pdu... pdupass) throws UnknownHostException, IOException { List<Pdu> generatedPdus = new ArrayList<>(); @@ -68,14 +79,7 @@ public class OBSSendRecieve1 { short currentPduType = pdu.getPduType(); System.out.println("in observer sender, processing PDU type: " + currentPduType); -// String currentPduTypeName = pdu.getClass().getName(); -// short currentProtocolFamilyID = pdu.getProtocolFamily(); -// String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); - - // Loop through all the enumerated PDU types, create a PDU for each type, - // and add that PDU to a list. - //System.out.println(pdu); - //Change the switch statement to the currentPduType from the recieve portion, then when a packet we want comes in, send the CASE file. + switch (currentPduType) // using enumeration values from edu.nps.moves.disenum.* { @@ -83,22 +87,6 @@ public class OBSSendRecieve1 { aPdu = pdu; break; -// case COMMENT: -// aPdu = new CommentPdu(); -// break; -// -// case 2: //FIRE -// aPdu = pdu; -// break; -// -// case DETONATION: -// aPdu = new DetonationPdu(); -// break; -// -// case 15: //AcknowledgePdu -// aPdu = pdu; -// break; -//// case 16: //ACTION_REQUEST: aPdu = new ActionRequestPdu(); break; @@ -107,11 +95,7 @@ public class OBSSendRecieve1 { aPdu = pdu; break; -// case 14: -// aPdu = pdu; -// break; default: - //add some shit that makes sense here. System.out.print("PDU of type " + pdu + " not supported by Observer, created or sent "); System.out.println(); } @@ -132,28 +116,19 @@ public class OBSSendRecieve1 { buffer = baos.toByteArray(); DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); socket.send(packet); - //sentBuffer[sentBuffer.length] = aPdu.getTimestamp(); sentBufferList.add(aPdu.getTimestamp()); - System.out.println("Observer Sent PDU of type " + aPdu.getClass().getName()+"/n"); + System.out.println("Observer Sent PDU of type " + aPdu.getClass().getName()+"\n"); } } + /** + * Main function takes no specific arguments, but is the recieving portion of the code. Once it hears a specific type of PDU it creates another and sends it to the Run function + * called sender created on line 136 (2nd statement in the main function) + * @param args + * @throws IOException + */ public static void main(String[] args) throws IOException { DisTime disTime = DisTime.getInstance(); - //turns on the sender code - might need to move around down into the recieve with the if statements... - // - // ORIGINAL SENDING CODE MAIN CLASS: - // - // -// if (args.length == 2) { -// FDCSendRecieve sender = new FDCSendRecieve(Integer.parseInt(args[0]), args[1]); -// // sender.run(); //needs to be sender.run(pdu) -// } else { -// System.out.println("Usage: PduSender <port> <multicast group>"); -// System.out.println("Default: PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); -// FDCSendRecieve sender = new FDCSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); - // sender.run(); -// } // // Inital Hello world from entity: @@ -168,7 +143,7 @@ public class OBSSendRecieve1 { EntityID OBSID = OBSespdu.getEntityID(); OBSID.setSite(1); // 0 is apparently not a valid site number, per the spec OBSID.setApplication(1); - OBSID.setEntity(2); //change for each person I think??? - JMF + OBSID.setEntity(2); EntityType entityType = OBSespdu.getEntityType(); // //Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21 @@ -187,7 +162,6 @@ public class OBSSendRecieve1 { OBSespdu.setEntityLocation(location); int timestamp = disTime.getDisAbsoluteTimestamp(); OBSespdu.setTimestamp(timestamp); - //FDCespdu.setTimestamp(System.currentTimeMillis()); sender.run(OBSespdu); //sends inital here I am and who I am //other player to look out for: @@ -212,7 +186,6 @@ public class OBSSendRecieve1 { short currentPduType; //will use the curentPduType as the check for sending other packets. try { - // TODO: Change the line below to make sense for each class System.out.println("Observer is in the OP and looking for targets...\n\n"); socket = new MulticastSocket(MULTICAST_PORT); address = InetAddress.getByName(MULTICAST_GROUP); @@ -227,9 +200,6 @@ public class OBSSendRecieve1 { packet = new DatagramPacket(buffer, buffer.length); // reset socket.receive(packet); - // - //TODO: NEED IF STATEMENT IF THE SENDER IS THIS CLASS TO DELETE. - // String marking2 = new String(); Pdu pdu = factory.createPdu(packet.getData()); @@ -239,7 +209,6 @@ public class OBSSendRecieve1 { System.out.println("recieved Stop/Freeze packet..."); return; } -// pdu.setExerciseID((short)5); if (pdu != null) { if (sentBufferList.contains(pdu.getTimestamp())) { pdu = null; @@ -251,7 +220,7 @@ public class OBSSendRecieve1 { EntityStatePdu pdu2 = (EntityStatePdu) pdu; marking2 = pdu2.getMarking().getCharactersString(); } -//Keep adding any if statements as needed for the class you are building. + StringBuilder message = new StringBuilder(); message.append("received DIS PDU: "); message.append("pduType "); diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/Observer Output Log.PNG b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/Observer Output Log.PNG new file mode 100644 index 0000000000000000000000000000000000000000..9153e2b46dcad89413c891c297544504c5e297cf Binary files /dev/null and b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/Observer Output Log.PNG differ diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/TGTSendRecieve.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/TGTSendRecieve.java index 2ea1d4de3e028a3fd0e61e8b4c2b3a73fb9d2274..55c41bfc2f06274727be0663258caaf725d76e0e 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/TGTSendRecieve.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/TGTSendRecieve.java @@ -31,6 +31,11 @@ public class TGTSendRecieve { DisTime disTime = DisTime.getInstance(); int transmission = 1; + /** + * Constructor just got to construct. + * @param port + * @param multicast + */ public TGTSendRecieve(int port, String multicast) { this.sentBufferList = new ArrayList<>(); try { @@ -44,6 +49,12 @@ public class TGTSendRecieve { } } + /** + * This would be the sending Run method. Takes in several PDUs and for each one has a switch statement ready for it. + * @param pdupass + * @throws UnknownHostException + * @throws IOException + */ public void run(Pdu... pdupass) throws UnknownHostException, IOException { List<Pdu> generatedPdus = new ArrayList<>(); @@ -104,10 +115,16 @@ public class TGTSendRecieve { socket.send(packet); //sentBuffer[sentBuffer.length] = aPdu.getTimestamp(); sentBufferList.add(aPdu.getTimestamp()); - System.out.println("Observer Sent PDU of type " + aPdu.getClass().getName() + "/n"); + System.out.println("Target Sent PDU of type " + aPdu.getClass().getName() + "\n"); } } + /** + * Main function takes no specific arguments, but is the recieving portion of the code. Once it hears a specific type of PDU it creates another and sends it to the Run function + * called sender created on line 135 (2nd statement in the main function) + * @param args + * @throws IOException + */ public static void main(String[] args) throws IOException { DisTime disTime = DisTime.getInstance(); //turns on the sender code - might need to move around down into the recieve with the if statements... @@ -125,7 +142,7 @@ public class TGTSendRecieve { EntityID OBSID = TGTespdu.getEntityID(); OBSID.setSite(1); // 0 is apparently not a valid site number, per the spec OBSID.setApplication(1); - OBSID.setEntity(3); //change for each person I think??? - JMF + OBSID.setEntity(3); EntityType entityType = TGTespdu.getEntityType(); // //Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21 @@ -168,7 +185,6 @@ public class TGTSendRecieve { short currentPduType; //will use the curentPduType as the check for sending other packets. try { - // TODO: Change the line below to make sense for each class System.out.println("Russian T72 out on the prowl...\n\n"); socket = new MulticastSocket(MULTICAST_PORT); address = InetAddress.getByName(MULTICAST_GROUP); @@ -183,10 +199,7 @@ public class TGTSendRecieve { packet = new DatagramPacket(buffer, buffer.length); // reset socket.receive(packet); - // - //TODO: NEED IF STATEMENT IF THE SENDER IS THIS CLASS TO DELETE. - // - + String marking2 = new String(); Pdu pdu = factory.createPdu(packet.getData()); currentPduType = pdu.getPduType(); @@ -195,7 +208,6 @@ public class TGTSendRecieve { System.out.println("recieved Stop/Freeze packet..."); return; } -// pdu.setExerciseID((short)5); if (pdu != null) { if (sentBufferList.contains(pdu.getTimestamp())) { pdu = null; @@ -207,7 +219,6 @@ public class TGTSendRecieve { EntityStatePdu pdu2 = (EntityStatePdu) pdu; marking2 = pdu2.getMarking().getCharactersString(); } -//Keep adding any if statements as needed for the class you are building. StringBuilder message = new StringBuilder(); message.append("received DIS PDU: "); message.append("pduType "); diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/Target Output Log.PNG b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/Target Output Log.PNG new file mode 100644 index 0000000000000000000000000000000000000000..b38460e95e96045c33b9c16422848e3e78c18c50 Binary files /dev/null and b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/FriscoFurrProject/Target Output Log.PNG differ diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/LoeffelmanSeverson/Networks_Presentation.pptx b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/LoeffelmanSeverson/Networks_Presentation.pptx new file mode 100644 index 0000000000000000000000000000000000000000..36d9faa83e1b54412a11d65882e48720eacfb537 Binary files /dev/null and b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProjects/LoeffelmanSeverson/Networks_Presentation.pptx differ