-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow setting what heading sentence to use
- Loading branch information
Showing
8 changed files
with
207 additions
and
81 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
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,70 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/waterlinked/go-nmea" | ||
) | ||
|
||
// headingParser is the interface parsing heading input | ||
type headingParser interface { | ||
// parseNMEA takes a nmea.Sentence and return true if new data, else false | ||
parseNMEA(sentence nmea.Sentence) (bool, error) | ||
// String returns a string representing the current status | ||
String() string | ||
} | ||
|
||
type hdmParser struct { | ||
count int | ||
} | ||
type hdtParser struct { | ||
count int | ||
} | ||
type thsParser struct { | ||
count int | ||
} | ||
|
||
func (p *hdmParser) parseNMEA(sentence nmea.Sentence) (bool, error) { | ||
switch m := sentence.(type) { | ||
case nmea.HDM: | ||
debugPrintf("HDM: Heading : %f\n", m.Heading) | ||
latest.Orientation = m.Heading | ||
p.count++ | ||
return true, nil | ||
} | ||
return false, nil | ||
} | ||
|
||
func (p hdmParser) String() string { | ||
return fmt.Sprintf("HDM: %d", p.count) | ||
} | ||
|
||
func (p *hdtParser) parseNMEA(sentence nmea.Sentence) (bool, error) { | ||
switch m := sentence.(type) { | ||
case nmea.GPHDT: | ||
debugPrintf("HDT: Heading : %f\n", m.Heading) | ||
latest.Orientation = m.Heading | ||
p.count++ | ||
return true, nil | ||
} | ||
return false, nil | ||
} | ||
|
||
func (p hdtParser) String() string { | ||
return fmt.Sprintf("HDT: %d", p.count) | ||
} | ||
|
||
func (p *thsParser) parseNMEA(sentence nmea.Sentence) (bool, error) { | ||
switch m := sentence.(type) { | ||
case nmea.THS: | ||
debugPrintf("THS: Heading : %f\n", m.Heading) | ||
latest.Orientation = m.Heading | ||
p.count++ | ||
return true, nil | ||
} | ||
return false, nil | ||
} | ||
|
||
func (p thsParser) String() string { | ||
return fmt.Sprintf("THS: %d", p.count) | ||
} |
Oops, something went wrong.