gps: improvements and bugfixes (#186)

* gps: buxfixes and refactoring of API to separate device from parser

Signed-off-by: deadprogram <ron@hybridgroup.com>

* gps: simplify time parser

Signed-off-by: deadprogram <ron@hybridgroup.com>

* gps: add support for RMC sentences

Signed-off-by: deadprogram <ron@hybridgroup.com>

* gps: small renaming to remove reduntant use of word GPS

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
Ron Evans
2020-08-20 11:22:07 +02:00
committed by GitHub
parent 88aeec9f69
commit 5df96c8138
6 changed files with 174 additions and 107 deletions
+11 -11
View File
@@ -24,25 +24,25 @@ var cfg_gnss_cmd = [...]byte{
0x01, 0x01, 0x06, 0x08, 0x0E, 0x00, 0x00, 0x00,
0x01, 0x01, 0xFC, 0x11}
func FlightMode(gpsDevice GPSDevice) (err error) {
err = sendCommand(gpsDevice, flight_mode_cmd[:])
func FlightMode(d Device) (err error) {
err = sendCommand(d, flight_mode_cmd[:])
return err
}
func SetCfgGNSS(gpsDevice GPSDevice) (err error) {
err = sendCommand(gpsDevice, cfg_gnss_cmd[:])
func SetCfgGNSS(d Device) (err error) {
err = sendCommand(d, cfg_gnss_cmd[:])
return err
}
func sendCommand(gpsDevice GPSDevice, command []byte) (err error) {
gpsDevice.WriteBytes(command)
func sendCommand(d Device, command []byte) (err error) {
d.WriteBytes(command)
start := time.Now()
for time.Now().Sub(start) < 1000 {
if gpsDevice.readNextByte() == '\n' {
if gpsDevice.readNextByte() == 0xB5 {
gpsDevice.readNextByte()
if gpsDevice.readNextByte() == 0x05 {
if gpsDevice.readNextByte() == 0x01 {
if d.readNextByte() == '\n' {
if d.readNextByte() == 0xB5 {
d.readNextByte()
if d.readNextByte() == 0x05 {
if d.readNextByte() == 0x01 {
return
}
}