diff --git a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Boron/BoronPduReceiver.java b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Boron/BoronPduReceiver.java index 1f78bf5cfc33233a16f394063cd92ca97e30ef4f..413b297f87a55e1acfa3c0010be3e2e440600850 100644 --- a/assignments/src/MV3500Cohort2019JulySeptember/homework4/Boron/BoronPduReceiver.java +++ b/assignments/src/MV3500Cohort2019JulySeptember/homework4/Boron/BoronPduReceiver.java @@ -5,6 +5,7 @@ import java.io.*; import edu.nps.moves.dis7.*; import edu.nps.moves.dis7.enumerations.*; +import static edu.nps.moves.dis7.enumerations.DISPDUType.*; import edu.nps.moves.dis7.util.*; public class BoronPduReceiver @@ -46,24 +47,35 @@ public class BoronPduReceiver Pdu pdu = factory.createPdu(packet.getData()); if (pdu != null) { - DISPDUType currentPduType = pdu.getPduType(); //short currentPduType = pdu.getPduType(); - String currentPduTypeName = pdu.getClass().getName(); - DISProtocolFamily currentProtocolFamilyID = pdu.getProtocolFamily(); //short currentProtocolFamilyID = pdu.getProtocolFamily(); - String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); + DISPDUType currentPduType = pdu.getPduType(); //short currentPduType = pdu.getPduType(); + String currentPduTypeName = pdu.getClass().getName(); + DISProtocolFamily currentProtocolFamilyID = pdu.getProtocolFamily(); //short currentProtocolFamilyID = pdu.getProtocolFamily(); + String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); - StringBuilder message = new StringBuilder(); - message.append("received DIS PDU "); - if (currentPduType.getValue() < 10) - message.append(" "); - message.append(currentPduType.getValue()); - String currentPduTypePadded = String.format("%-34s", currentPduType); // - indicates right padding of whitespace - message.append(" " ).append(currentPduTypePadded); - String currentPduTypeNamePadded = String.format("%-49s", currentPduTypeName); // - indicates right padding of whitespace - message.append(" of type ").append(currentPduTypeNamePadded); // package.class name - message.append(" (protocolFamily ").append(currentProtocolFamilyID); -// message.append(" ").append(currentPduFamilyName); // class name is also available - message.append(")"); - System.out.println(message.toString()); + StringBuilder message = new StringBuilder(); + message.append("received DIS PDU "); + if (currentPduType.getValue() < 10) + { + message.append(" "); + } + message.append(currentPduType.getValue()); + String currentPduTypePadded = String.format("%-34s", currentPduType); // - indicates right padding of whitespace + message.append(" " ).append(currentPduTypePadded); + String currentPduTypeNamePadded = String.format("%-49s", currentPduTypeName); // - indicates right padding of whitespace + message.append(" of type ").append(currentPduTypeNamePadded); // package.class name + message.append(" (protocolFamily ").append(currentProtocolFamilyID); +// message.append(" ").append(currentPduFamilyName); // class name is also available + message.append(")"); + System.out.println(message.toString()); + + if (currentPduType == ENTITY_STATE) + { + EntityStatePdu espdu = new EntityStatePdu(); + espdu = (EntityStatePdu) pdu; + + Vector3Double location = espdu.getEntityLocation(); + System.out.println("Entity is at position: x = " + location.getX() + ", y = " + location.getY() + ", z = " + location.getZ()); + } } else System.out.println("received packet but pdu is null, packet.getData().length=" + packet.getData().length + ", error...");