Skip to content

Commit

Permalink
Add built in t42 file playback mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ZXGuesser committed Dec 5, 2023
1 parent dc03f04 commit 55a2c38
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ Teletext TCP Packet Server
--------------------------

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

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

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

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

A suitable packet stream can be generated using https://github.com/peterkvt80/vbit2
For example: `~/vbit2/vbit2 --dir ~/teletext | python3 packet-server.py -p 19761 -l 16`
For example: `vbit2 --dir ~/teletext | python3 packet-server.py -p 19761 -l 16`
13 changes: 11 additions & 2 deletions packet-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ def server6(PORT):
if __name__ == "__main__":
PORT = 0
linesPerField = 0
inputfile = sys.stdin

try:
opts, args = getopt.getopt(sys.argv[1:],"p:l:")
opts, args = getopt.getopt(sys.argv[1:],"p:l:i:")
except getopt.GetoptError as err:
print(err)
sys.exit(2)
Expand All @@ -74,6 +75,12 @@ def server6(PORT):
except:
print("invalid lines per field")
sys.exit(2)
elif opt in ('-i'):
try:
inputfile = open(arg, "r")
except:
print("failed to open file")
sys.exit(2)

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

while(True):
data = bytearray(sys.stdin.buffer.read(42 * linesPerField))
data = bytearray(inputfile.buffer.read(42 * linesPerField))
if not data:
inputfile.seek(0) # loop input file
if (linesPerField < 16):
data.extend(bytearray(42*(16-linesPerField)))
for q in clientQueues[:]:
Expand Down

0 comments on commit 55a2c38

Please sign in to comment.