summaryrefslogtreecommitdiff
path: root/src/rhctl/serial_port.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/rhctl/serial_port.go')
-rw-r--r--src/rhctl/serial_port.go16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/rhctl/serial_port.go b/src/rhctl/serial_port.go
index d805bdc..e8bfd92 100644
--- a/src/rhctl/serial_port.go
+++ b/src/rhctl/serial_port.go
@@ -41,15 +41,13 @@ const (
B115200 = syscall.B115200
)
-type SerialLine string
-
type SerialPort struct {
port *sio.Port
- rx <-chan SerialLine
- tx chan<- SerialLine
+ rx <-chan string
+ tx chan<- string
}
-func SerialRead(c chan<- SerialLine, port *sio.Port) {
+func SerialRead(c chan<- string, port *sio.Port) {
scanner := bufio.NewScanner(port)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
@@ -60,11 +58,11 @@ func SerialRead(c chan<- SerialLine, port *sio.Port) {
if len(data) == 0 {
continue
}
- c <- SerialLine(data)
+ c <- string(data)
}
}
-func SerialWrite(c <-chan SerialLine, port *sio.Port) {
+func SerialWrite(c <-chan string, port *sio.Port) {
for data := range c {
port.Write([]byte(data))
}
@@ -76,8 +74,8 @@ func SerialOpenAndHandle(device string, speed Baudrate) (port *SerialPort, err e
if port.port, err = sio.Open(device, uint32(speed)); err != nil {
return
}
- tx := make(chan SerialLine, 1)
- rx := make(chan SerialLine, 20)
+ tx := make(chan string, 1)
+ rx := make(chan string, 20)
go SerialRead(rx, port.port)
go SerialWrite(tx, port.port)