commit 45ac4648dd8bc822c7b108210f78bd422f92c185 Author: Ishan S. Patel Date: Wed Apr 24 13:28:38 2024 -0400 YACWC diff --git a/__pycache__/uart_monitor_config.cpython-311.pyc b/__pycache__/uart_monitor_config.cpython-311.pyc new file mode 100644 index 0000000..94fbb00 Binary files /dev/null and b/__pycache__/uart_monitor_config.cpython-311.pyc differ diff --git a/crap b/crap new file mode 100644 index 0000000..d4902b0 --- /dev/null +++ b/crap @@ -0,0 +1,740 @@ +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +4800 [224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +4800 [96] +9600 [0, 120] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +9600 [0] +19200 [0] +2400 [140] +4800 [224] +9600 [0] +19200 [0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +4800 [96] +9600 [0, 120] +19200 [0, 128] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +9600 [0] +19200 [0] +4800 [254] +9600 [248] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +4800 [152, 158] +9600 [128, 248, 120] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +9600 [0] +19200 [0] +4800 [248] +9600 [128] +19200 [0] +4800 [224] +9600 [0, 0] +19200 [0, 0] +4800 [152, 158] +9600 [128, 248] +19200 [0, 128, 128] +9600 [248] +19200 [128] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +9600 [0] +19200 [0] +2400 [140] +4800 [224] +9600 [0] +19200 [0] +4800 [152, 158] +9600 [128, 248, 120] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +4800 [128] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +4800 [152] +9600 [128, 248] +19200 [0, 128] +4800 [230] +9600 [120, 248] +19200 [128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [128] +19200 [0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158] +9600 [128, 248, 120] +19200 [0, 128, 128, 128] +19200 [0] +2400 [20] +4800 [96, 6] +9600 [120, 0] +19200 [128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +4800 [96] +9600 [0, 120] +19200 [0, 128] +9600 [0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +4800 [152, 158] +9600 [128, 248, 120] +19200 [0, 128, 128] +9600 [248] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +4800 [96] +9600 [0] +19200 [0] +4800 [6] +9600 [0] +19200 [0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +9600 [0] +19200 [0] +4800 [6] +9600 [120, 0] +19200 [128, 0] +9600 [0] +19200 [0] +2400 [200] +4800 [248] +9600 [128] +19200 [0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [128] +19200 [0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +4800 [152] +9600 [128, 248] +19200 [0, 128, 128] +4800 [230] +9600 [248] +19200 [128] +4800 [96] +9600 [0, 120] +19200 [0, 128] +9600 [0] +19200 [0] +2400 [200] +4800 [128, 248] +9600 [128] +19200 [0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +4800 [128] +9600 [0, 128] +19200 [0, 0] +4800 [224] +9600 [0, 0] +19200 [0, 0] +4800 [152, 158] +9600 [128, 248, 120] +19200 [0, 128, 128] +4800 [96, 6] +9600 [248, 0, 120, 0] +19200 [0, 128, 0] +19200 [0] +2400 [200] +4800 [128, 248] +9600 [128] +19200 [0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +9600 [0] +19200 [0] +2400 [140] +4800 [224] +9600 [0] +19200 [0] +19200 [0] +2400 [90] +4800 [152, 158, 230] +9600 [248, 120, 248] +19200 [128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +4800 [224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +4800 [128] +9600 [0, 128] +19200 [0, 0] +4800 [224] +9600 [0, 0] +19200 [0, 0] +4800 [152, 158] +9600 [128, 248, 120] +19200 [0, 128, 128] +9600 [248] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +9600 [0] +19200 [0] +2400 [200] +4800 [248] +9600 [128] +19200 [0] +4800 [224] +9600 [0] +19200 [0] +4800 [224] +9600 [0] +19200 [0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +4800 [96] +9600 [0] +19200 [0, 128] +4800 [6] +9600 [0] +19200 [0] +19200 [0] +2400 [200] +4800 [248] +9600 [128] +19200 [0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +4800 [96] +9600 [0] +19200 [0, 128] +4800 [6] +9600 [0] +19200 [0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0] +9600 [0] +19200 [0] +2400 [140] +4800 [224] +9600 [0] +19200 [0] +9600 [128] +19200 [0] +2400 [90] +4800 [158, 230] +9600 [248, 120, 248] +19200 [128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +9600 [0] +19200 [0] +4800 [224] +9600 [0] +19200 [0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +4800 [96] +9600 [0] +19200 [0] +4800 [6] +9600 [0] +19200 [0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +9600 [0] +19200 [0] +2400 [140] +4800 [224] +9600 [0] +19200 [0] +4800 [152, 158] +9600 [128, 248, 120] +19200 [0, 128, 128] +9600 [248] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +4800 [224] +9600 [0, 0] +19200 [0, 0] +9600 [128] +19200 [0, 128] +4800 [158, 230] +9600 [120, 248] +19200 [128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +19200 [0] +2400 [140] +4800 [224, 224] +9600 [0] +19200 [0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +19200 [0] +2400 [20] +4800 [96, 6] +9600 [120, 0] +19200 [128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +4800 [128] +9600 [0] +19200 [0] +4800 [248] +9600 [128] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +4800 [152, 158] +9600 [128, 248, 120] +19200 [0, 128, 128] +9600 [248] +19200 [0] +2400 [20] +4800 [6] +9600 [120, 0] +19200 [128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0] +19200 [0] +4800 [152, 158] +9600 [128, 248, 120] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +4800 [128] +9600 [0] +19200 [0, 0] +4800 [248] +4800 [224] +9600 [0, 0] +19200 [0, 0] +2400 [90] +4800 [152, 158, 230] +9600 [128, 248, 120, 248] +19200 [0, 128, 128, 128] +2400 [20] +4800 [96, 6] +9600 [0, 120, 0] +19200 [0, 128, 0] +2400 [200] +4800 [128, 248] +9600 [0, 128] +19200 [0, 0] +2400 [140] +4800 [224, 224] +9600 [0, 0] +19200 [0, 0] +4800 [152] +9600 [128, 248] +19200 [0, 128] +4800 [230] +9600 [120, 248] +19200 [128, 0] +2400 [20] +4800 [6] +9600 [120, 0] +19200 [128, 0] diff --git a/old/af_client.py b/old/af_client.py new file mode 100644 index 0000000..ea8601f --- /dev/null +++ b/old/af_client.py @@ -0,0 +1,20 @@ +import socket +import os + +# Client socket file +client_socket_file = '/tmp/server_socket_use2' + +# Create a UDP socket +client_socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) + +# Bind the socket to the file +client_socket.connect(client_socket_file) + +while True: + # Receive data from the server + data, _ = client_socket.recvfrom(1024) + print("Received from server:", data.decode()) + +# Close the socket +client_socket.close() + diff --git a/old/af_server.py b/old/af_server.py new file mode 100644 index 0000000..47a5a64 --- /dev/null +++ b/old/af_server.py @@ -0,0 +1,21 @@ +import socket +import os + +# Server socket file +server_socket_file = '/tmp/server_socket_use2' + +# Create a UDP socket +server_socket = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) + +# Bind the socket to the file +server_socket.bind(server_socket_file) + +while True: + # Send a message to the client + message = b"Hello, client!" + server_socket.sendto(message, server_socket_file) + +# Close the socket +server_socket.close() + + diff --git a/old/bins.png b/old/bins.png new file mode 100644 index 0000000..4f6caca Binary files /dev/null and b/old/bins.png differ diff --git a/old/bins2.png b/old/bins2.png new file mode 100644 index 0000000..4f6caca Binary files /dev/null and b/old/bins2.png differ diff --git a/old/bins2O.png b/old/bins2O.png new file mode 100644 index 0000000..d2df955 Binary files /dev/null and b/old/bins2O.png differ diff --git a/old/bins2OS[O.png b/old/bins2OS[O.png new file mode 100644 index 0000000..f8efeca Binary files /dev/null and b/old/bins2OS[O.png differ diff --git a/old/crap.png b/old/crap.png new file mode 100644 index 0000000..8f6d50e Binary files /dev/null and b/old/crap.png differ diff --git a/old/crap2.png b/old/crap2.png new file mode 100644 index 0000000..03d60db Binary files /dev/null and b/old/crap2.png differ diff --git a/old/crap5.png b/old/crap5.png new file mode 100644 index 0000000..c8eccee Binary files /dev/null and b/old/crap5.png differ diff --git a/old/crap6.png b/old/crap6.png new file mode 100644 index 0000000..04e4a5c Binary files /dev/null and b/old/crap6.png differ diff --git a/old/serial_monitor.py b/old/serial_monitor.py new file mode 100644 index 0000000..bffe5c5 --- /dev/null +++ b/old/serial_monitor.py @@ -0,0 +1,40 @@ + + + +#baud_rates_test = (2400, 4800, 9600, 19200, 28800, 38400, 56000, 57600, 115200, 128000, 153600, 230400, 256000) +baud_rates_test = [57600] + + +cmd_line = '/home/thebears/sr/bin/sigrok-cli --config samplerate=12M --driver=fx2lafw --continuous' +cmd_start = cmd_line +#'-P uart:baudrate=57600:tx=D0 -P uart:baudrate=9600:tx=D0 -A uart=tx-data:tx-warning' +cmd_split = cmd_line.split() +for x in baud_rates_test: + cmd_split.append('-P') + cmd_split.append(f'uart:baudrate={str(x)}:tx=D0') + +cmd_split.append('-A') +cmd_split.append('uart=tx-data:tx-warning') + + +import io +import time +import subprocess +import sys + +command_to_run = cmd_split +#command_to_run = ['/bin/bash','/home/thebears/Source/serial_monitor_variable/run_me.sh'] +process = subprocess.Popen(command_to_run,stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) + +idx = 0 +while True: + stuff = process.stdout.readline() + if len(stuff) == 0: + break + print(idx,stuff) + idx+=1 + + + + + diff --git a/old/socket_server.py b/old/socket_server.py new file mode 100644 index 0000000..c5508f2 --- /dev/null +++ b/old/socket_server.py @@ -0,0 +1,51 @@ +import socket +import os + +# Set the path for the Unix socket +socket_path = '/tmp/my_socket' + +# remove the socket file if it already exists +try: + os.unlink(socket_path) +except OSError: + if os.path.exists(socket_path): + raise + +# Create the Unix socket server +server = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) + +# Bind the socket to the path +server.bind(socket_path) +import time +from datetime import datetime +while True: + time.sleep(0.25) + print("Sending") + server.sendto(("Hello "+str(datetime.now())).encode(), socket_path) + + +# Listen for incoming connections +server.listen(1) + +# accept connections +print('Server is listening for incoming connections...') +connection, client_address = server.accept() + +try: + print('Connection from', str(connection).split(", ")[0][-4:]) + + # receive data from the client + while True: + data = connection.recv(1024) + if not data: + break + print('Received data:', data.decode()) + + # Send a response back to the client + response = 'Hello from the server!' + connection.sendall(response.encode()) +finally: + # close the connection + connection.close() + # remove the socket file + os.unlink(socket_path) diff --git a/old/sovket_client.py b/old/sovket_client.py new file mode 100644 index 0000000..aa5cb2f --- /dev/null +++ b/old/sovket_client.py @@ -0,0 +1,15 @@ +import socket + + +socket_path = '/tmp/my_socket' + + +# Create the Unix socket server +client = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) + + +client.bind(socket_path) +client.send("hello".encode()) +while True: + data, addr = client.recvfrom(1024) + print(data) diff --git a/old/udp_server.py b/old/udp_server.py new file mode 100644 index 0000000..07f89e3 --- /dev/null +++ b/old/udp_server.py @@ -0,0 +1,22 @@ + +import socket + +MCAST_GRP = '239.255.255.255' +MCAST_PORT = 5007 +# regarding socket.IP_MULTICAST_TTL +# --------------------------------- +# for all packets sent, after two hops on the network the packet will not +# be re-sent/broadcast (see https://www.tldp.org/HOWTO/Multicast-HOWTO-6.html) +MULTICAST_TTL = 2 + +sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) +sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, MULTICAST_TTL) + +# For Python 3, change next line to 'sock.sendto(b"robot", ...' to avoid the +# "bytes-like object is required" msg (https://stackoverflow.com/a/42612820) + +from datetime import datetime +import time +for i in range(100): + dsend = str(i)+' '+str(datetime.now()) + sock.sendto(dsend.encode(), (MCAST_GRP, MCAST_PORT)) diff --git a/receive_data.py b/receive_data.py new file mode 100644 index 0000000..76180cb --- /dev/null +++ b/receive_data.py @@ -0,0 +1,15 @@ +import socket +import struct +import uart_monitor_config as c + + + +sockets = dict() +for baud_rate, MCAST_PORT in c.baud_rate_map.items(): + sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) + sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + sock.bind(('', MCAST_PORT)) + + mreq = struct.pack("4sl", socket.inet_aton(c.udp_grp), socket.INADDR_ANY) + sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) + sockets[baud_rate] = sock diff --git a/run_me.sh b/run_me.sh new file mode 100755 index 0000000..14df5be --- /dev/null +++ b/run_me.sh @@ -0,0 +1,6 @@ + +while true +do + date + done + diff --git a/run_scli.sh b/run_scli.sh new file mode 100755 index 0000000..616905d --- /dev/null +++ b/run_scli.sh @@ -0,0 +1,5 @@ +#!/bin/bash +/home/thebears/sr/bin/sigrok-cli --config samplerate=2M --driver=fx2lafw --continuous -P uart\ +:baudrate=9600:tx=D0 -P uart:baudrate=57600:tx=D0 -P uart:baudrate=115200:tx=D0 -A uart=tx-data:tx-warn\ +ing + diff --git a/run_serial_monitor.py b/run_serial_monitor.py new file mode 100644 index 0000000..4642da0 --- /dev/null +++ b/run_serial_monitor.py @@ -0,0 +1,55 @@ +import sigrok.core as sr +import numpy as np +import socket +import uart_monitor_config as c + + +MCAST_GRP = c.udp_grp +MCAST_PORT = c.udp_raw_port +MULTICAST_TTL = c.MULTICAST_TTL + + +driver='fx2lafw' + +context = sr.Context.create() +devices = context.drivers[driver].scan() +device = devices[0] +device.open() + + +session = context.create_session() +session.add_device(device) + +output_format = 'bits' +output = context.output_formats[output_format].create_output(device) +sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) +sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, MULTICAST_TTL) + + + + + +def data_callback(device, packet): + if packet.type != sr.PacketType.LOGIC: + return + + text = output.receive(packet) + data = packet._payload_logic().data + sock.sendto(data, (MCAST_GRP,MCAST_PORT)) + + + +device.config_set(sr.ConfigKey.SAMPLERATE,c.samplerate) +session.start() + +session.add_datafeed_callback(data_callback) + + + +#~/sr/bin/sigrok-cli --config samplerate=500000 --driver=fx2lafw --samples 1M -P uart:baudrate=57600:tx=D0 -P uart:baudrate=9600:tx=D0 -A uart=tx-data:tx-warning + +session.run() +session.stop() + + + diff --git a/run_udp_test.py b/run_udp_test.py new file mode 100644 index 0000000..eb0428e --- /dev/null +++ b/run_udp_test.py @@ -0,0 +1,83 @@ +import sigrok.core as sr +import numpy as np +import ripyl +import ripyl.protocol.uart as uart +import socket + +MCAST_GRP = '239.255.255.255' +MCAST_PORT = 5007 +MULTICAST_TTL = 2 + +socket_path = '/tmp/logic_stream' + + + +driver='fx2lafw' + +context = sr.Context.create() +devices = context.drivers[driver].scan() +device = devices[0] +device.open() + + +session = context.create_session() +session.add_device(device) + +output_format = 'bits' +output = context.output_formats[output_format].create_output(device) +#baud_rates_test = (2400, 4800, 9600, 19200, 28800, 38400, 56000, 57600, 115200, 128000, 153600, 230400, 256000) +baud_rates_test = (4800, 9600, 19200, 28800, 38400, 56000, 57600, 115200, 128000, 153600, 230400, 256000) + + +sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) +sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, MULTICAST_TTL) + + +pack_size = 256 +idx = 0 + +import pickle +import time +while True: + data = np.arange(idx*pack_size, (idx+1)*pack_size, 1) + idx +=1 + sock.sendto(data, (MCAST_GRP,MCAST_PORT)) + time.sleep(0.02) +# bit_data = np.ascontiguousarray(np.unpackbits(data).reshape((-1,8))[:,::-1]) + + # sock.sendto(bit_data, (MCAST_GRP,MCAST_PORT)) + + + + +#~/sr/bin/sigrok-cli --config samplerate=500000 --driver=fx2lafw --samples 1M -P uart:baudrate=57600:tx=D0 -P uart:baudrate=9600:tx=D0 -A uart=tx-data:tx-warning + +session.run() +session.stop() +#device.close() +# %% +import pickle +with open('data.p','rb') as ff: + bit_data = pickle.load(ff) +# %% +baud_rates_test = (2400, 4800, 9600, 19200, 28800, 38400, 56000, 57600, 115200, 128000, 153600, 230400, 256000) +import ripyl +import ripyl.protocol.uart as uart +txd = ripyl.streaming.samples_to_sample_stream(bit_data[:,0], 1/1000000) +for br in baud_rates_test: +# out = uart.uart_decode(txd,baud_rate=57600) + try: + txd = ripyl.streaming.samples_to_sample_stream(bit_data[:,0], 1/1000000) + out = uart.uart_decode(txd,baud_rate=br) + dat = list(out) + for y in dat: + print(chr(y.data),end='') + except: + pass +#print('Session running',session.is_running()) +#session.stop() +#device.close() + +# %% + + diff --git a/uart_cli.py b/uart_cli.py new file mode 100644 index 0000000..e69de29 diff --git a/uart_monitor_config.py b/uart_monitor_config.py new file mode 100644 index 0000000..c064d44 --- /dev/null +++ b/uart_monitor_config.py @@ -0,0 +1,10 @@ + +samplerate = 2000000 +udp_raw_port = 5007 +udp_grp = '239.255.255.255' +MULTICAST_TTL = 2 +#baud_rates_test = (2400, 4800, 9600, 19200, 28800, 38400, 56000, 57600, 115200, 128000, 153600, 230400, 256000) +baud_rates_test = [2400, 4800, 9600, 19200, 57600, 115200] +baud_rates_ports = [udp_raw_port+idx+1 for idx,brate in enumerate(baud_rates_test)] + +baud_rate_map = {brate:port for brate,port in zip(baud_rates_test, baud_rates_ports)} diff --git a/udp_client.py b/udp_client.py new file mode 100644 index 0000000..20c0eca --- /dev/null +++ b/udp_client.py @@ -0,0 +1,135 @@ +import socket +import struct +import uart_monitor_config as c +from networkx import Graph, DiGraph, simple_cycles, connected_components +import networkx as nx +import sys +import time +import numpy as np +from functools import partial + +MCAST_GRP = c.udp_grp +MCAST_PORT = c.udp_raw_port + +sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) +sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) +sock.bind(('', MCAST_PORT)) + +mreq = struct.pack("4sl", socket.inet_aton(MCAST_GRP), socket.INADDR_ANY) +sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq) + + +samplerate = c.samplerate +channel_idx = 2 +baud_rates_test = c.baud_rates_test + + +do_graph_analysis = False +recv_size = 1024*256 + +sock_send = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) +sock_send.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, c.MULTICAST_TTL) + +sock_send_funcs = dict() + +def send_packet(data, flags = None): + print(data, flags) + sock_send.sendto(data, flags) + +for b_rate, udp_port in c.baud_rate_map.items(): +# sock_send_funcs[b_rate] = partial(sock_send.sendto, flags = (MCAST_GRP,MCAST_PORT)) + sock_send_funcs[b_rate] = partial(send_packet, flags = (MCAST_GRP,udp_port)) + + +# %% + + + +bcands = dict() +bcands_zero = dict() +pre_bits = {x:np.zeros(0,dtype=np.uint8) for x in baud_rates_test} +while True: + dat = sock.recv(recv_size) + bits = np.unpackbits(np.frombuffer(dat,dtype=np.uint8)).reshape((-1,8))[:,::-1] + bit_stream_pre = bits[:,channel_idx] + + + for baud_rate in baud_rates_test: + bit_stream = np.concatenate([ pre_bits[baud_rate] ,bit_stream_pre]) + all_to_zero_total = np.where(np.diff(bit_stream) == 255)[0] #bit_stream is uint8, so transition f + bit_period = 1.0 / float(baud_rate) + brhz=1/samplerate + bspace = bit_period/brhz + to_keep = all_to_zero_total < (len(bit_stream) - 10*bspace) + to_not_keep = np.logical_not(to_keep) + all_to_zero = all_to_zero_total [to_keep] + frames = np.arange(0,8*bspace, bspace, dtype=np.int64) + int(bspace/2 + bspace) + frame_length = 9*bspace + idx_scan = all_to_zero[:,None] + frames[None,:] + possible_arrays = bit_stream[idx_scan] + if len(possible_arrays) > 0: + packed_bits = np.packbits(possible_arrays,axis=1,bitorder='little') + else: + packed_bits = [] + + diff_this = np.insert(all_to_zero,0,0) + sum_ending = np.sum(all_to_zero_total > (len(bit_stream) - 11*bspace)) + big_spaces = np.where(np.diff(diff_this) / (bspace/2) > 10.25)[0] + + diff_this_total = np.insert(all_to_zero_total,0,0) + big_spaces_total = np.where(np.diff(diff_this_total)/ (bspace/2) > 10)[0] + + if len(big_spaces) > 0: + relevant_bits = packed_bits[big_spaces].flatten() + print(baud_rate, list(relevant_bits)) + sys.stdout.flush() + + for x in relevant_bits: + print('Sending') + sock_send_funcs[baud_rate](x) + else: + relevant_bits = [] + + + set_diff = set(big_spaces_total) - set(big_spaces) + if len(set_diff)>0: + space_start = max(set_diff) + m1 = np.ones((int(11*bspace)), dtype=np.uint8) + m2 = bit_stream[int(diff_this_total[space_start+1] - bspace):] + pre_bits[baud_rate]=np.concatenate((m1,m2)) + + elif np.sum(to_not_keep) > 0: + m1 = np.ones((int(11*bspace)), dtype=np.uint8) + m2 = bit_stream[all_to_zero_total[np.argmax(to_not_keep)]:] + pre_bits[baud_rate]=np.concatenate((m1,m2)) + else: + pre_bits[baud_rate] = np.zeros(0) + + pre_bits[baud_rate] = bit_stream[-int(frame_length):] + + if do_graph_analysis and len(all_to_zero)>0: + atz = all_to_zero + diff_mat = atz[:,None] - atz[None,:] + #id_trav = np.logical_or(diff_mat > frame_length,diff_mat == 0) + id_trav = diff_mat > frame_length + conn = np.argmax(id_trav,axis=0) + con_dict = dict() + + for idf, cc in zip(range(len(conn)),conn): + if cc == 0: + leaves.append(str(idf)) + continue + + con_dict[str(idf)] = [str(cc)] + + + G = DiGraph(con_dict) + roots = [i for i,d in G.in_degree() if d == 0] + leaves = [i for i,d in G.out_degree() if d == 0] + + + all_ps = list() + for root in roots: + paths = nx.all_simple_paths(G, root, leaves) + all_ps.extend(paths) +