Skip to content
Snippets Groups Projects
Commit f5e0d6f0 authored by UnityGrunt03's avatar UnityGrunt03
Browse files

refactors the DIS7 files. Also imported all the libraries into the

assignments package.  Still no joy on my refactors files to compile
parent 2f48a891
No related branches found
No related tags found
No related merge requests found
Showing
with 1476 additions and 0 deletions
package MV3500Cohort2019JulySeptember.homework4.Yurkovich;
import java.net.*;
import java.io.*;
import edu.nps.moves.dis7.*;
import edu.nps.moves.dis7.enumerations.*;
import edu.nps.moves.dis7.util.*;
public class AllPduReceiver
{
public static final int DEFAULT_MULTICAST_PORT = AllPduSender.DEFAULT_MULTICAST_PORT;
public static final String DEFAULT_MULTICAST_ADDRESS = AllPduSender.DEFAULT_MULTICAST_ADDRESS;
public static final boolean USE_FAST_ESPDU = false;
public static void main(String args[])
{
PduFactory factory;
MulticastSocket socket;
InetAddress address;
DatagramPacket packet;
try {
System.out.println("DisExamplesOpenDis7.AllPduReceiver started...");
if (args.length == 2) {
socket = new MulticastSocket(Integer.parseInt(args[0]));
address = InetAddress.getByName(args[1]);
}
else {
System.out.println("Usage: AllPduReceiver <port> <multicast group>");
System.out.println("Default: AllPduReceiver " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS);
socket = new MulticastSocket(DEFAULT_MULTICAST_PORT);
address = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS);
}
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);
Pdu pdu = factory.createPdu(packet.getData());
if (pdu != null) {
DISPDUType currentPduType = pdu.getPduType(); //short currentPduType = pdu.getPduType();
String currentPduTypeName = pdu.getClass().getName();
DISProtocolFamily currentProtocolFamilyID = pdu.getProtocolFamily(); //short currentProtocolFamilyID = pdu.getProtocolFamily();
String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName();
StringBuilder message = new StringBuilder();
message.append("received DIS PDU ");
if (currentPduType.getValue() < 10)
message.append(" ");
message.append(currentPduType.getValue());
String currentPduTypePadded = String.format("%-34s", currentPduType); // - indicates right padding of whitespace
message.append(" " ).append(currentPduTypePadded);
String currentPduTypeNamePadded = String.format("%-49s", currentPduTypeName); // - indicates right padding of whitespace
message.append(" of type ").append(currentPduTypeNamePadded); // package.class name
message.append(" (protocolFamily ").append(currentProtocolFamilyID);
// message.append(" ").append(currentPduFamilyName); // class name is also available
message.append(")");
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) {
System.out.println("Problem with DisExamplesOpenDis7.AllPduReceiver, see exception trace:");
System.out.println(e);
}
finally {
System.out.println("DisExamplesOpenDis7.AllPduReceiver complete.");
}
}
}
Invocation instructions:
1. run or debug AllPduReceiver.java
2. send PDUs from another program such as AllPduSender.java (shown here)
3. kill process console when complete.
Program response:
===================================================
DisExamplesOpenDis7.AllPduReceiver started...
Usage: AllPduReceiver <port> <multicast group>
Default: AllPduReceiver 3000 239.1.2.3
received DIS PDU 1 ENTITY_STATE of type edu.nps.moves.dis7.EntityStatePdu (protocolFamily ENTITY_INFORMATION_INTERACTION)
received DIS PDU 2 FIRE of type edu.nps.moves.dis7.FirePdu (protocolFamily WARFARE)
received DIS PDU 3 DETONATION of type edu.nps.moves.dis7.DetonationPdu (protocolFamily WARFARE)
received DIS PDU 4 COLLISION of type edu.nps.moves.dis7.CollisionPdu (protocolFamily ENTITY_INFORMATION_INTERACTION)
received DIS PDU 5 SERVICE_REQUEST of type edu.nps.moves.dis7.ServiceRequestPdu (protocolFamily LOGISTICS)
received DIS PDU 6 RESUPPLY_OFFER of type edu.nps.moves.dis7.ResupplyOfferPdu (protocolFamily LOGISTICS)
received DIS PDU 7 RESUPPLY_RECEIVED of type edu.nps.moves.dis7.ResupplyReceivedPdu (protocolFamily LOGISTICS)
received DIS PDU 8 RESUPPLY_CANCEL of type edu.nps.moves.dis7.ResupplyCancelPdu (protocolFamily LOGISTICS)
received DIS PDU 9 REPAIR_COMPLETE of type edu.nps.moves.dis7.RepairCompletePdu (protocolFamily LOGISTICS)
received DIS PDU 10 REPAIR_RESPONSE of type edu.nps.moves.dis7.RepairResponsePdu (protocolFamily LOGISTICS)
received DIS PDU 11 CREATE_ENTITY of type edu.nps.moves.dis7.CreateEntityPdu (protocolFamily SIMULATION_MANAGEMENT)
received DIS PDU 12 REMOVE_ENTITY of type edu.nps.moves.dis7.RemoveEntityPdu (protocolFamily SIMULATION_MANAGEMENT)
received DIS PDU 13 START_RESUME of type edu.nps.moves.dis7.StartResumePdu (protocolFamily SIMULATION_MANAGEMENT)
received DIS PDU 14 STOP_FREEZE of type edu.nps.moves.dis7.StopFreezePdu (protocolFamily SIMULATION_MANAGEMENT)
received DIS PDU 15 ACKNOWLEDGE of type edu.nps.moves.dis7.AcknowledgePdu (protocolFamily SIMULATION_MANAGEMENT)
received DIS PDU 16 ACTION_REQUEST of type edu.nps.moves.dis7.ActionRequestPdu (protocolFamily SIMULATION_MANAGEMENT)
received DIS PDU 17 ACTION_RESPONSE of type edu.nps.moves.dis7.ActionResponsePdu (protocolFamily SIMULATION_MANAGEMENT)
received DIS PDU 18 DATA_QUERY of type edu.nps.moves.dis7.DataQueryPdu (protocolFamily SIMULATION_MANAGEMENT)
received DIS PDU 19 SET_DATA of type edu.nps.moves.dis7.SetDataPdu (protocolFamily SIMULATION_MANAGEMENT)
received DIS PDU 20 DATA of type edu.nps.moves.dis7.DataPdu (protocolFamily SIMULATION_MANAGEMENT)
received DIS PDU 21 EVENT_REPORT of type edu.nps.moves.dis7.EventReportPdu (protocolFamily SIMULATION_MANAGEMENT)
received DIS PDU 22 COMMENT of type edu.nps.moves.dis7.CommentPdu (protocolFamily SIMULATION_MANAGEMENT)
received DIS PDU 23 ELECTROMAGNETIC_EMISSION of type edu.nps.moves.dis7.ElectromagneticEmissionPdu (protocolFamily DISTRIBUTED_EMISSION_REGENERATION)
received DIS PDU 24 DESIGNATOR of type edu.nps.moves.dis7.DesignatorPdu (protocolFamily DISTRIBUTED_EMISSION_REGENERATION)
received DIS PDU 25 TRANSMITTER of type edu.nps.moves.dis7.TransmitterPdu (protocolFamily RADIO_COMMUNICATIONS)
received DIS PDU 26 SIGNAL of type edu.nps.moves.dis7.SignalPdu (protocolFamily RADIO_COMMUNICATIONS)
received DIS PDU 27 RECEIVER of type edu.nps.moves.dis7.ReceiverPdu (protocolFamily RADIO_COMMUNICATIONS)
received DIS PDU 28 IDENTIFICATION_FRIEND_OR_FOE of type edu.nps.moves.dis7.IFFPdu (protocolFamily DISTRIBUTED_EMISSION_REGENERATION)
received DIS PDU 29 UNDERWATER_ACOUSTIC of type edu.nps.moves.dis7.UnderwaterAcousticPdu (protocolFamily DISTRIBUTED_EMISSION_REGENERATION)
received DIS PDU 30 SUPPLEMENTAL_EMISSION_ENTITY_STATE of type edu.nps.moves.dis7.SEESPdu (protocolFamily DISTRIBUTED_EMISSION_REGENERATION)
received DIS PDU 31 INTERCOM_SIGNAL of type edu.nps.moves.dis7.IntercomSignalPdu (protocolFamily RADIO_COMMUNICATIONS)
received DIS PDU 32 INTERCOM_CONTROL of type edu.nps.moves.dis7.IntercomControlPdu (protocolFamily RADIO_COMMUNICATIONS)
received DIS PDU 33 AGGREGATE_STATE of type edu.nps.moves.dis7.AggregateStatePdu (protocolFamily ENTITY_MANAGEMENT)
received DIS PDU 34 ISGROUPOF of type edu.nps.moves.dis7.IsGroupOfPdu (protocolFamily ENTITY_MANAGEMENT)
received DIS PDU 35 TRANSFER_OWNERSHIP of type edu.nps.moves.dis7.TransferOwnershipPdu (protocolFamily ENTITY_MANAGEMENT)
received DIS PDU 36 ISPARTOF of type edu.nps.moves.dis7.IsPartOfPdu (protocolFamily ENTITY_MANAGEMENT)
received DIS PDU 37 MINEFIELD_STATE of type edu.nps.moves.dis7.MinefieldStatePdu (protocolFamily MINEFIELD)
received DIS PDU 38 MINEFIELD_QUERY of type edu.nps.moves.dis7.MinefieldQueryPdu (protocolFamily MINEFIELD)
received DIS PDU 39 MINEFIELD_DATA of type edu.nps.moves.dis7.MinefieldDataPdu (protocolFamily MINEFIELD)
received DIS PDU 40 MINEFIELD_RESPONSE_NACK of type edu.nps.moves.dis7.MinefieldResponseNACKPdu (protocolFamily MINEFIELD)
received DIS PDU 41 ENVIRONMENTAL_PROCESS of type edu.nps.moves.dis7.EnvironmentalProcessPdu (protocolFamily SYNTHETIC_ENVIRONMENT)
received DIS PDU 42 GRIDDED_DATA of type edu.nps.moves.dis7.GriddedDataPdu (protocolFamily SYNTHETIC_ENVIRONMENT)
received DIS PDU 43 POINT_OBJECT_STATE of type edu.nps.moves.dis7.PointObjectStatePdu (protocolFamily SYNTHETIC_ENVIRONMENT)
received DIS PDU 44 LINEAR_OBJECT_STATE of type edu.nps.moves.dis7.LinearObjectStatePdu (protocolFamily SYNTHETIC_ENVIRONMENT)
received DIS PDU 45 AREAL_OBJECT_STATE of type edu.nps.moves.dis7.ArealObjectStatePdu (protocolFamily SYNTHETIC_ENVIRONMENT)
received DIS PDU 46 TIME_SPACE_POSITION_INFORMATION of type edu.nps.moves.dis7.TSPIPdu (protocolFamily LIVE_ENTITY_LE_INFORMATION_INTERACTION)
received DIS PDU 47 APPEARANCE of type edu.nps.moves.dis7.AppearancePdu (protocolFamily LIVE_ENTITY_LE_INFORMATION_INTERACTION)
received DIS PDU 48 ARTICULATED_PARTS of type edu.nps.moves.dis7.ArticulatedPartsPdu (protocolFamily LIVE_ENTITY_LE_INFORMATION_INTERACTION)
received DIS PDU 49 LIVE_ENTITY_FIRE of type edu.nps.moves.dis7.LEFirePdu (protocolFamily LIVE_ENTITY_LE_INFORMATION_INTERACTION)
received DIS PDU 50 LIVE_ENTITY_DETONATION of type edu.nps.moves.dis7.LEDetonationPdu (protocolFamily LIVE_ENTITY_LE_INFORMATION_INTERACTION)
received DIS PDU 51 CREATE_ENTITY_RELIABLE of type edu.nps.moves.dis7.CreateEntityReliablePdu (protocolFamily SIMULATION_MANAGEMENT_WITH_RELIABILITY)
received DIS PDU 52 REMOVE_ENTITY_RELIABLE of type edu.nps.moves.dis7.RemoveEntityReliablePdu (protocolFamily SIMULATION_MANAGEMENT_WITH_RELIABILITY)
received DIS PDU 53 START_RESUME_RELIABLE of type edu.nps.moves.dis7.StartResumeReliablePdu (protocolFamily SIMULATION_MANAGEMENT_WITH_RELIABILITY)
received DIS PDU 54 STOP_FREEZE_RELIABLE of type edu.nps.moves.dis7.StopFreezeReliablePdu (protocolFamily SIMULATION_MANAGEMENT_WITH_RELIABILITY)
received DIS PDU 55 ACKNOWLEDGE_RELIABLE of type edu.nps.moves.dis7.AcknowledgeReliablePdu (protocolFamily SIMULATION_MANAGEMENT_WITH_RELIABILITY)
received DIS PDU 56 ACTION_REQUEST_RELIABLE of type edu.nps.moves.dis7.ActionRequestReliablePdu (protocolFamily SIMULATION_MANAGEMENT_WITH_RELIABILITY)
received DIS PDU 57 ACTION_RESPONSE_RELIABLE of type edu.nps.moves.dis7.ActionResponseReliablePdu (protocolFamily SIMULATION_MANAGEMENT_WITH_RELIABILITY)
received DIS PDU 58 DATA_QUERY_RELIABLE of type edu.nps.moves.dis7.DataQueryReliablePdu (protocolFamily SIMULATION_MANAGEMENT_WITH_RELIABILITY)
received DIS PDU 59 SET_DATA_RELIABLE of type edu.nps.moves.dis7.SetDataReliablePdu (protocolFamily SIMULATION_MANAGEMENT_WITH_RELIABILITY)
received DIS PDU 60 DATA_RELIABLE of type edu.nps.moves.dis7.DataReliablePdu (protocolFamily SIMULATION_MANAGEMENT_WITH_RELIABILITY)
received DIS PDU 61 EVENT_REPORT_RELIABLE of type edu.nps.moves.dis7.EventReportReliablePdu (protocolFamily SIMULATION_MANAGEMENT_WITH_RELIABILITY)
received DIS PDU 62 COMMENT_RELIABLE of type edu.nps.moves.dis7.CommentReliablePdu (protocolFamily SIMULATION_MANAGEMENT_WITH_RELIABILITY)
received DIS PDU 63 RECORD_RELIABLE of type edu.nps.moves.dis7.RecordReliablePdu (protocolFamily SIMULATION_MANAGEMENT_WITH_RELIABILITY)
received DIS PDU 64 SET_RECORD_RELIABLE of type edu.nps.moves.dis7.SetRecordReliablePdu (protocolFamily SIMULATION_MANAGEMENT_WITH_RELIABILITY)
received DIS PDU 65 RECORD_QUERY_RELIABLE of type edu.nps.moves.dis7.RecordQueryReliablePdu (protocolFamily SIMULATION_MANAGEMENT_WITH_RELIABILITY)
received DIS PDU 66 COLLISION_ELASTIC of type edu.nps.moves.dis7.CollisionElasticPdu (protocolFamily ENTITY_INFORMATION_INTERACTION)
received DIS PDU 67 ENTITY_STATE_UPDATE of type edu.nps.moves.dis7.EntityStateUpdatePdu (protocolFamily ENTITY_INFORMATION_INTERACTION)
received DIS PDU 68 DIRECTED_ENERGY_FIRE of type edu.nps.moves.dis7.DirectedEnergyFirePdu (protocolFamily WARFARE)
received DIS PDU 69 ENTITY_DAMAGE_STATUS of type edu.nps.moves.dis7.EntityDamageStatusPdu (protocolFamily WARFARE)
received DIS PDU 70 INFORMATION_OPERATIONS_ACTION of type edu.nps.moves.dis7.InformationOperationsActionPdu (protocolFamily INFORMATION_OPERATIONS)
received DIS PDU 71 INFORMATION_OPERATIONS_REPORT of type edu.nps.moves.dis7.InformationOperationsReportPdu (protocolFamily INFORMATION_OPERATIONS)
received DIS PDU 72 ATTRIBUTE of type edu.nps.moves.dis7.AttributePdu (protocolFamily ENTITY_INFORMATION_INTERACTION)
BUILD STOPPED (total time: 53 seconds)
package MV3500Cohort2019JulySeptember.homework4.Yurkovich;
import java.io.*;
import java.net.*;
import java.util.*;
import edu.nps.moves.dis7.*;
import edu.nps.moves.dis7.enumerations.*;
/**
* 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.
* Adapted from OpenDIS library example package edu.nps.moves.examples
*
* @author DMcG
* @version $Id:$
*/
public class AllPduSender
{
/** 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 AllPduSender(int port, String multicast) {
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()
{
System.out.println("DisExamplesOpenDis7.AllPduSender started...");
try
{
System.out.println("Generate PDUs and note issues, if any...");
List<Pdu> generatedPdusList = new ArrayList<>();
// Loop through all the enumerated PDU types, create a PDU for each type,
// add that PDU to generatedPdusList, and send each one
for (DISPDUType pdu : DISPDUType.values())
{
// System.out.println("PDU " + pdu.getValue() + " " + pdu.name() + " " + pdu.getDescription()); // diagnostic
Pdu aPdu = null; // edu.​nps.​moves7.​dis.PDU superclass for all PDUs, in preparation for custom assignment
try {
switch (pdu) // using enumeration values from edu.​nps.​moves.​dis7.​enumerations.​DISPDUType
{
case OTHER: // 0
System.out.println ("*** Note: DISPDUType." + pdu.name() + " not supported"); // TODO why was this received?
// nothing to send
break;
case ENTITY_STATE: // 1
aPdu = new EntityStatePdu();
EntityStatePdu espdu = (EntityStatePdu) aPdu;
EntityMarking entityMarking = new EntityMarking ();
entityMarking.setCharacters("AllPduSender".getBytes()); //entityMarking.setCharacters(Byte.valueOf("0")); // 11 characters max?
espdu.setMarking(entityMarking);
Vector3Double espduLocation = new Vector3Double();
espduLocation.setX(1.0);
espduLocation.setY(2.0);
espduLocation.setZ(3.0);
espdu.setEntityLocation(espduLocation);
// it is important to identify questions as you think of them
// TODO how to set azimuth, i.e. course direction over ground?
break;
case FIRE: // 2
aPdu = new FirePdu();
break;
case DETONATION: // 3
aPdu = new DetonationPdu();
break;
case COLLISION: // 4
aPdu = new CollisionPdu();
break;
case SERVICE_REQUEST: // 5
aPdu = new ServiceRequestPdu();
break;
case RESUPPLY_OFFER: // 6
aPdu = new ResupplyOfferPdu();
break;
case RESUPPLY_RECEIVED: // 7
aPdu = new ResupplyReceivedPdu();
break;
case RESUPPLY_CANCEL: //8
aPdu = new ResupplyCancelPdu();
break;
case REPAIR_COMPLETE: // 9
aPdu = new RepairCompletePdu();
break;
case REPAIR_RESPONSE: // 10
aPdu = new RepairResponsePdu();
break;
case CREATE_ENTITY: // 11
aPdu = new CreateEntityPdu();
break;
case REMOVE_ENTITY: // 12
aPdu = new RemoveEntityPdu();
break;
case START_RESUME: // 13
aPdu = new StartResumePdu();
break;
case STOP_FREEZE: // 14
aPdu = new StopFreezePdu();
break;
case ACKNOWLEDGE: // 15
aPdu = new AcknowledgePdu();
break;
case ACTION_REQUEST: // 16
aPdu = new ActionRequestPdu();
break;
case ACTION_RESPONSE: // 17
aPdu = new ActionResponsePdu();
break;
case DATA_QUERY: // 18
aPdu = new DataQueryPdu();
break;
case SET_DATA: // 19
aPdu = new SetDataPdu();
break;
case DATA: // 20
aPdu = new DataPdu();
break;
case EVENT_REPORT: // 21
aPdu = new EventReportPdu();
break;
case ELECTROMAGNETIC_EMISSION: // 23
aPdu = new ElectromagneticEmissionPdu();
break;
case DESIGNATOR: // 24
aPdu = new DesignatorPdu();
break;
case TRANSMITTER: // 25
aPdu = new TransmitterPdu();
break;
case SIGNAL: // 26
aPdu = new SignalPdu();
break;
case RECEIVER: // 27
aPdu = new ReceiverPdu();
break;
case IDENTIFICATION_FRIEND_OR_FOE: // 28
aPdu = new IdentificationFriendOrFoePdu();
break;
case UNDERWATER_ACOUSTIC: // 29
aPdu = new UnderwaterAcousticPdu();
break;
case SUPPLEMENTAL_EMISSION_ENTITY_STATE: // 30
aPdu = new SupplementalEmissionEntityStatePdu();
break;
case INTERCOM_SIGNAL: // 31
aPdu = new IntercomSignalPdu();
break;
case INTERCOM_CONTROL: // 32
aPdu = new IntercomControlPdu();
break;
case AGGREGATE_STATE: // 33
aPdu = new AggregateStatePdu();
break;
case ISGROUPOF: // 34
aPdu = new IsGroupOfPdu();
break;
case TRANSFER_OWNERSHIP: // 35
aPdu = new TransferOwnershipPdu();
break;
case ISPARTOF: // 36
aPdu = new IsPartOfPdu();
break;
case MINEFIELD_STATE: // 37
aPdu = new MinefieldStatePdu();
break;
case MINEFIELD_QUERY: // 38
aPdu = new MinefieldQueryPdu();
break;
case MINEFIELD_DATA: // 39
aPdu = new MinefieldDataPdu();
break;
case MINEFIELD_RESPONSE_NACK: // 40
aPdu = new MinefieldResponseNACKPdu();
break;
case ENVIRONMENTAL_PROCESS: // 41
aPdu = new EnvironmentalProcessPdu();
break;
case GRIDDED_DATA: // 42
aPdu = new GriddedDataPdu();
break;
case POINT_OBJECT_STATE: // 43
aPdu = new PointObjectStatePdu();
break;
case LINEAR_OBJECT_STATE: // 44
aPdu = new LinearObjectStatePdu();
break;
case AREAL_OBJECT_STATE: // 45
aPdu = new ArealObjectStatePdu();
break;
case TIME_SPACE_POSITION_INFORMATION: // 46
aPdu = new TimeSpacePositionInformationPdu();
break;
case APPEARANCE: // 47
aPdu = new AppearancePdu();
break;
case ARTICULATED_PARTS: // 48
aPdu = new ArticulatedPartsPdu();
break;
case LIVE_ENTITY_FIRE: // 49
aPdu = new LiveEntityFirePdu();
break;
case LIVE_ENTITY_DETONATION: // 50
aPdu = new LiveEntityDetonationPdu();
break;
case CREATE_ENTITY_RELIABLE: // 51
aPdu = new CreateEntityReliablePdu();
break;
case REMOVE_ENTITY_RELIABLE: // 52
aPdu = new RemoveEntityReliablePdu();
break;
case START_RESUME_RELIABLE: // 53
aPdu = new StartResumeReliablePdu();
break;
case STOP_FREEZE_RELIABLE: // 54
aPdu = new StopFreezeReliablePdu();
break;
case ACKNOWLEDGE_RELIABLE: // 55
aPdu = new AcknowledgeReliablePdu();
break;
case ACTION_REQUEST_RELIABLE: // 56
aPdu = new ActionRequestReliablePdu();
break;
case ACTION_RESPONSE_RELIABLE: // 57
aPdu = new ActionResponseReliablePdu();
break;
case DATA_QUERY_RELIABLE: // 58
aPdu = new DataQueryReliablePdu();
break;
case SET_DATA_RELIABLE: // 59
aPdu = new SetDataReliablePdu();
break;
case DATA_RELIABLE: // 60
aPdu = new DataReliablePdu();
break;
case EVENT_REPORT_RELIABLE: // 61
aPdu = new EventReportReliablePdu();
break;
case COMMENT_RELIABLE: // 62
aPdu = new CommentReliablePdu();
break;
case RECORD_RELIABLE: // 63
aPdu = new RecordReliablePdu();
break;
case SET_RECORD_RELIABLE: // 64
aPdu = new SetRecordReliablePdu();
break;
case RECORD_QUERY_RELIABLE: // 65
aPdu = new RecordQueryReliablePdu();
break;
case COLLISION_ELASTIC: // 66
aPdu = new CollisionElasticPdu();
break;
case ENTITY_STATE_UPDATE: // 67
aPdu = new EntityStateUpdatePdu();
break;
case DIRECTED_ENERGY_FIRE: // 68
aPdu = new DirectedEnergyFirePdu();
break;
case ENTITY_DAMAGE_STATUS: // 69
aPdu = new EntityDamageStatusPdu();
break;
case INFORMATION_OPERATIONS_ACTION: // 70
aPdu = new InformationOperationsActionPdu();
break;
case INFORMATION_OPERATIONS_REPORT: // 71
aPdu = new InformationOperationsReportPdu();
break;
case ATTRIBUTE: // 72
aPdu = new AttributePdu();
break;
case COMMENT:
aPdu = new CommentPdu();
CommentPdu newCommentPdu = (CommentPdu)aPdu;
VariableDatum newVariableDatum = new VariableDatum();
// etc. see Garrett and Pete's code
break;
default:
System.out.println("*** Warning: PDU " + pdu.getValue() + " " + pdu + " not supported, created or sent ");
// code generation block for this class follows:
// System.out.println(" case " + pdu + ": // " + pdu.getValue());
// System.out.println(" aPdu = new " + pdu.getDescription().replace(" ","").replace("-","").replace("/","") +
// "Pdu();");
// System.out.println(" break;");
// System.out.println();
}
if (aPdu != null)
{
generatedPdusList.add(aPdu);
}
}
catch (Exception e)
{
System.out.print("Exception thrown for PDU " + pdu.getValue() + " " + pdu);
System.out.print(Arrays.toString(e.getStackTrace()));
// continue looping
}
}
// Send the PDUs we created
System.out.println("Send the " + generatedPdusList.size() + " PDUs we created...");
InetAddress localMulticastAddress = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS);
MulticastSocket socket = new MulticastSocket(DEFAULT_MULTICAST_PORT);
socket.joinGroup(localMulticastAddress);
for (int idx = 0; idx < generatedPdusList.size(); idx++)
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
byte[] buffer;
Pdu aPdu = generatedPdusList.get(idx);
aPdu.marshal(dos);
buffer = baos.toByteArray();
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT);
socket.send(packet);
try {
Thread.sleep(100L);
} catch (InterruptedException ex) {
}
String currentPduTypeValuePadded = String.format("%2s", aPdu.getPduType().getValue());
String currentPduTypePadded = String.format("%-34s", aPdu.getPduType()); // - indicates right padding of whitespace
System.out.print ("Sent DIS PDU " + currentPduTypeValuePadded + " " + currentPduTypePadded );
System.out.println(" of type " + aPdu.getClass().getName());
}
// write the PDUs out to an XML file.
//PduContainer container = new PduContainer();
//container.setPdus(generatedPdus);
//container.marshallToXml("examplePdus.xml");
}
catch (IOException e)
{
System.out.println(e);
}
}
public static void main(String args[])
{
if (args.length == 2)
{
AllPduSender sender = new AllPduSender(Integer.parseInt(args[0]), args[1]);
sender.run();
}
else
{
System.out.println("Usage: AllPduSender <port> <multicast group>");
System.out.println("Default: AllPduSender " + DEFAULT_MULTICAST_PORT + " " + DEFAULT_MULTICAST_ADDRESS);
AllPduSender sender = new AllPduSender(DEFAULT_MULTICAST_PORT, DEFAULT_MULTICAST_ADDRESS);
sender.run();
}
System.out.println("DisExamplesOpenDis7.AllPduSender complete.");
}
}
Invocation instructions:
1. run or debug AllPduSender.java
Program response:
===================================================
Usage: AllPduSender <port> <multicast group>
Default: AllPduSender 3000 239.1.2.3
DisExamplesOpenDis7.AllPduSender started...
Generate PDUs and note issues, if any...
*** Note: DISPDUType.OTHER not supported
Send the 72 PDUs we created...
Sent DIS PDU 1 ENTITY_STATE of type edu.nps.moves.dis7.EntityStatePdu
Sent DIS PDU 2 FIRE of type edu.nps.moves.dis7.FirePdu
Sent DIS PDU 3 DETONATION of type edu.nps.moves.dis7.DetonationPdu
Sent DIS PDU 4 COLLISION of type edu.nps.moves.dis7.CollisionPdu
Sent DIS PDU 5 SERVICE_REQUEST of type edu.nps.moves.dis7.ServiceRequestPdu
Sent DIS PDU 6 RESUPPLY_OFFER of type edu.nps.moves.dis7.ResupplyOfferPdu
Sent DIS PDU 7 RESUPPLY_RECEIVED of type edu.nps.moves.dis7.ResupplyReceivedPdu
Sent DIS PDU 8 RESUPPLY_CANCEL of type edu.nps.moves.dis7.ResupplyCancelPdu
Sent DIS PDU 9 REPAIR_COMPLETE of type edu.nps.moves.dis7.RepairCompletePdu
Sent DIS PDU 10 REPAIR_RESPONSE of type edu.nps.moves.dis7.RepairResponsePdu
Sent DIS PDU 11 CREATE_ENTITY of type edu.nps.moves.dis7.CreateEntityPdu
Sent DIS PDU 12 REMOVE_ENTITY of type edu.nps.moves.dis7.RemoveEntityPdu
Sent DIS PDU 13 START_RESUME of type edu.nps.moves.dis7.StartResumePdu
Sent DIS PDU 14 STOP_FREEZE of type edu.nps.moves.dis7.StopFreezePdu
Sent DIS PDU 15 ACKNOWLEDGE of type edu.nps.moves.dis7.AcknowledgePdu
Sent DIS PDU 16 ACTION_REQUEST of type edu.nps.moves.dis7.ActionRequestPdu
Sent DIS PDU 17 ACTION_RESPONSE of type edu.nps.moves.dis7.ActionResponsePdu
Sent DIS PDU 18 DATA_QUERY of type edu.nps.moves.dis7.DataQueryPdu
Sent DIS PDU 19 SET_DATA of type edu.nps.moves.dis7.SetDataPdu
Sent DIS PDU 20 DATA of type edu.nps.moves.dis7.DataPdu
Sent DIS PDU 21 EVENT_REPORT of type edu.nps.moves.dis7.EventReportPdu
Sent DIS PDU 22 COMMENT of type edu.nps.moves.dis7.CommentPdu
Sent DIS PDU 23 ELECTROMAGNETIC_EMISSION of type edu.nps.moves.dis7.ElectromagneticEmissionPdu
Sent DIS PDU 24 DESIGNATOR of type edu.nps.moves.dis7.DesignatorPdu
Sent DIS PDU 25 TRANSMITTER of type edu.nps.moves.dis7.TransmitterPdu
Sent DIS PDU 26 SIGNAL of type edu.nps.moves.dis7.SignalPdu
Sent DIS PDU 27 RECEIVER of type edu.nps.moves.dis7.ReceiverPdu
Sent DIS PDU 28 IDENTIFICATION_FRIEND_OR_FOE of type edu.nps.moves.dis7.IdentificationFriendOrFoePdu
Sent DIS PDU 29 UNDERWATER_ACOUSTIC of type edu.nps.moves.dis7.UnderwaterAcousticPdu
Sent DIS PDU 30 SUPPLEMENTAL_EMISSION_ENTITY_STATE of type edu.nps.moves.dis7.SupplementalEmissionEntityStatePdu
Sent DIS PDU 31 INTERCOM_SIGNAL of type edu.nps.moves.dis7.IntercomSignalPdu
Sent DIS PDU 32 INTERCOM_CONTROL of type edu.nps.moves.dis7.IntercomControlPdu
Sent DIS PDU 33 AGGREGATE_STATE of type edu.nps.moves.dis7.AggregateStatePdu
Sent DIS PDU 34 ISGROUPOF of type edu.nps.moves.dis7.IsGroupOfPdu
Sent DIS PDU 35 TRANSFER_OWNERSHIP of type edu.nps.moves.dis7.TransferOwnershipPdu
Sent DIS PDU 36 ISPARTOF of type edu.nps.moves.dis7.IsPartOfPdu
Sent DIS PDU 37 MINEFIELD_STATE of type edu.nps.moves.dis7.MinefieldStatePdu
Sent DIS PDU 38 MINEFIELD_QUERY of type edu.nps.moves.dis7.MinefieldQueryPdu
Sent DIS PDU 39 MINEFIELD_DATA of type edu.nps.moves.dis7.MinefieldDataPdu
Sent DIS PDU 40 MINEFIELD_RESPONSE_NACK of type edu.nps.moves.dis7.MinefieldResponseNACKPdu
Sent DIS PDU 41 ENVIRONMENTAL_PROCESS of type edu.nps.moves.dis7.EnvironmentalProcessPdu
Sent DIS PDU 42 GRIDDED_DATA of type edu.nps.moves.dis7.GriddedDataPdu
Sent DIS PDU 43 POINT_OBJECT_STATE of type edu.nps.moves.dis7.PointObjectStatePdu
Sent DIS PDU 44 LINEAR_OBJECT_STATE of type edu.nps.moves.dis7.LinearObjectStatePdu
Sent DIS PDU 45 AREAL_OBJECT_STATE of type edu.nps.moves.dis7.ArealObjectStatePdu
Sent DIS PDU 46 TIME_SPACE_POSITION_INFORMATION of type edu.nps.moves.dis7.TimeSpacePositionInformationPdu
Sent DIS PDU 47 APPEARANCE of type edu.nps.moves.dis7.AppearancePdu
Sent DIS PDU 48 ARTICULATED_PARTS of type edu.nps.moves.dis7.ArticulatedPartsPdu
Sent DIS PDU 49 LIVE_ENTITY_FIRE of type edu.nps.moves.dis7.LiveEntityFirePdu
Sent DIS PDU 50 LIVE_ENTITY_DETONATION of type edu.nps.moves.dis7.LiveEntityDetonationPdu
Sent DIS PDU 51 CREATE_ENTITY_RELIABLE of type edu.nps.moves.dis7.CreateEntityReliablePdu
Sent DIS PDU 52 REMOVE_ENTITY_RELIABLE of type edu.nps.moves.dis7.RemoveEntityReliablePdu
Sent DIS PDU 53 START_RESUME_RELIABLE of type edu.nps.moves.dis7.StartResumeReliablePdu
Sent DIS PDU 54 STOP_FREEZE_RELIABLE of type edu.nps.moves.dis7.StopFreezeReliablePdu
Sent DIS PDU 55 ACKNOWLEDGE_RELIABLE of type edu.nps.moves.dis7.AcknowledgeReliablePdu
Sent DIS PDU 56 ACTION_REQUEST_RELIABLE of type edu.nps.moves.dis7.ActionRequestReliablePdu
Sent DIS PDU 57 ACTION_RESPONSE_RELIABLE of type edu.nps.moves.dis7.ActionResponseReliablePdu
Sent DIS PDU 58 DATA_QUERY_RELIABLE of type edu.nps.moves.dis7.DataQueryReliablePdu
Sent DIS PDU 59 SET_DATA_RELIABLE of type edu.nps.moves.dis7.SetDataReliablePdu
Sent DIS PDU 60 DATA_RELIABLE of type edu.nps.moves.dis7.DataReliablePdu
Sent DIS PDU 61 EVENT_REPORT_RELIABLE of type edu.nps.moves.dis7.EventReportReliablePdu
Sent DIS PDU 62 COMMENT_RELIABLE of type edu.nps.moves.dis7.CommentReliablePdu
Sent DIS PDU 63 RECORD_RELIABLE of type edu.nps.moves.dis7.RecordReliablePdu
Sent DIS PDU 64 SET_RECORD_RELIABLE of type edu.nps.moves.dis7.SetRecordReliablePdu
Sent DIS PDU 65 RECORD_QUERY_RELIABLE of type edu.nps.moves.dis7.RecordQueryReliablePdu
Sent DIS PDU 66 COLLISION_ELASTIC of type edu.nps.moves.dis7.CollisionElasticPdu
Sent DIS PDU 67 ENTITY_STATE_UPDATE of type edu.nps.moves.dis7.EntityStateUpdatePdu
Sent DIS PDU 68 DIRECTED_ENERGY_FIRE of type edu.nps.moves.dis7.DirectedEnergyFirePdu
Sent DIS PDU 69 ENTITY_DAMAGE_STATUS of type edu.nps.moves.dis7.EntityDamageStatusPdu
Sent DIS PDU 70 INFORMATION_OPERATIONS_ACTION of type edu.nps.moves.dis7.InformationOperationsActionPdu
Sent DIS PDU 71 INFORMATION_OPERATIONS_REPORT of type edu.nps.moves.dis7.InformationOperationsReportPdu
Sent DIS PDU 72 ATTRIBUTE of type edu.nps.moves.dis7.AttributePdu
DisExamplesOpenDis7.AllPduSender complete.
BUILD SUCCESSFUL (total time: 8 seconds)
package MV3500Cohort2019JulySeptember.homework4.Yurkovich;
import java.io.*;
import java.net.*;
import java.util.*;
import edu.nps.moves.dis7.*;
import edu.nps.moves.dis7.util.*;
/**
* Receives PDUs from the network in IEEE DIS format.
* Adapted from OpenDIS library example package edu.nps.moves.examples
*
* @author DMcG
* @version $Id:$
*/
public class EspduReceiver
{
/** Max size of a PDU in binary format that we can receive. This is actually
* somewhat outdated--PDUs can be larger--but this is a reasonable starting point.
*/
public static final int MAX_PDU_SIZE = 8192;
/** Default multicast group address we send on. */
public static final String DEFAULT_MULTICAST_ADDRESS = EspduSender.DEFAULT_MULTICAST_ADDRESS;
/** Default multicast port used, matches Wireshark DIS capture default */
public static final int DEFAULT_MULTICAST_PORT = EspduSender.DEFAULT_MULTICAST_PORT;
public static void main(String args[])
{
System.out.println("DisExamplesOpenDis7.EspduReceiver started...");
MulticastSocket socket;
DatagramPacket packet;
InetAddress address;
PduFactory pduFactory = new PduFactory();
try {
// Specify the socket to receive data
socket = new MulticastSocket(DEFAULT_MULTICAST_PORT);
// socket.setBroadcast(true);
address = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS);
socket.joinGroup(address);
while (true) // Loop infinitely, receiving datagrams
{
byte buffer[] = new byte[MAX_PDU_SIZE];
packet = new DatagramPacket(buffer, buffer.length);
socket.receive(packet);
List<Pdu> pduBundle = pduFactory.getPdusFromBundle(packet.getData(),packet.getLength());
if (pduBundle.size() > 1)
System.out.println("Bundle size is " + pduBundle.size());
Iterator iterator = pduBundle.iterator();
while (iterator.hasNext())
{
Pdu aPdu = (Pdu)iterator.next();
String receiptMessage = "received PDU type " + aPdu.getPduType().getValue() + "=" + aPdu.getPduType().name() + " " + aPdu.getClass().getName();
if (aPdu instanceof EntityStatePdu)
{
System.out.println("===============");
System.out.println(receiptMessage);
EntityID entityID = ((EntityStatePdu)aPdu).getEntityID();
Vector3Double position = ((EntityStatePdu)aPdu).getEntityLocation();
System.out.println(" entityID triplet: [" + entityID.getSiteID()+ ", " + entityID.getApplicationID()+ ", " + entityID.getEntityID()+ "] ");
System.out.println(" Location in DIS coordinates: [" + position.getX() + ", " + position.getY() + ", " + position.getZ() + "]");
}
else if (aPdu instanceof FirePdu)
{
System.out.println(receiptMessage);
Vector3Double position = ((FirePdu)aPdu).getLocationInWorldCoordinates();
System.out.println(" FirePdu locationInWorldCoordinates: [" + position.getX() + ", " + position.getY() + ", " + position.getZ() + "]");
}
else
{
System.out.println(receiptMessage);
}
} // end iterator loop through PDU bundle
} // end while
} // end try block
catch (IOException e)
{
System.out.println("Problem with DisExamplesOpenDis7.EspduReceiver, see exception trace:");
System.out.println(e);
}
System.out.println("DisExamplesOpenDis7.EspduReceiver complete.");
} // end main
} // end class
package MV3500Cohort2019JulySeptember.homework4.Yurkovich;
import java.io.*;
import java.net.*;
import java.util.*;
import edu.nps.moves.dis7.*;
import edu.nps.moves.dis7.util.*;
import edu.nps.moves.dis7.enumerations.Country;
import edu.nps.moves.dis7.enumerations.EntityKind;
import edu.nps.moves.dis7.enumerations.PlatformDomain;
/**
* Creates and sends ESPDUs in IEEE binary format. Adapted from OpenDIS library
* example package edu.nps.moves.examples
*
* @author Don McGregor
* @author Don Brutzman
*/
public class EspduSender
{
public static final int NUMBER_TO_SEND = 5; // 5000
/**
* 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;
public enum NetworkMode {
UNICAST, MULTICAST, BROADCAST
};
/**
* Possible system properties, passed in via -Dattr=val networkMode:
* unicast, broadcast, multicast destinationIp: where to send the packet. If
* in multicast mode, this can be multicast. To determine broadcast
* destination IP, use an online broadcast address calculator, for example
* http://www.remotemonitoringsystems.ca/broadcast.php If in multicast mode,
* a join() will be done on the multicast address. port: port used for both
* source and destination.
*
* @param args
*/
public static void main(String args[])
{
System.out.println("DisExamplesOpenDis7.EspduSender started...");
// Default settings. These are used if no system properties are set.
// If system properties are passed in, these are overridden later.
NetworkMode networkMode = NetworkMode.BROADCAST;
InetAddress address = null; // must be initialized, even if null
int port = DEFAULT_MULTICAST_PORT;
MulticastSocket socket = null; // must be initialized to avoid later error, even if null;
EntityStatePdu espdu = new EntityStatePdu();
DisTime disTime = new DisTime();
// ICBM coordinates for my office
double latitude = 36.595517;
double longitude = -121.877000;
try
{
address = InetAddress.getByName(DEFAULT_MULTICAST_ADDRESS);
}
catch (UnknownHostException e)
{
System.out.println(e + " Cannot create multicast address");
System.exit(0);
}
// All system properties, passed in on the command line via -Dattribute=value
Properties systemProperties = System.getProperties();
// IP address we send to
String destinationIpString = systemProperties.getProperty("destinationIp");
// Port we send to, and local port we open the socket on
String portString = systemProperties.getProperty("port");
// Network mode: unicast, multicast, broadcast
String networkModeString = systemProperties.getProperty("networkMode"); // unicast or multicast or broadcast
// Set up socket to send information
try
{
if (portString != null) // Update port we send to, if provided
{
port = Integer.parseInt(portString);
}
socket = new MulticastSocket(port);
// Where we send packets to, the destination IP address
if (destinationIpString != null)
{
address = InetAddress.getByName(destinationIpString);
}
// Type of transport: unicast, broadcast, or multicast
if (networkModeString != null)
{
if (networkModeString.equalsIgnoreCase("unicast"))
{
networkMode = NetworkMode.UNICAST;
}
else if (networkModeString.equalsIgnoreCase("broadcast"))
{
networkMode = NetworkMode.BROADCAST;
}
else if (networkModeString.equalsIgnoreCase("multicast"))
{
networkMode = NetworkMode.MULTICAST;
if (!address.isMulticastAddress())
{
throw new RuntimeException("*** Error: sending to multicast address, but destination address " + address.toString() + "is not multicast");
}
socket.joinGroup(address);
}
} // end networkModeString
}
catch (IOException | RuntimeException e)
{
System.out.println("Unable to initialize network correctly, exiting.");
System.out.println(e);
System.exit(-1); // outta here
}
// Initialize values in the Entity State PDU object. The exercise ID is
// a way to differentiate between different virtual worlds on one network.
// Note that some values (such as the PDU type and PDU family) are set
// automatically when you create the ESPDU.
espdu.setExerciseID((byte)1); //(short) 1);
// The EID is the unique identifier for objects in the world. This
// EID should match up with the ID for the object specified in the
// VMRL/x3d/virtual world.
EntityID entityID = espdu.getEntityID(); // initialize, reset, override
// TODO check: 0 is apparently not a valid site number, per DIS specification
entityID.setSiteID ((short)1); // TODO utility method to allow int values
entityID.setApplicationID((short)2);
entityID.setEntityID ((short)3);
espdu.setEntityID(entityID);
// Set the entity type. SISO has a big list of enumerations, so that by
// specifying various numbers we can say this is an M1A2 American tank,
// the USS Enterprise, and so on. We'll make this a tank. There is a
// separate project elsehwhere in this project that implements DIS
// enumerations in C++ and Java, but to keep things simple we just use
// numbers here.
// New way using entity jar(s)
espdu.setEntityType(new edu.nps.moves.dis7.entities.usa.platform.land.M1A2());
// Manual way:
/*
EntityType entityType = espdu.getEntityType();
entityType.setEntityKind(EntityKind.PLATFORM); //(short) 1); // Platform (vs lifeform, munition, sensor, etc.)
entityType.setCountry(Country.UNITED_STATES_OF_AMERICA_USA); //225); // USA
entityType.setDomain(Domain.inst(PlatformDomain.LAND)); // Land (vs air, surface, subsurface, space)
entityType.setCategory((byte) 1); // Tank
entityType.setSubCategory((byte) 1); // M1 Abrams
entityType.setSpecific((byte) 3); // M1A2 Abrams
*/
Set<InetAddress> broadcastAddresses;
try // Loop through sending N ESPDUs
{
System.out.println("Sending " + NUMBER_TO_SEND + " sets of packets:"); // + address.toString()
for (int index = 0; index < NUMBER_TO_SEND; index++) {
// DIS time is a pain in the uh, neck. DIS time units are 2^31-1 units per
// hour, and time is set to DIS time units from the top of the hour.
// This means that if you start sending just before the top of the hour
// the time units can roll over to zero as you are sending. The receivers
// (escpecially homegrown ones) are often not able to detect rollover
// and may start discarding packets as dupes or out of order. We use
// an NPS timestamp here, hundredths of a second since the start of the
// year. The DIS standard for time is often ignored in the wild; I've seen
// people use Unix time (seconds since 1970) and more. Or you can
// just stuff idx into the timestamp field to get something that is monotonically
// increasing.
// Note that timestamp is used to detect duplicate and out of order packets.
// That means if you DON'T change the timestamp, many implementations will simply
// discard subsequent packets that have an identical timestamp. Also, if they
// receive a PDU with an timestamp lower than the last one they received, they
// may discard it as an earlier, out-of-order PDU. So it is a good idea to
// update the timestamp on ALL packets sent.
// An alterative approach: actually follow the standard. It's a crazy concept,
// but it might just work.
int timestamp = disTime.getDisAbsoluteTimestamp();
espdu.setTimestamp(timestamp);
// Set the position of the entity in the world. DIS uses a cartesian
// coordinate system with the origin at the center of the earth, the x
// axis out at the equator and prime meridian, y out at the equator and
// 90 deg east, and z up and out the north pole. To place an object on
// the earth's surface you also need a model for the shape of the earth
// (it's not a sphere.) All the fancy math necessary to do this is in
// the SEDRIS SRM package. There are also some one-off formulas for
// doing conversions from, for example, lat/lon/altitude to DIS coordinates.
// Here we use those one-off formulas.
// Modify the position of the object. This will send the object a little
// due east by adding some to the longitude every iteration. Since we
// are on the Pacific coast, this sends the object east. Assume we are
// at zero altitude. In other worlds you'd use DTED to determine the
// local ground altitude at that lat/lon, or you'd just use ground clamping.
// The x and y values will change, but the z value should not.
//lon = lon + (double)((double)idx / 100000.0);
//System.out.println("lla=" + lat + "," + lon + ", 0.0");
double direction = Math.pow((double) (-1.0), (double) (index));
longitude = longitude + (direction * 0.00006);
double disCoordinates[] = CoordinateConversions.getXYZfromLatLonDegrees(latitude, longitude, 1.0);
Vector3Double location = espdu.getEntityLocation();
location.setX(disCoordinates[0]);
location.setY(disCoordinates[1]);
location.setZ(disCoordinates[2]);
System.out.println("===============");
System.out.println("Create new PDUs");
System.out.println(" latitude, longitude: [" + latitude + ", " + longitude + "]");
System.out.println(" coordinate conversion: [" + disCoordinates[0] + ", " + disCoordinates[1] + ", " + disCoordinates[2] + "]");
location = espdu.getEntityLocation();
System.out.println("Espdu #" + index + " entityID=[" + entityID.getSiteID()+ "," + entityID.getApplicationID()+ "," + entityID.getEntityID()+ "]");
double c[] = {location.getX(), location.getY(), location.getZ()};
double lla[] = CoordinateConversions.xyzToLatLonDegrees(c);
// System.out.println(" DIS entityLocation: [" + location.getX() + "," + location.getY() + "," + location.getZ() + "]");
String debugString = " Location (latitude/longitude/altitude): [" + lla[0] + ", " + lla[1] + ", " + lla[2] + "]";
// System.out.println(debugString);
// Optionally, we can do some rotation of the entity
/*
Orientation orientation = espdu.getEntityOrientation();
float psi = orientation.getPsi();
psi = psi + idx;
orientation.setPsi(psi);
orientation.setTheta((float)(orientation.getTheta() + idx /2.0));
*/
// You can set other ESPDU values here, such as the velocity, acceleration,
// and so on.
// Marshal out the espdu object to a byte array, then send a datagram
// packet with that data in it.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
DatagramPacket packet;
// The byte array here is the packet in DIS format. We put that into a
// datagram and send it.
espdu.marshal(dos);
byte[] espduArray = baos.toByteArray();
FirePdu firePdu = new FirePdu();
firePdu.setLocationInWorldCoordinates(espdu.getEntityLocation());
byte[] fireArray = firePdu.marshal();
broadcastAddresses = getBroadcastAddresses();
Iterator iterator = broadcastAddresses.iterator();
while (iterator.hasNext())
{
InetAddress broadcast = (InetAddress) iterator.next();
if (espduArray.length > 0)
{
System.out.println("Sending espdu datagram packet to " + broadcast);
packet = new DatagramPacket(espduArray, espduArray.length, broadcast, port);
socket.send(packet);
}
// TODO experiment with these! 8)
if (fireArray.length > 0)
{
System.out.println("Sending fire datagram packet to " + broadcast);
packet = new DatagramPacket(fireArray, fireArray.length, broadcast, port); // alternate
socket.send(packet);
}
}
// Send every 1 second within loop. Otherwise all this will be all over in a fraction of a second.
Thread.sleep(1000); // msec
}
}
catch (Exception e)
{
System.out.println("Problem with DisExamplesOpenDis7.EspduSender, see exception trace:");
System.out.println(e);
}
System.out.println("===============");
System.out.println("DisExamplesOpenDis7.EspduSender complete.");
}
/**
* A number of sites get all snippy about using 255.255.255.255 for a
* broadcast address; it trips their security software and they kick you off
* their network. (Comcast, NPS, etc.) This determines the broadcast address for
* all connected interfaces, based on the IP and subnet mask. If you have a
* dual-homed host it will return a broadcast address for both. If you have
* some VMs running on your host this will pick up the addresses for those
* as well--e.g. running VMWare on your laptop with a local IP this will also
* pick up a 192.168 address assigned to the VM by the host OS.
*
* @return set of all broadcast addresses
*/
public static Set<InetAddress> getBroadcastAddresses()
{
Set<InetAddress> broadcastAddresses = new HashSet<>();
Enumeration interfaces;
try {
interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements())
{
NetworkInterface anInterface = (NetworkInterface) interfaces.nextElement();
if (anInterface.isUp())
{
Iterator iterator = anInterface.getInterfaceAddresses().iterator();
while (iterator.hasNext())
{
InterfaceAddress anAddress = (InterfaceAddress) iterator.next();
if ((anAddress == null || anAddress.getAddress().isLinkLocalAddress()))
{
continue;
}
//System.out.println("Getting broadcast address for " + anAddress);
InetAddress broadcastAddress = anAddress.getBroadcast();
if (broadcastAddress != null)
{
broadcastAddresses.add(broadcastAddress);
}
}
}
}
}
catch (SocketException e)
{
System.out.println("Problem with DisExamplesOpenDis7.EspduSender.getBroadcastAddresses(), see exception trace:");
System.out.println(e);
}
return broadcastAddresses;
}
}
Invocation instructions:
1. run/debug EspduReceiver.java (since sender does not block, first be ready to listen)
2. run/debug EspduSender.java
Program responses, sender and receiver:
===================================================
run:
DisExamplesOpenDis7.EspduSender started...
Sending 5 sets of packets:
===============
Create new PDUs
latitude, longitude: [36.595517, -121.87693999999999]
coordinate conversion: [-2707488.3677768684, -4353666.735244378, 3781450.3202754413]
Espdu #0 entityID=[1,2,3]
Sending espdu datagram packet to /127.255.255.255
Sending fire datagram packet to /127.255.255.255
Sending espdu datagram packet to /172.20.221.218
Sending fire datagram packet to /172.20.221.218
Sending espdu datagram packet to /10.0.0.255
Sending fire datagram packet to /10.0.0.255
===============
Create new PDUs
latitude, longitude: [36.595517, -121.877]
coordinate conversion: [-2707492.9269245286, -4353663.899966802, 3781450.3202754413]
Espdu #1 entityID=[1,2,3]
Sending espdu datagram packet to /127.255.255.255
Sending fire datagram packet to /127.255.255.255
Sending espdu datagram packet to /172.20.221.218
Sending fire datagram packet to /172.20.221.218
Sending espdu datagram packet to /10.0.0.255
Sending fire datagram packet to /10.0.0.255
===============
Create new PDUs
latitude, longitude: [36.595517, -121.87693999999999]
coordinate conversion: [-2707488.3677768684, -4353666.735244378, 3781450.3202754413]
Espdu #2 entityID=[1,2,3]
Sending espdu datagram packet to /127.255.255.255
Sending fire datagram packet to /127.255.255.255
Sending espdu datagram packet to /172.20.221.218
Sending fire datagram packet to /172.20.221.218
Sending espdu datagram packet to /10.0.0.255
Sending fire datagram packet to /10.0.0.255
===============
Create new PDUs
latitude, longitude: [36.595517, -121.877]
coordinate conversion: [-2707492.9269245286, -4353663.899966802, 3781450.3202754413]
Espdu #3 entityID=[1,2,3]
Sending espdu datagram packet to /127.255.255.255
Sending fire datagram packet to /127.255.255.255
Sending espdu datagram packet to /172.20.221.218
Sending fire datagram packet to /172.20.221.218
Sending espdu datagram packet to /10.0.0.255
Sending fire datagram packet to /10.0.0.255
===============
Create new PDUs
latitude, longitude: [36.595517, -121.87693999999999]
coordinate conversion: [-2707488.3677768684, -4353666.735244378, 3781450.3202754413]
Espdu #4 entityID=[1,2,3]
Sending espdu datagram packet to /127.255.255.255
Sending fire datagram packet to /127.255.255.255
Sending espdu datagram packet to /172.20.221.218
Sending fire datagram packet to /172.20.221.218
Sending espdu datagram packet to /10.0.0.255
Sending fire datagram packet to /10.0.0.255
===============
DisExamplesOpenDis7.EspduSender complete.
BUILD SUCCESSFUL (total time: 8 seconds)
===================================================
DisExamplesOpenDis7.EspduReceiver started...
===============
received PDU type 1=ENTITY_STATE edu.nps.moves.dis7.EntityStatePdu
entityID triplet: [1, 2, 3]
Location in DIS coordinates: [-2707488.3677768684, -4353666.735244378, 3781450.3202754413]
received PDU type 2=FIRE edu.nps.moves.dis7.FirePdu
FirePdu locationInWorldCoordinates: [-2707488.3677768684, -4353666.735244378, 3781450.3202754413]
===============
received PDU type 1=ENTITY_STATE edu.nps.moves.dis7.EntityStatePdu
entityID triplet: [1, 2, 3]
Location in DIS coordinates: [-2707488.3677768684, -4353666.735244378, 3781450.3202754413]
received PDU type 2=FIRE edu.nps.moves.dis7.FirePdu
FirePdu locationInWorldCoordinates: [-2707488.3677768684, -4353666.735244378, 3781450.3202754413]
===============
received PDU type 1=ENTITY_STATE edu.nps.moves.dis7.EntityStatePdu
entityID triplet: [1, 2, 3]
Location in DIS coordinates: [-2707492.9269245286, -4353663.899966802, 3781450.3202754413]
received PDU type 2=FIRE edu.nps.moves.dis7.FirePdu
FirePdu locationInWorldCoordinates: [-2707492.9269245286, -4353663.899966802, 3781450.3202754413]
===============
received PDU type 1=ENTITY_STATE edu.nps.moves.dis7.EntityStatePdu
entityID triplet: [1, 2, 3]
Location in DIS coordinates: [-2707492.9269245286, -4353663.899966802, 3781450.3202754413]
received PDU type 2=FIRE edu.nps.moves.dis7.FirePdu
FirePdu locationInWorldCoordinates: [-2707492.9269245286, -4353663.899966802, 3781450.3202754413]
===============
received PDU type 1=ENTITY_STATE edu.nps.moves.dis7.EntityStatePdu
entityID triplet: [1, 2, 3]
Location in DIS coordinates: [-2707488.3677768684, -4353666.735244378, 3781450.3202754413]
received PDU type 2=FIRE edu.nps.moves.dis7.FirePdu
FirePdu locationInWorldCoordinates: [-2707488.3677768684, -4353666.735244378, 3781450.3202754413]
===============
received PDU type 1=ENTITY_STATE edu.nps.moves.dis7.EntityStatePdu
entityID triplet: [1, 2, 3]
Location in DIS coordinates: [-2707488.3677768684, -4353666.735244378, 3781450.3202754413]
received PDU type 2=FIRE edu.nps.moves.dis7.FirePdu
FirePdu locationInWorldCoordinates: [-2707488.3677768684, -4353666.735244378, 3781450.3202754413]
===============
received PDU type 1=ENTITY_STATE edu.nps.moves.dis7.EntityStatePdu
entityID triplet: [1, 2, 3]
Location in DIS coordinates: [-2707492.9269245286, -4353663.899966802, 3781450.3202754413]
received PDU type 2=FIRE edu.nps.moves.dis7.FirePdu
FirePdu locationInWorldCoordinates: [-2707492.9269245286, -4353663.899966802, 3781450.3202754413]
===============
received PDU type 1=ENTITY_STATE edu.nps.moves.dis7.EntityStatePdu
entityID triplet: [1, 2, 3]
Location in DIS coordinates: [-2707492.9269245286, -4353663.899966802, 3781450.3202754413]
received PDU type 2=FIRE edu.nps.moves.dis7.FirePdu
FirePdu locationInWorldCoordinates: [-2707492.9269245286, -4353663.899966802, 3781450.3202754413]
===============
received PDU type 1=ENTITY_STATE edu.nps.moves.dis7.EntityStatePdu
entityID triplet: [1, 2, 3]
Location in DIS coordinates: [-2707488.3677768684, -4353666.735244378, 3781450.3202754413]
received PDU type 2=FIRE edu.nps.moves.dis7.FirePdu
FirePdu locationInWorldCoordinates: [-2707488.3677768684, -4353666.735244378, 3781450.3202754413]
===============
received PDU type 1=ENTITY_STATE edu.nps.moves.dis7.EntityStatePdu
entityID triplet: [1, 2, 3]
Location in DIS coordinates: [-2707488.3677768684, -4353666.735244378, 3781450.3202754413]
received PDU type 2=FIRE edu.nps.moves.dis7.FirePdu
FirePdu locationInWorldCoordinates: [-2707488.3677768684, -4353666.735244378, 3781450.3202754413]
===================================================
\ No newline at end of file
/**
* Copyright (c) 2008-2019, MOVES Institute, Naval Postgraduate School. All rights reserved.
* This work is licensed under the BSD open source license, available at https://www.movesinstitute.org/licenses/bsd.html
*/
package MV3500Cohort2019JulySeptember.homework4.Yurkovich;
import edu.nps.moves.dis7.util.playerrecorder.Recorder;
import java.io.IOException;
import java.util.Scanner;
/**
* PduSaver.java created on Aug 21, 2019
* MOVES Institute Naval Postgraduate School, Monterey, CA, USA www.nps.edu
*
* @author Mike Bailey, jmbailey@nps.edu
* @version $Id$
*/
public class PduListenerSaver
{
private final static String DEFAULT_OUTPUTDIR = "./pduLog";
private final static String MCAST_ADDR = "239.1.2.3";
private final static int DIS_PORT = 3000;
private enum mystate
{
RUNNING,
PAUSED;
}
public static void main(String[] args)
{
String outDir = DEFAULT_OUTPUTDIR;
String mcast = MCAST_ADDR;
int port = DIS_PORT;
switch (args.length) {
case 0:
break;
case 1:
outDir = args[0];
break;
case 3:
outDir = args[0];
mcast = args[1];
port = Integer.parseInt(args[2]);
break;
default:
System.err.println("Usage: PduListener() or PduListener(\"outputdir\") or PduListener(\"outputdir\",\"multicast address\", ipPort");
System.exit(1);
}
System.out.println("Beginning pdu save to directory " + outDir);
try {
Recorder recorder = new Recorder(outDir, mcast, port);
recorder.startResume();
mystate state = mystate.RUNNING;
Scanner scan = new Scanner(System.in);
while (true) {
System.out.println("Type p/enter to pause, r/enter to resume, q/enter to quit");
String line = scan.nextLine();
if (line.equalsIgnoreCase("p") && state == mystate.RUNNING) {
recorder.stopPause();
state = mystate.PAUSED;
}
else if (line.equalsIgnoreCase("r") && state == mystate.PAUSED) {
recorder.startResume();
state = mystate.RUNNING;
}
else if (line.equalsIgnoreCase("q")) {
recorder.end();
break;
}
}
System.out.println("Ending pdu save to "+recorder.getLogFile());
}
catch (IOException ex) {
System.err.println("Exception: " + ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage());
}
}
}
/**
* Copyright (c) 2008-2019, MOVES Institute, Naval Postgraduate School. All rights reserved.
* This work is licensed under the BSD open source license, available at https://www.movesinstitute.org/licenses/bsd.html
*/
package MV3500Cohort2019JulySeptember.homework4.Yurkovich;
import edu.nps.moves.dis7.util.playerrecorder.Player;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
/**
* PduSaver.java created on Aug 21, 2019
* MOVES Institute Naval Postgraduate School, Monterey, CA, USA www.nps.edu
*
* @author Mike Bailey, jmbailey@nps.edu
* @version $Id$
*/
public class PduReaderPlayer
{
private final static String DEFAULT_OUTPUTDIR = "pduLog";
private final static String MCAST_ADDR = "239.1.2.3";
private final static int DIS_PORT = 3000;
private enum mystate
{
RUNNING,
PAUSED;
}
public static void main(String[] args)
{
String outDir = DEFAULT_OUTPUTDIR;
String mcast = MCAST_ADDR;
int port = DIS_PORT;
System.out.println("DisExamplesOpenDis7.PduReaderPlayer started...");
switch (args.length) {
case 0:
break;
case 1:
outDir = args[0];
break;
case 3:
outDir = args[0];
mcast = args[1];
port = Integer.parseInt(args[2]);
break;
default:
System.err.println("Usage: PduReaderPlayer() or PduReaderPlayer(\"outputdir\") or PduReaderPlayer(\"outputdir\",\"multicast address\", ipPort");
System.exit(1);
}
System.out.println("Beginning pdu playback from directory " + outDir);
try {
Player player = new Player(mcast, port, new File(outDir).toPath());
player.startResume();
mystate state = mystate.RUNNING;
Scanner scan = new Scanner(System.in);
while (true) {
System.out.println("Type p/enter to pause, r/enter to resume, q/enter to quit");
String line = scan.nextLine();
if (line.equalsIgnoreCase("p") && state == mystate.RUNNING) {
player.stopPause();
state = mystate.PAUSED;
}
else if (line.equalsIgnoreCase("r") && state == mystate.PAUSED) {
player.startResume();
state = mystate.RUNNING;
}
else if (line.equalsIgnoreCase("q")) {
player.end();
break;
}
}
System.out.println("Ending pdu files playback for directory " + outDir);
System.out.println("DisExamplesOpenDis7.PduReaderPlayer complete.");
System.exit(0); // not sure why this is necessary with Netbeans...
}
catch (IOException ex) {
System.err.println("Exception: " + ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage());
}
}
}
Invocation instructions:
0. check for existence of recorded files in directory, e.g. examples/pduLog/Pdusave.dislog
1. first running AllPduReceiver can confirm that DIS replay actually occurs.
2. run or debug PduReaderPlayer.java
3. Type p/enter to pause, r/enter to resume, q/enter to quit
Program response:
===================================================
DisExamplesOpenDis7.PduReaderPlayer started...
Beginning pdu playback from directory pduLog
Replaying DIS logs.
Replaying C:\x-nps-gitlab\NetworkedGraphicsMV3500\examples\pduLog\Pdusave.dislog
Beginning of DIS capture file, Pdusave.dislog.
Type p/enter to pause, r/enter to resume, q/enter to quit
72
End of replay from Pdusave.dislog
End of DIS capture file, Pdusave.dislog.
q
Ending pdu files playback for directory pduLog
DisExamplesOpenDis7.PduReaderPlayer complete.
BUILD SUCCESSFUL (total time: 20 seconds)
\ No newline at end of file
# DIS Protocol Examples using Open-DIS-Java Library v7
TODO under development!
Course examples using the [Open-DIS-Java](https://github.com/open-dis/open-dis-java) library are presented in this package.
See [specifications](../../../specifications) directory to obtain reference copies of DIS and RPRFOM standards.
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