diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FDCSendRecieve.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FDCSendRecieve.java index ee9b1ad5a0ee25c2a1e2a7c8c49505a476d45fab..4282aba1e86866926ee18b40a08bd31f8cfa8ebe 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FDCSendRecieve.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FDCSendRecieve.java @@ -47,7 +47,7 @@ public class FDCSendRecieve { List<Pdu> generatedPdus = new ArrayList<>(); Pdu aPdu = null; - System.out.println("FDC Sender started..."); + 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); @@ -128,11 +128,11 @@ public class FDCSendRecieve { socket.send(packet); //sentBuffer[sentBuffer.length] = aPdu.getTimestamp(); sentBufferList.add(aPdu.getTimestamp()); - System.out.println("Sent PDU of type " + aPdu.getClass().getName()); + System.out.println("Sent PDU of type " + aPdu.getClass().getName()+ "\n"); } } - public static void main(String[] args) throws IOException { + public static void main(String[] args) throws IOException, InterruptedException { DisTime disTime = DisTime.getInstance(); //turns on the sender code - might need to move around down into the recieve with the if statements... // @@ -184,6 +184,17 @@ public class FDCSendRecieve { //FDCespdu.setTimestamp(System.currentTimeMillis()); 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 // // // // // @@ -192,7 +203,7 @@ public class FDCSendRecieve { MulticastSocket socket = null; InetAddress address = null; DatagramPacket packet; - short currentPduType; //will use the curentPduType as the check for sending other packets. + short currentPduType = 0; //will use the curentPduType as the check for sending other packets. try { // TODO: Change the line below to make sense for each class @@ -230,8 +241,7 @@ public class FDCSendRecieve { if (pdu != null) { String currentPduTypeName = pdu.getClass().getName(); - short currentProtocolFamilyID = pdu.getProtocolFamily(); - String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); + if (currentPduType == 1) { EntityStatePdu pdu2 = (EntityStatePdu) pdu; marking2 = pdu2.getMarking().getCharactersString(); @@ -255,38 +265,43 @@ public class FDCSendRecieve { { EntityStatePdu entityPDU = (EntityStatePdu) pdu; EntityType PduEntityType = entityPDU.getEntityType(); - if (PduEntityType.getCountry() == 222) { + if (PduEntityType.getCountry() == 225) { //do something for the OBS as this is a russian asshat. Most likely send the pdu with sender.run(pdu); //create Action Request PDU //sender.run(actionPDU); - System.out.println("got a russian SOB!"); + Thread.sleep((long) 200); + timestamp = disTime.getDisAbsoluteTimestamp(); + FDCespdu.setTimestamp(timestamp); + System.out.println("Talking to the Observer, sending a radio check "); + sender.run(FDCespdu); } } - 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); - if (currentPduType == 16) //Action request { - ActionResponsePdu response = new ActionResponsePdu(); - response.setExerciseID((short) 1); - response.setRequestID((long) 1); + // 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(); - response.setTimestamp(timestamp); + ack.setTimestamp(timestamp); +// ActionResponsePdu response = new ActionResponsePdu(); +// response.setExerciseID((short) 1); +// response.setRequestID((long) 1); +// response.setOriginatingEntityID(FDCID); +// response.setReceivingEntityID(OBSEntityID); +// timestamp = disTime.getDisAbsoluteTimestamp(); +// response.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(response, fire); + sender.run(ack, fire); +// sender.run(fire,fire); } if (currentPduType == 22) //Comment PDU diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FFTestEspduSender.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FFTestEspduSender.java deleted file mode 100644 index 2e8812b43aa128f393368269d6698ac65f7242e5..0000000000000000000000000000000000000000 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FFTestEspduSender.java +++ /dev/null @@ -1,324 +0,0 @@ -package MV3500Cohort2018JulySeptember.FinalProject.FriscoFurrProject; - -import java.io.*; -import java.net.*; -import java.util.*; - -import edu.nps.moves.dis.*; -import edu.nps.moves.disutil.CoordinateConversions; -import edu.nps.moves.disutil.DisTime; - -/** - * Creates and sends ESPDUs in IEEE binary format. Adapted from OpenDIS library - * example package edu.nps.moves.examples - * - * @author DMcG - */ -public class FFTestEspduSender { - - public static final int NUMBER_TO_SEND = 5000; - - public enum NetworkMode { - UNICAST, MULTICAST, BROADCAST - }; - - /** - * 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; - - /** - * Possible system properties, passed in via -Dattr=val networkMode: - * unicast, broadcast, multicast destinationIp: where to send the packet. If - * in multicast mode, this can be multicast. To determine broadcast - * destination IP, use an online broadcast address calculator, for example - * http://www.remotemonitoringsystems.ca/broadcast.php If in multicast mode, - * a join() will be done on the multicast address. port: port used for both - * source and destination. - * - * @param args - */ - public static void main(String args[]) - { - System.out.println("DisExamples.EspduSender started... send " + NUMBER_TO_SEND + " ESPDUs, initial index=0"); - /** - * an entity state pdu - */ - EntityStatePdu espdu = new EntityStatePdu(); - MulticastSocket socket = null; // must be initialized, even if null - DisTime disTime = DisTime.getInstance(); // TODO explain - int alternator = -1; - - // ICBM coordinates for my office - double lat = 36.595517; - double lon = -121.877000; - - // Default settings. These are used if no system properties are set. - // If system properties are passed in, these are over ridden. - int port = DEFAULT_MULTICAST_PORT; - NetworkMode mode = NetworkMode.BROADCAST; - InetAddress destinationIp = null; // must be initialized, even if null - - try { - destinationIp = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS); - } catch (UnknownHostException e) { - System.out.println(e + " Cannot create multicast address"); - System.exit(0); - } - - // All system properties, passed in on the command line via -Dattribute=value - Properties systemProperties = System.getProperties(); - - // IP address we send to - String destinationIpString = systemProperties.getProperty("destinationIp"); - - // Port we send to, and local port we open the socket on - String portString = systemProperties.getProperty("port"); - - // Network mode: unicast, multicast, broadcast - String networkModeString = systemProperties.getProperty("networkMode"); // unicast or multicast or broadcast - - // Set up a socket to send information - try { - // Port we send to - if (portString != null) - { - port = Integer.parseInt(portString); - } - - socket = new MulticastSocket(port); - - // Where we send packets to, the destination IP address - if (destinationIpString != null) - { - destinationIp = InetAddress.getByName(destinationIpString); - } - - // Type of transport: unicast, broadcast, or multicast - // TODO convert to String constants - if (networkModeString != null) { - if (networkModeString.equalsIgnoreCase("unicast")) - { - mode = NetworkMode.UNICAST; - } - else if (networkModeString.equalsIgnoreCase("broadcast")) { - mode = NetworkMode.BROADCAST; - } - else if (networkModeString.equalsIgnoreCase("multicast")) { - mode = NetworkMode.MULTICAST; - if (!destinationIp.isMulticastAddress()) - { - throw new RuntimeException("Sending to multicast address, but destination address " + destinationIp.toString() + "is not multicast"); - } - socket.joinGroup(destinationIp); - } - } // end networkModeString - } - catch (IOException | RuntimeException e) - { - System.out.println("Unable to initialize networking. Exiting."); - System.out.println(e); - System.exit(-1); - } - - // Initialize values in the Entity State PDU object. The exercise ID is - // a way to differentiate between different virtual worlds on one network. - // Note that some values (such as the PDU type and PDU family) are set - // automatically when you create the ESPDU. - espdu.setExerciseID((short) 1); - - // The EID is the unique identifier for objects in the world. This - // EID should match up with the ID for the object specified in the - // VMRL/x3d/virtual world. - EntityID entityID = espdu.getEntityID(); - entityID.setSite(1); // 0 is apparently not a valid site number, per the spec - entityID.setApplication(1); - entityID.setEntity(2); - - // Set the entity type. SISO has a big list of enumerations, so that by - // specifying various numbers we can say this is an M1A2 American tank, - // the USS Enterprise, and so on. We'll make this a tank. There is a - // separate project elsehwhere in this project that implements DIS - // enumerations in C++ and Java, but to keep things simple we just use - // numbers here. - EntityType entityType = espdu.getEntityType(); - entityType.setEntityKind((short) 1); // Platform (vs lifeform, munition, sensor, etc.) - entityType.setCountry(225); // USA - entityType.setDomain((short) 1); // Land (vs air, surface, subsurface, space) - entityType.setCategory((short) 1); // Tank - entityType.setSubcategory((short) 1); // M1 Abrams - entityType.setSpec((short) 3); // M1A2 Abrams - - Set<InetAddress> broadcastAddresses; - // Loop through sending N ESPDUs - try - { - System.out.println("Sending " + NUMBER_TO_SEND + " ESPDU packets to " + destinationIp.toString()); - - for (int index = 0; index < NUMBER_TO_SEND; index++) { - // DIS time is a pain in the uh, neck. DIS time units are 2^31-1 units per - // hour, and time is set to DIS time units from the top of the hour. - // This means that if you start sending just before the top of the hour - // the time units can roll over to zero as you are sending. The receivers - // (escpecially homegrown ones) are often not able to detect rollover - // and may start discarding packets as dupes or out of order. We use - // an NPS timestamp here, hundredths of a second since the start of the - // year. The DIS standard for time is often ignored in the wild; I've seen - // people use Unix time (seconds since 1970) and more. Or you can - // just stuff idx into the timestamp field to get something that is monotonically - // increasing. - - // Note that timestamp is used to detect duplicate and out of order packets. - // That means if you DON'T change the timestamp, many implementations will simply - // discard subsequent packets that have an identical timestamp. Also, if they - // receive a PDU with an timestamp lower than the last one they received, they - // may discard it as an earlier, out-of-order PDU. So it is a good idea to - // update the timestamp on ALL packets sent. - // An alterative approach: actually follow the standard. It's a crazy concept, - // but it might just work. - int timestamp = disTime.getDisAbsoluteTimestamp(); - espdu.setTimestamp(timestamp); - - // Set the position of the entity in the world. DIS uses a cartesian - // coordinate system with the origin at the center of the earth, the x - // axis out at the equator and prime meridian, y out at the equator and - // 90 deg east, and z up and out the north pole. To place an object on - // the earth's surface you also need a model for the shape of the earth - // (it's not a sphere.) All the fancy math necessary to do this is in - // the SEDRIS SRM package. There are also some one-off formulas for - // doing conversions from, for example, lat/lon/altitude to DIS coordinates. - // Here we use those one-off formulas. - // Modify the position of the object. This will send the object a little - // due east by adding some to the longitude every iteration. Since we - // are on the Pacific coast, this sends the object east. Assume we are - // at zero altitude. In other worlds you'd use DTED to determine the - // local ground altitude at that lat/lon, or you'd just use ground clamping. - // The x and y values will change, but the z value should not. - //lon = lon + (double)((double)idx / 100000.0); - //System.out.println("lla=" + lat + "," + lon + ", 0.0"); - double direction = Math.pow((double) (-1.0), (double) (index)); - lon = lon + (direction * 0.00006); - System.out.println(lon); - - double disCoordinates[] = CoordinateConversions.getXYZfromLatLonDegrees(lat, lon, 1.0); - Vector3Double location = espdu.getEntityLocation(); - location.setX(disCoordinates[0]); - location.setY(disCoordinates[1]); - location.setZ(disCoordinates[2]); - System.out.println("lat, lon:" + lat + ", " + lon); - System.out.println("DIS coord:" + disCoordinates[0] + ", " + disCoordinates[1] + ", " + disCoordinates[2]); - - // Optionally, we can do some rotation of the entity - /* - Orientation orientation = espdu.getEntityOrientation(); - float psi = orientation.getPsi(); - psi = psi + idx; - orientation.setPsi(psi); - orientation.setTheta((float)(orientation.getTheta() + idx /2.0)); - */ - // You can set other ESPDU values here, such as the velocity, acceleration, - // and so on. - // Marshal out the espdu object to a byte array, then send a datagram - // packet with that data in it. - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream dos = new DataOutputStream(baos); - espdu.marshal(dos); - - FirePdu fire = new FirePdu(); - //fire.set - byte[] fireArray = fire.marshal(); - - // The byte array here is the packet in DIS format. We put that into a - // datagram and send it. - byte[] data = baos.toByteArray(); - - broadcastAddresses = getBroadcastAddresses(); - Iterator iterator = broadcastAddresses.iterator(); - while (iterator.hasNext()) - { - InetAddress broadcast = (InetAddress) iterator.next(); - System.out.println("Sending broadcast datagram packet to " + broadcast); - DatagramPacket packet = new DatagramPacket(data, data.length, broadcast, port); - socket.send(packet); - // TODO experiment with these! 8) - packet = new DatagramPacket(fireArray, fireArray.length, broadcast, port); // alternate - socket.send(packet); - } - - // Send every 1 sec. Otherwise all this will be all over in a fraction of a second. - Thread.sleep(1000); // msec - - location = espdu.getEntityLocation(); - - System.out.println("Espdu #" + index + " EID=[" + entityID.getSite() + "," + entityID.getApplication() + "," + entityID.getEntity() + "]"); - System.out.println(" DIS coordinates location=[" + location.getX() + "," + location.getY() + "," + location.getZ() + "]"); - double c[] = {location.getX(), location.getY(), location.getZ()}; - double lla[] = CoordinateConversions.xyzToLatLonDegrees(c); -// debug: System.out.println(" Location (lat/lon/alt): [" + lla[0] + ", " + lla[1] + ", " + lla[2] + "]"); - } - } - catch (IOException | InterruptedException e) - { - System.out.println("Problem with DisExamples.EspduSender, see exception trace:"); - System.out.println(e); - } - } - - /** - * A number of sites get all snippy about using 255.255.255.255 for a - * broadcast address; it trips their security software and they kick you off - * their network. (Comcast, NPS.) This determines the broadcast address for - * all connected interfaces, based on the IP and subnet mask. If you have a - * dual-homed host it will return a broadcast address for both. If you have - * some VMs running on your host this will pick up the addresses for those - * as well--e.g. running VMWare on your laptop with a local IP this will also - * pick up a 192.168 address assigned to the VM by the host OS. - * - * @return set of all broadcast addresses - */ - public static Set<InetAddress> getBroadcastAddresses() - { - Set<InetAddress> broadcastAddresses = new HashSet<>(); - Enumeration interfaces; - - try { - interfaces = NetworkInterface.getNetworkInterfaces(); - - while (interfaces.hasMoreElements()) - { - NetworkInterface anInterface = (NetworkInterface) interfaces.nextElement(); - - if (anInterface.isUp()) - { - Iterator iterator = anInterface.getInterfaceAddresses().iterator(); - while (iterator.hasNext()) - { - InterfaceAddress anAddress = (InterfaceAddress) iterator.next(); - if ((anAddress == null || anAddress.getAddress().isLinkLocalAddress())) - { - continue; - } - - //System.out.println("Getting broadcast address for " + anAddress); - InetAddress broadcastAddress = anAddress.getBroadcast(); - if (broadcastAddress != null) - { - broadcastAddresses.add(broadcastAddress); - } - } - } - } - } - catch (SocketException e) - { - System.out.println("Problem with DisExamples.EspduSender.getBroadcastAddresses(), see exception trace:"); - System.out.println(e); - } - return broadcastAddresses; - } -} diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FriscoFurrPduSender.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FriscoFurrPduSender.java index da1ae8774512d70e3890e0adc25c5cfedceb072f..f6b1a2fbc513e6d291d9c02d5c52c35838c9af4a 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FriscoFurrPduSender.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/FriscoFurrPduSender.java @@ -57,7 +57,7 @@ public class FriscoFurrPduSender 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(); @@ -74,40 +74,41 @@ public class FriscoFurrPduSender // // 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 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(); -// break; + case DETONATION: + aPdu = new DetonationPdu(); + System.out.println("detonationPdu type " + aPdu.getPduType()); + break; // // case COLLISION: // aPdu = new CollisionPdu(); diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/OBSSendRecieve1.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/OBSSendRecieve1.java index dd2075ef3e811c64c8aa040a0ad5d57feb379e3e..dad22e9ba5075903207153e36e5d18ff117da3b1 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/OBSSendRecieve1.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/OBSSendRecieve1.java @@ -29,6 +29,7 @@ public class OBSSendRecieve1 { 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<>(); @@ -47,7 +48,13 @@ public class OBSSendRecieve1 { List<Pdu> generatedPdus = new ArrayList<>(); Pdu aPdu = null; - System.out.println("FDC Sender started..."); + 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); @@ -60,7 +67,7 @@ public class OBSSendRecieve1 { } short currentPduType = pdu.getPduType(); - System.out.println("in sender, recived PDU type: " + currentPduType); + 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(); @@ -80,33 +87,32 @@ public class OBSSendRecieve1 { // aPdu = new CommentPdu(); // break; // - case 2: //FIRE - aPdu = pdu; - 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 17: - aPdu = pdu; +// case 15: //AcknowledgePdu +// aPdu = pdu; +// break; +//// + case 16: //ACTION_REQUEST: + aPdu = new ActionRequestPdu(); break; - case 14: + 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, created or sent "); + System.out.print("PDU of type " + pdu + " not supported by Observer, created or sent "); System.out.println(); } if (aPdu != null) { @@ -128,7 +134,7 @@ public class OBSSendRecieve1 { socket.send(packet); //sentBuffer[sentBuffer.length] = aPdu.getTimestamp(); sentBufferList.add(aPdu.getTimestamp()); - System.out.println("Sent PDU of type " + aPdu.getClass().getName()); + System.out.println("Observer Sent PDU of type " + aPdu.getClass().getName()+"/n"); } } @@ -154,16 +160,16 @@ public class OBSSendRecieve1 { // OBSSendRecieve1 sender = new OBSSendRecieve1(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender - EntityStatePdu FDCespdu = new EntityStatePdu(); + EntityStatePdu OBSespdu = 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(); + 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 @@ -171,18 +177,29 @@ public class OBSSendRecieve1 { 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 + 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(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); + 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(); - FDCespdu.setTimestamp(timestamp); + OBSespdu.setTimestamp(timestamp); //FDCespdu.setTimestamp(System.currentTimeMillis()); - sender.run(FDCespdu); //sends inital here I am and who I am + 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 // // // @@ -193,10 +210,10 @@ public class OBSSendRecieve1 { 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("FDC is alive and ready to recieve fire missions...\n\n"); + 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); @@ -230,8 +247,6 @@ public class OBSSendRecieve1 { if (pdu != null) { String currentPduTypeName = pdu.getClass().getName(); - short currentProtocolFamilyID = pdu.getProtocolFamily(); - String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); if (currentPduType == 1) { EntityStatePdu pdu2 = (EntityStatePdu) pdu; marking2 = pdu2.getMarking().getCharactersString(); @@ -256,63 +271,39 @@ public class OBSSendRecieve1 { EntityStatePdu entityPDU = (EntityStatePdu) pdu; EntityType PduEntityType = entityPDU.getEntityType(); if (PduEntityType.getCountry() == 222) { - //do something for the OBS as this is a russian asshat. Most likely send the pdu with sender.run(pdu); - //create Action Request PDU - //sender.run(actionPDU); - System.out.println("got a russian SOB!"); + 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); } } - 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); - - if (currentPduType == 16) //Action request - { - ActionResponsePdu response = new ActionResponsePdu(); - response.setExerciseID((short) 1); - response.setRequestID((long) 1); - timestamp = disTime.getDisAbsoluteTimestamp(); - response.setTimestamp(timestamp); - FirePdu fire = new FirePdu(); - fire.setExerciseID((short) 1); - fire.setFireMissionIndex(1000); - fire.setFiringEntityID(FDCID); - fire.setTargetEntityID(TGTEntityID); - timestamp = disTime.getDisAbsoluteTimestamp(); - fire.setTimestamp(timestamp); - sender.run(response, fire); - } - if (currentPduType == 22) //Comment PDU + if (currentPduType == 3) //Detination { - AcknowledgePdu ack = new AcknowledgePdu(); - ack.setExerciseID((short) 1); - ack.setRequestID((long) 1); + System.out.println("In detination if"); + CommentPdu comment = new CommentPdu(); + comment.setExerciseID((short) 1); + comment.setOriginatingEntityID(TGTEntityID); timestamp = disTime.getDisAbsoluteTimestamp(); - ack.setTimestamp(timestamp); - - StopFreezePdu stop = new StopFreezePdu(); - stop.setExerciseID((short) 1); - stop.setRequestID((long) 1); - sender.run(ack, stop); + comment.setTimestamp(timestamp); + sender.run(comment); } } else { - System.out.println("received packet but pdu is null and originated from FDC. Still standing by..."); + 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 FDC.PduReceiver, see exception trace:"); + System.out.println("Problem with Observer.PduReceiver, see exception trace:"); System.out.println(e); } finally { - System.out.println("FDC.PduReceiver complete. - OUT!"); + System.out.println("Observer.PduReceiver complete. - OUT!"); } } diff --git a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/TGTSendRecieve1.java b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/TGTSendRecieve.java similarity index 65% rename from deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/TGTSendRecieve1.java rename to deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/TGTSendRecieve.java index 41fd8f020e4e4bc00580c62eaee4dadebe578cca..43582abcb21339e631450fbc5e71ef915bcd9233 100644 --- a/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/TGTSendRecieve1.java +++ b/deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/FriscoFurrProject/TGTSendRecieve.java @@ -8,7 +8,7 @@ import java.io.IOException; import edu.nps.moves.disutil.PduFactory; import edu.nps.moves.disutil.DisTime; -public class TGTSendRecieve1 { +public class TGTSendRecieve { /** * Default multicast group address we send on. @@ -29,8 +29,9 @@ public class TGTSendRecieve1 { public long[] sentBuffer = new long[100]; public static List sentBufferList; DisTime disTime = DisTime.getInstance(); + int transmission =1; - public TGTSendRecieve1(int port, String multicast) { + public TGTSendRecieve(int port, String multicast) { this.sentBufferList = new ArrayList<>(); try { this.port = port; @@ -47,7 +48,13 @@ public class TGTSendRecieve1 { List<Pdu> generatedPdus = new ArrayList<>(); Pdu aPdu = null; - System.out.println("FDC Sender started..."); + 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); @@ -60,7 +67,7 @@ public class TGTSendRecieve1 { } short currentPduType = pdu.getPduType(); - System.out.println("in sender, recived PDU type: " + currentPduType); + 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(); @@ -80,33 +87,32 @@ public class TGTSendRecieve1 { // aPdu = new CommentPdu(); // break; // - case 2: //FIRE - aPdu = pdu; - 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 17: - aPdu = pdu; +// case 15: //AcknowledgePdu +// aPdu = pdu; +// break; +//// + case 16: //ACTION_REQUEST: + aPdu = new ActionRequestPdu(); break; - case 14: + 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, created or sent "); + System.out.print("PDU of type " + pdu + " not supported by Observer, created or sent "); System.out.println(); } if (aPdu != null) { @@ -128,7 +134,7 @@ public class TGTSendRecieve1 { socket.send(packet); //sentBuffer[sentBuffer.length] = aPdu.getTimestamp(); sentBufferList.add(aPdu.getTimestamp()); - System.out.println("Sent PDU of type " + aPdu.getClass().getName()); + System.out.println("Observer Sent PDU of type " + aPdu.getClass().getName()+"/n"); } } @@ -152,18 +158,18 @@ public class TGTSendRecieve1 { // // Inital Hello world from entity: // - TGTSendRecieve1 sender = new TGTSendRecieve1(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender + TGTSendRecieve sender = new TGTSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender - EntityStatePdu FDCespdu = new EntityStatePdu(); + EntityStatePdu OBSespdu = 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(); + 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 @@ -171,18 +177,29 @@ public class TGTSendRecieve1 { 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 + 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(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); + 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(); - FDCespdu.setTimestamp(timestamp); + OBSespdu.setTimestamp(timestamp); //FDCespdu.setTimestamp(System.currentTimeMillis()); - sender.run(FDCespdu); //sends inital here I am and who I am + 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 // // // @@ -193,10 +210,10 @@ public class TGTSendRecieve1 { 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("FDC is alive and ready to recieve fire missions...\n\n"); + 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); @@ -230,8 +247,6 @@ public class TGTSendRecieve1 { if (pdu != null) { String currentPduTypeName = pdu.getClass().getName(); - short currentProtocolFamilyID = pdu.getProtocolFamily(); - String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); if (currentPduType == 1) { EntityStatePdu pdu2 = (EntityStatePdu) pdu; marking2 = pdu2.getMarking().getCharactersString(); @@ -256,63 +271,39 @@ public class TGTSendRecieve1 { EntityStatePdu entityPDU = (EntityStatePdu) pdu; EntityType PduEntityType = entityPDU.getEntityType(); if (PduEntityType.getCountry() == 222) { - //do something for the OBS as this is a russian asshat. Most likely send the pdu with sender.run(pdu); - //create Action Request PDU - //sender.run(actionPDU); - System.out.println("got a russian SOB!"); + 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); } } - 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); - - if (currentPduType == 16) //Action request - { - ActionResponsePdu response = new ActionResponsePdu(); - response.setExerciseID((short) 1); - response.setRequestID((long) 1); - timestamp = disTime.getDisAbsoluteTimestamp(); - response.setTimestamp(timestamp); - FirePdu fire = new FirePdu(); - fire.setExerciseID((short) 1); - fire.setFireMissionIndex(1000); - fire.setFiringEntityID(FDCID); - fire.setTargetEntityID(TGTEntityID); - timestamp = disTime.getDisAbsoluteTimestamp(); - fire.setTimestamp(timestamp); - sender.run(response, fire); - } - if (currentPduType == 22) //Comment PDU + if (currentPduType == 3) //Detination { - AcknowledgePdu ack = new AcknowledgePdu(); - ack.setExerciseID((short) 1); - ack.setRequestID((long) 1); + System.out.println("In detination if"); + CommentPdu comment = new CommentPdu(); + comment.setExerciseID((short) 1); + comment.setOriginatingEntityID(TGTEntityID); timestamp = disTime.getDisAbsoluteTimestamp(); - ack.setTimestamp(timestamp); - - StopFreezePdu stop = new StopFreezePdu(); - stop.setExerciseID((short) 1); - stop.setRequestID((long) 1); - sender.run(ack, stop); + comment.setTimestamp(timestamp); + sender.run(comment); } } else { - System.out.println("received packet but pdu is null and originated from FDC. Still standing by..."); + 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 FDC.PduReceiver, see exception trace:"); + System.out.println("Problem with Observer.PduReceiver, see exception trace:"); System.out.println(e); } finally { - System.out.println("FDC.PduReceiver complete. - OUT!"); + System.out.println("Observer.PduReceiver complete. - OUT!"); } }