本文整理匯總了Python中rtlsdr.RtlSdr.read_bytes_async方法的典型用法代碼示例。如果您正苦於以下問題:Python RtlSdr.read_bytes_async方法的具體用法?Python RtlSdr.read_bytes_async怎麽用?Python RtlSdr.read_bytes_async使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rtlsdr.RtlSdr
的用法示例。
在下文中一共展示了RtlSdr.read_bytes_async方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from rtlsdr import RtlSdr [as 別名]
# 或者: from rtlsdr.RtlSdr import read_bytes_async [as 別名]
class Demod:
SAMP_RATE = 256000.
SAMP_WINDOW = 1024*40
def __init__(self):
self.sdr = RtlSdr()
# Sampling rate
self.sdr.rs = Demod.SAMP_RATE
# Pins 1 and 2
self.sdr.set_direct_sampling(1)
# I don't think this is used?
self.sdr.gain = 1
def run(self, limit=None, callback=lambda x: print(x),
carrier=32000, bw=1000, sps=8,
codes=manchester, mod=Mods.MAGNITUDE,
header=HEADER, footer=FOOTER, pktlen=PKTBYTES):
# Center frequency
self.sdr.fc = carrier
self.mod = mod
self.header = header
self.footer = footer
self.pktlen = 8*pktlen + len(footer)
self.rxcallback = callback
decim = Demod.SAMP_RATE/bw/sps
assert decim == int(decim)
self.decim = int(decim)
assert Demod.SAMP_WINDOW % self.decim == 0
self.sampchips = Demod.SAMP_WINDOW / self.decim
self.corr = codes2corr(codes, sps)
self.codelen = len(self.corr[0])
self.last = np.zeros(Demod.SAMP_WINDOW)
self.index = 0
self.tocheck = [None] * self.codelen
for i in range(self.codelen):
self.tocheck[i] = dict()
self.tocheck[i]['last'] = ''.join(range(0))
self.tocheck[i]['pkts'] = range(0)
if limit is None:
def byte_callback(samp, sdr):
if select.select([sys.stdin], [], [], 0)[0]:
sdr.cancel_read_async()
self.ddc(samp, sdr)
else:
@limit_calls(limit)
def byte_callback(samp, sdr):
if select.select([sys.stdin], [], [], 0)[0]:
sdr.cancel_read_async()
self.ddc(samp, sdr)
self.sdr.read_bytes_async(byte_callback, Demod.SAMP_WINDOW*2)
print (self.index, "samples read")
sys.stdout.flush()
sys.stdin.readline()
def bb2c(self, baseband):
mag = np.abs(baseband)
phase = np.angle(baseband)
dp = np.mod(np.ediff1d(phase)+np.pi, 2*np.pi)-np.pi
return mag[1:], phase[1:], dp
def decode(self, chips):
corrs = []
for c in self.corr:
corrs.append(np.correlate(chips, c))
# Vector correlations
if np.iscomplex(corrs).any():
corrs = np.abs(corrs)
maxes = np.max(np.array(corrs), 0)
codes = np.argmax(np.array(corrs), 0)
return maxes, codes
def debounce(self, i, l, rxstr):
try:
if i != self.debounce_i or abs(l - self.debounce_l) > 1:
self.rxcallback(rxstr)
except AttributeError:
self.rxcallback(rxstr)
self.debounce_i = i
self.debounce_l = l
def extract(self, nc):
for codeoffset in range(self.codelen):
pkts = []
codestr = "".join(map(repr, map(int, nc[codeoffset::self.codelen])))
for p in self.tocheck[codeoffset]['pkts']:
pkt = p + codestr[0:self.pktlen-len(p)]
if len(pkt) < self.pktlen:
pkts.append(pkt)
elif len(self.footer) == 0 or pkt[-len(self.footer):] == self.footer:
str = ""
for j in range(0,len(pkt)-1,8):
#.........這裏部分代碼省略.........