summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-11-20 08:45:54 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-11-20 08:45:54 (GMT)
commite9c1929e1aab07c798f20d079cf3a77081a0771e (patch)
treea286964fc1c6f333b0873003f5556a652b0d6656 /src
parenteaa9c42fbe5adad0af5b71c7544080cff42d6850 (diff)
test implemented first command methodHEADmaster
Diffstat (limited to 'src')
-rw-r--r--src/pira32ctl/command.go42
1 files changed, 35 insertions, 7 deletions
diff --git a/src/pira32ctl/command.go b/src/pira32ctl/command.go
index 5a8e860..390cb40 100644
--- a/src/pira32ctl/command.go
+++ b/src/pira32ctl/command.go
@@ -22,6 +22,7 @@
package main
import (
+ "errors"
"fmt"
"time"
@@ -29,14 +30,24 @@ import (
)
const (
- REQ_PERSISTANT = '*'
+ REQ_PERSISTANT = "*"
- RESP_OK = '+'
- RESP_UNKNOWN_CMD = '!'
- RESP_INVALID_ARG = '-'
- RESP_PARTIAL = '/'
+ RESP_OK = "+"
+ RESP_UNKNOWN_CMD = "!"
+ RESP_INVALID_ARG = "-"
+ RESP_PARTIAL = "/"
storeExecutionTime = 10 * time.Millisecond
+
+ respTimeout = 500 * time.Millisecond
+)
+
+var (
+ ErrInvalidResp = errors.New("got invalid response")
+ ErrTimeout = errors.New("timeout")
+ ErrUnknownCmd = errors.New("unknown command")
+ ErrInvalidArg = errors.New("invalid argument")
+ ErrPartial = errors.New("partial success")
)
type Command interface {
@@ -81,8 +92,25 @@ func (c BasicCommand) Store(port *goserial.Port, params ...interface{}) error {
if len(params) != 0 {
return fmt.Errorf("this command takes no arguments")
}
- // TODO: implement this
- return nil
+ port.TX <- REQ_PERSISTANT + c.code
+ t := time.NewTimer(respTimeout)
+ var resp string
+ select {
+ case resp = <-port.RX:
+ case <-t.C:
+ return ErrTimeout
+ }
+ switch resp {
+ case RESP_OK:
+ return nil
+ case RESP_UNKNOWN_CMD:
+ return ErrUnknownCmd
+ case RESP_INVALID_ARG:
+ return ErrUnknownCmd
+ case RESP_PARTIAL:
+ return ErrUnknownCmd
+ }
+ return ErrInvalidResp
}
func (c BasicCommand) AssignStore(port *goserial.Port, params ...interface{}) error {