Use better maintained go.bug.st/serial

This commit switches to serial port library to the better maintained
go.bug.st/serial library.
This commit is contained in:
Jan Dittberner 2020-04-17 19:39:06 +02:00
parent 42d1e6e991
commit 80b3309c7c
7 changed files with 51 additions and 65 deletions

View file

@ -2,39 +2,25 @@ package main
import (
"fmt"
"io/ioutil"
"time"
"github.com/goburrow/serial"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
"go.bug.st/serial"
"gopkg.in/yaml.v3"
"io/ioutil"
)
type SerialConfig struct {
Address string `yaml:"address"`
BaudRate int `yaml:"baudrate"`
DataBits int `yaml:"databits"`
StopBits int `yaml:"stopbits"`
Parity string `yaml:"parity"`
}
type ClientConfig struct {
Serial SerialConfig `yaml:"serial_config"`
Paranoid bool `yaml:"paranoid"`
Debug bool `yaml:"debug"`
GNUPGBinary string `yaml:"gnupg_bin"`
OpenSSLBinary string `yaml:"openssl_bin"`
MySQLDSN string `yaml:"mysql_dsn"`
SerialAddress string `yaml:"serial_address"`
BaudRate int `yaml:"serial_baudrate"`
Paranoid bool `yaml:"paranoid"`
Debug bool `yaml:"debug"`
GNUPGBinary string `yaml:"gnupg_bin"`
OpenSSLBinary string `yaml:"openssl_bin"`
MySQLDSN string `yaml:"mysql_dsn"`
}
var defaultConfig = ClientConfig{
Serial: SerialConfig{
Address: "/dev/ttyUSB0",
BaudRate: 115200,
DataBits: 8,
StopBits: 1,
Parity: "N",
},
SerialAddress: "/dev/ttyUSB0",
BaudRate: 115200,
Paranoid: false,
Debug: false,
OpenSSLBinary: "/usr/bin/openssl",
@ -72,13 +58,11 @@ func readConfig(configFile string) (config *ClientConfig, err error) {
return config, nil
}
func fillSerialConfig(clientConfig *ClientConfig) *serial.Config {
return &serial.Config{
Address: clientConfig.Serial.Address,
BaudRate: clientConfig.Serial.BaudRate,
DataBits: clientConfig.Serial.DataBits,
StopBits: clientConfig.Serial.StopBits,
Parity: clientConfig.Serial.Parity,
Timeout: 30 * time.Second,
func fillSerialMode(clientConfig *ClientConfig) *serial.Mode {
return &serial.Mode{
BaudRate: clientConfig.BaudRate,
DataBits: 8,
StopBits: serial.OneStopBit,
Parity: serial.NoParity,
}
}