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,10 +107,7 @@ def configure(radio, frequency):
description: The specified radio is not connected. description: The specified radio is not connected.
""" """
if radio in radios: if radio in radios:
if radios[radio].is_streaming(): return jsonify(radios[radio].configure(frequency))
return 'no', 400
else:
return jsonify(radios[radio].configure(frequency))
else: else:
return "Radio not connected", 400 return "Radio not connected", 400

View File

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

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