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

finish rename DISPDUType -> DisPduType for consistency

parent d8c8f788
No related branches found
No related tags found
No related merge requests found
package edu.nps.moves.dis7.examples;
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 java.io.ByteArrayOutputStream;
......@@ -57,7 +57,7 @@ public class AlphabeticalPduSender
// Loop through all the enumerated PDU types, create a PDU for each type,
// 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;
......
......@@ -8,7 +8,7 @@ package edu.nps.moves.dis7.examples;
import edu.nps.moves.dis7.pdus.EntityStatePdu;
import edu.nps.moves.dis7.pdus.Pdu;
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 java.io.IOException;
import edu.nps.moves.dis7.entities.usa.platform.surface.*;
......@@ -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 */
espdu = (EntityStatePdu)pduFactory.createPdu(DISPDUType.ENTITY_STATE);
espdu = (EntityStatePdu)pduFactory.createPdu(DisPduType.ENTITY_STATE);
/* set desired entity state fields here */
AD44Shenandoah entityType2 = new AD44Shenandoah(); // edu.nps.moves.dis7.entities.usa.platform.surface
......
......@@ -7,7 +7,7 @@ package edu.nps.moves.dis7.utilities;
import edu.nps.moves.dis7.pdus.*;
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.Method;
import java.nio.ByteBuffer;
......@@ -1471,7 +1471,7 @@ public class PduFactory
.setOriginatingSimulationAddress(newSimulationAddress());
/*
.setActionCode(DISAttributeActionCode.NO_STATEMENT)
.setAttributeRecordPduType(DISPDUType.OTHER)
.setAttributeRecordPduType(DisPduType.OTHER)
.setAttributeRecordProtocolVersion(DISProtocolFamily.OTHER)
.setMasterAttributeRecordType(VariableRecordTypes.OTHER)
*/
......@@ -1500,7 +1500,7 @@ public class PduFactory
*/
public Pdu createPdu(ByteBuffer byteBuffer)
{
DISPDUType pduType = getTypeFromByteArray(byteBuffer.array());
DisPduType pduType = getTypeFromByteArray(byteBuffer.array());
return createPdu(pduType, byteBuffer);
}
......@@ -1511,9 +1511,9 @@ public class PduFactory
* @param ba byte array
* @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
}
/**
......@@ -1521,12 +1521,12 @@ public class PduFactory
* @param pduType PDU type to create
* @return the empty pdu
*/
public Pdu createPdu(DISPDUType pduType)
public Pdu createPdu(DisPduType pduType)
{
return createPdu(pduType, null);
}
private Pdu createPdu(DISPDUType pduType, ByteBuffer byteBuffer)
private Pdu createPdu(DisPduType pduType, ByteBuffer byteBuffer)
{
Pdu aPdu = null;
switch (pduType) {
......
......@@ -5,7 +5,7 @@
package edu.nps.moves.dis7.utilities.stream;
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.net.DatagramPacket;
......@@ -104,7 +104,7 @@ public class PduPlayer {
InetAddress addr = null;
DatagramPacket datagramPacket;
DISPDUType type;
DisPduType type;
String tempString;
String[] sa = null, splitString;
String REGEX;
......@@ -248,7 +248,7 @@ public class PduPlayer {
if (netSend) {
datagramPacket = new DatagramPacket(buffer, buffer.length, addr, port);
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);
}
break;
......@@ -308,7 +308,7 @@ public class PduPlayer {
globalByteBufferForX3dInterPolators = bufferShort.clone();
x3dInterpolators.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);
}
break;
......
......@@ -2,7 +2,7 @@ package edu.nps.moves.dis7.utilities.stream;
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.PduFactory;
......@@ -176,7 +176,7 @@ public class PduRecorder implements PduReceiver
//System.out.println("wrote time "+(packetRcvNanoTime - startNanoTime));
byte[] buffsized = Arrays.copyOf(newBuffer, newLength);
DISPDUType pduType;
DisPduType pduType;
switch (pduLogEncoding)
{
......@@ -192,7 +192,7 @@ public class PduRecorder implements PduReceiver
sb.append(',');
sb.append(Arrays.toString(buffsized).replace(" ", ""));
sb.append(" # ");
pduType = DISPDUType.getEnumForValue(Byte.toUnsignedInt(buffsized[2])); // 3rd byte
pduType = DisPduType.getEnumForValue(Byte.toUnsignedInt(buffsized[2])); // 3rd byte
sb.append(pduType);
break;
......@@ -336,10 +336,10 @@ public class PduRecorder implements PduReceiver
}
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 + " ...");
Arrays.stream(allPDUTypesArray).forEach(pduTypeValue-> {
if(pduTypeValue != DISPDUType.OTHER)
if(pduTypeValue != DisPduType.OTHER)
{
try {
pduRecorder.getDisThreadedNetIF().send(factory.createPdu(pduTypeValue));
......
package edu.nps.moves.dis7.utilities.stream;
import edu.nps.moves.dis7.pdus.EntityStatePdu;
import edu.nps.moves.dis7.pdus.Pdu;
import edu.nps.moves.dis7.enumerations.DISPDUType;
import edu.nps.moves.dis7.utilities.PduFactory;
import java.nio.ByteBuffer;
import java.text.NumberFormat;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Tobias Brennenstuhl @ NPS
*/
public class X3dCreateLineSet {
private byte[] bufferShort;
// -------------------- Begin Variables for Position Interpolator
private Boolean firstTimeStamp = true;
private int firstLocalTimeStamp = 0;
private double firstLocalX = 0;
private double firstLocalY = 0;
private double firstLocalZ = 0;
private Map<Double, X3dCoordinates> testMap = new LinkedHashMap<>();
//Setting up a NumberFormatter for limitting the decimal count to 3
private NumberFormat coordinateNumberFormat = NumberFormat.getInstance(new Locale("en", "US"));
// -------------------- End Variables for Position Interpolator
/** Constructor */
public X3dCreateLineSet()
{
//3 significant digits equals milimeter position accuracy and 0.001 radians = 0.0572963266634555 degrees
coordinateNumberFormat.setMaximumFractionDigits(3);
}
public void addPointsToMap(byte[] localBufferShort)
{
this.bufferShort = localBufferShort.clone();
if (bufferShort[2] == 1) {
//PDU Factory
PduFactory pduFactory = new PduFactory();
Pdu localPdu = pduFactory.createPdu(bufferShort);
// ToDO figure out how to do this! makeEntityStatePDU
EntityStatePdu localEspdu = pduFactory.makeEntityStatePdu();
//Put all the data we need into the localEspdu
ByteBuffer espduByteBuffer = ByteBuffer.wrap(bufferShort);
try {
localEspdu.unmarshal(espduByteBuffer);
} catch (Exception ex) {
Logger.getLogger(X3dCreateLineSet.class.getName()).log(Level.SEVERE, null, ex);
}
double localTimeStamp;
double localX;
double localY;
double localZ;
//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
//Store the first timestamp to subtract it from all others
//Same with X,Y,Z to create a local coordiante system
if (firstTimeStamp) {
firstLocalTimeStamp = localPdu.getTimestamp();
firstLocalX = localEspdu.getEntityLocation().getX();
firstLocalY = localEspdu.getEntityLocation().getZ();
firstLocalZ = -1 * localEspdu.getEntityLocation().getY();
firstTimeStamp = false;
}
localTimeStamp = localPdu.getTimestamp();
localX = localEspdu.getEntityLocation().getX();
localY = localEspdu.getEntityLocation().getZ();
localZ = -1 * localEspdu.getEntityLocation().getY();
//Debug for printing X,Y,Z
//System.out.println(localX + " " + localY + " " + localZ);
localTimeStamp = localTimeStamp - firstLocalTimeStamp;
localX = localX - firstLocalX;
localY = localY - firstLocalY;
localZ = localZ - firstLocalZ;
//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
//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
localTimeStamp = localTimeStamp / 1300000;
//Only add to stream if it is an ESPDU
//ToDo: Add support for multiple Entities
if ((localPdu.getPduType() != null) && (localPdu.getPduType() == DISPDUType.ENTITY_STATE))
testMap.put(localTimeStamp, new X3dCoordinates(localX, localY, localZ, 0.0, 0.0, 0.0));
}
}
public void makeX3dLineSet() {
//Compression of the testMap.
//Remove all collinear points.
X3dSlidingWindowCompression regression = new X3dSlidingWindowCompression(testMap);
//To turn of the compression just comment the next line out and the very next in.
Map<Double, X3dCoordinates> returnMap = regression.doSlidingWindow();
//returnMap.putAll(testMap);
//Writing all values from the KeyMap to a proper Position Interpolator String
System.out.println("Writing X3D LineSet");
Set<Double> keys = returnMap.keySet();
String lineSetPoints = "";
String lineSet = "<LineSet vertexCount='" + returnMap.size() + "'> \n <Coordinate point='";
//Find highest time to do the normalization
double lastTimeStamp = 0;
for (Double k : keys) {
if (k > lastTimeStamp)
lastTimeStamp = k;
}
//Normalize all times in the set
Map<Double, String> keyKeyValueSetPositionInterpolator = new LinkedHashMap<>();
for (Double k : keys) {
String localCoordinateString;
double tempX = returnMap.get(k).getX();
double tempY = returnMap.get(k).getY();
double tempZ = returnMap.get(k).getZ();
localCoordinateString = " " + coordinateNumberFormat.format(tempX) + " " + coordinateNumberFormat.format(tempY) + " " + coordinateNumberFormat.format(tempZ);
keyKeyValueSetPositionInterpolator.put(k / lastTimeStamp, localCoordinateString);
}
keys = keyKeyValueSetPositionInterpolator.keySet();
//Setting up PositionInterpolator and OrientationInterpolator
for (Double k : keys)
lineSetPoints += keyKeyValueSetPositionInterpolator.get(k) + " ";
lineSetPoints += "' ";
//PositionInterpolator
lineSet += lineSetPoints;
lineSet += "/>\n</LineSet> \n";
//Printing PositionInterpolator to the console
System.out.println(lineSet);
}
}
package edu.nps.moves.dis7.utilities.stream;
import edu.nps.moves.dis7.pdus.EntityStatePdu;
import edu.nps.moves.dis7.pdus.Pdu;
import edu.nps.moves.dis7.enumerations.DisPduType;
import edu.nps.moves.dis7.utilities.PduFactory;
import java.nio.ByteBuffer;
import java.text.NumberFormat;
import java.util.LinkedHashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Tobias Brennenstuhl @ NPS
*/
public class X3dCreateLineSet {
private byte[] bufferShort;
// -------------------- Begin Variables for Position Interpolator
private Boolean firstTimeStamp = true;
private int firstLocalTimeStamp = 0;
private double firstLocalX = 0;
private double firstLocalY = 0;
private double firstLocalZ = 0;
private Map<Double, X3dCoordinates> testMap = new LinkedHashMap<>();
//Setting up a NumberFormatter for limitting the decimal count to 3
private NumberFormat coordinateNumberFormat = NumberFormat.getInstance(new Locale("en", "US"));
// -------------------- End Variables for Position Interpolator
/** Constructor */
public X3dCreateLineSet()
{
//3 significant digits equals milimeter position accuracy and 0.001 radians = 0.0572963266634555 degrees
coordinateNumberFormat.setMaximumFractionDigits(3);
}
public void addPointsToMap(byte[] localBufferShort)
{
this.bufferShort = localBufferShort.clone();
if (bufferShort[2] == 1) {
//PDU Factory
PduFactory pduFactory = new PduFactory();
Pdu localPdu = pduFactory.createPdu(bufferShort);
// ToDO figure out how to do this! makeEntityStatePDU
EntityStatePdu localEspdu = pduFactory.makeEntityStatePdu();
//Put all the data we need into the localEspdu
ByteBuffer espduByteBuffer = ByteBuffer.wrap(bufferShort);
try {
localEspdu.unmarshal(espduByteBuffer);
} catch (Exception ex) {
Logger.getLogger(X3dCreateLineSet.class.getName()).log(Level.SEVERE, null, ex);
}
double localTimeStamp;
double localX;
double localY;
double localZ;
//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
//Store the first timestamp to subtract it from all others
//Same with X,Y,Z to create a local coordiante system
if (firstTimeStamp) {
firstLocalTimeStamp = localPdu.getTimestamp();
firstLocalX = localEspdu.getEntityLocation().getX();
firstLocalY = localEspdu.getEntityLocation().getZ();
firstLocalZ = -1 * localEspdu.getEntityLocation().getY();
firstTimeStamp = false;
}
localTimeStamp = localPdu.getTimestamp();
localX = localEspdu.getEntityLocation().getX();
localY = localEspdu.getEntityLocation().getZ();
localZ = -1 * localEspdu.getEntityLocation().getY();
//Debug for printing X,Y,Z
//System.out.println(localX + " " + localY + " " + localZ);
localTimeStamp = localTimeStamp - firstLocalTimeStamp;
localX = localX - firstLocalX;
localY = localY - firstLocalY;
localZ = localZ - firstLocalZ;
//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
//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
localTimeStamp = localTimeStamp / 1300000;
//Only add to stream if it is an ESPDU
//ToDo: Add support for multiple Entities
if ((localPdu.getPduType() != null) && (localPdu.getPduType() == DisPduType.ENTITY_STATE))
testMap.put(localTimeStamp, new X3dCoordinates(localX, localY, localZ, 0.0, 0.0, 0.0));
}
}
public void makeX3dLineSet() {
//Compression of the testMap.
//Remove all collinear points.
X3dSlidingWindowCompression regression = new X3dSlidingWindowCompression(testMap);
//To turn of the compression just comment the next line out and the very next in.
Map<Double, X3dCoordinates> returnMap = regression.doSlidingWindow();
//returnMap.putAll(testMap);
//Writing all values from the KeyMap to a proper Position Interpolator String
System.out.println("Writing X3D LineSet");
Set<Double> keys = returnMap.keySet();
String lineSetPoints = "";
String lineSet = "<LineSet vertexCount='" + returnMap.size() + "'> \n <Coordinate point='";
//Find highest time to do the normalization
double lastTimeStamp = 0;
for (Double k : keys) {
if (k > lastTimeStamp)
lastTimeStamp = k;
}
//Normalize all times in the set
Map<Double, String> keyKeyValueSetPositionInterpolator = new LinkedHashMap<>();
for (Double k : keys) {
String localCoordinateString;
double tempX = returnMap.get(k).getX();
double tempY = returnMap.get(k).getY();
double tempZ = returnMap.get(k).getZ();
localCoordinateString = " " + coordinateNumberFormat.format(tempX) + " " + coordinateNumberFormat.format(tempY) + " " + coordinateNumberFormat.format(tempZ);
keyKeyValueSetPositionInterpolator.put(k / lastTimeStamp, localCoordinateString);
}
keys = keyKeyValueSetPositionInterpolator.keySet();
//Setting up PositionInterpolator and OrientationInterpolator
for (Double k : keys)
lineSetPoints += keyKeyValueSetPositionInterpolator.get(k) + " ";
lineSetPoints += "' ";
//PositionInterpolator
lineSet += lineSetPoints;
lineSet += "/>\n</LineSet> \n";
//Printing PositionInterpolator to the console
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