-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package nmea | ||
|
||
const ( | ||
// TypeDBS type for DBS sentences | ||
TypeDBS = "DBS" | ||
) | ||
|
||
// DBS - Depth Below Surface | ||
// https://gpsd.gitlab.io/gpsd/NMEA.html#_dbs_depth_below_surface | ||
type DBS struct { | ||
BaseSentence | ||
DepthFeet float64 | ||
DepthMeters float64 | ||
DepthFathoms float64 | ||
} | ||
|
||
// newDBS constructor | ||
func newDBS(s BaseSentence) (DBS, error) { | ||
p := newParser(s) | ||
p.AssertType(TypeDBS) | ||
return DBS{ | ||
BaseSentence: s, | ||
DepthFeet: p.Float64(0, "depth_feet"), | ||
DepthMeters: p.Float64(2, "depth_meters"), | ||
DepthFathoms: p.Float64(4, "depth_fathoms"), | ||
}, p.Err() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package nmea | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var dbstests = []struct { | ||
name string | ||
raw string | ||
err string | ||
msg DBS | ||
}{ | ||
{ | ||
name: "good sentence", | ||
raw: "$23DBS,01.9,f,0.58,M,00.3,F*21", | ||
msg: DBS{ | ||
DepthFeet: MustParseDecimal("1.9"), | ||
DepthMeters: MustParseDecimal("0.58"), | ||
DepthFathoms: MustParseDecimal("0.3"), | ||
}, | ||
}, | ||
{ | ||
name: "bad validity", | ||
raw: "$23DBS,01.9,f,0.58,M,00.3,F*25", | ||
err: "nmea: sentence checksum mismatch [21 != 25]", | ||
}, | ||
} | ||
|
||
func TestDBS(t *testing.T) { | ||
for _, tt := range dbstests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
m, err := Parse(tt.raw) | ||
if tt.err != "" { | ||
assert.Error(t, err) | ||
assert.EqualError(t, err, tt.err) | ||
} else { | ||
assert.NoError(t, err) | ||
dbs := m.(DBS) | ||
dbs.BaseSentence = BaseSentence{} | ||
assert.Equal(t, tt.msg, dbs) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package nmea | ||
|
||
const ( | ||
// TypeDBT type for DBT sentences | ||
TypeDBT = "DBT" | ||
) | ||
|
||
// DBT - Depth below transducer | ||
// https://gpsd.gitlab.io/gpsd/NMEA.html#_dbt_depth_below_transducer | ||
type DBT struct { | ||
BaseSentence | ||
DepthFeet float64 | ||
DepthMeters float64 | ||
DepthFathoms float64 | ||
} | ||
|
||
// newDBT constructor | ||
func newDBT(s BaseSentence) (DBT, error) { | ||
p := newParser(s) | ||
p.AssertType(TypeDBT) | ||
return DBT{ | ||
BaseSentence: s, | ||
DepthFeet: p.Float64(0, "depth_feet"), | ||
DepthMeters: p.Float64(2, "depth_meters"), | ||
DepthFathoms: p.Float64(4, "depth_fathoms"), | ||
}, p.Err() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package nmea | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var dbttests = []struct { | ||
name string | ||
raw string | ||
err string | ||
msg DBT | ||
}{ | ||
{ | ||
name: "good sentence", | ||
raw: "$IIDBT,032.93,f,010.04,M,005.42,F*2C", | ||
msg: DBT{ | ||
DepthFeet: MustParseDecimal("32.93"), | ||
DepthMeters: MustParseDecimal("10.04"), | ||
DepthFathoms: MustParseDecimal("5.42"), | ||
}, | ||
}, | ||
{ | ||
name: "bad validity", | ||
raw: "$IIDBT,032.93,f,010.04,M,005.42,F*22", | ||
err: "nmea: sentence checksum mismatch [2C != 22]", | ||
}, | ||
} | ||
|
||
func TestDBT(t *testing.T) { | ||
for _, tt := range dbttests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
m, err := Parse(tt.raw) | ||
if tt.err != "" { | ||
assert.Error(t, err) | ||
assert.EqualError(t, err, tt.err) | ||
} else { | ||
assert.NoError(t, err) | ||
dbt := m.(DBT) | ||
dbt.BaseSentence = BaseSentence{} | ||
assert.Equal(t, tt.msg, dbt) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package nmea | ||
|
||
const ( | ||
// TypeDPT type for DPT sentences | ||
TypeDPT = "DPT" | ||
) | ||
|
||
// DPT - Depth of Water | ||
// https://gpsd.gitlab.io/gpsd/NMEA.html#_dpt_depth_of_water | ||
type DPT struct { | ||
BaseSentence | ||
Depth float64 | ||
Offset float64 | ||
} | ||
|
||
// newDPT constructor | ||
func newDPT(s BaseSentence) (DPT, error) { | ||
p := newParser(s) | ||
p.AssertType(TypeDPT) | ||
return DPT{ | ||
BaseSentence: s, | ||
Depth: p.Float64(0, "depth"), | ||
Offset: p.Float64(1, "offset"), | ||
}, p.Err() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package nmea | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var dpttests = []struct { | ||
name string | ||
raw string | ||
err string | ||
msg DPT | ||
}{ | ||
{ | ||
name: "good sentence", | ||
raw: "$SDDPT,0.5,0.5,*7B", | ||
msg: DPT{ | ||
Depth: MustParseDecimal("0.5"), | ||
Offset: MustParseDecimal("0.5"), | ||
}, | ||
}, | ||
{ | ||
name: "bad validity", | ||
raw: "$SDDPT,0.5,0.5,*AA", | ||
err: "nmea: sentence checksum mismatch [7B != AA]", | ||
}, | ||
} | ||
|
||
func TestDPT(t *testing.T) { | ||
for _, tt := range dpttests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
m, err := Parse(tt.raw) | ||
if tt.err != "" { | ||
assert.Error(t, err) | ||
assert.EqualError(t, err, tt.err) | ||
} else { | ||
assert.NoError(t, err) | ||
dpt := m.(DPT) | ||
dpt.BaseSentence = BaseSentence{} | ||
assert.Equal(t, tt.msg, dpt) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters