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
02e523c1
Commit
02e523c1
authored
5 years ago
by
brutzman
Browse files
Options
Downloads
Patches
Plain Diff
sample code for COMMENTS PDU, some library debugging needed
parent
d4e2099f
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
examples/src/OpenDis7Examples/AllPduReceiver.java
+32
-18
32 additions, 18 deletions
examples/src/OpenDis7Examples/AllPduReceiver.java
examples/src/OpenDis7Examples/AllPduSender.java
+26
-4
26 additions, 4 deletions
examples/src/OpenDis7Examples/AllPduSender.java
with
58 additions
and
22 deletions
examples/src/OpenDis7Examples/AllPduReceiver.java
+
32
−
18
View file @
02e523c1
...
@@ -6,6 +6,7 @@ import java.io.*;
...
@@ -6,6 +6,7 @@ import java.io.*;
import
edu.nps.moves.dis7.*
;
import
edu.nps.moves.dis7.*
;
import
edu.nps.moves.dis7.enumerations.*
;
import
edu.nps.moves.dis7.enumerations.*
;
import
edu.nps.moves.dis7.util.*
;
import
edu.nps.moves.dis7.util.*
;
import
java.util.ArrayList
;
public
class
AllPduReceiver
public
class
AllPduReceiver
{
{
...
@@ -45,25 +46,38 @@ public class AllPduReceiver
...
@@ -45,25 +46,38 @@ public class AllPduReceiver
socket
.
receive
(
packet
);
socket
.
receive
(
packet
);
Pdu
pdu
=
factory
.
createPdu
(
packet
.
getData
());
Pdu
pdu
=
factory
.
createPdu
(
packet
.
getData
());
if
(
pdu
!=
null
)
{
if
(
pdu
!=
null
)
DISPDUType
currentPduType
=
pdu
.
getPduType
();
//short currentPduType = pdu.getPduType();
{
String
currentPduTypeName
=
pdu
.
getClass
().
getName
();
DISPDUType
currentPduType
=
pdu
.
getPduType
();
//short currentPduType = pdu.getPduType();
DISProtocolFamily
currentProtocolFamilyID
=
pdu
.
getProtocolFamily
();
//short currentProtocolFamilyID = pdu.getProtocolFamily();
String
currentPduTypeName
=
pdu
.
getClass
().
getName
();
String
currentPduFamilyName
=
pdu
.
getClass
().
getSuperclass
().
getSimpleName
();
DISProtocolFamily
currentProtocolFamilyID
=
pdu
.
getProtocolFamily
();
//short currentProtocolFamilyID = pdu.getProtocolFamily();
String
currentPduFamilyName
=
pdu
.
getClass
().
getSuperclass
().
getSimpleName
();
StringBuilder
message
=
new
StringBuilder
();
StringBuilder
message
=
new
StringBuilder
();
message
.
append
(
"received DIS PDU "
);
message
.
append
(
"received DIS PDU "
);
if
(
currentPduType
.
getValue
()
<
10
)
if
(
currentPduType
.
getValue
()
<
10
)
message
.
append
(
" "
);
message
.
append
(
" "
);
// column spacing
message
.
append
(
currentPduType
.
getValue
());
message
.
append
(
currentPduType
.
getValue
());
String
currentPduTypePadded
=
String
.
format
(
"%-34s"
,
currentPduType
);
// - indicates right padding of whitespace
String
currentPduTypePadded
=
String
.
format
(
"%-34s"
,
currentPduType
);
// - indicates right padding of whitespace
message
.
append
(
" "
).
append
(
currentPduTypePadded
);
message
.
append
(
" "
).
append
(
currentPduTypePadded
);
String
currentPduTypeNamePadded
=
String
.
format
(
"%-49s"
,
currentPduTypeName
);
// - indicates right padding of whitespace
String
currentPduTypeNamePadded
=
String
.
format
(
"%-49s"
,
currentPduTypeName
);
// - indicates right padding of whitespace
message
.
append
(
" of type "
).
append
(
currentPduTypeNamePadded
);
// package.class name
message
.
append
(
" of type "
).
append
(
currentPduTypeNamePadded
);
// package.class name
message
.
append
(
" (protocolFamily "
).
append
(
currentProtocolFamilyID
);
message
.
append
(
" (protocolFamily "
).
append
(
currentProtocolFamilyID
);
// message.append(" ").append(currentPduFamilyName); // class name is also available
// message.append(" ").append(currentPduFamilyName); // class name is also available
message
.
append
(
")"
);
message
.
append
(
")"
);
System
.
out
.
println
(
message
.
toString
());
System
.
out
.
println
(
message
.
toString
());
switch
(
currentPduType
)
// using enumeration values from edu.nps.moves.dis7.enumerations.DISPDUType
{
case
COMMENT:
CommentPdu
commentPdu
=
(
CommentPdu
)
pdu
;
// cast to precise type
ArrayList
<
VariableDatum
>
payloadList
=
(
ArrayList
)
commentPdu
.
getVariableDatums
();
for
(
VariableDatum
variableDatum
:
payloadList
)
{
String
nextComment
=
new
String
(
variableDatum
.
getVariableDatumValue
());
// convert byte[] to String
System
.
out
.
println
(
"\""
+
nextComment
+
"\""
);
}
}
}
}
else
else
System
.
out
.
println
(
"received packet but pdu is null, packet.getData().length="
+
packet
.
getData
().
length
+
", error..."
);
System
.
out
.
println
(
"received packet but pdu is null, packet.getData().length="
+
packet
.
getData
().
length
+
", error..."
);
...
...
This diff is collapsed.
Click to expand it.
examples/src/OpenDis7Examples/AllPduSender.java
+
26
−
4
View file @
02e523c1
...
@@ -363,10 +363,32 @@ public class AllPduSender
...
@@ -363,10 +363,32 @@ public class AllPduSender
break
;
break
;
case
COMMENT:
case
COMMENT:
aPdu
=
new
CommentPdu
();
// aPdu = new CommentPdu(); // default for this switch logic
CommentPdu
newCommentPdu
=
(
CommentPdu
)
aPdu
;
VariableDatum
newVariableDatum
=
new
VariableDatum
();
// see Garrett Loffelman and Pete Severson's code for OpenDis version 4 example
// etc. see Garrett and Pete's code
// https://gitlab.nps.edu/Savage/NetworkedGraphicsMV3500/tree/master/assignments/src/MV3500Cohort2018JulySeptember/projects/LoeffelmanSeverson
CommentPdu
newCommentPdu
=
new
CommentPdu
();
ArrayList
<
VariableDatum
>
payloadList
=
new
ArrayList
<
VariableDatum
>();
ArrayList
<
String
>
commentsList
=
new
ArrayList
<>();
commentsList
.
add
(
"Hello CommentPDU"
);
commentsList
.
add
(
"Here is a new message"
);
if
(!
commentsList
.
isEmpty
())
System
.
out
.
println
(
"Preparing CommentPDU:"
);
for
(
String
comment
:
commentsList
)
{
VariableDatum
newVariableDatum
=
new
VariableDatum
();
newVariableDatum
.
setVariableDatumValue
(
comment
.
getBytes
());
// conversion
newVariableDatum
.
setVariableDatumLength
(
comment
.
getBytes
().
length
);
// housekeeping
payloadList
.
add
(
newVariableDatum
);
System
.
out
.
println
(
" \""
+
comment
+
"\""
);
}
newCommentPdu
.
setVariableDatums
(
payloadList
);
aPdu
=
newCommentPdu
;
// hand off for sending
break
;
break
;
default
:
default
:
...
...
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