Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

Commit 12c2343

Browse files
committed
Pass through timestamp, don't try to normalise
Addresses adrianmo#59 (comment)
1 parent 492c8fa commit 12c2343

2 files changed

Lines changed: 7 additions & 42 deletions

File tree

tagblock.go

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package nmea
22

33
import (
4-
"errors"
54
"fmt"
65
"regexp"
76
"strconv"
87
"strings"
9-
"time"
108
)
119

1210
var (
@@ -17,8 +15,8 @@ var (
1715
// TagBlock struct
1816
type TagBlock struct {
1917
Head string // *
20-
Time int64 // TypeUnixTime unix timestamp, parameter: -c
21-
RelativeTime int64 // TypeRelativeTime relative time time, parameter: -r
18+
Time int64 // TypeUnixTime unix timestamp (unit is likely to be s, but might be ms, YMMV), parameter: -c
19+
RelativeTime int64 // TypeRelativeTime relative time, parameter: -r
2220
Destination string // TypeDestinationID destination identification 15 char max, parameter: -d
2321
Grouping string // TypeGrouping sentence grouping, parameter: -g
2422
LineCount int64 // TypeLineCount line count, parameter: -n
@@ -29,28 +27,11 @@ type TagBlock struct {
2927
func parseInt64(raw string) (int64, error) {
3028
i, err := strconv.ParseInt(raw[2:], 10, 64)
3129
if err != nil {
32-
return 0, fmt.Errorf("nmea: tagblock unable to parse uint32 [%s]", raw)
30+
return 0, fmt.Errorf("nmea: tagblock unable to parse uint64 [%s]", raw)
3331
}
3432
return i, nil
3533
}
3634

37-
// Timestamp can come as milliseconds or seconds
38-
func validUnixTimestamp(timestamp int64) (int64, error) {
39-
if timestamp < 0 {
40-
return 0, errors.New("nmea: Tagblock timestamp is not valid must be between 0 and now + 24h")
41-
}
42-
now := time.Now()
43-
unix := now.Unix() + 24*3600
44-
if timestamp > unix {
45-
if timestamp > unix*1000 {
46-
return 0, errors.New("nmea: Tagblock timestamp is not valid")
47-
}
48-
return timestamp / 1000, nil
49-
}
50-
51-
return timestamp, nil
52-
}
53-
5435
// parseTagBlock adds support for tagblocks
5536
// https://rietman.wordpress.com/2016/09/17/nemastudio-now-supports-the-nmea-0183-tag-block/
5637
func parseTagBlock(raw string) (TagBlock, string, error) {
@@ -92,10 +73,6 @@ func parseTagBlock(raw string) (TagBlock, string, error) {
9273
if err != nil {
9374
return tagBlock, raw, err
9475
}
95-
tagBlock.Time, err = validUnixTimestamp(tagBlock.Time)
96-
if err != nil {
97-
return tagBlock, raw, err
98-
}
9976
case "d": // Destination ID
10077
tagBlock.Destination = item[2:]
10178
case "g": // Grouping

tagblock_test.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,11 @@ var tagblocktests = []struct {
5555
name: "Test milliseconds timestamp",
5656
raw: "UdPbC?\\x:NorSat_1,c:1564827317000*72\\!AIVDM,1,1,,A,19NSRaP02A0fo91kwnaMKbjR08:J,0*15",
5757
msg: TagBlock{
58-
Time: 1564827317,
58+
Time: 1564827317000,
5959
Source: "",
6060
Head: "UdPbC?",
6161
},
6262
},
63-
{
64-
65-
name: "Test invalid high timestamp",
66-
raw: "UdPbC?\\x:NorSat_1,c:25648273170000000*71\\!AIVDM,1,1,,A,19NSRaP02A0fo91kwnaMKbjR08:J,0*15",
67-
err: "nmea: Tagblock timestamp is not valid",
68-
},
69-
{
70-
71-
name: "Test invalid low timestamp",
72-
raw: "UdPbC?\\x:NorSat_1,c:-10*60\\!AIVDM,1,1,,A,19NSRaP02A0fo91kwnaMKbjR08:J,0*15",
73-
err: "nmea: Tagblock timestamp is not valid must be between 0 and now + 24h",
74-
},
7563
{
7664

7765
name: "Test all input types",
@@ -119,19 +107,19 @@ var tagblocktests = []struct {
119107

120108
name: "Test invalid timestamp",
121109
raw: "UdPbC?\\s:satelite,c:gjadslkg*30\\!AIVDM,1,1,,A,19NSRaP02A0fo91kwnaMKbjR08:J,0*15",
122-
err: "nmea: tagblock unable to parse uint32 [c:gjadslkg]",
110+
err: "nmea: tagblock unable to parse uint64 [c:gjadslkg]",
123111
},
124112
{
125113

126114
name: "Test invalid linecount",
127115
raw: "UdPbC?\\s:satelite,n:gjadslkg*3D\\!AIVDM,1,1,,A,19NSRaP02A0fo91kwnaMKbjR08:J,0*15",
128-
err: "nmea: tagblock unable to parse uint32 [n:gjadslkg]",
116+
err: "nmea: tagblock unable to parse uint64 [n:gjadslkg]",
129117
},
130118
{
131119

132120
name: "Test invalid relative time",
133121
raw: "UdPbC?\\s:satelite,r:gjadslkg*21\\!AIVDM,1,1,,A,19NSRaP02A0fo91kwnaMKbjR08:J,0*15",
134-
err: "nmea: tagblock unable to parse uint32 [r:gjadslkg]",
122+
err: "nmea: tagblock unable to parse uint64 [r:gjadslkg]",
135123
},
136124
}
137125

0 commit comments

Comments
 (0)