mirror of
https://github.com/romanz/amodem.git
synced 2026-04-01 17:26:49 +08:00
recv: add timeout for carrier waiting
This commit is contained in:
@@ -24,17 +24,22 @@ class Detector(object):
|
||||
CARRIER_THRESHOLD = int(0.9 * CARRIER_DURATION)
|
||||
SEARCH_WINDOW = int(0.1 * CARRIER_DURATION)
|
||||
|
||||
TIMEOUT = 10.0 # [seconds]
|
||||
|
||||
def __init__(self, config):
|
||||
self.freq = config.Fc
|
||||
self.omega = 2 * np.pi * self.freq / config.Fs
|
||||
self.Nsym = config.Nsym
|
||||
self.Tsym = config.Tsym
|
||||
self.maxlen = config.baud # 1 second of symbols
|
||||
self.max_offset = self.TIMEOUT * config.Fs
|
||||
|
||||
def run(self, samples):
|
||||
counter = 0
|
||||
bufs = collections.deque([], maxlen=self.maxlen)
|
||||
for offset, buf in common.iterate(samples, self.Nsym, enumerate=True):
|
||||
if offset > self.max_offset:
|
||||
raise ValueError('Timeout waiting for carrier')
|
||||
bufs.append(buf)
|
||||
|
||||
coeff = dsp.coherence(buf, self.omega)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from amodem import dsp
|
||||
from amodem import recv
|
||||
@@ -18,11 +19,12 @@ def test_detect():
|
||||
assert abs(1 - amp) < 1e-12
|
||||
|
||||
x = np.cos(2 * np.pi * (2*config.Fc) * t)
|
||||
try:
|
||||
with pytest.raises(ValueError):
|
||||
detector.run(x)
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
detector.max_offset = 0
|
||||
detector.run(x)
|
||||
assert False
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
def test_prefix():
|
||||
@@ -37,12 +39,9 @@ def test_prefix():
|
||||
freq_err = r._prefix(symbols_stream(signal))
|
||||
assert abs(freq_err) < 1e-16
|
||||
|
||||
try:
|
||||
with pytest.raises(ValueError):
|
||||
silence = 0 * signal
|
||||
r._prefix(symbols_stream(silence))
|
||||
assert False
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
|
||||
def test_find_start():
|
||||
|
||||
Reference in New Issue
Block a user