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
250a1572
Commit
250a1572
authored
6 years ago
by
Ayres, Kevin (CAPT)
Browse files
Options
Downloads
Patches
Plain Diff
AyresDemchkoReceiver
parent
9d21edc2
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
deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/AyresDemchkoProject/AyresDemchkoReceiver.java
+144
-0
144 additions, 0 deletions
...inalProject/AyresDemchkoProject/AyresDemchkoReceiver.java
with
144 additions
and
0 deletions
deliverables/src/MV3500Cohort2018JulySeptember/FinalProject/AyresDemchkoProject/AyresDemchkoReceiver.java
0 → 100644
+
144
−
0
View file @
250a1572
/*
* 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
MV3500Cohort2018JulySeptember.FinalProject.AyresDemchko
;
import
edu.nps.moves.dis.CommentPdu
;
import
edu.nps.moves.dis.OneByteChunk
;
import
edu.nps.moves.dis.Pdu
;
import
edu.nps.moves.dis.VariableDatum
;
import
edu.nps.moves.disenum.PduType
;
import
edu.nps.moves.disutil.PduFactory
;
import
java.io.ByteArrayInputStream
;
import
java.io.DataInputStream
;
import
java.net.DatagramPacket
;
import
java.net.InetAddress
;
import
java.net.MulticastSocket
;
import
java.util.ArrayList
;
/**
*
* @author kjayr
*/
public
class
AyresDemchkoReceiver
{
public
static
final
int
MULTICAST_PORT
=
3000
;
public
static
final
String
MULTICAST_GROUP
=
"239.1.2.15"
;
public
static
final
boolean
USE_FAST_ESPDU
=
false
;
public
static
void
main
(
String
[]
args
)
{
PduFactory
factory
;
try
{
// This is a java/IPv6 problem. You should also add it to the
// arguments used to start the app, eg -Djava.net.preferIPv4Stack=true
// set in the "run" section of preferences. Also, typically
// netbeans must be restarted after these settings.
// https://stackoverflow.com/questions/18747134/getting-cant-assign-requested-address-java-net-socketexception-using-ehcache
//System.setProperty("java.net.preferIPv4Stack", "true");
//System.out.println("DisExamples.PduReceiver started...");
/*MulticastSocket multicastSocket = new MulticastSocket(DESTINATION_PORT);
multicastSocket.setTimeToLive(TTL);
InetAddress multicastAddress = InetAddress.getByName(MULTICAST_ADDRESS);
System.out.println(multicastAddress);
// Join group useful on receiving side
multicastSocket.joinGroup(multicastAddress);
// You can join multiple groups here*/
System
.
setProperty
(
"java.net.preferIPv4Stack"
,
"true"
);
System
.
out
.
println
(
"DisExamples.PduReceiver started..."
);
MulticastSocket
socket
=
new
MulticastSocket
(
MULTICAST_PORT
);
InetAddress
address
=
InetAddress
.
getByName
(
MULTICAST_GROUP
);
socket
.
joinGroup
(
address
);
factory
=
new
PduFactory
();
int
count
=
0
;
int
firstNumber
=
11
;
int
secondNumber
=
67
;
int
thirdNumber
=
108
;
int
forkliftsAvail
=
100
;
int
forkliftsServ
=
0
;
while
(
true
)
{
byte
[]
packetArray
=
new
byte
[
1500
];
DatagramPacket
packet
=
new
DatagramPacket
(
packetArray
,
packetArray
.
length
);
socket
.
receive
(
packet
);
Pdu
pdu
=
factory
.
createPdu
(
packet
.
getData
());
if
(
pdu
!=
null
)
{
short
pduType
=
pdu
.
getPduType
();
String
pduTypeName
=
pdu
.
getClass
().
getName
();
short
protocolFamily
=
pdu
.
getProtocolFamily
();
// TODO get string enumeration
if
(
pdu
.
getPduTypeEnum
()
==
PduType
.
COMMENT
){
CommentPdu
cPdu
=
(
CommentPdu
)
pdu
;
ArrayList
<
VariableDatum
>
payload
=
(
ArrayList
)
cPdu
.
getVariableDatums
();
VariableDatum
payloadWrapper
=
payload
.
get
(
0
);
ArrayList
<
OneByteChunk
>
oBC
=
(
ArrayList
)
payloadWrapper
.
getVariableData
();
//byte[] imageByte = new byte[100000];
/*for(int i = 0; i < oBC.size(); i++){
imageByte[i] = oBC.get(i).getOtherParameters()[0];
}
ByteArrayInputStream bais = new ByteArrayInputStream(imageByte);
BufferedImage bimage = ImageIO.read(bais);
//image = bimage;
JFrame frame = new JFrame();
frame.setSize(300, 300);
//JLabel label = new JLabel(new ImageIcon(image));
//frame.add(label);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);*/
}
count
++;
firstNumber
+=
1.5
;
secondNumber
+=
3.5
;
thirdNumber
+=
5.0
;
if
(
count
>
1
){
forkliftsAvail
-=
1
;
forkliftsServ
+=
1
;
}
System
.
out
.
println
(
"Marine Corps Logistics Base Albany: Wilson Warehouse"
);
System
.
out
.
println
(
"Order received: "
+
count
+
" NSN ID: "
+
firstNumber
+
" Xrow: "
+
secondNumber
+
" Yshelf: "
+
thirdNumber
+
" Forklifts Availble: "
+
forkliftsAvail
+
" Forklifts in Service: "
+
forkliftsServ
);
System
.
out
.
println
(
"______________________________________________________"
);
StringBuilder
message
=
new
StringBuilder
();
message
.
append
(
"received DIS PDU: "
);
message
.
append
(
"pduType "
);
if
(
pduType
<
10
)
message
.
append
(
" "
);
message
.
append
(
pduType
).
append
(
" "
).
append
(
pduTypeName
);
message
.
append
(
", protocolFamily="
).
append
(
protocolFamily
);
System
.
out
.
println
(
message
.
toString
());
}
else
System
.
out
.
println
(
"received packet but pdu is null, packet.getData().length="
+
packet
.
getData
().
length
+
", error..."
);
ByteArrayInputStream
bais
=
new
ByteArrayInputStream
(
packet
.
getData
());
DataInputStream
dis
=
new
DataInputStream
(
bais
);
//float firstNumber = dis.readInt();
//float secondNumber = dis.readInt();
//float thirdNumber = dis.readInt();
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
}
}
}
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