psx

package module
v0.0.0-...-60def60 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2018 License: Zlib Imports: 6 Imported by: 0

README

go-psx

A library for interfacing with Precision Simulator X from go

License

See COPYING

Usage

import (
    psx "git.sysadninjas.net/flightsim/go-psx"
)

func doStuff() {
    conn := psx.NewConnection("localhost:10747", "myAddon")
    // set up stuff on conn
    conn.Connect()
    conn.Listener()
}

See http://godoc.org/git.sysadninjas.net/flightsim/go-psx for detailed API documentation.

It's probably important to note a few things that aren't obvious from the API:

  • Qs/Qi/Qh strings are converted for you into their Lexicon names (see Variables.txt) for code readability reasons. This translation cannot be trusted to occur before load1 is received from the simulator.

  • We speak the SwitchPSX/Router extensions, including Notify. Be sure to use the lexicon names, not the Q names when subscribing.

  • psx.go is threadsafe. Just make sure you only ever start one Listener per PSXConn.

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

View Source
const (
	MsgTypeI = iota // Integer Parameter (Qi)
	MsgTypeS        // String Parameter (Qs)
	MsgTypeH        // Human Paramter (Qh)
)
View Source
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

View Source
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")
)
View Source
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) Connect

func (pconn *Connection) Connect() (err error)

Connect to the server.

func (*Connection) Disconnect

func (pconn *Connection) Disconnect()

Disconnect from the server.

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

func (msg *WireMsg) GetDecodedKey() string

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) GetKey

func (msg *WireMsg) GetKey() string

return the encoded key as it would be sent on the wire

func (*WireMsg) Parse

func (msg *WireMsg) Parse(line string)

Populate this WireMsg with the line of network input (sans line end)

func (*WireMsg) SetDecodedKey

func (msg *WireMsg) SetDecodedKey(humanName string)

given the humanName, set the Key.

func (*WireMsg) SetKey

func (msg *WireMsg) SetKey(key string)

set the key without any decode attempt

func (*WireMsg) String

func (msg *WireMsg) String() string

string format the message with the key decoded for easy logging/debug use.

func (*WireMsg) ValueAtSubIndex

func (msg *WireMsg) ValueAtSubIndex(idx int) (val string, found bool)

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

func (msg *WireMsg) WireString() string

return the message, ready to send, as a string.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL