-
Notifications
You must be signed in to change notification settings - Fork 0
/
type4.go
65 lines (58 loc) · 1.8 KB
/
type4.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
package nmeaais
import (
"fmt"
"time"
)
type BaseStationReport struct {
MessageType int64
RepeatIndicator int64
MMSI int64
TimeStamp time.Time
PositionAccuracy bool
Longitude float64
Latitude float64
EPFDType string
RAIM bool
RadioStatus int64
}
func (m *Message) GetAsBaseStationReport() (p *BaseStationReport, 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 = 4
if m.MessageType != validMessageType {
return nil, fmt.Errorf("nmeaais: tried to get message as type %v, but is type %v", validMessageType, m.MessageType)
}
var expectedMinimumLength int64 = 168
if m.bitLength < expectedMinimumLength {
return nil, fmt.Errorf("nmeaais: type %v message payload has insufficient length of %v, expected at least %v", m.MessageType, m.bitLength, expectedMinimumLength)
}
p = &BaseStationReport{
MessageType: m.MessageType,
RepeatIndicator: m.RepeatIndicator,
MMSI: m.MMSI,
TimeStamp: time.Date(
int(asUInt(m.unarmoredPayload, 38, 14)),
time.Month(asUInt(m.unarmoredPayload, 52, 4)),
int(asUInt(m.unarmoredPayload, 56, 5)),
int(asUInt(m.unarmoredPayload, 61, 5)),
int(asUInt(m.unarmoredPayload, 66, 6)),
int(asUInt(m.unarmoredPayload, 72, 6)),
0,
time.UTC),
PositionAccuracy: asBool(asUInt(m.unarmoredPayload, 78, 1)),
Longitude: latlon(asInt(m.unarmoredPayload, 79, 28)),
Latitude: latlon(asInt(m.unarmoredPayload, 107, 27)),
EPFDType: epfdType(asUInt(m.unarmoredPayload, 134, 4)),
RAIM: asBool(asUInt(m.unarmoredPayload, 148, 1)),
RadioStatus: int64(asUInt(m.unarmoredPayload, 149, 19)),
}
return
}