#!/usr/bin/python3 """Stabilizer streaming receiver and parsers""" import argparse import asyncio import logging import struct import socket import ipaddress from collections import namedtuple from dataclasses import dataclass import numpy as np from . import DAC_VOLTS_PER_LSB logger = logging.getLogger(__name__) Trace = namedtuple("Trace", "values scale label") def wrap(wide): """Wrap to 32 bit integer""" return wide & 0xffffffff def get_local_ip(remote): """Get the local IP of a connection to the to a remote host. Returns a list of four octets.""" sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) try: sock.connect((remote, 1883)) return sock.getsockname()[0] finally: sock.close() class AdcDac: """Stabilizer default striming data format""" format_id = 1 def __init__(self, header, body): self.header = header self.body = body def size(self): """Return the data size of the frame in bytes""" return len(self.body) def to_mu(self): """Return the raw data in machine units""" data = np.frombuffer(self.body, "