-
Notifications
You must be signed in to change notification settings - Fork 80
/
tlb.go
52 lines (47 loc) · 1.37 KB
/
tlb.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
package nmea
import "errors"
const (
// TypeTLB type of TLB target label.
TypeTLB = "TLB"
)
// TLB is sentence for target label.
// https://fcc.report/FCC-ID/ADB9ZWRTR100/2768717.pdf (page 8) FURUNO MARINE RADAR, model FAR-15XX manual
//
// Format: $--TLB,x.x,c--c,x.x,c--c,...x.x,c--c*hh<CR><LF>
// Example: $CDTLB,1,XXX,2.0,YYY*41
type TLB struct {
BaseSentence
Targets []TLBTarget
}
// TLBTarget is instance of target for TLB sentence
type TLBTarget struct {
// TargetNumber is target number “n” reported by the device (1 - 1023)
TargetNumber float64
// TargetLabel is label assigned to target “n” (TT=000 - 999, AIS=000000000 - 999999999). Could be empty.
TargetLabel string
}
// newTLB constructor
func newTLB(s BaseSentence) (Sentence, error) {
p := NewParser(s)
p.AssertType(TypeTLB)
tlb := TLB{
BaseSentence: s,
Targets: make([]TLBTarget, 0),
}
fieldCount := len(p.Fields)
if fieldCount < 2 {
return tlb, errors.New("TLB is missing fields for parsing target pairs")
}
if fieldCount%2 != 0 {
return tlb, errors.New("TLB data set field count is not exactly dividable by 2")
}
tlb.Targets = make([]TLBTarget, 0, fieldCount/2)
for i := 0; i < fieldCount; i = i + 2 {
tmp := TLBTarget{
TargetNumber: p.Float64(0+i, "target number"),
TargetLabel: p.String(1+i, "target label"),
}
tlb.Targets = append(tlb.Targets, tmp)
}
return tlb, p.Err()
}