ActiveState Code

Recipe 576892: Parse a DIS PDU


Decodes Distributed Interactive Simulation (DIS) Protocol Data Units (PDUs) from UDP packets. Requires UDP package (http://tcludp.sourceforge.net)

Entity State (1), Fire (2), and Detonation (3) PDUs are decoded.

Tcl
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
proc read_socket {sock} {
set pdu [read $sock]
if {[catch {binary scan $pdu ccc d(disver) d(exercise) d(kind)}]} {return}

switch -- $d(kind) {
 1	{
	# ENTITY STATE
	catch {binary scan $pdu ccccISSSSSccccSccccccSccccIIIWWWIIIIcA39cA11I \
	d(disver) d(exercise) d(kind) d(family) d(time) d(length) pad \
	d(site) d(host) d(ent) d(force) d(art) \
	d(kind) d(domain) d(country) d(cat) d(subcat) d(spec) d(extra) \
	d(altkind) d(altdomain) d(altcountry) d(altcat) d(altsubcat) d(altspec) d(altextra) \
	d(velx) d(vely) d(velz) d(locx) d(locy) d(locz) d(orientx) d(orienty) d(orientz) \
	d(appearance) d(dra) pad d(charset) d(marking) d(cap)} result

	}
 2	{
	# FIRE
	catch {binary scan $pdu ccccISSSSSSSSSSSSSSIWWWccSccccSSSSIIII \
	d(disver) d(exercise) d(kind) d(family) d(time) d(length) 0 \
	d(site) d(host) d(ent) d(sitetgt) d(hosttgt) d(enttgt) \
	d(sitemun) d(hostmun) d(entmun) d(siteevt) d(hostevt) d(entevt) \
	d(mission) d(locx) d(locy) d(locz) \
	d(kind) d(domain) d(country) d(cat) d(subcat) d(spec) d(extra) \
	d(warhead) d(fuze) d(quantity) d(rate) d(velx) d(vely) d(velz) d(range)} result

	}
 3	{
	# DETONATION
	catch {binary scan $pdu ccccISSSSSSSSSSSSSSIIIWWWccSccccSSSSIIIccS \
	d(disver) d(exercise) d(kind) d(family) d(time) d(length) 0 \
	d(site) d(host) d(ent) d(sitetgt) d(hosttgt) d(enttgt) \
	d(sitemun) d(hostmun) d(entmun) d(siteevt) d(hostevt) d(entevt) \
	d(velx) d(vely) d(velz) d(locx) d(locy) d(locz) \
	d(kind) d(domain) d(country) d(cat) d(subcat) d(spec) d(extra) \
	d(warhead) d(fuze) d(quantity) d(rate) d(entx) d(enty) d(entz) d(result) \
	d(parts) d(art)} result

	}
}

}

Discussion

Military simulations use DIS PDUs to pass simulation world data (entity states and events) between simulations. DIS PDUs can represent an entity (vehicle, lifeform, platform), an event (weapon fire, munition detonation), world changes (weather conditions), or simulation management (create, destroy, manage entities).

Sign in to comment