-
Notifications
You must be signed in to change notification settings - Fork 29
/
xmlevent.go
140 lines (115 loc) · 3.38 KB
/
xmlevent.go
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package cot
import (
"encoding/xml"
"fmt"
"strconv"
"time"
)
type Event struct {
XMLName xml.Name `xml:"event"`
Version string `xml:"version,attr"`
Type string `xml:"type,attr"`
Access string `xml:"access,attr,omitempty"`
Qos string `xml:"qos,attr,omitempty"`
Opex string `xml:"opex,attr,omitempty"`
UID string `xml:"uid,attr"`
Time time.Time `xml:"time,attr"`
Start time.Time `xml:"start,attr"`
Stale time.Time `xml:"stale,attr"`
How string `xml:"how,attr"`
Detail *Node `xml:"detail"`
Point Point `xml:"point"`
}
func (e *Event) String() string {
if e == nil {
return "nil"
}
return fmt.Sprintf("version=%s, type=%s, uid=%s, how=%s, stale=%s, detail={%s}", e.Version, e.Type, e.UID, e.How, e.Stale.Sub(e.Start), e.Detail)
}
func (e *Event) AddDetail() *Node {
if e == nil {
return nil
}
if e.Detail == nil {
e.Detail = &Node{XMLName: xml.Name{Local: "detail"}}
}
return e.Detail
}
func (e *Event) AddGroup(group, role string) {
if e == nil {
return
}
e.AddDetail().AddOrChangeChild("__group", map[string]string{"name": group, "role": role})
}
func (e *Event) AddCallsign(callsign, endpoint string, addDroid bool) {
if e == nil {
return
}
e.AddDetail().AddOrChangeChild("contact", map[string]string{"callsign": callsign, "endpoint": endpoint})
if addDroid {
e.AddDetail().AddOrChangeChild("uid", map[string]string{"Droid": callsign})
}
}
func (e *Event) AddTrack(speed, course string) {
if e == nil {
return
}
e.AddDetail().AddOrChangeChild("track", map[string]string{"speed": speed, "course": course})
}
func (e *Event) AddVersion(device, platform, os, version string) {
if e == nil {
return
}
e.AddDetail().AddOrChangeChild("takv", map[string]string{"device": device, "platform": platform, "os": os, "version": version})
}
type Point struct {
XMLName xml.Name `xml:"point"`
Lat float64 `xml:"lat,attr"`
Lon float64 `xml:"lon,attr"`
Hae float64 `xml:"hae,attr"`
Ce float64 `xml:"ce,attr"`
Le float64 `xml:"le,attr"`
}
func XMLBasicMsg(typ string, uid string, stale time.Duration) *Event {
return &Event{
Version: "2.0",
UID: uid,
Type: typ,
Time: time.Now().UTC(),
Start: time.Now().UTC(),
Stale: time.Now().Add(stale).UTC(),
Point: Point{
Lat: 0,
Lon: 0,
Hae: 0,
Ce: NotNum,
Le: NotNum,
},
}
}
func VersionSupportMsg(ver int8) *Event {
v := strconv.Itoa(int(ver))
ev := XMLBasicMsg("t-x-takp-v", "protouid", time.Minute)
ev.How = "m-g"
ev.AddDetail().AddOrChangeChild("TakControl", nil).AddOrChangeChild("TakProtocolSupport", map[string]string{"version": v})
return ev
}
func VersionReqMsg(ver int8) *Event {
v := strconv.Itoa(int(ver))
ev := XMLBasicMsg("t-x-takp-q", "protouid", time.Minute)
ev.How = "m-g"
ev.AddDetail().AddOrChangeChild("TakControl", nil).AddOrChangeChild("TakRequest", map[string]string{"version": v})
return ev
}
func ProtoChangeOkMsg() *Event {
ev := XMLBasicMsg("t-x-takp-r", "protouid", time.Minute)
ev.How = "m-g"
ev.AddDetail().AddOrChangeChild("TakControl", nil).AddOrChangeChild("TakResponse", map[string]string{"status": "true"})
return ev
}
// Geopointsrc = "USER" Altsrc - "DTED0"
// ce
// high 0 - cat1, 7 - CAT2 16 - CAT3 31 - CAT4 92 - CAT5
// medium 3 - cat1, 11 - CAT2 23 - CAT3 61 - CAT4 198.5 - CAT5
// low 6 - cat1, 15 - CAT2 30 - CAT3 91 - CAT4 305 - CAT5
// UNKNOWN 9999999