ttrn

package
v0.0.0-...-fa22948 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(cfg Config, doDebug bool)

Run runs the server application.

Types

type Config

type Config struct {
	// Port is the port where the page is served on localhost.
	Port int `json:"port"`
	// Db is the path to the sqlite db.
	Db string `json:"db"`
	// MqttClientId is the MQTT client id.
	MqttClientId string `json:"mqtt_client_id"`
	// MqttHost is the hostname of the the MQTT broker.
	MqttHost string `json:"mqtt_host"`
	// MqttPort is the port of the MQTT broker.
	MqttPort int `json:"mqtt_port"`
	// MqttUser is the user name for the MQTT broker.
	MqttUser string `json:"mqtt_user"`
	// MqttPassword is the password for the MQTT broker.
	MqttPassword string `json:"mqtt_password"`
	// CertCache path to autocert cache location.
	CertCache string `json:"cert_cache"`
}

Config describes the structure of parameters for ttrn.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a new instance of the Config struct with default values.

func OpenConfig

func OpenConfig(path string) Config

OpenConfig loads the configuration from a JSON file and returns the result.

func (Config) SaveConfig

func (c Config) SaveConfig(path string)

SaveConfig writes a configuration to the given path as a JSON.

type FrontendState

type FrontendState struct {
	Train1Speed      int `json:"train_1_speed"`
	Train2Speed      int `json:"train_2_speed"`
	Turnout0Position int `json:"turnout_0_position"`
	Turnout1Position int `json:"turnout_1_position"`
	Turnout2Position int `json:"turnout_2_position"`
	Turnout3Position int `json:"turnout_3_position"`
	Turnout4Position int `json:"turnout_4_position"`
}

FrontendState represents the state for the frontend.

func FromState

func FromState(s State) FrontendState

FromState returns a FrontendState instance from a State instance.

type Mqtt

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

Mqtt bundles the MQTT related stuff.

func NewMqtt

func NewMqtt(cfg Config, turnoutPositionEvents chan TurnoutPositionEvent, trainSpeedEvents chan TrainSpeedEvent, trainPositionEvents chan TrainPositionEvent) Mqtt

NewMqtt returns a new Mqtt instance.

func (Mqtt) Run

func (m Mqtt) Run()

Run connects to the MQTT broker.

type State

type State struct {
	TrainSpeeds      [2]int
	TurnoutPositions [5]int
}

State represents the current state of the application.

func DefaultState

func DefaultState() State

DefaultState returns the initial state.

func (*State) ChangeTrainSpeed

func (s *State) ChangeTrainSpeed(id int, delta int) (int, error)

ChangeTrainSpeed changes the speed of a train by a given delta and returns the new speed value.

func (*State) SwitchTurnout

func (s *State) SwitchTurnout(id int) (int, error)

SwitchTurnout switches the turnout to the other position and returns the new state.

type TemplateRenderer

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

TemplateRenderer implements the Echo renderer interface.

func (TemplateRenderer) Render

func (t TemplateRenderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error

Implement the Echo renderer interface.

type TrainPositionEvent

type TrainPositionEvent struct {
	// Id of the train.
	Id int
	// NewSpeed is the new speed of the train ranging from 0 to 2.
	NewPosition int
}

TrainPositionEvent is a event on the position change of a train.

type TrainSpeedEvent

type TrainSpeedEvent struct {
	// Id of the train.
	Id int
	// NewSpeed is the new speed of the train ranging from -4 to 4.
	NewSpeed int
}

TrainSpeedEvent is a event on the speed change of a train.

type TurnoutPositionEvent

type TurnoutPositionEvent struct {
	// Id of the turnout.
	Id int
	// NewPosition is the new position of the turnout. O = straight, 1 = diverging.
	NewPosition int
}

TurnoutPositionEvent is a event on the position change of a turnaout.

type User

type User struct {
	gorm.Model
	Session      string
	Name         string
	IsAdmin      bool
	IsBanned     bool
	DrivedBefore int
}

User is a User of the system.

type Web

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

Web handles the web view stuff.

func NewWeb

func NewWeb(cfg Config, doDebug bool, turnoutPositionEvents chan TurnoutPositionEvent, trainSpeedEvents chan TrainSpeedEvent, trainPositionEvents chan TrainPositionEvent) Web

NewWeb returns a new instance of the Web struct. When debug parameter is true, debugging is enabled.

func (*Web) Run

func (w *Web) Run()

Run runs the web server.

Jump to

Keyboard shortcuts

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