Skip to content
Snippets Groups Projects
Commit cc93d178 authored by courtneythomerson's avatar courtneythomerson
Browse files

Cain Thomerson - COMPLETED

parent 7e852ad6
No related branches found
No related tags found
No related merge requests found
......@@ -143,8 +143,8 @@ public class C_T_EspduRequestingUnit {
ResupplyOfferPdu resupplyOffer = new ResupplyOfferPdu();
//Create a Resupply Received
ResupplyReceivedPdu resupplyReceived = new ResupplyReceivedPdu();
AcknowledgePdu acknowledge = new AcknowledgePdu();
//Booleans for dialogue
boolean connectionMade = false;
boolean serviceRequestAcknowledged = false;
......@@ -187,7 +187,7 @@ public class C_T_EspduRequestingUnit {
socket.send(packet);
}
// Send every 1 sec. Otherwise all this will be all over in a fraction of a second.
//Thread.sleep(1000); // msec
Thread.sleep(1000); // msec
System.out.println("SENDING ENTITY STATE INFORMATION");
System.out.println("\tEID=[" + entityID.getSite() + "," + entityID.getApplication() + "," + entityID.getEntity() + "]");
......@@ -240,7 +240,7 @@ public class C_T_EspduRequestingUnit {
socket.send(packet);
}
// Send every 1 sec. Otherwise all this will be all over in a fraction of a second.
//Thread.sleep(1000); // msec
Thread.sleep(1000); // msec
//Print out the details on the service reuqest being sent
System.out.println("SENDING SERVICE REQUEST");
......@@ -285,39 +285,32 @@ public class C_T_EspduRequestingUnit {
}
}
}
while(!serviceRequestComplete && serviceRequestAcknowledged)
{
while(!serviceRequestComplete && serviceRequestAcknowledged) {
//DIS Time must be used for this because DIS requires it.
timestamp = disTime.getDisAbsoluteTimestamp();
resupplyReceived.setTimestamp(timestamp);
resupplyReceived.setReceivingEntityID(resupplyOffer.getReceivingEntityID());
resupplyReceived.setSupplyingEntityID(resupplyOffer.getSupplyingEntityID());
resupplyReceived.setSupplies(resupplyOffer.getSupplies());
// Marshal out the Resupply Received PDU object to a byte array
ByteArrayOutputStream baosResupplyReceived = new ByteArrayOutputStream();
DataOutputStream dosResupplyReceived = new DataOutputStream(baosResupplyReceived);
resupplyReceived.marshal(dosResupplyReceived);
acknowledge.setTimestamp(timestamp);
// Marshal out the Service Request PDU object to a byte array
ByteArrayOutputStream baosAcknowledge = new ByteArrayOutputStream();
DataOutputStream dosAcknowledge = new DataOutputStream(baosAcknowledge);
acknowledge.marshal(dosAcknowledge);
//The byte array here is the packet in DIS format. We put that into a
// datagram and send it.
byte[] dataResupplyReceived = baosResupplyReceived.toByteArray();
byte[] dataAcknowledge = baosAcknowledge.toByteArray();
broadcastAddresses = getBroadcastAddresses();
Iterator broadcastIterator = broadcastAddresses.iterator();
while (broadcastIterator.hasNext()) {
InetAddress broadcast = (InetAddress) broadcastIterator.next();
DatagramPacket packet = new DatagramPacket(dataResupplyReceived, dataResupplyReceived.length, broadcast, port);
DatagramPacket packet = new DatagramPacket(dataAcknowledge, dataAcknowledge.length, broadcast, port);
socket.send(packet);
}
// Send every 1 sec. Otherwise all this will be all over in a fraction of a second.
//Thread.sleep(1000); // msec
Thread.sleep(1000); // msec
System.out.println("SENDING RESUPPLY RECEIVED");
System.out.println("\tReceiving Entity ID:[" + resupplyReceived.getReceivingEntityID().getSite() + ", " + resupplyReceived.getReceivingEntityID().getApplication() + ", " + resupplyReceived.getReceivingEntityID().getEntity() + "]");
System.out.println("\tSupplying Entity ID: [" + resupplyReceived.getSupplyingEntityID().getSite() + ", " + resupplyReceived.getSupplyingEntityID().getApplication() + ", " + resupplyReceived.getSupplyingEntityID().getEntity() + "]");
//Print out the details on the service reuqest being sent
System.out.println("SENDING ACKNOWLEDGE\n");
//Prepare to receive a package
byte buffer[] = new byte[MAX_PDU_SIZE];
......@@ -332,7 +325,6 @@ public class C_T_EspduRequestingUnit {
Pdu aPdu = (Pdu) iterator.next();
if (aPdu instanceof AcknowledgePdu) {
System.out.println("RECEIVED PACKET");
System.out.println("\tPacket Type: " + aPdu.getClass().getName());
......@@ -347,7 +339,7 @@ public class C_T_EspduRequestingUnit {
break;
}
}
} catch (IOException | InterruptedException e) {
} catch (IOException | InterruptedException e) {
System.out.println("Problem with DisExamples.EspduSender, see exception trace:");
System.out.println(e);
}
......
......@@ -191,7 +191,6 @@ public class C_T_EspduSupplyerUnit {
if (eType.getEntityKind() != supplyerUnitEsPdu.getEntityType().getEntityKind()) {
while (broadcastIterator.hasNext()) {
InetAddress broadcast = (InetAddress) broadcastIterator.next();
DatagramPacket packet = new DatagramPacket(data, data.length, broadcast, port);
socket.send(packet);
}
......@@ -208,7 +207,7 @@ public class C_T_EspduSupplyerUnit {
while (!serviceRequestReceived && someoneWantsToTalk) {
//DIS Time must be used for this because DIS requires it.
timestamp = disTime.getDisAbsoluteTimestamp();
supplyerUnitEsPdu.setTimestamp(timestamp);
resupplyOffer.setTimestamp(timestamp);
//The byte array here is the packet in DIS format. We put that into a
// datagram and send it.
......@@ -259,18 +258,21 @@ public class C_T_EspduSupplyerUnit {
System.out.println("SENDING PACKET");
System.out.println("\tPacket Type: Resupply Offer");
System.out.println("\tReceiving Entity ID: [" + resupplyOffer.getReceivingEntityID().getSite() + ", " + resupplyOffer.getReceivingEntityID().getApplication() + ", " + resupplyOffer.getReceivingEntityID().getEntity() + "]");
System.out.println("\tSupplying Entity ID: [" + resupplyOffer.getSupplyingEntityID().getSite() + ", " + resupplyOffer.getSupplyingEntityID().getApplication() + ", " + resupplyOffer.getSupplyingEntityID().getEntity() + "]");
System.out.println("\tSupplying Entity ID: [" + resupplyOffer.getSupplyingEntityID().getSite() + ", " + resupplyOffer.getSupplyingEntityID().getApplication() + ", " + resupplyOffer.getSupplyingEntityID().getEntity() + "]\n");
serviceRequestReceived = true;
}
}
}
}
while (!serviceRequestComplete && serviceRequestReceived) {
System.out.println("I am in the service request complete loop");
while (!serviceRequestComplete && serviceRequestReceived ) {
//DIS Time must be used for this because DIS requires it.
timestamp = disTime.getDisAbsoluteTimestamp();
acknowledge.setTimestamp(timestamp);
//The byte array here is the packet in DIS format. We put that into a
// datagram and send it.
//byte[] data = baos.toByteArray();
broadcastAddresses = getBroadcastAddresses();
Iterator broadcastIterator = broadcastAddresses.iterator();
......@@ -282,20 +284,15 @@ public class C_T_EspduSupplyerUnit {
List<Pdu> pduBundle = pduFactory.getPdusFromBundle(receivingPacket.getData());
Iterator receivingIterator = pduBundle.iterator();
System.out.println("I am about to start the while loop");
while (receivingIterator.hasNext()) {
while (receivingIterator.hasNext()) {
Pdu aPdu = (Pdu) receivingIterator.next();
System.out.println("I am in the while loop");
System.out.println("got PDU of type: " + aPdu.getClass().getName());
if (aPdu instanceof ResupplyReceivedPdu) {
System.out.println("I know I received a ResupplyReceivedPDU");
EntityID receivingEntityID = ((ResupplyReceivedPdu) aPdu).getReceivingEntityID();
EntityID supplyingEntityID = ((ResupplyReceivedPdu) aPdu).getSupplyingEntityID();
if (aPdu instanceof AcknowledgePdu) {
System.out.println("RECEIVED PACKET");
System.out.println("\tReceiving Entity ID:[" + receivingEntityID.getSite() + ", " + receivingEntityID.getApplication() + ", " + receivingEntityID.getEntity() + "]");
System.out.println("\tSupplying Entity ID: [" + supplyingEntityID.getSite() + ", " + supplyingEntityID.getApplication() + ", " + supplyingEntityID.getEntity() + "]");
System.out.println("\tPacket Type: " + aPdu.getClass().getName());
// Marshal out the Service Request PDU object to a byte array
ByteArrayOutputStream baosAcknowledge = new ByteArrayOutputStream();
......@@ -309,12 +306,14 @@ public class C_T_EspduSupplyerUnit {
DatagramPacket packet = new DatagramPacket(dataAcknowledge, dataAcknowledge.length, broadcast, port);
socket.send(packet);
}
System.out.println("SENDING ACKNOWLEDGE PACKET");
serviceRequestComplete = true;
System.out.println("SENDING PACKET");
System.out.println("\tPacket Type: Acknowledge");
serviceRequestComplete = true;
}
}
}
} // end while
} // End try
catch (IOException e) {
......
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