From 605a1434613c98c6e8b8e14c7450eaf778877a08 Mon Sep 17 00:00:00 2001 From: brutzman <brutzman@nps.edu> Date: Wed, 5 Sep 2018 11:36:42 -0700 Subject: [PATCH] output log demonstrating results --- .../HanleyOpenDisEspduSenderOutputLog.txt | 430 +++--------------- 1 file changed, 59 insertions(+), 371 deletions(-) diff --git a/deliverables/src/MV3500Cohort2018JanuaryMarch/FinalProjects/Hanley/HanleyOpenDisEspduSenderOutputLog.txt b/deliverables/src/MV3500Cohort2018JanuaryMarch/FinalProjects/Hanley/HanleyOpenDisEspduSenderOutputLog.txt index 6b101fcf07..ab9a7bccd3 100644 --- a/deliverables/src/MV3500Cohort2018JanuaryMarch/FinalProjects/Hanley/HanleyOpenDisEspduSenderOutputLog.txt +++ b/deliverables/src/MV3500Cohort2018JanuaryMarch/FinalProjects/Hanley/HanleyOpenDisEspduSenderOutputLog.txt @@ -1,371 +1,59 @@ -package MV3500Cohort2018JanuaryMarch.FinalProjects.Hanley; - -// package edu.nps.moves.examples; // copy example from OpenDIS distribution, modify to serve as template - -import java.io.*; -import java.net.*; -import java.util.*; -import java.io.File; -import java.io.FileNotFoundException; -import java.util.Scanner; - - -import edu.nps.moves.dis.*; -import edu.nps.moves.disutil.CoordinateConversions; -import edu.nps.moves.disutil.DisTime; - -/**This file reads a .csv and send out ESPDUs based on each row of the .csv. - * This file uses Don McGregors original example of OpneDisEspduSender as the - * starting point for the file and was modified to read the .csv and send an - * espdu for each entry. - * - * modified for MV3500 final project by Brian Hanley - * - * - * Creates and sends ESPDUs in IEEE binary format. - * - * @author DMcG - */ -public class HanleyOpenDisEspduSenderOutputLog -{ - //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_GROUP="239.1.2.3"; - - /** Default port we send on */ - public static final int DIS_DESTINATION_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[]) throws FileNotFoundException -{ - /** 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 = DIS_DESTINATION_PORT; - NetworkMode mode = NetworkMode.BROADCAST; - InetAddress destinationIp = null; // must be initialized, even if null - - try - { - destinationIp = InetAddress.getByName(DEFAULT_MULTICAST_GROUP); - } - 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(224); // UK -// entityType.setDomain((short)1); // Land (vs air, surface, subsurface, space) -// entityType.setCategory((short)1); // Tank -// entityType.setSubcategory((short)1); // M1 Abrams -// entityType.setSpec((short)4); // M1A1 w/ mine roller - - - Set<InetAddress> broadcastAddresses; - // Loop through sending .csv entities - String fileName = "Entities.csv"; - File inputFile = new File(System.getProperty("user.dir") + File.separator + // netbeans project directory - "src/MV3500Cohort2018JanuaryMarch/FinalProjects/Hanley/" // deliverables project subdirectory - + fileName); - Scanner scanner; - try { - for (int idx = 0; idx < 10; idx++) - { - scanner = new Scanner(inputFile); //this scanner reads from the .csv file identified by fileName - - //this next line is only necesary if the .csv has a header row. this has the - //scanner read the line and gets ready for the parsing in the while loop. - //if the .csv does not have a header, comment out this line or you will miss the first entity. - scanner.nextLine(); - - //this section reads through the .csv and parses it to send out as an espdu. - while (scanner.hasNextLine()) { - String line = scanner.nextLine(); - //System.out.println(line); - String[] splits; - splits = line.split(","); - if (splits[0].startsWith("#")) { - continue; - } - //this section parse each line into the component necessary to build a DIS ESPDU; - int kind = Integer.parseInt(splits[3]); - int country = Integer.parseInt(splits[4]); - int domain = Integer.parseInt(splits[5]); - int category = Integer.parseInt(splits[6]); - int subCategory = Integer.parseInt(splits[7]); - int special = Integer.parseInt(splits[8]); - int bumperNumber = Integer.parseInt(splits[2]); - float entityLat = Float.parseFloat(splits[9]); - //System.out.println(entityLat); - float entityLon = Float.parseFloat(splits[10]); - String marking = splits[11]; - //System.out.println(marking); - - //This section provides the ESPDU its entity specific information - entityID.setEntity(bumperNumber); - EntityType entityType = espdu.getEntityType(); - entityType.setEntityKind((short) kind); // Platform (vs lifeform, munition, sensor, etc.) - entityType.setCountry((short) country); // country identifier from .csv all should be us for this example - entityType.setDomain((short) domain); // Land (vs air, surface, subsurface, space) - entityType.setCategory((short) category); // for this exampl tank, light truck, heavy truck or light armor - entityType.setSubcategory((short) subCategory); // M1 Abrams, M113, M998, or FMTV - entityType.setSpec((short) special); // various for this example - //System.out.println("entity ID: "+ bumperNumber); // a check built to make sure each line of the .csv was being read and parsed - Marking entityMarking = new Marking(); //creates a marking instance which can be added to the espdu - entityMarking.setCharactersString(marking); - espdu.setMarking(entityMarking); - - //System.out.println("Sending " + NUMBER_TO_SEND + " ESPDU packets to " + destinationIp.toString()); - //for(int idx = 0; idx < NUMBER_TO_SEND; idx++) - // DIS time is a pain in the ass. 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((-1.0), (idx)); - lon = entityLon + (idx * 0.002); - lat = entityLat + (idx * 0.002); - //System.out.println(lat); - //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(); - //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 it = broadcastAddresses.iterator(); - while (it.hasNext()) { - InetAddress broadcast = (InetAddress) it.next(); - //System.out.println("Sending broadcast datagram packet to " + broadcast); - DatagramPacket packet = new DatagramPacket(data, data.length, broadcast, 3000); - socket.send(packet); - // TODO experiment with these! 8) - //packet = new DatagramPacket(fireArray, fireArray.length, broadcast, 3000); // alternate - // socket.send(packet); - } - location = espdu.getEntityLocation(); - - if (bumperNumber == 66) - { - System.out.println("Espdu #" + idx + " 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); - System.out.printf(" Location (lat/lon/alt): [ %.4f , %.4f, %.4f] \n", lla[0], lla[1], lla[2]); - } - - } - ////// - // Send every 1 sec. Otherwise this will be all over in a fraction of a second. - System.out.println("Iteration " + idx); - System.out.println("Sleep Time"); - Thread.sleep(1000); // msec - } - } - catch (IOException | InterruptedException e) - { - 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--eg 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 it = anInterface.getInterfaceAddresses().iterator(); - while (it.hasNext()) { - InterfaceAddress anAddress = (InterfaceAddress) it.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) { - e.printStackTrace(); - System.out.println(e); - } - return broadcastAddresses; - } -} +ant -f E:\\x-nps-gitlab\\NetworkedGraphicsMV3500\\deliverables -Djavac.includes=MV3500Cohort2018JanuaryMarch/FinalProjects/Hanley/HanleyOpenDisEspduSenderFP.java -Dnb.internal.action.name=run.single -Drun.class=MV3500Cohort2018JanuaryMarch.FinalProjects.Hanley.HanleyOpenDisEspduSenderFP run-single +init: +Deleting: E:\x-nps-gitlab\NetworkedGraphicsMV3500\deliverables\build\built-jar.properties +deps-jar: +Updating property file: E:\x-nps-gitlab\NetworkedGraphicsMV3500\deliverables\build\built-jar.properties +Compiling 1 source file to E:\x-nps-gitlab\NetworkedGraphicsMV3500\deliverables\build\classes +compile-single: +run-single: +Espdu #0 EID=[1,1,66] + DIS coordinates location=[-2707341.5145797743,-4353759.30855679,3781448.889965697] + Location (lat/lon/alt): [ 36.5955 , -121.8750, 1.0000] +Iteration 0 +Sleep Time +Espdu #1 EID=[1,1,66] + DIS coordinates location=[-2707119.6704729535,-4353741.444983877,3781627.075538968] + Location (lat/lon/alt): [ 36.5975 , -121.8730, 1.0000] +Iteration 1 +Sleep Time +Espdu #2 EID=[1,1,66] + DIS coordinates location=[-2706897.827604551,-4353723.56590852,3781805.2565533826] + Location (lat/lon/alt): [ 36.5995 , -121.8710, 1.0000] +Iteration 2 +Sleep Time +Espdu #3 EID=[1,1,66] + DIS coordinates location=[-2706675.9859756515,-4353705.671330796,3781983.4330087234] + Location (lat/lon/alt): [ 36.6015 , -121.8690, 1.0000] +Iteration 3 +Sleep Time +Espdu #4 EID=[1,1,66] + DIS coordinates location=[-2706454.1455873316,-4353687.761250788,3782161.6049047676] + Location (lat/lon/alt): [ 36.6035 , -121.8670, 1.0000] +Iteration 4 +Sleep Time +Espdu #5 EID=[1,1,66] + DIS coordinates location=[-2706232.306440672,-4353669.835668579,3782339.7722412986] + Location (lat/lon/alt): [ 36.6055 , -121.8650, 1.0000] +Iteration 5 +Sleep Time +Espdu #6 EID=[1,1,66] + DIS coordinates location=[-2706010.468536753,-4353651.89458425,3782517.9350180984] + Location (lat/lon/alt): [ 36.6075 , -121.8630, 1.0000] +Iteration 6 +Sleep Time +Espdu #7 EID=[1,1,66] + DIS coordinates location=[-2705788.631876655,-4353633.937997884,3782696.0932349465] + Location (lat/lon/alt): [ 36.6095 , -121.8610, 1.0000] +Iteration 7 +Sleep Time +Espdu #8 EID=[1,1,66] + DIS coordinates location=[-2705566.796461456,-4353615.965909564,3782874.2468916243] + Location (lat/lon/alt): [ 36.6115 , -121.8590, 1.0000] +Iteration 8 +Sleep Time +Espdu #9 EID=[1,1,66] + DIS coordinates location=[-2705344.962292239,-4353597.978319372,3783052.3959879144] + Location (lat/lon/alt): [ 36.6135 , -121.8570, 1.0000] +Iteration 9 +Sleep Time +BUILD SUCCESSFUL (total time: 56 seconds) -- GitLab