Documentation ¶
Index ¶
- Constants
- Variables
- func ParseHeader(data []byte) (int, int, error)
- type Callback
- type Command
- type CommandSet
- type Config
- type ConnectionState
- type Device
- func (d *Device) OnConnected(callback func())
- func (d *Device) OnDisconnected(callback func())
- func (d *Device) OnMessage(callback Callback)
- func (d *Device) Query(name string) error
- func (d *Device) SendCommand(name string, param interface{}) error
- func (d *Device) SendISCP(cmd ISCPCommand, timeout time.Duration) error
- func (d *Device) Start()
- func (d *Device) Stop()
- type EISCPMessage
- type ISCPCommand
- type ISCPGroup
- type ISCPMessage
- type LogLevel
- type Logger
- type MessageHandler
- type ParamType
Constants ¶
const Version = "0.4.3"
Version is the version string.
Variables ¶
var ( ErrNotConnected = errors.New("not connected") ErrTimeout = errors.New("timeout") )
Functions ¶
Types ¶
type Callback ¶
type Callback func(name, value string)
Callback is the type for message callback functions.
type Command ¶
type Command struct { Name string Group ISCPGroup ParamType ParamType Lookup map[string]string Lower int Upper int Scale int }
Command is the "friendly" wrapper around an ISCP command group.
func (*Command) CreateCommand ¶
func (c *Command) CreateCommand(param interface{}) (ISCPCommand, error)
CreateCommand creates an ISCP command with the given parameter. An error is returned if the parameter is invalid.
func (*Command) CreateQuery ¶
func (c *Command) CreateQuery() ISCPCommand
CreateQuery generates the "xxxQSTN" command for this Command.
type CommandSet ¶
type CommandSet interface { // ReadCommand finds the command definition for an ISCP command // and converts the parameter. ReadCommand(command ISCPCommand) (string, string, error) // CreateCommand creates an ISCP command for the given friendly name // and parameter. // An error is returned if the name or parameter is invalid. CreateCommand(name string, param interface{}) (ISCPCommand, error) // CreateQuery creates a QSTN command for the given friendly name. CreateQuery(name string) (ISCPCommand, error) }
A CommandSet represents a set of known/supported commands and can be used to convert the "friendly" version to ISCP and vice-versa.
func BasicCommands ¶
func BasicCommands() CommandSet
BasicCommands creates a command set with some commonly used commands.
func NewBasicCommandSet ¶
func NewBasicCommandSet(commands []Command) CommandSet
NewBasicCommandSet creates a new CommandSet from the given list of command definitions.
func ReadCommands ¶
func ReadCommands(path string) (CommandSet, error)
ReadCommands loads a CommandSet from a YAML file specified by the given path.
type Config ¶
type Config struct { Host string Port int AutoConnect bool AllowReconnect bool ReconnectSeconds int CommandFile string Commands CommandSet Log Logger }
Config holds configuration settings.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a Config struct with default values.
func ReadConfig ¶
ReadConfig reads configuration from ini format from the given source. Source can be a path, an opened file or a []byte array.
type ConnectionState ¶
type ConnectionState int
ConnectionState is the type used to describe the connection status for the client.
const ( Disconnected ConnectionState = iota Connecting Connected Disconnecting )
func (ConnectionState) String ¶
func (cs ConnectionState) String() string
type Device ¶
Device is an Onkyo device.
func (*Device) OnConnected ¶
func (d *Device) OnConnected(callback func())
OnConnected is called when the deivce is (re-)connected.
func (*Device) OnDisconnected ¶
func (d *Device) OnDisconnected(callback func())
OnDisconnected is called when the device is disconnected.
func (*Device) OnMessage ¶
OnMessage sets the handler for received messages to the given function. This will replace any existing handler.
func (*Device) Query ¶
Query sends a QSTN command for the given friendly name.
This method calls `SendISCP()` behind the scenes.
func (*Device) SendCommand ¶
SendCommand sends an "friendly" command (e.g. "power off") to the device.
This method calls `SendISCP()` behind the scenes.
func (*Device) SendISCP ¶
func (d *Device) SendISCP(cmd ISCPCommand, timeout time.Duration) error
SendISCP sends a raw ISCP command to the device.
You must `Start()` before you can send messages. The device may lose its connection after start. With AutoConnect set to true, attempts to connect and returns an error only if that fails. Without autoconnect, an error is returned if the device is not connected.
The message is send asynchronously. Use a non-zero timeout to wait until the message is sent. Note that the message may still be sent even if `ErrTimeout` is returned.
type EISCPMessage ¶
type EISCPMessage struct {
// contains filtered or unexported fields
}
EISCPMessage is the type for eISCP messages.
func NewEISCPMessage ¶
func NewEISCPMessage(command ISCPCommand) *EISCPMessage
NewEISCPMessage creates a new eISCP message for the given command.
func ParseEISCP ¶
func ParseEISCP(data []byte) (*EISCPMessage, error)
ParseEISCP reads an eISCP message from a byte array.
func (*EISCPMessage) Command ¶
func (e *EISCPMessage) Command() ISCPCommand
Command returns the ISCP command for this message.
func (*EISCPMessage) Raw ¶
func (e *EISCPMessage) Raw() []byte
Raw returns the byte data (header and payload) for this message.
func (*EISCPMessage) String ¶
func (e *EISCPMessage) String() string
type ISCPCommand ¶
type ISCPCommand string
An ISCPCommand is a low-level command like PWR01 (power on) or MVLUP (master volume up).
type ISCPGroup ¶
type ISCPGroup string
ISCPGroup is the 3-digit ISCP command group, e.g. "PWR" or "MVL".
func SplitISCP ¶
func SplitISCP(command ISCPCommand) (ISCPGroup, string)
SplitISCP splits an ISCP command into group and parameter.
type ISCPMessage ¶
type ISCPMessage struct {
// contains filtered or unexported fields
}
ISCPMessage is the base message for ISCP. The messages consists of: ! - start character 1 - receiver type ... - <command> \r\n - terminator
func NewISCPMessage ¶
func NewISCPMessage(command ISCPCommand) *ISCPMessage
NewISCPMessage creates a new ISCP message with the given command.
func ParseISCP ¶
func ParseISCP(data []byte) (*ISCPMessage, error)
ParseISCP parses an ISCP message from a byte array.
func (*ISCPMessage) Command ¶
func (i *ISCPMessage) Command() ISCPCommand
Command returns the ISCP command for a message.
func (*ISCPMessage) Format ¶
func (i *ISCPMessage) Format() string
Format returns the string representation for an ISCPMessage. Includes terminating newline (CRLF).
func (*ISCPMessage) String ¶
func (i *ISCPMessage) String() string
func (*ISCPMessage) ToEISCP ¶
func (i *ISCPMessage) ToEISCP() *EISCPMessage
ToEISCP converts this message to eISCP format.
type Logger ¶
type Logger interface { Debug(msg string, v ...interface{}) Info(msg string, v ...interface{}) Warning(msg string, v ...interface{}) Error(msg string, v ...interface{}) }
Logger is the interface used for logging.
type MessageHandler ¶
type MessageHandler func(ISCPCommand)
MessageHandler is a callback function to handle incoming messages.
type ParamType ¶
type ParamType string
ParamType is the kind of parameter expcted by a Command.
const ( // OnOff commands accept only on/off as parameter. OnOff ParamType = "onOff" // OnOffToggle commands work like on/off but accept an additional "toggle". OnOffToggle ParamType = "onOffToggle" // Enum based commands expect parameters from a list of values. Enum ParamType = "enum" // EnumToggle works like Enum but accepts an additional toggle/cycle parameter. EnumToggle ParamType = "enumToggle" // IntRange accepts an integer value with min and max values. IntRange ParamType = "intRange" // IntRangeEnum accepts integers and additional values from a list. IntRangeEnum ParamType = "intRangeEnum" )