Better error handling for stream failures, actually give an error message
This commit is contained in:
parent
9267570e89
commit
56bb29ebdd
@ -107,9 +107,6 @@ 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 'no', 400
|
|
||||||
else:
|
|
||||||
return jsonify(radios[radio].configure(frequency))
|
return jsonify(radios[radio].configure(frequency))
|
||||||
else:
|
else:
|
||||||
return "Radio not connected", 400
|
return "Radio not connected", 400
|
||||||
|
|||||||
12
radio.py
12
radio.py
@ -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,15 +73,18 @@ 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,
|
||||||
|
|||||||
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