-
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
4 changed files
with
97 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package nmea | ||
|
||
const ( | ||
// TypeGSensord type for GSensord sentences | ||
TypeGSensord = "GSENSORD" | ||
) | ||
|
||
// GSensord represents measured g-loadings in the x, y and z axis. | ||
// http://aprs.gids.nl/nmea/#gsa | ||
type GSensord struct { | ||
BaseSentence | ||
X float64 // X-axis G value | ||
Y float64 // Y-axis G value | ||
Z float64 // Z-axis G valye | ||
} | ||
|
||
// newGSensord parses the GSensord sentence into this struct. | ||
func newGSensord(s BaseSentence) (GSensord, error) { | ||
p := newParser(s) | ||
p.AssertType(TypeGSensord) | ||
m := GSensord{ | ||
BaseSentence: s, | ||
X: p.Float64(0, "x-axis g value"), | ||
Y: p.Float64(1, "y-axis g value"), | ||
Z: p.Float64(2, "z-axis g value"), | ||
} | ||
return m, 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,41 @@ | ||
package nmea | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var gsensoredtests = []struct { | ||
name string | ||
raw string | ||
err string | ||
msg GSensord | ||
}{ | ||
{ | ||
name: "good sentence", | ||
raw: "$GSENSORD,0.060,0.060,-0.180", | ||
msg: GSensord{ | ||
X: 0.06, | ||
Y: 0.06, | ||
Z: -0.180, | ||
}, | ||
}, | ||
} | ||
|
||
func TestGSensord(t *testing.T) { | ||
for _, tt := range gsensoredtests { | ||
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) | ||
gsensored := m.(GSensord) | ||
gsensored.BaseSentence = BaseSentence{} | ||
assert.Equal(t, tt.msg, gsensored) | ||
} | ||
}) | ||
} | ||
} |
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