Welcome to TrainThing’s documentation!

Todo

This is just the beginning

TT_4 main

This is the software for the LapTop, part 4 of the TrainThing

This top level module provides a menu of program options to display and implement passing commands and responses to/from module client for RPi and Arduino Base Station.

main.VERBOSE = True

Generates additional print lines to help troubleshooting

main.main()

Uses module Client to open an internet connection to TrainThing. provide menu of options Passes Commands/responses between options and Client. If nothing else happens send wakeup status command every 30 seconds

Module client

This module provides: A socket client for the internet (WiFi LAN) connection to the Raspberry Pi (3), running TrainThing software, and on to the Arduino (2), running the DCC++ Base Station. All DCC++ and TrainThing commands strings passed to this module are sent to the Raspberry Pi. All received status messages are converted from bytes to strings bounded by “<” and “>”.

class client.Client

Establish internet client (WiFi LAN) connection with Raspberry Pi server

FORMAT

encoding format

__init__() None

Initialize link to Raspberry Pi. Start thread to receive responses

Constants:

_receive() None

Thread to receive responses from RPi/Arduino

get_response() str
send(msg: str) None

Send command to Raspberry Pi/Arduino

Module dumb

Opens a window to enter a command to send to TrainThing. No editing or validity checking.

Module smart

Replacement for module “dumb” . Open a window to enter DCC++ and TrainThing commands to be sent to the Raspberry Pi and Arduino. Bracketing “<” and “>” are provided. Command syntax and value validity are checked.

Module dump

Opens a window to display traffic between the laptop and TrainThing.

Module Pile

Replacement for module “dump”. Opens a window to display traffic between the laptop and TrainThing with decoding of each command/response.

Module printit

Provides a menu of data elements/tables to print in a ‘pretty’ format.

Module Signals

This module contains all aspects and methods related to TrainThing semaphore signals, establishing signal aspect and sending commands to RPi to change signals.

The aspect of each signal depends on the state of turnouts and track

class HW.signals.Signals

Signal aspects and methods

Constance:

B_CLEAR = 0
T_CLEAR = 1
T_THROWN = 2
T_UNKN = 0
X_CLEAR = 0
X_EVEN = 2
X_ODD = 1
__init__() None

Use db to load saved configuration

_change_aspect(part: chr, value: int) tuple
Parameters
  • part (chr) – ‘T’urnout, ‘B’lock, ‘T’urnout, ‘X’ing that changed

  • value (int) – Which element of tbx changed

Returns

a tuple of tuples. Each tuple is (pole, top, aspect)

signal_com(com: str) str

Process DCC++ added commands A|G|K|N|n Validates command and parameters saves results waits for RPi response G|K|n|U ~~ NOT V add saved data.

valid commands use _update_signal() to send A|G|K|N|n commands to RPi

track_change(track: int, new_state: int) None

module track sends changed status of a block of track

turnout_change(turnout: int, new_state: int) None

module turnout sends change in turnout status

xing_change(new_state: int) None

Module Xing sends change in the crossing status

Module Track

This module contains all aspects and methods related to TrainThing railroad track status

Constant:

HW.track.B_CLEAR = 0

The BLOCK of track is not occupied. 1-5 occupied at location

HW.track.B_PARK = 6

The BLOCK of track is coded for the Parking Lot.

class HW.track.Track

Track aspects and methods

all_track() dir

When requested (by signals) return pairs of all blocks # and current state

get_track(block: int) int
Return int

status of block of track.

Module Xing

This module contains all aspects and methods related to TrainThing Crossing status

Constants:

HW.xing.X_CLEAR = 0

Crossing is not in use

HW.xing.X_EVEN = 2

Crossing in use top-right/bottom-left

HW.xing.X_ODD = 1

Crossing in use top-left/bottom-right

class HW.xing.Xing

Xing aspects and methods

clear_xing(train: int) bool

if train is the train using the crossing, release crossing and clear stored train

Return bool

True if xing cleared

get_xing() int

When requested (by signals) return current status of the Crossing

set_xing(train: int, state: int) bool

If crossing is available, commit crossing in state to train

Return bool

True of assigned, False if in use

Module Turnouts

This module contains all aspects and methods related to TrainThing railroad turnout status

Constance:

HW.turnouts.T_CLEAR = 1

Turnout in CLEAR state

HW.turnouts.T_THROWN = 2

Turnout in THROWN state

HW.turnouts.T_UNKN = 0

Turnout in unknown state

class HW.turnouts.Turnouts

Turnout aspects and methods based on the state of two sensors.

all_turnout() dir

When requested (by signals) return pairs of all turnout # and current state

get_turnout(name: int) int
Return int

status of named turnout

turnout_command() None

Process DCC++ commands T|E|e etc, Validates command and parameters saves results waits for Arduino response add saved data.

valid commands use _update_turnout() to send TEe commands onto Arduino

Indices and tables