mirror of
https://github.com/xtaci/kcptun.git
synced 2024-04-21 12:32:32 +00:00
39 lines
619 B
Go
39 lines
619 B
Go
package generic
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/pkg/errors"
|
|
"github.com/tarm/serial"
|
|
)
|
|
|
|
const (
|
|
// serial@name@baud
|
|
// eg:
|
|
// serial@/dev/ttys002@9600
|
|
// serial@COM4@9600
|
|
SERIAL_PROTO = "serial@"
|
|
)
|
|
|
|
func ParseSerialParams(addr string) (*serial.Config, error) {
|
|
// serial://NAME
|
|
strs := strings.Split(addr, "@")
|
|
if len(strs) < 3 {
|
|
return nil, errors.Errorf("serial format error:%v", addr)
|
|
}
|
|
|
|
port := strs[1]
|
|
// parse baud
|
|
baud, err := strconv.Atoi(strs[2])
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
config := new(serial.Config)
|
|
config.Name = port
|
|
config.Baud = baud
|
|
|
|
return config, nil
|
|
}
|