Skip to content

Commit f96e799

Browse files
rush0815b3nn0
authored andcommitted
Changed UART GPS baud detection and initialisation
1 parent e2b6073 commit f96e799

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

main/gps.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ func initGPSSerial() bool {
250250
} else if _, err := os.Stat("/dev/ttyAMA0"); err == nil { // ttyAMA0 is PL011 UART (GPIO pins 8 and 10) on all RPi.
251251
device = "/dev/ttyAMA0"
252252
globalStatus.GPS_detected_type = GPS_TYPE_UART
253+
baudrates = []int{115200, 38400, 9600}
253254
} else {
254255
if globalSettings.DEBUG {
255256
log.Printf("No GPS device found.\n")
@@ -260,11 +261,13 @@ func initGPSSerial() bool {
260261
log.Printf("Using %s for GPS\n", device)
261262
}
262263

263-
// Open port at default baud for config.
264-
serialConfig = &serial.Config{Name: device, Baud: baudrates[0]}
265-
p, err := serial.OpenPort(serialConfig)
264+
// try to open port with previously defined baud rate
265+
// port remains opend if detectOpenSerialPort finds matching baurate parameter
266+
// and will be closed after reprogramming.
267+
268+
p, err := detectOpenSerialPort(device, baudrates)
266269
if err != nil {
267-
log.Printf("serial port err: %s\n", err.Error())
270+
log.Printf("serial port/baudrate detection err: %s\n", err.Error())
268271
return false
269272
}
270273

@@ -307,7 +310,6 @@ func initGPSSerial() bool {
307310
//p.Write(makeUBXCFG(0x06, 0x09, 13, []byte{0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x03}))
308311
//time.Sleep(100* time.Millisecond) // pause and wait for the GPS to finish configuring itself before closing / reopening the port
309312

310-
311313
if globalStatus.GPS_detected_type == GPS_TYPE_UBX9 {
312314
if globalSettings.DEBUG {
313315
log.Printf("ublox 9 detected\n")
@@ -400,6 +402,7 @@ func initGPSSerial() bool {
400402
// Re-open port at newly configured baud so we can read messages. ReadTimeout is set to keep from blocking the gpsSerialReader() on misconfigures or ttyAMA disconnects
401403
// serialConfig = &serial.Config{Name: device, Baud: baudrate, ReadTimeout: time.Millisecond * 2500}
402404
// serial.OpenPort(serialConfig)
405+
403406
p, err = detectOpenSerialPort(device, baudrates)
404407
if err != nil {
405408
log.Printf("serial port err: %s\n", err.Error())
@@ -408,6 +411,7 @@ func initGPSSerial() bool {
408411

409412
serialPort = p
410413
return true
414+
411415
}
412416

413417
func detectOpenSerialPort(device string, baudrates []int) (*(serial.Port), error) {

0 commit comments

Comments
 (0)