Skip to content
Snippets Groups Projects
Commit 22c77aa9 authored by Brutzman, Don's avatar Brutzman, Don
Browse files

license year, PDU simple name (without path)

parent 49afdec3
No related branches found
No related tags found
No related merge requests found
package OpenDis4Examples;
import java.net.*;
import java.util.*;
import edu.nps.moves.disutil.*;
import edu.nps.moves.dis.*;
import java.io.IOException;
/**
* 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.
*/
private static final int MAX_PDU_SIZE = 8192;
/** Default multicast group address we send on.
* @see <a href="https://en.wikipedia.org/wiki/Multicast_address">https://en.wikipedia.org/wiki/Multicast_address</a> */
private static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3";
/** Default multicast port used, matches Wireshark DIS capture default
* @see <a href="https://en.wikipedia.org/wiki/Port_(computer_networking)">https://en.wikipedia.org/wiki/Port_(computer_networking)</a> */
private static final int DEFAULT_MULTICAST_PORT = 3000;
/**
* Program invocation, execution starts here
* @param args command-line arguments
*/
public static void main(String args[])
{
System.out.println("OpenDis4Examples.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(EspduSender.DEFAULT_MULTICAST_GROUP);
// 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());
System.out.println("Bundle size is " + pduBundle.size());
Iterator iterator = pduBundle.iterator();
while(iterator.hasNext())
{
Pdu aPdu = (Pdu)iterator.next();
System.out.print("got PDU of type: " + aPdu.getClass().getName());
if(aPdu instanceof EntityStatePdu)
{
EntityID eid = ((EntityStatePdu)aPdu).getEntityID();
Vector3Double position = ((EntityStatePdu)aPdu).getEntityLocation();
System.out.print(" EID:[" + eid.getSite() + ", " + eid.getApplication() + ", " + eid.getEntity() + "] ");
System.out.print(" Location in DIS coordinates: [" + position.getX() + ", " + position.getY() + ", " + position.getZ() + "]");
}
System.out.println();
} // end trop through PDU bundle
} // end while
} // End try
catch (IOException e)
{
System.out.println("Problem with OpenDis4Examples.EspduReceiver, see exception trace:");
System.out.println(e);
}
} // end main
} // end class
package OpenDis4Examples;
import java.net.*;
import java.util.*;
import edu.nps.moves.disutil.*;
import edu.nps.moves.dis.*;
import java.io.IOException;
/**
* 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.
*/
private static final int MAX_PDU_SIZE = 8192;
/** Default multicast group address we send on.
* @see <a href="https://en.wikipedia.org/wiki/Multicast_address">https://en.wikipedia.org/wiki/Multicast_address</a> */
private static final String DEFAULT_MULTICAST_ADDRESS = "239.1.2.3";
/** Default multicast port used, matches Wireshark DIS capture default
* @see <a href="https://en.wikipedia.org/wiki/Port_(computer_networking)">https://en.wikipedia.org/wiki/Port_(computer_networking)</a> */
private static final int DEFAULT_MULTICAST_PORT = 3000;
/**
* Program invocation, execution starts here
* @param args command-line arguments
*/
public static void main(String args[])
{
System.out.println("OpenDis4Examples.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(EspduSender.DEFAULT_MULTICAST_GROUP);
// 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());
System.out.println("Bundle size is " + pduBundle.size());
Iterator iterator = pduBundle.iterator();
while(iterator.hasNext())
{
Pdu aPdu = (Pdu)iterator.next();
System.out.print("got PDU of type: " + aPdu.getClass().getSimpleName());
if(aPdu instanceof EntityStatePdu)
{
EntityID eid = ((EntityStatePdu)aPdu).getEntityID();
Vector3Double position = ((EntityStatePdu)aPdu).getEntityLocation();
System.out.print(" EID:[" + eid.getSite() + ", " + eid.getApplication() + ", " + eid.getEntity() + "] ");
System.out.print(" Location in DIS coordinates: [" + position.getX() + ", " + position.getY() + ", " + position.getZ() + "]");
}
System.out.println();
} // end trop through PDU bundle
} // end while
} // End try
catch (IOException e)
{
System.out.println("Problem with OpenDis4Examples.EspduReceiver, see exception trace:");
System.out.println(e);
}
} // end main
} // end class
......@@ -53,7 +53,7 @@ public class PduReceiver
if (pdu != null)
{
short currentPduType = pdu.getPduType();
String currentPduTypeName = pdu.getClass().getName();
String currentPduTypeName = pdu.getClass().getSimpleName();
short currentProtocolFamilyID = pdu.getProtocolFamily();
String currentPduFamilyName = pdu.getClass().getSuperclass().getSimpleName();
......
......@@ -184,7 +184,7 @@ public class PduSender
buffer = baos.toByteArray();
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, localMulticastAddress, DEFAULT_MULTICAST_PORT);
socket.send(packet);
System.out.println("Sent PDU of type " + aPdu.getClass().getName());
System.out.println("Sent PDU of type " + aPdu.getClass().getSimpleName());
}
// write the PDUs out to an XML file.
//PduContainer container = new PduContainer();
......
/**
* Copyright (c) 2008-2021, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved.
* Copyright (c) 2008-2022, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved.
* This work is provided under a BSD open-source license, see project license.html and license.txt
* @author brutzman@nps.edu
*/
......
/**
* Copyright (c) 2008-2021, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved.
* Copyright (c) 2008-2022, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved.
* This work is provided under a BSD open-source license, see project license.html and license.txt
*
* @author brutzman@nps.edu
......
/**
* Copyright (c) 2008-2021, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved.
* Copyright (c) 2008-2022, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved.
* This work is provided under a BSD open-source license, see project license.html and license.txt
*/
package OpenDis7Examples;
......
/**
* Copyright (c) 2008-2021, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved.
* Copyright (c) 2008-2022, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved.
* This work is provided under a BSD open-source license, see project license.html and license.txt
*/
package OpenDis7Examples;
......
/*
Copyright (c) 1995-2021 held by the author(s). All rights reserved.
Copyright (c) 1995-2022 held by the author(s). All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
......
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