Files
groundstation/internal/serialport/serial_linux.go
T
piotr 4f02a40a6b
Build Ground Station / build (push) Successful in 19s
fix: block while waiting for UART data
2026-09-29 13:18:18 +02:00

38 lines
820 B
Go

package serialport
import (
"fmt"
"os"
"golang.org/x/sys/unix"
)
func Open115200(path string) (*os.File, error) {
file, err := os.OpenFile(path, os.O_RDWR|unix.O_NOCTTY, 0)
if err != nil {
return nil, err
}
termios, err := unix.IoctlGetTermios(int(file.Fd()), unix.TCGETS)
if err != nil {
file.Close()
return nil, err
}
termios.Iflag = 0
termios.Oflag = 0
termios.Lflag = 0
termios.Cflag &^= unix.CSIZE | unix.PARENB | unix.CSTOPB | unix.CRTSCTS
termios.Cflag |= unix.CS8 | unix.CREAD | unix.CLOCAL
termios.Ispeed = unix.B115200
termios.Ospeed = unix.B115200
termios.Cc[unix.VMIN] = 1
termios.Cc[unix.VTIME] = 0
if err := unix.IoctlSetTermios(int(file.Fd()), unix.TCSETS, termios); err != nil {
file.Close()
return nil, fmt.Errorf("configure %s: %w", path, err)
}
return file, nil
}