SHA256
Hilos:DEBUG
This commit is contained in:
1 parent
321565eefd
commit
b920bdf55c
2 files changed
+52
No files matched your search
@@ -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.")
|
||||||
+30
@@ -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()
|
||||||
Reference in new issue
Block a user