diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework4/White/working/PDUReciever.java b/assignments/src/MV3500Cohort2020JulySeptember/homework4/White/working/PDUReciever.java index a0ac43f61913b35cbee0f3dbd4b09ff854065405..91601d5cba452dc256c3694658760c282e6a1c23 100755 --- a/assignments/src/MV3500Cohort2020JulySeptember/homework4/White/working/PDUReciever.java +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework4/White/working/PDUReciever.java @@ -102,15 +102,31 @@ public class PDUReciever { else if (aPdu instanceof CommentReliablePdu){ System.out.println(receiptMessage); ArrayList<VariableDatum> payloadList = (ArrayList)((CommentReliablePdu) aPdu).getVariableDatumRecords(); - if (!payloadList.isEmpty()) - System.out.print (" messages: "); - for (VariableDatum variableDatum : payloadList) - { - String nextComment = new String(variableDatum.getVariableDatumValue()); // convert byte[] to String - System.out.print (" \"" + nextComment + "\""); - System.out.println(); + if (!payloadList.isEmpty()) + System.out.print (" messages: "); + for (VariableDatum variableDatum : payloadList) + { + String nextComment = new String(variableDatum.getVariableDatumValue()); // convert byte[] to String + System.out.print (" \"" + nextComment + "\""); + System.out.println(); + } + } + else if (aPdu instanceof ResupplyOfferPdu){ + System.out.println(receiptMessage); + EntityID receiverID = ((ResupplyOfferPdu) aPdu).getReceivingEntityID(); + EntityID supplierID = ((ResupplyOfferPdu) aPdu).getSupplyingEntityID(); + List<SupplyQuantity> supplyList = ((ResupplyOfferPdu) aPdu).getSupplies(); + System.out.println(" Resupply Offer from Entity [" + supplierID.getSiteID() + ", "+ supplierID.getApplicationID() + ", " + supplierID.getEntityID() + "] to resupply Entity ["+ receiverID.getSiteID() + ", "+ receiverID.getApplicationID() + ", " + receiverID.getEntityID() + "]" ); + for (int i = 0; i < supplyList.size(); i++){ + SupplyQuantity supplyQ = supplyList.get(i); + EntityType entityType = supplyQ.getSupplyType(); + float supplyQuantity = supplyQ.getQuantity(); + System.out.println(" Supplies Offered: [Quantity: " + supplyQuantity + ", Type: " +entityType.getEntityKind() + " "+ entityType.getDomain() + " "+ entityType.getCountry() + " "+ entityType.getCategory() + " "+ entityType.getSubCategory() + " "+ entityType.getSpecific() + " ]"); + + } } - } //OTHER PDU TYPES + + //OTHER PDU TYPES else { System.out.println(receiptMessage); } diff --git a/assignments/src/MV3500Cohort2020JulySeptember/homework4/White/working/WhiteSimulation.java b/assignments/src/MV3500Cohort2020JulySeptember/homework4/White/working/WhiteSimulation.java index c2799bdbf8120239ba8b14ed82a2a6e0187d0a10..f9cd8fd72a98c9356b3934a346e39acaa4d5e167 100644 --- a/assignments/src/MV3500Cohort2020JulySeptember/homework4/White/working/WhiteSimulation.java +++ b/assignments/src/MV3500Cohort2020JulySeptember/homework4/White/working/WhiteSimulation.java @@ -16,6 +16,7 @@ import java.net.InetAddress; import java.net.MulticastSocket; import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.List; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -226,8 +227,10 @@ public class WhiteSimulation double[] loc3 = CoordinateConversions.getXYZfromLatLonDegrees(36.600757, -121.869309, 0 );//NPS Corner by lake EntityID entityID_1 = new EntityID(); - entityID_1.setSiteID(1).setApplicationID(2).setEntityID(3); // made-up example ID + entityID_1.setSiteID(1).setApplicationID(2).setEntityID(3); // made-up example ID + + EntityStatePdu entityStatePdu = pduFactory.makeEntityStatePdu(); entityStatePdu.setEntityID(entityID_1); @@ -324,12 +327,30 @@ public class WhiteSimulation EntityID HEID = new EntityID(); HEID.setEntityID(1); firePdu.setMunitionExpendibleID(HEID); + + CommentReliablePdu bmpDestroyedComment = pduFactory.makeCommentReliablePdu("BMP2 DESTROYED BY LAV25-A2 AFTER TWO BURSTS OF 25mm HEI-T ON TARGET"); CommentReliablePdu bmpSightedComment = pduFactory.makeCommentReliablePdu("LAV25-A2 ACQUIRES TARGET BMP2 WITHIN FIRING DISTANCE"); //if(eloc1.getX()) - + + + ResupplyOfferPdu resupplyOfferPdu = pduFactory.makeResupplyOfferPdu(); + ArrayList<SupplyQuantity> pSupplies = new ArrayList<SupplyQuantity>(); + SupplyQuantity ammoSupplyQ = new SupplyQuantity(); + ammoSupplyQ.setSupplyType(HEType); + ammoSupplyQ.setQuantity(500); + + //EntityType ammoSupply = new EntityType(); + // ammoSupply.setEntityKind(EntityKind.MUNITION); + //ammoSupply.setDomain(Entity) + //ammoSupplyQ.setSupplyType(EntityType.) + pSupplies.add(ammoSupplyQ); + resupplyOfferPdu.setSupplies(pSupplies); + resupplyOfferPdu.setReceivingEntityID(lavID); + resupplyOfferPdu.setSupplyingEntityID(bmpID); + // should we customize this munition? what is it for your simulation? while (loopCount < MAX_LOOP_COUNT) // loop the simulation while allowed, can set additional conditions to break @@ -397,8 +418,10 @@ public class WhiteSimulation sendPDU(entityStatePdu2); if (fireBool) sendPDU(firePdu); - if (destBool) + if (destBool){ sendPDU(bmpDestroyedComment); + sendPDU(resupplyOfferPdu); + } System.out.println ("... PDUs successfully sent");