From 1087a7f4ad8bb1bc9bf4472bf2734b0e4929e7d1 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 11 Dec 2017 15:07:18 +0100 Subject: Remove references to malloc.h and use posix_memalign --- src/DabMod.cpp | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src/DabMod.cpp') diff --git a/src/DabMod.cpp b/src/DabMod.cpp index af3adde..1625a82 100644 --- a/src/DabMod.cpp +++ b/src/DabMod.cpp @@ -64,13 +64,6 @@ # include #endif -#if HAVE_DECL__MM_MALLOC -# include -#else -# define memalign(a, b) malloc(b) -#endif - - /* UHD requires the input I and Q samples to be in the interval * [-1.0,1.0], otherwise they get truncated, which creates very * wide-spectrum spikes. Depending on the Transmission Mode, the -- cgit v1.2.3 From fdbea05b16e3c716b5226a1f0d45cc98561500e4 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 11 Dec 2017 15:56:55 +0100 Subject: Fix all the warnings shown since previous commit --- src/Buffer.cpp | 43 ++++++++++++++++++++++--------------------- src/Buffer.h | 10 +++++----- src/ConvEncoder.cpp | 1 + src/DabMod.cpp | 5 +++-- src/FIRFilter.cpp | 3 --- src/FicSource.cpp | 1 + src/Flowgraph.cpp | 1 + src/FrameMultiplexer.cpp | 1 + src/FrequencyInterleaver.cpp | 1 + src/GainControl.cpp | 12 ++++++------ src/GainControl.h | 2 +- src/MemlessPoly.cpp | 5 +---- src/OfdmGenerator.cpp | 12 ++++++------ src/OutputUHD.cpp | 10 +++++----- src/OutputUHD.h | 2 +- src/PrbsGenerator.cpp | 7 ++++--- src/PuncturingEncoder.cpp | 1 + src/RemoteControl.cpp | 18 +++++++++--------- src/Resampler.cpp | 3 ++- src/Socket.h | 1 + src/SubchannelSource.cpp | 1 + src/TII.cpp | 6 +++--- src/TimeInterleaver.cpp | 1 + src/TimestampDecoder.cpp | 6 +++--- 24 files changed, 80 insertions(+), 73 deletions(-) (limited to 'src/DabMod.cpp') diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 6b14561..9df834a 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -28,17 +28,17 @@ #include "Buffer.h" #include "PcDebug.h" +#include #include #include - Buffer::Buffer(size_t len, const void *data) { PDEBUG("Buffer::Buffer(%zu, %p)\n", len, data); - this->len = 0; - this->size = 0; - this->data = NULL; + m_len = 0; + m_size = 0; + m_data = NULL; setData(data, len); } @@ -46,23 +46,23 @@ Buffer::Buffer(const std::vector &vec) { PDEBUG("Buffer::Buffer(vector [%zu])\n", vec.size()); - this->len = 0; - this->size = 0; - this->data = NULL; + m_len = 0; + m_size = 0; + m_data = NULL; setData(vec.data(), vec.size()); } Buffer::~Buffer() { - PDEBUG("Buffer::~Buffer() len=%zu, data=%p\n", len, data); - free(data); + PDEBUG("Buffer::~Buffer() len=%zu, data=%p\n", m_len, m_data); + free(m_data); } Buffer &Buffer::operator=(const Buffer ©) { - setData(copy.data, copy.len); + setData(copy.m_data, copy.m_len); return *this; } @@ -74,29 +74,30 @@ Buffer &Buffer::operator=(const std::vector ©) Buffer &Buffer::operator+=(const Buffer ©) { - appendData(copy.data, copy.len); + appendData(copy.m_data, copy.m_len); return *this; } void Buffer::setLength(size_t len) { - if (len > size) { - void *tmp = data; + if (len > m_size) { + void *tmp = m_data; /* Align to 32-byte boundary for AVX. */ - const int ret = posix_memalign(&data, 32, len); + const int ret = posix_memalign(&m_data, 32, len); if (ret != 0) { - throw std::runtime_error("memory allocation failed: " + std::to_string(ret)); + throw std::runtime_error("memory allocation failed: " + + std::to_string(ret)); } if (tmp != NULL) { - memcpy(data, tmp, this->len); + memcpy(m_data, tmp, m_len); free(tmp); } - size = len; + m_size = len; } - this->len = len; + m_len = len; } @@ -109,10 +110,10 @@ void Buffer::setData(const void *data, size_t len) void Buffer::appendData(const void *data, size_t len) { - size_t offset = this->len; - setLength(this->len + len); + size_t offset = m_len; + setLength(m_len + len); if (data != NULL) { - memcpy((char*)this->data + offset, data, len); + memcpy((char*)m_data + offset, data, len); } } diff --git a/src/Buffer.h b/src/Buffer.h index 8c5c768..60a7d50 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -43,15 +43,15 @@ class Buffer { protected: /* Current length of the data in the Buffer */ - size_t len; + size_t m_len; /* Allocated size of the Buffer */ - size_t size; + size_t m_size; /* Pointer to the data. Memory allocation is entirely * handled by setLength. */ - void *data; + void *m_data; public: using sptr = std::shared_ptr; @@ -77,7 +77,7 @@ class Buffer { void appendData(const void *data, size_t len); Buffer &operator+=(const Buffer ©); - size_t getLength() const { return len; } - void *getData() const { return data; } + size_t getLength() const { return m_len; } + void *getData() const { return m_data; } }; diff --git a/src/ConvEncoder.cpp b/src/ConvEncoder.cpp index 06b2e85..074898f 100644 --- a/src/ConvEncoder.cpp +++ b/src/ConvEncoder.cpp @@ -25,6 +25,7 @@ #include #include #include +#include const static uint8_t PARITY[] = { diff --git a/src/DabMod.cpp b/src/DabMod.cpp index 1625a82..0ac7d4f 100644 --- a/src/DabMod.cpp +++ b/src/DabMod.cpp @@ -445,7 +445,7 @@ int launch_modulator(int argc, char* argv[]) } } #if defined(HAVE_ZEROMQ) - else if (auto in = dynamic_pointer_cast(inputReader)) { + else if (dynamic_pointer_cast(inputReader)) { run_again = true; // Create a new input reader auto inputZeroMQReader = make_shared(); @@ -453,7 +453,8 @@ int launch_modulator(int argc, char* argv[]) inputReader = inputZeroMQReader; } #endif - else if (auto in = dynamic_pointer_cast(inputReader)) { + else if (dynamic_pointer_cast(inputReader)) { + // Create a new input reader auto inputTcpReader = make_shared(); inputTcpReader->Open(mod_settings.inputName); inputReader = inputTcpReader; diff --git a/src/FIRFilter.cpp b/src/FIRFilter.cpp index 4296822..1450b1e 100644 --- a/src/FIRFilter.cpp +++ b/src/FIRFilter.cpp @@ -306,9 +306,6 @@ int FIRFilter::internal_process(Buffer* const dataIn, Buffer* dataOut) void FIRFilter::set_parameter(const string& parameter, const string& value) { - stringstream ss(value); - ss.exceptions ( stringstream::failbit | stringstream::badbit ); - if (parameter == "ntaps") { throw ParameterError("Parameter 'ntaps' is read-only"); } diff --git a/src/FicSource.cpp b/src/FicSource.cpp index 92932ec..04197db 100644 --- a/src/FicSource.cpp +++ b/src/FicSource.cpp @@ -28,6 +28,7 @@ #include "PcDebug.h" #include +#include #include #include #include diff --git a/src/Flowgraph.cpp b/src/Flowgraph.cpp index 4870534..465ef41 100644 --- a/src/Flowgraph.cpp +++ b/src/Flowgraph.cpp @@ -26,6 +26,7 @@ #include "Flowgraph.h" #include "PcDebug.h" +#include #include #include #include diff --git a/src/FrameMultiplexer.cpp b/src/FrameMultiplexer.cpp index 1cfaadd..4cee0b2 100644 --- a/src/FrameMultiplexer.cpp +++ b/src/FrameMultiplexer.cpp @@ -28,6 +28,7 @@ #include "PcDebug.h" #include +#include #include #include #include diff --git a/src/FrequencyInterleaver.cpp b/src/FrequencyInterleaver.cpp index bd5042c..e76d525 100644 --- a/src/FrequencyInterleaver.cpp +++ b/src/FrequencyInterleaver.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include diff --git a/src/GainControl.cpp b/src/GainControl.cpp index 2a91b12..f44aa68 100644 --- a/src/GainControl.cpp +++ b/src/GainControl.cpp @@ -46,7 +46,7 @@ using namespace std; static float var_variance; GainControl::GainControl(size_t framesize, - GainMode mode, + GainMode gainMode, float digGain, float normalise, float varVariance) : @@ -60,10 +60,10 @@ GainControl::GainControl(size_t framesize, m_digGain(digGain), m_normalise(normalise), m_var_variance_rc(varVariance), - m_gainmode(mode), + m_gainmode(gainMode), m_mutex() { - PDEBUG("GainControl::GainControl(%zu, %zu) @ %p\n", framesize, (size_t)mode, this); + PDEBUG("GainControl::GainControl(%zu, %zu) @ %p\n", framesize, (size_t)m_gainMode, this); /* register the parameters that can be remote controlled */ RC_ADD_PARAMETER(digital, "Digital Gain"); @@ -532,10 +532,10 @@ void GainControl::set_parameter(const string& parameter, const string& value) } } else { - stringstream ss; - ss << "Parameter '" << parameter + stringstream ss_err; + ss_err << "Parameter '" << parameter << "' is not exported by controllable " << get_rc_name(); - throw ParameterError(ss.str()); + throw ParameterError(ss_err.str()); } } diff --git a/src/GainControl.h b/src/GainControl.h index 44c9fa9..e9eaa8c 100644 --- a/src/GainControl.h +++ b/src/GainControl.h @@ -51,7 +51,7 @@ class GainControl : public PipelinedModCodec, public RemoteControllable { public: GainControl(size_t framesize, - GainMode mode, + GainMode gainMode, float digGain, float normalise, float varVariance); diff --git a/src/MemlessPoly.cpp b/src/MemlessPoly.cpp index f223d34..ae097c9 100644 --- a/src/MemlessPoly.cpp +++ b/src/MemlessPoly.cpp @@ -38,7 +38,7 @@ #include #include - +#include #include #include #include @@ -370,9 +370,6 @@ int MemlessPoly::internal_process(Buffer* const dataIn, Buffer* dataOut) void MemlessPoly::set_parameter(const string& parameter, const string& value) { - stringstream ss(value); - ss.exceptions ( stringstream::failbit | stringstream::badbit ); - if (parameter == "ncoefs") { throw ParameterError("Parameter 'ncoefs' is read-only"); } diff --git a/src/OfdmGenerator.cpp b/src/OfdmGenerator.cpp index a6609a3..915d568 100644 --- a/src/OfdmGenerator.cpp +++ b/src/OfdmGenerator.cpp @@ -230,9 +230,9 @@ int OfdmGenerator::process(Buffer* const dataIn, Buffer* dataOut) */ double sum_iq = 0; double sum_delta = 0; - for (size_t i = 0; i < mySpacing; i++) { - sum_iq += (double)std::norm(before_cfr[i]); - sum_delta += (double)std::norm(symbol[i] - before_cfr[i]); + for (size_t j = 0; j < mySpacing; j++) { + sum_iq += (double)std::norm(before_cfr[j]); + sum_delta += (double)std::norm(symbol[j] - before_cfr[j]); } // Clamp to 90dB, otherwise the MER average is going to be inf @@ -362,10 +362,10 @@ void OfdmGenerator::set_parameter(const std::string& parameter, throw ParameterError("Parameter 'clip_stats' is read-only"); } else { - stringstream ss; - ss << "Parameter '" << parameter + stringstream ss_err; + ss_err << "Parameter '" << parameter << "' is not exported by controllable " << get_rc_name(); - throw ParameterError(ss.str()); + throw ParameterError(ss_err.str()); } } diff --git a/src/OutputUHD.cpp b/src/OutputUHD.cpp index e2616a6..b533075 100644 --- a/src/OutputUHD.cpp +++ b/src/OutputUHD.cpp @@ -472,7 +472,7 @@ int OutputUHD::process(Buffer* dataIn) myUsrp, myConf.dpdFeedbackServerPort, myConf.sampleRate); } - size_t num_frames = frames.push_wait_if_full(frame, + size_t num_frames = m_frames.push_wait_if_full(frame, FRAMES_MAX_SIZE); etiLog.log(trace, "UHD,push %zu", num_frames); } @@ -686,7 +686,7 @@ void OutputUHD::workerthread() struct UHDWorkerFrameData frame; etiLog.log(trace, "UHD,wait"); - frames.wait_and_pop(frame, pop_prebuffering); + m_frames.wait_and_pop(frame, pop_prebuffering); etiLog.log(trace, "UHD,pop"); handle_frame(&frame); @@ -989,10 +989,10 @@ void OutputUHD::set_parameter(const string& parameter, const string& value) throw ParameterError("Parameter " + parameter + " is read-only."); } else { - stringstream ss; - ss << "Parameter '" << parameter + stringstream ss_err; + ss_err << "Parameter '" << parameter << "' is not exported by controllable " << get_rc_name(); - throw ParameterError(ss.str()); + throw ParameterError(ss_err.str()); } } diff --git a/src/OutputUHD.h b/src/OutputUHD.h index 0630480..9213183 100644 --- a/src/OutputUHD.h +++ b/src/OutputUHD.h @@ -211,7 +211,7 @@ class OutputUHD: public ModOutput, public RemoteControllable { bool sync_and_ts_valid = false; - ThreadsafeQueue frames; + ThreadsafeQueue m_frames; // Returns true if we want to verify loss of refclk bool refclk_loss_needs_check(void) const; diff --git a/src/PrbsGenerator.cpp b/src/PrbsGenerator.cpp index 69d6af4..b159bd3 100644 --- a/src/PrbsGenerator.cpp +++ b/src/PrbsGenerator.cpp @@ -22,9 +22,10 @@ #include "PrbsGenerator.h" #include "PcDebug.h" +#include +#include #include #include -#include PrbsGenerator::PrbsGenerator(size_t framesize, uint32_t polynomial, @@ -178,8 +179,8 @@ int PrbsGenerator::process( throw std::runtime_error("PrbsGenerator::process " "input size is not equal to output size!\n"); } - for (size_t i = 0; i < dataOut[0]->getLength(); ++i) { - out[i] ^= in[i]; + for (size_t j = 0; j < dataOut[0]->getLength(); ++j) { + out[j] ^= in[j]; } } diff --git a/src/PuncturingEncoder.cpp b/src/PuncturingEncoder.cpp index 9bd9004..de4319b 100644 --- a/src/PuncturingEncoder.cpp +++ b/src/PuncturingEncoder.cpp @@ -27,6 +27,7 @@ #include "PuncturingEncoder.h" #include "PcDebug.h" +#include #include #include #include diff --git a/src/RemoteControl.cpp b/src/RemoteControl.cpp index ceae942..a050278 100644 --- a/src/RemoteControl.cpp +++ b/src/RemoteControl.cpp @@ -422,11 +422,11 @@ void RemoteControllerZmq::process() std::string msg_s = ss.str(); - zmq::message_t msg(ss.str().size()); - memcpy ((void*) msg.data(), msg_s.data(), msg_s.size()); + zmq::message_t zmsg(ss.str().size()); + memcpy ((void*) zmsg.data(), msg_s.data(), msg_s.size()); int flag = (--cohort_size > 0) ? ZMQ_SNDMORE : 0; - repSocket.send(msg, flag); + repSocket.send(zmsg, flag); } } else if (msg.size() == 2 && command == "show") { @@ -437,11 +437,11 @@ void RemoteControllerZmq::process() for (auto ¶m_val : r) { std::stringstream ss; ss << param_val[0] << ": " << param_val[1] << endl; - zmq::message_t msg(ss.str().size()); - memcpy(msg.data(), ss.str().data(), ss.str().size()); + zmq::message_t zmsg(ss.str().size()); + memcpy(zmsg.data(), ss.str().data(), ss.str().size()); int flag = (--r_size > 0) ? ZMQ_SNDMORE : 0; - repSocket.send(msg, flag); + repSocket.send(zmsg, flag); } } catch (ParameterError &e) { @@ -454,9 +454,9 @@ void RemoteControllerZmq::process() try { std::string value = rcs.get_param(module, parameter); - zmq::message_t msg(value.size()); - memcpy ((void*) msg.data(), value.data(), value.size()); - repSocket.send(msg, 0); + zmq::message_t zmsg(value.size()); + memcpy ((void*) zmsg.data(), value.data(), value.size()); + repSocket.send(zmsg, 0); } catch (ParameterError &err) { send_fail_reply(repSocket, err.what()); diff --git a/src/Resampler.cpp b/src/Resampler.cpp index 2be753e..42951c5 100644 --- a/src/Resampler.cpp +++ b/src/Resampler.cpp @@ -27,10 +27,11 @@ #include "Resampler.h" #include "PcDebug.h" +#include +#include #include #include #include -#include #include #define FFT_REAL(x) x[0] diff --git a/src/Socket.h b/src/Socket.h index f6a023d..39554ca 100644 --- a/src/Socket.h +++ b/src/Socket.h @@ -37,6 +37,7 @@ DESCRIPTION: #include #include #include +#include #include #include #include diff --git a/src/SubchannelSource.cpp b/src/SubchannelSource.cpp index 2a8dc37..b4d6750 100644 --- a/src/SubchannelSource.cpp +++ b/src/SubchannelSource.cpp @@ -28,6 +28,7 @@ #include "PcDebug.h" #include "Log.h" +#include #include #include #include diff --git a/src/TII.cpp b/src/TII.cpp index a30d7f6..af64c9f 100644 --- a/src/TII.cpp +++ b/src/TII.cpp @@ -350,10 +350,10 @@ void TII::set_parameter(const std::string& parameter, const std::string& value) ss >> m_conf.old_variant; } else { - stringstream ss; - ss << "Parameter '" << parameter << + stringstream ss_err; + ss_err << "Parameter '" << parameter << "' is not exported by controllable " << get_rc_name(); - throw ParameterError(ss.str()); + throw ParameterError(ss_err.str()); } } diff --git a/src/TimeInterleaver.cpp b/src/TimeInterleaver.cpp index 3bf6339..7e19af8 100644 --- a/src/TimeInterleaver.cpp +++ b/src/TimeInterleaver.cpp @@ -23,6 +23,7 @@ #include "PcDebug.h" #include +#include #include diff --git a/src/TimestampDecoder.cpp b/src/TimestampDecoder.cpp index ddd3fb7..26deb60 100644 --- a/src/TimestampDecoder.cpp +++ b/src/TimestampDecoder.cpp @@ -228,10 +228,10 @@ void TimestampDecoder::set_parameter( throw ParameterError("timestamp is read-only"); } else { - stringstream ss; - ss << "Parameter '" << parameter + stringstream ss_err; + ss_err << "Parameter '" << parameter << "' is not exported by controllable " << get_rc_name(); - throw ParameterError(ss.str()); + throw ParameterError(ss_err.str()); } } -- cgit v1.2.3 From 3255ff66dab0870c54c8f5c62b1c461b38abfe20 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 22 Dec 2017 09:07:13 +0100 Subject: Check for invalid file output format --- src/DabMod.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/DabMod.cpp') diff --git a/src/DabMod.cpp b/src/DabMod.cpp index 0ac7d4f..dfefb53 100644 --- a/src/DabMod.cpp +++ b/src/DabMod.cpp @@ -199,6 +199,10 @@ static shared_ptr prepare_output( output = make_shared(s.outputName); } + else { + throw runtime_error("File output format " + s.fileOutputFormat + + " not known"); + } } #if defined(HAVE_OUTPUT_UHD) else if (s.useUHDOutput) { -- cgit v1.2.3 From 2a199ca830cb1338b5c52ca5f147ebef26330d22 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 25 Dec 2017 05:08:14 +0100 Subject: Do not use out_of_range for multiplex reconfiguration error --- src/DabMod.cpp | 15 +++++++++------ src/FrameMultiplexer.cpp | 4 ++-- src/FrameMultiplexer.h | 10 ++++++++-- 3 files changed, 19 insertions(+), 10 deletions(-) (limited to 'src/DabMod.cpp') diff --git a/src/DabMod.cpp b/src/DabMod.cpp index dfefb53..b6f2dee 100644 --- a/src/DabMod.cpp +++ b/src/DabMod.cpp @@ -36,6 +36,7 @@ #include "InputMemory.h" #include "OutputFile.h" #include "FormatConverter.h" +#include "FrameMultiplexer.h" #if defined(HAVE_OUTPUT_UHD) # include "OutputUHD.h" #endif @@ -534,17 +535,19 @@ run_modulator_state_t run_modulator(modulator_data& m) running = 0; ret = run_modulator_state_t::normal_end; } - } catch (zmq_input_overflow& e) { + } + catch (const zmq_input_overflow& e) { // The ZeroMQ input has overflowed its buffer etiLog.level(warn) << e.what(); ret = run_modulator_state_t::again; - } catch (std::out_of_range& e) { - // One of the DSP blocks has detected an invalid change - // or value in some settings. This can be due to a multiplex - // reconfiguration. + } + catch (const FrameMultiplexerError& e) { + // The FrameMultiplexer saw an error or a change in the size of a + // subchannel. This can be due to a multiplex reconfiguration. etiLog.level(warn) << e.what(); ret = run_modulator_state_t::reconfigure; - } catch (std::exception& e) { + } + catch (const std::exception& e) { etiLog.level(error) << "Exception caught: " << e.what(); ret = run_modulator_state_t::failure; } diff --git a/src/FrameMultiplexer.cpp b/src/FrameMultiplexer.cpp index 4cee0b2..5dc6dca 100644 --- a/src/FrameMultiplexer.cpp +++ b/src/FrameMultiplexer.cpp @@ -74,7 +74,7 @@ int FrameMultiplexer::process(std::vector dataIn, Buffer* dataOut) // Write subchannel const auto subchannels = m_etiSource.getSubchannels(); if (subchannels.size() != dataIn.size() - 1) { - throw std::out_of_range( + throw FrameMultiplexerError( "FrameMultiplexer detected subchannel size change from " + std::to_string(dataIn.size() - 1) + " to " + std::to_string(subchannels.size())); @@ -82,7 +82,7 @@ int FrameMultiplexer::process(std::vector dataIn, Buffer* dataOut) auto subchannel = subchannels.begin(); while (in != dataIn.end()) { if ((*subchannel)->framesizeCu() * 8 != (*in)->getLength()) { - throw std::out_of_range( + throw FrameMultiplexerError( "FrameMultiplexer detected invalid subchannel size! " + std::to_string((*subchannel)->framesizeCu() * 8) + " != " + std::to_string((*in)->getLength())); diff --git a/src/FrameMultiplexer.h b/src/FrameMultiplexer.h index 680cdc7..4d68d88 100644 --- a/src/FrameMultiplexer.h +++ b/src/FrameMultiplexer.h @@ -38,12 +38,18 @@ #include +class FrameMultiplexerError : public std::runtime_error { + public: + FrameMultiplexerError(const char* msg) : + std::runtime_error(msg) {} + FrameMultiplexerError(const std::string& msg) : + std::runtime_error(msg) {} +}; class FrameMultiplexer : public ModMux { public: - FrameMultiplexer( - const EtiSource& etiSource); + FrameMultiplexer(const EtiSource& etiSource); int process(std::vector dataIn, Buffer* dataOut); const char* name() { return "FrameMultiplexer"; } -- cgit v1.2.3