From f37994fa47a7370d298830cfcd35cb2178d353cf Mon Sep 17 00:00:00 2001 From: FO Date: Thu, 29 Feb 2024 11:10:38 +0100 Subject: [PATCH] set pdu type for IFF, extends correct pdu family, avoid layer 2 null pointer exception and corrected system mode size to a byte according to the DIS 7 Standard --- src/main/java/edu/nps/moves/dis7/IFFPdu.java | 8 +++++++- src/main/java/edu/nps/moves/dis7/SystemIdentifier.java | 10 +++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/edu/nps/moves/dis7/IFFPdu.java b/src/main/java/edu/nps/moves/dis7/IFFPdu.java index 8aba09b..f4f9c3d 100644 --- a/src/main/java/edu/nps/moves/dis7/IFFPdu.java +++ b/src/main/java/edu/nps/moves/dis7/IFFPdu.java @@ -9,7 +9,7 @@ * * @author fo */ -public class IFFPdu extends Pdu implements Serializable { +public class IFFPdu extends DistributedEmissionsFamilyPdu implements Serializable { /** * Basic System Data. This is the only layer that is required to be included @@ -30,6 +30,11 @@ public class IFFPdu extends Pdu implements Serializable { // protected IFFLayer5 layer5 = null; // protected IFFLayer6 layer6 = null; // protected IFFLayer7 layer7 = null; + + public IFFPdu() { + setPduType((short) 28); + } + public int getMarshalledSize() { int marshalSize = 0; marshalSize = super.getMarshalledSize(); @@ -83,6 +88,7 @@ public void unmarshal(DataInputStream dis) { try { layer1.unmarshal(dis); if (isLayerPresent(2)) { + layer2 = new IFFLayer2(); layer2.unmarshal(dis); } } // end try diff --git a/src/main/java/edu/nps/moves/dis7/SystemIdentifier.java b/src/main/java/edu/nps/moves/dis7/SystemIdentifier.java index f7f1d2e..924bbe5 100644 --- a/src/main/java/edu/nps/moves/dis7/SystemIdentifier.java +++ b/src/main/java/edu/nps/moves/dis7/SystemIdentifier.java @@ -44,7 +44,7 @@ public int getMarshalledSize() { marshalSize = marshalSize + 2; // systemType marshalSize = marshalSize + 2; // systemName - marshalSize = marshalSize + 2; // systemMode + marshalSize = marshalSize + 1; // systemMode marshalSize = marshalSize + changeOptions.getMarshalledSize(); // changeOptions return marshalSize; @@ -86,7 +86,7 @@ public void marshal(DataOutputStream dos) { try { dos.writeShort((short) systemType); dos.writeShort((short) systemName); - dos.writeShort((short) systemMode); + dos.writeByte((byte) systemMode); changeOptions.marshal(dos); } // end try catch (Exception e) { @@ -98,7 +98,7 @@ public void unmarshal(DataInputStream dis) { try { systemType = (int) dis.readUnsignedShort(); systemName = (int) dis.readUnsignedShort(); - systemMode = (int) dis.readUnsignedShort(); + systemMode = (int) dis.readUnsignedByte(); changeOptions.unmarshal(dis); } // end try catch (Exception e) { @@ -118,7 +118,7 @@ public void unmarshal(DataInputStream dis) { public void marshal(java.nio.ByteBuffer buff) { buff.putShort((short) systemType); buff.putShort((short) systemName); - buff.putShort((short) systemMode); + buff.put((byte) systemMode); changeOptions.marshal(buff); } // end of marshal method @@ -133,7 +133,7 @@ public void marshal(java.nio.ByteBuffer buff) { public void unmarshal(java.nio.ByteBuffer buff) { systemType = (int) (buff.getShort() & 0xFFFF); systemName = (int) (buff.getShort() & 0xFFFF); - systemMode = (int) (buff.getShort() & 0xFFFF); + systemMode = (int) (buff.get()& 0xFF); changeOptions.unmarshal(buff); } // end of unmarshal method