Skip to content
Snippets Groups Projects
Commit b08d585c authored by brutzman's avatar brutzman
Browse files

Merge origin/master

Conflicts:
	.gitignore
parents 96561cca 44ee3006
No related branches found
No related tags found
No related merge requests found
Showing
with 2642 additions and 35 deletions
~$3500NetworkedGraphicsSyllabus2019JulySeptember.doc
/nbproject/build-impl.xml~
/nbproject/genfiles.properties
/nbproject/private/
/assignments/build/
/assignments/dist/
/assignments/nbproject/build-impl.xml~
/assignments/nbproject/genfiles.properties
/assignments/nbproject/private/
/examples/BasicServletDemo/nbproject/private/
/examples/WebsocketGateway/nbproject/private/
/examples/manifest.mf
/examples/build/
/examples/dist/
/examples/nbproject/build-impl.xml~
/examples/nbproject/genfiles.properties
/examples/nbproject/private/
/specifications/*.SAVEME
/specifications/*.doc
/specifications/*.htm
/specifications/*.xsd
/specifications/*.xsl
/specifications/*.pdf
/specifications/Makefile
/specifications/README.txt
/specifications/SISO-REF-010-v24
/specifications/RPR*.xml
/specifications/SISO*.xml
/specifications/archive
!/specifications/2019-SIW-Presentation-039_CompressedDis.pdf
!/specifications/IeeeDisPduColorFigures.pdf
/examples/WebsocketGateway/build/
/examples/WebsocketGateway/dist/
/examples/BasicServletDemo/dist/
/examples/BasicServletDemo/build/
~$3500NetworkedGraphicsSyllabus2019JulySeptember.doc
/nbproject/build-impl.xml~
/nbproject/private/
/assignments/build/
/assignments/dist/
/assignments/nbproject/build-impl.xml~
/assignments/nbproject/genfiles.properties
/assignments/nbproject/private/
/examples/BasicServletDemo/nbproject/private/
/examples/WebsocketGateway/nbproject/private/
/examples/manifest.mf
/examples/build/
/examples/dist/
/examples/nbproject/build-impl.xml~
/examples/nbproject/genfiles.properties
/examples/nbproject/private/
/specifications/*.SAVEME
/specifications/*.doc
/specifications/*.htm
/specifications/*.xsd
/specifications/*.xsl
/specifications/*.pdf
/specifications/Makefile
/specifications/README.txt
/specifications/SISO-REF-010-v24
/specifications/RPR*.xml
/specifications/SISO*.xml
/specifications/archive
!/specifications/2019-SIW-Presentation-039_CompressedDis.pdf
!/specifications/IeeeDisPduColorFigures.pdf
/examples/WebsocketGateway/build/
/examples/WebsocketGateway/dist/
/examples/BasicServletDemo/dist/
/examples/BasicServletDemo/build/
/examples/DisShooting/build/
/examples/DisShooting/dist/
/examples/DisShooting/nbproject/private/
<?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="DisShooting" default="default" basedir=".">
<description>Builds, tests, and runs the project DisShooting.</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="DisShooting-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=82bb712e
build.xml.script.CRC32=c8ced301
build.xml.stylesheet.CRC32=f85dc8f2@1.96.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=82bb712e
nbproject/build-impl.xml.script.CRC32=d1ff42b0
nbproject/build-impl.xml.stylesheet.CRC32=f89f7d21@1.96.0.48
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.desc=Legacy DMcG DIS demo
application.title=DisShooting
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}/DisShooting.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.archive.disabled=${jnlp.enabled}
jar.compress=false
jar.index=${jnlp.enabled}
javac.classpath=\
${file.reference.open-dis7-enumerations-classes.jar}:\
${file.reference.open-dis7-pdus-classes.jar}:\
${file.reference.srm-4.4.0.jar}
# Space-separated list of extra javac options
javac.compilerargs=
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 Shooting Demo
jlink.launcher=false
jlink.launcher.name=DisShooting
jnlp.codebase.type=no.codebase
jnlp.descriptor=application
jnlp.enabled=false
jnlp.mixed.code=default
jnlp.offline-allowed=false
jnlp.signed=false
jnlp.signing=
jnlp.signing.alias=
jnlp.signing.keystore=
main.class=mv4503.SimulationRunner
# Optional override of default Application-Library-Allowable-Codebase attribute identifying the locations where your signed RIA is expected to be found.
manifest.custom.application.library.allowable.codebase=
# Optional override of default Caller-Allowable-Codebase attribute identifying the domains from which JavaScript code can make calls to your RIA without security prompts.
manifest.custom.caller.allowable.codebase=
# Optional override of default Codebase manifest attribute, use to prevent RIAs from being repurposed
manifest.custom.codebase=
# Optional override of default Permissions manifest attribute (supported values: sandbox, all-permissions)
manifest.custom.permissions=
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
no.dependencies=true
platform.active=default_platform
project.license=MOVES
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# 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>DisShooting</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>
package mv4503;
import edu.nps.moves.dis7.pdus.DisTime;
import edu.nps.moves.dis7.pdus.Pdu;
import edu.nps.moves.dis7.utilities.*;
import java.io.IOException;
import java.net.*;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/** Networking utility working in ipv4 broadcast mode for both send/receive
* of entity and targeting DIS PDUs.
*
* @author DMcG
* @author &lt;a href="mailto:tdnorbra@nps.edu?subject=mv4503.NetworkComms"&gt;Terry Norbraten, NPS MOVES&lt;/a&gt;
*/
public class NetworkComms implements Runnable
{
public static final int PORT = 3000;
private static NetworkComms networkComms = null;
private DatagramSocket socket;
private InetAddress broadcastAddress = null;
private PduFactory pduFactory;
private DatagramPacket sendPacket, receivePacket;
private ByteBuffer buffSend, buffReceive;
private DisTime time;
/** people we notify when we receive a PDU */
private List<PduListener> listeners;
public static NetworkComms getInstance()
{
synchronized(NetworkComms.class)
{
if(networkComms == null)
{
networkComms = new NetworkComms();
Thread aThread = new Thread(networkComms);
aThread.setDaemon(true);
aThread.start();
}
}
return networkComms;
}
private NetworkComms()
{
pduFactory = new PduFactory();
listeners = new ArrayList<>();
try
{
time = new DisTime();
// Some fancy footwork to allow us to open a UDP socket even if
// anther program has already opened a socket on that port. Opens
// on the wildcard address, i.e. all configured interfaces, both
// wired and wireless, typically.
socket = new DatagramSocket(null);
socket.setReuseAddress(true);
socket.setBroadcast(true);
socket.bind(new InetSocketAddress(PORT));
broadcastAddress = InetAddress.getByName("255.255.255.255");
buffSend = ByteBuffer.allocate(1500);
sendPacket = new DatagramPacket(buffSend.array(), buffSend.array().length, broadcastAddress, PORT);
buffReceive = ByteBuffer.allocate(1500);
receivePacket = new DatagramPacket(buffReceive.array(), buffReceive.array().length);
}
catch(SocketException | UnknownHostException e)
{
buffSend.clear();
buffReceive.clear();
socket.close();
System.err.println(e);
}
}
/**
* Listens for PDUs. Builds a list of all the entities it hears from
* in the form of ESPDUs.
*/
@Override
public void run()
{
Pdu aPdu;
try {
while (true) {
socket.receive(receivePacket);
aPdu = pduFactory.createPdu(buffReceive.array());
// unable to decode data from socket; just continue
if (aPdu == null)
continue;
notifyListeners(aPdu);
buffReceive.clear();
}
} catch (IOException ex) {
Logger.getLogger(NetworkComms.class.getName()).log(Level.SEVERE, null, ex);
} finally {
listeners.clear();
buffReceive.clear();
socket.close();
}
}
public void sendPdu(Pdu aPdu)
{
aPdu.setTimestamp(time.getDisAbsoluteTimestamp());
try {
sendPacket.setData(aPdu.marshal());
if (!socket.isClosed())
socket.send(sendPacket);
} catch (Exception ex) {
Logger.getLogger(NetworkComms.class.getName()).log(Level.SEVERE, null, ex);
} finally {
buffSend.clear();
}
}
public void addListener(PduListener aListener)
{
listeners.add(aListener);
}
public void removeListener(PduListener aListener)
{
listeners.remove(aListener);
}
private void notifyListeners(Pdu aPdu)
{
for(PduListener aListener: listeners)
{
aListener.pduReceived(aPdu);
}
}
}
/*
* BSD License. Copyright MOVES Institute 2005-2014.
*/
package mv4503;
import edu.nps.moves.dis7.pdus.*;
/**
* Interface for things that may be notified of the receipt of a PDU
*
* @author DMcG
*/
public interface PduListener
{
/** Allows for protocol data unit processing once received from the net
*
* @param aPdu the PDU to process
*/
void pduReceived(Pdu aPdu);
}
package mv4503;
import edu.nps.moves.dis7.enumerations.EntityKind;
import edu.nps.moves.dis7.pdus.EntityID;
import edu.nps.moves.dis7.pdus.EntityStatePdu;
import edu.nps.moves.dis7.pdus.Pdu;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/** PDU listener for this simulation run
*
* @author &lt;a href="mailto:tdnorbra@nps.edu?subject=mv4503.PduListenerImpl"&gt;Terry Norbraten, NPS MOVES&lt;/a&gt;
*/
public class PduListenerImpl implements PduListener {
/** All ENTITIES in the world we have heard from */
static final Map<EntityID, EntityStatePdu> ENTITIES = Collections.synchronizedMap(new HashMap<>());
static Collection<EntityStatePdu> allEntities = ENTITIES.values();
static Set<EntityID> allIds = ENTITIES.keySet();
/**
* We are notified by NetworkComms singleton that a PDU has arrived. Do
* something with it.
*
* @param aPdu a protocol data unit to process
*/
@Override
public void pduReceived(Pdu aPdu)
{
switch(aPdu.getPduType())
{
case ENTITY_STATE: // targetEspdu
EntityStatePdu espdu = (EntityStatePdu) aPdu;
EntityID id = espdu.getEntityID();
if(espdu.getEntityType().getEntityKind() == EntityKind.MUNITION) // A munition
break;
ENTITIES.put(id, espdu);
print(id);
break;
case FIRE:
case DETONATION:
System.out.println("Got " + aPdu);
break;
default:
System.out.println("Received PDU " + aPdu.getClass().getName() + " of type " + aPdu.getPduType());
System.err.println("Not handled");
}
}
private void print(EntityID id) {
System.out.println("Adding entity (SiteID, AppID, ID): " + id.getSiteID() + ", " + id.getApplicationID() + ", " + id.getEntityID());
}
} // end class file PduListenerImpl.java
package mv4503;
import edu.nps.moves.dis7.enumerations.Country;
import edu.nps.moves.dis7.enumerations.DetonationResult;
import edu.nps.moves.dis7.enumerations.EntityKind;
import edu.nps.moves.dis7.enumerations.MunitionDescriptorFuse;
import edu.nps.moves.dis7.enumerations.MunitionDescriptorWarhead;
import edu.nps.moves.dis7.enumerations.PlatformDomain;
import edu.nps.moves.dis7.pdus.*;
/**
* Shoots at stuff it sees.
*
* @author DMcG
* @author &lt;a href="mailto:tdnorbra@nps.edu?subject=mv4503.SimulationRunner"&gt;Terry Norbraten, NPS MOVES&lt;/a&gt;
*/
public class SimulationRunner
{
public final static int FIRING_ATTEMPTS = 3;
private static NetworkComms networkComms = null;
private static PduListenerImpl pDuL;
private Sniper sniper;
private Target target;
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
SimulationRunner runner = new SimulationRunner();
// Creates socket, starts listening thread for network traffic (if
// not already listening)
networkComms = NetworkComms.getInstance();
// Will work for both sniper and target PDUs
// Listen for PDUs and build up a list of all the ENTITIES in the world
networkComms.addListener(pDuL = new PduListenerImpl());
for(int idx = 0; idx < FIRING_ATTEMPTS; idx++)
{
System.out.println("Going to sleep for 10 seconds to build a list of entities in the world");
sleep(10000);
System.out.println("Number of entities in the world: " + PduListenerImpl.ENTITIES.size());
// Now we should have a list of ENTITIES in the world we can shoot at.
// Fire away.
runner.shoot();
}
networkComms.removeListener(pDuL);
}
/**
* Constructor starts a list of ENTITIES in the world that is populated by
* the NetworkComms object notifying us of new ESPDUs.
*/
public SimulationRunner()
{
// Sends ESPDUs from our shooter
sniper = Sniper.getInstance();
Thread sniperThread = new Thread(sniper);
sniperThread.setDaemon(true);
sniperThread.start();
// Sends ESPDUs from our target
target = Target.getInstance();
Thread targetThread = new Thread(target);
targetThread.setDaemon(true);
targetThread.start();
}
/**
* Called after a list of entities has been build up by receiving ESPDUs.
* Generates Fire and Detonation PDUs for each of the entities heard from,
* and fires at all the entities, except the sniper (us).
*/
public void shoot()
{
FirePdu firePdu ; // this is actually somewhat optional
DetonationPdu detonationPdu;
EntityStatePdu munitionEspdu;
EntityID targetEntityID, munitionEntityID;
Vector3Double targetLocation;
Vector3Float localCoordinates;
EventIdentifier event;
MunitionDescriptor burst, burst1;
short eventNumber = 1;
// We do a synchronize() here on the ENTITIES variable because another
// thread may be modifying it at the same time.
synchronized (PduListenerImpl.ENTITIES) {
// Loop through all ENTITIES, sending a detonation PDU to
// each at their location.
for (EntityStatePdu targetEspdu : PduListenerImpl.allEntities) {
targetEntityID = targetEspdu.getEntityID();
System.out.println("Target entity (ID, AppID, SiteID): " + targetEntityID.getSiteID() + ", " + targetEntityID.getApplicationID() + ", " + targetEntityID.getEntityID());
targetLocation = targetEspdu.getEntityLocation();
System.out.println("Target location (x, y, z): " + targetLocation.getX() + ", " + targetLocation.getY() + ", " + targetLocation.getZ());
if (targetEntityID.equals(sniper.eId)) {
System.out.println("don't shoot, it's me!");
continue;
}
// create and announce an entity for the munition fired
munitionEspdu = new EntityStatePdu();
munitionEspdu.setExerciseID((byte)1);
munitionEntityID = new EntityID();
munitionEntityID.setSiteID(sniper.eId.getSiteID());
munitionEntityID.setApplicationID(sniper.eId.getApplicationID());
munitionEntityID.setEntityID((int) ((Math.random() * 32000)));
munitionEspdu.setEntityID(munitionEntityID);
// This is some kind of grenade
munitionEspdu.getEntityType().setEntityKind(EntityKind.MUNITION);
munitionEspdu.getEntityType().setDomain(Domain.inst(PlatformDomain.LAND));
munitionEspdu.getEntityType().setCountry(Country.UNITED_STATES_OF_AMERICA_USA);
munitionEspdu.getEntityType().setCategory((short) 2); // ballistic
munitionEspdu.getEntityType().setSubCategory((short) 44);
munitionEspdu.getEntityType().setSpecific((short) 0);
munitionEspdu.getEntityType().setExtra((short) 0);
// Blow up the target entity
munitionEspdu.getEntityLocation().setX(targetLocation.getX());
munitionEspdu.getEntityLocation().setY(targetLocation.getY());
munitionEspdu.getEntityLocation().setZ(targetLocation.getZ());
// Typically the shooter models the flight of the munition.
//Vector3Float vel = munitionEspdu.getEntityLinearVelocity();
//vel.setX(10.0f);
//vel.setY(20.0f);
//vel.setZ(40.0f);
// Send the munition pdu
networkComms.sendPdu(munitionEspdu);
// sleep(1000);
// Fire PDU
firePdu = new FirePdu();
firePdu.setExerciseID((byte)1);
// Shooter
event = new EventIdentifier();
SimulationAddress addr = new SimulationAddress();
addr.setApplication(sniper.eId.getApplicationID());
addr.setSite(sniper.eId.getSiteID());
event.setSimulationAddress(addr);
event.setEventNumber(eventNumber);
eventNumber++;
firePdu.setEventID(event);
firePdu.getLocationInWorldCoordinates().setX(sniper.disCoordinates.getX());
firePdu.getLocationInWorldCoordinates().setY(sniper.disCoordinates.getY());
firePdu.getLocationInWorldCoordinates().setZ(sniper.disCoordinates.getZ());
firePdu.setRange(0.0f);
firePdu.setMunitionExpendibleID(munitionEntityID);
firePdu.setTargetEntityID(targetEntityID);
firePdu.setFiringEntityID(sniper.eId);
networkComms.sendPdu(firePdu);
// sleep(1000);
// Create an explosion that ties together the shooter, target, and munition
detonationPdu = new DetonationPdu();
detonationPdu.setExerciseID((byte)1);
// Who's shooting: us
detonationPdu.setSourceEntityID(sniper.eId);
// Who we're shooting at; one of the ESPDUS (other than us) we received
detonationPdu.setTargetEntityID(targetEntityID);
// The thing blowing up (the munition)
detonationPdu.setExplodingEntityID(munitionEntityID);
// An event ID; this is used to tie fire and detonation events together
detonationPdu.setEventID(event);
// location of detonation
detonationPdu.setLocationInWorldCoordinates(targetLocation);
// Result of detonation
detonationPdu.setDetonationResult(DetonationResult.GROUND_IMPACT); // ground impact
// Location of explosion in local entity coordinates
localCoordinates = new Vector3Float();
localCoordinates.setX(0.0f);
localCoordinates.setY(0.0f);
localCoordinates.setZ(0.0f);
detonationPdu.setLocationOfEntityCoordinates(localCoordinates);
// Descriptors
// Grenade (swiped from VBS2 wireshark capture)
burst = firePdu.getDescriptor();
burst.setMunitionType(munitionEspdu.getEntityType());
burst.setQuantity(1);
burst.setRate(1);
burst.setFuse(MunitionDescriptorFuse._100_MS_DELAY);
burst.setWarhead(MunitionDescriptorWarhead.HE_SHAPED_CHARGE); // HE
detonationPdu.setDescriptor(burst);
networkComms.sendPdu(detonationPdu);
// sleep(1000);
// burst1 = new MunitionDescriptor();
// burst1.setMunitionType(munitionEspdu.getEntityType());
// burst1.setQuantity(1);
// burst1.setRate(1);
// burst1.setFuse(MunitionDescriptorFuse._250_MS_DELAY);
// burst1.setWarhead(MunitionDescriptorWarhead.KINETIC); // kinetic
// detonationPdu.setDescriptor(burst1);
// networkComms.sendPdu(detonationPdu);
// sleep(1000);
}
// Wipe out all the ENTITIES for the next time through the loop
PduListenerImpl.ENTITIES.clear();
}
}
public static void sleep(long ms) {
try
{
Thread.sleep(ms);
}
catch(InterruptedException e)
{
System.err.println("Bad sleep");
}
}
}
package mv4503;
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.*;
import edu.nps.moves.spatial.*;
/** Setup for friendly entity
*
* @author DMcG
*/
public class Sniper implements Runnable
{
private static Sniper sniper = null;
Vector3Double disCoordinates;
EntityID eId;
public static Sniper getInstance() {
if (sniper == null) {
sniper = new Sniper();
}
return sniper;
}
private Sniper()
{
this.eId = new EntityID();
eId.setSiteID(17);
eId.setApplicationID(42);
eId.setEntityID(104);
}
@Override
public void run()
{
System.out.println("Announcing " + this.eId);
EntityStatePdu espdu;
RangeCoordinates rangeCoordinates;
while(true)
{
// Create a new coordinate system at the give latitude, longitude, and altitude
rangeCoordinates = new RangeCoordinates(31.441, 45.227, 17.0);
espdu = new EntityStatePdu();
// Convert from the coodinate system with the rangeCoordinates above to DIS coordinates
disCoordinates = rangeCoordinates.DISCoordFromLocalFlat(0, 0, 0);
espdu.setEntityLocation(disCoordinates);
// Set various fields--entityID, entity type, etc.
espdu.setExerciseID((byte)1);
espdu.setEntityID(eId);
espdu.getEntityType().setEntityKind(EntityKind.PLATFORM);
espdu.getEntityType().setDomain(Domain.inst(PlatformDomain.LAND));
espdu.getEntityType().setCategory((short)2);
espdu.getEntityType().setSubCategory((short)1);
espdu.getEntityType().setSpecific((short)1);
espdu.getEntityType().setCountry(Country.UNITED_STATES_OF_AMERICA_USA);
espdu.getMarking().setCharacters("KaPOW".getBytes());
espdu.setForceId(ForceID.FRIENDLY);
NetworkComms.getInstance().sendPdu(espdu);
SimulationRunner.sleep(2000);
}
}
}
package mv4503;
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.Domain;
import edu.nps.moves.dis7.pdus.EntityID;
import edu.nps.moves.dis7.pdus.EntityStatePdu;
import edu.nps.moves.dis7.pdus.Vector3Double;
import edu.nps.moves.spatial.RangeCoordinates;
/** Our sniper's target
*
* @author &lt;a href="mailto:tdnorbra@nps.edu?subject=mv4503.Target"&gt;Terry Norbraten, NPS MOVES&lt;/a&gt;
*/
public class Target implements Runnable {
private static Target target = null;
private EntityID eId;
public static Target getInstance() {
if (target == null) {
target = new Target();
}
return target;
}
private Target()
{
this.eId = new EntityID();
eId.setSiteID(17);
eId.setApplicationID(42);
eId.setEntityID(208);
}
@Override
public void run()
{
System.out.println("Announcing " + this.eId);
EntityStatePdu espdu;
RangeCoordinates rangeCoordinates;
Vector3Double disCoordinates;
while(true)
{
// Create a new coordinate system at the give latitude, longitude, and altitude
rangeCoordinates = new RangeCoordinates(31.667, 45.421, 16.5);
espdu = new EntityStatePdu();
// Convert from the coodinate system with the rangeCoordinates above to DIS coordinates
disCoordinates = rangeCoordinates.DISCoordFromLocalFlat(0, 1, 0);
espdu.setEntityLocation(disCoordinates);
// Set various fields--entityID, entity type, etc.
espdu.setExerciseID((byte)1);
espdu.setEntityID(eId);
espdu.getEntityType().setEntityKind(EntityKind.PLATFORM);
espdu.getEntityType().setDomain(Domain.inst(PlatformDomain.LAND));
espdu.getEntityType().setCategory((short)2);
espdu.getEntityType().setSubCategory((short)1);
espdu.getEntityType().setSpecific((short)1);
espdu.getEntityType().setCountry(Country.IRAN_ISLAMIC_REPUBLIC_OF_IRN);
espdu.getMarking().setCharacters("RunAndHide".getBytes());
espdu.setForceId(ForceID.OPPOSING);
NetworkComms.getInstance().sendPdu(espdu);
SimulationRunner.sleep(2000);
}
}
} // end class file Target.java
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