-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for Garmin sensor status information (#117)
- Loading branch information
Showing
4 changed files
with
124 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,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() | ||
} |
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,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) | ||
} | ||
}) | ||
} | ||
} |
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