Skip to content
Snippets Groups Projects
Commit 758c49a9 authored by terry-norbraten's avatar terry-norbraten
Browse files

Merge origin/master

parents e926720f 00b0255a
No related branches found
No related tags found
No related merge requests found
package edu.nps.moves.dis7.examples; package edu.nps.moves.dis7.examples;
import edu.nps.moves.dis7.pdus.*; import edu.nps.moves.dis7.pdus.*;
import edu.nps.moves.dis7.enumerations.DISPDUType; import edu.nps.moves.dis7.enumerations.DisPduType;
import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface; import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
...@@ -57,7 +57,7 @@ public class AlphabeticalPduSender ...@@ -57,7 +57,7 @@ public class AlphabeticalPduSender
// Loop through all the enumerated PDU types, create a PDU for each type, // Loop through all the enumerated PDU types, create a PDU for each type,
// and add that PDU to a list. // and add that PDU to a list.
for (DISPDUType pdu : DISPDUType.values()) { // results are in alphabetic, not numeric order for (DisPduType pdu : DisPduType.values()) { // results are in alphabetic, not numeric order
Pdu aPdu = null; Pdu aPdu = null;
......
...@@ -8,7 +8,7 @@ package edu.nps.moves.dis7.examples; ...@@ -8,7 +8,7 @@ package edu.nps.moves.dis7.examples;
import edu.nps.moves.dis7.pdus.EntityStatePdu; import edu.nps.moves.dis7.pdus.EntityStatePdu;
import edu.nps.moves.dis7.pdus.Pdu; import edu.nps.moves.dis7.pdus.Pdu;
import edu.nps.moves.dis7.utilities.PduFactory; import edu.nps.moves.dis7.utilities.PduFactory;
import edu.nps.moves.dis7.enumerations.DISPDUType; import edu.nps.moves.dis7.enumerations.DisPduType;
import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface; import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface;
import java.io.IOException; import java.io.IOException;
import edu.nps.moves.dis7.entities.usa.platform.surface.*; import edu.nps.moves.dis7.entities.usa.platform.surface.*;
...@@ -100,7 +100,7 @@ public class EntityStateEntityIdExampleUse ...@@ -100,7 +100,7 @@ public class EntityStateEntityIdExampleUse
/* Do the same for the second way of creating a Shenandoah entity type and show an alternate way of creating an ESPDU */ /* Do the same for the second way of creating a Shenandoah entity type and show an alternate way of creating an ESPDU */
espdu = (EntityStatePdu)pduFactory.createPdu(DISPDUType.ENTITY_STATE); espdu = (EntityStatePdu)pduFactory.createPdu(DisPduType.ENTITY_STATE);
/* set desired entity state fields here */ /* set desired entity state fields here */
AD44Shenandoah entityType2 = new AD44Shenandoah(); // edu.nps.moves.dis7.entities.usa.platform.surface AD44Shenandoah entityType2 = new AD44Shenandoah(); // edu.nps.moves.dis7.entities.usa.platform.surface
......
...@@ -7,7 +7,7 @@ package edu.nps.moves.dis7.utilities; ...@@ -7,7 +7,7 @@ package edu.nps.moves.dis7.utilities;
import edu.nps.moves.dis7.pdus.*; import edu.nps.moves.dis7.pdus.*;
import edu.nps.moves.dis7.enumerations.*; import edu.nps.moves.dis7.enumerations.*;
import edu.nps.moves.dis7.enumerations.DISPDUType; import edu.nps.moves.dis7.enumerations.DisPduType;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
...@@ -1475,7 +1475,7 @@ public class PduFactory ...@@ -1475,7 +1475,7 @@ public class PduFactory
.setOriginatingSimulationAddress(newSimulationAddress()); .setOriginatingSimulationAddress(newSimulationAddress());
/* /*
.setActionCode(DISAttributeActionCode.NO_STATEMENT) .setActionCode(DISAttributeActionCode.NO_STATEMENT)
.setAttributeRecordPduType(DISPDUType.OTHER) .setAttributeRecordPduType(DisPduType.OTHER)
.setAttributeRecordProtocolVersion(DISProtocolFamily.OTHER) .setAttributeRecordProtocolVersion(DISProtocolFamily.OTHER)
.setMasterAttributeRecordType(VariableRecordTypes.OTHER) .setMasterAttributeRecordType(VariableRecordTypes.OTHER)
*/ */
...@@ -1504,7 +1504,7 @@ public class PduFactory ...@@ -1504,7 +1504,7 @@ public class PduFactory
*/ */
public Pdu createPdu(ByteBuffer byteBuffer) public Pdu createPdu(ByteBuffer byteBuffer)
{ {
DISPDUType pduType = getTypeFromByteArray(byteBuffer.array()); DisPduType pduType = getTypeFromByteArray(byteBuffer.array());
return createPdu(pduType, byteBuffer); return createPdu(pduType, byteBuffer);
} }
...@@ -1515,9 +1515,9 @@ public class PduFactory ...@@ -1515,9 +1515,9 @@ public class PduFactory
* @param ba byte array * @param ba byte array
* @return the type * @return the type
*/ */
private DISPDUType getTypeFromByteArray(byte[] ba) private DisPduType getTypeFromByteArray(byte[] ba)
{ {
return DISPDUType.getEnumForValue(Byte.toUnsignedInt(ba[2])); // 3rd byte return DisPduType.getEnumForValue(Byte.toUnsignedInt(ba[2])); // 3rd byte
} }
/** /**
...@@ -1525,12 +1525,12 @@ public class PduFactory ...@@ -1525,12 +1525,12 @@ public class PduFactory
* @param pduType PDU type to create * @param pduType PDU type to create
* @return the empty pdu * @return the empty pdu
*/ */
public Pdu createPdu(DISPDUType pduType) public Pdu createPdu(DisPduType pduType)
{ {
return createPdu(pduType, null); return createPdu(pduType, null);
} }
private Pdu createPdu(DISPDUType pduType, ByteBuffer byteBuffer) private Pdu createPdu(DisPduType pduType, ByteBuffer byteBuffer)
{ {
Pdu aPdu = null; Pdu aPdu = null;
switch (pduType) { switch (pduType) {
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
package edu.nps.moves.dis7.utilities.stream; package edu.nps.moves.dis7.utilities.stream;
import com.google.common.primitives.Longs; import com.google.common.primitives.Longs;
import edu.nps.moves.dis7.enumerations.DISPDUType; import edu.nps.moves.dis7.enumerations.DisPduType;
import java.io.*; import java.io.*;
import java.net.DatagramPacket; import java.net.DatagramPacket;
...@@ -104,7 +104,7 @@ public class PduPlayer { ...@@ -104,7 +104,7 @@ public class PduPlayer {
InetAddress addr = null; InetAddress addr = null;
DatagramPacket datagramPacket; DatagramPacket datagramPacket;
DISPDUType type; DisPduType type;
String tempString; String tempString;
String[] sa = null, splitString; String[] sa = null, splitString;
String REGEX; String REGEX;
...@@ -248,7 +248,7 @@ public class PduPlayer { ...@@ -248,7 +248,7 @@ public class PduPlayer {
if (netSend) { if (netSend) {
datagramPacket = new DatagramPacket(buffer, buffer.length, addr, port); datagramPacket = new DatagramPacket(buffer, buffer.length, addr, port);
datagramSocket.send(datagramPacket); datagramSocket.send(datagramPacket);
type = DISPDUType.getEnumForValue(Byte.toUnsignedInt(buffer[2])); // 3rd byte type = DisPduType.getEnumForValue(Byte.toUnsignedInt(buffer[2])); // 3rd byte
System.out.println("Sent PDU: " + type); System.out.println("Sent PDU: " + type);
} }
break; break;
...@@ -308,7 +308,7 @@ public class PduPlayer { ...@@ -308,7 +308,7 @@ public class PduPlayer {
globalByteBufferForX3dInterPolators = bufferShort.clone(); globalByteBufferForX3dInterPolators = bufferShort.clone();
x3dInterpolators.addPointsToMap(globalByteBufferForX3dInterPolators); // gets cloned again x3dInterpolators.addPointsToMap(globalByteBufferForX3dInterPolators); // gets cloned again
x3dLineSet.addPointsToMap(globalByteBufferForX3dInterPolators); // gets cloned again x3dLineSet.addPointsToMap(globalByteBufferForX3dInterPolators); // gets cloned again
type = DISPDUType.getEnumForValue(Byte.toUnsignedInt(bufferShort[2])); // 3rd byte type = DisPduType.getEnumForValue(Byte.toUnsignedInt(bufferShort[2])); // 3rd byte
System.out.println("Sent PDU: " + type); System.out.println("Sent PDU: " + type);
} }
break; break;
......
...@@ -2,7 +2,7 @@ package edu.nps.moves.dis7.utilities.stream; ...@@ -2,7 +2,7 @@ package edu.nps.moves.dis7.utilities.stream;
import com.google.common.primitives.Longs; import com.google.common.primitives.Longs;
import edu.nps.moves.dis7.enumerations.DISPDUType; import edu.nps.moves.dis7.enumerations.DisPduType;
import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface; import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface;
import edu.nps.moves.dis7.utilities.PduFactory; import edu.nps.moves.dis7.utilities.PduFactory;
...@@ -176,7 +176,7 @@ public class PduRecorder implements PduReceiver ...@@ -176,7 +176,7 @@ public class PduRecorder implements PduReceiver
//System.out.println("wrote time "+(packetRcvNanoTime - startNanoTime)); //System.out.println("wrote time "+(packetRcvNanoTime - startNanoTime));
byte[] buffsized = Arrays.copyOf(newBuffer, newLength); byte[] buffsized = Arrays.copyOf(newBuffer, newLength);
DISPDUType pduType; DisPduType pduType;
switch (pduLogEncoding) switch (pduLogEncoding)
{ {
...@@ -192,7 +192,7 @@ public class PduRecorder implements PduReceiver ...@@ -192,7 +192,7 @@ public class PduRecorder implements PduReceiver
sb.append(','); sb.append(',');
sb.append(Arrays.toString(buffsized).replace(" ", "")); sb.append(Arrays.toString(buffsized).replace(" ", ""));
sb.append(" # "); sb.append(" # ");
pduType = DISPDUType.getEnumForValue(Byte.toUnsignedInt(buffsized[2])); // 3rd byte pduType = DisPduType.getEnumForValue(Byte.toUnsignedInt(buffsized[2])); // 3rd byte
sb.append(pduType); sb.append(pduType);
break; break;
...@@ -336,10 +336,10 @@ public class PduRecorder implements PduReceiver ...@@ -336,10 +336,10 @@ public class PduRecorder implements PduReceiver
} }
System.out.println("dis7.utilities.stream.PduRecorder pduRecorder created... isRunning()=" + pduRecorder.isRunning()); System.out.println("dis7.utilities.stream.PduRecorder pduRecorder created... isRunning()=" + pduRecorder.isRunning());
DISPDUType allPDUTypesArray[] = DISPDUType.values(); DisPduType allPDUTypesArray[] = DisPduType.values();
System.out.println("dis7.utilities.stream.PduRecorder allPDUTypesArray created, length=" + allPDUTypesArray.length + " ..."); System.out.println("dis7.utilities.stream.PduRecorder allPDUTypesArray created, length=" + allPDUTypesArray.length + " ...");
Arrays.stream(allPDUTypesArray).forEach(pduTypeValue-> { Arrays.stream(allPDUTypesArray).forEach(pduTypeValue-> {
if(pduTypeValue != DISPDUType.OTHER) if(pduTypeValue != DisPduType.OTHER)
{ {
try { try {
pduRecorder.getDisThreadedNetIF().send(factory.createPdu(pduTypeValue)); pduRecorder.getDisThreadedNetIF().send(factory.createPdu(pduTypeValue));
......
package edu.nps.moves.dis7.utilities.stream; package edu.nps.moves.dis7.utilities.stream;
import edu.nps.moves.dis7.pdus.EntityStatePdu; import edu.nps.moves.dis7.pdus.EntityStatePdu;
import edu.nps.moves.dis7.pdus.Pdu; import edu.nps.moves.dis7.pdus.Pdu;
import edu.nps.moves.dis7.enumerations.DISPDUType; import edu.nps.moves.dis7.enumerations.DisPduType;
import edu.nps.moves.dis7.utilities.PduFactory; import edu.nps.moves.dis7.utilities.PduFactory;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
* *
* @author Tobias Brennenstuhl @ NPS * @author Tobias Brennenstuhl @ NPS
*/ */
public class X3dCreateLineSet { public class X3dCreateLineSet {
private byte[] bufferShort; private byte[] bufferShort;
// -------------------- Begin Variables for Position Interpolator // -------------------- Begin Variables for Position Interpolator
private Boolean firstTimeStamp = true; private Boolean firstTimeStamp = true;
private int firstLocalTimeStamp = 0; private int firstLocalTimeStamp = 0;
private double firstLocalX = 0; private double firstLocalX = 0;
private double firstLocalY = 0; private double firstLocalY = 0;
private double firstLocalZ = 0; private double firstLocalZ = 0;
private Map<Double, X3dCoordinates> testMap = new LinkedHashMap<>(); private Map<Double, X3dCoordinates> testMap = new LinkedHashMap<>();
//Setting up a NumberFormatter for limitting the decimal count to 3 //Setting up a NumberFormatter for limitting the decimal count to 3
private NumberFormat coordinateNumberFormat = NumberFormat.getInstance(new Locale("en", "US")); private NumberFormat coordinateNumberFormat = NumberFormat.getInstance(new Locale("en", "US"));
// -------------------- End Variables for Position Interpolator // -------------------- End Variables for Position Interpolator
/** Constructor */ /** Constructor */
public X3dCreateLineSet() public X3dCreateLineSet()
{ {
//3 significant digits equals milimeter position accuracy and 0.001 radians = 0.0572963266634555 degrees //3 significant digits equals milimeter position accuracy and 0.001 radians = 0.0572963266634555 degrees
coordinateNumberFormat.setMaximumFractionDigits(3); coordinateNumberFormat.setMaximumFractionDigits(3);
} }
public void addPointsToMap(byte[] localBufferShort) public void addPointsToMap(byte[] localBufferShort)
{ {
this.bufferShort = localBufferShort.clone(); this.bufferShort = localBufferShort.clone();
if (bufferShort[2] == 1) { if (bufferShort[2] == 1) {
//PDU Factory //PDU Factory
PduFactory pduFactory = new PduFactory(); PduFactory pduFactory = new PduFactory();
Pdu localPdu = pduFactory.createPdu(bufferShort); Pdu localPdu = pduFactory.createPdu(bufferShort);
// ToDO figure out how to do this! makeEntityStatePDU // ToDO figure out how to do this! makeEntityStatePDU
EntityStatePdu localEspdu = pduFactory.makeEntityStatePdu(); EntityStatePdu localEspdu = pduFactory.makeEntityStatePdu();
//Put all the data we need into the localEspdu //Put all the data we need into the localEspdu
ByteBuffer espduByteBuffer = ByteBuffer.wrap(bufferShort); ByteBuffer espduByteBuffer = ByteBuffer.wrap(bufferShort);
try { try {
localEspdu.unmarshal(espduByteBuffer); localEspdu.unmarshal(espduByteBuffer);
} catch (Exception ex) { } catch (Exception ex) {
Logger.getLogger(X3dCreateLineSet.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(X3dCreateLineSet.class.getName()).log(Level.SEVERE, null, ex);
} }
double localTimeStamp; double localTimeStamp;
double localX; double localX;
double localY; double localY;
double localZ; double localZ;
//TimeStamps for a lineSet is not needed but copied from X3DInterpolators to use them as key for the hashmap //TimeStamps for a lineSet is not needed but copied from X3DInterpolators to use them as key for the hashmap
// and the standard compression class can be used // and the standard compression class can be used
//Store the first timestamp to subtract it from all others //Store the first timestamp to subtract it from all others
//Same with X,Y,Z to create a local coordiante system //Same with X,Y,Z to create a local coordiante system
if (firstTimeStamp) { if (firstTimeStamp) {
firstLocalTimeStamp = localPdu.getTimestamp(); firstLocalTimeStamp = localPdu.getTimestamp();
firstLocalX = localEspdu.getEntityLocation().getX(); firstLocalX = localEspdu.getEntityLocation().getX();
firstLocalY = localEspdu.getEntityLocation().getZ(); firstLocalY = localEspdu.getEntityLocation().getZ();
firstLocalZ = -1 * localEspdu.getEntityLocation().getY(); firstLocalZ = -1 * localEspdu.getEntityLocation().getY();
firstTimeStamp = false; firstTimeStamp = false;
} }
localTimeStamp = localPdu.getTimestamp(); localTimeStamp = localPdu.getTimestamp();
localX = localEspdu.getEntityLocation().getX(); localX = localEspdu.getEntityLocation().getX();
localY = localEspdu.getEntityLocation().getZ(); localY = localEspdu.getEntityLocation().getZ();
localZ = -1 * localEspdu.getEntityLocation().getY(); localZ = -1 * localEspdu.getEntityLocation().getY();
//Debug for printing X,Y,Z //Debug for printing X,Y,Z
//System.out.println(localX + " " + localY + " " + localZ); //System.out.println(localX + " " + localY + " " + localZ);
localTimeStamp = localTimeStamp - firstLocalTimeStamp; localTimeStamp = localTimeStamp - firstLocalTimeStamp;
localX = localX - firstLocalX; localX = localX - firstLocalX;
localY = localY - firstLocalY; localY = localY - firstLocalY;
localZ = localZ - firstLocalZ; localZ = localZ - firstLocalZ;
//Divide TimeStamp by 1,300,000 to get something close to a second per Unit. //Divide TimeStamp by 1,300,000 to get something close to a second per Unit.
//According to the DIS standard one tick is 3600/(2^31) seconds ~ 1.6764 µs //According to the DIS standard one tick is 3600/(2^31) seconds ~ 1.6764 µs
//1,300,000 was derived from a stream that is 61 seconds long. The number was adjusted to get a timesensor with 61 seconds //1,300,000 was derived from a stream that is 61 seconds long. The number was adjusted to get a timesensor with 61 seconds
//ToDo find the real conversion between TimeStampDelta and seconds //ToDo find the real conversion between TimeStampDelta and seconds
localTimeStamp = localTimeStamp / 1300000; localTimeStamp = localTimeStamp / 1300000;
//Only add to stream if it is an ESPDU //Only add to stream if it is an ESPDU
//ToDo: Add support for multiple Entities //ToDo: Add support for multiple Entities
if ((localPdu.getPduType() != null) && (localPdu.getPduType() == DISPDUType.ENTITY_STATE)) if ((localPdu.getPduType() != null) && (localPdu.getPduType() == DisPduType.ENTITY_STATE))
testMap.put(localTimeStamp, new X3dCoordinates(localX, localY, localZ, 0.0, 0.0, 0.0)); testMap.put(localTimeStamp, new X3dCoordinates(localX, localY, localZ, 0.0, 0.0, 0.0));
} }
} }
public void makeX3dLineSet() { public void makeX3dLineSet() {
//Compression of the testMap. //Compression of the testMap.
//Remove all collinear points. //Remove all collinear points.
X3dSlidingWindowCompression regression = new X3dSlidingWindowCompression(testMap); X3dSlidingWindowCompression regression = new X3dSlidingWindowCompression(testMap);
//To turn of the compression just comment the next line out and the very next in. //To turn of the compression just comment the next line out and the very next in.
Map<Double, X3dCoordinates> returnMap = regression.doSlidingWindow(); Map<Double, X3dCoordinates> returnMap = regression.doSlidingWindow();
//returnMap.putAll(testMap); //returnMap.putAll(testMap);
//Writing all values from the KeyMap to a proper Position Interpolator String //Writing all values from the KeyMap to a proper Position Interpolator String
System.out.println("Writing X3D LineSet"); System.out.println("Writing X3D LineSet");
Set<Double> keys = returnMap.keySet(); Set<Double> keys = returnMap.keySet();
String lineSetPoints = ""; String lineSetPoints = "";
String lineSet = "<LineSet vertexCount='" + returnMap.size() + "'> \n <Coordinate point='"; String lineSet = "<LineSet vertexCount='" + returnMap.size() + "'> \n <Coordinate point='";
//Find highest time to do the normalization //Find highest time to do the normalization
double lastTimeStamp = 0; double lastTimeStamp = 0;
for (Double k : keys) { for (Double k : keys) {
if (k > lastTimeStamp) if (k > lastTimeStamp)
lastTimeStamp = k; lastTimeStamp = k;
} }
//Normalize all times in the set //Normalize all times in the set
Map<Double, String> keyKeyValueSetPositionInterpolator = new LinkedHashMap<>(); Map<Double, String> keyKeyValueSetPositionInterpolator = new LinkedHashMap<>();
for (Double k : keys) { for (Double k : keys) {
String localCoordinateString; String localCoordinateString;
double tempX = returnMap.get(k).getX(); double tempX = returnMap.get(k).getX();
double tempY = returnMap.get(k).getY(); double tempY = returnMap.get(k).getY();
double tempZ = returnMap.get(k).getZ(); double tempZ = returnMap.get(k).getZ();
localCoordinateString = " " + coordinateNumberFormat.format(tempX) + " " + coordinateNumberFormat.format(tempY) + " " + coordinateNumberFormat.format(tempZ); localCoordinateString = " " + coordinateNumberFormat.format(tempX) + " " + coordinateNumberFormat.format(tempY) + " " + coordinateNumberFormat.format(tempZ);
keyKeyValueSetPositionInterpolator.put(k / lastTimeStamp, localCoordinateString); keyKeyValueSetPositionInterpolator.put(k / lastTimeStamp, localCoordinateString);
} }
keys = keyKeyValueSetPositionInterpolator.keySet(); keys = keyKeyValueSetPositionInterpolator.keySet();
//Setting up PositionInterpolator and OrientationInterpolator //Setting up PositionInterpolator and OrientationInterpolator
for (Double k : keys) for (Double k : keys)
lineSetPoints += keyKeyValueSetPositionInterpolator.get(k) + " "; lineSetPoints += keyKeyValueSetPositionInterpolator.get(k) + " ";
lineSetPoints += "' "; lineSetPoints += "' ";
//PositionInterpolator //PositionInterpolator
lineSet += lineSetPoints; lineSet += lineSetPoints;
lineSet += "/>\n</LineSet> \n"; lineSet += "/>\n</LineSet> \n";
//Printing PositionInterpolator to the console //Printing PositionInterpolator to the console
System.out.println(lineSet); System.out.println(lineSet);
} }
} }
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