Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
OpenConfig loads the configuration from a JSON file and returns the result.
func (Config) SaveConfig ¶
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.
type State ¶
State represents the current state of the application.
func (*State) ChangeTrainSpeed ¶
ChangeTrainSpeed changes the speed of a train by a given delta and returns the new speed value.
type TemplateRenderer ¶
type TemplateRenderer struct {
// contains filtered or unexported fields
}
TemplateRenderer implements 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.