Skip to content

Commit

Permalink
set pdu type for IFF, extends correct pdu family, avoid layer 2 null …
Browse files Browse the repository at this point in the history
…pointer exception and corrected system mode size to a byte according to the DIS 7 Standard
  • Loading branch information
fo-ifad committed Feb 29, 2024
1 parent 7aa0efa commit f37994f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/main/java/edu/nps/moves/dis7/IFFPdu.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -83,6 +88,7 @@ public void unmarshal(DataInputStream dis) {
try {
layer1.unmarshal(dis);
if (isLayerPresent(2)) {
layer2 = new IFFLayer2();
layer2.unmarshal(dis);
}
} // end try
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/edu/nps/moves/dis7/SystemIdentifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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

Expand All @@ -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

Expand Down

0 comments on commit f37994f

Please sign in to comment.