Advertisement
DeaD_EyE

kxc1_subscriber

Mar 7th, 2019
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. """
  4. Subscriber for: https://pastebin.com/yECG4APX
  5. """
  6.  
  7. import zmq
  8. import struct
  9.  
  10.  
  11. IQ_STRUCT = struct.Struct('>512h')
  12.  
  13.  
  14. def parse(data):
  15.     iq = IQ_STRUCT.unpack(data)
  16.     return iq[:256], iq[256:]
  17.  
  18.  
  19. def receive(address):
  20.     with zmq.Context() as ctx:
  21.         sock = ctx.socket(zmq.SUB)
  22.         sock.connect(address)
  23.         sock.subscribe(b'sensor')
  24.         while True:
  25.             topic, frame = sock.recv_multipart()
  26.             i, q = parse(frame)
  27.             print(i[:4], q[:4])
  28.  
  29.  
  30. if __name__ == '__main__':
  31.     address = 'tcp://192.168.0.254:5050'
  32.     receive(address)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement