From d51d3f7d3798ba8f7ff2b97e9072f8c8e91fcf09 Mon Sep 17 00:00:00 2001 From: "J.A. de Jong - Redu-Sone B.V., ASCEE V.O.F" Date: Wed, 2 Feb 2022 14:07:21 +0100 Subject: [PATCH] Some sanity checks. Removed activateSiggen and deactivateSiggen fucntionality, as it has no use. --- lasp/lasp_avstream.py | 61 ++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 39 deletions(-) diff --git a/lasp/lasp_avstream.py b/lasp/lasp_avstream.py index fa5bb7b..e7eba83 100644 --- a/lasp/lasp_avstream.py +++ b/lasp/lasp_avstream.py @@ -67,8 +67,6 @@ class StreamMsg(Enum): endProcess = auto() scanDaqDevices = auto() - activateSiggen = auto() - deactivateSiggen = auto() """ Second part, status messages that are send back on all listeners """ @@ -116,7 +114,6 @@ class AudioStream: self.running = False self.aframectr = 0 self.avtype = avtype - self.siggen_activated = Atomic(False) api_devices = devices[daqconfig.api] self.processCallback = processCallback @@ -138,6 +135,12 @@ class AudioStream: if en_in_ch == 0 and en_out_ch == 0: raise RuntimeError('No enabled input / output channels') + elif en_out_ch == 0 and avtype in (AvType.audio_duplex, + AvType.audio_output): + raise RuntimeError('No enabled output channels') + elif en_in_ch == 0 and avtype in (AvType.audio_input, + AvType.audio_duplex): + raise RuntimeError('No enabled input channels') logging.debug('Ready to start device...') samplerate = self.daq.start(self.streamCallback) @@ -264,7 +267,6 @@ class AvStreamProcess(mp.Process): # Check for devices self.rescanDaqDevices() - self.siggen_activated = Atomic(False) while True: try: @@ -275,13 +277,7 @@ class AvStreamProcess(mp.Process): self.terminate() logging.debug(f"Streamprocess obtained message {msg}") - if msg == StreamMsg.activateSiggen: - self.siggen_activated <<= True - - elif msg == StreamMsg.deactivateSiggen: - self.siggen_activated <<= False - - elif msg == StreamMsg.scanDaqDevices: + if msg == StreamMsg.scanDaqDevices: self.rescanDaqDevices() elif msg == StreamMsg.stopAllStreams: @@ -355,7 +351,7 @@ class AvStreamProcess(mp.Process): self.sendAllQueues( StreamMsg.streamError, stream.avtype, - "Error occured in stopping stream: {str(e)}", + f"Error occured in stopping stream: {str(e)}", ) self.streams[avtype] = None @@ -427,28 +423,22 @@ class AvStreamProcess(mp.Process): """This is called (from a separate thread) for each audio block.""" # logging.debug('streamCallback()') if outdata is not None: - if self.siggen_activated(): - if not self.outq.empty(): - newdata = self.outq.get() - if newdata.shape[0] != outdata.shape[0] or newdata.ndim != 1: - msgtxt = "Invalid output data obtained from queue" - logging.fatal(msgtxt) - self.sendAllQueues( - StreamMsg.streamFatalError, audiostream.avtype, msgtxt - ) - return 1 - outdata[:, :] = newdata[:, None] - else: - msgtxt = "Signal generator buffer underflow. Signal generator cannot keep up with data generation." - # logging.error(msgtxt) + if not self.outq.empty(): + newdata = self.outq.get() + if newdata.shape[0] != outdata.shape[0] or newdata.ndim != 1: + msgtxt = "Invalid output data obtained from queue" + logging.fatal(msgtxt) self.sendAllQueues( - StreamMsg.streamTemporaryError, audiostream.avtype, msgtxt + StreamMsg.streamFatalError, audiostream.avtype, msgtxt ) - outdata[:, :] = 0 - - # Siggen not activated + return 1 + outdata[:, :] = newdata[:, None] else: - logging.debug("siggen not activated") + msgtxt = "Signal generator buffer underflow. Signal generator cannot keep up with data generation." + # logging.error(msgtxt) + self.sendAllQueues( + StreamMsg.streamTemporaryError, audiostream.avtype, msgtxt + ) outdata[:, :] = 0 if indata is not None: @@ -617,15 +607,7 @@ class StreamManager: self.handleMessages() return self.outq - def activateSiggen(self): - self.handleMessages() - logging.debug("activateSiggen()") - self.sendPipe(StreamMsg.activateSiggen, None) - def deactivateSiggen(self): - self.handleMessages() - logging.debug("deactivateSiggen()") - self.sendPipe(StreamMsg.deactivateSiggen, None) def addMsgQueueListener(self): """ @@ -692,6 +674,7 @@ class StreamManager: break def stopStream(self, avtype: AvType): + logging.debug(f'StreamManager::stopStream({avtype})') self.handleMessages() self.sendPipe(StreamMsg.stopStream, avtype)