diff --git a/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngelBlankEspduReceiverBtoTCPTest.java b/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngelBlankEspduReceiverBtoTCPTest.java new file mode 100644 index 0000000000000000000000000000000000000000..7d35611fe400a97bdd069677bc06948e53763bc5 --- /dev/null +++ b/projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngelBlankEspduReceiverBtoTCPTest.java @@ -0,0 +1,104 @@ + +import java.net.*; +import java.util.*; + +import edu.nps.moves.disutil.*; +import edu.nps.moves.dis.*; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.OutputStream; +import java.io.PrintStream; + +/** + * Receives PDUs from the network in IEEE format and creates a TCP connection, + * then sends information through the connection. + * + * @author Angelopoulos/Blankenbeker + * @version 8 MAR 2018 + */ +public class AngelBlankEspduReceiverBtoTCPTest { + + public static final String TCP_DESTINATION_IP = "172.20.144.187"; + public static final int DIS_DESTINATION_PORT = 2800; + public static final int TCP_DESTINATION_PORT = 2998; + public static final int MAX_PDU_SIZE = 8192; + public static final String GROUP = "239.1.2.3"; + public static void main(String args[]) { + MulticastSocket socket; + DatagramPacket packet; + DatagramSocket dataGram; + InetAddress address; + PduFactory pduFactory = new PduFactory(); + + try { + + // Specify the socket to receive data + socket = new MulticastSocket(DIS_DESTINATION_PORT); + socket.setBroadcast(true); + address = InetAddress.getByName(GROUP); + socket.joinGroup(address); + //System.out.println("Joined Group."); + // Loop infinitely, receiving datagrams + while (true) { + try{ + byte buffer[] = new byte[MAX_PDU_SIZE]; + packet = new DatagramPacket(buffer, buffer.length); + socket.receive(packet); + //System.out.println("Packet Received"); + List<Pdu> pduBundle = pduFactory.getPdusFromBundle(packet.getData()); + //System.out.println("Bundle size is " + pduBundle.size()); + Iterator it = pduBundle.iterator(); + + while(it.hasNext()){ + Pdu aPdu = (Pdu)it.next(); + //System.out.print("got PDU of type: " + aPdu.getClass().getName()); + if(aPdu instanceof EntityStatePdu){ + EntityID eid = ((EntityStatePdu)aPdu).getEntityID(); + if (eid.getSite() == 200){ + dataGram = new DatagramSocket(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream dos = new DataOutputStream(baos); + aPdu.marshal(dos); + byte[] data = baos.toByteArray(); + + DatagramPacket DpSend = new DatagramPacket(data, data.length, InetAddress.getByName(TCP_DESTINATION_IP), TCP_DESTINATION_PORT); + dataGram.send(DpSend); // Create TCP Bridge + //Socket clientConnection = new Socket(TCP_DESTINATION_IP, TCP_DESTINATION_PORT); + // OutputStream os = clientConnection.getOutputStream(); + //PrintStream ps = new PrintStream(os); + + System.out.println("Bravo briding complete to: "+ TCP_DESTINATION_IP); + //EntityType entityType = ((EntityStatePdu)aPdu).getEntityType(); + /** ps.println(eid.getSite()); + ps.println(eid.getApplication()); + ps.println(eid.getEntity()); + ps.println(entityType.getEntityKind()); // Platform (vs lifeform, munition, sensor, etc.) + ps.println(entityType.getCountry()); // USA + ps.println(entityType.getDomain()); // Land (vs air, surface, subsurface, space) + ps.println(entityType.getCategory()); // Tank + ps.println(entityType.getSubcategory()); // M1 Abrams + ps.println(entityType.getSpec()); // M1A2 Abrams**/ + + + } + Vector3Double location = ((EntityStatePdu)aPdu).getEntityLocation(); + System.out.print(" EID:[" + eid.getSite() + ", " + eid.getApplication() + ", " + eid.getEntity() + "] "); + //System.out.print(" Location in DIS coordinates: [" + location.getX() + ", " + location.getY() + ", " + position.getZ() + "]"); + double c[] = {location.getX(), location.getY(), location.getZ()}; + double lla[] = CoordinateConversions.xyzToLatLonDegrees(c); + System.out.println(" Location (lat/lon/alt): [" + lla[0] + ", " + lla[1] + ", " + lla[2] + "]"); + } + System.out.println(); + } // end trop through PDU bundle + } + catch (Exception e) { + System.out.println(e); + } + } // end while + } // End try + catch (Exception e) { + System.out.println(e); + } + + } // end main +} // end class