From b920bdf55ce6c6f55018140f92df579c6d2b4fbea98b107f74cb559084a15ef2 Mon Sep 17 00:00:00 2001 From: Sebastian Mariano Flores Date: Mon, 25 May 2026 22:17:40 -0600 Subject: [PATCH] Hilos:DEBUG --- src/cliente_ws.py | 22 ++++++++++++++++++++++ src/main.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/cliente_ws.py create mode 100644 src/main.py diff --git a/src/cliente_ws.py b/src/cliente_ws.py new file mode 100644 index 0000000..1989b78 --- /dev/null +++ b/src/cliente_ws.py @@ -0,0 +1,22 @@ +import struct +import threading + +from websocket import create_connection + + +class websocket_cliente(threading.Thread): + def __init__(self, cola_datos, ip_server): + super().__init__() + self.cola_datos = cola_datos + self.ip_server = ip_server + self.ws = create_connection(f"ws://{self.ip_server}") + + def run(self): + while True: + data = self.ws.recv() + + if isinstance(data, bytes): + samples = struct.unpack(f"<{len(data) // 2}H", data) + self.cola_datos.put(samples) + else: + print("Datos: TXT. No se procesan.") diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..7895205 --- /dev/null +++ b/src/main.py @@ -0,0 +1,30 @@ +# Aquitectura: 3 hilos -> Wwebsocket -> Procesamiento -> Visualización + +# Base: Hilos y datos buffer de datos compartidos +import queue +import threading + +from cliente_ws import websocket_cliente + +# Datos globals +ip_server = "10.42.0.100:81" + +# Cola de datos compartidos +raw_data = queue.Queue() +data_clean = queue.Queue() + + +def debug_print(): + while True: + raw = raw_data.get() + print(raw) + + +hilo_1 = websocket_cliente(raw_data, ip_server) +hilo_2 = threading.Thread(target=debug_print) + +hilo_1.start() +hilo_2.start() + +hilo_1.join() +hilo_2.join()