Skip to content

Commit

Permalink
add support for Garmin sensor status information (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
tnn2 authored Aug 12, 2024
1 parent af41c6a commit cd0f55b
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ on [IEC 61162-1:2016 (Edition 5.0 2016-08)](https://webstore.iec.ch/publication/
| [PNG](./pgn.go) | Transfer NMEA2000 frame as NMEA0183 sentence (ShipModul MiniPlex-3) | [1](https://opencpn.org/wiki/dokuwiki/lib/exe/fetch.php?media=opencpn:software:mxpgn_sentence.pdf) |
| [PCDIN](./pcdin.go) | Transfer NMEA2000 frame as NMEA0183 sentence (SeaSmart.Net Protocol) | [1](http://www.seasmart.net/pdf/SeaSmart_HTTP_Protocol_RevG_043012.pdf) |
| [PGRME](./pgrme.go) | Estimated Position Error (Garmin proprietary sentence) | [1](http://aprs.gids.nl/nmea/#rme) |
| [PGRMT](./pgrmt.go) | Sensor Status Information (Garmin proprietary sentence) | [1#2.2.6](https://developer.garmin.com/downloads/legacy/uploads/2015/08/190-00684-00.pdf) |
| [PHTRO](./phtro.go) | Vessel pitch and roll (Xsens IMU/VRU/AHRS) | |
| [PMTK001](./pmtk.go) | Acknowledgement of previously sent command/packet | [1](https://www.rhydolabz.com/documents/25/PMTK_A11.pdf) |
| [PRDID](./prdid.go) | Vessel pitch, roll and heading (Xsens IMU/VRU/AHRS) | |
Expand Down
53 changes: 53 additions & 0 deletions pgrmt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package nmea

const (
// TypePGRMT type for PGRMT sentences
TypePGRMT = "GRMT"
// PassPGRMT Self-Test Passed
PassPGRMT = "P"
// FailPGRMT Self-Test Failed
FailPGRMT = "F"
// DataRetainedPGRMT Data Retained
DataRetainedPGRMT = "R"
// DataLostPGRMT Data Lost
DataLostPGRMT = "L"
// DataCollectingPGRMT Data Collecting
DataCollectingPGRMT = "C"
)

// PGRMT is Sensor Status Information (Garmin proprietary sentence)
// https://developer.garmin.com/downloads/legacy/uploads/2015/08/190-00684-00.pdf
// $PGRMT,<0>,<1>,<2>,<3>,<4>,<5>,<6>,<7>,<8>*hh<CR><LF>
// Format: $PGRMT,xxxxxxxxxx,A,A,A,A,A,A,N,A*hh<CR><LF>
// Example: $PGRMT,GPS24xd-HVS VER 2.30,,,,,,,,*10
type PGRMT struct {
BaseSentence
ModelAndFirmwareVersion string
ROMChecksumTest string // "P" = pass, "F" = fail
ReceiverFailureDiscrete string // "P" = pass, "F" = fail
StoredDataLost string // "R" = retained, "L" = lost
RealtimeClockLost string // "R" = retained, "L" = lost
OscillatorDriftDiscrete string // "P" = pass, "F" = fail
DataCollectionDiscrete string // "C" = collecting, "" = not collecting
SensorTemperature float64 // Degrees C
SensorConfigurationData string // "R" = retained, "L" = lost
}

// newPGRMT constructor
func newPGRMT(s BaseSentence) (Sentence, error) {
p := NewParser(s)
p.AssertType(TypePGRMT)

return PGRMT{
BaseSentence: s,
ModelAndFirmwareVersion: p.String(0, "product, model and software version"),
ROMChecksumTest: p.EnumString(1, "rom checksum test", PassPGRMT, FailPGRMT),
ReceiverFailureDiscrete: p.EnumString(2, "receiver failure discrete", PassPGRMT, FailPGRMT),
StoredDataLost: p.EnumString(3, "stored data lost", DataRetainedPGRMT, DataLostPGRMT),
RealtimeClockLost: p.EnumString(4, "realtime clock lost", DataRetainedPGRMT, DataLostPGRMT),
OscillatorDriftDiscrete: p.EnumString(5, "oscillator drift discrete", PassPGRMT, FailPGRMT),
DataCollectionDiscrete: p.EnumString(6, "data collection discrete", DataCollectingPGRMT),
SensorTemperature: p.Float64(7, "sensor temperature in degrees celsius"),
SensorConfigurationData: p.EnumString(8, "sensor configuration data", DataRetainedPGRMT, DataLostPGRMT),
}, p.Err()
}
68 changes: 68 additions & 0 deletions pgrmt_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package nmea

import (
"testing"

"github.com/stretchr/testify/assert"
)

var pgrmttests = []struct {
name string
raw string
err string
msg PGRMT
}{
{
name: "typical sentence",
raw: "$PGRMT,GPS24xd-HVS VER 2.30,,,,,,,,*10",
msg: PGRMT{
ModelAndFirmwareVersion: "GPS24xd-HVS VER 2.30",
},
},
{
name: "all good",
raw: "$PGRMT,GOOD GPS VER 1.0,P,P,R,R,P,C,32,R*39",
msg: PGRMT{
ModelAndFirmwareVersion: "GOOD GPS VER 1.0",
ROMChecksumTest: PassPGRMT,
ReceiverFailureDiscrete: PassPGRMT,
StoredDataLost: DataRetainedPGRMT,
RealtimeClockLost: DataRetainedPGRMT,
OscillatorDriftDiscrete: PassPGRMT,
DataCollectionDiscrete: DataCollectingPGRMT,
SensorTemperature: 32,
SensorConfigurationData: DataRetainedPGRMT,
},
},
{
name: "all bad",
raw: "$PGRMT,BAD GPS VER 1.0,F,F,L,L,F,,-64,L*18",
msg: PGRMT{
ModelAndFirmwareVersion: "BAD GPS VER 1.0",
ROMChecksumTest: FailPGRMT,
ReceiverFailureDiscrete: FailPGRMT,
StoredDataLost: DataLostPGRMT,
RealtimeClockLost: DataLostPGRMT,
OscillatorDriftDiscrete: FailPGRMT,
SensorTemperature: -64,
SensorConfigurationData: DataLostPGRMT,
},
},
}

func TestPGRMT(t *testing.T) {
for _, tt := range pgrmttests {
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)
pgrmt := m.(PGRMT)
pgrmt.BaseSentence = BaseSentence{}
assert.Equal(t, tt.msg, pgrmt)
}
})
}
}
2 changes: 2 additions & 0 deletions sentence.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ func (p *SentenceParser) Parse(raw string) (Sentence, error) {
return newPCDIN(s)
case TypePGRME:
return newPGRME(s)
case TypePGRMT:
return newPGRMT(s)
case TypePHTRO:
return newPHTRO(s)
case TypePMTK001:
Expand Down

0 comments on commit cd0f55b

Please sign in to comment.