diff --git a/hitl/run.sh b/hitl/run.sh index 7c7aa27..c4f8821 100755 --- a/hitl/run.sh +++ b/hitl/run.sh @@ -11,10 +11,11 @@ set -eux # Set up python for testing -python3 -m venv --system-site-packages py +python3 -m venv --system-site-packages py-venv . py/bin/activate # Install Miniconf utilities for configuring stabilizer. +python3 -m pip install -e py/ python3 -m pip install git+https://github.com/quartiq/miniconf#subdirectory=py/miniconf-mqtt python3 -m pip install gmqtt diff --git a/hitl/streaming.py b/hitl/streaming.py index 6d884b6..2e6fa3b 100644 --- a/hitl/streaming.py +++ b/hitl/streaming.py @@ -6,13 +6,11 @@ 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 +from stabilizer.stream import StabilizerStream def _get_ip(broker): """ Get the IP of the local device. @@ -42,74 +40,6 @@ def sequence_delta(previous_sequence, next_sequence): 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 = ' 0x{seqnum:08X}' last_sequence = seqnum # Disable the stream. print('Closing stream') print('') - await interface.command('stream_target', {'ip': [0, 0, 0, 0], 'port': 0}) + await interface.command('stream_target', {'ip': [0, 0, 0, 0], 'port': 0}, retain=False) stream.clear() print('Verifying no further data is received') diff --git a/py/.gitignore b/py/.gitignore new file mode 100644 index 0000000..d9dc407 --- /dev/null +++ b/py/.gitignore @@ -0,0 +1,2 @@ +/*.egg-info/ +__pycache__/ diff --git a/py/README.md b/py/README.md new file mode 100644 index 0000000..b768ea1 --- /dev/null +++ b/py/README.md @@ -0,0 +1,8 @@ +# Stabilizer Python Utilities + +This directory contains common Python utilities for Stabilizer, such as livestream data receivers. + +To install this module locally (in editable mode): +``` +python -m pip install -e . +``` diff --git a/py/setup.py b/py/setup.py new file mode 100644 index 0000000..5b48bd3 --- /dev/null +++ b/py/setup.py @@ -0,0 +1,7 @@ +from setuptools import setup + +setup(name='stabilizer', + version='0.1', + description='Stabilizer Utilities', + author='QUARTIQ GmbH', + license='MIT') diff --git a/py/stabilizer/__init__.py b/py/stabilizer/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/py/stabilizer/stream.py b/py/stabilizer/stream.py new file mode 100644 index 0000000..e6144db --- /dev/null +++ b/py/stabilizer/stream.py @@ -0,0 +1,92 @@ +#!/usr/bin/python3 +""" +Author: Vertigo Designs, Ryan Summers + +Description: Provides a means of accessing Stabilizer livestream data. +""" +import socket +import time +import logging +import struct + +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 = '