-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage_vdlm2.go
More file actions
121 lines (111 loc) · 4.38 KB
/
Copy pathmessage_vdlm2.go
File metadata and controls
121 lines (111 loc) · 4.38 KB
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
package main
import (
"fmt"
"net/url"
"slices"
"strings"
"time"
"gorm.io/gorm"
)
type VDLM2 struct {
}
func (v VDLM2Message) Name() string {
return "VDLM2Message"
}
func (v VDLM2Message) GetDefaultFields() APMessage {
return VDLM2Message{}.Prepare()
}
// This is the format VDLM2Hub sends
type VDLM2Message struct {
gorm.Model
ProcessingStartedAt time.Time
ProcessingFinishedAt time.Time
Processed bool `gorm:"index"`
// The rest of the struct is the actual message from ACARSHub
VDL2 struct {
App struct {
Name string `json:"name"`
Version string `json:"ver"`
Proxied bool `json:"proxied"`
ProxiedBy string `json:"proxied_by"`
ACARSRouterVersion string `json:"acars_router_version"`
ACARSRouterUUID string `json:"acars_router_uuid"`
} `json:"app" gorm:"embedded"`
AVLC struct {
CR string `json:"cr"`
Destination struct {
Address string `json:"addr"`
Type string `json:"type"`
} `json:"dst" gorm:"embedded"`
FrameType string `json:"frame_type"`
Source struct {
Address string `json:"addr"`
Type string `json:"type"`
Status string `json:"status"`
} `json:"src" gorm:"embedded"`
RSequence int `json:"rseq"`
SSequence int `json:"sseq"`
Poll bool `json:"poll"`
ACARS struct {
Error bool `json:"err"`
CRCOK bool `json:"crc_ok"`
More bool `json:"more"`
Registration string `json:"reg" ap:"TailCode"`
Mode string `json:"mode" ap:"Mode"`
Label string `json:"label" ap:"Label"`
BlockID string `json:"blk_id"`
Acknowledge any `json:"ack" gorm:"type:string"`
FlightNumber string `json:"flight" ap:"FlightNumber"`
MessageNumber string `json:"msg_num"`
MessageNumberSequence string `json:"msg_num_seq"`
MessageText string `json:"msg_text" ap:"MessageText"`
} `json:"acars" gorm:"embedded"`
} `json:"avlc" gorm:"embedded"`
BurstLengthOctets int `json:"burst_len_octets"`
FrequencyHz int `json:"freq" ap:"FrequencyHz"`
Index int `json:"idx"`
FrequencySkew float64 `json:"freq_skew"`
HDRBitsFixed int `json:"hdr_bits_fixed"`
NoiseLevel float64 `json:"noise_level"`
OctetsCorrectedByFEC int `json:"octets_corrected_by_fec"`
SignalLevel float64 `json:"sig_level" ap:"SignalLeveldBm"`
Station string `json:"station" ap:"StationId"`
Timestamp struct {
UnixTimestamp int64 `json:"sec" ap:"UnixTimestamp"`
Microseconds int64 `json:"usec"`
} `json:"t" gorm:"embedded"`
} `json:"vdl2" gorm:"embedded"`
}
func (v VDLM2Message) Prepare() (result APMessage) {
// Chop off leading periods
v.VDL2.AVLC.ACARS.Registration, _ = strings.CutPrefix(v.VDL2.AVLC.ACARS.Registration, ".")
var thumbnail, link string
img := getImageByRegistration(v.VDL2.AVLC.ACARS.Registration)
if img != nil {
thumbnail = img.ThumbnailLarge.Src
link = img.Link
}
result = FormatAsAPMessage(v, v.Name())
// Sometimes tail numbers lead with periods, chop them off
result[ACARSProcessorPrefix+"TailCode"] = strings.TrimPrefix(v.VDL2.AVLC.ACARS.Registration, ".")
// Extra helper or common fields
result[ACARSProcessorPrefix+"TrackingLink"] = FlightAwareRoot + v.VDL2.AVLC.ACARS.Registration
result[ACARSProcessorPrefix+"PhotosLink"] = FlightAwarePhotos + v.VDL2.AVLC.ACARS.Registration
result[ACARSProcessorPrefix+"ThumbnailLink"] = thumbnail
result[ACARSProcessorPrefix+"ImageLink"] = link
result[ACARSProcessorPrefix+"TranslateLink"] = fmt.Sprintf(GoogleTranslateLink, url.QueryEscape(v.VDL2.AVLC.ACARS.MessageText))
result[ACARSProcessorPrefix+"ACARSDramaTailNumberLink"] = fmt.Sprintf(ACARSDramaTailNumberLink, v.VDL2.AVLC.ACARS.Registration)
result[ACARSProcessorPrefix+"UnixTimestamp"] = int64(v.VDL2.Timestamp.UnixTimestamp)
result[ACARSProcessorPrefix+"FrequencyMHz"] = float64(v.VDL2.FrequencyHz) / 1000000
result[ACARSProcessorPrefix+"From"] = AircraftOrTower(v.VDL2.AVLC.ACARS.FlightNumber)
selectedFields := config.ACARSProcessorSettings.ACARSHub.ACARS.SelectedFields
// Remove all but any selected fields
if len(selectedFields) > 0 {
for field := range result {
if !slices.Contains(selectedFields, field) {
delete(result, field)
}
}
}
return result
}