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
313589d7
Commit
313589d7
authored
5 years ago
by
Terry D. Norbraten
Browse files
Options
Downloads
Patches
Plain Diff
convert to the threaded network interface (last to go)
parent
ccfdaf34
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/edu/nps/moves/dis7/examples/EntityUse.java
+24
-8
24 additions, 8 deletions
src/edu/nps/moves/dis7/examples/EntityUse.java
with
24 additions
and
8 deletions
src/edu/nps/moves/dis7/examples/EntityUse.java
+
24
−
8
View file @
313589d7
...
...
@@ -7,10 +7,11 @@ package edu.nps.moves.dis7.examples;
import
edu.nps.moves.dis7.EntityStatePdu
;
import
edu.nps.moves.dis7.EntityType
;
import
edu.nps.moves.dis7.
utilities.DisNetworking
;
import
edu.nps.moves.dis7.
Pdu
;
import
edu.nps.moves.dis7.utilities.PduFactory
;
import
edu.nps.moves.dis7.entities.EntityTypeFactory
;
import
edu.nps.moves.dis7.enumerations.DISPDUType
;
import
edu.nps.moves.dis7.utilities.DisThreadedNetIF
;
import
java.io.IOException
;
/**
...
...
@@ -76,7 +77,7 @@ public class EntityUse
{
PduFactory
pduFactory
=
new
PduFactory
();
// uses defaults: usa, exercise id 1, site id 2, app id 3, absolute time
EntityStatePdu
pdu
=
pduFactory
.
makeEntityStatePdu
();
EntityStatePdu
es
pdu
=
pduFactory
.
makeEntityStatePdu
();
/* set desired entity state fields here */
EntityType
et
=
EntityTypeFactory
.
makeEntity
(
11963
);
...
...
@@ -85,20 +86,35 @@ public class EntityUse
return
;
}
pdu
.
setEntityType
(
et
);
DisNetworking
disnet
=
new
DisNetworking
();
// uses defaults: multicast port 3000 ip 230.0.0.0
disnet
.
sendPdu
(
pdu
);
// possibly throws IOException
espdu
.
setEntityType
(
et
);
DisThreadedNetIF
netif
=
new
DisThreadedNetIF
();
// uses defaults: multicast port 3000 ip 230.0.0.0
// We want to listen also, so add a listener, using JDK8+ lambda grammar
netif
.
addListener
(
pdu
->
handleReceivedPdu
(
pdu
));
netif
.
send
(
espdu
);
// possibly throws IOException
/* Do the same for the second way of creating a Shenandoah entity type and show an alternate way of creating an ESPDU */
EntityStatePdu
pdu2
=
(
EntityStatePdu
)
pduFactory
.
createPdu
(
DISPDUType
.
ENTITY_STATE
);
EntityStatePdu
es
pdu2
=
(
EntityStatePdu
)
pduFactory
.
createPdu
(
DISPDUType
.
ENTITY_STATE
);
/* set desired entity state fields here */
edu
.
nps
.
moves
.
dis7
.
entities
.
usa
.
platform
.
surface
.
AD44Shenandoah
et2
=
new
edu
.
nps
.
moves
.
dis7
.
entities
.
usa
.
platform
.
surface
.
AD44Shenandoah
();
/* Use import statement to make the code above more readable */
pdu2
.
setEntityType
(
et2
);
disnet
.
sendPdu
(
pdu2
);
// possibly throws IOException
espdu2
.
setEntityType
(
et2
);
netif
.
send
(
espdu2
);
// possibly throws IOException
// Wait a bit to see output
try
{
Thread
.
sleep
(
250L
);
}
catch
(
InterruptedException
ex
)
{}
}
private
static
void
handleReceivedPdu
(
Pdu
pdu
)
{
// Do something here with the pdu you received
System
.
out
.
println
(
"Received "
+
pdu
.
getClass
().
getSimpleName
());
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
...
...
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