Documentation
¶
Overview ¶
Package client provides a pico-cs go command station client.
Index ¶
- Constants
- Variables
- func SerialDefaultPortName() (string, error)
- type Board
- type BoardType
- type Client
- func (c *Client) Board() (*Board, error)
- func (c *Client) Close() error
- func (c *Client) DCCSyncBits() (uint, error)
- func (c *Client) DelLoco(addr uint) (uint, error)
- func (c *Client) Enabled() (bool, error)
- func (c *Client) Help() ([]string, error)
- func (c *Client) IOADC(input uint) (float64, error)
- func (c *Client) IOCmdb(cmd, gpio uint) (bool, error)
- 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) RBuf() (*RBuf, error)
- func (c *Client) SetDCCSyncBits(syncBits uint) (uint, error)
- func (c *Client) SetEnabled(enabled bool) (bool, error)
- func (c *Client) SetIOCmdb(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) Temp() (float64, error)
- func (c *Client) ToggleIOCmdb(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 RBuf
- type RBufEntry
- type Serial
- type TCPClient
Examples ¶
Constants ¶
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") ErrUnknown = errors.New("unknown error") )
Command station error definitions.
Functions ¶
func SerialDefaultPortName ¶
SerialDefaultPortName returns the default serial port name if a detection is possible and an error otherwise.
Types ¶
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"
"github.com/pico-cs/go-client/client"
)
func main() {
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 string) {
// handle push messages
log.Printf("push message: %s", msg)
})
defer client.Close()
// read borad 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) DCCSyncBits ¶
DCCSyncBits returns the number of DCC sync bits.
func (*Client) Enabled ¶
Enabled returns true if the DCC sigal generation is enabled, false otherwise.
func (*Client) IOCmdb ¶ added in v0.2.0
IOCmdb returns the boolean result value of the binary GPIO command.
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) SetDCCSyncBits ¶
SetDCCSyncBits sets the number of DCC sync bits.
func (*Client) SetEnabled ¶
SetEnabled sets DCC sigal generation whether to enabled or disabled.
func (*Client) SetIOCmdb ¶ added in v0.2.0
SetIOCmdb sets the boolean value of the binary GPIO command.
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) ToggleIOCmdb ¶ added in v0.2.1
ToggleIOCmdb toggles the value of the binary GPIO command.
func (*Client) ToggleLocoDir ¶
ToggleLocoDir toggles the direction of a loco.
type Conn ¶
type Conn interface {
io.ReadWriteCloser
}
Conn is a stream oriented connection to the pico board.
type RBufEntry ¶
type RBufEntry struct {
Idx int
Addr uint
NumRefreshCycle byte
RefreshCycle byte
DirSpeed byte
F0_4 byte
F5_8 byte
F9_12 byte //lint:ignore ST1003 complains about ALL_CAPS
F5_12 byte //lint:ignore ST1003 complains about ALL_CAPS
F13_20 byte //lint:ignore ST1003 complains about ALL_CAPS
F21_28 byte //lint:ignore ST1003 complains about ALL_CAPS
F29_36 byte //lint:ignore ST1003 complains about ALL_CAPS
F37_44 byte //lint:ignore ST1003 complains about ALL_CAPS
F45_52 byte //lint:ignore ST1003 complains about ALL_CAPS
F53_60 byte //lint:ignore ST1003 complains about ALL_CAPS
F61_68 byte //lint:ignore ST1003 complains about ALL_CAPS
Prev byte
Next byte
}
RBufEntry represents a command station refresh buffer entry.
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.