Documentation
¶
Overview ¶
Package client provides a pico-cs go command station client.
Index ¶
- Constants
- Variables
- func SerialDefaultPortName() (string, error)
- type Board
- type BoardType
- type CVIdx
- type Client
- func (c *Client) Board() (*Board, error)
- func (c *Client) CV(idx CVIdx) (byte, error)
- func (c *Client) Close() error
- func (c *Client) Flash() (*flash.Flash, error)
- func (c *Client) FlashFormat() (bool, error)
- func (c *Client) Help() ([]string, error)
- func (c *Client) IOADC(input uint) (float64, error)
- func (c *Client) IODir(cmd, gpio uint) (bool, error)
- func (c *Client) IODown(cmd, gpio uint) (bool, error)
- func (c *Client) IOUp(cmd, gpio uint) (bool, error)
- func (c *Client) IOVal(cmd, gpio uint) (bool, error)
- func (c *Client) IsSerialConn() bool
- func (c *Client) LocoCV1718(addr uint) (byte, byte, error)
- func (c *Client) LocoDir(addr uint) (bool, error)
- func (c *Client) LocoFct(addr, no uint) (bool, error)
- func (c *Client) LocoSpeed128(addr uint) (uint, error)
- func (c *Client) MTE() (bool, error)
- func (c *Client) Reboot() error
- func (c *Client) Reconnect() error
- func (c *Client) RefreshBuffer() (*rbuf.Buffer, error)
- func (c *Client) RefreshBufferDelete(addr uint) (uint, error)
- func (c *Client) RefreshBufferReset() (bool, error)
- func (c *Client) SetAccFct(addr uint, out byte, fct bool) (bool, error)
- func (c *Client) SetAccStatus(addr uint, status byte) (bool, error)
- func (c *Client) SetAccTime(addr uint, out, time byte) (bool, error)
- func (c *Client) SetCV(idx CVIdx, val byte) (byte, error)
- func (c *Client) SetIODir(cmd, gpio uint, value bool) (bool, error)
- func (c *Client) SetIODown(cmd, gpio uint, value bool) (bool, error)
- func (c *Client) SetIOUp(cmd, gpio uint, value bool) (bool, error)
- func (c *Client) SetIOVal(cmd, gpio uint, value bool) (bool, error)
- func (c *Client) SetLocoCV29Bit5(addr uint, bit bool) (bool, error)
- func (c *Client) SetLocoCVBit(addr, idx uint, bit byte, val bool) (bool, error)
- func (c *Client) SetLocoCVByte(addr, idx uint, val byte) (byte, error)
- func (c *Client) SetLocoDir(addr uint, dir bool) (bool, error)
- func (c *Client) SetLocoFct(addr, no uint, fct bool) (bool, error)
- func (c *Client) SetLocoLaddr(addr, laddr uint) (uint, error)
- func (c *Client) SetLocoSpeed128(addr, speed uint) (uint, error)
- func (c *Client) SetMTE(enabled bool) (bool, error)
- func (c *Client) Store() (bool, error)
- func (c *Client) Temp() (float64, error)
- func (c *Client) ToggleIODir(cmd, gpio uint) (bool, error)
- func (c *Client) ToggleIODown(cmd, gpio uint) (bool, error)
- func (c *Client) ToggleIOUp(cmd, gpio uint) (bool, error)
- func (c *Client) ToggleIOVal(cmd, gpio uint) (bool, error)
- func (c *Client) ToggleLocoDir(addr uint) (bool, error)
- func (c *Client) ToggleLocoFct(addr, no uint) (bool, error)
- type Conn
- type IOIEMsg
- type Msg
- type Serial
- type TCPClient
- type TCPMsg
- type WifiMsg
Examples ¶
Constants ¶
const ( MkUnknown = iota MkWifi MkTCP MkIOIE )
Message kind.
const DefaultTCPPort = "4242"
DefaultTCPPort is the default TCP Port used by Pico W.
Variables ¶
var ( ErrInvCmd = errors.New("invalid command") ErrInvPrm = errors.New("invalid parameter") ErrInvNumPrm = errors.New("invalid number of parameters") ErrNoData = errors.New("no data") ErrNoChange = errors.New("no change") ErrInvGPIO = errors.New("invalid GPIO") ErrNotImpl = errors.New("not implemented") ErrIO = errors.New("io error") ErrNotExec = errors.New("not executed") ErrUnknown = errors.New("unknown error") )
Command station error definitions.
var ( ErrSerialDefaultPortPathMissing = fmt.Errorf("missing default serial port path for %s", runtime.GOOS) ErrSerialDefaultPortNotFound = fmt.Errorf("default port could not be detected for %s", defaultSerialPortPath) )
Serial default port errors.
Functions ¶
func SerialDefaultPortName ¶
SerialDefaultPortName returns the default serial port name if a detection is possible and an error otherwise.
Types ¶
type CVIdx ¶ added in v0.5.0
type CVIdx byte
CVIdx represents a command station CV index.
const ( CVMT CVIdx = iota // Main track configuration flags CVNumSyncBit // Number of DCC synchronization bits CVNumRepeat // DCC command repetitions CVNumRepeatCV // DCC command repetitions for main track CV programming CVNumRepeatAcc // DCC command repetitions for accessory decoders CVBidiTS // BiDi (microseconds until power off after end bit) CVBidiTE // BiDi (microseconds to power on before start of 5th sync bit) )
Main track CV index constants.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a command station client instance.
Example ¶
ExampleClient shows how to establish a pico-cs command station client.
package main import ( "log" "time" "github.com/pico-cs/go-client/client" ) func main() { time.Sleep(2 * time.Second) defaultPortName, err := client.SerialDefaultPortName() if err != nil { log.Fatal(err) } conn, err := client.NewSerial(defaultPortName) if err != nil { log.Fatal(err) } client := client.New(conn, func(msg client.Msg, err error) { // handle push messages if err != nil { log.Printf("push message: %s", msg) } else { log.Printf("push message error: %s", err) } }) defer client.Close() // read board information. board, err := client.Board() if err != nil { log.Fatal(err) } log.Printf("%s ID %s MAC %s", board.Type, board.ID, board.MAC) // read command station temperature. temp, err := client.Temp() if err != nil { log.Fatal(err) } log.Printf("temperature %f", temp) }
func (*Client) FlashFormat ¶ added in v0.5.0
FlashFormat formats the command station flash (debugging).
func (*Client) IsSerialConn ¶ added in v0.5.1
IsSerialConn returns true if the connection is serial, false otherwise.
func (*Client) LocoCV1718 ¶
LocoCV1718 returns (calculates) the CV17 and CV18 values (long address) from a loco address.
func (*Client) LocoDir ¶
LocoDir returns the direction of a loco. true : forward direction false: backward direction
func (*Client) LocoSpeed128 ¶
LocoSpeed128 returns the speed of a loco. 0 : stop 1 : emergency stop 2-127: 126 speed steps
func (*Client) MTE ¶ added in v0.4.0
MTE returns true if the main track DCC sigal generation is enabled, false otherwise.
func (*Client) RefreshBuffer ¶ added in v0.5.0
RefreshBuffer returns the command station refresh buffer (debugging).
func (*Client) RefreshBufferDelete ¶ added in v0.5.0
RefreshBufferDelete deletes address addr from refresh buffer (debugging).
func (*Client) RefreshBufferReset ¶ added in v0.5.0
RefreshBufferReset resets the refresh buffer (debugging).
func (*Client) SetAccFct ¶ added in v0.5.0
SetAccFct sets the function value of an accessory decoder on output out.
func (*Client) SetAccStatus ¶ added in v0.5.0
SetAccStatus sets the status byte of an extended accessory decoder.
func (*Client) SetAccTime ¶ added in v0.5.0
SetAccTime sets the activation time of an accessory decoder on output out.
func (*Client) SetIODir ¶ added in v0.3.0
SetIODir sets the direction of the GPIO. false: in true: out
func (*Client) SetLocoCV29Bit5 ¶
SetLocoCV29Bit5 sets the CV 29 bit 5 value of a loco.
func (*Client) SetLocoCVBit ¶
SetLocoCVBit sets the indexed CV bit value of a loco.
func (*Client) SetLocoCVByte ¶
SetLocoCVByte sets the indexed CV byte value of a loco.
func (*Client) SetLocoDir ¶
SetLocoDir sets the direction of a loco. true : forward direction false: backward direction
func (*Client) SetLocoFct ¶
SetLocoFct sets a function value of a loco.
func (*Client) SetLocoLaddr ¶
SetLocoLaddr sets the long address of a loco.
func (*Client) SetLocoSpeed128 ¶
SetLocoSpeed128 sets the speed of a loco. 0 : stop 1 : emergency stop 2-127: 126 speed steps
func (*Client) SetMTE ¶ added in v0.4.0
SetMTE sets main track DCC sigal generation whether to enabled or disabled.
func (*Client) ToggleIODir ¶ added in v0.3.0
ToggleIODir toggles the direction of the GPIO.
func (*Client) ToggleIODown ¶ added in v0.3.0
ToggleIODown toggles the pull-down status of the GPIO.
func (*Client) ToggleIOUp ¶ added in v0.3.0
ToggleIOUp toggles the pull-up status of the GPIO.
func (*Client) ToggleIOVal ¶ added in v0.3.1
ToggleIOVal toggles the value of the GPIO.
func (*Client) ToggleLocoDir ¶
ToggleLocoDir toggles the direction of a loco.
type Conn ¶
type Conn interface { Connect() error io.ReadWriteCloser }
Conn is a stream oriented connection to the pico board.
type IOIEMsg ¶ added in v0.2.2
IOIEMsg represents a GPIO input event message.
type Serial ¶
type Serial struct {
// contains filtered or unexported fields
}
Serial provides a serial connection to to the Raspberry Pi Pico.
type TCPClient ¶ added in v0.1.10
type TCPClient struct {
// contains filtered or unexported fields
}
TCPClient provides a TCP/IP connection to to the Raspberry Pi Pico W.
func NewTCPClient ¶ added in v0.1.10
NewTCPClient returns a new TCP/IP connection instance.