Please review any and all PUBLIC repositories, groups and associate files. These allow anyone on the Internet to access without authentication. Repository and group owners are responsible for their content and permission settings. Go to your project(s), click on Settings > General and expand the "Visibility, project features, permissions" to change this setting.

Renamed the folder to BrennenstuhlTobias

parent 669ec6c7
......@@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package PduStreamTools;
package DISTools;
import static java.lang.Math.pow;
import static java.lang.Math.sqrt;
......
......@@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package PduStreamTools;
package DISTools;
/**
*
......
package PduStreamTools;
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 String DEFAULT_MULTICAST_ADDRESS;
/** Default multicast port used, matches Wireshark DIS capture default */
public int DEFAULT_MULTICAST_PORT;
public String receive(String localBroadCastAddress, int localPort)
{
System.out.println("DisExamplesOpenDis7.EspduReceiver started...");
String returnString;
returnString = new String("Test Return Receiver \n");
this.DEFAULT_MULTICAST_ADDRESS = localBroadCastAddress;
this.DEFAULT_MULTICAST_PORT = localPort;
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);
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());
returnString += "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("===============");
returnString += "===============\n";
System.out.println(receiptMessage);
returnString += receiptMessage + "\n";
EntityID entityID = ((EntityStatePdu)aPdu).getEntityID();
Vector3Double position = ((EntityStatePdu)aPdu).getEntityLocation();
System.out.println(" entityID triplet: [" + entityID.getSiteID()+ ", " + entityID.getApplicationID()+ ", " + entityID.getEntityID()+ "] ");
returnString += " entityID triplet: [" + entityID.getSiteID()+ ", " + entityID.getApplicationID()+ ", " + entityID.getEntityID()+ "] ";
System.out.println(" Location in DIS coordinates: [" + position.getX() + ", " + position.getY() + ", " + position.getZ() + "]\n");
returnString += " Location in DIS coordinates: [" + position.getX() + ", " + position.getY() + ", " + position.getZ() + "]\n";
}
else if (aPdu instanceof FirePdu)
{
System.out.println(receiptMessage);
returnString += receiptMessage + "\n";
Vector3Double position = ((FirePdu)aPdu).getLocationInWorldCoordinates();
System.out.println(" FirePdu locationInWorldCoordinates: [" + position.getX() + ", " + position.getY() + ", " + position.getZ() + "]");
returnString += " FirePdu locationInWorldCoordinates: [" + position.getX() + ", " + position.getY() + ", " + position.getZ() + "]\n";
}
else
{
System.out.println(receiptMessage);
returnString += receiptMessage + "\n";
}
} // end iterator loop through PDU bundle
} // end try block
catch (IOException e)
{
System.out.println("Problem with DisExamplesOpenDis7.EspduReceiver, see exception trace:");
returnString += "Problem with DisExamplesOpenDis7.EspduReceiver, see exception trace:\n";
System.out.println(e);
returnString += e + "\n";
}
System.out.println("DisExamplesOpenDis7.EspduReceiver complete.");
return returnString;
} // end main
} // end class
This diff is collapsed.
......@@ -8,85 +8,76 @@ 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
* 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;
public class PduListenerSaver {
private enum mystate
{
RUNNING,
PAUSED;
}
private final static String DEFAULT_OUTPUTDIR = "pduLog";
private final static String MCAST_ADDR = "239.1.2.3";
private final static int DIS_PORT = 3000;
public static void main(String[] args)
{
String outDir = DEFAULT_OUTPUTDIR;
String mcast = MCAST_ADDR;
int port = DIS_PORT;
System.out.println("DisExamplesOpenDis7.PduListenerSaver 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: PduListener() or PduListener(\"outputdir\") or PduListener(\"outputdir\",\"multicast address\", ipPort");
System.exit(1);
private enum mystate {
RUNNING,
PAUSED;
}
System.out.println("Beginning pdu save to directory " + outDir);
try {
//RecorderTobi stores an unencoded PduLog
RecorderTobi recorder = new RecorderTobi(outDir, mcast, port);
//Recorder stores a BASE64 encoded PduLod
//Recorder recorder = new Recorder(outDir, mcast, port);
recorder.startResume();
mystate state = mystate.RUNNING;
System.out.println("* recorder.startResume(), state=RUNNING, recording in progress...");
Scanner scan = new Scanner(System.in);
public static void main(String[] args) throws IOException {
String outDir = DEFAULT_OUTPUTDIR;
String mcast = MCAST_ADDR;
int port = DIS_PORT;
while (true) {
System.out.println("Warning: you must quit when complete, otherwise recorded PDUs are lost!");
System.out.println("Type p/enter to pause, r/enter to resume, q/enter to stop recording, save and quit");
String line = scan.nextLine();
if (line.equalsIgnoreCase("p") && state == mystate.RUNNING) {
recorder.stopPause();
state = mystate.PAUSED;
System.out.println("* recorder.stopPause(), state=PAUSED, recording paused...");
}
else if (line.equalsIgnoreCase("r") && state == mystate.PAUSED) {
recorder.startResume();
state = mystate.RUNNING;
System.out.println("* recorder.startResume(), state=RUNNING, recording in progress...");
System.out.println("DisExamplesOpenDis7.PduListenerSaver 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: PduListener() or PduListener(\"outputdir\") or PduListener(\"outputdir\",\"multicast address\", ipPort");
System.exit(1);
}
else if (line.equalsIgnoreCase("q")) {
recorder.end();
System.out.println("* recorder.end(), recording complete.");
break;
System.out.println("Beginning pdu save to directory " + outDir);
//RecorderPlainText stores an unencoded PduLog
//RecorderPlainText recorder = new RecorderPlainText(outDir, mcast, port);
//RecorderBase64 stores a BASE64 encoded PduLog
//RecorderBase64 recorder = new RecorderBase64(outDir, mcast, port);
//RecorderBinary stores a Binary PduLog
RecorderBinary recorder = new RecorderBinary(outDir, mcast, port);
recorder.startResume();
mystate state = mystate.RUNNING;
System.out.println("* recorder.startResume(), state=RUNNING, recording in progress...");
Scanner scan = new Scanner(System.in);
while (true) {
System.out.println("Warning: you must quit when complete, otherwise recorded PDUs are lost!");
System.out.println("Type p/enter to pause, r/enter to resume, q/enter to stop recording, save and quit");
String line = scan.nextLine();
if (line.equalsIgnoreCase("p") && state == mystate.RUNNING) {
recorder.stopPause();
state = mystate.PAUSED;
System.out.println("* recorder.stopPause(), state=PAUSED, recording paused...");
} else if (line.equalsIgnoreCase("r") && state == mystate.PAUSED) {
recorder.startResume();
state = mystate.RUNNING;
System.out.println("* recorder.startResume(), state=RUNNING, recording in progress...");
} else if (line.equalsIgnoreCase("q")) {
recorder.end();
System.out.println("* recorder.end(), recording complete.");
break;
}
}
}
System.out.println("Ending pdu save to "+recorder.getLogFile());
}
catch (IOException ex) {
System.err.println("*** Exception: " + ex.getClass().getSimpleName() + ": " + ex.getLocalizedMessage());
System.out.println("Ending pdu save to " + recorder.getLogFile());
}
}
}
......@@ -53,10 +53,11 @@ public class PduReaderPlayer {
try {
//Use Tobis Code without decryption
//Does only work with unecrypted PduLogs
PlayerTobi player = new PlayerTobi(mcast, port, new File(outDir).toPath());
//Use Mikes Code
//Player player = new Player(mcast, port, new File(outDir).toPath());
//PlayerPlainText player = new PlayerPlainText(mcast, port, new File(outDir).toPath());
//Use Mike Baileys Code to store a file in BASE64 format
PlayerBase64 player = new PlayerBase64(mcast, port, new File(outDir).toPath());
player.startResume();
mystate state = mystate.RUNNING;
Scanner scan = new Scanner(System.in);
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package PduStreamTools;
public interface PduReceiver
{
void receivePdu(byte[] buff, int len);
}
......@@ -9,6 +9,9 @@ package PduStreamTools;
* This work is licensed under the BSD open source license, available at https://www.movesinstitute.org/licenses/bsd.html
*/
import static PduStreamTools.RecorderBase64.COMMENT_MARKER;
import static PduStreamTools.RecorderBase64.START_COMMENT_MARKER;
import static PduStreamTools.RecorderBase64.STOP_COMMENT_MARKER;
import com.google.common.primitives.Longs;
import java.io.*;
......@@ -19,16 +22,15 @@ import java.nio.file.Path;
import java.util.Arrays;
import java.util.Base64;
import static PduStreamTools.Recorder.*;
public class Player
public class PlayerBase64
{
private Path disLogDirectory;
private String ip;
private int port;
private Thread thrd;
public Player(String ip, int port, Path disLogDirectory) throws IOException
public PlayerBase64(String ip, int port, Path disLogDirectory) throws IOException
{
this.disLogDirectory = disLogDirectory;
this.ip = ip;
......@@ -56,7 +58,7 @@ public class Player
System.out.println("Replaying DIS logs.");
InetAddress addr = InetAddress.getByName(ip);
FilenameFilter filter = (dir, name) -> name.endsWith(Recorder.DISLOG_FILE_TAIL) && !name.startsWith(".");
FilenameFilter filter = (dir, name) -> name.endsWith(RecorderBase64.DISLOG_FILE_TAIL) && !name.startsWith(".");
File[] fs = disLogDirectory.toFile().listFiles(filter);
if (fs == null)
......@@ -221,7 +223,7 @@ public class Player
{
try {
//new Player("230.0.0.0", 3000, new File("./pdulog").toPath()).startResume();
new Player("230.0.0.0", 3000, new File("/Users/mike/NetbeansProjects/open-dis7-java/examples/pdulog").toPath());
new PlayerBase64("230.0.0.0", 3000, new File("/Users/mike/NetbeansProjects/open-dis7-java/examples/pdulog").toPath());
}
catch (Exception ex) {
ex.printStackTrace();
......
......@@ -10,9 +10,9 @@ package PduStreamTools;
* rights reserved. This work is licensed under the BSD open source license,
* available at https://www.movesinstitute.org/licenses/bsd.html
*/
import static PduStreamTools.Recorder.COMMENT_MARKER;
import static PduStreamTools.Recorder.START_COMMENT_MARKER;
import static PduStreamTools.Recorder.STOP_COMMENT_MARKER;
import static PduStreamTools.RecorderBase64.COMMENT_MARKER;
import static PduStreamTools.RecorderBase64.START_COMMENT_MARKER;
import static PduStreamTools.RecorderBase64.STOP_COMMENT_MARKER;
import com.google.common.primitives.Longs;
import edu.nps.moves.dis7.EntityStatePdu;
import edu.nps.moves.dis7.Pdu;
......@@ -35,14 +35,14 @@ import java.util.Set;
import java.util.TreeMap;
import java.util.regex.Pattern;
public class PlayerTobi {
public class PlayerPlainText {
private Path disLogDirectory;
private String ip;
private int port;
private Thread thrd;
public PlayerTobi(String ip, int port, Path disLogDirectory) throws IOException {
public PlayerPlainText(String ip, int port, Path disLogDirectory) throws IOException {
this.disLogDirectory = disLogDirectory;
this.ip = ip;
this.port = port;
......@@ -68,7 +68,7 @@ public class PlayerTobi {
System.out.println("Replaying DIS logs.");
InetAddress addr = InetAddress.getByName(ip);
FilenameFilter filter = (dir, name) -> name.endsWith(Recorder.DISLOG_FILE_TAIL) && !name.startsWith(".");
FilenameFilter filter = (dir, name) -> name.endsWith(RecorderBase64.DISLOG_FILE_TAIL) && !name.startsWith(".");
File[] fs = disLogDirectory.toFile().listFiles(filter);
if (fs == null) {
......@@ -466,7 +466,7 @@ public class PlayerTobi {
public static void main(String[] args) {
try {
//new Player("230.0.0.0", 3000, new File("./pdulog").toPath()).startResume();
new PlayerTobi("239.1.2.3", 3000, new File("/Users/mike/NetbeansProjects/open-dis7-java/examples/pdulog").toPath());
new PlayerPlainText("239.1.2.3", 3000, new File("/Users/mike/NetbeansProjects/open-dis7-java/examples/pdulog").toPath());
} catch (Exception ex) {
ex.printStackTrace();
}
......
......@@ -22,7 +22,7 @@ import java.nio.file.Path;
import java.util.Arrays;
import java.util.Base64;
public class Recorder implements edu.nps.moves.dis7.util.playerrecorder.PduReceiver
public class RecorderBase64 implements edu.nps.moves.dis7.util.playerrecorder.PduReceiver
{
static String DEFAULT_OUTDIR = "./pdulog";
static String DEFAULT_FILEPREFIX = "Pdusave";
......@@ -40,12 +40,12 @@ public class Recorder implements edu.nps.moves.dis7.util.playerrecorder.PduRecei
private DisNetworking disnet;
private Thread receiverThrd;
public Recorder() throws IOException
public RecorderBase64() throws IOException
{
this(DEFAULT_OUTDIR,DEFAULT_MCAST,DEFAULT_PORT);
}
public Recorder(String outputDir, String mcastaddr, int port) throws IOException
public RecorderBase64(String outputDir, String mcastaddr, int port) throws IOException
{
logFile = makeFile(new File(outputDir).toPath(), DEFAULT_FILEPREFIX+DISLOG_FILE_TAIL );
bwr = new BufferedWriter(new FileWriter(logFile));
......@@ -107,7 +107,7 @@ public class Recorder implements edu.nps.moves.dis7.util.playerrecorder.PduRecei
Long startNanoTime = null;
StringBuilder sb = new StringBuilder();
//Base64.Encoder encdr = Base64.getEncoder();
Base64.Encoder encdr = Base64.getEncoder();
int pduCount = 0;
boolean headerWritten = false;
boolean dosave = true;
......@@ -126,12 +126,10 @@ public class Recorder implements edu.nps.moves.dis7.util.playerrecorder.PduRecei
//System.out.println("wrote time "+(packetRcvNanoTime - startNanoTime));
sb.setLength(0);
//sb.append(encdr.encodeToString(timeAr));
sb.append(Arrays.toString(timeAr));
sb.append(encdr.encodeToString(timeAr));
sb.append(',');
byte[] buffsized = Arrays.copyOf(buff, len);
//sb.append(encdr.encodeToString(buffsized));
sb.append(Arrays.toString(buffsized));
sb.append(encdr.encodeToString(buffsized));
try {
if (!headerWritten) {
writeHeader();
......@@ -205,8 +203,8 @@ public class Recorder implements edu.nps.moves.dis7.util.playerrecorder.PduRecei
Path path = new File("./pdulog").toPath();
String filename = "Pdusave";
Recorder recorder;
try{recorder = new Recorder();} catch(IOException ex) {
RecorderBase64 recorder;
try{recorder = new RecorderBase64();} catch(IOException ex) {
System.err.println("Exception creating recorder: "+ex.getLocalizedMessage());
return;
}
......@@ -224,7 +222,7 @@ public class Recorder implements edu.nps.moves.dis7.util.playerrecorder.PduRecei
}
}
});
sleep(2000L);
sleep(2000);
recorder.end();
}
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package PduStreamTools;
import com.google.common.primitives.Longs;
import edu.nps.moves.dis7.Pdu;
import edu.nps.moves.dis7.enumerations.DISPDUType;
import edu.nps.moves.dis7.util.DisNetworking;
import edu.nps.moves.dis7.util.DisNetworking.BuffAndLength;
import edu.nps.moves.dis7.util.PduFactory;
import org.apache.commons.io.FilenameUtils;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
public class RecorderBinary implements PduReceiver
{
static String DEFAULT_OUTDIR = "./pdulog";
static String DEFAULT_FILEPREFIX = "Pdusave";
static String DEFAULT_MCAST = "239.1.2.3";
static int DEFAULT_PORT = 3000;
static String DISLOG_FILE_TAIL = ".dislog";
public static String COMMENT_MARKER = "!";
static String START_COMMENT_MARKER = COMMENT_MARKER + "Begin" + COMMENT_MARKER;
static String STOP_COMMENT_MARKER = COMMENT_MARKER + "End" + COMMENT_MARKER;
private BufferedWriter bwr;
private File logFile;
private DisNetworking disnet;
private Thread receiverThrd;
public RecorderBinary() throws IOException
{
this(DEFAULT_OUTDIR,DEFAULT_MCAST,DEFAULT_PORT);
}
public RecorderBinary(String outputDir, String mcastaddr, int port) throws IOException
{
logFile = makeFile(new File(outputDir).toPath(), DEFAULT_FILEPREFIX+DISLOG_FILE_TAIL );
bwr = new BufferedWriter(new FileWriter(logFile));
disnet = new DisNetworking(port, mcastaddr);
// Start a thread to receive and record pdus
receiverThrd = new Thread(()->{
int count = 1;
while(!Thread.interrupted()){
try {
BuffAndLength blen = disnet.receiveRawPdu();
//System.out.println(""+ count++ +" Got pdu from DisNetworking");
receivePdu(blen.buff,blen.length);
}
catch(IOException ex) {
// this is the normal exception if you do disnet.stop() System.err.println("Exception receiving Pdu: "+ex.getLocalizedMessage());
}
}
});
receiverThrd.setPriority(Thread.NORM_PRIORITY);
receiverThrd.setDaemon(true);
receiverThrd.start();
}
public void startResume()
{
dosave = true;
}
public void stopPause()
{
dosave = false;
}
public String getOutputFile()
{
if(logFile != null)
return logFile.getAbsolutePath();
return null;
}
public void end()
{
disnet.stop();
receiverThrd.interrupt();
try {
writeFooter();
bwr.flush();
bwr.close();
System.out.println();
System.out.println("Recorder log file closed");
}
catch (IOException ex) {
System.out.println("IOException closing file: " + ex.getMessage());
}
}
Long startNanoTime = null;
StringBuilder sb = new StringBuilder();
int pduCount = 0;
boolean headerWritten = false;
boolean dosave = true;
@Override
public void receivePdu(byte[] buff, int len)
{
if(!dosave)
return;
long packetRcvNanoTime = System.nanoTime();
if (startNanoTime == null)
startNanoTime = packetRcvNanoTime;
byte[] timeAr = Longs.toByteArray(packetRcvNanoTime - startNanoTime);
//System.out.println("wrote time "+(packetRcvNanoTime - startNanoTime));
sb.setLength(0);
sb.append(Arrays.toString(timeAr));
sb.append(',');
byte[] buffsized = Arrays.copyOf(buff, len);
sb.append(Arrays.toString(buffsized));
try {
if (!headerWritten) {
writeHeader();
headerWritten = true;
}
//Added a REGEX to strip all spaces from the string before writing to file
bwr.write(sb.toString().replaceAll("\\s",""));
bwr.newLine();
}
catch (IOException ex) {
System.