-
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
31 changed files
with
1,031 additions
and
999 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 |
---|---|---|
@@ -1,70 +1,39 @@ | ||
package nmea | ||
|
||
import "fmt" | ||
|
||
const ( | ||
// PrefixGNGGA prefix | ||
PrefixGNGGA = "GNGGA" | ||
) | ||
|
||
// GNGGA is the Time, position, and fix related data of the receiver. | ||
type GNGGA struct { | ||
Sentence | ||
// Time of fix. | ||
Time string | ||
// Latitude. | ||
Latitude LatLong | ||
// Longitude. | ||
Longitude LatLong | ||
// Quality of fix. | ||
FixQuality string | ||
// Number of satellites in use. | ||
NumSatellites string | ||
// Horizontal dilution of precision. | ||
HDOP string | ||
// Altitude. | ||
Altitude string | ||
// Geoidal separation | ||
Separation string | ||
// Age of differential GPD data. | ||
DGPSAge string | ||
// DGPS reference station ID. | ||
DGPSId string | ||
} | ||
|
||
func NewGNGGA(sentence Sentence) GNGGA { | ||
s := new(GNGGA) | ||
s.Sentence = sentence | ||
return *s | ||
Sent | ||
Time Time // Time of fix. | ||
Latitude LatLong // Latitude. | ||
Longitude LatLong // Longitude. | ||
FixQuality string // Quality of fix. | ||
NumSatellites int64 // Number of satellites in use. | ||
HDOP float64 // Horizontal dilution of precision. | ||
Altitude float64 // Altitude. | ||
Separation float64 // Geoidal separation | ||
DGPSAge string // Age of differential GPD data. | ||
DGPSId string // DGPS reference station ID. | ||
} | ||
|
||
func (s GNGGA) GetSentence() Sentence { | ||
return s.Sentence | ||
} | ||
|
||
func (s *GNGGA) parse() error { | ||
var err error | ||
|
||
if s.Type != PrefixGNGGA { | ||
return fmt.Errorf("%s is not a %s", s.Type, PrefixGNGGA) | ||
} | ||
s.Time = s.Fields[0] | ||
s.Latitude, err = NewLatLong(fmt.Sprintf("%s %s", s.Fields[1], s.Fields[2])) | ||
if err != nil { | ||
return fmt.Errorf("GNGGA decode error: %s", err) | ||
} | ||
s.Longitude, err = NewLatLong(fmt.Sprintf("%s %s", s.Fields[3], s.Fields[4])) | ||
if err != nil { | ||
return fmt.Errorf("GNGGA decode error: %s", err) | ||
} | ||
s.FixQuality = s.Fields[5] | ||
if s.FixQuality != Invalid && s.FixQuality != GPS && s.FixQuality != DGPS { | ||
return fmt.Errorf("Invalid fix quality [%s]", s.FixQuality) | ||
} | ||
s.NumSatellites = s.Fields[6] | ||
s.HDOP = s.Fields[7] | ||
s.Altitude = s.Fields[8] | ||
s.Separation = s.Fields[10] | ||
s.DGPSAge = s.Fields[12] | ||
s.DGPSId = s.Fields[13] | ||
return nil | ||
// NewGNGGA constructor | ||
func NewGNGGA(s Sent) (GNGGA, error) { | ||
p := newParser(s, PrefixGNGGA) | ||
return GNGGA{ | ||
Sent: s, | ||
Time: p.Time(0, "time"), | ||
Latitude: p.LatLong(1, 2, "latitude"), | ||
Longitude: p.LatLong(3, 4, "longitude"), | ||
FixQuality: p.EnumString(5, "fix quality", Invalid, GPS, DGPS), | ||
NumSatellites: p.Int64(6, "number of satelites"), | ||
HDOP: p.Float64(7, "hdop"), | ||
Altitude: p.Float64(8, "altitude"), | ||
Separation: p.Float64(10, "separation"), | ||
DGPSAge: p.String(12, "dgps age"), | ||
DGPSId: p.String(13, "dgps id"), | ||
}, 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
Oops, something went wrong.