Skip to content

Commit 55a2c38

Browse files
committed
Add built in t42 file playback mode
1 parent dc03f04 commit 55a2c38

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ Teletext TCP Packet Server
22
--------------------------
33

44
packet-server.py takes a teletext packet stream and serves it to multiple clients.
5-
The script attempts to consume <lines per field> 42 byte packets from stdin every 20ms
5+
The script attempts to consume <lines per field> 42 byte packets from stdin every 20ms unless an input filename is specified with `-i`
66

77
test.py is a test client which connects to the server and outputs packets to stdout
88

9-
The port is set using the -p argument, and the number of lines per field by -l
9+
The port is set using the `-p` argument, and the number of lines per field by `-l`
1010

11-
The server can be tested using example.t42:
12-
`(while cat example.t42; do :; done) | python3 packet-server.py -p 19761 -l 16`
11+
The server can be tested using example.t42:
12+
`python3 packet-server.py -p 19761 -l 16 -i example.t42`
1313

1414
A suitable packet stream can be generated using https://github.com/peterkvt80/vbit2
15-
For example: `~/vbit2/vbit2 --dir ~/teletext | python3 packet-server.py -p 19761 -l 16`
15+
For example: `vbit2 --dir ~/teletext | python3 packet-server.py -p 19761 -l 16`

packet-server.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ def server6(PORT):
5454
if __name__ == "__main__":
5555
PORT = 0
5656
linesPerField = 0
57+
inputfile = sys.stdin
5758

5859
try:
59-
opts, args = getopt.getopt(sys.argv[1:],"p:l:")
60+
opts, args = getopt.getopt(sys.argv[1:],"p:l:i:")
6061
except getopt.GetoptError as err:
6162
print(err)
6263
sys.exit(2)
@@ -74,6 +75,12 @@ def server6(PORT):
7475
except:
7576
print("invalid lines per field")
7677
sys.exit(2)
78+
elif opt in ('-i'):
79+
try:
80+
inputfile = open(arg, "r")
81+
except:
82+
print("failed to open file")
83+
sys.exit(2)
7784

7885
if PORT <= 1024 or PORT > 65535:
7986
print("invalid port, use -p <port>")
@@ -94,7 +101,9 @@ def server6(PORT):
94101
starttime=time.time()
95102

96103
while(True):
97-
data = bytearray(sys.stdin.buffer.read(42 * linesPerField))
104+
data = bytearray(inputfile.buffer.read(42 * linesPerField))
105+
if not data:
106+
inputfile.seek(0) # loop input file
98107
if (linesPerField < 16):
99108
data.extend(bytearray(42*(16-linesPerField)))
100109
for q in clientQueues[:]:

0 commit comments

Comments
 (0)