Skip to content
Snippets Groups Projects
Commit fa2bb1e1 authored by Brutzman, Don's avatar Brutzman, Don
Browse files

package info, package rename, view javadoc

parent cc40a6cc
No related branches found
No related tags found
No related merge requests found
package disdemo;
import edu.nps.moves.dis7.enumerations.Country;
import edu.nps.moves.dis7.enumerations.EntityKind;
import edu.nps.moves.dis7.enumerations.ForceID;
import edu.nps.moves.dis7.enumerations.PlatformDomain;
import edu.nps.moves.dis7.pdus.DisTime;
import edu.nps.moves.dis7.pdus.Domain;
import edu.nps.moves.dis7.pdus.EntityStatePdu;
import edu.nps.moves.dis7.pdus.Vector3Double;
import edu.nps.moves.spatial.*;
import java.io.IOException;
import java.net.*;
import java.nio.ByteBuffer;
import java.util.*;
/**
*
* @author DMcG
*/
public class DisDemo {
/**
* Program invocation, execution starts here
* @param args command-line arguments
* @throws java.lang.Exception execution error
*/
public static void main(String[] args) throws Exception
{
EntityStatePdu espdu = new EntityStatePdu();
int NUMBER_OF_SENDS = 20;
int PORT = 3000;
int INTERVAL_MSEC = 1000; // 1 second
// Create a new coordinate system at the give latitude, longitude, and altitude
RangeCoordinates rangeCoordinates = new RangeCoordinates(31.435, 45.223, 17.0);
// Convert from the coodinate system with the origin above to DIS coordinates
Vector3Double disCoordinates = rangeCoordinates.DISCoordFromLocalFlat(0, 0, 0);
espdu.setEntityLocation(disCoordinates);
// Set various fields--entityID, entity type, etc.
espdu.setExerciseID((byte)1);
espdu.getEntityID().setSiteID(17);
espdu.getEntityID().setApplicationID(42);
espdu.getEntityID().setEntityID(104);
espdu.getEntityType().setEntityKind(EntityKind.PLATFORM); // platform
espdu.getEntityType().setDomain(Domain.inst(PlatformDomain.LAND)); // land
espdu.getEntityType().setCategory((short)2);
espdu.getEntityType().setSubCategory(1);
espdu.getEntityType().setSpecific((short)1);
espdu.getEntityType().setCountry(Country.UNITED_STATES_OF_AMERICA_USA);
espdu.getMarking().setCharacters("lulz".getBytes());
espdu.setForceId(ForceID.FRIENDLY);
try (DatagramSocket socket = new DatagramSocket(PORT))
{
// We set the starting position to (0,0,0) in the local coordinate
// system, which is equivalent to the (lat, lon, alt) set above as
// the origin, which also corresponds to some DIS geocentric point.
// All three coordinate system points correspond to the same point
// in space.
Vector3Double startPosition = new Vector3Double();
startPosition.setX(0.0);
startPosition.setY(0.0);
startPosition.setZ(0.0);
// Our mover is told to start at (0,0,0) in the local coordinate system
EntityMoverSquare mover = new EntityMoverSquare(startPosition);
List<InetAddress> allBcasts = getBroadcastAddresses();
Vector3Double currentPosition, currentPositionDisCoords;
ByteBuffer buffer;
DatagramPacket packet;
// Do some movement for a while
System.out.println ("Sending " + NUMBER_OF_SENDS + " ESPDU packets at " +
INTERVAL_MSEC + " msec (" + INTERVAL_MSEC/1000.0 +
" second) intervals on");
System.out.println (" broadcast address=" + allBcasts + " port " + PORT);
for(int index = 1; index <= NUMBER_OF_SENDS; index++)
{
mover.step();
// get the current position of the enity in the local coordinate system
currentPosition = mover.getPosition();
// Convert that point to the DIS geocentric coordinate system
currentPositionDisCoords = rangeCoordinates.DISCoordFromLocalFlat(currentPosition.getX(), currentPosition.getY(), currentPosition.getZ());
// Set entity position in the espdu
espdu.setEntityLocation(currentPositionDisCoords);
// Marshall it, send it
espdu.setTimestamp(new DisTime().getDisRelativeTimestamp());
buffer = ByteBuffer.wrap(espdu.marshal());
for(InetAddress aBcast: allBcasts)
{
packet = new DatagramPacket(buffer.array(), buffer.array().length, aBcast, PORT);
socket.send(packet);
}
Thread.sleep(INTERVAL_MSEC);
System.out.println("... sent " + index);
}
}
catch(IOException | InterruptedException e)
{
System.err.println(e);
}
}
public static List<InetAddress> getBroadcastAddresses()
{
List<InetAddress> broadcastAddresses = new ArrayList<>();
try
{
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements())
{
NetworkInterface networkInterface = interfaces.nextElement();
if (networkInterface.isLoopback())
continue; // Don't want to broadcast to the loopback interface
for (InterfaceAddress interfaceAddress : networkInterface.getInterfaceAddresses())
{
InetAddress broadcast = interfaceAddress.getBroadcast();
if (broadcast == null)
continue;
// Use the address
broadcastAddresses.add(broadcast);
}
}
}
catch(SocketException e)
{
System.err.println(e);
}
return broadcastAddresses;
}
}
package disdemo;
import edu.nps.moves.dis7.pdus.*;
/**
* Abstract superclass for moving entities. Initialized with a starting
* position (IN LOCAL COORDINATES). Step() performs one quanta of moving
* the thing around. After movement you can retrieve the new position with
* getPosition(), convert it to global DIS coordinates, and be on your way.
*
* @author DMcG
*/
public abstract class EntityMover
{
Vector3Double position;
public EntityMover(Vector3Double startPosition)
{
this.position = startPosition;
}
public abstract void step();
public Vector3Double getPosition()
{
return position;
}
}
package disdemo;
import edu.nps.moves.dis7.pdus.*;
/**
* Logic for moving something around in a square using a local coordinate system,
* ENU. East is positive X, north is positive Y, positive Z is "up".
*
* @author DMcG
*/
public class EntityMoverSquare extends EntityMover
{
/** How much an entity moves every quanta */
private static final int STEP_SIZE = 1;
/** How big the square we move around is */
private static final int SQUARE_SIZE = 50; // size of a side to the square, in meters
/** Directions we can travel. */
public enum Direction{NORTH, EAST, SOUTH, WEST};
public Direction currentDirection;
public EntityMoverSquare(Vector3Double position)
{
super(position);
this.currentDirection = Direction.NORTH;
}
@Override
public void step()
{
switch(currentDirection)
{
case NORTH:
position.setY( position.getY() + STEP_SIZE);
if(position.getY() >= SQUARE_SIZE)
{
currentDirection = Direction.EAST;
}
break;
case EAST:
position.setX( position.getX() + STEP_SIZE);
if(position.getX() >= SQUARE_SIZE)
{
currentDirection = Direction.SOUTH;
}
break;
case SOUTH:
position.setY( position.getY() - STEP_SIZE);
if(position.getY() <= 0.0)
{
currentDirection = Direction.WEST;
}
break;
case WEST:
position.setX( position.getX() - STEP_SIZE);
if(position.getX() <= 0.0)
{
currentDirection = Direction.NORTH;
}
break;
default:
System.out.println("Unrecognized direction");
}
System.out.println("Current position: " + position.getX() + ", " + position.getY() + ", " + position.getZ());
}
}
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for --> <!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. --> <!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) --> <!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. --> <!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if --> <!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. --> <!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting --> <!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.--> <!-- in the project's Project Properties dialog box.-->
<project name="MV3500 examples" default="default" basedir="."> <project name="MV3500 examples" default="default" basedir=".">
<description>Builds, tests, and runs the project Networked Graphics MV3500 examples.</description> <description>Builds, tests, and runs the project Networked Graphics MV3500 examples.</description>
<import file="nbproject/build-impl.xml"/> <import file="nbproject/build-impl.xml"/>
<!-- TODO target to test all examples as quick unit test --> <!-- TODO target to test all examples as quick unit test -->
<target name="test.examples"> <target name="test.examples">
<!-- invoke single-process tests first --> <!-- invoke single-process tests first -->
<!-- invoke two-process tests next, perhaps following patterns in open-dis7-java --> <!-- invoke two-process tests next, perhaps following patterns in open-dis7-java -->
</target> </target>
<target name="clean.pduLogAdditions"> <target name="clean.pduLogAdditions">
<delete verbose="true"> <delete verbose="true">
<fileset dir="pduLog"> <fileset dir="pduLog">
<include name="Pdusave*.dislog"/> <include name="Pdusave*.dislog"/>
<exclude name="Pdusave.dislog"/><!-- version control default example --> <exclude name="Pdusave.dislog"/><!-- version control default example -->
</fileset> </fileset>
</delete> </delete>
</target> </target>
<!-- <!--
There exist several targets which are by default empty and which can be There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed used for execution of your tasks. These targets are usually executed
before and after some main targets. They are: before and after some main targets. They are:
-pre-init: called before initialization of project properties -pre-init: called before initialization of project properties
-post-init: called after initialization of project properties -post-init: called after initialization of project properties
-pre-compile: called before javac compilation -pre-compile: called before javac compilation
-post-compile: called after javac compilation -post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file -pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file -post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests -pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests -post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test -pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test -post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building -pre-jar: called before JAR building
-post-jar: called after JAR building -post-jar: called after JAR building
-post-clean: called after cleaning build products -post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.) (Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this: Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile"> <target name="-post-compile">
<obfuscate> <obfuscate>
<fileset dir="${build.classes.dir}"/> <fileset dir="${build.classes.dir}"/>
</obfuscate> </obfuscate>
</target> </target>
For list of available properties check the imported For list of available properties check the imported
nbproject/build-impl.xml file. nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets. Another way to customize the build is by overriding existing main targets.
The targets of interest are: The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation -init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution -init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging -init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution -init-macrodef-java: defines macro for class execution
-do-jar: JAR building -do-jar: JAR building
run: execution of project run: execution of project
-javadoc-build: Javadoc generation -javadoc-build: Javadoc generation
test-report: JUnit report generation test-report: JUnit report generation
An example of overriding the target for project execution could look like this: An example of overriding the target for project execution could look like this:
<target name="run" depends="Networked_Graphics_MV3500_examples-impl.jar"> <target name="run" depends="Networked_Graphics_MV3500_examples-impl.jar">
<exec dir="bin" executable="launcher.exe"> <exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/> <arg file="${dist.jar}"/>
</exec> </exec>
</target> </target>
Notice that the overridden target depends on the jar target and not only on Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file. nbproject/build-impl.xml file.
--> -->
</project>
<target name="view.examples.javadoc.local" depends="javadoc"
description="view local MV3500 assignments javadoc in web browser (via Netbeans only)">
<!-- no online javadoc -->
<echo message="dist/javadoc/index.html"/>
<nbbrowse file="dist/javadoc/index.html"/>
</target>
<target name="view.examples.gitlab" description="view gitlab MV3500 examples in web browser (via Netbeans only)">
<echo message="https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/tree/master/examples"/>
<nbbrowse url="https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/tree/master/examples"/>
</target>
</project>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment