Implement first client command
The client can now talk to the old Perl signer implementation. Running socat has been documented in README.md. Commonly used I/O code has been moved to the shared/io.go file.
This commit is contained in:
parent
5aa557c9aa
commit
65855152ce
6 changed files with 287 additions and 84 deletions
31
shared/io.go
Normal file
31
shared/io.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package shared
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/goburrow/serial"
|
||||
"io"
|
||||
"time"
|
||||
)
|
||||
|
||||
// receive the requested number of bytes from serial port and stop after the given timeout in seconds
|
||||
func ReceiveBytes(port *serial.Port, count int, timeout time.Duration) ([]byte, error) {
|
||||
timeoutCh := time.After(timeout * time.Second)
|
||||
readCh := make(chan []byte, 1)
|
||||
errCh := make(chan error, 1)
|
||||
go func() {
|
||||
data := make([]byte, count)
|
||||
if _, err := io.ReadAtLeast(*port, data, count); err != nil {
|
||||
errCh <- err
|
||||
} else {
|
||||
readCh <- data
|
||||
}
|
||||
}()
|
||||
select {
|
||||
case <-timeoutCh:
|
||||
return nil, errors.New("timeout")
|
||||
case err := <-errCh:
|
||||
return nil, err
|
||||
case data := <-readCh:
|
||||
return data, nil
|
||||
}
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
package shared
|
||||
|
||||
const MagicTrailer = "rie4Ech7"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue