Documentation
¶
Overview ¶
Package dcc implements the DCC protocol for controlling model trains. It can support a number of different encoders, which are in charge of translating DCC packages into electrical signals. By default, a Raspberry Pi driver is provided.
The implementation follows the S-91 Electrical Standard (http://www.nmra.org/sites/default/files/standards/sandrp/pdf/s-9.1_electrical_standards_2006.pdf), the S-92 DCC Communications Standard (http://www.nmra.org/sites/default/files/s-92-2004-07.pdf) and the S-9.2.1 Extended Packet Formats for Digital Command Control standard (http://www.nmra.org/sites/default/files/s-9.2.1_2012_07.pdf).
Index ¶
- Constants
- Variables
- type Config
- type Controller
- type Direction
- type Driver
- type Locomotive
- type Packet
- func NewBaselinePacket(d Driver, addr byte, data []byte) *Packet
- func NewBroadcastIdlePacket(d Driver) *Packet
- func NewBroadcastResetPacket(d Driver) *Packet
- func NewBroadcastStopPacket(d Driver, dir Direction, softStop bool, ignoreDir bool) *Packet
- func NewFunctionGroupOnePacket(d Driver, addr byte, fl, fl1, fl2, fl3, fl4 bool) *Packet
- func NewPacket(d Driver, addr byte, data []byte) *Packet
- func NewSpeedAndDirectionPacket(d Driver, addr byte, speed byte, dir Direction) *Packet
Constants ¶
const ( BitOnePartMinDuration = 55 * time.Microsecond BitOnePartMaxDuration = 61 * time.Microsecond BitZeroPartMinDuration = 95 * time.Microsecond BitZeroPartMaxDuration = 9900 * time.Microsecond PacketSeparationMin = 5 * time.Millisecond PacketSeparationMax = 30 * time.Millisecond PreambleBitsMin = 14 )
DCC protocol-defined values for reference.
Variables ¶
var ( BitOnePartDuration = 55 * time.Microsecond BitZeroPartDuration = 100 * time.Microsecond PacketSeparation = 15 * time.Millisecond PreambleBits = 16 )
Some customizable DCC-related variables.
var CommandMaxQueue = 3
CommandMaxQueue specifies how many commands can queue before sending a new command blocks the sender
var CommandRepeat = 30
CommandRepeat specifies how many times a single packet is sent.
var HeadlightCompatMode = false
HeadlightCompatMode controls if one bit in the speed instruction is reserved for headlight. This reduces speed steps from 32 to 16 steps.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Locomotives []*Locomotive `json:"locomotives"`
}
Config allows to store configuration settings to initialize go-dcc.
func LoadConfig ¶
LoadConfig parses a configuration file and returns a Config object.
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller represents a DCC Control Station. The controller keeps tracks of the DCC Locomotives and is in charge of sending DCC packets continuously to the tracks.
func NewControllerWithConfig ¶
func NewControllerWithConfig(d Driver, cfg *Config) *Controller
NewControllerWithConfig builds a new Controller using the given configuration.
func (*Controller) AddLoco ¶
func (c *Controller) AddLoco(l *Locomotive)
AddLoco adds a DCC device to the controller. The device will start receiving packets if the controller is running.
func (*Controller) Command ¶
func (c *Controller) Command(p *Packet)
Command allows to send a custom Packet to the tracks. The packet will be sent CommandRepeat times.
func (*Controller) GetLoco ¶
func (c *Controller) GetLoco(n string) (*Locomotive, bool)
GetLoco retrieves a DCC device by its Name. The boolean is true if the Locomotive was found.
func (*Controller) Locos ¶
func (c *Controller) Locos() []*Locomotive
Locos returns a list of all registered Locomotives.
func (*Controller) RmLoco ¶
func (c *Controller) RmLoco(l *Locomotive)
RmLoco removes a DCC device from the controller. There will be no longer packets sent to it.
func (*Controller) Start ¶
func (c *Controller) Start()
Start starts the controller: powers on the tracks and starts sending packets on them.
func (*Controller) Stop ¶
func (c *Controller) Stop()
Stop shuts down the controller by stopping to send packets and removing power from the tracks.
type Direction ¶
type Direction byte
Direction represents the locomotive direction and can be Forward or Backward.
type Driver ¶
type Driver interface { // Low sets the output to low state. Low() // High sets the output to high. High() // TracksOn turns the tracks on. The exact procedure is left to the // implementation, but tracks should be ready to receive packets from // this point. TracksOn() // TracksOff disables the tracks. The exact procedure is left to the // implementation, but tracks should not carry any power and all // trains should stop after calling it. TracksOff() }
Driver can be implemented by any module to allow using go-dcc on different platforms. dcc.Driver modules are in charge of producing an electrical signal output (i.e. on a GPIO Pin)
type Locomotive ¶
type Locomotive struct { Name string `json:"name"` Address uint8 `json:"address"` Speed uint8 `json:"speed"` Direction Direction `json:"direction"` Fl bool `json:"fl"` F1 bool `json:"f1"` F2 bool `json:"f2"` F3 bool `json:"f3"` F4 bool `json:"f4"` // contains filtered or unexported fields }
Locomotive represents a DCC device, usually a locomotive. Locomotives are represented by their name and address and include certain properties like speed, direction or FL. Each locomotive produces two packets: one speed and direction packet and one Function Group One packet.
func (*Locomotive) Apply ¶
func (l *Locomotive) Apply()
Apply makes any changes to the Locomotive's properties to be reflected in the packets generated for it and, therefore, alter the behaviour of the device on the tracks.
func (*Locomotive) String ¶
func (l *Locomotive) String() string
type Packet ¶
type Packet struct {
// contains filtered or unexported fields
}
Packet represents the unit of information that can be sent to the DCC devices in the system. Packet implements the DCC protocol for converting the information into DCC-encoded 1 and 0s.
func NewBaselinePacket ¶
NewBaselinePacket returns a new generic baseline packet. Baseline packets are different because they use a 128 address space. Therefore the address is forced to start with bit 0.
func NewBroadcastIdlePacket ¶
NewBroadcastIdlePacket returns a new broadcast baseline DCC packet on which decoders perform no action.
func NewBroadcastResetPacket ¶
NewBroadcastResetPacket returns a new broadcast baseline DCC packet which makes the decoders erase their volatile memory and return to power up state. This stops all locomotives at non-zero speed.
func NewBroadcastStopPacket ¶
NewBroadcastStopPacket returns a new broadcast baseline DCC packet which tells the decoders to stop all locomotives. If softStop is false, an emergency stop will happen by cutting power off the engine.
func NewFunctionGroupOnePacket ¶
NewFunctionGroupOnePacket returns an advanced DCC packet which allows to control FL,F1-F4 functions. FL is usually associated to the headlights.
func NewSpeedAndDirectionPacket ¶
NewSpeedAndDirectionPacket returns a new baseline DCC packet with speed and direction information.
func (*Packet) PacketPause ¶
func (p *Packet) PacketPause()
PacketPause performs a pause by sleeping during the PacketSeparation time.