diff --git a/tools/re-server.py b/tools/re-server.py new file mode 100644 index 0000000..ec21fc6 --- /dev/null +++ b/tools/re-server.py @@ -0,0 +1,42 @@ +""" +Simple socket server used to reverse engineer the messaging protocol the bundled software uses to send data to the +LED sign. + +The server just dumps incoming messages in a hexdump-like format as well as an easy to read Python bytestring. +""" + + +import asyncio +import string + + +async def handle_client(reader, writer): + message = await reader.read(255) + + hex_chars = [hex(j)[2:].zfill(2) for j in message] + + ascii_chars = [] + for j in message: + char = chr(j) + if char in (string.ascii_letters + string.digits + string.punctuation): + ascii_chars.append(char) + else: + ascii_chars.append(".") + + print("Message received: ", end="") + print(" ".join(hex_chars), end=" | ") + print("".join(ascii_chars), end=" | ") + print("".join(repr(message))) + + writer.close() + + +async def run_server(): + server = await asyncio.start_server(handle_client, '', 3000) + async with server: + await server.serve_forever() + + +if __name__ == "__main__": + asyncio.run(run_server()) +