From 00d721f820be17f001abc44b4b042178f8c5e4de Mon Sep 17 00:00:00 2001 From: brutzman <brutzman@DESKTOP-2S09UKA> Date: Mon, 1 Jul 2019 08:12:10 -0700 Subject: [PATCH] move earlier duplicates to archive location --- .../FriscoFurrProject/FDCSendRecieve.java | 281 ---------------- .../FriscoFurrPduSender.java | 226 ------------- .../FriscoFurrProject/OBSSendRecieve1.java | 310 ------------------ .../FriscoFurrProject/TGTSendRecieve.java | 250 -------------- 4 files changed, 1067 deletions(-) delete mode 100644 deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FDCSendRecieve.java delete mode 100644 deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FriscoFurrPduSender.java delete mode 100644 deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/OBSSendRecieve1.java delete mode 100644 deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/TGTSendRecieve.java diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FDCSendRecieve.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FDCSendRecieve.java deleted file mode 100644 index 4dadb6ee76..0000000000 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FDCSendRecieve.java +++ /dev/null @@ -1,281 +0,0 @@ -package MV3500Cohort2018JulySeptember.FinalProject.FriscoFurrProject; - -import java.net.*; -import java.io.*; -import java.util.*; -import edu.nps.moves.dis.*; -import java.io.IOException; -import edu.nps.moves.disutil.PduFactory; -import edu.nps.moves.disutil.DisTime; - -public class FDCSendRecieve { - - /** - * Default multicast group address we send on. - */ - public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; - - /** - * Default multicast port used, matches Wireshark DIS capture default - */ - public static final int DEFAULT_MULTICAST_PORT = 3000; - - private int port; - InetAddress multicastAddress; - - public static final int MULTICAST_PORT = 3000; - public static final String MULTICAST_GROUP = "239.1.2.3"; - public static final boolean USE_FAST_ESPDU = false; - public long[] sentBuffer = new long[100]; - public static List sentBufferList; - DisTime disTime = DisTime.getInstance(); - - public FDCSendRecieve(int port, String multicast) { - this.sentBufferList = new ArrayList<>(); - try { - this.port = port; - multicastAddress = InetAddress.getByName(multicast); - if (!multicastAddress.isMulticastAddress()) { - System.out.println("Not a multicast address: " + multicast); - } - } catch (UnknownHostException e) { - System.out.println("Unable to open socket: " + e); - } - } - - public void run(Pdu... pdupass) throws UnknownHostException, IOException { - - List<Pdu> generatedPdus = new ArrayList<>(); - Pdu aPdu = null; - System.out.println("\nFDC Sender started..."); - // Send the PDUs we created - InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); - MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); - socket.joinGroup(localMulticastAddress); - - for (Pdu i : pdupass) { - Pdu pdu = i; - if (sentBufferList.contains(pdu.getTimestamp())) { - break; - } - - short currentPduType = pdu.getPduType(); - System.out.println("in sender, recived PDU type: " + currentPduType); - - switch (currentPduType) // using enumeration values from edu.nps.moves.disenum.* - { - - case 1: //ENTITY_STATE: - aPdu = pdu; - break; - - case 2: //FIRE - aPdu = pdu; - break; -// - case 15: //AcknowledgePdu - aPdu = pdu; - break; - - case 17: - aPdu = pdu; - break; - - case 14: - aPdu = pdu; - break; - - default: - System.out.print("PDU of type " + pdu + " not supported, created or sent "); - System.out.println(); - } - if (aPdu != null) { - generatedPdus.add(aPdu); - System.out.println("APDU container count " + generatedPdus.size()); - } - - } - for (int idx = 0; idx < generatedPdus.size(); idx++) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - byte[] buffer; - - aPdu = generatedPdus.get(idx); - aPdu.marshal(dos); - - buffer = baos.toByteArray(); - DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT); - socket.send(packet); - sentBufferList.add(aPdu.getTimestamp()); - System.out.println("Sent PDU of type " + aPdu.getClass().getName()+ "\n"); - } - } - - public static void main(String[] args) throws IOException, InterruptedException { - DisTime disTime = DisTime.getInstance(); - - FDCSendRecieve sender = new FDCSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender - - EntityStatePdu FDCespdu = new EntityStatePdu(); - Marking marking = new Marking(); - marking.setCharactersString("FDC"); - 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.setApplication(1); - FDCID.setEntity(1); //change for each person I think??? - JMF - EntityType entityType = FDCespdu.getEntityType(); - // - //Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21 - // https://www.sisostds.org/DesktopModules/Bring2mind/DMX/Download.aspx?Command=Core_Download&EntryId=42916&PortalId=0&TabId=105 - // - entityType.setEntityKind((short) 1); // Platform (vs lifeform, munition, sensor, etc.) TGT=1, OBS = 1 - entityType.setCountry(225); // USA TGT = 222 (Russia), OBS = 225 - entityType.setDomain((short) 1); // Land (vs air, surface, subsurface, space) both TGT and OBS are 1 - entityType.setCategory((short) 3); // FDC TGT = 1, Tank OBS=40 OP - entityType.setSubcategory((short) 12); // M1068 TGT = 2, T72 tank NONE FOR OP - entityType.setSpec((short) 1); // M1068 w/ SICUP Tent NONE FOR TGT OR OP - Vector3Double location = new Vector3Double(); - location.setX(0.0); //TGT = 150 OBS = 75 - location.setY(0.0); //TGT = 150 OBS = 75 - location.setZ(10.0); //TGT = 20 OBS = 50 - FDCespdu.setEntityLocation(location); - int timestamp = disTime.getDisAbsoluteTimestamp(); - FDCespdu.setTimestamp(timestamp); - - 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 - 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 - TGTEntityID.setEntity(3); - TGTEntityID.setApplication(1); - TGTEntityID.setSite(1); - - /* BELOW IS THE RECIEVE CODE // - // // - // // - */ // - PduFactory factory; - MulticastSocket socket = null; - InetAddress address = null; - DatagramPacket packet; - short currentPduType = 0; //will use the curentPduType as the check for sending other packets. - - try { - System.out.println("FDC is alive and ready to recieve fire missions...\n\n"); - socket = new MulticastSocket(MULTICAST_PORT); - address = InetAddress.getByName(MULTICAST_GROUP); - socket.joinGroup(address); - - factory = new PduFactory(); - - while (true) // Loop infinitely, receiving datagrams - { - byte buffer[] = new byte[1500]; // typical MTU size - - packet = new DatagramPacket(buffer, buffer.length); // reset - - socket.receive(packet); - - String marking2 = new String(); - Pdu pdu = factory.createPdu(packet.getData()); - currentPduType = pdu.getPduType(); - if (currentPduType == 14) //stop/freeze PDU - { - System.out.println("recieved Stop/Freeze packet..."); - return; - } -// pdu.setExerciseID((short)5); - if (pdu != null) { - if (sentBufferList.contains(pdu.getTimestamp())) { - pdu = null; - } - if (pdu != null) { - - String currentPduTypeName = pdu.getClass().getName(); - - if (currentPduType == 1) { - EntityStatePdu pdu2 = (EntityStatePdu) pdu; - marking2 = pdu2.getMarking().getCharactersString(); - } - StringBuilder message = new StringBuilder(); - message.append("received DIS PDU: "); - message.append("pduType "); - if (currentPduType < 10) { - message.append(" "); - } - message.append(currentPduType).append(" ").append(currentPduTypeName); - message.append(" "); - message.append(marking2); - System.out.println(message.toString()); - //Reference for PDU Types: - // http://faculty.nps.edu/brutzman/vrtp/mil/navy/nps/disEnumerations/JdbeHtmlFiles/pdu/8.htm - // - - if (currentPduType == 1) //EntityState - { - EntityStatePdu entityPDU = (EntityStatePdu) pdu; - EntityType PduEntityType = entityPDU.getEntityType(); - if (PduEntityType.getCountry() == 225) { - Thread.sleep((long) 200); - timestamp = disTime.getDisAbsoluteTimestamp(); - FDCespdu.setTimestamp(timestamp); - System.out.println("Talking to the Observer, sending a radio check "); - sender.run(FDCespdu); - } - } - if (currentPduType == 16) //Action request - { - // Action response is sending a Null PDU, not sure why... - AcknowledgePdu ack = new AcknowledgePdu(); - ack.setExerciseID((short) 1); - ack.setRequestID((long) 1); - timestamp = disTime.getDisAbsoluteTimestamp(); - ack.setTimestamp(timestamp); - - FirePdu fire = new FirePdu(); - fire.setExerciseID((short) 1); - fire.setFireMissionIndex(1000); - fire.setRangeToTarget((float) Math.sqrt(Math.pow(150, 2) + Math.pow(150, 2))); //would pass in target info, but here we know location of tgt is (150,150) and FDC (0,0) - fire.setFiringEntityID(FDCID); - fire.setTargetEntityID(TGTEntityID); - timestamp = disTime.getDisAbsoluteTimestamp(); - fire.setTimestamp(timestamp); - sender.run(ack, fire); - } - - if (currentPduType == 22) //Comment PDU - { - AcknowledgePdu ack = new AcknowledgePdu(); - ack.setExerciseID((short) 1); - ack.setRequestID((long) 1); - timestamp = disTime.getDisAbsoluteTimestamp(); - ack.setTimestamp(timestamp); - - StopFreezePdu stop = new StopFreezePdu(); - stop.setExerciseID((short) 1); - stop.setRequestID((long) 1); - sender.run(ack, stop); - } - - } else { - System.out.println("received packet but pdu is null and originated from FDC. Still standing by..."); - } - } - } - } catch (IOException e) { - System.out.println("Problem with FDC.PduReceiver, see exception trace:"); - System.out.println(e); - } finally { - System.out.println("FDC.PduReceiver complete. - OUT!"); - } - - } - -} diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FriscoFurrPduSender.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FriscoFurrPduSender.java deleted file mode 100644 index f6b1a2fbc5..0000000000 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FriscoFurrPduSender.java +++ /dev/null @@ -1,226 +0,0 @@ -package MV3500Cohort2018JulySeptember.FinalProject.FriscoFurrProject; - -import java.io.*; -import java.net.*; -import java.util.*; - -import edu.nps.moves.dis.*; -import edu.nps.moves.disenum.*; -import edu.nps.moves.examples.ClassNameComparator; - - -/** - * This is an example that sends many/most types of PDUs. Useful for testing standards - * compliance or getting a full set of PDUs. It also writes the generated PDUs to an XML file. - * Adapted from OpenDIS library example package edu.nps.moves.examples - * - * @author DMcG - * @version $Id:$ - */ -public class FriscoFurrPduSender -{ - /** Default multicast group address we send on. */ - public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; - - /** Default multicast port used, matches Wireshark DIS capture default */ - public static final int DEFAULT_MULTICAST_PORT = 3000; - - private int port; - InetAddress multicastAddress; - - public FriscoFurrPduSender(int port, String multicast) { - try - { - this.port = port; - multicastAddress = InetAddress.getByName(multicast); - if (!multicastAddress.isMulticastAddress()) - { - System.out.println("Not a multicast address: " + multicast); - } - } - catch (UnknownHostException e) { - System.out.println("Unable to open socket: " + e); - } - } - - public void run() - { - System.out.println("DisExamples.PduSender started..."); - try { - List<Pdu> generatedPdus = new ArrayList<>(); - - // Loop through all the enumerated PDU types, create a PDU for each type, - // and add that PDU to a list. - System.out.println("number of PDU types in pduType is " + PduType.values().length); - for (PduType pdu : PduType.values()) { - Pdu aPdu = null; - System.out.println(pdu); - switch (pdu) // using enumeration values from edu.nps.moves.disenum.* - { -// -// case ENTITY_STATE: -// System.out.println("Case: Enitity_State "+pdu+"\n"); -// aPdu = new EntityStatePdu(); -// EntityStatePdu espdu = (EntityStatePdu) aPdu; -// Marking marking = new Marking(); -// marking.setCharactersString("TEST DUDE"); -// espdu.setMarking(marking); -// Vector3Double espduLocation = new Vector3Double(); -// espduLocation.setX(1.0); -// espduLocation.setY(2.0); -// espduLocation.setZ(3.0); -// EntityType entityType = espdu.getEntityType(); -// entityType.setCountry(222); -// -// break; - -// case COMMENT: -// aPdu = new CommentPdu(); -// CommentPdu comment = (CommentPdu) aPdu; -// EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below -// OBSEntityID.setEntity(2); -// OBSEntityID.setApplication(1); -// OBSEntityID.setSite(1); -// comment.setOriginatingEntityID(OBSEntityID); -// -// long number = 1; -// //comment.setNumberOfFixedDatumRecords(number); -// -// comment.setNumberOfVariableDatumRecords(number); -// List datum = new ArrayList<FixedDatum>(); -// FixedDatum superDatum = new FixedDatum(); -// superDatum.setFixedDatumID((long)5); -// superDatum.setFixedDatumValue((long) 54321); -// datum.add(10); -// datum.add(superDatum); -// comment.setFixedDatums(datum); -// List Vdatum = new ArrayList<VariableDatum>(); -// VariableDatum testBitch = new VariableDatum(); -// testBitch.setVariableDatumID(1); -// Vdatum.add(15); -// comment.setVariableDatums(Vdatum); -// break; - -// case FIRE: -// aPdu = new FirePdu(); -// break; - - case DETONATION: - aPdu = new DetonationPdu(); - System.out.println("detonationPdu type " + aPdu.getPduType()); - break; -// -// case COLLISION: -// aPdu = new CollisionPdu(); -// break; -// -// case SERVICE_REQUEST: -// aPdu = new ServiceRequestPdu(); -// break; -// -// case RESUPPLY_OFFER: -// aPdu = new ResupplyOfferPdu(); -// break; -// -// case RESUPPLY_RECEIVED: -// aPdu = new ResupplyReceivedPdu(); -// break; -// -// case RESUPPLY_CANCEL: -// aPdu = new ResupplyCancelPdu(); -// break; -// -// case REPAIR_COMPLETE: -// aPdu = new RepairCompletePdu(); -// break; -// -// case REPAIR_RESPONSE: -// aPdu = new RepairResponsePdu(); -// break; -// -// case CREATE_ENTITY: -// aPdu = new CreateEntityPdu(); -// break; -// -// case REMOVE_ENTITY: -// aPdu = new RemoveEntityPdu(); -// break; -// -// case START_RESUME: -// aPdu = new StartResumePdu(); -// break; -// -// case STOP_FREEZE: -// aPdu = new StopFreezePdu(); -// break; -// -// case ACKNOWLEDGE: -// aPdu = new AcknowledgePdu(); -// break; -// -// case ACTION_REQUEST: -// aPdu = new ActionRequestPdu(); -// ActionRequestPdu action = (ActionRequestPdu) aPdu; -// EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below -// OBSEntityID.setEntity(2); -// OBSEntityID.setApplication(1); -// OBSEntityID.setSite(1); -// action.setOriginatingEntityID(OBSEntityID); -// break; - - default: - System.out.print("PDU of type " + pdu + " not supported, created or sent "); - System.out.println(); - } - if (aPdu != null) - { - generatedPdus.add(aPdu); - System.out.println("APDU container count "+generatedPdus.size()); - } - } - - // 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()); - } - // write the PDUs out to an XML file. - //PduContainer container = new PduContainer(); - //container.setPdus(generatedPdus); - //container.marshallToXml("examplePdus.xml"); - } catch (IOException e) - { - System.out.println(e); - } - } - - public static void main(String args[]) - { - if (args.length == 2) { - FriscoFurrPduSender sender = new FriscoFurrPduSender(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); - FriscoFurrPduSender sender = new FriscoFurrPduSender(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); - sender.run(); - } - } -} diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/OBSSendRecieve1.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/OBSSendRecieve1.java deleted file mode 100644 index 30b53dad2f..0000000000 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/OBSSendRecieve1.java +++ /dev/null @@ -1,310 +0,0 @@ -package MV3500Cohort2018JulySeptember.FinalProject.FriscoFurrProject; - -import java.net.*; -import java.io.*; -import java.util.*; -import edu.nps.moves.dis.*; -import java.io.IOException; -import edu.nps.moves.disutil.PduFactory; -import edu.nps.moves.disutil.DisTime; - -public class OBSSendRecieve1 { - - /** - * Default multicast group address we send on. - */ - public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; - - /** - * Default multicast port used, matches Wireshark DIS capture default - */ - public static final int DEFAULT_MULTICAST_PORT = 3000; - - private int port; - InetAddress multicastAddress; - - public static final int MULTICAST_PORT = 3000; - public static final String MULTICAST_GROUP = "239.1.2.3"; - public static final boolean USE_FAST_ESPDU = false; - public long[] sentBuffer = new long[100]; - public static List sentBufferList; - DisTime disTime = DisTime.getInstance(); - int transmission =1; - - public OBSSendRecieve1(int port, String multicast) { - this.sentBufferList = new ArrayList<>(); - try { - this.port = port; - multicastAddress = InetAddress.getByName(multicast); - if (!multicastAddress.isMulticastAddress()) { - System.out.println("Not a multicast address: " + multicast); - } - } catch (UnknownHostException e) { - System.out.println("Unable to open socket: " + e); - } - } - - public void run(Pdu... pdupass) throws UnknownHostException, IOException { - - List<Pdu> generatedPdus = new ArrayList<>(); - Pdu aPdu = null; - if(transmission ==1){ - System.out.println("\nInitalizing OP coms..."); - transmission++; - } - if(transmission>1){ - System.out.println("\nObserver Sending traffic..."); - } - // Send the PDUs we created - InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); - MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); - socket.joinGroup(localMulticastAddress); - - for (Pdu i : pdupass) { - Pdu pdu = i; - if (sentBufferList.contains(pdu.getTimestamp())) { - break; - } - - 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.* - { - - case 1: //ENTITY_STATE: - 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; - - case 22: //CommentPdu - 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(); - } - if (aPdu != null) { - generatedPdus.add(aPdu); - System.out.println("APDU container count " + generatedPdus.size()); - } - - } - for (int idx = 0; idx < generatedPdus.size(); idx++) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - byte[] buffer; - - aPdu = generatedPdus.get(idx); - aPdu.marshal(dos); - - 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"); - } - } - - 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: - // - OBSSendRecieve1 sender = new OBSSendRecieve1(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender - - EntityStatePdu OBSespdu = new EntityStatePdu(); - Marking marking = new Marking(); - marking.setCharactersString("Observer"); - OBSespdu.setMarking(marking); - OBSespdu.setExerciseID((short) 1); - 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 - EntityType entityType = OBSespdu.getEntityType(); - // - //Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21 - // https://www.sisostds.org/DesktopModules/Bring2mind/DMX/Download.aspx?Command=Core_Download&EntryId=42916&PortalId=0&TabId=105 - // - entityType.setEntityKind((short) 1); // Platform (vs lifeform, munition, sensor, etc.) TGT=1, OBS = 1 - entityType.setCountry(225); // USA TGT = 222 (Russia), OBS = 225 - entityType.setDomain((short) 1); // Land (vs air, surface, subsurface, space) both TGT and OBS are 1 - entityType.setCategory((short) 40); // FDC TGT = 1, Tank OBS=40 OP -// entityType.setSubcategory((short) 12); // M1068 TGT = 2, T72 tank NONE FOR OP -// entityType.setSpec((short) 1); // M1068 w/ SICUP Tent NONE FOR TGT OR OP - Vector3Double location = new Vector3Double(); - location.setX(75.0); //TGT = 150 OBS = 75 - location.setY(75.0); //TGT = 150 OBS = 75 - location.setZ(50.0); //TGT = 20 OBS = 50 - 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: - EntityID FDCEntityID = new EntityID(); - FDCEntityID.setEntity(1); - FDCEntityID.setApplication(1); - FDCEntityID.setSite(1); - - EntityID TGTEntityID = new EntityID(); - TGTEntityID.setEntity(3); - TGTEntityID.setApplication(1); - TGTEntityID.setSite(1); - - /* BELOW IS THE RECIEVE CODE // - // // - // // - */ // - PduFactory factory; - MulticastSocket socket = null; - InetAddress address = null; - DatagramPacket packet; - 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); - socket.joinGroup(address); - - factory = new PduFactory(); - - while (true) // Loop infinitely, receiving datagrams - { - byte buffer[] = new byte[1500]; // typical MTU size - - 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(); - if (currentPduType == 14) //stop/freeze PDU - { - System.out.println("recieved Stop/Freeze packet..."); - return; - } -// pdu.setExerciseID((short)5); - if (pdu != null) { - if (sentBufferList.contains(pdu.getTimestamp())) { - pdu = null; - } - if (pdu != null) { - - String currentPduTypeName = pdu.getClass().getName(); - if (currentPduType == 1) { - 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 "); - if (currentPduType < 10) { - message.append(" "); - } - message.append(currentPduType).append(" ").append(currentPduTypeName); - message.append(" "); - message.append(marking2); - System.out.println(message.toString()); - //Reference for PDU Types: - // http://faculty.nps.edu/brutzman/vrtp/mil/navy/nps/disEnumerations/JdbeHtmlFiles/pdu/8.htm - // - - if (currentPduType == 1) //EntityState - { - EntityStatePdu entityPDU = (EntityStatePdu) pdu; - EntityType PduEntityType = entityPDU.getEntityType(); - if (PduEntityType.getCountry() == 222) { - ActionRequestPdu action = new ActionRequestPdu(); - action.setExerciseID((short) 1); - action.setRequestID((long) 2); - action.setOriginatingEntityID(OBSID); - action.setReceivingEntityID(FDCEntityID); - timestamp = disTime.getDisAbsoluteTimestamp(); - action.setTimestamp(timestamp); - System.out.println("\n Got a Russian SOB! Preparing CFF to send."); - sender.run(action); - } - } - - if (currentPduType == 3) //Detination - { - CommentPdu comment = new CommentPdu(); - comment.setExerciseID((short) 1); - comment.setOriginatingEntityID(TGTEntityID); - timestamp = disTime.getDisAbsoluteTimestamp(); - comment.setTimestamp(timestamp); - sender.run(comment); - } - - } else { - System.out.println("received packet but pdu is null and originated from Observer. Still searching for other Targets..."); - } - } - } - } catch (IOException e) { - System.out.println("Problem with Observer.PduReceiver, see exception trace:"); - System.out.println(e); - } finally { - System.out.println("Observer.PduReceiver complete. - OUT!"); - } - - } - -} diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/TGTSendRecieve.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/TGTSendRecieve.java deleted file mode 100644 index 7ba723ceba..0000000000 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/TGTSendRecieve.java +++ /dev/null @@ -1,250 +0,0 @@ -package MV3500Cohort2018JulySeptember.FinalProject.FriscoFurrProject; - -import java.net.*; -import java.io.*; -import java.util.*; -import edu.nps.moves.dis.*; -import java.io.IOException; -import edu.nps.moves.disutil.PduFactory; -import edu.nps.moves.disutil.DisTime; - -public class TGTSendRecieve { - - /** - * Default multicast group address we send on. - */ - public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3"; - - /** - * Default multicast port used, matches Wireshark DIS capture default - */ - public static final int DEFAULT_MULTICAST_PORT = 3000; - - private int port; - InetAddress multicastAddress; - - public static final int MULTICAST_PORT = 3000; - public static final String MULTICAST_GROUP = "239.1.2.3"; - public static final boolean USE_FAST_ESPDU = false; - public long[] sentBuffer = new long[100]; - public static List sentBufferList; - DisTime disTime = DisTime.getInstance(); - int transmission = 1; - - public TGTSendRecieve(int port, String multicast) { - this.sentBufferList = new ArrayList<>(); - try { - this.port = port; - multicastAddress = InetAddress.getByName(multicast); - if (!multicastAddress.isMulticastAddress()) { - System.out.println("Not a multicast address: " + multicast); - } - } catch (UnknownHostException e) { - System.out.println("Unable to open socket: " + e); - } - } - - public void run(Pdu... pdupass) throws UnknownHostException, IOException { - - List<Pdu> generatedPdus = new ArrayList<>(); - Pdu aPdu = null; - if (transmission == 1) { - System.out.println("\nTarget is rolling out..."); - transmission++; - } - if (transmission > 1) { - System.out.println("\nDeath from above everywhere! (sending function started)..."); - } - // Send the PDUs we created - InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); - MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT); - socket.joinGroup(localMulticastAddress); - - for (Pdu i : pdupass) { - Pdu pdu = i; - if (sentBufferList.contains(pdu.getTimestamp())) { - break; - } - - short currentPduType = pdu.getPduType(); - System.out.println("in Target sender, processing PDU type: " + currentPduType); -// - switch (currentPduType) // using enumeration values from edu.nps.moves.disenum.* - { - - case 1: //ENTITY_STATE: - aPdu = pdu; - break; - - case 3: //detination PDU - 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(); - } - if (aPdu != null) { - generatedPdus.add(aPdu); - System.out.println("APDU container count " + generatedPdus.size()); - } - - } - for (int idx = 0; idx < generatedPdus.size(); idx++) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - byte[] buffer; - - aPdu = generatedPdus.get(idx); - aPdu.marshal(dos); - - 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"); - } - } - - 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... - - // - // Inital Hello world from entity: - // - TGTSendRecieve sender = new TGTSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender - - EntityStatePdu TGTespdu = new EntityStatePdu(); - Marking marking = new Marking(); - marking.setCharactersString("Target"); - TGTespdu.setMarking(marking); - TGTespdu.setExerciseID((short) 1); - 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 - EntityType entityType = TGTespdu.getEntityType(); - // - //Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21 - // https://www.sisostds.org/DesktopModules/Bring2mind/DMX/Download.aspx?Command=Core_Download&EntryId=42916&PortalId=0&TabId=105 - // - entityType.setEntityKind((short) 1); // Platform (vs lifeform, munition, sensor, etc.) TGT=1, OBS = 1 - entityType.setCountry(222); // USA TGT = 222 (Russia), OBS = 225 - entityType.setDomain((short) 1); // Land (vs air, surface, subsurface, space) both TGT and OBS are 1 - entityType.setCategory((short) 1); // FDC TGT = 1, Tank OBS=40 OP - entityType.setSubcategory((short) 2); // M1068 TGT = 2, T72 tank NONE FOR OP - - Vector3Double location = new Vector3Double(); - location.setX(150.0); //TGT = 150 OBS = 75 - location.setY(150.0); //TGT = 150 OBS = 75 - location.setZ(20.0); //TGT = 20 OBS = 50 - TGTespdu.setEntityLocation(location); - int timestamp = disTime.getDisAbsoluteTimestamp(); - TGTespdu.setTimestamp(timestamp); - sender.run(TGTespdu); //sends inital here I am and who I am - - //other player to look out for: - EntityID FDCEntityID = new EntityID(); - FDCEntityID.setEntity(1); - FDCEntityID.setApplication(1); - FDCEntityID.setSite(1); - - EntityID OBSEntityID = new EntityID(); - OBSEntityID.setEntity(2); - OBSEntityID.setApplication(1); - OBSEntityID.setSite(1); - - /* BELOW IS THE RECIEVE CODE // - // // - // // - */ // - PduFactory factory; - MulticastSocket socket = null; - InetAddress address = null; - DatagramPacket packet; - 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); - socket.joinGroup(address); - - factory = new PduFactory(); - - while (true) // Loop infinitely, receiving datagrams - { - byte buffer[] = new byte[1500]; // typical MTU size - - 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(); - if (currentPduType == 14) //stop/freeze PDU - { - System.out.println("recieved Stop/Freeze packet..."); - return; - } -// pdu.setExerciseID((short)5); - if (pdu != null) { - if (sentBufferList.contains(pdu.getTimestamp())) { - pdu = null; - } - if (pdu != null) { - - String currentPduTypeName = pdu.getClass().getName(); - if (currentPduType == 1) { - 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 "); - if (currentPduType < 10) { - message.append(" "); - } - message.append(currentPduType).append(" ").append(currentPduTypeName); - message.append(" "); - message.append(marking2); - System.out.println(message.toString()); - //Reference for PDU Types: - // http://faculty.nps.edu/brutzman/vrtp/mil/navy/nps/disEnumerations/JdbeHtmlFiles/pdu/8.htm - // - - - if (currentPduType == 2) //FirePDU - { - DetonationPdu det = new DetonationPdu(); - det.setExerciseID((short) 1); - det.setDetonationResult((short)1); - timestamp = disTime.getDisAbsoluteTimestamp(); - det.setTimestamp(timestamp); - sender.run(det); - } - - } else { - System.out.println("received packet but pdu is null and originated from Target. Still doing sketchy Russian things..."); - } - } - } - } catch (IOException e) { - System.out.println("Problem with Target.PduReceiver, see exception trace:"); - System.out.println(e); - } finally { - System.out.println("Target.PduReceiver complete. - T-72 DESTROYED!"); - } - - } - -} -- GitLab