gateway

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2022 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package gateway provides a pico-cs MQTT broker gateway.

Index

Constants

View Source
const (
	DefaultTopicRoot = "pico-cs"
	DefaultHost      = "localhost"
	DefaultPort      = "1883"
)

Default values.

Variables

View Source
var ReservedFctNames = []string{"dir", "speed"}

ReservedFctNames is the list of reserved function names which cannot be used in loco configurations.

Functions

This section is empty.

Types

type CS

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

A CS represents a command station.

func (*CS) AddLoco

func (cs *CS) AddLoco(loco *Loco) error

AddLoco adds a loco to the command station.

func (*CS) Name added in v0.4.0

func (cs *CS) Name() string

Name returns the command station name.

func (*CS) String

func (cs *CS) String() string

type CSConfig

type CSConfig struct {
	// command station name (used in topic)
	Name string
	// pico_w host in case of WiFi TCP/IP connection
	Host string
	// TCP/IP port (WiFi) or serial port (serial over USB)
	Port string
	// filter of devices for which this command station should be a primary device
	Primary Filter
	// filter of devices for which this command station should be a secondary device
	Secondary Filter
}

CSConfig represents configuration data for a command station.

func (*CSConfig) String

func (c *CSConfig) String() string

type Config

type Config struct {
	// root part of all gateway MQTT topics
	TopicRoot string
	// MQTT broker host
	Host string
	// MQTT broker port
	Port string
	// MQTT authentication username
	Username string
	// MQTT authentication password
	Password string
	// Logger
	Logger *log.Logger
}

Config represents configuration data for the gateway.

type Filter added in v0.4.0

type Filter struct {
	// list of regular expressions defining which set of devices should be included
	Incls []string
	// list of regular expressions defining which set of devices should be excluded
	// excluding regular expressions do have precedence over including regular expressions
	Excls []string
}

Filter represents an including and excluding list of device names.

func (*Filter) String added in v0.4.0

func (f *Filter) String() string

type Gateway

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

Gateway represents a MQTT broker gateway.

func New

func New(config *Config) (*Gateway, error)

New returns a new gateway instance.

func (*Gateway) AddCS added in v0.4.0

func (gw *Gateway) AddCS(config *CSConfig) (*CS, error)

AddCS adds a command station to the gateway via a command station configuration.

func (*Gateway) AddLoco added in v0.4.0

func (gw *Gateway) AddLoco(config *LocoConfig) (*Loco, error)

AddLoco adds a loco to the gateway via a loco configuration.

func (*Gateway) CSList added in v0.4.0

func (gw *Gateway) CSList() []*CS

CSList returns the list of command stations assigned to this gateway.

func (*Gateway) Close

func (gw *Gateway) Close() error

Close closes the gateway and the MQTT connection.

func (*Gateway) Listen added in v0.5.0

func (gw *Gateway) Listen() error

Listen starts the gateway listening to subscriptions.

func (*Gateway) LocoList added in v0.4.0

func (gw *Gateway) LocoList() []*Loco

LocoList returns the list of locos assigned to this gateway.

type Loco added in v0.4.0

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

A Loco represents a loco.

func (*Loco) Name added in v0.4.0

func (l *Loco) Name() string

Name returns the loco name.

func (*Loco) Primary added in v0.4.0

func (l *Loco) Primary() string

Primary retirns the name of the primary command station.

func (*Loco) SecondaryList added in v0.4.0

func (l *Loco) SecondaryList() []string

SecondaryList returns the list of secondary command stations.

type LocoConfig

type LocoConfig struct {
	// loco name (used in topic)
	Name string
	// loco decoder address
	Addr uint
	// loco function mapping (key is used in topic)
	Fcts map[string]LocoFct
}

LocoConfig represents configuration data for a loco.

type LocoFct added in v0.4.0

type LocoFct struct {
	// loco decoder function number
	No uint
}

LocoFct represents a loco function.

Jump to

Keyboard shortcuts

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