simconnect

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 9 Imported by: 0

README

SimConnect API Connector

Go Reference

This package provides a convenient way to interact with the SimConnect API that takes the hassle out of dealing with the polling behavior of the API.

This is based on the seemingly abandoned msfs2020-go package that implemented vfr map. The critical code is extracted, and a new connector API is layered on top to make writing reliable services much easier. This can be easily integrated with other servies, like UIs, APIs, etc.

See the examples for sample code. The fuelhack example provides the simpliest example of the API.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsReport

func IsReport[T any](s *client.SimConnect, ppData *client.RecvSimobjectDataByType) (*T, bool)

IsReport Convenience function to check if the data is the correct type

func RequestData

func RequestData[T any](s *client.SimConnect) error

RequestData Convenience function to request data

Types

type Connector

type Connector struct {
	// contains filtered or unexported fields
}

Connector is the main struct for connecting to SimConnect

func NewConnector

func NewConnector(name string, opts ...ConnectorOption) *Connector

NewConnector creates a new connector you can pass options to the connector

func (*Connector) Start

func (c *Connector) Start(ctx context.Context)

Start starts the connector it will connect to SimConnect and start the receivers this is BLOCKING, and will terminate at the first disconnect

func (*Connector) StartReconnect

func (c *Connector) StartReconnect(ctx context.Context)

StartReconnect starts the connector with reconnect it will connect to SimConnect and start the receivers this is BLOCKING, and will reconnect on disconnect This is a simple wrapper around Start that adds a exponential backoff

type ConnectorError

type ConnectorError string

ConnectorError is the error type for the connector

const (
	// ErrE_FAIL is the error for E_FAIL
	ErrE_FAIL ConnectorError = "E_FAIL"
	// ErrGetNextDispatch is the error for GetNextDispatch
	ErrGetNextDispatch ConnectorError = "GetNextDispatch"
)

func (ConnectorError) Error

func (e ConnectorError) Error() string

type ConnectorOption

type ConnectorOption func(*Connector)

ConnectorOption is a function that sets options on the Connector

func WithCycle

func WithCycle(cycle time.Duration) ConnectorOption

WithCycle sets the cycle time for the connector the connector will dispatch data every cycle

func WithDLLPath

func WithDLLPath(path string) ConnectorOption

WithDLLPath sets the path to the SimConnect DLL if not set, the default DLL will be used

func WithLogger

func WithLogger(l *slog.Logger) ConnectorOption

WithLogger sets the logger for the connector

func WithReceiver

func WithReceiver(r Receiver) ConnectorOption

WithReceiver adds a receiver to the connector you can add multiple receivers

type Receiver

type Receiver interface {
	// Start is called when the receiver is started
	// it gets called after the connection is established
	// and whenever a reconnection happens
	// the context is cancelled when the connection is lost
	// this may be called multiple times if the connection is lost and re-established
	Start(ctx context.Context, sc *client.SimConnect)

	// Update is called whenever a new data packet is received
	// the context is cancelled when the connection is lost
	// this may be called multiple times over the life of the connection
	Update(ctx context.Context, sc *client.SimConnect, ppData *client.RecvSimobjectDataByType)
}

Receiver is the interface for receiving data from SimConnect

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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