From eaa9c42fbe5adad0af5b71c7544080cff42d6850 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 19 Nov 2016 11:21:42 +0100 Subject: added public command functions diff --git a/src/pira32ctl/command.go b/src/pira32ctl/command.go index 9291ef9..5a8e860 100644 --- a/src/pira32ctl/command.go +++ b/src/pira32ctl/command.go @@ -22,7 +22,10 @@ package main import ( + "fmt" "time" + + "code.helsinki.at/goserial" ) const ( @@ -38,6 +41,10 @@ const ( type Command interface { AllowedMethods() (get, assign, store, assignstore bool) + Get(port *goserial.Port, params ...interface{}) (interface{}, error) + Assign(port *goserial.Port, params ...interface{}) error + Store(port *goserial.Port, params ...interface{}) error + AssignStore(port *goserial.Port, params ...interface{}) error } type BasicCommand struct { @@ -54,6 +61,38 @@ func (c BasicCommand) AllowedMethods() (bool, bool, bool, bool) { return c.get, c.assign, c.store, c.assignStore } +func (c BasicCommand) Get(port *goserial.Port, params ...interface{}) (interface{}, error) { + if len(params) != 0 { + return nil, fmt.Errorf("this command takes no arguments") + } + // TODO: implement this + return nil, nil +} + +func (c BasicCommand) Assign(port *goserial.Port, params ...interface{}) error { + if len(params) != 1 { + return fmt.Errorf("this command takes exactly one argument") + } + // TODO: implement this + return nil +} + +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 +} + +func (c BasicCommand) AssignStore(port *goserial.Port, params ...interface{}) error { + if len(params) != 1 { + return fmt.Errorf("this command takes exactly one argument") + } + // TODO: implement this + return nil +} + type ParamCommand struct { code string description string @@ -70,6 +109,38 @@ func (c ParamCommand) AllowedMethods() (bool, bool, bool, bool) { return c.get, c.assign, c.store, c.assignStore } +func (c ParamCommand) Get(port *goserial.Port, params ...interface{}) (interface{}, error) { + if len(params) != 1 { + return nil, fmt.Errorf("this command takes exactly one argument") + } + // TODO: implement this + return nil, nil +} + +func (c ParamCommand) Assign(port *goserial.Port, params ...interface{}) error { + if len(params) != 2 { + return fmt.Errorf("this command takes exactly two arguments") + } + // TODO: implement this + return nil +} + +func (c ParamCommand) Store(port *goserial.Port, params ...interface{}) error { + if len(params) != 1 { + return fmt.Errorf("this command takes exactly one argument") + } + // TODO: implement this + return nil +} + +func (c ParamCommand) AssignStore(port *goserial.Port, params ...interface{}) error { + if len(params) != 2 { + return fmt.Errorf("this command takes exactly two argument") + } + // TODO: implement this + return nil +} + type Param2Command struct { code string description string @@ -85,6 +156,37 @@ type Param2Command struct { func (c Param2Command) AllowedMethods() (bool, bool, bool, bool) { return c.get, c.assign, c.store, c.assignStore } +func (c Param2Command) Get(port *goserial.Port, params ...interface{}) (interface{}, error) { + if len(params) != 1 { + return nil, fmt.Errorf("this command takes exactly one argument") + } + // TODO: implement this + return nil, nil +} + +func (c Param2Command) Assign(port *goserial.Port, params ...interface{}) error { + if len(params) != 2 { + return fmt.Errorf("this command takes exactly two arguments") + } + // TODO: implement this + return nil +} + +func (c Param2Command) Store(port *goserial.Port, params ...interface{}) error { + if len(params) != 1 { + return fmt.Errorf("this command takes exactly one argument") + } + // TODO: implement this + return nil +} + +func (c Param2Command) AssignStore(port *goserial.Port, params ...interface{}) error { + if len(params) != 2 { + return fmt.Errorf("this command takes exactly two argument") + } + // TODO: implement this + return nil +} var ( // Basic: -- cgit v0.10.2