-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvessel.go
58 lines (54 loc) · 2.22 KB
/
vessel.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
package ino
import (
"log/slog"
"time"
"github.com/guregu/null/v5"
"github.com/ralreegorganon/nmeaais"
)
type Vessel struct {
MMSI int64 `json:"mmsi" db:"mmsi"`
VesselName null.String `json:"vesselName" db:"vessel_name"`
CallSign null.String `json:"callSign" db:"call_sign"`
ShipType null.String `json:"shipType" db:"ship_type"`
Length null.Int `json:"length" db:"length"`
Breadth null.Int `json:"breadth" db:"breadth"`
Draught null.Float `json:"draught" db:"draught"`
Latitude null.Float `json:"latitude" db:"latitude"`
Longitude null.Float `json:"longitude" db:"longitude"`
SpeedOverGround null.Float `json:"speedOverGround" db:"speed_over_ground"`
TrueHeading null.Float `json:"trueHeading" db:"true_heading"`
CourseOverGround null.Float `json:"courseOverGround" db:"course_over_ground"`
NavigationStatus null.String `json:"navigationStatus" db:"navigation_status"`
Destination null.String `json:"destination" db:"destination"`
UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
}
func (db *DB) UpdateVessel(r nmeaais.DecoderOutput) {
switch dm := r.DecodedMessage.(type) {
case *nmeaais.PositionReportClassA:
err := db.UpdateVesselFromPositionReportClassA(dm)
if err != nil {
slog.Error("Couldn't update vessel from PositionReportClassA", slog.Any("error", err))
}
case *nmeaais.StaticAndVoyageRelatedData:
err := db.UpdateVesselFromStaticAndVoyageRelatedData(dm)
if err != nil {
slog.Error("Couldn't update vessel from StaticAndVoyageRelatedData", slog.Any("error", err))
}
case *nmeaais.PositionReportClassBStandard:
err := db.UpdateVesselFromPositionReportClassBStandard(dm)
if err != nil {
slog.Error("Couldn't update vessel from PositionReportClassBStandard", slog.Any("error", err))
}
case *nmeaais.StaticDataReportA:
err := db.UpdateVesselFromStaticDataReportA(dm)
if err != nil {
slog.Error("Couldn't update vessel from StaticDataReportA", slog.Any("error", err))
}
case *nmeaais.StaticDataReportB:
err := db.UpdateVesselFromStaticDataReportB(dm)
if err != nil {
slog.Error("Couldn't update vessel from StaticDataReportB", slog.Any("error", err))
}
default:
}
}