diff --git a/src/main/java/edu/nps/moves/dis7/ElectronicEmissionsPdu.java b/src/main/java/edu/nps/moves/dis7/ElectronicEmissionsPdu.java index 2f75b69c..6a0f4c2f 100644 --- a/src/main/java/edu/nps/moves/dis7/ElectronicEmissionsPdu.java +++ b/src/main/java/edu/nps/moves/dis7/ElectronicEmissionsPdu.java @@ -1,327 +1,351 @@ package edu.nps.moves.dis7; -import java.util.*; -import java.io.*; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.Serializable; /** - * Section 5.3.7.1. Information about active electronic warfare (EW) emissions and active EW countermeasures shall be communicated using an Electromagnetic Emission PDU. NOT COMPLETE - * - * 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 + * Section 5.3.7.1. Information about active electronic warfare (EW) emissions and active EW countermeasures shall be communicated using an + * Electromagnetic Emission PDU. NOT COMPLETE * + * 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 ElectronicEmissionsPdu extends DistributedEmissionsFamilyPdu implements Serializable { - /** ID of the entity emitting */ - protected EntityID emittingEntityID = new EntityID(); - - /** ID of event */ - protected EventIdentifier eventID = new EventIdentifier(); + /** ID of the entity emitting */ + protected EntityID emittingEntityID = new EntityID(); - /** This field shall be used to indicate if the data in the PDU represents a state update or just data that has changed since issuance of the last Electromagnetic Emission PDU [relative to the identified entity and emission system(s)]. */ - protected short stateUpdateIndicator; + /** ID of event */ + protected EventIdentifier eventID = new EventIdentifier(); - /** This field shall specify the number of emission systems being described in the current PDU. */ - protected short numberOfSystems; + /** + * This field shall be used to indicate if the data in the PDU represents a state update or just data that has changed since issuance of + * the last Electromagnetic Emission PDU [relative to the identified entity and emission system(s)]. + */ + protected short stateUpdateIndicator; - /** padding */ - protected int paddingForEmissionsPdu; + /** This field shall specify the number of emission systems being described in the current PDU. */ + protected short numberOfSystems; - /** this field shall specify the length of this emitter system's data in 32-bit words. */ - protected short systemDataLength; + /** padding */ + protected int paddingForEmissionsPdu; - /** the number of beams being described in the current PDU for the emitter system being described. */ - protected short numberOfBeams; + /** this field shall specify the length of this emitter system's data in 32-bit words. */ + protected short systemDataLength; - /** information about a particular emitter system and shall be represented by an Emitter System record (see 6.2.23). */ - protected EmitterSystem emitterSystem = new EmitterSystem(); + /** the number of beams being described in the current PDU for the emitter system being described. */ + protected short numberOfBeams; - /** the location of the antenna beam source with respect to the emitting entity's coordinate system. This location shall be the origin of the emitter coordinate system that shall have the same orientation as the entity coordinate system. This field shall be represented by an Entity Coordinate Vector record see 6.2.95 */ - protected Vector3Float location = new Vector3Float(); + /** information about a particular emitter system and shall be represented by an Emitter System record (see 6.2.23). */ + protected EmitterSystem emitterSystem = new EmitterSystem(); - /** Electronic emmissions systems THIS IS WRONG. It has the WRONG class type and will cause problems in any marshalling. */ - protected List< Vector3Float > systems = new ArrayList< Vector3Float >(); + /** + * the location of the antenna beam source with respect to the emitting entity's coordinate system. This location shall be the origin of + * the emitter coordinate system that shall have the same orientation as the entity coordinate system. This field shall be represented + * by an Entity Coordinate Vector record see 6.2.95 + */ + protected Vector3Float location = new Vector3Float(); -/** Constructor */ - public ElectronicEmissionsPdu() - { - setPduType( (short)23 ); - setPaddingForEmissionsPdu( (int)0 ); - } + /** Electronic emmissions systems */ + protected ElectronicEmissisionBeamData electronicEmissisionBeamData = new ElectronicEmissisionBeamData(); -public int getMarshalledSize() -{ - int marshalSize = 0; - - marshalSize = super.getMarshalledSize(); - marshalSize = marshalSize + emittingEntityID.getMarshalledSize(); // emittingEntityID - marshalSize = marshalSize + eventID.getMarshalledSize(); // eventID - marshalSize = marshalSize + 1; // stateUpdateIndicator - marshalSize = marshalSize + 1; // numberOfSystems - marshalSize = marshalSize + 2; // paddingForEmissionsPdu - marshalSize = marshalSize + 1; // systemDataLength - marshalSize = marshalSize + 1; // numberOfBeams - marshalSize = marshalSize + emitterSystem.getMarshalledSize(); // emitterSystem - marshalSize = marshalSize + location.getMarshalledSize(); // location - for(int idx=0; idx < systems.size(); idx++) - { - Vector3Float listElement = systems.get(idx); - marshalSize = marshalSize + listElement.getMarshalledSize(); - } - - return marshalSize; -} - - -public void setEmittingEntityID(EntityID pEmittingEntityID) -{ emittingEntityID = pEmittingEntityID; -} - -public EntityID getEmittingEntityID() -{ return emittingEntityID; -} - -public void setEventID(EventIdentifier pEventID) -{ eventID = pEventID; -} - -public EventIdentifier getEventID() -{ return eventID; -} - -public void setStateUpdateIndicator(short pStateUpdateIndicator) -{ stateUpdateIndicator = pStateUpdateIndicator; -} - -public short getStateUpdateIndicator() -{ return stateUpdateIndicator; -} - -public short getNumberOfSystems() -{ return (short)systems.size(); -} - -/** Note that setting this value will not change the marshalled value. The list whose length this describes is used for that purpose. - * The getnumberOfSystems 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 setNumberOfSystems(short pNumberOfSystems) -{ numberOfSystems = pNumberOfSystems; -} + /** Constructor */ + public ElectronicEmissionsPdu() + { + setPduType((short) 23); + setPaddingForEmissionsPdu((int) 0); + } -public void setPaddingForEmissionsPdu(int pPaddingForEmissionsPdu) -{ paddingForEmissionsPdu = pPaddingForEmissionsPdu; -} + public int getMarshalledSize() + { + int marshalSize = 0; + + marshalSize = super.getMarshalledSize(); + marshalSize = marshalSize + emittingEntityID.getMarshalledSize(); // emittingEntityID + marshalSize = marshalSize + eventID.getMarshalledSize(); // eventID + marshalSize = marshalSize + 1; // stateUpdateIndicator + marshalSize = marshalSize + 1; // numberOfSystems + marshalSize = marshalSize + 2; // paddingForEmissionsPdu + marshalSize = marshalSize + 1; // systemDataLength + marshalSize = marshalSize + 1; // numberOfBeams + marshalSize = marshalSize + 2; // paddingForEmissionsPdu + marshalSize = marshalSize + emitterSystem.getMarshalledSize(); // emitterSystem + marshalSize = marshalSize + location.getMarshalledSize(); // location + marshalSize = marshalSize + electronicEmissisionBeamData.getMarshalledSize(); // electronicEmissisionBeamData + + return marshalSize; + } -public int getPaddingForEmissionsPdu() -{ return paddingForEmissionsPdu; -} + public EntityID getEmittingEntityID() + { + return emittingEntityID; + } -public void setSystemDataLength(short pSystemDataLength) -{ systemDataLength = pSystemDataLength; -} + public void setEmittingEntityID(EntityID pEmittingEntityID) + { + emittingEntityID = pEmittingEntityID; + } -public short getSystemDataLength() -{ return systemDataLength; -} + public EventIdentifier getEventID() + { + return eventID; + } -public void setNumberOfBeams(short pNumberOfBeams) -{ numberOfBeams = pNumberOfBeams; -} + public void setEventID(EventIdentifier pEventID) + { + eventID = pEventID; + } -public short getNumberOfBeams() -{ return numberOfBeams; -} + public short getStateUpdateIndicator() + { + return stateUpdateIndicator; + } -public void setEmitterSystem(EmitterSystem pEmitterSystem) -{ emitterSystem = pEmitterSystem; -} + public void setStateUpdateIndicator(short pStateUpdateIndicator) + { + stateUpdateIndicator = pStateUpdateIndicator; + } -public EmitterSystem getEmitterSystem() -{ return emitterSystem; -} + public short getNumberOfSystems() + { + return numberOfSystems; + } -public void setLocation(Vector3Float pLocation) -{ location = pLocation; -} + public ElectronicEmissisionBeamData getElectronicEmissionBeamData() + { + return electronicEmissisionBeamData; + } -public Vector3Float getLocation() -{ return location; -} + public void setElectronicEmissionBeamData(ElectronicEmissisionBeamData electronicEmissisionBeamData) + { + this.electronicEmissisionBeamData = electronicEmissisionBeamData; + } -public void setSystems(List pSystems) -{ systems = pSystems; -} + /** + * Note that setting this value will not change the marshalled value. The list whose length this describes is used for that purpose. The + * getnumberOfSystems 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 setNumberOfSystems(short pNumberOfSystems) + { + numberOfSystems = pNumberOfSystems; + } -public List getSystems() -{ return systems; } + public int getPaddingForEmissionsPdu() + { + return paddingForEmissionsPdu; + } + public void setPaddingForEmissionsPdu(int pPaddingForEmissionsPdu) + { + paddingForEmissionsPdu = pPaddingForEmissionsPdu; + } -public void marshal(DataOutputStream dos) -{ - super.marshal(dos); - try + public short getSystemDataLength() { - emittingEntityID.marshal(dos); - eventID.marshal(dos); - dos.writeByte( (byte)stateUpdateIndicator); - dos.writeByte( (byte)systems.size()); - dos.writeShort( (short)paddingForEmissionsPdu); - dos.writeByte( (byte)systemDataLength); - dos.writeByte( (byte)numberOfBeams); - emitterSystem.marshal(dos); - location.marshal(dos); - - for(int idx = 0; idx < systems.size(); idx++) - { - Vector3Float aVector3Float = systems.get(idx); - aVector3Float.marshal(dos); - } // end of list marshalling - - } // end try - catch(Exception e) - { - System.out.println(e);} - } // end of marshal method + return systemDataLength; + } -public void unmarshal(DataInputStream dis) -{ - super.unmarshal(dis); + public void setSystemDataLength(short pSystemDataLength) + { + systemDataLength = pSystemDataLength; + } - try + public short getNumberOfBeams() { - emittingEntityID.unmarshal(dis); - eventID.unmarshal(dis); - stateUpdateIndicator = (short)dis.readUnsignedByte(); - numberOfSystems = (short)dis.readUnsignedByte(); - paddingForEmissionsPdu = (int)dis.readUnsignedShort(); - systemDataLength = (short)dis.readUnsignedByte(); - numberOfBeams = (short)dis.readUnsignedByte(); - emitterSystem.unmarshal(dis); - location.unmarshal(dis); - for(int idx = 0; idx < numberOfSystems; idx++) - { - Vector3Float anX = new Vector3Float(); - anX.unmarshal(dis); - systems.add(anX); - } - - } // end try - catch(Exception e) - { - System.out.println(e); + return numberOfBeams; } - } // end of unmarshal method + public void setNumberOfBeams(short pNumberOfBeams) + { + numberOfBeams = pNumberOfBeams; + } -/** - * 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) -{ - super.marshal(buff); - emittingEntityID.marshal(buff); - eventID.marshal(buff); - buff.put( (byte)stateUpdateIndicator); - buff.put( (byte)systems.size()); - buff.putShort( (short)paddingForEmissionsPdu); - buff.put( (byte)systemDataLength); - buff.put( (byte)numberOfBeams); - emitterSystem.marshal(buff); - location.marshal(buff); - - for(int idx = 0; idx < systems.size(); idx++) - { - Vector3Float aVector3Float = (Vector3Float)systems.get(idx); - aVector3Float.marshal(buff); - } // end of list marshalling + public EmitterSystem getEmitterSystem() + { + return emitterSystem; + } - } // end of marshal method + public void setEmitterSystem(EmitterSystem pEmitterSystem) + { + emitterSystem = pEmitterSystem; + } -/** - * 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) -{ - super.unmarshal(buff); - - emittingEntityID.unmarshal(buff); - eventID.unmarshal(buff); - stateUpdateIndicator = (short)(buff.get() & 0xFF); - numberOfSystems = (short)(buff.get() & 0xFF); - paddingForEmissionsPdu = (int)(buff.getShort() & 0xFFFF); - systemDataLength = (short)(buff.get() & 0xFF); - numberOfBeams = (short)(buff.get() & 0xFF); - emitterSystem.unmarshal(buff); - location.unmarshal(buff); - for(int idx = 0; idx < numberOfSystems; idx++) - { - Vector3Float anX = new Vector3Float(); - anX.unmarshal(buff); - systems.add(anX); - } - - } // 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; + public Vector3Float getLocation() + { + return location; } - if(obj == null){ - return false; + public void setLocation(Vector3Float pLocation) + { + location = pLocation; } - if(getClass() != obj.getClass()) - return false; - return equalsImpl(obj); - } + public void marshal(DataOutputStream dos) + { + super.marshal(dos); + try { + emittingEntityID.marshal(dos); + eventID.marshal(dos); + dos.writeByte((byte) stateUpdateIndicator); + dos.writeByte((byte) numberOfSystems); + dos.writeShort((short) paddingForEmissionsPdu); + dos.writeByte((byte) systemDataLength); + dos.writeByte((byte) numberOfBeams); + emitterSystem.marshal(dos); + location.marshal(dos); + electronicEmissisionBeamData.marshal(dos); + + } // end try + catch (Exception e) { + System.out.println(e); + } + } // end of marshal method + + public void unmarshal(DataInputStream dis) + { + super.unmarshal(dis); + + try { + emittingEntityID.unmarshal(dis); + eventID.unmarshal(dis); + stateUpdateIndicator = (short) dis.readUnsignedByte(); + numberOfSystems = (short) dis.readUnsignedByte(); + paddingForEmissionsPdu = (int) dis.readUnsignedShort(); + systemDataLength = (short) dis.readUnsignedByte(); + numberOfBeams = (short) dis.readUnsignedByte(); + emitterSystem.unmarshal(dis); + location.unmarshal(dis); + electronicEmissisionBeamData.unmarshal(dis); + + } // end try + catch (Exception e) { + System.out.println(e); + } + } // end of unmarshal method + + + /** + * Packs a Pdu into the ByteBuffer. + * @param buff The ByteBuffer at the position to begin writing + * @throws java.nio.BufferOverflowException if buff is too small + * @throws java.nio.ReadOnlyBufferException if buff is read only + * @see java.nio.ByteBuffer + * @since ?? + */ + public void marshal(java.nio.ByteBuffer buff) + { + super.marshal(buff); + emittingEntityID.marshal(buff); + eventID.marshal(buff); + buff.put((byte) stateUpdateIndicator); + buff.put((byte) numberOfSystems); + buff.putShort((short) paddingForEmissionsPdu); + buff.put((byte) systemDataLength); + buff.put((byte) numberOfBeams); + emitterSystem.marshal(buff); + location.marshal(buff); + electronicEmissisionBeamData.marshal(buff); -@Override - public boolean equalsImpl(Object obj) - { - boolean ivarsEqual = true; + } // end of marshal method - if(!(obj instanceof ElectronicEmissionsPdu)) - return false; + /** + * Unpacks a Pdu from the underlying data. + * @param buff The ByteBuffer at the position to begin reading + * @throws java.nio.BufferUnderflowException if buff is too small + * @see java.nio.ByteBuffer + * @since ?? + */ + public void unmarshal(java.nio.ByteBuffer buff) + { + super.unmarshal(buff); + + emittingEntityID.unmarshal(buff); + eventID.unmarshal(buff); + stateUpdateIndicator = (short) ( buff.get() & 0xFF ); + numberOfSystems = (short) ( buff.get() & 0xFF ); + paddingForEmissionsPdu = (int) ( buff.getShort() & 0xFFFF ); + systemDataLength = (short) ( buff.get() & 0xFF ); + numberOfBeams = (short) ( buff.get() & 0xFF ); + buff.getShort(); // remove padding + emitterSystem.unmarshal(buff); + location.unmarshal(buff); + electronicEmissisionBeamData.unmarshal(buff); + + } // 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) + { - final ElectronicEmissionsPdu rhs = (ElectronicEmissionsPdu)obj; + if (this == obj) { + return true; + } - if( ! (emittingEntityID.equals( rhs.emittingEntityID) )) ivarsEqual = false; - if( ! (eventID.equals( rhs.eventID) )) ivarsEqual = false; - if( ! (stateUpdateIndicator == rhs.stateUpdateIndicator)) ivarsEqual = false; - if( ! (numberOfSystems == rhs.numberOfSystems)) ivarsEqual = false; - if( ! (paddingForEmissionsPdu == rhs.paddingForEmissionsPdu)) ivarsEqual = false; - if( ! (systemDataLength == rhs.systemDataLength)) ivarsEqual = false; - if( ! (numberOfBeams == rhs.numberOfBeams)) ivarsEqual = false; - if( ! (emitterSystem.equals( rhs.emitterSystem) )) ivarsEqual = false; - if( ! (location.equals( rhs.location) )) ivarsEqual = false; + if (obj == null) { + return false; + } - for(int idx = 0; idx < systems.size(); idx++) - { - if( ! ( systems.get(idx).equals(rhs.systems.get(idx)))) ivarsEqual = false; - } + if (getClass() != obj.getClass()) { + return false; + } + return equalsImpl(obj); + } - return ivarsEqual && super.equalsImpl(rhs); - } + @Override + public boolean equalsImpl(Object obj) + { + boolean ivarsEqual = true; + + if (!( obj instanceof ElectronicEmissionsPdu )) { + return false; + } + + final ElectronicEmissionsPdu rhs = (ElectronicEmissionsPdu) obj; + + if (!( emittingEntityID.equals(rhs.emittingEntityID) )) { + ivarsEqual = false; + } + if (!( eventID.equals(rhs.eventID) )) { + ivarsEqual = false; + } + if (!( stateUpdateIndicator == rhs.stateUpdateIndicator )) { + ivarsEqual = false; + } + if (!( numberOfSystems == rhs.numberOfSystems )) { + ivarsEqual = false; + } + if (!( paddingForEmissionsPdu == rhs.paddingForEmissionsPdu )) { + ivarsEqual = false; + } + if (!( systemDataLength == rhs.systemDataLength )) { + ivarsEqual = false; + } + if (!( numberOfBeams == rhs.numberOfBeams )) { + ivarsEqual = false; + } + if (!( emitterSystem.equals(rhs.emitterSystem) )) { + ivarsEqual = false; + } + if (!( location.equals(rhs.location) )) { + ivarsEqual = false; + } + if (!( electronicEmissisionBeamData.equals(rhs.electronicEmissisionBeamData) )) { + ivarsEqual = false; + } + + + + return ivarsEqual && super.equalsImpl(rhs); + } } // end of class diff --git a/src/main/java/edu/nps/moves/dis7/ElectronicEmissisionBeamData.java b/src/main/java/edu/nps/moves/dis7/ElectronicEmissisionBeamData.java new file mode 100644 index 00000000..3da2e0aa --- /dev/null +++ b/src/main/java/edu/nps/moves/dis7/ElectronicEmissisionBeamData.java @@ -0,0 +1,339 @@ +package edu.nps.moves.dis7; + + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.Serializable; +import java.util.Objects; + + +/** + * This field shall specify information about a particular active electronicEmissisionBeamData. Section 7.6.2. + * + * 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 ElectronicEmissisionBeamData extends Object implements Serializable +{ + /** Specifies the length of this electronicEmissisionBeamData's data, 8 bit unsigned int */ + protected short beamDataLength; + + /** unique electronicEmissisionBeamData number, 8 bit unsigned int */ + protected short beamNumber; + + /** + * Used in conjunction with the Emitter Name field as a database primary key, this field shall specify a number by which receiving + * entities reference stored database parameters required to regenerate the electronicEmissisionBeamData., 16 bit unsigned int + */ + protected int beamParameterIndex; + + /** + * specify dynamic parameters of the emitter and shall be represented by an EE Fundamental Parameter Data record (see 6.2.22). + */ + protected EEFundamentalParameterData fundamentalParameterData = new EEFundamentalParameterData(); + + /** + * specify parameters of the electronicEmissisionBeamData and shall be represented by a ElectronicEmissisionBeamData Data record (see 6.2.11) + */ + protected BeamData beamData = new BeamData(); + + /** + * specify the intended use of a particular electronicEmissisionBeamData. Typical functions include search, acquisition, tracking, illumination, jamming, and so + * on. This field is intended to help receiving entities determine the emission mode represented by the electronicEmissisionBeamData. This field shall be + * represented by an 8-bit enumeration + */ + protected short beamFunction; + + /** + * This field, in conjunction with the High-Density Track/Jam field, shall identify, for the current PDU and emitter electronicEmissisionBeamData, the number of + * entities tracked or under illumination (as appropriate for an emitter electronicEmissisionBeamData’s function) or the number of targeted emitter beams (for + * jammers). This field shall be represented by an 8-bit unsigned integer. + */ + protected short numberOfTargets; + + /** + * This field shall be used to indicate that receiving simulation applications can assume that all viable targets in the field of regard + * specified by the electronicEmissisionBeamData data are being tracked or jammed. This field shall be represented by an 8-bit enumeration + */ + protected short highDensityTrackJam; + + /** + * This field shall indicate the status of the electronicEmissisionBeamData (e.g., the electronicEmissisionBeamData is active or deactivated) and shall be represented by the ElectronicEmissisionBeamData + * Status record (see 6.2.12) + */ + protected BeamStatus beamStatus = new BeamStatus(); + + /** + * Jamming Technique. This field shall be used to identify the jamming method or methods and shall be represented by a Jamming Technique + * record (see 6.2.49). + */ + protected JammingTechnique jammingTechnique = new JammingTechnique(); + + /** + * This field is optional for any given electronicEmissisionBeamData. Rules for inclusion and use are provided in 5.7.3.3, 5.7.3.7, and 5.7.3.8. When included, + * this field shall be represented by a series of Track/Jam Data records (see 6.2.90). + */ + protected TrackJamData trackJamData = new TrackJamData(); + + /** Constructor */ + public ElectronicEmissisionBeamData() + { + } + + public int getMarshalledSize() + { + int marshalSize = 0; + + marshalSize = marshalSize + 1; // beamDataLength + marshalSize = marshalSize + 1; // beamNumber + marshalSize = marshalSize + 2; // beamParameterIndex + marshalSize = marshalSize + fundamentalParameterData.getMarshalledSize(); // fundamentalParameterData + marshalSize = marshalSize + beamData.getMarshalledSize(); // beamData + marshalSize = marshalSize + 1; // beamFunction + marshalSize = marshalSize + 1; // numberOfTargets + marshalSize = marshalSize + 1; // highDensityTrackJam + marshalSize = marshalSize + beamStatus.getMarshalledSize(); // beamStatus + marshalSize = marshalSize + jammingTechnique.getMarshalledSize(); // jammingTechnique + if (numberOfTargets != 0) { + marshalSize = marshalSize + trackJamData.getMarshalledSize(); // trackJamData + } + + return marshalSize; + } + + public EEFundamentalParameterData getFundamentalParameterData() + { + return fundamentalParameterData; + } + + public void setFundamentalParameterData(EEFundamentalParameterData fundamentalParameterData) + { + this.fundamentalParameterData = fundamentalParameterData; + } + + public BeamData getBeamData() + { + return beamData; + } + + public void setBeamData(BeamData beamData) + { + this.beamData = beamData; + } + + public short getBeamFunction() + { + return beamFunction; + } + + public void setBeamFunction(short beamFunction) + { + this.beamFunction = beamFunction; + } + + public short getNumberOfTargets() + { + return numberOfTargets; + } + + public void setNumberOfTargets(short numberOfTargets) + { + this.numberOfTargets = numberOfTargets; + } + + public short getHighDensityTrackJam() + { + return highDensityTrackJam; + } + + public void setHighDensityTrackJam(short highDensityTrackJam) + { + this.highDensityTrackJam = highDensityTrackJam; + } + + public BeamStatus getBeamStatus() + { + return beamStatus; + } + + public void setBeamStatus(BeamStatus beamStatus) + { + this.beamStatus = beamStatus; + } + + public JammingTechnique getJammingTechnique() + { + return jammingTechnique; + } + + public void setJammingTechnique(JammingTechnique jammingTechnique) + { + this.jammingTechnique = jammingTechnique; + } + + public TrackJamData getTrackJamData() + { + return trackJamData; + } + + public void setTrackJamData(TrackJamData trackJamData) + { + this.trackJamData = trackJamData; + } + + public int getBeamDataLength() + { + return beamDataLength; + } + + public void setBeamDataLength(short beamDataLength) + { + this.beamDataLength = beamDataLength; + } + + public short getBeamNumber() + { + return beamNumber; + } + + public void setBeamNumber(short pEmitterFunction) + { + beamNumber = pEmitterFunction; + } + + public int getBeamParameterIndex() + { + return beamParameterIndex; + } + + public void setBeamParameterIndex(short pEmitterIDNumber) + { + beamParameterIndex = pEmitterIDNumber; + } + + public void marshal(DataOutputStream dos) + { + try { + dos.writeByte((byte) beamDataLength); + dos.writeByte((byte) beamNumber); + dos.writeShort(beamParameterIndex); + fundamentalParameterData.marshal(dos); + beamData.marshal(dos); + dos.writeByte((byte) beamFunction); + dos.writeByte((byte) numberOfTargets); + dos.writeByte((byte) highDensityTrackJam); + beamStatus.marshal(dos); + jammingTechnique.marshal(dos); + if (numberOfTargets != 0) { //When the Number of Targets value is zero, this field shall be omitted + trackJamData.marshal(dos); + } + } // end try + catch (Exception e) { + System.out.println(e); + } + } // end of marshal method + + /** + * Packs a Pdu into the ByteBuffer. + * @param buff The ByteBuffer at the position to begin writing + * @throws java.nio.BufferOverflowException if buff is too small + * @throws java.nio.ReadOnlyBufferException if buff is read only + * @see java.nio.ByteBuffer + * @since ?? + */ + public void marshal(java.nio.ByteBuffer buff) + { + buff.put((byte) beamDataLength); + buff.put((byte) beamNumber); + buff.putShort((short) beamParameterIndex); + fundamentalParameterData.marshal(buff); + beamData.marshal(buff); + buff.put((byte) beamFunction); + buff.put((byte) numberOfTargets); + buff.put((byte) highDensityTrackJam); + beamStatus.marshal(buff); + jammingTechnique.marshal(buff); + if (numberOfTargets != 0) { //When the Number of Targets value is zero, this field shall be omitted + trackJamData.marshal(buff); + } + } // end of marshal method + + public void unmarshal(DataInputStream dis) + { + try { + beamDataLength = (short) dis.readUnsignedByte(); + beamNumber = (short) dis.readUnsignedByte(); + beamParameterIndex = dis.readUnsignedShort(); + fundamentalParameterData.unmarshal(dis); + beamData.unmarshal(dis); + beamFunction = (short) dis.readUnsignedShort(); + numberOfTargets = (short) dis.readUnsignedShort(); + highDensityTrackJam = (short) dis.readUnsignedShort(); + beamStatus.unmarshal(dis); + jammingTechnique.unmarshal(dis); + if (numberOfTargets != 0) { //When the Number of Targets value is zero, this field shall be omitted + trackJamData.unmarshal(dis); + } + + } // end try + catch (Exception e) { + System.out.println(e); + } + } // end of unmarshal method + + /** + * Unpacks a Pdu from the underlying data. + * @param buff The ByteBuffer at the position to begin reading + * @throws java.nio.BufferUnderflowException if buff is too small + * @see java.nio.ByteBuffer + * @since ?? + */ + public void unmarshal(java.nio.ByteBuffer buff) + { + beamDataLength = (short) ( buff.get() & 0xFF ); + beamNumber = (short) ( buff.get() & 0xFF ); + beamParameterIndex = ( buff.getShort() & 0xFFFF ); + fundamentalParameterData.unmarshal(buff); + beamData.unmarshal(buff); + beamFunction = (short) ( buff.get() & 0xFF ); + numberOfTargets = (short) ( buff.get() & 0xFF ); + highDensityTrackJam = (short) ( buff.get() & 0xFF ); + beamStatus.unmarshal(buff); + jammingTechnique.unmarshal(buff); + if (numberOfTargets != 0) { //When the Number of Targets value is zero, this field shall be omitted + trackJamData.unmarshal(buff); + } + } // end of unmarshal method + + @Override + public boolean equals(Object o) + { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ElectronicEmissisionBeamData electronicEmissisionBeamData = (ElectronicEmissisionBeamData) o; + return beamDataLength == electronicEmissisionBeamData.beamDataLength && + beamNumber == electronicEmissisionBeamData.beamNumber && + beamParameterIndex == electronicEmissisionBeamData.beamParameterIndex && + beamFunction == electronicEmissisionBeamData.beamFunction && + numberOfTargets == electronicEmissisionBeamData.numberOfTargets && + highDensityTrackJam == electronicEmissisionBeamData.highDensityTrackJam && + Objects.equals(fundamentalParameterData, electronicEmissisionBeamData.fundamentalParameterData) && + Objects.equals(beamData, electronicEmissisionBeamData.beamData) && + Objects.equals(beamStatus, electronicEmissisionBeamData.beamStatus) && + Objects.equals(jammingTechnique, electronicEmissisionBeamData.jammingTechnique) && + Objects.equals(trackJamData, electronicEmissisionBeamData.trackJamData); + } + + @Override + public int hashCode() + { + return Objects + .hash(beamDataLength, beamNumber, beamParameterIndex, fundamentalParameterData, beamData, beamFunction, numberOfTargets, highDensityTrackJam, beamStatus, jammingTechnique, trackJamData); + } + +} // end of class diff --git a/src/main/java/edu/nps/moves/dis7/PduFactory.java b/src/main/java/edu/nps/moves/dis7/PduFactory.java new file mode 100644 index 00000000..2ea5a7f4 --- /dev/null +++ b/src/main/java/edu/nps/moves/dis7/PduFactory.java @@ -0,0 +1,317 @@ +package edu.nps.moves.dis7; + + +import edu.nps.moves.dis7.AcknowledgePdu; +import edu.nps.moves.dis7.AcknowledgeReliablePdu; +import edu.nps.moves.dis7.ActionRequestPdu; +import edu.nps.moves.dis7.ActionRequestReliablePdu; +import edu.nps.moves.dis7.ActionResponsePdu; +import edu.nps.moves.dis7.ActionResponseReliablePdu; +import edu.nps.moves.dis7.ArealObjectStatePdu; +import edu.nps.moves.dis7.CollisionElasticPdu; +import edu.nps.moves.dis7.CollisionPdu; +import edu.nps.moves.dis7.CommentPdu; +import edu.nps.moves.dis7.CommentReliablePdu; +import edu.nps.moves.dis7.CreateEntityPdu; +import edu.nps.moves.dis7.CreateEntityReliablePdu; +import edu.nps.moves.dis7.DataPdu; +import edu.nps.moves.dis7.DataQueryPdu; +import edu.nps.moves.dis7.DataQueryReliablePdu; +import edu.nps.moves.dis7.DataReliablePdu; +import edu.nps.moves.dis7.DesignatorPdu; +import edu.nps.moves.dis7.DetonationPdu; +import edu.nps.moves.dis7.ElectronicEmissionsPdu; +import edu.nps.moves.dis7.EntityStatePdu; +import edu.nps.moves.dis7.EntityStateUpdatePdu; +import edu.nps.moves.dis7.EventReportPdu; +import edu.nps.moves.dis7.EventReportReliablePdu; +import edu.nps.moves.dis7.FastEntityStatePdu; +import edu.nps.moves.dis7.FirePdu; +import edu.nps.moves.dis7.IntercomControlPdu; +import edu.nps.moves.dis7.IntercomSignalPdu; +import edu.nps.moves.dis7.IsPartOfPdu; +import edu.nps.moves.dis7.LinearObjectStatePdu; +import edu.nps.moves.dis7.MinefieldResponseNackPdu; +import edu.nps.moves.dis7.MinefieldStatePdu; +import edu.nps.moves.dis7.Pdu; +import edu.nps.moves.dis7.PointObjectStatePdu; +import edu.nps.moves.dis7.ReceiverPdu; +import edu.nps.moves.dis7.RecordQueryReliablePdu; +import edu.nps.moves.dis7.RemoveEntityPdu; +import edu.nps.moves.dis7.RemoveEntityReliablePdu; +import edu.nps.moves.dis7.RepairCompletePdu; +import edu.nps.moves.dis7.RepairResponsePdu; +import edu.nps.moves.dis7.ResupplyOfferPdu; +import edu.nps.moves.dis7.ResupplyReceivedPdu; +import edu.nps.moves.dis7.SeesPdu; +import edu.nps.moves.dis7.ServiceRequestPdu; +import edu.nps.moves.dis7.SetDataPdu; +import edu.nps.moves.dis7.SetDataReliablePdu; +import edu.nps.moves.dis7.SignalPdu; +import edu.nps.moves.dis7.StartResumePdu; +import edu.nps.moves.dis7.StartResumeReliablePdu; +import edu.nps.moves.dis7.StopFreezePdu; +import edu.nps.moves.dis7.StopFreezeReliablePdu; +import edu.nps.moves.dis7.TransmitterPdu; +import edu.nps.moves.dis7.UaPdu; +import edu.nps.moves.disenum.PduType; + +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + + +public class PduFactory +{ + private boolean useFastPdu; + private Logger logger; + + public PduFactory() + { + this(false); + } + + public PduFactory(boolean useFastPdu) + { + this.useFastPdu = false; + this.useFastPdu = useFastPdu; + this.logger = Logger.getLogger(edu.nps.moves.disutil.PduFactory.class.getName()); + this.logger.setLevel(Level.OFF); + } + + public boolean getUseFastPdu() + { + return this.useFastPdu; + } + + public void setUseFastPdu(boolean use) + { + this.useFastPdu = use; + } + + public void setLoggingLevel(Level loggingLevel) + { + this.logger.setLevel(loggingLevel); + } + + public Pdu createPdu(byte[] data) + { + return this.createPdu(ByteBuffer.wrap(data)); + } + + public Pdu createPdu(ByteBuffer buff) + { + int pos = buff.position(); + if (pos + 2 > buff.limit()) { + return null; + } else { + buff.position(pos + 2); + int pduType = buff.get() & 255; + buff.position(pos); + PduType pduTypeEnum = PduType.lookup[pduType]; + Pdu aPdu = null; + switch (pduTypeEnum) { + case ENTITY_STATE: + if (this.useFastPdu) { + aPdu = new FastEntityStatePdu(); + } else { + aPdu = new EntityStatePdu(); + } + break; + case FIRE: + aPdu = new FirePdu(); + break; + case DETONATION: + aPdu = new DetonationPdu(); + break; + case COLLISION: + aPdu = new CollisionPdu(); + break; + case SERVICE_REQUEST: + aPdu = new ServiceRequestPdu(); + break; + case RESUPPLY_OFFER: + aPdu = new ResupplyOfferPdu(); + break; + case RESUPPLY_RECEIVED: + aPdu = new ResupplyReceivedPdu(); + break; + case REPAIR_COMPLETE: + aPdu = new RepairCompletePdu(); + break; + case REPAIR_RESPONSE: + aPdu = new RepairResponsePdu(); + break; + case CREATE_ENTITY: + aPdu = new CreateEntityPdu(); + break; + case REMOVE_ENTITY: + aPdu = new RemoveEntityPdu(); + break; + case START_RESUME: + aPdu = new StartResumePdu(); + break; + case STOP_FREEZE: + aPdu = new StopFreezePdu(); + break; + case ACKNOWLEDGE: + aPdu = new AcknowledgePdu(); + break; + case ACTION_REQUEST: + aPdu = new ActionRequestPdu(); + break; + case ACTION_RESPONSE: + aPdu = new ActionResponsePdu(); + break; + case DATA_QUERY: + aPdu = new DataQueryPdu(); + break; + case SET_DATA: + aPdu = new SetDataPdu(); + break; + case DATA: + aPdu = new DataPdu(); + break; + case EVENT_REPORT: + aPdu = new EventReportPdu(); + break; + case COMMENT: + aPdu = new CommentPdu(); + break; + case ELECTROMAGNETIC_EMISSION: + aPdu = new ElectronicEmissionsPdu(); + break; + case DESIGNATOR: + aPdu = new DesignatorPdu(); + break; + case TRANSMITTER: + aPdu = new TransmitterPdu(); + break; + case SIGNAL: + aPdu = new SignalPdu(); + break; + case RECEIVER: + aPdu = new ReceiverPdu(); + break; + case UNDERWATER_ACOUSTIC: + aPdu = new UaPdu(); + break; + case SUPPLEMENTAL_EMISSION_ENTITY_STATE: + aPdu = new SeesPdu(); + break; + case INTERCOM_SIGNAL: + aPdu = new IntercomSignalPdu(); + break; + case INTERCOM_CONTROL: + aPdu = new IntercomControlPdu(); + break; + case ISPARTOF: + aPdu = new IsPartOfPdu(); + break; + case MINEFIELD_STATE: + aPdu = new MinefieldStatePdu(); + break; + case MINEFIELD_RESPONSE_NAK: + aPdu = new MinefieldResponseNackPdu(); + break; + case POINT_OBJECT_STATE: + aPdu = new PointObjectStatePdu(); + break; + case LINEAR_OBJECT_STATE: + aPdu = new LinearObjectStatePdu(); + break; + case AREAL_OBJECT_STATE: + aPdu = new ArealObjectStatePdu(); + break; + case CREATE_ENTITY_R: + aPdu = new CreateEntityReliablePdu(); + break; + case REMOVE_ENTITY_R: + aPdu = new RemoveEntityReliablePdu(); + break; + case START_RESUME_R: + aPdu = new StartResumeReliablePdu(); + break; + case STOP_FREEZE_R: + aPdu = new StopFreezeReliablePdu(); + break; + case ACKNOWLEDGE_R: + aPdu = new AcknowledgeReliablePdu(); + break; + case ACTION_REQUEST_R: + aPdu = new ActionRequestReliablePdu(); + break; + case ACTION_RESPONSE_R: + aPdu = new ActionResponseReliablePdu(); + break; + case DATA_QUERY_R: + aPdu = new DataQueryReliablePdu(); + break; + case SET_DATA_R: + aPdu = new SetDataReliablePdu(); + break; + case DATA_R: + aPdu = new DataReliablePdu(); + break; + case EVENT_REPORT_R: + aPdu = new EventReportReliablePdu(); + break; + case COMMENT_R: + aPdu = new CommentReliablePdu(); + break; + case RECORD_QUERY_R: + aPdu = new RecordQueryReliablePdu(); + break; + case COLLISION_ELASTIC: + aPdu = new CollisionElasticPdu(); + break; + case ENTITY_STATE_UPDATE: + aPdu = new EntityStateUpdatePdu(); + break; + default: + this.logger.log(Level.INFO, "PDU not implemented. Type = " + pduType + "\n"); + if (pduTypeEnum != null) { + this.logger.log(Level.INFO, " PDU name is: " + pduTypeEnum.getDescription()); + } + } + + if (aPdu != null) { + ( (Pdu) aPdu ).unmarshal(buff); + } + + return (Pdu) aPdu; + } + } + + public List getPdusFromBundle(byte[] data) + { + ArrayList pdus = new ArrayList(); + int pduStartPointInData = 0; + + while (true) { + byte[] remaining = Arrays.copyOfRange(data, pduStartPointInData, data.length); + + try { + Pdu pdu = this.createPdu(remaining); + if (pdu == null) { + break; + } + + pdus.add(pdu); + int pduLength = pdu.getLength(); + pduStartPointInData += pduLength; + if (pduStartPointInData >= data.length) { + break; + } + } catch (Exception var7) { + System.out.println("Problems decoding multiple PDUs in datagram; decoded as may as possible"); + break; + } + } + + return pdus; + } +} diff --git a/src/main/java/edu/nps/moves/dis7/TrackJamData.java b/src/main/java/edu/nps/moves/dis7/TrackJamData.java index d95ba9ba..1db62aa9 100644 --- a/src/main/java/edu/nps/moves/dis7/TrackJamData.java +++ b/src/main/java/edu/nps/moves/dis7/TrackJamData.java @@ -1,140 +1,174 @@ package edu.nps.moves.dis7; -import java.io.*; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.Serializable; +import java.nio.ByteBuffer; /** - * Track-Jam data Section 6.2.89 - * - * 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 + * Track-Jam data Section 6.2.89 * + * 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 TrackJamData extends Object implements Serializable { - /** the entity tracked or illumated, or an emitter beam targeted with jamming */ - protected EntityID entityID = new EntityID(); - - /** Emitter system associated with the entity */ - protected short emitterNumber; - - /** Beam associated with the entity */ - protected short beamNumber; - - -/** Constructor */ - public TrackJamData() - { - } - -public int getMarshalledSize() -{ - int marshalSize = 0; - - marshalSize = marshalSize + entityID.getMarshalledSize(); // entityID - marshalSize = marshalSize + 1; // emitterNumber - marshalSize = marshalSize + 1; // beamNumber + /** the entity tracked or illumated, or an emitter beam targeted with jamming */ + protected EntityID entityID = new EntityID(); - return marshalSize; -} + /** Emitter system associated with the entity */ + protected short emitterNumber; + /** Beam associated with the entity */ + protected short beamNumber; -public void setEntityID(EntityID pEntityID) -{ entityID = pEntityID; -} -public EntityID getEntityID() -{ return entityID; -} - -public void setEmitterNumber(short pEmitterNumber) -{ emitterNumber = pEmitterNumber; -} + /** Constructor */ + public TrackJamData() + { + } -public short getEmitterNumber() -{ return emitterNumber; -} + public int getMarshalledSize() + { + int marshalSize = 0; -public void setBeamNumber(short pBeamNumber) -{ beamNumber = pBeamNumber; -} + marshalSize = marshalSize + entityID.getMarshalledSize(); // entityID + marshalSize = marshalSize + 1; // emitterNumber + marshalSize = marshalSize + 1; // beamNumber -public short getBeamNumber() -{ return beamNumber; -} + return marshalSize; + } + public EntityID getEntityID() + { + return entityID; + } -/** - * 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) -{ - entityID.marshal(buff); - buff.put( (byte)emitterNumber); - buff.put( (byte)beamNumber); - } // end of marshal method + public void setEntityID(EntityID pEntityID) + { + entityID = pEntityID; + } -/** - * 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) -{ - entityID.unmarshal(buff); - emitterNumber = (short)(buff.get() & 0xFF); - beamNumber = (short)(buff.get() & 0xFF); - } // end of unmarshal method + public short getEmitterNumber() + { + return emitterNumber; + } + public void setEmitterNumber(short pEmitterNumber) + { + emitterNumber = pEmitterNumber; + } - /* - * 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) - { + public short getBeamNumber() + { + return beamNumber; + } - if(this == obj){ - return true; + public void setBeamNumber(short pBeamNumber) + { + beamNumber = pBeamNumber; } - if(obj == null){ - return false; + /** + * Packs a Pdu into the DataOutputStream. + */ + public void marshal(DataOutputStream dos) + { + entityID.marshal(dos); + try { + dos.writeByte((byte) emitterNumber); + dos.writeByte((byte) beamNumber); + } catch (IOException e) { + System.out.println(e); + } + } // end of marshal method + /** + * 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) + { + entityID.marshal(buff); + buff.put( (byte)emitterNumber); + buff.put( (byte)beamNumber); + } // end of marshal method + /** + * Unpacks a Pdu from the underlying data. + */ + public void unmarshal(DataInputStream dis) + { + try { + entityID.unmarshal(dis); + emitterNumber = (short) dis.readUnsignedShort(); + beamNumber = (short) dis.readUnsignedShort(); + } catch (IOException e) { + e.printStackTrace(); + } + } // end of unmarshal method + + public void unmarshal(ByteBuffer buff) + { + entityID.unmarshal(buff); + emitterNumber = (short)(buff.get() & 0xFF); + beamNumber = (short)(buff.get() & 0xFF); } - if(getClass() != obj.getClass()) - return false; + /* + * 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) + { - return equalsImpl(obj); - } + if (this == obj) { + return true; + } - /** - * 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 == null) { + return false; + } - if(!(obj instanceof TrackJamData)) - return false; + if (getClass() != obj.getClass()) { + return false; + } - final TrackJamData rhs = (TrackJamData)obj; + return equalsImpl(obj); + } - if( ! (entityID.equals( rhs.entityID) )) ivarsEqual = false; - if( ! (emitterNumber == rhs.emitterNumber)) ivarsEqual = false; - if( ! (beamNumber == rhs.beamNumber)) ivarsEqual = false; + /** + * 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 TrackJamData )) { + return false; + } + + final TrackJamData rhs = (TrackJamData) obj; + + if (!( entityID.equals(rhs.entityID) )) { + ivarsEqual = false; + } + if (!( emitterNumber == rhs.emitterNumber )) { + ivarsEqual = false; + } + if (!( beamNumber == rhs.beamNumber )) { + ivarsEqual = false; + } + + return ivarsEqual; + } - return ivarsEqual; - } } // end of class diff --git a/src/test/java/edu/nps/moves/dis7/ElectronicEmissionsPduTest.java b/src/test/java/edu/nps/moves/dis7/ElectronicEmissionsPduTest.java new file mode 100644 index 00000000..0031cdbc --- /dev/null +++ b/src/test/java/edu/nps/moves/dis7/ElectronicEmissionsPduTest.java @@ -0,0 +1,123 @@ +package edu.nps.moves.dis7; + + +import edu.nps.moves.dis.PduFileLoader; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.IOException; + +import static org.junit.Assert.assertEquals; + + +/** + * @author lcowan + */ +public class ElectronicEmissionsPduTest +{ + + public ElectronicEmissionsPduTest() + { + } + + @BeforeClass + public static void setUpClass() + { + } + + @AfterClass + public static void tearDownClass() + { + } + + @Before + public void setUp() + { + } + + @After + public void tearDown() + { + } + + + @Test + public void unmarshal() + throws IOException + { + PduFactory factory = new PduFactory(); + Pdu pdu = factory.createPdu(PduFileLoader.load("ElectromagneticEmissionPdu.raw")); + + // Expected field values were determined from Wireshark: Decode As -> DIS. + + // Header + assertEquals(7, pdu.getProtocolVersion()); + assertEquals(51, pdu.getExerciseID()); + assertEquals(23, pdu.getPduType()); + assertEquals(6, pdu.getProtocolFamily()); + assertEquals(100, pdu.getMarshalledSize()); + assertEquals(0, pdu.getPadding()); + + ElectronicEmissionsPdu espdu = (ElectronicEmissionsPdu) pdu; + + // Entity ID + assertEquals(162, espdu.getEmittingEntityID().getSiteID()); + assertEquals(2, espdu.getEmittingEntityID().getApplicationID()); + assertEquals(0, espdu.getEmittingEntityID().getEntityID()); + + // Event ID + assertEquals(0, espdu.getEventID().getEventNumber()); + + // Emission System + assertEquals(18, espdu.getSystemDataLength()); + assertEquals(1, espdu.getNumberOfBeams()); + + // Emitter System + assertEquals(15660, espdu.getEmitterSystem().getEmitterName()); + assertEquals(7, espdu.getEmitterSystem().getEmitterFunction()); + assertEquals(1, espdu.getEmitterSystem().getEmitterIDNumber()); + + // Location + assertEquals(0.0, espdu.getLocation().getX(), 0.0001); + assertEquals(0.0, espdu.getLocation().getY(), 0.0001); + assertEquals(0.0, espdu.getLocation().getZ(), 0.0001); + + // Beam + assertEquals(13, espdu.getElectronicEmissionBeamData().getBeamDataLength()); + assertEquals(1, espdu.getElectronicEmissionBeamData().getBeamNumber()); + assertEquals(1, espdu.getElectronicEmissionBeamData().getBeamParameterIndex()); + assertEquals(14000000000.0, espdu.getElectronicEmissionBeamData().getFundamentalParameterData().getFrequency(), 0.000001); + assertEquals(6000000000.0, espdu.getElectronicEmissionBeamData().getFundamentalParameterData().getFrequencyRange(), 0.000001); + assertEquals(55.0, espdu.getElectronicEmissionBeamData().getFundamentalParameterData().getEffectiveRadiatedPower(), 0.000001); + assertEquals(600.0, espdu.getElectronicEmissionBeamData().getFundamentalParameterData().getPulseRepetitionFrequency(), 0.000001); + assertEquals(3.0, espdu.getElectronicEmissionBeamData().getFundamentalParameterData().getPulseWidth(), 0.000001); + assertEquals(0, espdu.getElectronicEmissionBeamData().getBeamData().getBeamAzimuthCenter(), 0.000001); + assertEquals(0.698132, espdu.getElectronicEmissionBeamData().getBeamData().getBeamAzimuthSweep(), 0.000001); + assertEquals(0.436332, espdu.getElectronicEmissionBeamData().getBeamData().getBeamElevationCenter(), 0.000001); + assertEquals(0.436332, espdu.getElectronicEmissionBeamData().getBeamData().getBeamElevationSweep(), 0.000001); + assertEquals(90.4001, espdu.getElectronicEmissionBeamData().getBeamData().getBeamSweepSync(), 0.000001); + assertEquals(7, espdu.getElectronicEmissionBeamData().getBeamFunction()); + assertEquals(0, espdu.getElectronicEmissionBeamData().getNumberOfTargets()); + assertEquals(0, espdu.getElectronicEmissionBeamData().getHighDensityTrackJam()); + assertEquals(0, espdu.getElectronicEmissionBeamData().getBeamStatus().getBeamState()); + assertEquals(0, espdu.getElectronicEmissionBeamData().getJammingTechnique().getCategory()); + assertEquals(0, espdu.getElectronicEmissionBeamData().getJammingTechnique().getKind()); + assertEquals(0, espdu.getElectronicEmissionBeamData().getJammingTechnique().getSpecific()); + assertEquals(0, espdu.getElectronicEmissionBeamData().getJammingTechnique().getCategory()); + + + } + + @Test + public void marshal() + { + EntityStatePdu espdu = new EntityStatePdu(); + + byte[] buffer = espdu.marshal(); + + assertEquals(buffer.length, espdu.getMarshalledSize()); + } +} diff --git a/src/test/java/edu/nps/moves/dis7/EntityStatePduTest.java b/src/test/java/edu/nps/moves/dis7/EntityStatePduTest.java new file mode 100644 index 00000000..6d0c1805 --- /dev/null +++ b/src/test/java/edu/nps/moves/dis7/EntityStatePduTest.java @@ -0,0 +1,125 @@ +package edu.nps.moves.dis7; + + +import edu.nps.moves.dis.PduFileLoader; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.IOException; + +import static org.junit.Assert.assertEquals; + + +/** + * @author mcgredo + */ +public class EntityStatePduTest +{ + + public EntityStatePduTest() + { + } + + @BeforeClass + public static void setUpClass() + { + } + + @AfterClass + public static void tearDownClass() + { + } + + @Before + public void setUp() + { + } + + @After + public void tearDown() + { + } + + + @Test + public void unmarshal() + throws IOException + { + PduFactory factory = new PduFactory(); + Pdu pdu = factory.createPdu(PduFileLoader.load("EntityStatePdu-26.raw")); + + // Expected field values were determined from Wireshark: Decode As -> DIS. + + // Header + assertEquals(6, pdu.getProtocolVersion()); + assertEquals(7, pdu.getExerciseID()); + assertEquals(1, pdu.getPduType()); + assertEquals(1, pdu.getProtocolFamily()); + assertEquals(144, pdu.getLength()); + assertEquals(0, pdu.getPadding()); + + EntityStatePdu espdu = (EntityStatePdu) pdu; + + // Entity ID + assertEquals(42, espdu.getEntityID().getSiteID()); + assertEquals(4, espdu.getEntityID().getApplicationID()); + assertEquals(26, espdu.getEntityID().getEntityID()); + + // Force ID + assertEquals(1, espdu.getForceId()); + + // Entity Type (aka DIS Enumeration) + assertEquals(1, espdu.getEntityType().getEntityKind()); + assertEquals(1, espdu.getEntityType().getDomain()); + assertEquals(39, espdu.getEntityType().getCountry()); + assertEquals(7, espdu.getEntityType().getCategory()); + assertEquals(2, espdu.getEntityType().getSubcategory()); + assertEquals(1, espdu.getEntityType().getSpecific()); + assertEquals(0, espdu.getEntityType().getExtra()); + + // Alternative Entity Type + assertEquals(1, espdu.getAlternativeEntityType().getEntityKind()); + assertEquals(1, espdu.getAlternativeEntityType().getDomain()); + assertEquals(39, espdu.getAlternativeEntityType().getCountry()); + assertEquals(7, espdu.getAlternativeEntityType().getCategory()); + assertEquals(2, espdu.getAlternativeEntityType().getSubcategory()); + assertEquals(1, espdu.getAlternativeEntityType().getSpecific()); + assertEquals(0, espdu.getAlternativeEntityType().getExtra()); + + // Entity Linear Velocity + assertEquals(0, espdu.getEntityLinearVelocity().getX(), 0); + assertEquals(0, espdu.getEntityLinearVelocity().getY(), 0); + assertEquals(0, espdu.getEntityLinearVelocity().getZ(), 0); + + // Entity Location + assertEquals(4374082.80485589, espdu.getEntityLocation().getX(), 0.001); + assertEquals(1667679.95730107, espdu.getEntityLocation().getY(), 0.001); + assertEquals(4318284.36890269, espdu.getEntityLocation().getZ(), 0.001); + + // Entity Orientation + assertEquals(1.93505, espdu.getEntityOrientation().getPsi(), 0.001); + assertEquals(0, espdu.getEntityOrientation().getTheta(), 0.001); + assertEquals(-2.31924, espdu.getEntityOrientation().getPhi(), 0.001); + + // Dead Reckoning Parameters + // TODO assertEquals(???, espdu.getDeadReckoningParameters()); + // Entity Marking + assertEquals("26", new String(espdu.getMarking().getCharacters()).trim()); + + // Capabilities + assertEquals(0, espdu.getCapabilities()); + } + + @Test + public void marshal() + { + EntityStatePdu espdu = new EntityStatePdu(); + + byte[] buffer = espdu.marshal(); + + assertEquals(buffer.length, espdu.getLength()); + } +} diff --git a/src/test/resources/edu/nps/moves/dis/ElectromagneticEmissionPdu.raw b/src/test/resources/edu/nps/moves/dis/ElectromagneticEmissionPdu.raw new file mode 100644 index 00000000..5b7dc66c Binary files /dev/null and b/src/test/resources/edu/nps/moves/dis/ElectromagneticEmissionPdu.raw differ