import struct
from pathlib import Path

import numpy as np
import zmq
import time
import sys

from matplotlib import pyplot as plt

def test():
    ctx = zmq.Context()
    sock = ctx.socket(zmq.PULL)
    sock.bind('tcp://0.0.0.0:5555')

    li = []
    cnt = 0
    while True:
        s = sock.recv_pyobj()
        cnt += 1
        if cnt == 1:
            cnt = 0
            li.append(s)
            if li.__len__() > 100:
                li = li[1:]
            # print(li.__len__())
            aa = np.array(li)
            plt.cla()
            # plt.plot(aa[:,0])
            # plt.plot(aa[:,1])
            plt.plot(aa[:,2]*1000)
            plt.plot(aa[:,3])
            plt.pause(0.0001)

        # plt.axis([0, 10, 0, 1])
        # for i in range(10):
        #     y = np.random.random()
        #     plt.scatter(i, y)
        #     plt.pause(0.05)



if __name__ == '__main__':
    test()
