Skip to content

Commit

Permalink
Allow omitting the DPT scale field (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
icholy authored Dec 10, 2021
1 parent 2e640c1 commit a4c9590
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 6 additions & 3 deletions dpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ type DPT struct {
func newDPT(s BaseSentence) (DPT, error) {
p := NewParser(s)
p.AssertType(TypeDPT)
return DPT{
dpt := DPT{
BaseSentence: s,
Depth: p.Float64(0, "depth"),
Offset: p.Float64(1, "offset"),
RangeScale: p.Float64(2, "range scale"),
}, p.Err()
}
if len(p.Fields) > 2 {
dpt.RangeScale = p.Float64(2, "range scale")
}
return dpt, p.Err()
}
9 changes: 9 additions & 0 deletions dpt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ var dpttests = []struct {
RangeScale: MustParseDecimal("0.1"),
},
},
{
name: "good sentence with 2 fields",
raw: "$INDPT,2.3,0.0*46",
msg: DPT{
Depth: MustParseDecimal("2.3"),
Offset: MustParseDecimal("0.0"),
RangeScale: MustParseDecimal("0"),
},
},
{
name: "bad validity",
raw: "$SDDPT,0.5,0.5,*AA",
Expand Down

0 comments on commit a4c9590

Please sign in to comment.