Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fire PDU fix for descriptor extension (DIS 7) #122

Merged
merged 4 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/main/java/edu/nps/moves/dis7/Descriptor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package edu.nps.moves.dis7;

import java.io.Serializable;

/**
* The super class for the Expendable-, Explosion-, and MunitionDescriptor
*
* 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 fo
*/
public class Descriptor extends Object implements Serializable {

public Descriptor() {
}
}
3 changes: 2 additions & 1 deletion src/main/java/edu/nps/moves/dis7/ExpendableDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @author DMcG
*/
public class ExpendableDescriptor extends Object implements Serializable {
public class ExpendableDescriptor extends Descriptor {

/**
* Type of the object that exploded
Expand All @@ -27,6 +27,7 @@ public class ExpendableDescriptor extends Object implements Serializable {
* Constructor
*/
public ExpendableDescriptor() {
super();
}

public int getMarshalledSize() {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/edu/nps/moves/dis7/ExplosionDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @author DMcG
*/
public class ExplosionDescriptor extends Object implements Serializable {
public class ExplosionDescriptor extends Descriptor {

/**
* Type of the object that exploded. See 6.2.30
Expand All @@ -38,6 +38,7 @@ public class ExplosionDescriptor extends Object implements Serializable {
* Constructor
*/
public ExplosionDescriptor() {
super();
}

public int getMarshalledSize() {
Expand Down
51 changes: 42 additions & 9 deletions src/main/java/edu/nps/moves/dis7/FirePdu.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ public class FirePdu extends WarfareFamilyPdu implements Serializable {
* This field shall describe the firing or launch of a munition or
* expendable represented by one of the following types of Descriptor
* records: Munition Descriptor (6.2.20.2) or Expendable Descriptor
* (6.2.20.4).
* (6.2.20.4), depending on Fire Type Indicator bit 4 in Pdu Status (6.2.67).
*/
protected MunitionDescriptor descriptor = new MunitionDescriptor();
protected Descriptor descriptor = new MunitionDescriptor();

/**
* This field shall specify the velocity of the fired munition at the point
Expand Down Expand Up @@ -83,7 +83,12 @@ public int getMarshalledSize() {
marshalSize = marshalSize + eventID.getMarshalledSize(); // eventID
marshalSize = marshalSize + 4; // fireMissionIndex
marshalSize = marshalSize + locationInWorldCoordinates.getMarshalledSize(); // locationInWorldCoordinates
marshalSize = marshalSize + descriptor.getMarshalledSize(); // descriptor
int fireTypeIndicator = getFireTypeIndicator();
if (fireTypeIndicator == 0) {
marshalSize = marshalSize + ((MunitionDescriptor) descriptor).getMarshalledSize(); //Munition descriptor
} else {
marshalSize = marshalSize + ((ExpendableDescriptor) descriptor).getMarshalledSize(); //Expendable descriptor
}
marshalSize = marshalSize + velocity.getMarshalledSize(); // velocity
marshalSize = marshalSize + 4; // range

Expand Down Expand Up @@ -122,11 +127,11 @@ public Vector3Double getLocationInWorldCoordinates() {
return locationInWorldCoordinates;
}

public void setDescriptor(MunitionDescriptor pDescriptor) {
public void setDescriptor(Descriptor pDescriptor) {
descriptor = pDescriptor;
}

public MunitionDescriptor getDescriptor() {
public Descriptor getDescriptor() {
return descriptor;
}

Expand All @@ -153,7 +158,12 @@ public void marshal(DataOutputStream dos) {
eventID.marshal(dos);
dos.writeInt((int) fireMissionIndex);
locationInWorldCoordinates.marshal(dos);
descriptor.marshal(dos);
int fireTypeIndicator = getFireTypeIndicator();
if (fireTypeIndicator == 0) {
((MunitionDescriptor) descriptor).marshal(dos);
} else {
((ExpendableDescriptor) descriptor).marshal(dos);
}
velocity.marshal(dos);
dos.writeFloat((float) range);
} // end try
Expand All @@ -170,7 +180,14 @@ public void unmarshal(DataInputStream dis) {
eventID.unmarshal(dis);
fireMissionIndex = dis.readInt();
locationInWorldCoordinates.unmarshal(dis);
descriptor.unmarshal(dis);
int fireTypeIndicator = getFireTypeIndicator();
if (fireTypeIndicator == 0) {
descriptor = new MunitionDescriptor();
((MunitionDescriptor) descriptor).unmarshal(dis);
} else {
descriptor = new ExpendableDescriptor();
((ExpendableDescriptor) descriptor).unmarshal(dis);
}
velocity.unmarshal(dis);
range = dis.readFloat();
} // end try
Expand All @@ -194,7 +211,12 @@ public void marshal(java.nio.ByteBuffer buff) {
eventID.marshal(buff);
buff.putInt((int) fireMissionIndex);
locationInWorldCoordinates.marshal(buff);
descriptor.marshal(buff);
int fireTypeIndicator = getFireTypeIndicator();
if (fireTypeIndicator == 0) {
((MunitionDescriptor) descriptor).marshal(buff);
} else {
((ExpendableDescriptor) descriptor).marshal(buff);
}
velocity.marshal(buff);
buff.putFloat((float) range);
} // end of marshal method
Expand All @@ -214,7 +236,14 @@ public void unmarshal(java.nio.ByteBuffer buff) {
eventID.unmarshal(buff);
fireMissionIndex = buff.getInt();
locationInWorldCoordinates.unmarshal(buff);
descriptor.unmarshal(buff);
int fireTypeIndicator = getFireTypeIndicator();
if (fireTypeIndicator == 0) {
descriptor = new MunitionDescriptor();
((MunitionDescriptor) descriptor).unmarshal(buff);
} else {
descriptor = new ExpendableDescriptor();
((ExpendableDescriptor) descriptor).unmarshal(buff);
}
velocity.unmarshal(buff);
range = buff.getFloat();
} // end of unmarshal method
Expand Down Expand Up @@ -275,4 +304,8 @@ public boolean equalsImpl(Object obj) {

return ivarsEqual && super.equalsImpl(rhs);
}

private int getFireTypeIndicator(){
return (pduStatus & 0x10) >> 4;
}
} // end of class
3 changes: 2 additions & 1 deletion src/main/java/edu/nps/moves/dis7/MunitionDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*
* @author DMcG
*/
public class MunitionDescriptor extends Object implements Serializable {
public class MunitionDescriptor extends Descriptor {

/**
* What munition was used in the burst
Expand Down Expand Up @@ -42,6 +42,7 @@ public class MunitionDescriptor extends Object implements Serializable {
* Constructor
*/
public MunitionDescriptor() {
super();
}

public int getMarshalledSize() {
Expand Down
181 changes: 181 additions & 0 deletions src/test/java/edu/nps/moves/dis7/FirePduTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
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 FirePduTest {

public FirePduTest() {
}

@BeforeClass
public static void setUpClass() {
}

@AfterClass
public static void tearDownClass() {
}

@Before
public void setUp() {
}

@After
public void tearDown() {
}

@Test
public void marshal() {
FirePdu fpdu = new FirePdu();

byte[] buffer = fpdu.marshal();

assertEquals(buffer.length, fpdu.getLength());
}

@Test
public void unmarshal_MunitionDescriptor()
throws IOException {
PduFactory factory = new PduFactory();
Pdu pdu = factory.createPdu(edu.nps.moves.dis7.PduFileLoader.load("FirePdu_MunitionDescriptor.raw"));

// Header
assertEquals(7, pdu.getProtocolVersion());
assertEquals(1, pdu.getExerciseID());
assertEquals(2, pdu.getPduType());
assertEquals(2, pdu.getProtocolFamily());
assertEquals(96, pdu.getLength());
assertEquals(0, pdu.getPduStatus());
assertEquals(0, pdu.getPadding());

FirePdu fPdu = (FirePdu) pdu;

// Firing Entity ID
assertEquals(1, fPdu.getFiringEntityID().getSiteID());
assertEquals(2, fPdu.getFiringEntityID().getApplicationID());
assertEquals(1, fPdu.getFiringEntityID().getEntityID());

// Target Entity ID
assertEquals(200, fPdu.getTargetEntityID().getSiteID());
assertEquals(400, fPdu.getTargetEntityID().getApplicationID());
assertEquals(1, fPdu.getTargetEntityID().getEntityID());

// Munition Entity ID
assertEquals(1, fPdu.getMunitionExpendibleID().getSiteID());
assertEquals(2, fPdu.getMunitionExpendibleID().getApplicationID());
assertEquals(2, fPdu.getMunitionExpendibleID().getEntityID());

// Event ID
assertEquals(1, fPdu.getEventID().getSimulationAddress().getSite());
assertEquals(226, fPdu.getEventID().getSimulationAddress().getApplication());
assertEquals(1, fPdu.getEventID().getEventNumber());

// Fire Mission Index
assertEquals(55, fPdu.getFireMissionIndex());

// Location
assertEquals(3434174.675, fPdu.getLocationInWorldCoordinates().getX(), 0.001);
assertEquals(700499.234, fPdu.getLocationInWorldCoordinates().getY(), 0.001);
assertEquals(5310970.613, fPdu.getLocationInWorldCoordinates().getZ(), 0.001);

// Descriptor
MunitionDescriptor munDesc = (MunitionDescriptor) fPdu.getDescriptor();

assertEquals(2, munDesc.getMunitionType().getEntityKind());
assertEquals(2, munDesc.getMunitionType().getDomain());
assertEquals(57, munDesc.getMunitionType().getCountry());
assertEquals(1, munDesc.getMunitionType().getCategory());
assertEquals(2, munDesc.getMunitionType().getSubcategory());
assertEquals(2, munDesc.getMunitionType().getSpecific());
assertEquals(2, munDesc.getMunitionType().getExtra());

assertEquals(4000, munDesc.getWarhead());
assertEquals(7000, munDesc.getFuse());
assertEquals(55, munDesc.getQuantity());
assertEquals(54, munDesc.getRate());

// Velocity
assertEquals(4, fPdu.getVelocity().getX(), 0);
assertEquals(5, fPdu.getVelocity().getY(), 0);
assertEquals(6, fPdu.getVelocity().getZ(), 0);

// Range
assertEquals(55.5, fPdu.getRange(), 0.001);
}

@Test
public void unmarshal_ExpendableDescriptor()
throws IOException {
PduFactory factory = new PduFactory();
Pdu pdu = factory.createPdu(edu.nps.moves.dis7.PduFileLoader.load("FirePdu_ExpendableDescriptor.raw"));

// Header
assertEquals(7, pdu.getProtocolVersion());
assertEquals(1, pdu.getExerciseID());
assertEquals(2, pdu.getPduType());
assertEquals(2, pdu.getProtocolFamily());
assertEquals(96, pdu.getLength());
assertEquals(16, pdu.getPduStatus());
assertEquals(0, pdu.getPadding());

FirePdu fPdu = (FirePdu) pdu;

// Firing Entity ID
assertEquals(1, fPdu.getFiringEntityID().getSiteID());
assertEquals(2, fPdu.getFiringEntityID().getApplicationID());
assertEquals(1, fPdu.getFiringEntityID().getEntityID());

// Target Entity ID
assertEquals(200, fPdu.getTargetEntityID().getSiteID());
assertEquals(400, fPdu.getTargetEntityID().getApplicationID());
assertEquals(1, fPdu.getTargetEntityID().getEntityID());

// Munition Entity ID
assertEquals(1, fPdu.getMunitionExpendibleID().getSiteID());
assertEquals(2, fPdu.getMunitionExpendibleID().getApplicationID());
assertEquals(2, fPdu.getMunitionExpendibleID().getEntityID());

// Event ID
assertEquals(1, fPdu.getEventID().getSimulationAddress().getSite());
assertEquals(226, fPdu.getEventID().getSimulationAddress().getApplication());
assertEquals(1, fPdu.getEventID().getEventNumber());

// Fire Mission Index
assertEquals(55, fPdu.getFireMissionIndex());

// Location
assertEquals(3434174.675, fPdu.getLocationInWorldCoordinates().getX(), 0.001);
assertEquals(700499.234, fPdu.getLocationInWorldCoordinates().getY(), 0.001);
assertEquals(5310970.613, fPdu.getLocationInWorldCoordinates().getZ(), 0.001);

// Descriptor
ExpendableDescriptor expendableDesc = (ExpendableDescriptor) fPdu.getDescriptor();

assertEquals(8, expendableDesc.getExpendableType().getEntityKind());
assertEquals(2, expendableDesc.getExpendableType().getDomain());
assertEquals(57, expendableDesc.getExpendableType().getCountry());
assertEquals(5, expendableDesc.getExpendableType().getCategory());
assertEquals(6, expendableDesc.getExpendableType().getSubcategory());
assertEquals(8, expendableDesc.getExpendableType().getSpecific());
assertEquals(8, expendableDesc.getExpendableType().getExtra());

assertEquals(0, expendableDesc.getPadding());

// Velocity
assertEquals(4, fPdu.getVelocity().getX(), 0);
assertEquals(5, fPdu.getVelocity().getY(), 0);
assertEquals(6, fPdu.getVelocity().getZ(), 0);

// Range
assertEquals(55.5, fPdu.getRange(), 0.001);
}
}
Binary file not shown.
Binary file not shown.