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
ea0c1197
Commit
ea0c1197
authored
7 years ago
by
Michael
Browse files
Options
Downloads
Patches
Plain Diff
AngelBlank final working versions
parent
45adaf96
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
projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngelBlankEspduReceiverBtoTCPTest.java
+104
-0
104 additions, 0 deletions
...poulosBlankenbeker/AngelBlankEspduReceiverBtoTCPTest.java
with
104 additions
and
0 deletions
projects/Assignments/FinalProjects/2018March/AngelopoulosBlankenbeker/AngelBlankEspduReceiverBtoTCPTest.java
0 → 100644
+
104
−
0
View file @
ea0c1197
import
java.net.*
;
import
java.util.*
;
import
edu.nps.moves.disutil.*
;
import
edu.nps.moves.dis.*
;
import
java.io.ByteArrayOutputStream
;
import
java.io.DataOutputStream
;
import
java.io.OutputStream
;
import
java.io.PrintStream
;
/**
* Receives PDUs from the network in IEEE format and creates a TCP connection,
* then sends information through the connection.
*
* @author Angelopoulos/Blankenbeker
* @version 8 MAR 2018
*/
public
class
AngelBlankEspduReceiverBtoTCPTest
{
public
static
final
String
TCP_DESTINATION_IP
=
"172.20.144.187"
;
public
static
final
int
DIS_DESTINATION_PORT
=
2800
;
public
static
final
int
TCP_DESTINATION_PORT
=
2998
;
public
static
final
int
MAX_PDU_SIZE
=
8192
;
public
static
final
String
GROUP
=
"239.1.2.3"
;
public
static
void
main
(
String
args
[])
{
MulticastSocket
socket
;
DatagramPacket
packet
;
DatagramSocket
dataGram
;
InetAddress
address
;
PduFactory
pduFactory
=
new
PduFactory
();
try
{
// Specify the socket to receive data
socket
=
new
MulticastSocket
(
DIS_DESTINATION_PORT
);
socket
.
setBroadcast
(
true
);
address
=
InetAddress
.
getByName
(
GROUP
);
socket
.
joinGroup
(
address
);
//System.out.println("Joined Group.");
// Loop infinitely, receiving datagrams
while
(
true
)
{
try
{
byte
buffer
[]
=
new
byte
[
MAX_PDU_SIZE
];
packet
=
new
DatagramPacket
(
buffer
,
buffer
.
length
);
socket
.
receive
(
packet
);
//System.out.println("Packet Received");
List
<
Pdu
>
pduBundle
=
pduFactory
.
getPdusFromBundle
(
packet
.
getData
());
//System.out.println("Bundle size is " + pduBundle.size());
Iterator
it
=
pduBundle
.
iterator
();
while
(
it
.
hasNext
()){
Pdu
aPdu
=
(
Pdu
)
it
.
next
();
//System.out.print("got PDU of type: " + aPdu.getClass().getName());
if
(
aPdu
instanceof
EntityStatePdu
){
EntityID
eid
=
((
EntityStatePdu
)
aPdu
).
getEntityID
();
if
(
eid
.
getSite
()
==
200
){
dataGram
=
new
DatagramSocket
();
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
DataOutputStream
dos
=
new
DataOutputStream
(
baos
);
aPdu
.
marshal
(
dos
);
byte
[]
data
=
baos
.
toByteArray
();
DatagramPacket
DpSend
=
new
DatagramPacket
(
data
,
data
.
length
,
InetAddress
.
getByName
(
TCP_DESTINATION_IP
),
TCP_DESTINATION_PORT
);
dataGram
.
send
(
DpSend
);
// Create TCP Bridge
//Socket clientConnection = new Socket(TCP_DESTINATION_IP, TCP_DESTINATION_PORT);
// OutputStream os = clientConnection.getOutputStream();
//PrintStream ps = new PrintStream(os);
System
.
out
.
println
(
"Bravo briding complete to: "
+
TCP_DESTINATION_IP
);
//EntityType entityType = ((EntityStatePdu)aPdu).getEntityType();
/** ps.println(eid.getSite());
ps.println(eid.getApplication());
ps.println(eid.getEntity());
ps.println(entityType.getEntityKind()); // Platform (vs lifeform, munition, sensor, etc.)
ps.println(entityType.getCountry()); // USA
ps.println(entityType.getDomain()); // Land (vs air, surface, subsurface, space)
ps.println(entityType.getCategory()); // Tank
ps.println(entityType.getSubcategory()); // M1 Abrams
ps.println(entityType.getSpec()); // M1A2 Abrams**/
}
Vector3Double
location
=
((
EntityStatePdu
)
aPdu
).
getEntityLocation
();
System
.
out
.
print
(
" EID:["
+
eid
.
getSite
()
+
", "
+
eid
.
getApplication
()
+
", "
+
eid
.
getEntity
()
+
"] "
);
//System.out.print(" Location in DIS coordinates: [" + location.getX() + ", " + location.getY() + ", " + position.getZ() + "]");
double
c
[]
=
{
location
.
getX
(),
location
.
getY
(),
location
.
getZ
()};
double
lla
[]
=
CoordinateConversions
.
xyzToLatLonDegrees
(
c
);
System
.
out
.
println
(
" Location (lat/lon/alt): ["
+
lla
[
0
]
+
", "
+
lla
[
1
]
+
", "
+
lla
[
2
]
+
"]"
);
}
System
.
out
.
println
();
}
// end trop through PDU bundle
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
}
}
// end while
}
// End try
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
}
}
// end main
}
// end class
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