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
4ec40d6d
Commit
4ec40d6d
authored
3 years ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
javadoc improvements, time updates
parent
3e75749e
No related branches found
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/PduSender.java
+3
-3
3 additions, 3 deletions
src/edu/nps/moves/dis7/examples/PduSender.java
src/edu/nps/moves/dis7/utilities/PduFactory.java
+53
-29
53 additions, 29 deletions
src/edu/nps/moves/dis7/utilities/PduFactory.java
with
56 additions
and
32 deletions
src/edu/nps/moves/dis7/examples/PduSender.java
+
3
−
3
View file @
4ec40d6d
...
@@ -164,11 +164,11 @@ public class PduSender
...
@@ -164,11 +164,11 @@ public class PduSender
for
(
int
idx
=
0
;
idx
<
NUMBER_TO_SEND
;
idx
++)
{
for
(
int
idx
=
0
;
idx
<
NUMBER_TO_SEND
;
idx
++)
{
// DIS time is a pain in the ass. DIS time units are 2^31-1 units per
// DIS time is a pain in the ass. DIS time units are 2^31-1 units per
// hour, and time is set to DIS time units from the top of the hour.
// hour, and time is set to DIS time units from the top of the hour.
// This means that if you
start
sending just before the top of the hour
// This means that if you
begin
sending just before the top of the hour
// the time units can roll over to zero as you are sending. The receivers
// the time units can roll over to zero as you are sending. The receivers
// (escpecially homegrown ones) are often not able to detect rollover
// (escpecially homegrown ones) are often not able to detect rollover
// and may
start
discarding packets as dupes or out of order. We use
// and may
begin
discarding packets as dupes or out of order. We use
// an NPS timestamp here, hundredths of a second since the
start
of the
// an NPS timestamp here, hundredths of a second since the
begin
of the
// year. The DIS standard for time is often ignored in the wild; I've seen
// year. The DIS standard for time is often ignored in the wild; I've seen
// people use Unix time (seconds since 1970) and more. Or you can
// people use Unix time (seconds since 1970) and more. Or you can
// just stuff idx into the timestamp field to get something that is monotonically
// just stuff idx into the timestamp field to get something that is monotonically
...
...
This diff is collapsed.
Click to expand it.
src/edu/nps/moves/dis7/utilities/PduFactory.java
+
53
−
29
View file @
4ec40d6d
...
@@ -10,9 +10,7 @@ import edu.nps.moves.dis7.enumerations.*;
...
@@ -10,9 +10,7 @@ import edu.nps.moves.dis7.enumerations.*;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteBuffer
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
...
@@ -35,30 +33,51 @@ import java.util.stream.Stream;
...
@@ -35,30 +33,51 @@ import java.util.stream.Stream;
*/
*/
public
class
PduFactory
public
class
PduFactory
{
{
public
enum
TimestampStyle
{
IEEE_ABSOLUTE
,
IEEE_RELATIVE
,
NPS
,
UNIX
};
/** Supported timestamp styles. TODO consider moving to Pdu abstract class.
* @see edu.nps.moves.dis7.pdus.DisTime
*/
public
enum
TimestampStyle
{
/** Clock ticks since top of hour, host synchronized to UTC via Network Time Protocol (NTP) */
IEEE_ABSOLUTE
,
/** Clock ticks since top of hour, host not synchronized to UTC via Network Time Protocol (NTP) */
IEEE_RELATIVE
,
/** Unix time (seconds since 1 January 1970) */
UNIX
,
/** hundreds of a second since the start of the year */
YEAR
};
private
Country
country
=
Country
.
UNITED_STATES_OF_AMERICA_USA
;
private
edu
.
nps
.
moves
.
dis7
.
enumerations
.
Country
country
=
Country
.
UNITED_STATES_OF_AMERICA_USA
;
private
byte
defaultExerciseId
=
1
;
private
byte
defaultExerciseId
=
1
;
private
short
defaultSiteId
=
2
;
private
short
defaultSiteId
=
2
;
private
short
defaultAppId
=
3
;
private
short
defaultAppId
=
3
;
private
final
DisTime
disTime
;
private
final
edu
.
nps
.
moves
.
dis7
.
pdus
.
DisTime
disTime
=
new
DisTime
()
;
private
Method
getTime
;
private
Method
getTime
Method
;
/** We can marshal the PDU with a timestamp set to any of several styles.
/** We can marshal the PDU with a timestamp set to any of several styles.
* Remember, you MUST set a timestamp. DIS will regard multiple packets sent
* Remember, you MUST set a timestamp. DIS will regard multiple packets sent
* with the same timestamp as duplicates and may discard them.
* with the same timestamp as duplicates and may discard them.
* Default value is TimestampStyle.IEEE_ABSOLUTE.
*/
*/
private
TimestampStyle
timestampStyle
=
TimestampStyle
.
IEEE_ABSOLUTE
;
private
TimestampStyle
timestampStyle
=
TimestampStyle
.
IEEE_ABSOLUTE
;
/**
* Create a PduFactory using newTimestampStyle.
* @param newTimestampStyle timeStampStyle of interest
*/
public
PduFactory
(
TimestampStyle
newTimestampStyle
)
{
timestampStyle
=
newTimestampStyle
;
setTimeStampMethod
();
}
/**
/**
* Create a PduFactory using defaults for country (USA), exerciseId (2),
* Create a PduFactory using defaults for country (USA), exerciseId (2),
* application (3) and absolute timestamps.
* application (3) and absolute timestamps.
*/
*/
public
PduFactory
()
public
PduFactory
()
{
{
this
.
disTime
=
new
DisTime
();
// initialization steps can go here
setTimeStampStyle
(
timestampStyle
);
}
}
/**
/**
...
@@ -71,7 +90,7 @@ public class PduFactory
...
@@ -71,7 +90,7 @@ public class PduFactory
* @see edu.nps.moves.dis7.pdus.EntityType
* @see edu.nps.moves.dis7.pdus.EntityType
* @see edu.nps.moves.dis7.pdus.RadioType
* @see edu.nps.moves.dis7.pdus.RadioType
*/
*/
public
PduFactory
(
Country
country
,
byte
exerciseId
,
short
siteId
,
short
applicationId
,
TimestampStyle
timestampStyle
)
public
PduFactory
(
edu
.
nps
.
moves
.
dis7
.
enumerations
.
Country
country
,
byte
exerciseId
,
short
siteId
,
short
applicationId
,
TimestampStyle
timestampStyle
)
{
{
this
();
this
();
this
.
country
=
country
;
this
.
country
=
country
;
...
@@ -79,39 +98,42 @@ public class PduFactory
...
@@ -79,39 +98,42 @@ public class PduFactory
this
.
defaultSiteId
=
siteId
;
this
.
defaultSiteId
=
siteId
;
this
.
defaultAppId
=
applicationId
;
this
.
defaultAppId
=
applicationId
;
setTime
S
tampStyle
(
timestampStyle
);
setTime
s
tampStyle
(
timestampStyle
);
}
}
/** Set one of four styles. IEEE_ABSOLUTE, IEEE_RELATIVE, NPS, or UNIX
/** Set one of four time references as timestampStyle: IEEE_ABSOLUTE, IEEE_RELATIVE, UNIX, or YEAR.
*
* @see TimestampStyle.IEEE_ABSOLUTE
* @param ts the timestamp style to set for this PDU
* @see TimestampStyle.IEEE_RELATIVE
*/
* @see TimestampStyle.UNIX
public
final
void
setTimeStampStyle
(
TimestampStyle
ts
)
{
* @see TimestampStyle.YEAR
timestampStyle
=
ts
;
* @param newtimestampStyle the timestamp style to set for this PDU
setTimeStampMethod
();
*/
}
public
final
void
setTimestampStyle
(
TimestampStyle
newtimestampStyle
)
{
timestampStyle
=
newtimestampStyle
;
setTimeStampMethod
();
}
private
void
setTimeStampMethod
()
{
private
void
setTimeStampMethod
()
{
try
{
try
{
switch
(
timestampStyle
)
{
switch
(
timestampStyle
)
{
case
IEEE_ABSOLUTE:
case
IEEE_ABSOLUTE:
getTime
=
DisTime
.
class
.
getDeclaredMethod
(
"getDisAbsoluteTimestamp"
,
new
Class
<?>[
0
]);
getTime
Method
=
DisTime
.
class
.
getDeclaredMethod
(
"get
Current
DisAbsoluteTimestamp"
,
new
Class
<?>[
0
]);
break
;
break
;
case
IEEE_RELATIVE:
case
IEEE_RELATIVE:
getTime
=
DisTime
.
class
.
getDeclaredMethod
(
"getDisRelativeTimestamp"
,
new
Class
<?>[
0
]);
getTime
Method
=
DisTime
.
class
.
getDeclaredMethod
(
"get
Current
DisRelativeTimestamp"
,
new
Class
<?>[
0
]);
break
;
break
;
case
NPS
:
case
UNIX
:
getTime
=
DisTime
.
class
.
getDeclaredMethod
(
"get
Nps
Timestamp"
,
new
Class
<?>[
0
]);
getTime
Method
=
DisTime
.
class
.
getDeclaredMethod
(
"get
CurrentUnix
Timestamp"
,
new
Class
<?>[
0
]);
break
;
break
;
case
UNIX
:
case
YEAR:
// formerly NPS
:
getTime
=
DisTime
.
class
.
getDeclaredMethod
(
"get
Unix
Timestamp"
,
new
Class
<?>[
0
]);
getTime
Method
=
DisTime
.
class
.
getDeclaredMethod
(
"get
CurrentYear
Timestamp"
,
new
Class
<?>[
0
]);
break
;
break
;
default
:
default
:
getTime
=
DisTime
.
class
.
getDeclaredMethod
(
"getDisAbsoluteTimestamp"
,
new
Class
<?>[
0
]);
getTime
Method
=
DisTime
.
class
.
getDeclaredMethod
(
"get
Current
DisAbsoluteTimestamp"
,
new
Class
<?>[
0
]);
break
;
break
;
}
}
}
catch
(
NoSuchMethodException
ex
)
{
}
catch
(
NoSuchMethodException
ex
)
{
...
@@ -127,7 +149,9 @@ public class PduFactory
...
@@ -127,7 +149,9 @@ public class PduFactory
public
int
getTimestamp
()
public
int
getTimestamp
()
{
{
try
{
try
{
return
(
int
)
getTime
.
invoke
(
disTime
,
(
Object
[])
null
);
if
(
getTimeMethod
==
null
)
setTimeStampMethod
();
// avoid NPE
return
(
int
)
getTimeMethod
.
invoke
(
disTime
,
(
Object
[])
null
);
}
}
catch
(
IllegalAccessException
|
InvocationTargetException
ex
)
{
catch
(
IllegalAccessException
|
InvocationTargetException
ex
)
{
throw
new
RuntimeException
(
ex
);
throw
new
RuntimeException
(
ex
);
...
...
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