Debugged collecting nmea data.
This commit is contained in:
parent
061ba2a859
commit
9bc94bfe7c
@ -2,6 +2,7 @@ package gps
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -29,15 +30,55 @@ const (
|
|||||||
|
|
||||||
nmeaFlagsMask = (1 << 18) - 1
|
nmeaFlagsMask = (1 << 18) - 1
|
||||||
|
|
||||||
collectTimeout = 2 * time.Second
|
collectTimeout = 5 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func secondCountDownTimer(title string, logger *log.Logger, t time.Duration) {
|
||||||
|
counter := 0
|
||||||
|
for {
|
||||||
|
if counter > int(t.Seconds()) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
logger.Printf("%s: %d/%f\n", title, counter, t.Seconds())
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
counter += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Go... otherwise will throw warning
|
// Go... otherwise will throw warning
|
||||||
var nmeaFlagsAll = gga | rmc | gpgsv | gpgsa | vtg | xfi | glgsa | gns | gagsv | bdpqgsa | bdpqgsv
|
var nmeaFlagsAll = gga | rmc | gpgsv | gpgsa | vtg | xfi | glgsa | gns | gagsv | bdpqgsa | bdpqgsv
|
||||||
|
|
||||||
func (g *gps) rawCollect(flags nmeaFlags) (string, error) {
|
func (g *gps) rawCollect(flags nmeaFlags) (string, error) {
|
||||||
// Need to omplement low level write/read here because collect must be atomic operation
|
// Need to omplement low level write/read here because collect must be atomic operation
|
||||||
// If other command is executed(write/read) it will read a part of nmea report and cause an error
|
// If other command is executed(write/read) it will read a part of nmea report and cause an error
|
||||||
|
|
||||||
|
// Setup gps
|
||||||
|
|
||||||
|
// Receive data from all contries' satelites, enable DPO(Dynamic Power Optimization) mode
|
||||||
|
// if resp, err := g.port.Send("AT+CGNSSMODE=15,1"); err != nil {
|
||||||
|
// return "", fmt.Errorf("AT+CGNSSMODE= request: %w", err)
|
||||||
|
// } else {
|
||||||
|
// if !resp.Check() {
|
||||||
|
// return "", fmt.Errorf("AT+CGNSSMODE= error response: %s", resp)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// Receive all types of data
|
||||||
|
// if resp, err := g.port.Send("AT+CGPSNMEA=200191"); err != nil {
|
||||||
|
// return "", fmt.Errorf("AT+CGPSNMEA= request: %w", err)
|
||||||
|
// } else {
|
||||||
|
// if !resp.Check() {
|
||||||
|
// return "", fmt.Errorf("AT+CGPSNMEA= error response: %s", resp)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// Set output rate to 10Hz
|
||||||
|
if resp, err := g.port.Send("AT+CGPSNMEARATE=1"); err != nil {
|
||||||
|
return "", fmt.Errorf("AT+CGPSNMEARATE= request: %w", err)
|
||||||
|
} else {
|
||||||
|
if !resp.Check() {
|
||||||
|
return "", fmt.Errorf("AT+CGPSNMEARATE= error response: %s", resp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
g.switchGpsMode(true)
|
g.switchGpsMode(true)
|
||||||
g.port.Mutex().Lock()
|
g.port.Mutex().Lock()
|
||||||
s := g.port.SerialPort()
|
s := g.port.SerialPort()
|
||||||
@ -48,16 +89,16 @@ func (g *gps) rawCollect(flags nmeaFlags) (string, error) {
|
|||||||
|
|
||||||
// Send AT+CGPSINFOCFG=255, flags
|
// Send AT+CGPSINFOCFG=255, flags
|
||||||
flags &= nmeaFlagsMask
|
flags &= nmeaFlagsMask
|
||||||
if _, err := s.Write([]byte("AT+CGPSINFOCFG=255," + string(flags) + "\r\n")); err != nil {
|
if _, err := s.Write([]byte("AT+CGPSINFOCFG=1,31\r\n")); err != nil {
|
||||||
return "", fmt.Errorf("serial port write 1: %w", err)
|
return "", fmt.Errorf("serial port write 1: %w", err)
|
||||||
}
|
}
|
||||||
// Do I need to read answer
|
// Do I need to read answer
|
||||||
|
|
||||||
// Wait
|
// Wait
|
||||||
time.Sleep(collectTimeout)
|
secondCountDownTimer("Collecting NMEA data", g.logger, collectTimeout)
|
||||||
|
|
||||||
// Send AT+CGPSINFOCFG=0, flags
|
// Send AT+CGPSINFOCFG=0, flags
|
||||||
if _, err := s.Write([]byte("AT+CGPSINFOCFG=0," + string(flags) + "\r\n")); err != nil {
|
if _, err := s.Write([]byte("AT+CGPSINFOCFG=0,31\r\n")); err != nil {
|
||||||
return "", fmt.Errorf("serial port write 2: %w", err)
|
return "", fmt.Errorf("serial port write 2: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user