diff --git a/src/main/java/edu/nps/moves/dis7/AcousticBeamData.java b/src/main/java/edu/nps/moves/dis7/AcousticBeamData.java new file mode 100644 index 0000000..508ce21 --- /dev/null +++ b/src/main/java/edu/nps/moves/dis7/AcousticBeamData.java @@ -0,0 +1,192 @@ +package edu.nps.moves.dis7; + +import java.io.*; + +/** + * Used in UA PDU + * + * Copyright (c) 2008-2016, MOVES Institute, Naval Postgraduate School. All + * rights reserved. This work is licensed under the BSD open source license, + * available at https://www.movesinstitute.org/licenses/bsd.html + * + * @author DMcG + */ +public class AcousticBeamData extends Object implements Serializable { + + /** + * beam data length + */ + protected int beamDataLength; + + /** + * beamIDNumber + */ + protected short beamIDNumber; + + /** + * padding + */ + protected int pad2; + + /** + * fundamental data parameters + */ + protected AcousticBeamFundamentalParameter fundamentalDataParameters = new AcousticBeamFundamentalParameter(); + + /** + * Constructor + */ + public AcousticBeamData() { + } + + public int getMarshalledSize() { + int marshalSize = 0; + + marshalSize = marshalSize + 2; // beamDataLength + marshalSize = marshalSize + 1; // beamIDNumber + marshalSize = marshalSize + 2; // pad2 + marshalSize = marshalSize + fundamentalDataParameters.getMarshalledSize(); // fundamentalDataParameters + + return marshalSize; + } + + public void setBeamDataLength(int pBeamDataLength) { + beamDataLength = pBeamDataLength; + } + + public int getBeamDataLength() { + return beamDataLength; + } + + public void setBeamIDNumber(short pBeamIDNumber) { + beamIDNumber = pBeamIDNumber; + } + + public short getBeamIDNumber() { + return beamIDNumber; + } + + public void setPad2(int pPad2) { + pad2 = pPad2; + } + + public int getPad2() { + return pad2; + } + + public void setFundamentalDataParameters(AcousticBeamFundamentalParameter pFundamentalDataParameters) { + fundamentalDataParameters = pFundamentalDataParameters; + } + + public AcousticBeamFundamentalParameter getFundamentalDataParameters() { + return fundamentalDataParameters; + } + + /** + * Packs a Pdu into the ByteBuffer. + * + * @throws java.nio.BufferOverflowException if buff is too small + * @throws java.nio.ReadOnlyBufferException if buff is read only + * @see java.nio.ByteBuffer + * @param buff The ByteBuffer at the position to begin writing + * @since ?? + */ + public void marshal(java.nio.ByteBuffer buff) { + buff.putShort((short) beamDataLength); + buff.put((byte) beamIDNumber); + buff.putShort((short) pad2); + fundamentalDataParameters.marshal(buff); + } // end of marshal method + + /** + * Unpacks a Pdu from the underlying data. + * + * @throws java.nio.BufferUnderflowException if buff is too small + * @see java.nio.ByteBuffer + * @param buff The ByteBuffer at the position to begin reading + * @since ?? + */ + public void unmarshal(java.nio.ByteBuffer buff) { + beamDataLength = (int) (buff.getShort() & 0xFFFF); + beamIDNumber = (short) (buff.get() & 0xFF); + pad2 = (int) (buff.getShort() & 0xFFFF); + fundamentalDataParameters.unmarshal(buff); + } // end of unmarshal method + + public void marshal(DataOutputStream dos) { + try { + dos.writeShort((short) beamDataLength); + dos.writeByte((byte) beamIDNumber); + dos.writeShort((short) pad2); + fundamentalDataParameters.marshal(dos); + } // end try + catch (Exception e) { + System.out.println(e); + } + } + + public void unmarshal(DataInputStream dis) { + try { + beamDataLength = (int) dis.readShort(); + beamIDNumber = (short) dis.readByte(); + pad2 = (int) dis.readShort(); + fundamentalDataParameters.unmarshal(dis); + } // end try + catch (Exception e) { + System.out.println(e); + } + } // end of unmarshal method + + /* + * The equals method doesn't always work--mostly it works only on classes that consist only of primitives. Be careful. + */ + @Override + public boolean equals(Object obj) { + + if (this == obj) { + return true; + } + + if (obj == null) { + return false; + } + + if (getClass() != obj.getClass()) { + return false; + } + + return equalsImpl(obj); + } + + /** + * Compare all fields that contribute to the state, ignoring transient and + * static fields, for this and the supplied object + * + * @param obj the object to compare to + * @return true if the objects are equal, false otherwise. + */ + public boolean equalsImpl(Object obj) { + boolean ivarsEqual = true; + + if (!(obj instanceof AcousticBeamData)) { + return false; + } + + final AcousticBeamData rhs = (AcousticBeamData) obj; + + if (!(beamDataLength == rhs.beamDataLength)) { + ivarsEqual = false; + } + if (!(beamIDNumber == rhs.beamIDNumber)) { + ivarsEqual = false; + } + if (!(pad2 == rhs.pad2)) { + ivarsEqual = false; + } + if (!(fundamentalDataParameters.equals(rhs.fundamentalDataParameters))) { + ivarsEqual = false; + } + + return ivarsEqual; + } +} // end of class diff --git a/src/main/java/edu/nps/moves/dis7/AcousticBeamFundamentalParameter.java b/src/main/java/edu/nps/moves/dis7/AcousticBeamFundamentalParameter.java new file mode 100644 index 0000000..eb299af --- /dev/null +++ b/src/main/java/edu/nps/moves/dis7/AcousticBeamFundamentalParameter.java @@ -0,0 +1,234 @@ +package edu.nps.moves.dis7; + +import java.io.*; + +/** + * Used in UaPdu + * + * Copyright (c) 2008-2016, MOVES Institute, Naval Postgraduate School. All + * rights reserved. This work is licensed under the BSD open source license, + * available at https://www.movesinstitute.org/licenses/bsd.html + * + * @author DMcG + */ +public class AcousticBeamFundamentalParameter extends Object implements Serializable { + + /** + * parameter index + */ + protected int activeEmissionParameterIndex; + + /** + * scan pattern + */ + protected int scanPattern; + + /** + * beam center azimuth + */ + protected float beamCenterAzimuth; + + /** + * azimuthal beamwidth + */ + protected float azimuthalBeamwidth; + + /** + * beam center + */ + protected float beamCenterDE; + + /** + * DE beamwidth (vertical beamwidth) + */ + protected float deBeamwidth; + + /** + * Constructor + */ + public AcousticBeamFundamentalParameter() { + } + + public int getMarshalledSize() { + int marshalSize = 0; + + marshalSize = marshalSize + 2; // activeEmissionParameterIndex + marshalSize = marshalSize + 2; // scanPattern + marshalSize = marshalSize + 4; // beamCenterAzimuth + marshalSize = marshalSize + 4; // azimuthalBeamwidth + marshalSize = marshalSize + 4; // beamCenterDE + marshalSize = marshalSize + 4; // deBeamwidth + + return marshalSize; + } + + public void setActiveEmissionParameterIndex(int pActiveEmissionParameterIndex) { + activeEmissionParameterIndex = pActiveEmissionParameterIndex; + } + + public int getActiveEmissionParameterIndex() { + return activeEmissionParameterIndex; + } + + public void setScanPattern(int pScanPattern) { + scanPattern = pScanPattern; + } + + public int getScanPattern() { + return scanPattern; + } + + public void setBeamCenterAzimuth(float pBeamCenterAzimuth) { + beamCenterAzimuth = pBeamCenterAzimuth; + } + + public float getBeamCenterAzimuth() { + return beamCenterAzimuth; + } + + public void setAzimuthalBeamwidth(float pAzimuthalBeamwidth) { + azimuthalBeamwidth = pAzimuthalBeamwidth; + } + + public float getAzimuthalBeamwidth() { + return azimuthalBeamwidth; + } + + public void setBeamCenterDE(float pBeamCenterDE) { + beamCenterDE = pBeamCenterDE; + } + + public float getBeamCenterDE() { + return beamCenterDE; + } + + public void setDeBeamwidth(float pDeBeamwidth) { + deBeamwidth = pDeBeamwidth; + } + + public float getDeBeamwidth() { + return deBeamwidth; + } + + /** + * Packs a Pdu into the ByteBuffer. + * + * @throws java.nio.BufferOverflowException if buff is too small + * @throws java.nio.ReadOnlyBufferException if buff is read only + * @see java.nio.ByteBuffer + * @param buff The ByteBuffer at the position to begin writing + * @since ?? + */ + public void marshal(java.nio.ByteBuffer buff) { + buff.putShort((short) activeEmissionParameterIndex); + buff.putShort((short) scanPattern); + buff.putFloat((float) beamCenterAzimuth); + buff.putFloat((float) azimuthalBeamwidth); + buff.putFloat((float) beamCenterDE); + buff.putFloat((float) deBeamwidth); + } // end of marshal method + + /** + * Unpacks a Pdu from the underlying data. + * + * @throws java.nio.BufferUnderflowException if buff is too small + * @see java.nio.ByteBuffer + * @param buff The ByteBuffer at the position to begin reading + * @since ?? + */ + public void unmarshal(java.nio.ByteBuffer buff) { + activeEmissionParameterIndex = (int) (buff.getShort() & 0xFFFF); + scanPattern = (int) (buff.getShort() & 0xFFFF); + beamCenterAzimuth = buff.getFloat(); + azimuthalBeamwidth = buff.getFloat(); + beamCenterDE = buff.getFloat(); + deBeamwidth = buff.getFloat(); + } // end of unmarshal method + + public void marshal(DataOutputStream dos) { + try { + dos.writeShort((short) activeEmissionParameterIndex); + dos.writeShort((short) scanPattern); + dos.writeFloat((float) beamCenterAzimuth); + dos.writeFloat((float) azimuthalBeamwidth); + dos.writeFloat((float) beamCenterDE); + dos.writeFloat((float) deBeamwidth); + } // end try + catch (Exception e) { + System.out.println(e); + } + } + + public void unmarshal(DataInputStream dis) { + try { + activeEmissionParameterIndex = (int) dis.readShort(); + scanPattern = (int) dis.readShort(); + beamCenterAzimuth = dis.readFloat(); + azimuthalBeamwidth = dis.readFloat(); + beamCenterDE = dis.readFloat(); + deBeamwidth = dis.readFloat(); + } // end try + catch (Exception e) { + System.out.println(e); + } + } // end of unmarshal method + + /* + * The equals method doesn't always work--mostly it works only on classes that consist only of primitives. Be careful. + */ + @Override + public boolean equals(Object obj) { + + if (this == obj) { + return true; + } + + if (obj == null) { + return false; + } + + if (getClass() != obj.getClass()) { + return false; + } + + return equalsImpl(obj); + } + + /** + * Compare all fields that contribute to the state, ignoring transient and + * static fields, for this and the supplied object + * + * @param obj the object to compare to + * @return true if the objects are equal, false otherwise. + */ + public boolean equalsImpl(Object obj) { + boolean ivarsEqual = true; + + if (!(obj instanceof AcousticBeamFundamentalParameter)) { + return false; + } + + final AcousticBeamFundamentalParameter rhs = (AcousticBeamFundamentalParameter) obj; + + if (!(activeEmissionParameterIndex == rhs.activeEmissionParameterIndex)) { + ivarsEqual = false; + } + if (!(scanPattern == rhs.scanPattern)) { + ivarsEqual = false; + } + if (!(beamCenterAzimuth == rhs.beamCenterAzimuth)) { + ivarsEqual = false; + } + if (!(azimuthalBeamwidth == rhs.azimuthalBeamwidth)) { + ivarsEqual = false; + } + if (!(beamCenterDE == rhs.beamCenterDE)) { + ivarsEqual = false; + } + if (!(deBeamwidth == rhs.deBeamwidth)) { + ivarsEqual = false; + } + + return ivarsEqual; + } +} // end of class diff --git a/src/main/java/edu/nps/moves/dis7/AcousticEmitterSystem.java b/src/main/java/edu/nps/moves/dis7/AcousticEmitterSystem.java new file mode 100644 index 0000000..b299f29 --- /dev/null +++ b/src/main/java/edu/nps/moves/dis7/AcousticEmitterSystem.java @@ -0,0 +1,178 @@ +package edu.nps.moves.dis7; + +import java.io.*; + +/** + * 5.3.35: Information about a particular UA emitter shall be represented using + * an Acoustic Emitter System record. This record shall consist of three fields: + * Acoustic Name, Function, and Acoustic ID Number + * + * Copyright (c) 2008-2016, MOVES Institute, Naval Postgraduate School. All + * rights reserved. This work is licensed under the BSD open source license, + * available at https://www.movesinstitute.org/licenses/bsd.html + * + * @author DMcG + */ +public class AcousticEmitterSystem extends Object implements Serializable { + + /** + * This field shall specify the system for a particular UA emitter. + */ + protected int acousticName; + + /** + * This field shall describe the function of the acoustic system. + */ + protected short acousticFunction; + + /** + * This field shall specify the UA emitter identification number relative to + * a specific system. This field shall be represented by an 8-bit unsigned + * integer. This field allows the differentiation of multiple systems on an + * entity, even if in some instances two or more of the systems may be + * identical UA emitter types. Numbering of systems shall begin with the + * value 1. + */ + protected short acousticID; + + /** + * Constructor + */ + public AcousticEmitterSystem() { + } + + public int getMarshalledSize() { + int marshalSize = 0; + + marshalSize = marshalSize + 2; // acousticName + marshalSize = marshalSize + 1; // acousticFunction + marshalSize = marshalSize + 1; // acousticID + + return marshalSize; + } + + public void setAcousticName(int pAcousticName) { + acousticName = pAcousticName; + } + + public int getAcousticName() { + return acousticName; + } + + public void setAcousticFunction(short pAcousticFunction) { + acousticFunction = pAcousticFunction; + } + + public short getAcousticFunction() { + return acousticFunction; + } + + public void setAcousticID(short pAcousticID) { + acousticID = pAcousticID; + } + + public short getAcousticID() { + return acousticID; + } + + /** + * Packs a Pdu into the ByteBuffer. + * + * @throws java.nio.BufferOverflowException if buff is too small + * @throws java.nio.ReadOnlyBufferException if buff is read only + * @see java.nio.ByteBuffer + * @param buff The ByteBuffer at the position to begin writing + * @since ?? + */ + public void marshal(java.nio.ByteBuffer buff) { + buff.putShort((short) acousticName); + buff.put((byte) acousticFunction); + buff.put((byte) acousticID); + } // end of marshal method + + /** + * Unpacks a Pdu from the underlying data. + * + * @throws java.nio.BufferUnderflowException if buff is too small + * @see java.nio.ByteBuffer + * @param buff The ByteBuffer at the position to begin reading + * @since ?? + */ + public void unmarshal(java.nio.ByteBuffer buff) { + acousticName = (int) (buff.getShort() & 0xFFFF); + acousticFunction = (short) (buff.get() & 0xFF); + acousticID = (short) (buff.get() & 0xFF); + } // end of unmarshal method + + public void marshal(DataOutputStream dos) { + try { + dos.writeShort((short) acousticName); + dos.writeByte((byte) acousticFunction); + dos.writeByte((byte) acousticID); + } // end try + catch (Exception e) { + System.out.println(e); + } + } + + public void unmarshal(DataInputStream dis) { + try { + acousticName = (int) dis.readShort(); + acousticFunction = (short) dis.readByte(); + acousticID = (short) dis.readByte(); + } // end try + catch (Exception e) { + System.out.println(e); + } + } // end of unmarshal method + + /* + * The equals method doesn't always work--mostly it works only on classes that consist only of primitives. Be careful. + */ + @Override + public boolean equals(Object obj) { + + if (this == obj) { + return true; + } + + if (obj == null) { + return false; + } + + if (getClass() != obj.getClass()) { + return false; + } + + return equalsImpl(obj); + } + + /** + * Compare all fields that contribute to the state, ignoring transient and + * static fields, for this and the supplied object + * + * @param obj the object to compare to + * @return true if the objects are equal, false otherwise. + */ + public boolean equalsImpl(Object obj) { + boolean ivarsEqual = true; + + if (!(obj instanceof AcousticEmitterSystem)) { + return false; + } + + final AcousticEmitterSystem rhs = (AcousticEmitterSystem) obj; + + if (!(acousticName == rhs.acousticName)) { + ivarsEqual = false; + } + if (!(acousticFunction == rhs.acousticFunction)) { + ivarsEqual = false; + } + if (!(acousticID == rhs.acousticID)) { + ivarsEqual = false; + } + + return ivarsEqual; + } +} // end of class diff --git a/src/main/java/edu/nps/moves/dis7/AcousticEmitterSystemData.java b/src/main/java/edu/nps/moves/dis7/AcousticEmitterSystemData.java new file mode 100644 index 0000000..6fd8eb2 --- /dev/null +++ b/src/main/java/edu/nps/moves/dis7/AcousticEmitterSystemData.java @@ -0,0 +1,269 @@ +package edu.nps.moves.dis7; + +import java.util.*; +import java.io.*; + +/** + * Used in the UA pdu; ties together an emmitter and a location. This requires + * manual cleanup; the beam data should not be attached to each emitter system. + * + * Copyright (c) 2008-2016, MOVES Institute, Naval Postgraduate School. All + * rights reserved. This work is licensed under the BSD open source license, + * available at https://www.movesinstitute.org/licenses/bsd.html + * + * @author DMcG + */ +public class AcousticEmitterSystemData extends Object implements Serializable { + + /** + * Length of emitter system data + */ + protected short emitterSystemDataLength; + + /** + * Number of beams + */ + protected short numberOfBeams; + + /** + * padding + */ + protected int pad2; + + /** + * This field shall specify the system for a particular UA emitter. + */ + protected AcousticEmitterSystem acousticEmitterSystem = new AcousticEmitterSystem(); + + /** + * Represents the location wrt the entity + */ + protected Vector3Float emitterLocation = new Vector3Float(); + + /** + * For each beam in numberOfBeams, an emitter system. This is not right--the + * beam records need to be at the end of the PDU, rather than attached to + * each system. + */ + protected List< AcousticBeamData> beamRecords = new ArrayList< AcousticBeamData>(); + + /** + * Constructor + */ + public AcousticEmitterSystemData() { + } + + public int getMarshalledSize() { + int marshalSize = 0; + + marshalSize = marshalSize + 1; // emitterSystemDataLength + marshalSize = marshalSize + 1; // numberOfBeams + marshalSize = marshalSize + 2; // pad2 + marshalSize = marshalSize + acousticEmitterSystem.getMarshalledSize(); // acousticEmitterSystem + marshalSize = marshalSize + emitterLocation.getMarshalledSize(); // emitterLocation + for (int idx = 0; idx < beamRecords.size(); idx++) { + AcousticBeamData listElement = beamRecords.get(idx); + marshalSize = marshalSize + listElement.getMarshalledSize(); + } + + return marshalSize; + } + + public void setEmitterSystemDataLength(short pEmitterSystemDataLength) { + emitterSystemDataLength = pEmitterSystemDataLength; + } + + public short getEmitterSystemDataLength() { + return emitterSystemDataLength; + } + + public short getNumberOfBeams() { + return (short) beamRecords.size(); + } + + /** + * Note that setting this value will not change the marshalled value. The + * list whose length this describes is used for that purpose. The + * getnumberOfBeams method will also be based on the actual list length + * rather than this value. The method is simply here for java bean + * completeness. + */ + public void setNumberOfBeams(short pNumberOfBeams) { + numberOfBeams = pNumberOfBeams; + } + + public void setPad2(int pPad2) { + pad2 = pPad2; + } + + public int getPad2() { + return pad2; + } + + public void setAcousticEmitterSystem(AcousticEmitterSystem pAcousticEmitterSystem) { + acousticEmitterSystem = pAcousticEmitterSystem; + } + + public AcousticEmitterSystem getAcousticEmitterSystem() { + return acousticEmitterSystem; + } + + public void setEmitterLocation(Vector3Float pEmitterLocation) { + emitterLocation = pEmitterLocation; + } + + public Vector3Float getEmitterLocation() { + return emitterLocation; + } + + public void setBeamRecords(List pBeamRecords) { + beamRecords = pBeamRecords; + } + + public List getBeamRecords() { + return beamRecords; + } + + /** + * Packs a Pdu into the ByteBuffer. + * + * @throws java.nio.BufferOverflowException if buff is too small + * @throws java.nio.ReadOnlyBufferException if buff is read only + * @see java.nio.ByteBuffer + * @param buff The ByteBuffer at the position to begin writing + * @since ?? + */ + public void marshal(java.nio.ByteBuffer buff) { + buff.put((byte) emitterSystemDataLength); + buff.put((byte) beamRecords.size()); + buff.putShort((short) pad2); + acousticEmitterSystem.marshal(buff); + emitterLocation.marshal(buff); + + for (int idx = 0; idx < beamRecords.size(); idx++) { + AcousticBeamData aAcousticBeamData = (AcousticBeamData) beamRecords.get(idx); + aAcousticBeamData.marshal(buff); + } // end of list marshalling + + } // end of marshal method + + /** + * Unpacks a Pdu from the underlying data. + * + * @throws java.nio.BufferUnderflowException if buff is too small + * @see java.nio.ByteBuffer + * @param buff The ByteBuffer at the position to begin reading + * @since ?? + */ + public void unmarshal(java.nio.ByteBuffer buff) { + emitterSystemDataLength = (short) (buff.get() & 0xFF); + numberOfBeams = (short) (buff.get() & 0xFF); + pad2 = (int) (buff.getShort() & 0xFFFF); + acousticEmitterSystem.unmarshal(buff); + emitterLocation.unmarshal(buff); + for (int idx = 0; idx < numberOfBeams; idx++) { + AcousticBeamData anX = new AcousticBeamData(); + anX.unmarshal(buff); + beamRecords.add(anX); + } + + } // end of unmarshal method + + public void marshal(DataOutputStream dos) { + try { + dos.writeByte((byte) emitterSystemDataLength); + dos.writeByte((byte) beamRecords.size()); + dos.writeShort((short) pad2); + acousticEmitterSystem.marshal(dos); + emitterLocation.marshal(dos); + + for (int idx = 0; idx < beamRecords.size(); idx++) { + AcousticBeamData aAcousticBeamData = (AcousticBeamData) beamRecords.get(idx); + aAcousticBeamData.marshal(dos); + } // end of list marshalling + } // end try + catch (Exception e) { + System.out.println(e); + } + } + + public void unmarshal(DataInputStream dis) { + try { + emitterSystemDataLength = (short) (dis.read() & 0xFF); + numberOfBeams = (short) (dis.read() & 0xFF); + pad2 = (int) (dis.readShort() & 0xFFFF); + acousticEmitterSystem.unmarshal(dis); + emitterLocation.unmarshal(dis); + for (int idx = 0; idx < numberOfBeams; idx++) { + AcousticBeamData anX = new AcousticBeamData(); + anX.unmarshal(dis); + beamRecords.add(anX); + } + } // end try + catch (Exception e) { + System.out.println(e); + } + } // end of unmarshal method + + /* + * The equals method doesn't always work--mostly it works only on classes that consist only of primitives. Be careful. + */ + @Override + public boolean equals(Object obj) { + + if (this == obj) { + return true; + } + + if (obj == null) { + return false; + } + + if (getClass() != obj.getClass()) { + return false; + } + + return equalsImpl(obj); + } + + /** + * Compare all fields that contribute to the state, ignoring transient and + * static fields, for this and the supplied object + * + * @param obj the object to compare to + * @return true if the objects are equal, false otherwise. + */ + public boolean equalsImpl(Object obj) { + boolean ivarsEqual = true; + + if (!(obj instanceof AcousticEmitterSystemData)) { + return false; + } + + final AcousticEmitterSystemData rhs = (AcousticEmitterSystemData) obj; + + if (!(emitterSystemDataLength == rhs.emitterSystemDataLength)) { + ivarsEqual = false; + } + if (!(numberOfBeams == rhs.numberOfBeams)) { + ivarsEqual = false; + } + if (!(pad2 == rhs.pad2)) { + ivarsEqual = false; + } + if (!(acousticEmitterSystem.equals(rhs.acousticEmitterSystem))) { + ivarsEqual = false; + } + if (!(emitterLocation.equals(rhs.emitterLocation))) { + ivarsEqual = false; + } + + for (int idx = 0; idx < beamRecords.size(); idx++) { + if (!(beamRecords.get(idx).equals(rhs.beamRecords.get(idx)))) { + ivarsEqual = false; + } + } + + return ivarsEqual; + } +} // end of class diff --git a/src/main/java/edu/nps/moves/dis7/ApaData.java b/src/main/java/edu/nps/moves/dis7/ApaData.java new file mode 100644 index 0000000..a23e807 --- /dev/null +++ b/src/main/java/edu/nps/moves/dis7/ApaData.java @@ -0,0 +1,149 @@ +package edu.nps.moves.dis7; + +import java.io.*; + +/** + * Used in UA PDU + * + * Copyright (c) 2008-2016, MOVES Institute, Naval Postgraduate School. All + * rights reserved. This work is licensed under the BSD open source license, + * available at https://www.movesinstitute.org/licenses/bsd.html + * + * @author DMcG + */ +public class ApaData extends Object implements Serializable { + + /** + * Index of APA parameter + */ + protected int parameterIndex; + + /** + * Index of APA parameter + */ + protected short parameterValue; + + /** + * Constructor + */ + public ApaData() { + } + + public int getMarshalledSize() { + int marshalSize = 0; + + marshalSize = marshalSize + 2; // parameterIndex + marshalSize = marshalSize + 2; // parameterValue + + return marshalSize; + } + + public void setParameterIndex(int pParameterIndex) { + parameterIndex = pParameterIndex; + } + + public int getParameterIndex() { + return parameterIndex; + } + + public void setParameterValue(short pParameterValue) { + parameterValue = pParameterValue; + } + + public short getParameterValue() { + return parameterValue; + } + + /** + * Packs a Pdu into the ByteBuffer. + * + * @throws java.nio.BufferOverflowException if buff is too small + * @throws java.nio.ReadOnlyBufferException if buff is read only + * @see java.nio.ByteBuffer + * @param buff The ByteBuffer at the position to begin writing + * @since ?? + */ + public void marshal(java.nio.ByteBuffer buff) { + buff.putShort((short) parameterIndex); + buff.putShort((short) parameterValue); + } // end of marshal method + + /** + * Unpacks a Pdu from the underlying data. + * + * @throws java.nio.BufferUnderflowException if buff is too small + * @see java.nio.ByteBuffer + * @param buff The ByteBuffer at the position to begin reading + * @since ?? + */ + public void unmarshal(java.nio.ByteBuffer buff) { + parameterIndex = (int) (buff.getShort() & 0xFFFF); + parameterValue = buff.getShort(); + } // end of unmarshal method + + public void marshal(DataOutputStream dos) { + try { + dos.writeShort((short) parameterIndex); + dos.writeShort((short) parameterValue); + } // end try + catch (Exception e) { + System.out.println(e); + } + } + + public void unmarshal(DataInputStream dis) { + try { + parameterIndex = (int) dis.readShort(); + parameterValue = dis.readShort(); + } // end try + catch (Exception e) { + System.out.println(e); + } + } // end of unmarshal method + /* + * The equals method doesn't always work--mostly it works only on classes that consist only of primitives. Be careful. + */ + @Override + public boolean equals(Object obj) { + + if (this == obj) { + return true; + } + + if (obj == null) { + return false; + } + + if (getClass() != obj.getClass()) { + return false; + } + + return equalsImpl(obj); + } + + /** + * Compare all fields that contribute to the state, ignoring transient and + * static fields, for this and the supplied object + * + * @param obj the object to compare to + * @return true if the objects are equal, false otherwise. + */ + public boolean equalsImpl(Object obj) { + boolean ivarsEqual = true; + + if (!(obj instanceof ApaData)) { + return false; + } + + final ApaData rhs = (ApaData) obj; + + if (!(parameterIndex == rhs.parameterIndex)) { + ivarsEqual = false; + } + if (!(parameterValue == rhs.parameterValue)) { + ivarsEqual = false; + } + + return ivarsEqual; + } +} // end of class diff --git a/src/main/java/edu/nps/moves/dis7/ShaftRPMs.java b/src/main/java/edu/nps/moves/dis7/ShaftRPMs.java new file mode 100644 index 0000000..caab0ce --- /dev/null +++ b/src/main/java/edu/nps/moves/dis7/ShaftRPMs.java @@ -0,0 +1,171 @@ +package edu.nps.moves.dis7; + +import java.io.*; + +/** + * Shaft RPMs, used in underwater acoustic clacluations. + * + * Copyright (c) 2008-2016, MOVES Institute, Naval Postgraduate School. All + * rights reserved. This work is licensed under the BSD open source license, + * available at https://www.movesinstitute.org/licenses/bsd.html + * + * @author DMcG + */ +public class ShaftRPMs extends Object implements Serializable { + + /** + * Current shaft RPMs + */ + protected short currentShaftRPMs; + + /** + * ordered shaft rpms + */ + protected short orderedShaftRPMs; + + /** + * rate of change of shaft RPMs + */ + protected float shaftRPMRateOfChange; + + /** + * Constructor + */ + public ShaftRPMs() { + } + + public int getMarshalledSize() { + int marshalSize = 0; + + marshalSize = marshalSize + 2; // currentShaftRPMs + marshalSize = marshalSize + 2; // orderedShaftRPMs + marshalSize = marshalSize + 4; // shaftRPMRateOfChange + + return marshalSize; + } + + public void setCurrentShaftRPMs(short pCurrentShaftRPMs) { + currentShaftRPMs = pCurrentShaftRPMs; + } + + public short getCurrentShaftRPMs() { + return currentShaftRPMs; + } + + public void setOrderedShaftRPMs(short pOrderedShaftRPMs) { + orderedShaftRPMs = pOrderedShaftRPMs; + } + + public short getOrderedShaftRPMs() { + return orderedShaftRPMs; + } + + public void setShaftRPMRateOfChange(float pShaftRPMRateOfChange) { + shaftRPMRateOfChange = pShaftRPMRateOfChange; + } + + public float getShaftRPMRateOfChange() { + return shaftRPMRateOfChange; + } + + /** + * Packs a Pdu into the ByteBuffer. + * + * @throws java.nio.BufferOverflowException if buff is too small + * @throws java.nio.ReadOnlyBufferException if buff is read only + * @see java.nio.ByteBuffer + * @param buff The ByteBuffer at the position to begin writing + * @since ?? + */ + public void marshal(java.nio.ByteBuffer buff) { + buff.putShort((short) currentShaftRPMs); + buff.putShort((short) orderedShaftRPMs); + buff.putFloat((float) shaftRPMRateOfChange); + } // end of marshal method + + /** + * Unpacks a Pdu from the underlying data. + * + * @throws java.nio.BufferUnderflowException if buff is too small + * @see java.nio.ByteBuffer + * @param buff The ByteBuffer at the position to begin reading + * @since ?? + */ + public void unmarshal(java.nio.ByteBuffer buff) { + currentShaftRPMs = buff.getShort(); + orderedShaftRPMs = buff.getShort(); + shaftRPMRateOfChange = buff.getFloat(); + } // end of unmarshal method + + public void marshal(DataOutputStream dos) { + try { + dos.writeShort(currentShaftRPMs); + dos.writeShort(orderedShaftRPMs); + dos.writeFloat(shaftRPMRateOfChange); + } // end try + catch (Exception e) { + System.out.println(e); + } + } // end of marshal method + + public void unmarshal(DataInputStream dis) { + try { + currentShaftRPMs = dis.readShort(); + orderedShaftRPMs = dis.readShort(); + shaftRPMRateOfChange = dis.readFloat(); + } // end try + catch (Exception e) { + System.out.println(e); + } + } // end of unmarshal method + + /* + * The equals method doesn't always work--mostly it works only on classes that consist only of primitives. Be careful. + */ + @Override + public boolean equals(Object obj) { + + if (this == obj) { + return true; + } + + if (obj == null) { + return false; + } + + if (getClass() != obj.getClass()) { + return false; + } + + return equalsImpl(obj); + } + + /** + * Compare all fields that contribute to the state, ignoring transient and + * static fields, for this and the supplied object + * + * @param obj the object to compare to + * @return true if the objects are equal, false otherwise. + */ + public boolean equalsImpl(Object obj) { + boolean ivarsEqual = true; + + if (!(obj instanceof ShaftRPMs)) { + return false; + } + + final ShaftRPMs rhs = (ShaftRPMs) obj; + + if (!(currentShaftRPMs == rhs.currentShaftRPMs)) { + ivarsEqual = false; + } + if (!(orderedShaftRPMs == rhs.orderedShaftRPMs)) { + ivarsEqual = false; + } + if (!(shaftRPMRateOfChange == rhs.shaftRPMRateOfChange)) { + ivarsEqual = false; + } + + return ivarsEqual; + } +} // end of class diff --git a/src/main/java/edu/nps/moves/dis7/UaPdu.java b/src/main/java/edu/nps/moves/dis7/UaPdu.java index 55dbb1e..6cc2207 100644 --- a/src/main/java/edu/nps/moves/dis7/UaPdu.java +++ b/src/main/java/edu/nps/moves/dis7/UaPdu.java @@ -72,17 +72,17 @@ public class UaPdu extends DistributedEmissionsFamilyPdu implements Serializable protected short numberOfUAEmitterSystems; /** - * shaft RPM values. THIS IS WRONG. It has the wrong class in the list. + * shaft RPM values. */ - protected List< Vector3Float> shaftRPMs = new ArrayList< Vector3Float>(); + protected List< ShaftRPMs> shaftRPMs = new ArrayList< ShaftRPMs>(); /** - * apaData. THIS IS WRONG. It has the worng class in the list. + * apaData. */ - protected List< Vector3Float> apaData = new ArrayList< Vector3Float>(); + protected List< ApaData> apaData = new ArrayList< ApaData>(); /** - * THIS IS WRONG. It has the wrong class in the list. + * THIS IS WRONG. */ - protected List< Vector3Float> emitterSystems = new ArrayList< Vector3Float>(); + protected List< AcousticEmitterSystemData> emitterSystems = new ArrayList< AcousticEmitterSystemData>(); /** * Constructor @@ -105,15 +105,15 @@ public int getMarshalledSize() { marshalSize = marshalSize + 1; // numberOfAPAs marshalSize = marshalSize + 1; // numberOfUAEmitterSystems for (int idx = 0; idx < shaftRPMs.size(); idx++) { - Vector3Float listElement = shaftRPMs.get(idx); + ShaftRPMs listElement = shaftRPMs.get(idx); marshalSize = marshalSize + listElement.getMarshalledSize(); } for (int idx = 0; idx < apaData.size(); idx++) { - Vector3Float listElement = apaData.get(idx); + ApaData listElement = apaData.get(idx); marshalSize = marshalSize + listElement.getMarshalledSize(); } for (int idx = 0; idx < emitterSystems.size(); idx++) { - Vector3Float listElement = emitterSystems.get(idx); + AcousticEmitterSystemData listElement = emitterSystems.get(idx); marshalSize = marshalSize + listElement.getMarshalledSize(); } @@ -213,27 +213,27 @@ public void setNumberOfUAEmitterSystems(short pNumberOfUAEmitterSystems) { numberOfUAEmitterSystems = pNumberOfUAEmitterSystems; } - public void setShaftRPMs(List pShaftRPMs) { + public void setShaftRPMs(List pShaftRPMs) { shaftRPMs = pShaftRPMs; } - public List getShaftRPMs() { + public List getShaftRPMs() { return shaftRPMs; } - public void setApaData(List pApaData) { + public void setApaData(List pApaData) { apaData = pApaData; } - public List getApaData() { + public List getApaData() { return apaData; } - public void setEmitterSystems(List pEmitterSystems) { + public void setEmitterSystems(List pEmitterSystems) { emitterSystems = pEmitterSystems; } - public List getEmitterSystems() { + public List getEmitterSystems() { return emitterSystems; } @@ -251,17 +251,17 @@ public void marshal(DataOutputStream dos) { dos.writeByte((byte) emitterSystems.size()); for (int idx = 0; idx < shaftRPMs.size(); idx++) { - Vector3Float aVector3Float = shaftRPMs.get(idx); - aVector3Float.marshal(dos); + ShaftRPMs aShaftRPMs = shaftRPMs.get(idx); + aShaftRPMs.marshal(dos); } // end of list marshalling for (int idx = 0; idx < apaData.size(); idx++) { - Vector3Float aVector3Float = apaData.get(idx); - aVector3Float.marshal(dos); + ApaData aApaData = apaData.get(idx); + aApaData.marshal(dos); } // end of list marshalling for (int idx = 0; idx < emitterSystems.size(); idx++) { - Vector3Float aVector3Float = emitterSystems.get(idx); + AcousticEmitterSystemData aVector3Float = emitterSystems.get(idx); aVector3Float.marshal(dos); } // end of list marshalling @@ -285,19 +285,19 @@ public void unmarshal(DataInputStream dis) { numberOfAPAs = (short) dis.readUnsignedByte(); numberOfUAEmitterSystems = (short) dis.readUnsignedByte(); for (int idx = 0; idx < numberOfShafts; idx++) { - Vector3Float anX = new Vector3Float(); + ShaftRPMs anX = new ShaftRPMs(); anX.unmarshal(dis); shaftRPMs.add(anX); } for (int idx = 0; idx < numberOfAPAs; idx++) { - Vector3Float anX = new Vector3Float(); + ApaData anX = new ApaData(); anX.unmarshal(dis); apaData.add(anX); } for (int idx = 0; idx < numberOfUAEmitterSystems; idx++) { - Vector3Float anX = new Vector3Float(); + AcousticEmitterSystemData anX = new AcousticEmitterSystemData(); anX.unmarshal(dis); emitterSystems.add(anX); } @@ -330,17 +330,17 @@ public void marshal(java.nio.ByteBuffer buff) { buff.put((byte) emitterSystems.size()); for (int idx = 0; idx < shaftRPMs.size(); idx++) { - Vector3Float aVector3Float = (Vector3Float) shaftRPMs.get(idx); - aVector3Float.marshal(buff); + ShaftRPMs aShaftRPMs = (ShaftRPMs) shaftRPMs.get(idx); + aShaftRPMs.marshal(buff); } // end of list marshalling for (int idx = 0; idx < apaData.size(); idx++) { - Vector3Float aVector3Float = (Vector3Float) apaData.get(idx); - aVector3Float.marshal(buff); + ApaData aApaData = (ApaData) apaData.get(idx); + aApaData.marshal(buff); } // end of list marshalling for (int idx = 0; idx < emitterSystems.size(); idx++) { - Vector3Float aVector3Float = (Vector3Float) emitterSystems.get(idx); + AcousticEmitterSystemData aVector3Float = (AcousticEmitterSystemData) emitterSystems.get(idx); aVector3Float.marshal(buff); } // end of list marshalling @@ -367,19 +367,19 @@ public void unmarshal(java.nio.ByteBuffer buff) { numberOfAPAs = (short) (buff.get() & 0xFF); numberOfUAEmitterSystems = (short) (buff.get() & 0xFF); for (int idx = 0; idx < numberOfShafts; idx++) { - Vector3Float anX = new Vector3Float(); + ShaftRPMs anX = new ShaftRPMs(); anX.unmarshal(buff); shaftRPMs.add(anX); } for (int idx = 0; idx < numberOfAPAs; idx++) { - Vector3Float anX = new Vector3Float(); + ApaData anX = new ApaData(); anX.unmarshal(buff); apaData.add(anX); } for (int idx = 0; idx < numberOfUAEmitterSystems; idx++) { - Vector3Float anX = new Vector3Float(); + AcousticEmitterSystemData anX = new AcousticEmitterSystemData(); anX.unmarshal(buff); emitterSystems.add(anX); } diff --git a/src/test/java/edu/nps/moves/dis7/UaPduTest.java b/src/test/java/edu/nps/moves/dis7/UaPduTest.java new file mode 100644 index 0000000..51f0276 --- /dev/null +++ b/src/test/java/edu/nps/moves/dis7/UaPduTest.java @@ -0,0 +1,91 @@ +package edu.nps.moves.dis7; + +import java.io.IOException; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; + +/** + * + * @author fo + */ +public class UaPduTest { + + public UaPduTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + @Test + public void marshal() { + UaPdu uapdu = new UaPdu(); + + byte[] buffer = uapdu.marshal(); + + assertEquals(buffer.length, uapdu.getLength()); + } + + @Test + public void unmarshal() throws IOException { + PduFactory factory = new PduFactory(); + Pdu pdu = factory.createPdu(edu.nps.moves.dis7.PduFileLoader.load("UAPdu.raw")); + // Header + assertEquals(7, pdu.getProtocolVersion()); + assertEquals(1, pdu.getExerciseID()); + assertEquals(29, pdu.getPduType()); + assertEquals(6, pdu.getProtocolFamily()); + assertEquals(56, pdu.getLength()); + assertEquals(12, pdu.getPduStatus()); + assertEquals(0, pdu.getPadding()); + + UaPdu uaPdu = (UaPdu) pdu; + + //EmittingEntityID + assertEquals(1, uaPdu.getEmittingEntityID().getSiteID()); + assertEquals(260, uaPdu.getEmittingEntityID().getApplicationID()); + assertEquals(55, uaPdu.getEmittingEntityID().getEntityID()); + + //Apa + assertEquals(1, uaPdu.getNumberOfAPAs()); + assertEquals(54, uaPdu.getApaData().get(0).getParameterIndex()); + assertEquals(55, uaPdu.getApaData().get(0).getParameterValue()); + + + + + + //EmitterSystems + + + assertEquals(1, uaPdu.getNumberOfUAEmitterSystems()); + assertEquals(0, uaPdu.getEmitterSystems().get(0).getEmitterSystemDataLength()); + assertEquals(0, uaPdu.getEmitterSystems().get(0).getBeamRecords().size()); + assertEquals(0, uaPdu.getEmitterSystems().get(0).getNumberOfBeams()); + //Relative position + assertEquals(1, uaPdu.getEmitterSystems().get(0).getEmitterLocation().getX(), 0.001); + assertEquals(1, uaPdu.getEmitterSystems().get(0).getEmitterLocation().getY(), 0.001); + assertEquals(1, uaPdu.getEmitterSystems().get(0).getEmitterLocation().getZ(), 0.001); + + //EventId + assertEquals(0, uaPdu.getEventID().getSimulationAddress().getSite()); + assertEquals(0, uaPdu.getEventID().getSimulationAddress().getApplication()); + assertEquals(0, uaPdu.getEventID().getEventNumber()); + } +} diff --git a/src/test/resources/edu/nps/moves/dis7/UAPdu.raw b/src/test/resources/edu/nps/moves/dis7/UAPdu.raw new file mode 100644 index 0000000..505cae6 Binary files /dev/null and b/src/test/resources/edu/nps/moves/dis7/UAPdu.raw differ