Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NetworkedGraphicsMV3500
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Savage
NetworkedGraphicsMV3500
Commits
c26576c7
Commit
c26576c7
authored
5 years ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
Tobi recovered Mike Bailey's missing fixes from MV3500, also updated PduReader for plaintext format
parent
9c70008c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/edu/nps/moves/dis7/examples/PduReaderPlayer.java
+5
-5
5 additions, 5 deletions
src/edu/nps/moves/dis7/examples/PduReaderPlayer.java
src/edu/nps/moves/dis7/utilities/stream/PduPlayer.java
+113
-13
113 additions, 13 deletions
src/edu/nps/moves/dis7/utilities/stream/PduPlayer.java
with
118 additions
and
18 deletions
src/edu/nps/moves/dis7/examples/PduReaderPlayer.java
+
5
−
5
View file @
c26576c7
...
...
@@ -52,8 +52,8 @@ public class PduReaderPlayer
System
.
out
.
println
(
"Beginning pdu playback from directory "
+
outDir
);
try
{
PduPlayer
player
=
new
PduPlayer
(
mcast
,
port
,
new
File
(
outDir
).
toPath
());
player
.
startResume
();
PduPlayer
p
duP
layer
=
new
PduPlayer
(
mcast
,
port
,
new
File
(
outDir
).
toPath
());
p
duP
layer
.
startResume
();
mystate
state
=
mystate
.
RUNNING
;
Scanner
scan
=
new
Scanner
(
System
.
in
);
...
...
@@ -61,15 +61,15 @@ public class PduReaderPlayer
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
();
p
duP
layer
.
stopPause
();
state
=
mystate
.
PAUSED
;
}
else
if
(
line
.
equalsIgnoreCase
(
"r"
)
&&
state
==
mystate
.
PAUSED
)
{
player
.
startResume
();
p
duP
layer
.
startResume
();
state
=
mystate
.
RUNNING
;
}
else
if
(
line
.
equalsIgnoreCase
(
"q"
))
{
player
.
end
();
p
duP
layer
.
end
();
break
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/edu/nps/moves/dis7/utilities/stream/PduPlayer.java
+
113
−
13
View file @
c26576c7
...
...
@@ -16,6 +16,9 @@ import java.util.Arrays;
import
java.util.Base64
;
import
static
edu
.
nps
.
moves
.
dis7
.
utilities
.
stream
.
PduRecorder
.*;
import
java.nio.ByteBuffer
;
import
java.nio.IntBuffer
;
import
java.util.regex.Pattern
;
public
class
PduPlayer
{
...
...
@@ -43,7 +46,7 @@ public class PduPlayer
private
Integer
scenarioPduCount
=
null
;
private
boolean
showPduCountsOneTime
=
false
;
private
int
pduCount
=
0
;
private
DatagramSocket
d
s
ock
;
private
DatagramSocket
d
atagramS
ock
et
;
private
BufferedReader
brdr
;
private
Long
startNanoTime
=
null
;
private
boolean
paused
=
false
;
...
...
@@ -77,8 +80,8 @@ public class PduPlayer
//Arrays.sort(fs, Comparator.comparing(File::getName));
if
(
netSend
)
d
s
ock
=
new
DatagramSocket
();
Base64
.
Decoder
de
cd
r
=
Base64
.
getDecoder
();
d
atagramS
ock
et
=
new
DatagramSocket
();
Base64
.
Decoder
base64Deco
der
=
Base64
.
getDecoder
();
for
(
File
f
:
fs
)
{
System
.
out
.
println
(
"Replaying "
+
f
.
getAbsolutePath
());
...
...
@@ -99,7 +102,19 @@ public class PduPlayer
}
else
{
String
[]
sa
=
line
.
split
(
","
);
//---Code Tobi for Plain Text---
if
(
line
.
contains
(
"#"
))
line
=
line
.
substring
(
0
,
line
.
indexOf
(
"#"
)-
1
);
//Delete appended Comments
//String[] sa = line.split(",");
//Pattern splitting needed for playback of unencoded streams
String
REGEX
=
"\\],\\["
;
Pattern
pattern
=
Pattern
.
compile
(
REGEX
);
String
[]
sa
;
sa
=
pattern
.
split
(
line
);
//Add the "]" to the end of sa[0]. It was taken off by the split
sa
[
0
]
=
sa
[
0
].
concat
(
"]"
);
//Add the "]" to the end of sa[0]. It was taken off by the split
sa
[
1
]
=
"["
.
concat
(
sa
[
1
]);
//------------------------------
if
(
sa
.
length
!=
2
)
{
System
.
err
.
println
(
"Error: parsing error. Line follows."
);
System
.
err
.
println
(
line
);
...
...
@@ -109,7 +124,41 @@ public class PduPlayer
if
(
startNanoTime
==
null
)
startNanoTime
=
System
.
nanoTime
();
byte
[]
pduTimeBytes
=
decdr
.
decode
(
sa
[
0
]);
//byte[] pduTimeBytes = decdr.decode(sa[0]);
//---Code Tobi for Plain Text---
byte
[]
pduTimeBytes
=
null
;
String
[]
splitString
;
//Split first String into multiple Strings cotaining integers
REGEX
=
","
;
pattern
=
Pattern
.
compile
(
REGEX
);
sa
[
0
]
=
sa
[
0
].
substring
(
1
,
sa
[
0
].
length
()
-
1
);
splitString
=
pattern
.
split
(
sa
[
0
]);
//Define an array to store the in values from the string and initalize it to a value drifferent from NULL
int
[]
arr
=
new
int
[
splitString
.
length
];
String
tempString
=
""
;
//Test
for
(
int
x
=
0
;
x
<
splitString
.
length
;
x
++)
{
tempString
=
splitString
[
x
].
trim
();
int
tempInt
=
Integer
.
parseInt
(
tempString
);
arr
[
x
]
=
tempInt
;
}
// Credit: https://stackoverflow.com/questions/1086054/how-to-convert-int-to-byte
ByteBuffer
byteBuffer1
=
ByteBuffer
.
allocate
(
arr
.
length
*
4
);
IntBuffer
intBuffer
=
byteBuffer1
.
asIntBuffer
();
intBuffer
.
put
(
arr
);
pduTimeBytes
=
byteBuffer1
.
array
();
//------------------------------
long
pduTimeInterval
=
Longs
.
fromByteArray
(
pduTimeBytes
);
// This is a relative number in nanoseconds of the time of packet reception minus first packet reception for scenario.
...
...
@@ -122,21 +171,72 @@ public class PduPlayer
sleep
(
sleepTime
/
1000000L
,
(
int
)
(
sleepTime
%
1000000L
));
}
byte
[]
buffer
=
decdr
.
decode
(
sa
[
1
]);
//byte[] buffer = decdr.decode(sa[1]);
//---Code Tobi for Plain Text---
//Handle the second String
// Split second String into multiple Strings cotaining integers
REGEX
=
","
;
pattern
=
Pattern
.
compile
(
REGEX
);
sa
[
1
]
=
sa
[
1
].
substring
(
1
,
sa
[
1
].
length
()
-
1
);
splitString
=
pattern
.
split
(
sa
[
1
]);
//Define an array to store the in values from the string and initalize it to a value drifferent from NULL
arr
=
new
int
[
splitString
.
length
];
//trim spaces, if any
tempString
=
""
;
//Test
for
(
int
x
=
0
;
x
<
splitString
.
length
;
x
++)
{
tempString
=
splitString
[
x
].
trim
();
int
tempInt
=
Integer
.
parseInt
(
tempString
);
arr
[
x
]
=
tempInt
;
//System.out.println(tempInt);
}
// Credit: https://stackoverflow.com/questions/1086054/how-to-convert-int-to-byte
ByteBuffer
byteBuffer2
=
ByteBuffer
.
allocate
(
arr
.
length
*
4
);
intBuffer
=
byteBuffer2
.
asIntBuffer
();
intBuffer
.
put
(
arr
);
byte
[]
buffer
=
byteBuffer2
.
array
();
//When the byteBuffer stores the arry of Integers into the byte array it store a 7 as 0 0 0 7.
//Therefore a shortBuffer is created where only every forth value is stored.
//it must be done with modulo instead of testing for "0" because a "0" could be there as value and not as padding
byte
[]
bufferShort
=
new
byte
[
byteBuffer2
.
array
().
length
/
4
];
int
bufferShortCounter
=
0
;
for
(
int
i
=
1
;
i
<
byteBuffer2
.
array
().
length
;
i
++)
{
if
(((
i
+
1
)
%
4
)
==
0
)
{
bufferShort
[
bufferShortCounter
]
=
buffer
[
i
];
bufferShortCounter
++;
}
}
//------------------------------
if
(
netSend
)
{
DatagramPacket
packet
=
new
DatagramPacket
(
buffer
,
buffer
.
length
,
addr
,
port
);
dsock
.
send
(
packet
);
DatagramPacket
datagramPacket
=
new
DatagramPacket
(
bufferShort
,
bufferShort
.
length
,
addr
,
port
);
datagramSocket
.
send
(
datagramPacket
);
System
.
out
.
println
(
"Sent PDU "
);
}
if
(
rawListener
!=
null
)
{
rawListener
.
receiveBytes
(
buffer
);
}
pduCount
++;
if
(
scenarioPduCount
!=
null
)
scenarioPduCount
++;
scenarioPduCount
++;
if
(
showPduCountsOneTime
||
pduCount
%
5
==
0
)
showCounts
();
showCounts
();
}
line
=
brdr
.
readLine
();
...
...
@@ -183,9 +283,9 @@ public class PduPlayer
private
void
closer
()
{
try
{
if
(
d
s
ock
!=
null
)
{
d
s
ock
.
close
();
d
s
ock
=
null
;
if
(
d
atagramS
ock
et
!=
null
)
{
d
atagramS
ock
et
.
close
();
d
atagramS
ock
et
=
null
;
}
if
(
brdr
!=
null
)
{
brdr
.
close
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment