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.

Initial upload of changed files from private project. Also added the libs.

parent 03432361
/Brennenstuhl/nbproject/private/
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
!Begin!Beginning of DIS capture file, Pdusave4.dislog. [PDU Header],[PDU Stream]
[0,0,0,0,25,-31,0,0],[7,0,5,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
[0,0,0,0,32,5,-36,88],[7,0,6,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
[0,0,0,0,38,43,-73,96],[7,0,7,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
[0,0,0,0,44,49,-50,-60],[7,0,8,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
[0,0,0,0,50,56,113,56],[7,0,9,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
[0,0,0,0,56,62,-116,32],[7,0,10,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
[0,0,0,0,62,69,-56,124],[7,0,11,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
[0,0,0,0,68,93,94,-56],[7,0,12,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
!End!End of DIS capture file, Pdusave4.dislog.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
!Begin!Beginning of DIS capture file, Pdusave.dislog. [PDU Header],[PDU Stream]
[0,0,0,0,0,0,0,0],[B@5c884fd0
[0,0,0,0,33,55,-1,12],[B@1052d894
[0,0,0,0,-5,-90,8,-96],[B@cfb77b1
[0,0,0,1,42,117,-65,24],[B@2f6f2e70
[0,0,0,1,120,127,104,-68],[B@7eb7c289
!End!End of DIS capture file, Pdusave.dislog.
!Begin!Beginning of DIS capture file, Pdusave1.dislog. [PDU Header],[PDU Stream]
[0,0,0,0,0,0,0,0][B@7e0210b4,[B@4ceb7d75
[0,0,0,0,15,-123,-106,-84][B@2fb955dd,[B@4af2482a
[0,0,0,0,40,-121,-54,88][B@42856fc3,[B@55ee8e64
[0,0,0,1,42,-59,-20,124][B@301c3eb9,[B@68779388
!End!End of DIS capture file, Pdusave1.dislog.
!Begin!Beginning of DIS capture file, Pdusave3.dislog.
AAAAABnRSPQ=,BwAFAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
AAAAAB/m8kg=,BwAGAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
AAAAACXtWVw=,BwAHAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
AAAAACvzmWA=,BwAIAwAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAADH7KVQ=,BwAJAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
AAAAADgffug=,BwAKAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
AAAAAD5FCqQ=,BwALBQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
AAAAAERbrfg=,BwAMBQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
!End!End of DIS capture file, Pdusave3.dislog.
......@@ -4,6 +4,7 @@
*/
package PduStreamTools;
import PduStreamTools.RecorderBinary;
import java.io.IOException;
import java.util.Scanner;
......@@ -26,7 +27,7 @@ public class PduListenerSaver
PAUSED;
}
public static void main(String[] args)
public static void main(String[] args) throws IOException
{
String outDir = DEFAULT_OUTPUTDIR;
String mcast = MCAST_ADDR;
......@@ -51,42 +52,37 @@ public class PduListenerSaver
}
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);
while (true) {
//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...");
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...");
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;
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,10 @@ 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());
PlayerPlainText player = new PlayerPlainText(mcast, port, new File(outDir).toPath());
//Use Mikes Code
//Player player = new Player(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);
......
......@@ -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.err.println("Fatal exception writing DIS log file in Recorder.start()");
throw new RuntimeException(ex);
}
System.out.print(++pduCount + "\r");
//bwr.flush();
sb.setLength(0);
}
public String getLogFile()
{
return logFile.getAbsolutePath();
}
private void writeHeader() throws IOException
{
String template = "Beginning of DIS capture file, %s. [PDU Header],[PDU Stream]";
String startComment = String.format(template, logFile.getName());
bwr.write(START_COMMENT_MARKER + startComment);
bwr.newLine();
}
private void writeFooter() throws IOException
{
String template = "End of DIS capture file, %s.";
String endComment = String.format(template, logFile.getName());
bwr.write(STOP_COMMENT_MARKER + endComment);
bwr.newLine();
}
private File makeFile(Path outputDir, String filename) throws IOException
{
String bname = FilenameUtils.getBaseName(filename);
String ext = FilenameUtils.getExtension(filename);
Integer count = null;
File f;
boolean fileExists;
outputDir.toFile().mkdirs();
do {
String fn = bname + (count == null ? "" : count) + "." + ext;
f = new File(outputDir.toFile(), fn);
fileExists = f.exists();
if (count == null)
count = 1;
else
count++;
} while (fileExists);
if (!f.createNewFile()) {
System.out.println("Cannot create dis log file at " + f.getAbsolutePath());
throw new RuntimeException("File creation error");
}
return f;
}
/* Example test usage */
public static void main(String[] args)
{
PduFactory factory = new PduFactory(); //default appid, country, etc.
DisNetworking disnet = new DisNetworking(); // default ip and port
Path path = new File("./pdulog").toPath();
String filename = "Pdusave";
RecorderBinary recorder;
try{recorder = new RecorderBinary();} catch(IOException ex) {
System.err.println("Exception creating recorder: "+ex.getLocalizedMessage());
return;
}
DISPDUType all[] = DISPDUType.values();
Arrays.stream(all).forEach(typ-> {
if(typ != DISPDUType.OTHER) {
try {
Pdu pdu = factory.createPdu(typ);
disnet.sendPdu(pdu);
sleep(100);
}
catch(Exception ex) {
System.err.println("Exception sending Pdu: "+ex.getLocalizedMessage());
}
}
});
sleep(2000);
recorder.end();
}
private static void sleep(long ms)
{
try{Thread.sleep(ms);}catch(InterruptedException ex) {}
}
}
......@@ -22,7 +22,7 @@ import java.nio.file.Path;
import java.util.Arrays;
public class RecorderTobi implements PduReceiver
public class RecorderPlainText implements PduReceiver
{
static String DEFAULT_OUTDIR = "./pdulog";
static String DEFAULT_FILEPREFIX = "Pdusave";
......@@ -40,12 +40,12 @@ public class RecorderTobi implements PduReceiver
private DisNetworking disnet;
private Thread receiverThrd;
public RecorderTobi() throws IOException
public RecorderPlainText() throws IOException
{
this(DEFAULT_OUTDIR,DEFAULT_MCAST,DEFAULT_PORT);
}
public RecorderTobi(String outputDir, String mcastaddr, int port) throws IOException
public RecorderPlainText(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));
......@@ -206,8 +206,8 @@ public class RecorderTobi implements PduReceiver
Path path = new File("./pdulog").toPath();
String filename = "Pdusave";
RecorderTobi recorder;
try{recorder = new RecorderTobi();} catch(IOException ex) {
RecorderPlainText recorder;
try{recorder = new RecorderPlainText();} catch(IOException ex) {
System.err.println("Exception creating recorder: "+ex.getLocalizedMessage());
return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment