first working nfm chain using pycsdr

This commit is contained in:
Jakob Ketterl
2021-07-19 19:04:14 +02:00
parent bb77d2ce0a
commit 5bb14a8997
5 changed files with 139 additions and 25 deletions

View File

@ -13,43 +13,57 @@ class Chain:
self._connect(self.workers[i - 1], self.workers[i])
def _connect(self, w1, w2):
buffer = Buffer(w1.getOutputFormat())
w1.setOutput(buffer)
if isinstance(w1, Chain):
buffer = w1.getOutput()
else:
buffer = Buffer(w1.getOutputFormat())
w1.setOutput(buffer)
w2.setInput(buffer)
def stop(self):
for w in self.workers:
w.stop()
self.setInput(None)
self.setOutput(None)
if self.output is not None:
self.output.stop()
def setInput(self, buffer):
if self.input == buffer:
return
self.input = buffer
self.workers[0].setInput(buffer)
if self.workers:
self.workers[0].setInput(buffer)
else:
self.output = self.input
def setOutput(self, buffer):
if self.output == buffer:
return
if self.output is not None:
self.output.stop()
self.output = buffer
self.workers[-1].setOutput(buffer)
def getOutput(self):
if self.output is None:
if self.workers:
lastWorker = self.workers[-1]
if isinstance(lastWorker, Chain):
self.output = lastWorker.getOutput()
else:
self.output = Buffer(self.getOutputFormat())
self.workers[-1].setOutput(self.output)
else:
self.output = self.input
return self.output
def getOutputFormat(self):
return self.workers[-1].getOutputFormat()
if self.workers:
return self.workers[-1].getOutputFormat()
else:
return self.input.getOutputFormat()
def pump(self, write):
if self.output is None:
self.setOutput(Buffer(self.getOutputFormat()))
output = self.getOutput()
def copy():
run = True
while run:
data = None
try:
data = self.output.read()
data = output.read()
except ValueError:
pass
if data is None or (isinstance(data, bytes) and len(data) == 0):