Documentation ¶
Overview ¶
Provides an API to communicate with Precision Simulator X by Aerowinx and its addons.
This library also supports the extensions introduced by router + switchpsx
Index ¶
- Constants
- Variables
- type Connection
- func (pconn *Connection) Connect() (err error)
- func (pconn *Connection) Disconnect()
- func (pconn *Connection) Id() int
- func (pconn *Connection) Listener()
- func (pconn *Connection) NewPair(humanKey, value string) (msg *WireMsg)
- func (pconn *Connection) NewWireMsg() *WireMsg
- func (pconn *Connection) SendMsg(msg *WireMsg) (err error)
- func (pconn *Connection) Subscribe(humanKey string)
- func (pconn *Connection) Version() string
- type MessageDef
- type MessageHook
- type WireMsg
- func (msg *WireMsg) GetDecodedKey() string
- func (msg *WireMsg) GetDefinition() *MessageDef
- func (msg *WireMsg) GetKey() string
- func (msg *WireMsg) Parse(line string)
- func (msg *WireMsg) SetDecodedKey(humanName string)
- func (msg *WireMsg) SetKey(key string)
- func (msg *WireMsg) String() string
- func (msg *WireMsg) ValueAtSubIndex(idx int) (val string, found bool)
- func (msg *WireMsg) WireString() string
Constants ¶
const ( MsgTypeI = iota // Integer Parameter (Qi) MsgTypeS // String Parameter (Qs) MsgTypeH // Human Paramter (Qh) )
const ( MsgModeStart = iota // (S) MsgModeCont // (C) ? never seen MsgModeEcon // (E) MsgModeDelta // (D) MsgModeBigmom // (B) MsgModeMcpmom // (M) MsgModeGuamom2 // (G) MsgModeGuamom4 // (F) MsgModeCdukeyb // (K) MsgModeRcp // (R) MsgModeAcp // (A) MsgModeMixed // (X) MsgModeXdelta // (Y) MsgModeXecon // (Z) MsgModeDemand // (N) )
Variables ¶
var ( DuplicateNameError = errors.New("lexicon Name Already Registered") DuplicateIndexError = errors.New("lexicon Index Already Registered") NotAQStringError = errors.New("Line cannot be decoded - not a Q string") QStringSyntaxError = errors.New("Malformed Q String") UnknownIndexError = errors.New("Index not known to lexicon") )
var ( // Returned when actions that require a live server connection are // called against a closed connection NotConnectedError = errors.New("Connection is not currently open") // Returned when the Connection can't reconnect yet as the worker is still live. ConnectionBusyError = errors.New("Connection is still busy and unable to reconnect") )
Functions ¶
This section is empty.
Types ¶
type Connection ¶
type Connection struct { // Hostname & Port to connect to Server string // Name of the client to report to Router/SwitchPSX ClientName string // Name of the subinstance to report to Router/SwitchPSX InstanceName string // Callback Hooks. // // The key is the (decoded, if necessary) attribute. Hooks map[string]MessageHook // contains filtered or unexported fields }
Connection manages the connection to Precision Simulator X and holds all the configuration.
Use NewConnection to initialise a new Connection.
Server, ClientName and InstanceName can all be changed after initialisation but will not be reported to the server whilst the connection is active.
func NewConnection ¶
func NewConnection(server, myName string) (pconn *Connection, err error)
func (*Connection) Id ¶
func (pconn *Connection) Id() int
Returns the ID as assigned by the server/router
func (*Connection) Listener ¶
func (pconn *Connection) Listener()
The Listner needs to be started AFTER Connect() has been invoked.
It can be started in it's own goroutine, or in the current one depending on requirements, but is generally intended to run in its own goroutine.
func (*Connection) NewPair ¶
func (pconn *Connection) NewPair(humanKey, value string) (msg *WireMsg)
Initialise a message given the human readable key/value pair
func (*Connection) NewWireMsg ¶
func (pconn *Connection) NewWireMsg() *WireMsg
return a new WireMsg linked to the Connection's Lexicon
func (*Connection) SendMsg ¶
func (pconn *Connection) SendMsg(msg *WireMsg) (err error)
func (*Connection) Subscribe ¶
func (pconn *Connection) Subscribe(humanKey string)
Add the named Q variable to the filter
func (*Connection) Version ¶
func (pconn *Connection) Version() string
Returns the Software Version as reported by the server
type MessageDef ¶
type MessageDef struct { MessageType int // one of the MsgType constants reflecting the RHS format. MessageMode int // onde of the MsgMode constants reflecting the update frequency/type Index int // numeric index within the given MessageType for the message HumanName string // the humanish display name for the item }
MessageDef defines a single term in the Precision Simulator lexicon.
A MessageDef contains the information you need to map the name to and from it's number (Index) as well as the information given to us about its update mode.
func (*MessageDef) KeyString ¶
func (msgdef *MessageDef) KeyString() string
type MessageHook ¶
type MessageHook func(pconn *Connection, msg *WireMsg)
MessageHooks are used for all callbacks from Connection's listener.
The Connection is passed through pconn, and the message that triggered the callback is passed in msg.
type WireMsg ¶
type WireMsg struct { HasValue bool // Indicates if there's a data section (right hand side) Value string // Value of the data section (right hand side) // contains filtered or unexported fields }
Represents a single message off the wire from the server
Construct an empty WireMsg using Connection.NewWireMsg().
When a message is received, Connection will construct it and hand it to the callback.
Some values have to be manipulated by getter-setter (such as the Key name) in order to keep the internal state consistent.
func (*WireMsg) GetDecodedKey ¶
try to decode the message key using the lexicon (using any cached result). Return the key if there's no decoded value.
Will cache the result if none exists, so you can use this (and discard the value) to force a late decode
func (*WireMsg) GetDefinition ¶
func (msg *WireMsg) GetDefinition() *MessageDef
Return the definition for this message type (based upon Key)
func (*WireMsg) SetDecodedKey ¶
given the humanName, set the Key.
func (*WireMsg) ValueAtSubIndex ¶
asumming the value is ; delimited, get the value at the numbered subindex. found will be true if it was there, false otherwise.
func (*WireMsg) WireString ¶
return the message, ready to send, as a string.