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

FDC Class is working as it needs to. Copied to OBS and TGT.

For FDC Class:  Sends - entity,  Listens for Action request, Sends-
ActionResponse and Fire, Listens for comment, sends - ACK and stop.
parent 83060943
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,7 @@ import java.util.*; ...@@ -6,7 +6,7 @@ import java.util.*;
import edu.nps.moves.dis.*; import edu.nps.moves.dis.*;
import java.io.IOException; import java.io.IOException;
import edu.nps.moves.disutil.PduFactory; import edu.nps.moves.disutil.PduFactory;
import java.sql.Timestamp; import edu.nps.moves.disutil.DisTime;
public class FDCSendRecieve { public class FDCSendRecieve {
...@@ -26,11 +26,12 @@ public class FDCSendRecieve { ...@@ -26,11 +26,12 @@ public class FDCSendRecieve {
public static final int MULTICAST_PORT = 3000; public static final int MULTICAST_PORT = 3000;
public static final String MULTICAST_GROUP = "239.1.2.3"; public static final String MULTICAST_GROUP = "239.1.2.3";
public static final boolean USE_FAST_ESPDU = false; public static final boolean USE_FAST_ESPDU = false;
public long [] sentBuffer = new long[100]; public long[] sentBuffer = new long[100];
// public List<long> sentBufferList; public static List sentBufferList;
DisTime disTime = DisTime.getInstance();
public FDCSendRecieve(int port, String multicast) { public FDCSendRecieve(int port, String multicast) {
this.sentBufferList = new ArrayList<>();
try { try {
this.port = port; this.port = port;
multicastAddress = InetAddress.getByName(multicast); multicastAddress = InetAddress.getByName(multicast);
...@@ -42,100 +43,97 @@ public class FDCSendRecieve { ...@@ -42,100 +43,97 @@ public class FDCSendRecieve {
} }
} }
public void run(Pdu pdu) { public void run(Pdu... pdupass) throws UnknownHostException, IOException {
if(sentBuffer.)
List<Pdu> generatedPdus = new ArrayList<>();
Pdu aPdu = null;
System.out.println("FDC Sender started..."); System.out.println("FDC Sender started...");
short currentPduType = pdu.getPduType(); // Send the PDUs we created
System.out.println("in sender, recived PDU type: "+currentPduType); InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS);
MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT);
socket.joinGroup(localMulticastAddress);
for (Pdu i : pdupass) {
Pdu pdu = i;
if (sentBufferList.contains(pdu.getTimestamp())) {
break;
}
short currentPduType = pdu.getPduType();
System.out.println("in sender, recived PDU type: " + currentPduType);
// String currentPduTypeName = pdu.getClass().getName(); // String currentPduTypeName = pdu.getClass().getName();
// short currentProtocolFamilyID = pdu.getProtocolFamily(); // short currentProtocolFamilyID = pdu.getProtocolFamily();
// String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName(); // String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName();
try {
List<Pdu> generatedPdus = new ArrayList<>();
// Loop through all the enumerated PDU types, create a PDU for each type, // Loop through all the enumerated PDU types, create a PDU for each type,
// and add that PDU to a list. // and add that PDU to a list.
//System.out.println(pdu);
Pdu aPdu = null; //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(pdu); switch (currentPduType) // using enumeration values from edu.nps.moves.disenum.*
{
//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.*
{
case 1: //ENTITY_STATE: case 1: //ENTITY_STATE:
System.out.println("Case: Enitity_State " + pdu + "\n"); aPdu = pdu;
aPdu = new EntityStatePdu(); break;
EntityStatePdu espdu = (EntityStatePdu) aPdu;
Marking marking = new Marking();
marking.setCharactersString("PduSender");
espdu.setMarking(marking);
Vector3Double espduLocation = new Vector3Double();
espduLocation.setX(1.0);
espduLocation.setY(2.0);
espduLocation.setZ(3.0);
espdu.setTimestamp(System.currentTimeMillis());
break;
// case COMMENT: // case COMMENT:
// aPdu = new CommentPdu(); // aPdu = new CommentPdu();
// break; // break;
// //
// case FIRE: case 2: //FIRE
// aPdu = new FirePdu(); aPdu = pdu;
// break; break;
// //
// case DETONATION: // case DETONATION:
// aPdu = new DetonationPdu(); // aPdu = new DetonationPdu();
// break; // break;
// //
// case ACKNOWLEDGE: case 15: //AcknowledgePdu
// aPdu = new AcknowledgePdu(); aPdu = pdu;
// break; break;
// //
case 16: //ACTION_REQUEST: // case 16: //ACTION_REQUEST:
aPdu = new ActionRequestPdu(); // aPdu = new ActionRequestPdu();
break; // break;
default: case 17:
//add some shit that makes sense here. aPdu = pdu;
System.out.print("PDU of type " + pdu + " not supported, created or sent "); break;
System.out.println();
} case 14:
if (aPdu != null) { aPdu = pdu;
generatedPdus.add(aPdu); break;
System.out.println("APDU container count " + generatedPdus.size());
} default:
//add some shit that makes sense here.
System.out.print("PDU of type " + pdu + " not supported, created or sent ");
// Send the PDUs we created System.out.println();
InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS);
MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT);
socket.joinGroup(localMulticastAddress);
for (int idx = 0; idx < generatedPdus.size(); idx++) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
byte[] buffer;
aPdu = generatedPdus.get(idx);
aPdu.marshal(dos);
buffer = baos.toByteArray();
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT);
socket.send(packet);
sentBuffer[sentBuffer.length] = aPdu.getTimestamp();
System.out.println("Sent PDU of type " + aPdu.getClass().getName());
} }
} catch (IOException e) { if (aPdu != null) {
System.out.println(e); generatedPdus.add(aPdu);
System.out.println("APDU container count " + generatedPdus.size());
}
}
for (int idx = 0; idx < generatedPdus.size(); idx++) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
byte[] buffer;
aPdu = generatedPdus.get(idx);
aPdu.marshal(dos);
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("Sent PDU of type " + aPdu.getClass().getName());
} }
} }
public static void main(String[] args) { 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... //turns on the sender code - might need to move around down into the recieve with the if statements...
// //
// ORIGINAL SENDING CODE MAIN CLASS: // ORIGINAL SENDING CODE MAIN CLASS:
...@@ -148,20 +146,23 @@ public class FDCSendRecieve { ...@@ -148,20 +146,23 @@ public class FDCSendRecieve {
// System.out.println("Usage: PduSender <port> <multicast group>"); // System.out.println("Usage: PduSender <port> <multicast group>");
// System.out.println("Default: PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS); // System.out.println("Default: PduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS);
// FDCSendRecieve sender = new FDCSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); // FDCSendRecieve sender = new FDCSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS);
// sender.run(); // sender.run();
// } // }
// //
// Inital Hello world from entity: // Inital Hello world from entity:
// //
FDCSendRecieve sender = new FDCSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender
FDCSendRecieve sender = new FDCSendRecieve(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender
EntityStatePdu FDCespdu = new EntityStatePdu(); EntityStatePdu FDCespdu = new EntityStatePdu();
FDCespdu.setExerciseID((short)1); Marking marking = new Marking();
EntityID entityID = FDCespdu.getEntityID(); marking.setCharactersString("FDC");
entityID.setSite(1); // 0 is apparently not a valid site number, per the spec FDCespdu.setMarking(marking);
entityID.setApplication(1); FDCespdu.setExerciseID((short) 1);
entityID.setEntity(1); //change for each person I think??? - JMF EntityID FDCID = FDCespdu.getEntityID();
FDCID.setSite(1); // 0 is apparently not a valid site number, per the spec
FDCID.setApplication(1);
FDCID.setEntity(1); //change for each person I think??? - JMF
EntityType entityType = FDCespdu.getEntityType(); EntityType entityType = FDCespdu.getEntityType();
// //
//Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21 //Need to update the info below to match the unit type IAW SISO-REF-010-2015 V.21
...@@ -178,9 +179,11 @@ public class FDCSendRecieve { ...@@ -178,9 +179,11 @@ public class FDCSendRecieve {
location.setY(0.0); //TGT = 150 OBS = 75 location.setY(0.0); //TGT = 150 OBS = 75
location.setZ(10.0); //TGT = 20 OBS = 50 location.setZ(10.0); //TGT = 20 OBS = 50
FDCespdu.setEntityLocation(location); FDCespdu.setEntityLocation(location);
FDCespdu.setTimestamp(System.currentTimeMillis()); int timestamp = disTime.getDisAbsoluteTimestamp();
//sender.run(FDCespdu); //sends inital here I am and who I am FDCespdu.setTimestamp(timestamp);
//FDCespdu.setTimestamp(System.currentTimeMillis());
sender.run(FDCespdu); //sends inital here I am and who I am
/* BELOW IS THE RECIEVE CODE // /* BELOW IS THE RECIEVE CODE //
// // // //
// // // //
...@@ -191,10 +194,9 @@ public class FDCSendRecieve { ...@@ -191,10 +194,9 @@ public class FDCSendRecieve {
DatagramPacket packet; DatagramPacket packet;
short currentPduType; //will use the curentPduType as the check for sending other packets. short currentPduType; //will use the curentPduType as the check for sending other packets.
try { try {
// TODO: Change the line below to make sense for each class // TODO: Change the line below to make sense for each class
System.out.println("FDC is alive and ready to recieve fire missions..."); System.out.println("FDC is alive and ready to recieve fire missions...\n\n");
socket = new MulticastSocket(MULTICAST_PORT); socket = new MulticastSocket(MULTICAST_PORT);
address = InetAddress.getByName(MULTICAST_GROUP); address = InetAddress.getByName(MULTICAST_GROUP);
socket.joinGroup(address); socket.joinGroup(address);
...@@ -211,54 +213,99 @@ public class FDCSendRecieve { ...@@ -211,54 +213,99 @@ public class FDCSendRecieve {
// //
//TODO: NEED IF STATEMENT IF THE SENDER IS THIS CLASS TO DELETE. //TODO: NEED IF STATEMENT IF THE SENDER IS THIS CLASS TO DELETE.
// //
String marking2 = new String();
Pdu pdu = factory.createPdu(packet.getData()); Pdu pdu = factory.createPdu(packet.getData());
currentPduType = pdu.getPduType();
if (currentPduType == 14) //stop/freeze PDU
{
System.out.println("recieved Stop/Freeze packet...");
return;
}
// pdu.setExerciseID((short)5);
if (pdu != null) { if (pdu != null) {
currentPduType = pdu.getPduType(); if (sentBufferList.contains(pdu.getTimestamp())) {
pdu = null;
String currentPduTypeName = pdu.getClass().getName();
short currentProtocolFamilyID = pdu.getProtocolFamily();
String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName();
//Reference for PDU Types:
// 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();
PduEntityType.setCountry(225);
if(PduEntityType.getCountry()==222){
//do something for the OBS as this is a russian asshat. Most likely send the pdu with sender.run(pdu);
System.out.println("got a russian SOB!");
}
} }
EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below if (pdu != null) {
if(currentPduType == 16) //Action request String currentPduTypeName = pdu.getClass().getName();
{ short currentProtocolFamilyID = pdu.getProtocolFamily();
ActionRequestPdu actionPdu = (ActionRequestPdu) pdu; String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName();
if(actionPdu.getOriginatingEntityID() == OBSEntityID) if (currentPduType == 1) {
{ EntityStatePdu pdu2 = (EntityStatePdu) pdu;
sender.run(pdu); marking2 = pdu2.getMarking().getCharactersString();
} }
} //Keep adding any if statements as needed for the class you are building.
StringBuilder message = new StringBuilder();
//Keep adding any if statements as needed for the class you are building. message.append("received DIS PDU: ");
message.append("pduType ");
if (currentPduType < 10) {
StringBuilder message = new StringBuilder(); message.append(" ");
message.append("received DIS PDU: "); }
message.append("pduType "); message.append(currentPduType).append(" ").append(currentPduTypeName);
if (currentPduType < 10) {
message.append(" "); message.append(" ");
message.append(marking2);
System.out.println(message.toString());
//Reference for PDU Types:
// 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) {
//do something for the OBS as this is a russian asshat. Most likely send the pdu with sender.run(pdu);
//create Action Request PDU
//sender.run(actionPDU);
System.out.println("got a russian SOB!");
}
}
EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below
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
TGTEntityID.setEntity(3);
TGTEntityID.setApplication(1);
TGTEntityID.setSite(1);
if (currentPduType == 16) //Action request
{
ActionResponsePdu response = new ActionResponsePdu();
response.setExerciseID((short) 1);
response.setRequestID((long) 1);
timestamp = disTime.getDisAbsoluteTimestamp();
response.setTimestamp(timestamp);
FirePdu fire = new FirePdu();
fire.setExerciseID((short) 1);
fire.setFireMissionIndex(1000);
fire.setFiringEntityID(FDCID);
fire.setTargetEntityID(TGTEntityID);
timestamp = disTime.getDisAbsoluteTimestamp();
fire.setTimestamp(timestamp);
sender.run(response, fire);
}
if (currentPduType == 22) //Comment PDU
{
AcknowledgePdu ack = new AcknowledgePdu();
ack.setExerciseID((short) 1);
ack.setRequestID((long) 1);
timestamp = disTime.getDisAbsoluteTimestamp();
ack.setTimestamp(timestamp);
StopFreezePdu stop = new StopFreezePdu();
stop.setExerciseID((short) 1);
stop.setRequestID((long) 1);
sender.run(ack, stop);
}
} else {
System.out.println("received packet but pdu is null and originated from FDC. Still standing by...");
} }
message.append(currentPduType).append(" ").append(currentPduTypeName);
message.append(", protocolFamily ").append(currentProtocolFamilyID);
message.append(" ").append(currentPduFamilyName);
System.out.println(message.toString());
} else {
System.out.println("received packet but pdu is null, packet.getData().length=" + packet.getData().length + ", error...");
} }
} }
} catch (IOException e) { } catch (IOException e) {
......
...@@ -230,7 +230,7 @@ public class FFTestEspduSender { ...@@ -230,7 +230,7 @@ public class FFTestEspduSender {
espdu.marshal(dos); espdu.marshal(dos);
FirePdu fire = new FirePdu(); FirePdu fire = new FirePdu();
fire.set //fire.set
byte[] fireArray = fire.marshal(); byte[] fireArray = fire.marshal();
// The byte array here is the packet in DIS format. We put that into a // The byte array here is the packet in DIS format. We put that into a
......
...@@ -8,6 +8,7 @@ import edu.nps.moves.dis.*; ...@@ -8,6 +8,7 @@ import edu.nps.moves.dis.*;
import edu.nps.moves.disenum.*; import edu.nps.moves.disenum.*;
import edu.nps.moves.examples.ClassNameComparator; import edu.nps.moves.examples.ClassNameComparator;
/** /**
* This is an example that sends many/most types of PDUs. Useful for testing standards * This is an example that sends many/most types of PDUs. Useful for testing standards
* compliance or getting a full set of PDUs. It also writes the generated PDUs to an XML file. * compliance or getting a full set of PDUs. It also writes the generated PDUs to an XML file.
...@@ -57,29 +58,53 @@ public class FriscoFurrPduSender ...@@ -57,29 +58,53 @@ public class FriscoFurrPduSender
switch (pdu) // using enumeration values from edu.nps.moves.disenum.* switch (pdu) // using enumeration values from edu.nps.moves.disenum.*
{ {
case ENTITY_STATE: // case ENTITY_STATE:
System.out.println("Case: Enitity_State "+pdu+"\n"); // System.out.println("Case: Enitity_State "+pdu+"\n");
aPdu = new EntityStatePdu(); // aPdu = new EntityStatePdu();
EntityStatePdu espdu = (EntityStatePdu) aPdu; // EntityStatePdu espdu = (EntityStatePdu) aPdu;
Marking marking = new Marking(); // Marking marking = new Marking();
marking.setCharactersString("PduSender"); // marking.setCharactersString("TEST DUDE");
espdu.setMarking(marking); // espdu.setMarking(marking);
Vector3Double espduLocation = new Vector3Double(); // Vector3Double espduLocation = new Vector3Double();
espduLocation.setX(1.0); // espduLocation.setX(1.0);
espduLocation.setY(2.0); // espduLocation.setY(2.0);
espduLocation.setZ(3.0); // espduLocation.setZ(3.0);
EntityType entityType = espdu.getEntityType(); // EntityType entityType = espdu.getEntityType();
entityType.setCountry(222); // entityType.setCountry(222);
break; //
// // break;
// case COMMENT:
// aPdu = new CommentPdu(); case COMMENT:
// break; aPdu = new CommentPdu();
// CommentPdu comment = (CommentPdu) aPdu;
EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below
OBSEntityID.setEntity(2);
OBSEntityID.setApplication(1);
OBSEntityID.setSite(1);
comment.setOriginatingEntityID(OBSEntityID);
long number = 1;
//comment.setNumberOfFixedDatumRecords(number);
comment.setNumberOfVariableDatumRecords(number);
List datum = new ArrayList<FixedDatum>();
FixedDatum superDatum = new FixedDatum();
superDatum.setFixedDatumID((long)5);
superDatum.setFixedDatumValue((long) 54321);
datum.add(10);
datum.add(superDatum);
comment.setFixedDatums(datum);
List Vdatum = new ArrayList<VariableDatum>();
VariableDatum testBitch = new VariableDatum();
testBitch.setVariableDatumID(1);
Vdatum.add(15);
comment.setVariableDatums(Vdatum);
break;
// case FIRE: // case FIRE:
// aPdu = new FirePdu(); // aPdu = new FirePdu();
// break; // break;
//
// case DETONATION: // case DETONATION:
// aPdu = new DetonationPdu(); // aPdu = new DetonationPdu();
// break; // break;
...@@ -134,6 +159,12 @@ public class FriscoFurrPduSender ...@@ -134,6 +159,12 @@ public class FriscoFurrPduSender
// //
// case ACTION_REQUEST: // case ACTION_REQUEST:
// aPdu = new ActionRequestPdu(); // aPdu = new ActionRequestPdu();
// ActionRequestPdu action = (ActionRequestPdu) aPdu;
// EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below
// OBSEntityID.setEntity(2);
// OBSEntityID.setApplication(1);
// OBSEntityID.setSite(1);
// action.setOriginatingEntityID(OBSEntityID);
// break; // break;
default: default:
......
package MV3500Cohort2018JulySeptember.FinalProject.FriscoFurrProject;
import java.net.*;
import java.io.*;
import java.util.*;
import edu.nps.moves.dis.*;
import java.io.IOException;
import edu.nps.moves.disutil.PduFactory;
import edu.nps.moves.disutil.DisTime;
public class OBSSendRecieve1 {
/**
* Default multicast group address we send on.
*/
public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3";
/**
* Default multicast port used, matches Wireshark DIS capture default
*/
public static final int DEFAULT_MULTICAST_PORT = 3000;
private int port;
InetAddress multicastAddress;
public static final int MULTICAST_PORT = 3000;
public static final String MULTICAST_GROUP = "239.1.2.3";
public static final boolean USE_FAST_ESPDU = false;
public long[] sentBuffer = new long[100];
public static List sentBufferList;
DisTime disTime = DisTime.getInstance();
public OBSSendRecieve1(int port, String multicast) {
this.sentBufferList = new ArrayList<>();
try {
this.port = port;
multicastAddress = InetAddress.getByName(multicast);
if (!multicastAddress.isMulticastAddress()) {
System.out.println("Not a multicast address: " + multicast);
}
} catch (UnknownHostException e) {
System.out.println("Unable to open socket: " + e);
}
}
public void run(Pdu... pdupass) throws UnknownHostException, IOException {
List<Pdu> generatedPdus = new ArrayList<>();
Pdu aPdu = null;
System.out.println("FDC Sender started...");
// Send the PDUs we created
InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS);
MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT);
socket.joinGroup(localMulticastAddress);
for (Pdu i : pdupass) {
Pdu pdu = i;
if (sentBufferList.contains(pdu.getTimestamp())) {
break;
}
short currentPduType = pdu.getPduType();
System.out.println("in sender, recived 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.*
{
case 1: //ENTITY_STATE:
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 17:
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, created or sent ");
System.out.println();
}
if (aPdu != null) {
generatedPdus.add(aPdu);
System.out.println("APDU container count " + generatedPdus.size());
}
}
for (int idx = 0; idx < generatedPdus.size(); idx++) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
byte[] buffer;
aPdu = generatedPdus.get(idx);
aPdu.marshal(dos);
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("Sent PDU of type " + aPdu.getClass().getName());
}
}
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:
//
OBSSendRecieve1 sender = new OBSSendRecieve1(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender
EntityStatePdu FDCespdu = new EntityStatePdu();
Marking marking = new Marking();
marking.setCharactersString("FDC");
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.setApplication(1);
FDCID.setEntity(1); //change for each person I think??? - JMF
EntityType entityType = FDCespdu.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.setDomain((short) 1); // Land (vs air, surface, subsurface, space) both TGT and OBS are 1
entityType.setCategory((short) 3); // 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
Vector3Double location = new Vector3Double();
location.setX(0.0); //TGT = 150 OBS = 75
location.setY(0.0); //TGT = 150 OBS = 75
location.setZ(10.0); //TGT = 20 OBS = 50
FDCespdu.setEntityLocation(location);
int timestamp = disTime.getDisAbsoluteTimestamp();
FDCespdu.setTimestamp(timestamp);
//FDCespdu.setTimestamp(System.currentTimeMillis());
sender.run(FDCespdu); //sends inital here I am and who I am
/* BELOW IS THE RECIEVE CODE //
// //
// //
*/ //
PduFactory factory;
MulticastSocket socket = null;
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("FDC is alive and ready to recieve fire missions...\n\n");
socket = new MulticastSocket(MULTICAST_PORT);
address = InetAddress.getByName(MULTICAST_GROUP);
socket.joinGroup(address);
factory = new PduFactory();
while (true) // Loop infinitely, receiving datagrams
{
byte buffer[] = new byte[1500]; // typical MTU size
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();
if (currentPduType == 14) //stop/freeze PDU
{
System.out.println("recieved Stop/Freeze packet...");
return;
}
// pdu.setExerciseID((short)5);
if (pdu != null) {
if (sentBufferList.contains(pdu.getTimestamp())) {
pdu = null;
}
if (pdu != null) {
String currentPduTypeName = pdu.getClass().getName();
short currentProtocolFamilyID = pdu.getProtocolFamily();
String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName();
if (currentPduType == 1) {
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 ");
if (currentPduType < 10) {
message.append(" ");
}
message.append(currentPduType).append(" ").append(currentPduTypeName);
message.append(" ");
message.append(marking2);
System.out.println(message.toString());
//Reference for PDU Types:
// 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) {
//do something for the OBS as this is a russian asshat. Most likely send the pdu with sender.run(pdu);
//create Action Request PDU
//sender.run(actionPDU);
System.out.println("got a russian SOB!");
}
}
EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below
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
TGTEntityID.setEntity(3);
TGTEntityID.setApplication(1);
TGTEntityID.setSite(1);
if (currentPduType == 16) //Action request
{
ActionResponsePdu response = new ActionResponsePdu();
response.setExerciseID((short) 1);
response.setRequestID((long) 1);
timestamp = disTime.getDisAbsoluteTimestamp();
response.setTimestamp(timestamp);
FirePdu fire = new FirePdu();
fire.setExerciseID((short) 1);
fire.setFireMissionIndex(1000);
fire.setFiringEntityID(FDCID);
fire.setTargetEntityID(TGTEntityID);
timestamp = disTime.getDisAbsoluteTimestamp();
fire.setTimestamp(timestamp);
sender.run(response, fire);
}
if (currentPduType == 22) //Comment PDU
{
AcknowledgePdu ack = new AcknowledgePdu();
ack.setExerciseID((short) 1);
ack.setRequestID((long) 1);
timestamp = disTime.getDisAbsoluteTimestamp();
ack.setTimestamp(timestamp);
StopFreezePdu stop = new StopFreezePdu();
stop.setExerciseID((short) 1);
stop.setRequestID((long) 1);
sender.run(ack, stop);
}
} else {
System.out.println("received packet but pdu is null and originated from FDC. Still standing by...");
}
}
}
} catch (IOException e) {
System.out.println("Problem with FDC.PduReceiver, see exception trace:");
System.out.println(e);
} finally {
System.out.println("FDC.PduReceiver complete. - OUT!");
}
}
}
package MV3500Cohort2018JulySeptember.FinalProject.FriscoFurrProject;
import java.net.*;
import java.io.*;
import java.util.*;
import edu.nps.moves.dis.*;
import java.io.IOException;
import edu.nps.moves.disutil.PduFactory;
import edu.nps.moves.disutil.DisTime;
public class TGTSendRecieve1 {
/**
* Default multicast group address we send on.
*/
public static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3";
/**
* Default multicast port used, matches Wireshark DIS capture default
*/
public static final int DEFAULT_MULTICAST_PORT = 3000;
private int port;
InetAddress multicastAddress;
public static final int MULTICAST_PORT = 3000;
public static final String MULTICAST_GROUP = "239.1.2.3";
public static final boolean USE_FAST_ESPDU = false;
public long[] sentBuffer = new long[100];
public static List sentBufferList;
DisTime disTime = DisTime.getInstance();
public TGTSendRecieve1(int port, String multicast) {
this.sentBufferList = new ArrayList<>();
try {
this.port = port;
multicastAddress = InetAddress.getByName(multicast);
if (!multicastAddress.isMulticastAddress()) {
System.out.println("Not a multicast address: " + multicast);
}
} catch (UnknownHostException e) {
System.out.println("Unable to open socket: " + e);
}
}
public void run(Pdu... pdupass) throws UnknownHostException, IOException {
List<Pdu> generatedPdus = new ArrayList<>();
Pdu aPdu = null;
System.out.println("FDC Sender started...");
// Send the PDUs we created
InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS);
MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT);
socket.joinGroup(localMulticastAddress);
for (Pdu i : pdupass) {
Pdu pdu = i;
if (sentBufferList.contains(pdu.getTimestamp())) {
break;
}
short currentPduType = pdu.getPduType();
System.out.println("in sender, recived 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.*
{
case 1: //ENTITY_STATE:
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 17:
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, created or sent ");
System.out.println();
}
if (aPdu != null) {
generatedPdus.add(aPdu);
System.out.println("APDU container count " + generatedPdus.size());
}
}
for (int idx = 0; idx < generatedPdus.size(); idx++) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
byte[] buffer;
aPdu = generatedPdus.get(idx);
aPdu.marshal(dos);
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("Sent PDU of type " + aPdu.getClass().getName());
}
}
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:
//
TGTSendRecieve1 sender = new TGTSendRecieve1(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS); //initalize the sender
EntityStatePdu FDCespdu = new EntityStatePdu();
Marking marking = new Marking();
marking.setCharactersString("FDC");
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.setApplication(1);
FDCID.setEntity(1); //change for each person I think??? - JMF
EntityType entityType = FDCespdu.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.setDomain((short) 1); // Land (vs air, surface, subsurface, space) both TGT and OBS are 1
entityType.setCategory((short) 3); // 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
Vector3Double location = new Vector3Double();
location.setX(0.0); //TGT = 150 OBS = 75
location.setY(0.0); //TGT = 150 OBS = 75
location.setZ(10.0); //TGT = 20 OBS = 50
FDCespdu.setEntityLocation(location);
int timestamp = disTime.getDisAbsoluteTimestamp();
FDCespdu.setTimestamp(timestamp);
//FDCespdu.setTimestamp(System.currentTimeMillis());
sender.run(FDCespdu); //sends inital here I am and who I am
/* BELOW IS THE RECIEVE CODE //
// //
// //
*/ //
PduFactory factory;
MulticastSocket socket = null;
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("FDC is alive and ready to recieve fire missions...\n\n");
socket = new MulticastSocket(MULTICAST_PORT);
address = InetAddress.getByName(MULTICAST_GROUP);
socket.joinGroup(address);
factory = new PduFactory();
while (true) // Loop infinitely, receiving datagrams
{
byte buffer[] = new byte[1500]; // typical MTU size
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();
if (currentPduType == 14) //stop/freeze PDU
{
System.out.println("recieved Stop/Freeze packet...");
return;
}
// pdu.setExerciseID((short)5);
if (pdu != null) {
if (sentBufferList.contains(pdu.getTimestamp())) {
pdu = null;
}
if (pdu != null) {
String currentPduTypeName = pdu.getClass().getName();
short currentProtocolFamilyID = pdu.getProtocolFamily();
String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName();
if (currentPduType == 1) {
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 ");
if (currentPduType < 10) {
message.append(" ");
}
message.append(currentPduType).append(" ").append(currentPduTypeName);
message.append(" ");
message.append(marking2);
System.out.println(message.toString());
//Reference for PDU Types:
// 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) {
//do something for the OBS as this is a russian asshat. Most likely send the pdu with sender.run(pdu);
//create Action Request PDU
//sender.run(actionPDU);
System.out.println("got a russian SOB!");
}
}
EntityID OBSEntityID = new EntityID(); // need to figure out what this is....and then just put into if statement below
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
TGTEntityID.setEntity(3);
TGTEntityID.setApplication(1);
TGTEntityID.setSite(1);
if (currentPduType == 16) //Action request
{
ActionResponsePdu response = new ActionResponsePdu();
response.setExerciseID((short) 1);
response.setRequestID((long) 1);
timestamp = disTime.getDisAbsoluteTimestamp();
response.setTimestamp(timestamp);
FirePdu fire = new FirePdu();
fire.setExerciseID((short) 1);
fire.setFireMissionIndex(1000);
fire.setFiringEntityID(FDCID);
fire.setTargetEntityID(TGTEntityID);
timestamp = disTime.getDisAbsoluteTimestamp();
fire.setTimestamp(timestamp);
sender.run(response, fire);
}
if (currentPduType == 22) //Comment PDU
{
AcknowledgePdu ack = new AcknowledgePdu();
ack.setExerciseID((short) 1);
ack.setRequestID((long) 1);
timestamp = disTime.getDisAbsoluteTimestamp();
ack.setTimestamp(timestamp);
StopFreezePdu stop = new StopFreezePdu();
stop.setExerciseID((short) 1);
stop.setRequestID((long) 1);
sender.run(ack, stop);
}
} else {
System.out.println("received packet but pdu is null and originated from FDC. Still standing by...");
}
}
}
} catch (IOException e) {
System.out.println("Problem with FDC.PduReceiver, see exception trace:");
System.out.println(e);
} finally {
System.out.println("FDC.PduReceiver complete. - OUT!");
}
}
}
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