Skip to content
Snippets Groups Projects
Commit 78fed6a9 authored by John Furr's avatar John Furr
Browse files

Added javadocs (really lame ones) and cleaned up code

parent 1b9b18c9
No related branches found
No related tags found
No related merge requests found
......@@ -43,6 +43,12 @@ public class FDCSendRecieve {
}
}
/**
* This would be the sending Run method. Takes in several PDUs and for each one has a switch statement ready for it.
* @param pdupass
* @throws UnknownHostException
* @throws IOException
*/
public void run(Pdu... pdupass) throws UnknownHostException, IOException {
List<Pdu> generatedPdus = new ArrayList<>();
......@@ -111,6 +117,13 @@ public class FDCSendRecieve {
}
}
/**
* Main function takes no specific arguments, but is the recieving portion of the code. Once it hears a specific type of PDU it creates another and sends it to the Run function
* called sender created on line 130 (2nd statement in the main function)
* @param args
* @throws IOException
* @throws InterruptedException
*/
public static void main(String[] args) throws IOException, InterruptedException {
DisTime disTime = DisTime.getInstance();
......@@ -122,9 +135,9 @@ public class FDCSendRecieve {
FDCespdu.setMarking(marking);
FDCespdu.setExerciseID((short) 1);
EntityID FDCID = FDCespdu.getEntityID();
FDCID.setSite(1); // 0 is apparently not a valid site number, per the spec
FDCID.setSite(1);
FDCID.setApplication(1);
FDCID.setEntity(1); //change for each person I think??? - JMF
FDCID.setEntity(1);
EntityType entityType = FDCespdu.getEntityType();
//
//Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21
......@@ -147,12 +160,12 @@ public class FDCSendRecieve {
sender.run(FDCespdu); //sends inital here I am and who I am
//Set up other players to look for:
EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below
EntityID OBSEntityID = new EntityID();
OBSEntityID.setEntity(2);
OBSEntityID.setApplication(1);
OBSEntityID.setSite(1);
EntityID TGTEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below
EntityID TGTEntityID = new EntityID();
TGTEntityID.setEntity(3);
TGTEntityID.setApplication(1);
TGTEntityID.setSite(1);
......@@ -232,13 +245,14 @@ public class FDCSendRecieve {
}
if (currentPduType == 16) //Action request
{
// Action response is sending a Null PDU, not sure why...
// Action response is sending a Null PDU, not sure why... so we will use the acknowledge pdu instead
AcknowledgePdu ack = new AcknowledgePdu();
ack.setExerciseID((short) 1);
ack.setRequestID((long) 1);
timestamp = disTime.getDisAbsoluteTimestamp();
ack.setTimestamp(timestamp);
//Creating a fire PDU
FirePdu fire = new FirePdu();
fire.setExerciseID((short) 1);
fire.setFireMissionIndex(1000);
......@@ -257,7 +271,8 @@ public class FDCSendRecieve {
ack.setRequestID((long) 1);
timestamp = disTime.getDisAbsoluteTimestamp();
ack.setTimestamp(timestamp);
//and the freeze PDU being created to stop everything.
StopFreezePdu stop = new StopFreezePdu();
stop.setExerciseID((short) 1);
stop.setRequestID((long) 1);
......@@ -270,10 +285,10 @@ public class FDCSendRecieve {
}
}
} catch (IOException e) {
System.out.println("Problem with FDC.PduReceiver, see exception trace:");
System.out.println("Problem with FDCSendRecieve, see exception trace:");
System.out.println(e);
} finally {
System.out.println("FDC.PduReceiver complete. - OUT!");
System.out.println("FDC SendReceive complete. - OUT!");
}
}
......
......@@ -31,6 +31,11 @@ public class OBSSendRecieve1 {
DisTime disTime = DisTime.getInstance();
int transmission =1;
/**
* Constructor just got to construct.
* @param port
* @param multicast
*/
public OBSSendRecieve1(int port, String multicast) {
this.sentBufferList = new ArrayList<>();
try {
......@@ -44,6 +49,12 @@ public class OBSSendRecieve1 {
}
}
/**
* This would be the sending Run method. Takes in several PDUs and for each one has a switch statement ready for it.
* @param pdupass
* @throws UnknownHostException
* @throws IOException
*/
public void run(Pdu... pdupass) throws UnknownHostException, IOException {
List<Pdu> generatedPdus = new ArrayList<>();
......@@ -68,14 +79,7 @@ public class OBSSendRecieve1 {
short currentPduType = pdu.getPduType();
System.out.println("in observer sender, processing PDU type: " + currentPduType);
// String currentPduTypeName = pdu.getClass().getName();
// short currentProtocolFamilyID = pdu.getProtocolFamily();
// String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName();
// Loop through all the enumerated PDU types, create a PDU for each type,
// and add that PDU to a list.
//System.out.println(pdu);
//Change the switch statement to the currentPduType from the recieve portion, then when a packet we want comes in, send the CASE file.
switch (currentPduType) // using enumeration values from edu.nps.moves.disenum.*
{
......@@ -83,22 +87,6 @@ public class OBSSendRecieve1 {
aPdu = pdu;
break;
// case COMMENT:
// aPdu = new CommentPdu();
// break;
//
// case 2: //FIRE
// aPdu = pdu;
// break;
//
// case DETONATION:
// aPdu = new DetonationPdu();
// break;
//
// case 15: //AcknowledgePdu
// aPdu = pdu;
// break;
////
case 16: //ACTION_REQUEST:
aPdu = new ActionRequestPdu();
break;
......@@ -107,11 +95,7 @@ public class OBSSendRecieve1 {
aPdu = pdu;
break;
// case 14:
// aPdu = pdu;
// break;
default:
//add some shit that makes sense here.
System.out.print("PDU of type " + pdu + " not supported by Observer, created or sent ");
System.out.println();
}
......@@ -132,28 +116,19 @@ public class OBSSendRecieve1 {
buffer = baos.toByteArray();
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT);
socket.send(packet);
//sentBuffer[sentBuffer.length] = aPdu.getTimestamp();
sentBufferList.add(aPdu.getTimestamp());
System.out.println("Observer Sent PDU of type " + aPdu.getClass().getName()+"/n");
System.out.println("Observer Sent PDU of type " + aPdu.getClass().getName()+"\n");
}
}
/**
* Main function takes no specific arguments, but is the recieving portion of the code. Once it hears a specific type of PDU it creates another and sends it to the Run function
* called sender created on line 136 (2nd statement in the main function)
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
DisTime disTime = DisTime.getInstance();
//turns on the sender code - might need to move around down into the recieve with the if statements...
//
// ORIGINAL SENDING CODE MAIN CLASS:
//
//
// if (args.length == 2) {
// FDCSendRecieve sender = new FDCSendRecieve(Integer.parseInt(args[0]), args[1]);
// // sender.run(); //needs to be sender.run(pdu)
// } else {
// System.out.println("Usage: PduSender <port> <multicast group>");
// System.out.println("Default: PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS);
// FDCSendRecieve sender = new FDCSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS);
// sender.run();
// }
//
// Inital Hello world from entity:
......@@ -168,7 +143,7 @@ public class OBSSendRecieve1 {
EntityID OBSID = OBSespdu.getEntityID();
OBSID.setSite(1); // 0 is apparently not a valid site number, per the spec
OBSID.setApplication(1);
OBSID.setEntity(2); //change for each person I think??? - JMF
OBSID.setEntity(2);
EntityType entityType = OBSespdu.getEntityType();
//
//Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21
......@@ -187,7 +162,6 @@ public class OBSSendRecieve1 {
OBSespdu.setEntityLocation(location);
int timestamp = disTime.getDisAbsoluteTimestamp();
OBSespdu.setTimestamp(timestamp);
//FDCespdu.setTimestamp(System.currentTimeMillis());
sender.run(OBSespdu); //sends inital here I am and who I am
//other player to look out for:
......@@ -212,7 +186,6 @@ public class OBSSendRecieve1 {
short currentPduType; //will use the curentPduType as the check for sending other packets.
try {
// TODO: Change the line below to make sense for each class
System.out.println("Observer is in the OP and looking for targets...\n\n");
socket = new MulticastSocket(MULTICAST_PORT);
address = InetAddress.getByName(MULTICAST_GROUP);
......@@ -227,9 +200,6 @@ public class OBSSendRecieve1 {
packet = new DatagramPacket(buffer, buffer.length); // reset
socket.receive(packet);
//
//TODO: NEED IF STATEMENT IF THE SENDER IS THIS CLASS TO DELETE.
//
String marking2 = new String();
Pdu pdu = factory.createPdu(packet.getData());
......@@ -239,7 +209,6 @@ public class OBSSendRecieve1 {
System.out.println("recieved Stop/Freeze packet...");
return;
}
// pdu.setExerciseID((short)5);
if (pdu != null) {
if (sentBufferList.contains(pdu.getTimestamp())) {
pdu = null;
......@@ -251,7 +220,7 @@ public class OBSSendRecieve1 {
EntityStatePdu pdu2 = (EntityStatePdu) pdu;
marking2 = pdu2.getMarking().getCharactersString();
}
//Keep adding any if statements as needed for the class you are building.
StringBuilder message = new StringBuilder();
message.append("received DIS PDU: ");
message.append("pduType ");
......
......@@ -31,6 +31,11 @@ public class TGTSendRecieve {
DisTime disTime = DisTime.getInstance();
int transmission = 1;
/**
* Constructor just got to construct.
* @param port
* @param multicast
*/
public TGTSendRecieve(int port, String multicast) {
this.sentBufferList = new ArrayList<>();
try {
......@@ -44,6 +49,12 @@ public class TGTSendRecieve {
}
}
/**
* This would be the sending Run method. Takes in several PDUs and for each one has a switch statement ready for it.
* @param pdupass
* @throws UnknownHostException
* @throws IOException
*/
public void run(Pdu... pdupass) throws UnknownHostException, IOException {
List<Pdu> generatedPdus = new ArrayList<>();
......@@ -104,10 +115,16 @@ public class TGTSendRecieve {
socket.send(packet);
//sentBuffer[sentBuffer.length] = aPdu.getTimestamp();
sentBufferList.add(aPdu.getTimestamp());
System.out.println("Observer Sent PDU of type " + aPdu.getClass().getName() + "/n");
System.out.println("Target Sent PDU of type " + aPdu.getClass().getName() + "\n");
}
}
/**
* Main function takes no specific arguments, but is the recieving portion of the code. Once it hears a specific type of PDU it creates another and sends it to the Run function
* called sender created on line 135 (2nd statement in the main function)
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
DisTime disTime = DisTime.getInstance();
//turns on the sender code - might need to move around down into the recieve with the if statements...
......@@ -125,7 +142,7 @@ public class TGTSendRecieve {
EntityID OBSID = TGTespdu.getEntityID();
OBSID.setSite(1); // 0 is apparently not a valid site number, per the spec
OBSID.setApplication(1);
OBSID.setEntity(3); //change for each person I think??? - JMF
OBSID.setEntity(3);
EntityType entityType = TGTespdu.getEntityType();
//
//Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21
......@@ -168,7 +185,6 @@ public class TGTSendRecieve {
short currentPduType; //will use the curentPduType as the check for sending other packets.
try {
// TODO: Change the line below to make sense for each class
System.out.println("Russian T72 out on the prowl...\n\n");
socket = new MulticastSocket(MULTICAST_PORT);
address = InetAddress.getByName(MULTICAST_GROUP);
......@@ -183,10 +199,7 @@ public class TGTSendRecieve {
packet = new DatagramPacket(buffer, buffer.length); // reset
socket.receive(packet);
//
//TODO: NEED IF STATEMENT IF THE SENDER IS THIS CLASS TO DELETE.
//
String marking2 = new String();
Pdu pdu = factory.createPdu(packet.getData());
currentPduType = pdu.getPduType();
......@@ -195,7 +208,6 @@ public class TGTSendRecieve {
System.out.println("recieved Stop/Freeze packet...");
return;
}
// pdu.setExerciseID((short)5);
if (pdu != null) {
if (sentBufferList.contains(pdu.getTimestamp())) {
pdu = null;
......@@ -207,7 +219,6 @@ public class TGTSendRecieve {
EntityStatePdu pdu2 = (EntityStatePdu) pdu;
marking2 = pdu2.getMarking().getCharactersString();
}
//Keep adding any if statements as needed for the class you are building.
StringBuilder message = new StringBuilder();
message.append("received DIS PDU: ");
message.append("pduType ");
......
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