traffic
|
index /media/pi/PI4_TT/TT3/traffic.py
|
This module provides:
A socket server for the WiFi connection to the Laptop running
JMRI DCC++ software
A serial link to the Arduino running the DCC++ Base Station
and blinks the 4 LEDs representing traffic to and from each.
By default the serial link is
EIGHTBITS = 8, PARITY_NONE = N, STOPBITS_ONE = 1
Modules
|
|
|
serial
|
socket
|
sys
|
threading
|
|
Classes
|
|
|
Monitor
Traffic
class Monitor
|
|
This class is used to blink each of the 4 traffic monitoring LEDs in relationship to the traffic Out from the laptop (Orange) and Back to the laptop (Blue). Output to the Base Station (Orange) and Back from the Base Station (Blue). Should be called only be Traffic
|
|
Methods defined here:
__init__(self)
Set up the IOPi HAT+ pins for traffic monitoring LEDs IOPi HAT Bus 2 using pins 9 - 12
blink_it(self, LED, num)
Common routine to blink a LED number of blinks = 1 + num // DIV (initager divide) Arg: LED - a variable equal to the output pin on bus2 num - number of bytes in the message i.e. len(message)
from_BS(self, num)
Creates a thread to Blink the BLUE LED for traffic from the Base Station Arg: length of message received from the Base Station
from_LT(self, num)
Creates a thread to Blink the ORANGE LED for traffic from the Laptop Arg: length of the message received i.e. len(message)
to_BS(self, num)
Creates a thread to Blink the ORANGE LED for traffic to the Base Station Arg: length of message sent to the Base Station
to_LT(self, num)
Creates a thread to Blink the BLUE LED for traffic to the Laptop Arg: length of message sent to the laptop
Data and other attributes defined here:
DIV = 30
|
class Traffic
|
|
This class handles all TrainThing communication wirelessly to/from the Laptop and wired to/from the Arduino. read_LT() returns commands from the Laptop NOT intended for the Arduino Base Station. Calls to write_LT() are used to return status from the Raspberry Pi to the Laptop.
|
|
Methods defined here:
__init__(self)
Defines and starts the WiFi socket to the Laptop and establishes a connection. Defines a serial link through a USB port to the Arduino Base Station.
read_BS(self)
Reads a string from the Arduino and passes it to write_LT()
read_LT(self)
Reads a string from the laptop ending with ">" If the command is intended for the Arduino it is passed directly to write_BS() and a "" is returned If the command is intended for the Raspberry Pi only it is returned If the command is intended for both passed to write_BS() and returned.
stop_servers(self)
write_BS(self, message)
Writes to the Arduino the string passed as a parameter from read_LT() then calls read_BS() and waits for a reply. Arg: string to be sent
write_LT(self, message)
Writes to the Laptop the string passed as a parameter. Arg: string to be sent
Data and other attributes defined here:
BAUDRATE = 115200
DEVICE_NAME = '/dev/ttyACM0'
FORMAT = 'utf-8'
PORT = 2560
SERVER_IP = '192.168.1.128'
clientsocket = None
ser = None
|
|
Functions
|
|
|
sleep(...)
sleep(seconds) Delay execution for a given number of seconds. The argument may be a floating point number for subsecond precision.
|