Skip to content
Snippets Groups Projects
Commit d3b1406f authored by jonathanboron's avatar jonathanboron
Browse files

HW4 update 3, modification to PduReceiver

parent 8958ae7f
No related branches found
No related tags found
No related merge requests found
......@@ -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...");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment