Better error handling for stream failures, actually give an error message

This commit is contained in:
Jono Targett 2023-05-15 12:02:23 +09:30
parent 9267570e89
commit 56bb29ebdd
3 changed files with 33 additions and 13 deletions

View File

@ -107,9 +107,6 @@ def configure(radio, frequency):
description: The specified radio is not connected.
"""
if radio in radios:
if radios[radio].is_streaming():
return 'no', 400
else:
return jsonify(radios[radio].configure(frequency))
else:
return "Radio not connected", 400

View File

@ -5,6 +5,7 @@ from formats import *
import sys
import subprocess
import struct
from soapyhelpers import *
class Radio:
@ -72,15 +73,18 @@ class Radio:
while self.run:
# Check that the child processes are still running
if (not is_alive(self.demod)) or (not is_alive(self.playback)):
print('DSP chain error, aborting stream.', file=sys.stderr)
print('DSP chain failed, aborting stream.', file=sys.stderr)
break
result = self.device.readStream(self.stream, [self.buffer], Radio.SAMPLES)
if result.ret < 1:
print('Stream read failed, aborting stream.', file=sys.stderr)
if result == 0:
continue
elif result.ret < 0:
error = SoapyError(result.ret)
print("Stream read failed, aborting stream:", error, file=sys.stderr)
break
else:
read_size = int(result.ret * 2)
self.demod.stdin.write(
struct.pack(PACKINGS[Radio.FORMAT] % read_size,

19
soapyhelpers.py Normal file
View File

@ -0,0 +1,19 @@
import SoapySDR as soapy
from enum import IntEnum
class SoapyError(IntEnum):
Timeout = soapy.SOAPY_SDR_TIMEOUT
StreamError = soapy.SOAPY_SDR_STREAM_ERROR
Corruption = soapy.SOAPY_SDR_CORRUPTION
Overflow = soapy.SOAPY_SDR_OVERFLOW
NotSupported = soapy.SOAPY_SDR_NOT_SUPPORTED
TimeError = soapy.SOAPY_SDR_TIME_ERROR
Underflow = soapy.SOAPY_SDR_UNDERFLOW
class SoapyFlag(IntEnum):
EndBurst = soapy.SOAPY_SDR_END_BURST
HasTime = soapy.SOAPY_SDR_HAS_TIME
EndAbrupt = soapy.SOAPY_SDR_END_ABRUPT
OnePacket = soapy.SOAPY_SDR_ONE_PACKET
MoreFragments = soapy.SOAPY_SDR_MORE_FRAGMENTS
WaitTrigger = soapy.SOAPY_SDR_WAIT_TRIGGER