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

All classes work, sends all data, gets all data, and closes when complete.

parent 95e15cc6
No related branches found
No related tags found
No related merge requests found
......@@ -285,7 +285,6 @@ public class OBSSendRecieve1 {
if (currentPduType == 3) //Detination
{
System.out.println("In detination if");
CommentPdu comment = new CommentPdu();
comment.setExerciseID((short) 1);
comment.setOriginatingEntityID(TGTEntityID);
......
......@@ -29,7 +29,7 @@ public class TGTSendRecieve {
public long[] sentBuffer = new long[100];
public static List sentBufferList;
DisTime disTime = DisTime.getInstance();
int transmission =1;
int transmission = 1;
public TGTSendRecieve(int port, String multicast) {
this.sentBufferList = new ArrayList<>();
......@@ -48,12 +48,12 @@ public class TGTSendRecieve {
List<Pdu> generatedPdus = new ArrayList<>();
Pdu aPdu = null;
if(transmission ==1){
System.out.println("\nInitalizing OP coms...");
if (transmission == 1) {
System.out.println("\nTarget is rolling out...");
transmission++;
}
if(transmission>1){
System.out.println("\nObserver Sending traffic...");
if (transmission > 1) {
System.out.println("\nDeath from above everywhere! (sending function started)...");
}
// Send the PDUs we created
InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS);
......@@ -67,15 +67,8 @@ public class TGTSendRecieve {
}
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.
System.out.println("in Target sender, processing PDU type: " + currentPduType);
//
switch (currentPduType) // using enumeration values from edu.nps.moves.disenum.*
{
......@@ -83,33 +76,10 @@ public class TGTSendRecieve {
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;
case 22: //CommentPdu
case 3: //detination PDU
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 ");
......@@ -134,61 +104,47 @@ 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("Observer Sent PDU of type " + aPdu.getClass().getName() + "/n");
}
}
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:
//
TGTSendRecieve sender = new TGTSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender
EntityStatePdu OBSespdu = new EntityStatePdu();
EntityStatePdu TGTespdu = new EntityStatePdu();
Marking marking = new Marking();
marking.setCharactersString("Observer");
OBSespdu.setMarking(marking);
OBSespdu.setExerciseID((short) 1);
EntityID OBSID = OBSespdu.getEntityID();
marking.setCharactersString("Target");
TGTespdu.setMarking(marking);
TGTespdu.setExerciseID((short) 1);
EntityID OBSID = TGTespdu.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
EntityType entityType = OBSespdu.getEntityType();
OBSID.setEntity(3); //change for each person I think??? - JMF
EntityType entityType = TGTespdu.getEntityType();
//
//Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21
// https://www.sisostds.org/DesktopModules/Bring2mind/DMX/Download.aspx?Command=Core_Download&EntryId=42916&PortalId=0&TabId=105
//
entityType.setEntityKind((short) 1); // Platform (vs lifeform, munition, sensor, etc.) TGT=1, OBS = 1
entityType.setCountry(225); // USA TGT = 222 (Russia), OBS = 225
entityType.setCountry(222); // USA TGT = 222 (Russia), OBS = 225
entityType.setDomain((short) 1); // Land (vs air, surface, subsurface, space) both TGT and OBS are 1
entityType.setCategory((short) 40); // FDC TGT = 1, Tank OBS=40 OP
// entityType.setSubcategory((short) 12); // M1068 TGT = 2, T72 tank NONE FOR OP
// entityType.setSpec((short) 1); // M1068 w/ SICUP Tent NONE FOR TGT OR OP
entityType.setCategory((short) 1); // FDC TGT = 1, Tank OBS=40 OP
entityType.setSubcategory((short) 2); // M1068 TGT = 2, T72 tank NONE FOR OP
Vector3Double location = new Vector3Double();
location.setX(75.0); //TGT = 150 OBS = 75
location.setY(75.0); //TGT = 150 OBS = 75
location.setZ(50.0); //TGT = 20 OBS = 50
OBSespdu.setEntityLocation(location);
location.setX(150.0); //TGT = 150 OBS = 75
location.setY(150.0); //TGT = 150 OBS = 75
location.setZ(20.0); //TGT = 20 OBS = 50
TGTespdu.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
TGTespdu.setTimestamp(timestamp);
sender.run(TGTespdu); //sends inital here I am and who I am
//other player to look out for:
EntityID FDCEntityID = new EntityID();
......@@ -196,10 +152,10 @@ public class TGTSendRecieve {
FDCEntityID.setApplication(1);
FDCEntityID.setSite(1);
EntityID TGTEntityID = new EntityID();
TGTEntityID.setEntity(3);
TGTEntityID.setApplication(1);
TGTEntityID.setSite(1);
EntityID OBSEntityID = new EntityID();
OBSEntityID.setEntity(2);
OBSEntityID.setApplication(1);
OBSEntityID.setSite(1);
/* BELOW IS THE RECIEVE CODE //
// //
......@@ -210,10 +166,10 @@ public class TGTSendRecieve {
InetAddress address = null;
DatagramPacket packet;
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");
System.out.println("Russian T72 out on the prowl...\n\n");
socket = new MulticastSocket(MULTICAST_PORT);
address = InetAddress.getByName(MULTICAST_GROUP);
socket.joinGroup(address);
......@@ -266,44 +222,27 @@ public class TGTSendRecieve {
// http://faculty.nps.edu/brutzman/vrtp/mil/navy/nps/disEnumerations/JdbeHtmlFiles/pdu/8.htm
//
if (currentPduType == 1) //EntityState
{
EntityStatePdu entityPDU = (EntityStatePdu) pdu;
EntityType PduEntityType = entityPDU.getEntityType();
if (PduEntityType.getCountry() == 222) {
ActionRequestPdu action = new ActionRequestPdu();
action.setExerciseID((short) 1);
action.setRequestID((long) 2);
action.setOriginatingEntityID(OBSID);
action.setReceivingEntityID(FDCEntityID);
timestamp = disTime.getDisAbsoluteTimestamp();
action.setTimestamp(timestamp);
System.out.println("\n Got a Russian SOB! Preparing CFF to send.");
sender.run(action);
}
}
if (currentPduType == 3) //Detination
if (currentPduType == 2) //FirePDU
{
System.out.println("In detination if");
CommentPdu comment = new CommentPdu();
comment.setExerciseID((short) 1);
comment.setOriginatingEntityID(TGTEntityID);
DetonationPdu det = new DetonationPdu();
det.setExerciseID((short) 1);
det.setDetonationResult((short)1);
timestamp = disTime.getDisAbsoluteTimestamp();
comment.setTimestamp(timestamp);
sender.run(comment);
det.setTimestamp(timestamp);
sender.run(det);
}
} else {
System.out.println("received packet but pdu is null and originated from Observer. Still searching for other Targets...");
System.out.println("received packet but pdu is null and originated from Target. Still doing sketchy Russian things...");
}
}
}
} catch (IOException e) {
System.out.println("Problem with Observer.PduReceiver, see exception trace:");
System.out.println("Problem with Target.PduReceiver, see exception trace:");
System.out.println(e);
} finally {
System.out.println("Observer.PduReceiver complete. - OUT!");
System.out.println("Target.PduReceiver complete. - T-72 DESTROYED!");
}
}
......
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