From 824b6763e16b48d60da291323c736fa558883436 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Thu, 5 Aug 2021 16:21:55 +0200 Subject: [PATCH] Adding livestream HITL test --- hitl/run.sh | 3 + hitl/streaming.py | 167 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 hitl/streaming.py diff --git a/hitl/run.sh b/hitl/run.sh index 582c0f0..45acb03 100755 --- a/hitl/run.sh +++ b/hitl/run.sh @@ -33,3 +33,6 @@ python3 -m miniconf dt/sinara/dual-iir/04-91-62-d9-7e-5f afe/0='"G1"' iir_ch/0/0 # Test the ADC/DACs connected via loopback. python3 hitl/loopback.py dt/sinara/dual-iir/04-91-62-d9-7e-5f + +# Test the livestream capabilities +python3 hitl/streaming.py dt/sinara/dual-iir/04-91-62-d9-7e-5f diff --git a/hitl/streaming.py b/hitl/streaming.py new file mode 100644 index 0000000..1675409 --- /dev/null +++ b/hitl/streaming.py @@ -0,0 +1,167 @@ +#!/usr/bin/python3 +""" +Author: Vertigo Designs, Ryan Summers + +Description: Implements HITL testing of Stabilizer data livestream capabilities. +""" +import asyncio +import sys +import time +import argparse +import socket +import struct +import logging + +from miniconf import Miniconf + +def _get_ip(broker): + """ Get the IP of the local device. + + Args: + broker: The broker IP of the test. Used to select an interface to get the IP of. + + Returns: + The IP as an array of integers. + """ + sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + try: + sock.connect((broker, 1883)) + address = sock.getsockname()[0] + finally: + sock.close() + + return list(map(int, address.split('.'))) + + +def sequence_delta(previous_sequence, next_sequence): + """ Check the number of items between two sequence numbers. """ + if previous_sequence is None: + return 0 + + delta = next_sequence - (previous_sequence + 1) + return delta & 0xFFFFFFFF + + +class StabilizerStream: + """ Provides access to Stabilizer's livestreamed data. """ + + # The magic header half-word at the start of each packet. + MAGIC_HEADER = 0x057B + + # The struct format of the header. + HEADER_FORMAT = '