Better error handling for stream failures, actually give an error message
This commit is contained in:
parent
9267570e89
commit
56bb29ebdd
@ -107,10 +107,7 @@ 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))
|
||||
return jsonify(radios[radio].configure(frequency))
|
||||
else:
|
||||
return "Radio not connected", 400
|
||||
|
||||
|
||||
22
radio.py
22
radio.py
@ -5,6 +5,7 @@ from formats import *
|
||||
import sys
|
||||
import subprocess
|
||||
import struct
|
||||
from soapyhelpers import *
|
||||
|
||||
|
||||
class Radio:
|
||||
@ -72,20 +73,23 @@ 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
|
||||
|
||||
read_size = int(result.ret * 2)
|
||||
self.demod.stdin.write(
|
||||
struct.pack(PACKINGS[Radio.FORMAT] % read_size,
|
||||
*self.buffer[:read_size])
|
||||
)
|
||||
else:
|
||||
read_size = int(result.ret * 2)
|
||||
self.demod.stdin.write(
|
||||
struct.pack(PACKINGS[Radio.FORMAT] % read_size,
|
||||
*self.buffer[:read_size])
|
||||
)
|
||||
|
||||
self._cleanup_stream()
|
||||
|
||||
|
||||
19
soapyhelpers.py
Normal file
19
soapyhelpers.py
Normal 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
|
||||
Loading…
Reference in New Issue
Block a user