diff --git a/examples/src/OpenDis7Examples/PduTrack.java b/examples/src/OpenDis7Examples/PduTrack.java index 1f134c9a213cd805ee71759e4d907da6fa9cd8e3..27dc692c05bc6befbb055c59efd462813e9e7ff0 100644 --- a/examples/src/OpenDis7Examples/PduTrack.java +++ b/examples/src/OpenDis7Examples/PduTrack.java @@ -40,9 +40,11 @@ import edu.nps.moves.dis7.pdus.EntityStatePdu; import edu.nps.moves.dis7.pdus.EulerAngles; import edu.nps.moves.dis7.pdus.Pdu; import edu.nps.moves.dis7.pdus.Vector3Double; +import java.nio.ByteBuffer; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Date; @@ -163,10 +165,10 @@ public class PduTrack { EntityStatePdu deepCopyEspdu = new EntityStatePdu(); deepCopyEspdu.setTimestamp (((EntityStatePdu)newPdu).getTimestamp()); + deepCopyEspdu.setMarking (((EntityStatePdu)newPdu).getMarking()); deepCopyEspdu.setEntityID (((EntityStatePdu)newPdu).getEntityID()); deepCopyEspdu.setForceId (((EntityStatePdu)newPdu).getForceId()); deepCopyEspdu.setEntityType (((EntityStatePdu)newPdu).getEntityType()); - deepCopyEspdu.setMarking (((EntityStatePdu)newPdu).getMarking()); deepCopyEspdu.setEntityLocation (((EntityStatePdu)newPdu).getEntityLocation()); deepCopyEspdu.setEntityOrientation(((EntityStatePdu)newPdu).getEntityOrientation()); @@ -717,6 +719,7 @@ public class PduTrack */ public void selfTest() { + final int TOTAL_PDUS = 5; System.out.println(TRACE_PREFIX + "selfTest() start..."); PduTrack pduTrack = new PduTrack(); @@ -725,11 +728,11 @@ public class PduTrack pduTrack.setAuthor("Don Brutzman"); pduTrack.setX3dModelIdentifier("https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/-/blob/master/examples/src/OpenDis7Examples/PduTrackInterpolation.x3d"); - EntityStatePdu espdu = new EntityStatePdu(); - espdu.setMarking("PduTrack"); - for (int i = 0; i < 5; i++) + for (int i = 0; i < TOTAL_PDUS; i++) { + EntityStatePdu espdu = new EntityStatePdu(); espdu.setTimestamp(i); + espdu.setMarking("PduTrack " + i); espdu.setEntityLocation(i, i, i); espdu.setEntityOrientation(0, (float)(45.0 * Math.PI / 180.0), 0); pduTrack.addPdu(espdu); @@ -742,6 +745,40 @@ public class PduTrack System.out.println(TRACE_PREFIX + "getEspduCount()=" + pduTrack.getEspduCount()); System.out.println(TRACE_PREFIX + "getDefaultWaypointInterval()=" + pduTrack.getDefaultWaypointInterval()); System.out.println(TRACE_PREFIX + "getTotalDurationSeconds()=" + pduTrack.getTotalDurationSeconds()); + + // marshalling checks + try + { + int BYTE_BUFFER_SIZE = 400; // TODO what is expected max buffer size? + for (int i = 0; i < TOTAL_PDUS; i++) + { + EntityStatePdu espdu = new EntityStatePdu(); + byte[] byteArray = new byte[BYTE_BUFFER_SIZE]; + byteArray = espdu.marshal(); + // https://stackoverflow.com/questions/9655181/how-to-convert-a-byte-array-to-a-hex-string-in-java + final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray(); + char[] hexChars = new char[byteArray.length * 2]; + for (int j = 0; j < byteArray.length; j++) { + int v = byteArray[j] & 0xFF; + hexChars[j * 2] = HEX_ARRAY[v >>> 4]; + hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F]; + } + System.out.println("espdu.marshal(): " + new String(hexChars)); + System.err.flush(); System.out.flush(); + + ByteBuffer byteBuffer = ByteBuffer.allocate(300); + espdu.marshal(byteBuffer); + System.out.println("espdu.marshal(byteBuffer): " + Arrays.toString(byteBuffer.array()).replace(", ", "")); + System.err.flush(); System.out.flush(); + espdu.copy().marshal(byteBuffer); + System.out.println("espdu.copy().marshal(byteBuffer):" + Arrays.toString(byteBuffer.array()).replace(", ", "")); + System.err.flush(); System.out.flush(); + } + } + catch(Exception e) + { + System.out.println(TRACE_PREFIX + "Marshalling test exception: " + e.getMessage()); + } System.out.println("================================="); pduTrack.setAddLineBreaksWithinKeyValues(true); System.out.println(pduTrack.createX3dModel()); // diff --git a/examples/src/OpenDis7Examples/PduTrackLog.txt b/examples/src/OpenDis7Examples/PduTrackLog.txt index a0fd4071903bd7d948ea89d1ef9bdc0db2a5cf6e..c99a57965bf1ab814e8413d40f8f70eb1af4810f 100644 --- a/examples/src/OpenDis7Examples/PduTrackLog.txt +++ b/examples/src/OpenDis7Examples/PduTrackLog.txt @@ -11,6 +11,36 @@ run-single: [PduTrack main() self test] getEspduCount()=5 [PduTrack main() self test] getDefaultWaypointInterval()=1.0 [PduTrack main() self test] getTotalDurationSeconds()=5.0 +*** buffer underflow error while unmarshalling edu.nps.moves.dis7.pdus.Vector3Double +espdu.marshal(): 070001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +*** buffer underflow error while unmarshalling edu.nps.moves.dis7.pdus.EulerAngles +*** buffer underflow error while unmarshalling edu.nps.moves.dis7.pdus.EntityStatePdu +espdu.marshal(byteBuffer): [701100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000] +*** buffer underflow error while unmarshalling edu.nps.moves.dis7.pdus.Vector3Double +*** buffer underflow error while unmarshalling edu.nps.moves.dis7.pdus.EulerAngles +espdu.copy().marshal(byteBuffer):[701100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000] +*** buffer underflow error while unmarshalling edu.nps.moves.dis7.pdus.EntityStatePdu +*** buffer underflow error while unmarshalling edu.nps.moves.dis7.pdus.Vector3Double +espdu.marshal(): 070001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +*** buffer underflow error while unmarshalling edu.nps.moves.dis7.pdus.EulerAngles +*** buffer underflow error while unmarshalling edu.nps.moves.dis7.pdus.EntityStatePdu +espdu.marshal(byteBuffer): [701100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000] +*** buffer underflow error while unmarshalling edu.nps.moves.dis7.pdus.Vector3Double +*** buffer underflow error while unmarshalling edu.nps.moves.dis7.pdus.EulerAngles +espdu.copy().marshal(byteBuffer):[701100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000] +*** buffer underflow error while unmarshalling edu.nps.moves.dis7.pdus.EntityStatePdu +*** buffer underflow error while unmarshalling edu.nps.moves.dis7.pdus.Vector3Double +*** buffer underflow error while unmarshalling edu.nps.moves.dis7.pdus.EulerAngles +espdu.marshal(): 070001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +*** buffer underflow error while unmarshalling edu.nps.moves.dis7.pdus.EntityStatePdu +espdu.marshal(byteBuffer): [701100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000] +espdu.copy().marshal(byteBuffer):[701100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000] +espdu.marshal(): 070001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +espdu.marshal(byteBuffer): [701100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000] +espdu.copy().marshal(byteBuffer):[701100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000] +espdu.marshal(): 070001010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +espdu.marshal(byteBuffer): [701100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000] +espdu.copy().marshal(byteBuffer):[701100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000] ================================= <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 4.0//EN" "https://www.web3d.org/specifications/x3d-4.0.dtd"> @@ -19,7 +49,7 @@ run-single: <meta content='PduTrackInterpolation.x3d' name='title'/> <meta content='Conversion of ESPDU track into X3D animation interpolators and LineSet.' name='description'/> <meta content='1 January 2022' name='created'/> - <meta content='5 January 2022' name='modified'/> + <meta content='6 January 2022' name='modified'/> <meta content='Don Brutzman' name='creator'/> <meta content='https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/-/blob/master/examples/src/OpenDis7Examples/PduTrackInterpolation.x3d' name='identifier'/> <meta content='PduTrack utility, open-dis7-java Library https://github.com/open-dis/open-dis7-java' name='generator'/>