Skip to content
Snippets Groups Projects
Commit cb915ffe authored by Terry D. Norbraten's avatar Terry D. Norbraten
Browse files

Another legacy DMcG demo for DIS. Entity moves in a square using SRM to

DIS coordinates
parent 9f5f6d19
No related branches found
No related tags found
No related merge requests found
Showing with 2215 additions and 0 deletions
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- 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 -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="DisDemo" default="default" basedir=".">
<description>Builds, tests, and runs the project DisDemo.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before 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
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="DisDemo-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
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
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>
File added
File added
File added
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
This diff is collapsed.
build.xml.data.CRC32=8b7a865d
build.xml.script.CRC32=c9a6c7e2
build.xml.stylesheet.CRC32=f85dc8f2@1.95.0.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=8b7a865d
nbproject/build-impl.xml.script.CRC32=e64b9551
nbproject/build-impl.xml.stylesheet.CRC32=f89f7d21@1.95.0.48
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=true
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=DisDemo
application.vendor=mcgredo
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.modulepath=\
${run.modulepath}
debug.test.classpath=\
${run.test.classpath}
debug.test.modulepath=\
${run.test.modulepath}
# Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/DisDemo.jar
dist.javadoc.dir=${dist.dir}/javadoc
endorsed.classpath=
excludes=
file.reference.open-dis7-enumerations-classes.jar=lib/open-dis7-enumerations-classes.jar
file.reference.open-dis7-pdus-classes.jar=lib/open-dis7-pdus-classes.jar
file.reference.srm-4.4.0.jar=lib/srm-4.4.0.jar
includes=**
jar.compress=false
javac.classpath=\
${file.reference.open-dis7-enumerations-classes.jar}:\
${file.reference.open-dis7-pdus-classes.jar}
# Space-separated list of extra javac options
javac.compilerargs=-Xlint:unchecked
javac.deprecation=true
javac.external.vm=false
javac.modulepath=
javac.processormodulepath=
javac.processorpath=\
${javac.classpath}
javac.source=11
javac.target=11
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.modulepath=\
${javac.modulepath}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=true
javadoc.encoding=${source.encoding}
javadoc.html5=false
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=DIS Square Box Demo
jlink.launcher=false
jlink.launcher.name=DisDemo
main.class=disdemo.DisDemo
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
project.license=MOVES
run.classpath=\
${javac.classpath}:\
${build.classes.dir}:\
${file.reference.srm-4.4.0.jar}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.modulepath=\
${javac.modulepath}
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
run.test.modulepath=\
${javac.test.modulepath}
source.encoding=UTF-8
src.dir=src
test.src.dir=test
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>DisDemo</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>
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 {
/**
* @param args the command line arguments
* @throws java.lang.Exception
*/
public static void main(String[] args) throws Exception
{
EntityStatePdu espdu = new EntityStatePdu();
// 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(3001))
{
// 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
for(int idx = 0; idx < 500; idx++)
{
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, 3000);
socket.send(packet);
}
Thread.sleep(1000);
System.out.println("sent " + idx);
}
}
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 */
public static final int STEP_SIZE = 1;
/** How big the square we move around is */
public 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());
}
}
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