From 365c2ef9469cfe95c3e2396d2e72ca9400d79ae1 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sat, 9 Jan 2016 12:20:57 -0800 Subject: [PATCH] Handle baseband::dma::wait_for_rx_buffer() returning empty buffer. Was technically OK before, because sample count was zero. But seems silly (and vaguely dangerous) to call all that code with a nullptr. --- firmware/baseband/baseband_thread.cpp | 26 ++++++++++++++------------ firmware/common/buffer.hpp | 4 ++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/firmware/baseband/baseband_thread.cpp b/firmware/baseband/baseband_thread.cpp index 223a762e5..d1a2e30c8 100644 --- a/firmware/baseband/baseband_thread.cpp +++ b/firmware/baseband/baseband_thread.cpp @@ -98,20 +98,22 @@ void BasebandThread::run() { while(true) { // TODO: Place correct sampling rate into buffer returned here: const auto buffer_tmp = baseband::dma::wait_for_rx_buffer(); - buffer_c8_t buffer { - buffer_tmp.p, buffer_tmp.count, baseband_configuration.sampling_rate - }; + if( buffer_tmp ) { + buffer_c8_t buffer { + buffer_tmp.p, buffer_tmp.count, baseband_configuration.sampling_rate + }; - if( baseband_processor ) { - baseband_processor->execute(buffer); - } - - stats.process(buffer, - [](const BasebandStatistics& statistics) { - const BasebandStatisticsMessage message { statistics }; - shared_memory.application_queue.push(message); + if( baseband_processor ) { + baseband_processor->execute(buffer); } - ); + + stats.process(buffer, + [](const BasebandStatistics& statistics) { + const BasebandStatisticsMessage message { statistics }; + shared_memory.application_queue.push(message); + } + ); + } } delete baseband_buffer; diff --git a/firmware/common/buffer.hpp b/firmware/common/buffer.hpp index da7e70a78..2b3d71707 100644 --- a/firmware/common/buffer.hpp +++ b/firmware/common/buffer.hpp @@ -92,6 +92,10 @@ struct buffer_t { timestamp { timestamp } { } + + operator bool() const { + return (p != nullptr); + } }; #endif/*__BUFFER_H__*/