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

package info, package rename

parent 207c72d2
No related branches found
No related tags found
No related merge requests found
......@@ -72,7 +72,7 @@ javadoc.version=false
javadoc.windowtitle=DIS Square Box Demo
jlink.launcher=false
jlink.launcher.name=DisDemo
main.class=disdemo.DisDemo
main.class=DisDemo.DisDemo
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
......
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());
}
}
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