File: rpm.go

package info (click to toggle)
golang-github-adrianmo-go-nmea 1.10.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 900 kB
  • sloc: makefile: 15
file content (39 lines) | stat: -rw-r--r-- 1,220 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package nmea

const (
	// TypeRPM type of RPM sentence for Engine or Shaft revolutions and pitch
	TypeRPM = "RPM"

	// SourceEngineRPM is value for case when source is Engine
	SourceEngineRPM = "E"
	// SourceShaftRPM is value for case when source is Shaft
	SourceShaftRPM = "S"
)

// RPM - Engine or Shaft revolutions and pitch
// https://gpsd.gitlab.io/gpsd/NMEA.html#_rpm_revolutions
//
// Format: $--RPM,a,x,x.x,x.x,A*hh<CR><LF>
// Example: $RCRPM,S,0,74.6,30.0,A*56
type RPM struct {
	BaseSentence
	Source       string  // Source, S = Shaft, E = Engine
	EngineNumber int64   // Engine or shaft number
	SpeedRPM     float64 // Speed, Revolutions per minute
	PitchPercent float64 // Propeller pitch, % of maximum, "-" means astern
	Status       string  // Status, A = Valid, V = Invalid
}

// newRPM constructor
func newRPM(s BaseSentence) (Sentence, error) {
	p := NewParser(s)
	p.AssertType(TypeRPM)
	return RPM{
		BaseSentence: s,
		Source:       p.EnumString(0, "source", SourceEngineRPM, SourceShaftRPM),
		EngineNumber: p.Int64(1, "engine number"),
		SpeedRPM:     p.Float64(2, "speed"),
		PitchPercent: p.Float64(3, "pitch"),
		Status:       p.EnumString(4, "status", StatusValid, StatusInvalid),
	}, p.Err()
}