From f263caa2db965ded17cbeb02280dc0174bd73587 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sat, 27 Nov 2021 14:46:47 +0100 Subject: Move network code and update nix files --- src/net.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/net.py') diff --git a/src/net.py b/src/net.py index 6bd71ac..2c91bb8 100644 --- a/src/net.py +++ b/src/net.py @@ -3,6 +3,8 @@ import socket from urllib.parse import urlparse import numpy as np +from numpy_ringbuffer import RingBuffer +import dearpygui.dearpygui as dpg class udpsource: @@ -31,3 +33,36 @@ class udpsource: else: return None + +class network_plot(udpsource): + def __init__(self, url, nsamples, **kwargs): + udpsource.__init__(self, url) + + self.nsamples = nsamples + self.plot = dpg.plot(**kwargs) + + # create buffer and fill with zeroes + self.buffer = RingBuffer(capacity=nsamples, dtype=(float, 2)) + for i in range(nsamples): + # TODO: remove random data used for testing + self.buffer.append(np.array([i, 1 + np.random.rand() / 5])) + + self.bind() + + def __enter__(self): + return self.plot.__enter__() + + def __exit__(self, t, val, tb): + self.plot.__exit__(t, val, tb) + + @property + def x_data(self): + return np.array(self.buffer[:,0]) + + @property + def y_data(self): + return np.array(self.buffer[:,1]) + + def refresh_series(self, tag): + dpg.set_value(tag, [self.x_data, self.y_data]) + pass -- cgit v1.2.1