-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtype22.go
More file actions
68 lines (60 loc) · 1.89 KB
/
type22.go
File metadata and controls
68 lines (60 loc) · 1.89 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
package nmeaais
import "fmt"
type ChannelManagement struct {
MessageType int64
RepeatIndicator int64
MMSI int64
ChannelA int64
ChannelB int64
TxRxMode int64
Power bool
NELongitude float64
NELatitutde float64
SWLongitude float64
SWLatitude float64
MMSI1 int64
MMSI2 int64
Addressed bool
ChannelABand bool
ChannelBBand bool
ZoneSize int64
}
func (m *Message) GetAsChannelManagement() (p *ChannelManagement, err error) {
defer func() {
if r := recover(); r != nil {
p = nil
var ok bool
err, ok = r.(error)
if !ok {
err = fmt.Errorf("pkg: %v", r)
}
}
}()
var validMessageType int64 = 22
if m.MessageType != validMessageType {
return nil, fmt.Errorf("nmeaais: tried to get message as type %v, but is type %v", validMessageType, m.MessageType)
}
p = &ChannelManagement{
MessageType: m.MessageType,
RepeatIndicator: m.RepeatIndicator,
MMSI: m.MMSI,
ChannelA: int64(asUInt(m.unarmoredPayload, 40, 12)),
ChannelB: int64(asUInt(m.unarmoredPayload, 52, 12)),
TxRxMode: int64(asUInt(m.unarmoredPayload, 64, 4)),
Power: asBool(asUInt(m.unarmoredPayload, 68, 1)),
Addressed: asBool(asUInt(m.unarmoredPayload, 139, 1)),
ChannelABand: asBool(asUInt(m.unarmoredPayload, 140, 1)),
ChannelBBand: asBool(asUInt(m.unarmoredPayload, 141, 1)),
ZoneSize: int64(asUInt(m.unarmoredPayload, 142, 3)),
}
if p.Addressed {
p.MMSI1 = int64(asUInt(m.unarmoredPayload, 69, 30))
p.MMSI2 = int64(asUInt(m.unarmoredPayload, 104, 30))
} else {
p.NELongitude = latlonShort(asInt(m.unarmoredPayload, 69, 18))
p.NELatitutde = latlonShort(asInt(m.unarmoredPayload, 87, 17))
p.SWLongitude = latlonShort(asInt(m.unarmoredPayload, 104, 18))
p.SWLatitude = latlonShort(asInt(m.unarmoredPayload, 122, 17))
}
return
}