diff --git a/src/FPGA_common/FPGA_common.cpp b/src/FPGA_common/FPGA_common.cpp index e65cd46dd..71d674f14 100644 --- a/src/FPGA_common/FPGA_common.cpp +++ b/src/FPGA_common/FPGA_common.cpp @@ -13,17 +13,11 @@ using namespace std; #ifndef NDEBUG #define ASSERT_WARNING(cond, message) \ if (!cond) \ - printf("W: %s (%s)\n", message, #cond) + lime::warning("W: %s (%s)", message, #cond) #else #define ASSERT_WARNING(cond, message) #endif -#if 0 - #define verbose_printf(...) printf(__VA_ARGS__); -#else - #define verbose_printf(...) -#endif - namespace lime { /** @brief A class for writing a batch of registers into the FPGA. */ @@ -119,7 +113,7 @@ FPGA::FPGA(std::shared_ptr fpgaSPI, std::shared_ptr lms7002mSPI) void FPGA::EnableValuesCache(bool enabled) { - verbose_printf("Enable FPGA registers cache: %s\n", enabled ? "true" : "false"); + lime::debug("Enable FPGA registers cache: %s", enabled ? "true" : "false"); useCache = enabled; if (!useCache) regsCache.clear(); @@ -309,7 +303,7 @@ int FPGA::ReadRegisters(const uint32_t* addrs, uint32_t* data, unsigned cnt) int FPGA::StartStreaming() { - verbose_printf("%s\n", __func__); + lime::debug("%s", __func__); int interface_ctrl_000A = ReadRegister(0x000A); if (interface_ctrl_000A < 0) return -1; @@ -319,7 +313,7 @@ int FPGA::StartStreaming() int FPGA::StopStreaming() { - verbose_printf("%s\n", __func__); + lime::debug("%s", __func__); int interface_ctrl_000A = ReadRegister(0x000A); if (interface_ctrl_000A < 0) return -1; @@ -329,7 +323,7 @@ int FPGA::StopStreaming() int FPGA::ResetTimestamp() { - verbose_printf("%s\n", __func__); + lime::debug("%s", __func__); #ifndef NDEBUG int interface_ctrl_000A = ReadRegister(0x000A); if (interface_ctrl_000A < 0) @@ -356,7 +350,7 @@ int FPGA::WaitTillDone(uint16_t pollAddr, uint16_t doneMask, uint16_t errorMask, uint16_t error = 0; if (!title.empty()) { - verbose_printf("%s\n", title.c_str()); + lime::debug("%s", title.c_str()); } do { @@ -382,7 +376,7 @@ int FPGA::WaitTillDone(uint16_t pollAddr, uint16_t doneMask, uint16_t errorMask, } while (!done); if (!title.empty()) { - verbose_printf("%s done\n", title.c_str()); + lime::debug(title + " done"s); } return 0; } @@ -445,7 +439,7 @@ int FPGA::SetPllClock(uint8_t clockIndex, int nSteps, bool waitLock, bool doPhas */ int FPGA::SetPllFrequency(const uint8_t pllIndex, const double inputFreq, FPGA_PLL_clock* clocks, const uint8_t clockCount) { - verbose_printf("FPGA SetPllFrequency: PLL[%i] input:%.3f MHz clockCount:%i\n", pllIndex, inputFreq / 1e6, clockCount); + lime::debug("FPGA SetPllFrequency: PLL[%i] input:%.3f MHz clockCount:%i", pllIndex, inputFreq / 1e6, clockCount); WriteRegistersBatch batch(this); const auto timeout = chrono::seconds(3); if (not fpgaPort) @@ -463,7 +457,7 @@ int FPGA::SetPllFrequency(const uint8_t pllIndex, const double inputFreq, FPGA_P return ReportError(ERANGE, "FPGA SetPllFrequency: PLL[%i] input frequency must be >=%g MHz", pllIndex, PLLlowerLimit / 1e6); for (int i = 0; i < clockCount; ++i) { - verbose_printf("CLK[%i] Fout:%.3f MHz bypass:%i phase:%g findPhase: %i\n", + lime::debug("CLK[%i] Fout:%.3f MHz bypass:%i phase:%g findPhase: %i", clocks[i].index, clocks[i].outFrequency / 1e6, clocks[i].bypass, @@ -528,7 +522,7 @@ int FPGA::SetPllFrequency(const uint8_t pllIndex, const double inputFreq, FPGA_P } } if (desiredVCO.size() == 0) - return ReportError(EINVAL, "FPGA SetPllFrequency: no suitable VCO frequencies found for requested clocks\n"); + return ReportError(EINVAL, "FPGA SetPllFrequency: no suitable VCO frequencies found for requested clocks"); // Find VCO that satisfies most outputs with integer dividers uint64_t bestFreqVCO = std::max_element( @@ -938,7 +932,7 @@ int FPGA::UploadWFM(const void* const* samples, uint8_t chCount, size_t sample_c */ int FPGA::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, double txPhase, double rxPhase, int channel) { - verbose_printf("FPGA::SetInterfaceFreq tx:%.3f MHz rx:%.3f MHz txPhase:%g rxPhase:%g ch:%i\n", + lime::debug("FPGA::SetInterfaceFreq tx:%.3f MHz rx:%.3f MHz txPhase:%g rxPhase:%g ch:%i", txRate_Hz / 1e6, rxRate_Hz / 1e6, txPhase, @@ -985,7 +979,7 @@ int FPGA::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, double txPhase, d */ int FPGA::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int chipIndex) { - verbose_printf("FPGA::SetInterfaceFreq tx:%.3f MHz rx:%.3f MHz chipIndex:%i\n", txRate_Hz / 1e6, rxRate_Hz / 1e6, chipIndex); + lime::debug("FPGA::SetInterfaceFreq tx:%.3f MHz rx:%.3f MHz chipIndex:%i", txRate_Hz / 1e6, rxRate_Hz / 1e6, chipIndex); //PrintStackTrace(); const int pll_ind = (chipIndex == 1) ? 2 : 0; int status = 0; @@ -1083,7 +1077,7 @@ int FPGA::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int chipIndex) } else { - verbose_printf("Retry%i: SetPllFrequency\n", i); + lime::debug("Retry%i: SetPllFrequency", i); std::this_thread::sleep_for(busyPollPeriod); } } @@ -1133,7 +1127,7 @@ int FPGA::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int chipIndex) } else { - verbose_printf("Retry%i: SetPllFrequency\n", i); + lime::debug("Retry%i: SetPllFrequency", i); std::this_thread::sleep_for(busyPollPeriod); } } @@ -1188,7 +1182,7 @@ int FPGA::ReadRawStreamData(char* buffer, unsigned length, int epIndex, int time double FPGA::DetectRefClk(double fx3Clk) { - verbose_printf("FPGA::DetectRefClk fx3Clk:%g\n", fx3Clk); + lime::debug("FPGA::DetectRefClk fx3Clk:%g", fx3Clk); const double fx3Cnt = 16777210; //fixed fx3 counter in FPGA const double clkTbl[] = { 10e6, 30.72e6, 38.4e6, 40e6, 52e6 }; const uint32_t addr[] = { 0x61, 0x63 }; diff --git a/src/GUI/ILMS7002MTab.cpp b/src/GUI/ILMS7002MTab.cpp index 9c36d802f..6ef9bb744 100644 --- a/src/GUI/ILMS7002MTab.cpp +++ b/src/GUI/ILMS7002MTab.cpp @@ -3,8 +3,10 @@ #include "lms7002_gui_utilities.h" #include "limesuite/LMS7002M.h" +#include "Logger.h" using namespace lime; +using namespace std::literals::string_literals; ILMS7002MTab::ILMS7002MTab(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) : wxPanel(parent, id, pos, size, style) @@ -34,7 +36,7 @@ void ILMS7002MTab::ParameterChangeHandler(wxCommandEvent& event) parameter = wndId2Enum.at(reinterpret_cast(event.GetEventObject())); } catch (std::exception& e) { - std::cout << "Control element(ID = " << event.GetId() << ") don't have assigned LMS parameter." << std::endl; + lime::error("Control element(ID = "s + std::to_string(event.GetId()) + ") don't have assigned LMS parameter."s); return; } WriteParam(parameter, event.GetInt()); diff --git a/src/LMS_Programing/LMS_Programing_wxgui.cpp b/src/LMS_Programing/LMS_Programing_wxgui.cpp index 9c4b83c5a..4fef73ccc 100644 --- a/src/LMS_Programing/LMS_Programing_wxgui.cpp +++ b/src/LMS_Programing/LMS_Programing_wxgui.cpp @@ -289,7 +289,7 @@ void LMS_Programing_wxgui::DoProgramming() evt.SetEventObject(this); evt.SetId(ID_PROGRAMING_FINISHED_EVENT); evt.SetEventType(wxEVT_COMMAND_THREAD); - evt.SetString(status == 0 ? _("Programming Completed!") : _("Programming failed!\n")); + evt.SetString(status == 0 ? _("Programming Completed!") : _("Programming failed!")); wxPostEvent(this, evt); mProgrammingInProgress.store(false); diff --git a/src/Logger.h b/src/Logger.h index 7b69b4219..dcbbecd0c 100644 --- a/src/Logger.h +++ b/src/Logger.h @@ -24,6 +24,7 @@ enum class LogLevel : uint8_t { DEBUG, //!< A debugging message, only shown in Debug configuration. }; +// C-string versions //! Log a critical error message with formatting static inline void critical(const char* format, ...); @@ -42,6 +43,25 @@ static inline void debug(const char* format, ...); //! Log a message with formatting and specified logging level static inline void log(const LogLevel level, const char* format, ...); +// C++ std::string versions +//! Log a critical error message +static inline void critical(const std::string& text); + +//! Log an error message +static inline int error(const std::string& text); + +//! Log a warning message +static inline void warning(const std::string& text); + +//! Log an information message +static inline void info(const std::string& text); + +//! Log a debug message +static inline void debug(const std::string& text); + +//! Log a message with specified logging level +static inline void log(const LogLevel level, const std::string& text); + /*! * Send a message to the registered logger. * \param level a possible logging level @@ -64,6 +84,44 @@ LIME_API void registerLogHandler(const LogHandler handler); //! Convert log level to a string name for printing LIME_API const char* logLevelToName(const LogLevel level); +/*! + * Get the error code to string + any optional message reported. + */ +LIME_API const char* GetLastErrorMessage(void); + +/*! + * Report a typical errno style error. + * The resulting error message comes from strerror(). + * \param errnum a recognized error code + * \return a non-zero status code to return + */ +LIME_API int ReportError(const int errnum); + +/*! + * Report an error as an integer code and a formatted message string. + * \param errnum a recognized error code + * \param format a format string followed by args + * \return a non-zero status code to return + */ +inline int ReportError(const int errnum, const char* format, ...); + +/*! + * Report an error as a formatted message string. + * The reported errnum is 0 - no relevant error code. + * \param format a format string followed by args + * \return a non-zero status code to return + */ +inline int ReportError(const char* format, ...); + +/*! + * Report an error as an integer code and message format arguments + * \param errnum a recognized error code + * \param format a printf-style format string + * \param argList the format string args as a va_list + * \return a non-zero status code to return + */ +LIME_API int ReportError(const int errnum, const char* format, va_list argList); + } // namespace lime static inline void lime::log(const LogLevel level, const char* format, ...) @@ -115,47 +173,37 @@ static inline void lime::debug(const char* format, ...) va_end(args); } -namespace lime { - -/*! - * Get the error code to string + any optional message reported. - */ -LIME_API const char* GetLastErrorMessage(void); +static inline void lime::critical(const std::string& text) +{ + lime::log(lime::LogLevel::CRITICAL, text); +} -/*! - * Report a typical errno style error. - * The resulting error message comes from strerror(). - * \param errnum a recognized error code - * \return a non-zero status code to return - */ -LIME_API int ReportError(const int errnum); +static inline int lime::error(const std::string& text) +{ + lime::log(lime::LogLevel::ERROR, text); + return -1; +} -/*! - * Report an error as an integer code and a formatted message string. - * \param errnum a recognized error code - * \param format a format string followed by args - * \return a non-zero status code to return - */ -inline int ReportError(const int errnum, const char* format, ...); +static inline void lime::warning(const std::string& text) +{ + lime::log(lime::LogLevel::WARNING, text); +} -/*! - * Report an error as a formatted message string. - * The reported errnum is 0 - no relevant error code. - * \param format a format string followed by args - * \return a non-zero status code to return - */ -inline int ReportError(const char* format, ...); +static inline void lime::info(const std::string& text) +{ + lime::log(lime::LogLevel::INFO, text); +} -/*! - * Report an error as an integer code and message format arguments - * \param errnum a recognized error code - * \param format a printf-style format string - * \param argList the format string args as a va_list - * \return a non-zero status code to return - */ -LIME_API int ReportError(const int errnum, const char* format, va_list argList); +static inline void lime::debug(const std::string& text) +{ + lime::log(lime::LogLevel::DEBUG, text); +} -} // namespace lime +//! Log a message with formatting and specified logging level +static inline void lime::log(const LogLevel level, const std::string& text) +{ + lime::log(level, "%s", text.c_str()); +} inline int lime::ReportError(const int errnum, const char* format, ...) { diff --git a/src/Si5351C/Si5351C.cpp b/src/Si5351C/Si5351C.cpp index b9d671862..b2397707e 100644 --- a/src/Si5351C/Si5351C.cpp +++ b/src/Si5351C/Si5351C.cpp @@ -565,7 +565,7 @@ Si5351C::Status Si5351C::UploadConfiguration() return Status::SUCCESS; } catch (std::runtime_error& e) { - printf("Si5351C configuration failed %s\n", e.what()); + lime::error("Si5351C configuration failed %s", e.what()); return Status::FAILED; } } @@ -746,9 +746,7 @@ void Si5351C::FindVCO(Si5351_Channel* clocks, Si5351_PLL* plls, const unsigned l bestVCOA = it->first; } } - //scores calculated - //cout << "PLLA stage: " << endl; - //cout << "best score: " << bestScore << " best VCO: " << bestVCOA << endl; + plls[0].VCO_Hz = bestVCOA; plls[0].feedbackDivider = (double)bestVCOA / plls[0].inputFreqHz; @@ -815,9 +813,7 @@ void Si5351C::FindVCO(Si5351_Channel* clocks, Si5351_PLL* plls, const unsigned l bestVCOB = it->first; } } - //scores calculated - // cout << "PLLB stage: " << endl; - // cout << "best score: " << bestScore << " best VCO: " << bestVCOB << endl; + if (bestVCOB == 0) //just in case if pllb is not used make it the same frequency as plla bestVCOB = bestVCOA; plls[1].VCO_Hz = bestVCOB; @@ -1091,7 +1087,7 @@ Si5351C::Status Si5351C::ClearStatus() return Status::SUCCESS; } catch (std::runtime_error& e) { - printf("Si5351C configuration failed %s\n", e.what()); + lime::error("Si5351C configuration failed %s", e.what()); return Status::FAILED; } } diff --git a/src/boards/DeviceRegistry.cpp b/src/boards/DeviceRegistry.cpp index 836330388..0e8a02b4d 100644 --- a/src/boards/DeviceRegistry.cpp +++ b/src/boards/DeviceRegistry.cpp @@ -1,17 +1,14 @@ #include "limesuite/DeviceRegistry.h" #include "limesuite/SDRDevice.h" +#include "Logger.h" #include #include #include #include #include // alternative operators for visual c++: not, and, or... -using namespace lime; -#if 0 - #define verbose_printf(...) printf(__VA_ARGS__) -#else - #define verbose_printf(...) -#endif +using namespace lime; +using namespace std::literals::string_literals; static std::mutex gRegistryMutex; static std::map registryEntries; @@ -87,12 +84,12 @@ DeviceRegistryEntry::DeviceRegistryEntry(const std::string& name) { std::lock_guard lock(gRegistryMutex); registryEntries[_name] = this; - verbose_printf("DeviceRegistry Added: %s\n", _name.c_str()); + lime::debug("DeviceRegistry Added: "s + _name); } DeviceRegistryEntry::~DeviceRegistryEntry(void) { std::lock_guard lock(gRegistryMutex); registryEntries.erase(_name); - verbose_printf("DeviceRegistry Removed: %s\n", _name.c_str()); + lime::debug("DeviceRegistry Removed: "s + _name); } diff --git a/src/boards/LimeSDR/LimeSDR.cpp b/src/boards/LimeSDR/LimeSDR.cpp index 0ac335ab5..a3270d41b 100644 --- a/src/boards/LimeSDR/LimeSDR.cpp +++ b/src/boards/LimeSDR/LimeSDR.cpp @@ -276,7 +276,7 @@ void LimeSDR::Configure(const SDRConfig& cfg, uint8_t moduleIndex = 0) } //try catch (std::logic_error& e) { - printf("LimeSDR config: %s\n", e.what()); + lime::error("LimeSDR config: %s", e.what()); throw; } catch (std::runtime_error& e) { diff --git a/src/boards/LimeSDR_Mini/LimeSDR_Mini.cpp b/src/boards/LimeSDR_Mini/LimeSDR_Mini.cpp index 4e53b736f..d9d4d6179 100644 --- a/src/boards/LimeSDR_Mini/LimeSDR_Mini.cpp +++ b/src/boards/LimeSDR_Mini/LimeSDR_Mini.cpp @@ -294,7 +294,7 @@ void LimeSDR_Mini::Configure(const SDRConfig& cfg, uint8_t moduleIndex = 0) } //try catch (std::logic_error& e) { - printf("LimeSDR_Mini config: %s\n", e.what()); + lime::error("LimeSDR_Mini config: %s", e.what()); throw; } catch (std::runtime_error& e) { diff --git a/src/boards/LimeSDR_X3/FPGA_X3.cpp b/src/boards/LimeSDR_X3/FPGA_X3.cpp index a93d3c6b4..dea24eda8 100644 --- a/src/boards/LimeSDR_X3/FPGA_X3.cpp +++ b/src/boards/LimeSDR_X3/FPGA_X3.cpp @@ -8,6 +8,8 @@ #include "Register.h" +using namespace std::literals::string_literals; + namespace lime { FPGA_X3::FPGA_X3(std::shared_ptr fpgaSPI, std::shared_ptr lms7002mSPI) @@ -19,8 +21,8 @@ int FPGA_X3::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, double txPhase { FPGA::FPGA_PLL_clock clocks[2]; - std::cerr << "FPGA_X3" << std::endl; - printf("Phases : tx phase %f rx phase %f \n", txPhase, rxPhase); + lime::debug("FPGA_X3"s); + lime::info("Phases : tx phase %f rx phase %f", txPhase, rxPhase); clocks[0].index = 0; clocks[0].outFrequency = rxRate_Hz; diff --git a/src/boards/LimeSDR_X3/LimeSDR_X3.cpp b/src/boards/LimeSDR_X3/LimeSDR_X3.cpp index f8eaa8822..6ed1fc775 100644 --- a/src/boards/LimeSDR_X3/LimeSDR_X3.cpp +++ b/src/boards/LimeSDR_X3/LimeSDR_X3.cpp @@ -634,7 +634,7 @@ void LimeSDR_X3::Configure(const SDRConfig& cfg, uint8_t socIndex) } //try catch (std::logic_error& e) { - printf("LimeSDR_X3 config: %s\n", e.what()); + lime::error("LimeSDR_X3 config: %s", e.what()); throw; } catch (std::runtime_error& e) { @@ -890,11 +890,11 @@ int LimeSDR_X3::StreamSetup(const StreamConfig& config, uint8_t moduleIndex) return 0; } catch (std::logic_error& e) { - printf("LimeSDR_X3::StreamSetup logic_error %s\n", e.what()); + lime::error("LimeSDR_X3::StreamSetup logic_error %s", e.what()); throw; } catch (std::runtime_error& e) { - printf("LimeSDR_X3::StreamSetup runtime_error %s\n", e.what()); + lime::error("LimeSDR_X3::StreamSetup runtime_error %s", e.what()); throw; } } diff --git a/src/boards/LimeSDR_XTRX/FPGA_XTRX.cpp b/src/boards/LimeSDR_XTRX/FPGA_XTRX.cpp index 3b6d90a4c..705c2ff45 100644 --- a/src/boards/LimeSDR_XTRX/FPGA_XTRX.cpp +++ b/src/boards/LimeSDR_XTRX/FPGA_XTRX.cpp @@ -8,6 +8,8 @@ #include "Register.h" +using namespace std::literals::string_literals; + namespace lime { FPGA_XTRX::FPGA_XTRX(std::shared_ptr fpgaSPI, std::shared_ptr lms7002mSPI) @@ -19,8 +21,8 @@ int FPGA_XTRX::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, double txPha { lime::FPGA::FPGA_PLL_clock clocks[2]; - std::cerr << "FPGA_XTRX" << std::endl; - printf("Phases : tx phase %f rx phase %f \n", txPhase, rxPhase); + lime::debug("FPGA_XTRX"s); + lime::info("Phases: tx phase %f rx phase %f", txPhase, rxPhase); clocks[0].index = 0; clocks[0].outFrequency = rxRate_Hz; diff --git a/src/boards/LimeSDR_XTRX/LimeSDR_XTRX.cpp b/src/boards/LimeSDR_XTRX/LimeSDR_XTRX.cpp index 60ce127ac..a5727ee07 100644 --- a/src/boards/LimeSDR_XTRX/LimeSDR_XTRX.cpp +++ b/src/boards/LimeSDR_XTRX/LimeSDR_XTRX.cpp @@ -357,7 +357,7 @@ void LimeSDR_XTRX::Configure(const SDRConfig& cfg, uint8_t socIndex) } //try catch (std::logic_error& e) { - printf("LimeSDR_XTRX config: %s\n", e.what()); + lime::error("LimeSDR_XTRX config: %s", e.what()); throw; } catch (std::runtime_error& e) { @@ -456,11 +456,11 @@ int LimeSDR_XTRX::StreamSetup(const StreamConfig& config, uint8_t moduleIndex) return 0; } catch (std::logic_error& e) { - printf("LimeSDR_XTRX::StreamSetup logic_error %s\n", e.what()); + lime::error("LimeSDR_XTRX::StreamSetup logic_error %s", e.what()); throw; } catch (std::runtime_error& e) { - printf("LimeSDR_XTRX::StreamSetup runtime_error %s\n", e.what()); + lime::error("LimeSDR_XTRX::StreamSetup runtime_error %s", e.what()); throw; } } diff --git a/src/boards/MMX8/MM_X8.cpp b/src/boards/MMX8/MM_X8.cpp index f3d0243d2..7c43ee4b4 100644 --- a/src/boards/MMX8/MM_X8.cpp +++ b/src/boards/MMX8/MM_X8.cpp @@ -122,7 +122,7 @@ void LimeSDR_MMX8::Configure(const SDRConfig& cfg, uint8_t socIndex) } //try catch (std::logic_error& e) { - printf("LimeSDR_MMX8 config: %s\n", e.what()); + lime::error("LimeSDR_MMX8 config: %s", e.what()); throw; } catch (std::runtime_error& e) { diff --git a/src/comms/PCIe/LitePCIe.cpp b/src/comms/PCIe/LitePCIe.cpp index bb3372e1c..e16764d3b 100644 --- a/src/comms/PCIe/LitePCIe.cpp +++ b/src/comms/PCIe/LitePCIe.cpp @@ -13,6 +13,7 @@ using namespace std; using namespace lime; +using namespace std::literals::string_literals; #define EXTRA_CHECKS 1 @@ -52,7 +53,7 @@ int LitePCIe::Open(const std::string& deviceFilename, uint32_t flags) if (mFileDescriptor < 0) { isConnected = false; - printf("LitePCIe: Failed to open (%s), errno(%i) %s\n", mFilePath.c_str(), errno, strerror(errno)); + lime::error("LitePCIe: Failed to open (%s), errno(%i) %s", mFilePath.c_str(), errno, strerror(errno)); return -1; } @@ -183,15 +184,13 @@ int LitePCIe::WriteRaw(const uint8_t* buffer, const int length, int timeout_ms) switch (errno) { case EAGAIN: - //printf("Write EAGAIN %i\n", bytesRemaining); bytesOut = 0; break; - //return totalBytesReceived; case EINTR: - printf("Write EINTR\n"); + lime::error("Write EINTR"s); continue; default: - printf("Write default\n"); + lime::error("Write default"s); return errno; } } @@ -205,16 +204,16 @@ int LitePCIe::WriteRaw(const uint8_t* buffer, const int length, int timeout_ms) std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - t1).count(); if (pollTimeout <= 0) break; - printf("poll for %ims\n", pollTimeout); + lime::debug("poll for %ims", pollTimeout); int ret = poll(&desc, 1, pollTimeout); if (ret < 0) { - printf("Write poll errno(%i) %s\n", errno, strerror(errno)); + lime::error("Write poll errno(%i) %s", errno, strerror(errno)); return -errno; } else if (ret == 0) // timeout { - printf("Write poll timeout %i\n", pollTimeout); + lime::error("Write poll timeout %i", pollTimeout); break; } continue; @@ -240,20 +239,16 @@ int LitePCIe::ReadRaw(uint8_t* buffer, const int length, int timeout_ms) if (bytesIn < 0) { - //printf("read errno %i, bytesIn: %i\n", errno, bytesIn); switch (errno) { case EAGAIN: - //printf("Read EAGAIN, bytes remaining: %i\n", bytesRemaining); bytesIn = 0; return length - bytesRemaining; - break; - //return totalBytesReceived; case EINTR: - printf("Read EINTR\n"); + lime::error("Read EINTR"s); continue; default: - printf("Read default\n"); + lime::error("Read default"s); return -errno; } } @@ -269,18 +264,18 @@ int LitePCIe::ReadRaw(uint8_t* buffer, const int length, int timeout_ms) std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - t1).count(); if (pollTimeout <= 0) { - printf("Read poll timeout of %i\n", pollTimeout); + lime::error("Read poll timeout of %i", pollTimeout); return length - bytesRemaining; } int ret = poll(&desc, 1, pollTimeout); if (ret < 0) { - printf("Read poll errno(%i) %s\n", errno, strerror(errno)); + lime::error("Read poll errno(%i) %s", errno, strerror(errno)); return -errno; } else if (ret == 0) // timeout { - printf("Read poll timeout %i\n", timeout_ms); + lime::error("Read poll timeout %i", timeout_ms); break; } continue; @@ -288,7 +283,7 @@ int LitePCIe::ReadRaw(uint8_t* buffer, const int length, int timeout_ms) #ifdef EXTRA_CHECKS if (bytesIn > bytesRemaining) { - printf("LitePCIe::ReadRaw read expected(%i), returned(%i)\n", bytesRemaining, bytesIn); + lime::error("LitePCIe::ReadRaw read expected(%i), returned(%i)", bytesRemaining, bytesIn); return -1; } #endif @@ -298,10 +293,10 @@ int LitePCIe::ReadRaw(uint8_t* buffer, const int length, int timeout_ms) std::chrono::duration_cast(chrono::high_resolution_clock::now() - t1).count() < timeout_ms); #ifdef EXTRA_CHECKS // if (bytesRemaining > 0) - // printf("LitePCIe::ReadRaw %i bytes remaining after timeout\n", bytesRemaining); + // lime::error("LitePCIe::ReadRaw %i bytes remaining after timeout", bytesRemaining); // auto rdTime = std::chrono::duration_cast(chrono::high_resolution_clock::now() - t1).count(); // if(rdTime > 100) - // printf("ReadRaw too long %i\n", rdTime); + // lime::error("ReadRaw too long %i", rdTime); #endif return length - bytesRemaining; } @@ -322,7 +317,7 @@ void LitePCIe::RxDMAEnable(bool enabled, uint32_t bufferSize, uint8_t irqPeriod) } int ret = ioctl(mFileDescriptor, LITEPCIE_IOCTL_DMA_WRITER, &writer); if (ret < 0) - printf("Failed DMA writer ioctl. errno(%i) %s\n", errno, strerror(errno)); + lime::error("Failed DMA writer ioctl. errno(%i) %s", errno, strerror(errno)); } void LitePCIe::TxDMAEnable(bool enabled) @@ -336,7 +331,7 @@ void LitePCIe::TxDMAEnable(bool enabled) reader.sw_count = 0; int ret = ioctl(mFileDescriptor, LITEPCIE_IOCTL_DMA_READER, &reader); if (ret < 0) - printf("Failed DMA reader ioctl. err(%i) %s\n", errno, strerror(errno)); + lime::error("Failed DMA reader ioctl. err(%i) %s", errno, strerror(errno)); } LitePCIe::DMAState LitePCIe::GetRxDMAState() @@ -388,7 +383,7 @@ bool LitePCIe::WaitRx() } else if (ret == 0) { - //printf("PollRx timeout\n"); + //lime::error("PollRx timeout"s); } else { @@ -422,7 +417,7 @@ bool LitePCIe::WaitTx() } else if (ret == 0) { - //printf("PollTx timeout\n"); + //lime::error("PollTx timeout"s); } else { diff --git a/src/comms/PCIe/TRXLooper_PCIE.cpp b/src/comms/PCIe/TRXLooper_PCIE.cpp index f65ec32f5..75c182205 100644 --- a/src/comms/PCIe/TRXLooper_PCIE.cpp +++ b/src/comms/PCIe/TRXLooper_PCIE.cpp @@ -128,9 +128,9 @@ TRXLooper_PCIE::~TRXLooper_PCIE() void TRXLooper_PCIE::Setup(const SDRDevice::StreamConfig& config) { if (config.channels.at(lime::TRXDir::Rx).size() > 0 && !mRxArgs.port->IsOpen()) - throw std::runtime_error("Rx data port not open\n"); + throw std::runtime_error("Rx data port not open"); if (config.channels.at(lime::TRXDir::Tx).size() > 0 && !mTxArgs.port->IsOpen()) - throw std::runtime_error("Tx data port not open\n"); + throw std::runtime_error("Tx data port not open"); float combinedSampleRate = std::max(config.channels.at(lime::TRXDir::Tx).size(), config.channels.at(lime::TRXDir::Rx).size()) * config.hintSampleRate; @@ -149,7 +149,7 @@ void TRXLooper_PCIE::Setup(const SDRDevice::StreamConfig& config) mRx.packetsToBatch = 4; mTx.packetsToBatch = 6; mRx.packetsToBatch = 6; - //printf("Batch size %i\n", batchSize); + //lime::debug("Batch size %i", batchSize); fpga->WriteRegister(0xFFFF, 1 << chipId); fpga->StopStreaming(); @@ -186,7 +186,7 @@ int TRXLooper_PCIE::TxSetup() if (mConfig.extraConfig.txSamplesInPacket != 0) { samplesInPkt = mConfig.extraConfig.txSamplesInPacket; - printf("Tx samples overide %i\n", samplesInPkt); + lime::debug("Tx samples overide %i", samplesInPkt); } mTx.samplesInPkt = samplesInPkt; @@ -215,7 +215,7 @@ int TRXLooper_PCIE::TxSetup() { char msg[256]; sprintf(msg, - "Stream%i samplesInTxPkt:%i maxTxPktInBatch:%i, batchSizeInTime:%gus\n", + "Stream%i samplesInTxPkt:%i maxTxPktInBatch:%i, batchSizeInTime:%gus", chipId, samplesInPkt, mTx.packetsToBatch, @@ -329,14 +329,14 @@ template class TxBufferManager int extraBytes = bytesUsed % busWidthBytes; if (extraBytes != 0) { - //printf("Patch buffer, bytes %i, extra: %i, last payload: %i\n", bytesUsed, extraBytes, payloadSize); + //lime::debug("Patch buffer, bytes %i, extra: %i, last payload: %i", bytesUsed, extraBytes, payloadSize); // patch last packet so that whole buffer size would be multiple of bus width int padding = busWidthBytes - extraBytes; memset(payloadPtr, 0, padding); payloadSize += padding; bytesUsed += padding; header->SetPayloadSize(payloadSize); - //printf("Patch buffer, bytes %i, last payload: %i\n", bytesUsed, payloadSize); + //lime::debug("Patch buffer, bytes %i, last payload: %i", bytesUsed, payloadSize); } break; } @@ -378,13 +378,13 @@ void FPGATxState(FPGA* fpga) pendingTxTS |= (uint64_t)words[2] << 32; pendingTxTS |= (uint64_t)words[3] << 48; if (i < 4) - printf("Buf%i: %08lX\n", i, pendingTxTS); + lime::debug("Buf%i: %08lX", i, pendingTxTS); else - printf("Rx: %08lX\n", pendingTxTS); + lime::debug("Rx: %08lX", pendingTxTS); } uint16_t bufs = fpga->ReadRegister(0x0075); - printf("currentIndex: %i, ready: %0X\n", bufs & 0xF, (bufs >> 4) & 0xF); + lime::debug("currentIndex: %i, ready: %0X", bufs & 0xF, (bufs >> 4) & 0xF); } void TRXLooper_PCIE::TransmitPacketsLoop() @@ -589,7 +589,7 @@ void TRXLooper_PCIE::TransmitPacketsLoop() { if (errno == EINVAL) { - printf("Failed to submit dma write (%i) %s\n", errno, strerror(errno)); + lime::error("Failed to submit dma write (%i) %s", errno, strerror(errno)); return; } mTxArgs.port->WaitTx(); @@ -597,7 +597,7 @@ void TRXLooper_PCIE::TransmitPacketsLoop() } else { - //printf("Sent sw: %li hw: %li, diff: %li\n", stagingBufferIndex, reader.hw_count, stagingBufferIndex-reader.hw_count); + //lime::debug("Sent sw: %li hw: %li, diff: %li", stagingBufferIndex, reader.hw_count, stagingBufferIndex-reader.hw_count); outputReady = false; pendingWrites.push(wrInfo); transferSize.Add(wrInfo.size); @@ -651,7 +651,7 @@ void TRXLooper_PCIE::TransmitPacketsLoop() (mConfig.hintSampleRate ? "us" : ""), fifo->size()); if (showStats) - printf("%s\n", msg); + lime::info("%s", msg); if (mCallback_logMessage) { bool showAsWarning = underrun.delta() || loss.delta(); @@ -684,7 +684,7 @@ void TRXLooper_PCIE::TxTeardown() { char msg[256]; sprintf(msg, - "Tx Loop totals: packets sent: %li (0x%08lX) , FPGA packet counter: %i (0x%08X), diff: %li, FPGA tx drops: %i\n", + "Tx Loop totals: packets sent: %li (0x%08lX) , FPGA packet counter: %i (0x%08X), diff: %li, FPGA tx drops: %i", mTx.stats.packets, mTx.stats.packets, fpgaTxPktIngressCount, @@ -749,7 +749,7 @@ int TRXLooper_PCIE::RxSetup() { char msg[256]; sprintf(msg, - "Stream%i usePoll:%i rxSamplesInPkt:%i rxPacketsInBatch:%i, DMA_ReadSize:%i, batchSizeInTime:%gus\n", + "Stream%i usePoll:%i rxSamplesInPkt:%i rxPacketsInBatch:%i, DMA_ReadSize:%i, batchSizeInTime:%gus", chipId, usePoll ? 1 : 0, samplesInPkt, @@ -874,7 +874,7 @@ void TRXLooper_PCIE::ReceivePacketsLoop() dma.hwIndex - dma.swIndex, mRx.fifo->size()); if (showStats) - printf("%s\n", msg); + lime::info("%s", msg); if (mCallback_logMessage) { bool showAsWarning = overrun.delta() || loss.delta(); @@ -926,7 +926,7 @@ void TRXLooper_PCIE::ReceivePacketsLoop() pkt = reinterpret_cast(&buffer[packetSize * i]); if (pkt->counter - expectedTS != 0) { - //printf("Loss: pkt:%i exp: %li, got: %li, diff: %li\n", stats.packets+i, expectedTS, pkt->counter, pkt->counter-expectedTS); + //lime::info("Loss: pkt:%i exp: %li, got: %li, diff: %li", stats.packets+i, expectedTS, pkt->counter, pkt->counter-expectedTS); ++stats.loss; loss.add(1); } @@ -986,7 +986,7 @@ void TRXLooper_PCIE::ReceivePacketsLoop() if (mCallback_logMessage) { char msg[256]; - sprintf(msg, "Rx%i: packetsIn: %li\n", chipId, stats.packets); + sprintf(msg, "Rx%i: packetsIn: %li", chipId, stats.packets); mCallback_logMessage(SDRDevice::LogLevel::DEBUG, msg); } } @@ -1074,7 +1074,7 @@ int TRXLooper_PCIE::UploadTxWaveform(FPGA* fpga, if (errno == EINVAL) { port->TxDMAEnable(false); - printf("Failed to submit dma write (%i) %s\n", errno, strerror(errno)); + lime::error("Failed to submit dma write (%i) %s", errno, strerror(errno)); return -1; } } diff --git a/src/comms/USB/TRXLooper_USB.cpp b/src/comms/USB/TRXLooper_USB.cpp index d1506c09d..5e8c52ccc 100644 --- a/src/comms/USB/TRXLooper_USB.cpp +++ b/src/comms/USB/TRXLooper_USB.cpp @@ -8,6 +8,8 @@ #include "TRXLooper_USB.h" #include "USBGeneric.h" +using namespace std::literals::string_literals; + namespace lime { TRXLooper_USB::TRXLooper_USB(std::shared_ptr comms, FPGA* f, LMS7002M* chip, uint8_t rxEndPt, uint8_t txEndPt) @@ -158,7 +160,7 @@ void TRXLooper_USB::TransmitPacketsLoop() else { // TODO: callback for Rx timeout - printf("Tx WaitForXfer timeout\n"); + lime::error("Tx WaitForXfer timeout"s); continue; } } @@ -242,7 +244,7 @@ void TRXLooper_USB::TransmitPacketsLoop() t1 = t2; float dataRate = 1000.0 * totalBytesSent / timePeriod.count(); - printf("Tx: %.3f MB/s\n", dataRate / 1000000.0); + lime::info("Tx: %.3f MB/s", dataRate / 1000000.0); totalBytesSent = 0; mTx.stats.dataRate_Bps = dataRate; @@ -336,13 +338,13 @@ void TRXLooper_USB::ReceivePacketsLoop() if (bytesReceived != bufferSize) { - printf("Recv %i, expected : %i\n", bytesReceived, bufferSize); + lime::error("Recv %i, expected : %i", bytesReceived, bufferSize); } } else { // TODO: callback for Rx timeout - printf("Rx WaitForXfer timeout\n"); + lime::error("Rx WaitForXfer timeout"s); continue; } } @@ -361,7 +363,7 @@ void TRXLooper_USB::ReceivePacketsLoop() if (pkt->counter - expectedTS != 0) { - printf("Loss: transfer:%li packet:%i, exp: %li, got: %li, diff: %li, handle: %i\n", + lime::warning("Loss: transfer:%li packet:%i, exp: %li, got: %li, diff: %li, handle: %i", stats.packets, j, expectedTS, @@ -416,7 +418,7 @@ void TRXLooper_USB::ReceivePacketsLoop() t1 = t2; float dataRate = 1000.0 * totalBytesReceived / timePeriod.count(); - printf("Rx: %.3f MB/s\n", dataRate / 1000000.0); + lime::info("Rx: %.3f MB/s", dataRate / 1000000.0); mRx.stats.dataRate_Bps = dataRate; totalBytesReceived = 0; diff --git a/src/comms/USB/USBGeneric.cpp b/src/comms/USB/USBGeneric.cpp index 4935994d8..1e9ada12b 100644 --- a/src/comms/USB/USBGeneric.cpp +++ b/src/comms/USB/USBGeneric.cpp @@ -3,6 +3,8 @@ #include +using namespace std::literals::string_literals; + namespace lime { #ifdef __unix__ @@ -209,7 +211,7 @@ int32_t USBGeneric::BulkTransfer(uint8_t endPointAddr, uint8_t* data, int length if (status != 0) { - printf("USBGeneric::BulkTransfer(0x%02X) : %s, transferred: %i, expected: %i\n", + lime::error("USBGeneric::BulkTransfer(0x%02X) : %s, transferred: %i, expected: %i", endPointAddr, libusb_error_name(status), actualTransferred, @@ -295,7 +297,7 @@ int USBGeneric::BeginDataXfer(uint8_t* buffer, uint32_t length, uint8_t endPoint if (status != 0) { - printf("BEGIN DATA TRANSFER %s\n", libusb_error_name(status)); + lime::error("BEGIN DATA TRANSFER %s", libusb_error_name(status)); contexts[i].used = false; return -1; } @@ -375,7 +377,7 @@ int USBGeneric::GetUSBContextIndex() if (!contextFound) { - printf("No contexts left for reading or sending data\n"); + lime::error("No contexts left for reading or sending data"s); return -1; } diff --git a/src/fftviewer_wxgui/fftviewer_frFFTviewer.cpp b/src/fftviewer_wxgui/fftviewer_frFFTviewer.cpp index 6139850ed..d86f6618e 100644 --- a/src/fftviewer_wxgui/fftviewer_frFFTviewer.cpp +++ b/src/fftviewer_wxgui/fftviewer_frFFTviewer.cpp @@ -456,10 +456,10 @@ void fftviewer_frFFTviewer::StreamingLoop( pthis->device->StreamStart(chipIndex); } catch (std::logic_error& e) { - printf("%s\n", e.what()); + lime::error("%s", e.what()); } catch (std::runtime_error& e) { - printf("%s\n", e.what()); + lime::error("%s", e.what()); } // uint16_t regVal = 0; diff --git a/src/lms7002_wxgui/lms7002_mainPanel.cpp b/src/lms7002_wxgui/lms7002_mainPanel.cpp index 0f1e9c9c9..fb945d574 100644 --- a/src/lms7002_wxgui/lms7002_mainPanel.cpp +++ b/src/lms7002_wxgui/lms7002_mainPanel.cpp @@ -28,8 +28,11 @@ #include "limesuite/SDRDevice.h" #include "limesuite/LMS7002M.h" +#include "Logger.h" + using namespace std; using namespace lime; +using namespace std::literals::string_literals; lms7002_mainPanel::lms7002_mainPanel(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) : ISOCPanel(parent, id, pos, size, style) @@ -238,7 +241,7 @@ void lms7002_mainPanel::UpdateVisiblePanel() currentTab->second->UpdateGUI(); t2 = wxGetUTCTimeMillis(); #ifndef NDEBUG - cout << "Visible GUI update time: " << (t2 - t1).ToString() << endl; + lime::debug("Visible GUI update time: "s + (t2 - t1).ToString()); #endif } diff --git a/src/lms7002_wxgui/lms7002_pnlCLKGEN_view.cpp b/src/lms7002_wxgui/lms7002_pnlCLKGEN_view.cpp index f46a9ecc7..b2615ebdc 100644 --- a/src/lms7002_wxgui/lms7002_pnlCLKGEN_view.cpp +++ b/src/lms7002_wxgui/lms7002_pnlCLKGEN_view.cpp @@ -9,7 +9,9 @@ #include "limesuite/LMS7002M.h" #include "FPGA_common.h" #include "Logger.h" + using namespace lime; +using namespace std::literals::string_literals; lms7002_pnlCLKGEN_view::lms7002_pnlCLKGEN_view(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) : ILMS7002MTab(parent, id, pos, size, style) @@ -792,7 +794,7 @@ void lms7002_pnlCLKGEN_view::ParameterChangeHandler(wxCommandEvent& event) parameter = wndId2Enum.at(reinterpret_cast(event.GetEventObject())); } catch (std::exception& e) { - std::cout << "Control element(ID = " << event.GetId() << ") don't have assigned LMS parameter." << std::endl; + lime::error("Control element(ID = "s + std::to_string(event.GetId()) + ") don't have assigned LMS parameter."s); return; } diff --git a/src/lms7002_wxgui/lms7002_pnlCalibrations_view.cpp b/src/lms7002_wxgui/lms7002_pnlCalibrations_view.cpp index adbbf05c6..6ec95a54d 100644 --- a/src/lms7002_wxgui/lms7002_pnlCalibrations_view.cpp +++ b/src/lms7002_wxgui/lms7002_pnlCalibrations_view.cpp @@ -6,7 +6,10 @@ #include #include "lms7suiteAppFrame.h" #include "limesuite/LMS7002M.h" +#include "Logger.h" + using namespace lime; +using namespace std::literals::string_literals; lms7002_pnlCalibrations_view::lms7002_pnlCalibrations_view( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) @@ -465,7 +468,7 @@ void lms7002_pnlCalibrations_view::ParameterChangeHandler(wxCommandEvent& event) parameter = wndId2Enum.at(reinterpret_cast(event.GetEventObject())); } catch (std::exception& e) { - std::cout << "Control element(ID = " << event.GetId() << ") don't have assigned LMS parameter." << std::endl; + lime::error("Control element(ID = "s + std::to_string(event.GetId()) + ") don't have assigned LMS parameter."s); return; } if (event.GetEventObject() == cmbDCOFFI_RFE || event.GetEventObject() == cmbDCOFFQ_RFE) diff --git a/src/lms7002_wxgui/lms7002_pnlGains_view.cpp b/src/lms7002_wxgui/lms7002_pnlGains_view.cpp index f593e6261..61afa4866 100644 --- a/src/lms7002_wxgui/lms7002_pnlGains_view.cpp +++ b/src/lms7002_wxgui/lms7002_pnlGains_view.cpp @@ -3,8 +3,11 @@ #include #include "lms7002_gui_utilities.h" #include "limesuite/SDRDevice.h" +#include "Logger.h" + using namespace lime; using namespace LMS7002_WXGUI; +using namespace std::literals::string_literals; static indexValueMap g_lna_rfe_IndexValuePairs; static indexValueMap g_tia_rfe_IndexValuePairs; @@ -261,7 +264,7 @@ void lms7002_pnlGains_view::ParameterChangeHandler(wxCommandEvent& event) parameter = wndId2Enum.at(reinterpret_cast(event.GetEventObject())); } catch (std::exception& e) { - std::cout << "Control element(ID = " << event.GetId() << ") don't have assigned LMS parameter." << std::endl; + lime::error("Control element(ID = "s + std::to_string(event.GetId()) + ") don't have assigned LMS parameter."s); return; } long value = event.GetInt(); diff --git a/src/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp b/src/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp index d54f19596..5c6872e1a 100644 --- a/src/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp +++ b/src/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp @@ -5,6 +5,9 @@ #include "dlgViewIRAM.h" #include "dlgViewSFR.h" #include "MCU_File.h" +#include "Logger.h" + +using namespace std::literals::string_literals; const long lms7002_pnlMCU_BD_view::ID_PROGRAMING_STATUS_EVENT = wxNewId(); const long lms7002_pnlMCU_BD_view::ID_PROGRAMING_FINISH_EVENT = wxNewId(); @@ -1393,13 +1396,10 @@ int lms7002_pnlMCU_BD_view::Read_IRAM() i = 256; // error, stop } OnProgrammingCallback(++stepsDone, 256, ""); -#ifndef NDEBUG - //printf("MCU reading IRAM: %2i/256\r", stepsDone.load()); -#endif Wait_CLK_Cycles(64); } #ifndef NDEBUG - printf("\nMCU reading IRAM finished\n"); + lime::info("MCU reading IRAM finished"s); #endif return retval; } @@ -1450,12 +1450,9 @@ int lms7002_pnlMCU_BD_view::Erase_IRAM() //aborted.store(true); } OnProgrammingCallback(++stepsDone, 256, ""); -#ifndef NDEBUG - //printf("MCU erasing IRAM: %2i/256\r", stepsDone.load()); -#endif } #ifndef NDEBUG - printf("\nMCU erasing IRAM finished\n"); + lime::info("MCU erasing IRAM finished"s); #endif return retval; } diff --git a/src/lms7002_wxgui/lms7002_pnlR3.cpp b/src/lms7002_wxgui/lms7002_pnlR3.cpp index 2962188c1..bbb5d3ce9 100644 --- a/src/lms7002_wxgui/lms7002_pnlR3.cpp +++ b/src/lms7002_wxgui/lms7002_pnlR3.cpp @@ -8,10 +8,13 @@ #include #include "mcu_programs.h" #include "limesuite/LMS7002M.h" +#include "Logger.h" #include + using namespace lime; using namespace std; +using namespace std::literals::string_literals; lms7002_pnlR3_view::lms7002_pnlR3_view(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) : ILMS7002MTab(parent, id, pos, size, style) @@ -568,7 +571,7 @@ void lms7002_pnlR3_view::ParameterChangeHandler(wxCommandEvent& event) parameter = wndId2Enum.at(reinterpret_cast(event.GetEventObject())); } catch (std::exception& e) { - std::cout << "Control element(ID = " << event.GetId() << ") don't have assigned LMS parameter." << std::endl; + lime::error("Control element(ID = "s + std::to_string(event.GetId()) + ") don't have assigned LMS parameter."s); return; } @@ -661,7 +664,7 @@ void lms7002_pnlR3_view::OnWriteTxDC(wxCommandEvent& event) return; } catch (std::exception& e) { - std::cout << "Control element(ID = " << event.GetId() << ") don't have assigned LMS parameter." << std::endl; + lime::error("Control element(ID = "s + std::to_string(event.GetId()) + ") don't have assigned LMS parameter."s); return; } } @@ -690,7 +693,7 @@ void lms7002_pnlR3_view::OnWriteRxDC(wxCommandEvent& event) return; } catch (std::exception& e) { - std::cout << "Control element(ID = " << event.GetId() << ") don't have assigned LMS parameter." << std::endl; + lime::error("Control element(ID = "s + std::to_string(event.GetId()) + ") don't have assigned LMS parameter."s); return; } } diff --git a/src/lms7002_wxgui/lms7002_pnlRBB_view.cpp b/src/lms7002_wxgui/lms7002_pnlRBB_view.cpp index 8e41661c3..8ad595258 100644 --- a/src/lms7002_wxgui/lms7002_pnlRBB_view.cpp +++ b/src/lms7002_wxgui/lms7002_pnlRBB_view.cpp @@ -5,7 +5,10 @@ #include "lms7002_gui_utilities.h" #include "lms7suiteEvents.h" #include "lms7suiteAppFrame.h" +#include "Logger.h" + using namespace lime; +using namespace std::literals::string_literals; lms7002_pnlRBB_view::lms7002_pnlRBB_view(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) : ILMS7002MTab(parent, id, pos, size, style) @@ -434,7 +437,7 @@ void lms7002_pnlRBB_view::ParameterChangeHandler(wxCommandEvent& event) parameter = wndId2Enum.at(reinterpret_cast(event.GetEventObject())); } catch (std::exception& e) { - std::cout << "Control element(ID = " << event.GetId() << ") don't have assigned LMS parameter." << std::endl; + lime::error("Control element(ID = "s + std::to_string(event.GetId()) + ") don't have assigned LMS parameter."s); return; } WriteParam(parameter, event.GetInt()); diff --git a/src/lms7002_wxgui/lms7002_pnlRFE_view.cpp b/src/lms7002_wxgui/lms7002_pnlRFE_view.cpp index 2ddc15211..0330c5184 100644 --- a/src/lms7002_wxgui/lms7002_pnlRFE_view.cpp +++ b/src/lms7002_wxgui/lms7002_pnlRFE_view.cpp @@ -10,10 +10,12 @@ #include #include "wx/spinctrl.h" #include "limesuite/SDRDevice.h" +#include "Logger.h" using namespace std; using namespace lime; using namespace LMS7002_WXGUI; +using namespace std::literals::string_literals; static indexValueMap g_lna_rfe_IndexValuePairs; static indexValueMap g_tia_rfe_IndexValuePairs; @@ -529,7 +531,7 @@ void lms7002_pnlRFE_view::ParameterChangeHandler(wxCommandEvent& event) parameter = wndId2Enum.at(reinterpret_cast(event.GetEventObject())); } catch (std::exception& e) { - std::cout << "Control element(ID = " << event.GetId() << ") don't have assigned LMS parameter." << std::endl; + lime::error("Control element(ID = "s + std::to_string(event.GetId()) + ") don't have assigned LMS parameter."s); return; } long value = event.GetInt(); diff --git a/src/lms7002_wxgui/lms7002_pnlRxTSP_view.cpp b/src/lms7002_wxgui/lms7002_pnlRxTSP_view.cpp index bbf805eef..63232155d 100644 --- a/src/lms7002_wxgui/lms7002_pnlRxTSP_view.cpp +++ b/src/lms7002_wxgui/lms7002_pnlRxTSP_view.cpp @@ -4,9 +4,12 @@ #include "lms7002_dlgGFIR_Coefficients.h" #include "lms7suiteAppFrame.h" #include "limesuite/LMS7002M.h" +#include "Logger.h" using namespace lime; using namespace LMS7002_WXGUI; +using namespace std::literals::string_literals; + static indexValueMap hbd_ovr_rxtsp_IndexValuePairs; static indexValueMap tsgfcw_rxtsp_IndexValuePairs; indexValueMap cmix_gain_rxtsp_IndexValuePairs; @@ -1727,7 +1730,7 @@ void lms7002_pnlRXTSP_view::ParameterChangeHandler(wxCommandEvent& event) parameter = wndId2Enum.at(reinterpret_cast(event.GetEventObject())); } catch (std::exception& e) { - std::cout << "Control element(ID = " << event.GetId() << ") don't have assigned LMS parameter." << std::endl; + lime::error("Control element(ID = "s + std::to_string(event.GetId()) + ") don't have assigned LMS parameter."s); return; } long value = event.GetInt(); diff --git a/src/lms7002_wxgui/lms7002_pnlTBB_view.cpp b/src/lms7002_wxgui/lms7002_pnlTBB_view.cpp index 698615591..d40490fab 100644 --- a/src/lms7002_wxgui/lms7002_pnlTBB_view.cpp +++ b/src/lms7002_wxgui/lms7002_pnlTBB_view.cpp @@ -6,8 +6,10 @@ #include "limesuite/SDRDevice.h" #include "lms7suiteAppFrame.h" #include "limesuite/LMS7002M.h" +#include "Logger.h" using namespace lime; +using namespace std::literals::string_literals; lms7002_pnlTBB_view::lms7002_pnlTBB_view(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) : ILMS7002MTab(parent, id, pos, size, style) @@ -577,7 +579,7 @@ void lms7002_pnlTBB_view::ParameterChangeHandler(wxCommandEvent& event) parameter = wndId2Enum.at(reinterpret_cast(event.GetEventObject())); } catch (std::exception& e) { - std::cout << "Control element(ID = " << event.GetId() << ") don't have assigned LMS parameter." << std::endl; + lime::error("Control element(ID = "s + std::to_string(event.GetId()) + ") don't have assigned LMS parameter."s); return; } WriteParam(parameter, event.GetInt()); diff --git a/src/lms7002_wxgui/lms7002_pnlTRF_view.cpp b/src/lms7002_wxgui/lms7002_pnlTRF_view.cpp index e902105a8..2724318a7 100644 --- a/src/lms7002_wxgui/lms7002_pnlTRF_view.cpp +++ b/src/lms7002_wxgui/lms7002_pnlTRF_view.cpp @@ -4,8 +4,12 @@ #include "lms7002_gui_utilities.h" #include "wx/msgdlg.h" #include "lms7suiteEvents.h" +#include "Logger.h" + using namespace lime; using namespace LMS7002_WXGUI; +using namespace std::literals::string_literals; + static indexValueMap en_amphf_pdet_trfIndexValuePairs; lms7002_pnlTRF_view::lms7002_pnlTRF_view(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style) @@ -432,7 +436,7 @@ void lms7002_pnlTRF_view::ParameterChangeHandler(wxCommandEvent& event) parameter = wndId2Enum.at(reinterpret_cast(event.GetEventObject())); } catch (std::exception& e) { - std::cout << "Control element(ID = " << event.GetId() << ") don't have assigned LMS parameter." << std::endl; + lime::error("Control element(ID = "s + std::to_string(event.GetId()) + ") don't have assigned LMS parameter."s); return; } long value = event.GetInt(); diff --git a/src/lms7002_wxgui/lms7002_pnlTxTSP_view.cpp b/src/lms7002_wxgui/lms7002_pnlTxTSP_view.cpp index be60b8036..4c33aa9a2 100644 --- a/src/lms7002_wxgui/lms7002_pnlTxTSP_view.cpp +++ b/src/lms7002_wxgui/lms7002_pnlTxTSP_view.cpp @@ -4,9 +4,11 @@ #include "lms7002_dlgGFIR_Coefficients.h" #include "lms7suiteAppFrame.h" #include "limesuite/LMS7002M.h" +#include "Logger.h" using namespace lime; using namespace LMS7002_WXGUI; +using namespace std::literals::string_literals; indexValueMap hbi_ovr_txtsp_IndexValuePairs; indexValueMap tsgfcw_txtsp_IndexValuePairs; @@ -1495,7 +1497,7 @@ void lms7002_pnlTXTSP_view::ParameterChangeHandler(wxCommandEvent& event) parameter = wndId2Enum.at(reinterpret_cast(event.GetEventObject())); } catch (std::exception& e) { - std::cout << "Control element(ID = " << event.GetId() << ") don't have assigned LMS parameter." << std::endl; + lime::error("Control element(ID = "s + std::to_string(event.GetId()) + ") don't have assigned LMS parameter."s); return; } long value = event.GetInt(); diff --git a/src/lms7002m/LMS7002M.cpp b/src/lms7002m/LMS7002M.cpp index 8385f9045..25cd4dd0f 100644 --- a/src/lms7002m/LMS7002M.cpp +++ b/src/lms7002m/LMS7002M.cpp @@ -494,10 +494,9 @@ int LMS7002M::LoadConfigLegacyFile(const std::string& filename) std::string type = ""; type = parser.get("type", "undefined"); - std::stringstream ss; + if (type.find("LMS7002 configuration") == std::string::npos) { - ss << "File " << filename << " not recognized" << std::endl; return ReportError(EINVAL, "LoadConfigLegacyFile(%s) - invalid format, missing LMS7002 configuration", filename.c_str()); } @@ -684,10 +683,9 @@ int LMS7002M::LoadConfig(const std::string& filename, bool tuneDynamicValues) } std::string type = ""; type = parser.get("type", "undefined"); - std::stringstream ss; + if (type.find("lms7002m_minimal_config") == std::string::npos) { - ss << "File " << filename << " not recognized" << std::endl; return ReportError(EINVAL, "LoadConfig(%s) - invalid format, missing lms7002m_minimal_config", filename.c_str()); } @@ -3392,7 +3390,7 @@ int LMS7002M::SetGFIRFilter(TRXDir dir, unsigned ch, bool enabled, double bandwi w2 = w * 1.05; if (w2 > 0.495) { - printf("GFIR LPF cannot be set to the requested bandwidth (%f)", bandwidth); + lime::error("GFIR LPF cannot be set to the requested bandwidth (%f)", bandwidth); return -1; } } @@ -3430,8 +3428,7 @@ int LMS7002M::SetGFIRFilter(TRXDir dir, unsigned ch, bool enabled, double bandwi for (int i = 0; i < L * 15; ++i) ss << " " << coef[i]; ss << std::endl; - - std::cout << ss.str(); + lime::info(ss.str()); return ResetLogicregisters(); } diff --git a/src/lms7002m/LMS7002M_RxTxCalibrations.cpp b/src/lms7002m/LMS7002M_RxTxCalibrations.cpp index 5111b1cd7..e3d2460a9 100644 --- a/src/lms7002m/LMS7002M_RxTxCalibrations.cpp +++ b/src/lms7002m/LMS7002M_RxTxCalibrations.cpp @@ -11,14 +11,9 @@ #define LMS_VERBOSE_OUTPUT #endif -#ifdef LMS_VERBOSE_OUTPUT -static const bool verboseEnabled = true; -#else -static const bool verboseEnabled = false; -#endif - using namespace std; using namespace lime; +using namespace std::literals::string_literals; // class BoardLoopbackStore // { @@ -72,15 +67,6 @@ static inline int16_t signextIqCorr(const uint16_t regVal) const double TrxCalib_RF_LimitLow = 2.5e6; const double TrxCalib_RF_LimitHigh = 120e6; -#define verbose_printf(...) \ - do \ - { \ - if (verboseEnabled) \ - { \ - fprintf(stderr, __VA_ARGS__); \ - } \ - } while (0) - static int16_t ReadAnalogDC(lime::LMS7002M* lmsControl, const LMS7Parameter& param) { uint16_t mask = param.address < 0x05C7 ? 0x03FF : 0x003F; @@ -214,8 +200,8 @@ int LMS7002M::CalibrateTx(float_type bandwidth_Hz, bool useExtLoopback) int band = Get_SPI_Reg_bits(LMS7_SEL_BAND1_TRF) ? 0 : 1; int dccorri(0), dccorrq(0), gcorri(0), gcorrq(0), phaseOffset(0); - verbose_printf("Tx calibration using MCU %s loopback\n", useExtLoopback ? "EXTERNAL" : "INTERNAL"); - verbose_printf("Tx ch.%s @ %4g MHz, BW: %g MHz, RF output: %s, Gain: %i\n", + lime::debug("Tx calibration using MCU %s loopback", useExtLoopback ? "EXTERNAL" : "INTERNAL"); + lime::debug("Tx ch.%s @ %4g MHz, BW: %g MHz, RF output: %s, Gain: %i", channel ? "B" : "A", txFreq / 1e6, bandwidth_Hz / 1e6, @@ -223,11 +209,11 @@ int LMS7002M::CalibrateTx(float_type bandwidth_Hz, bool useExtLoopback) Get_SPI_Reg_bits(LMS7_CG_IAMP_TBB)); uint8_t mcuID = mcuControl->ReadMCUProgramID(); - verbose_printf( - "Current MCU firmware: %i, %s\n", mcuID, mcuID == MCU_ID_CALIBRATIONS_SINGLE_IMAGE ? "DC/IQ calibration full" : "unknown"); + lime::debug( + "Current MCU firmware: %i, %s", mcuID, mcuID == MCU_ID_CALIBRATIONS_SINGLE_IMAGE ? "DC/IQ calibration full" : "unknown"); if (mcuID != MCU_ID_CALIBRATIONS_SINGLE_IMAGE) { - verbose_printf("Uploading DC/IQ calibration firmware\n"); + lime::debug("Uploading DC/IQ calibration firmware"s); status = mcuControl->Program_MCU(mcu_program_lms7_dc_iq_calibration_bin, MCU_BD::MCU_PROG_MODE::SRAM); if (status != 0) return status; @@ -236,7 +222,7 @@ int LMS7002M::CalibrateTx(float_type bandwidth_Hz, bool useExtLoopback) //set reference clock parameter inside MCU long refClk = GetReferenceClk_SX(TRXDir::Rx); mcuControl->SetParameter(MCU_BD::MCU_Parameter::MCU_REF_CLK, refClk); - verbose_printf("MCU Ref. clock: %g MHz\n", refClk / 1e6); + lime::debug("MCU Ref. clock: %g MHz", refClk / 1e6); //Tx Rx separation bandwidth while calibrating mcuControl->SetParameter(MCU_BD::MCU_Parameter::MCU_BW, bandwidth_Hz); @@ -270,13 +256,13 @@ int LMS7002M::CalibrateTx(float_type bandwidth_Hz, bool useExtLoopback) phaseOffset = signextIqCorr(Get_SPI_Reg_bits(LMS7_IQCORR_TXTSP, true)); Log("Tx calibration finished", LogType::LOG_INFO); - verbose_printf("Tx | DC | GAIN | PHASE\n"); - verbose_printf("---+-----+------+------\n"); - verbose_printf("I: | %3i | %4i | %i\n", dccorri, gcorri, phaseOffset); - verbose_printf("Q: | %3i | %4i |\n", dccorrq, gcorrq); + lime::debug("Tx | DC | GAIN | PHASE"); + lime::debug("---+-----+------+------"); + lime::debug("I: | %3i | %4i | %i", dccorri, gcorri, phaseOffset); + lime::debug("Q: | %3i | %4i |", dccorrq, gcorrq); int32_t duration = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - beginTime).count(); - verbose_printf("Duration: %i ms\n", duration); + lime::debug("Duration: %i ms", duration); return 0; } @@ -330,8 +316,8 @@ int LMS7002M::CalibrateRx(float_type bandwidth_Hz, bool useExtLoopback) lnaName = "none"; break; } - verbose_printf("Rx calibration using %s loopback\n", (useExtLoopback ? "EXTERNAL" : "INTERNAL")); - verbose_printf("Rx ch.%s @ %4g MHz, BW: %g MHz, RF input: %s, PGA: %i, LNA: %i, TIA: %i\n", + lime::debug("Rx calibration using %s loopback", (useExtLoopback ? "EXTERNAL" : "INTERNAL")); + lime::debug("Rx ch.%s @ %4g MHz, BW: %g MHz, RF input: %s, PGA: %i, LNA: %i, TIA: %i", ch == static_cast(Channel::ChA) ? "A" : "B", rxFreq / 1e6, bandwidth_Hz / 1e6, @@ -343,11 +329,11 @@ int LMS7002M::CalibrateRx(float_type bandwidth_Hz, bool useExtLoopback) int dcoffi(0), dcoffq(0), gcorri(0), gcorrq(0), phaseOffset(0); //check if MCU has correct firmware uint8_t mcuID = mcuControl->ReadMCUProgramID(); - verbose_printf( - "Current MCU firmware: %i, %s\n", mcuID, mcuID == MCU_ID_CALIBRATIONS_SINGLE_IMAGE ? "DC/IQ calibration full" : "unknown"); + lime::debug( + "Current MCU firmware: %i, %s", mcuID, mcuID == MCU_ID_CALIBRATIONS_SINGLE_IMAGE ? "DC/IQ calibration full" : "unknown"); if (mcuID != MCU_ID_CALIBRATIONS_SINGLE_IMAGE) { - verbose_printf("Uploading DC/IQ calibration firmware\n"); + lime::debug("Uploading DC/IQ calibration firmware"); status = mcuControl->Program_MCU(mcu_program_lms7_dc_iq_calibration_bin, MCU_BD::MCU_PROG_MODE::SRAM); if (status != 0) return status; @@ -356,7 +342,7 @@ int LMS7002M::CalibrateRx(float_type bandwidth_Hz, bool useExtLoopback) //set reference clock parameter inside MCU long refClk = GetReferenceClk_SX(TRXDir::Rx); mcuControl->SetParameter(MCU_BD::MCU_Parameter::MCU_REF_CLK, refClk); - verbose_printf("MCU Ref. clock: %g MHz\n", refClk / 1e6); + lime::debug("MCU Ref. clock: %g MHz", refClk / 1e6); //Tx Rx separation bandwidth while calibrating mcuControl->SetParameter(MCU_BD::MCU_Parameter::MCU_BW, bandwidth_Hz); @@ -391,14 +377,14 @@ int LMS7002M::CalibrateRx(float_type bandwidth_Hz, bool useExtLoopback) phaseOffset = signextIqCorr(Get_SPI_Reg_bits(LMS7_IQCORR_RXTSP, true)); Log("Rx calibration finished", LogType::LOG_INFO); - verbose_printf("RX | DC | GAIN | PHASE\n"); - verbose_printf("---+-----+------+------\n"); - verbose_printf("I: | %3i | %4i | %i\n", dcoffi, gcorri, phaseOffset); - verbose_printf("Q: | %3i | %4i |\n", dcoffq, gcorrq); + lime::debug("RX | DC | GAIN | PHASE"); + lime::debug("---+-----+------+------"); + lime::debug("I: | %3i | %4i | %i", dcoffi, gcorri, phaseOffset); + lime::debug("Q: | %3i | %4i |", dcoffq, gcorrq); #ifdef LMS_VERBOSE_OUTPUT int32_t duration = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - beginTime).count(); - verbose_printf("Duration: %i ms\n", duration); + lime::debug("Duration: %i ms", duration); #endif //LMS_VERBOSE_OUTPUT return 0; } diff --git a/src/lms7002m/MCU_BD.cpp b/src/lms7002m/MCU_BD.cpp index e30c83e3a..20220735d 100644 --- a/src/lms7002m/MCU_BD.cpp +++ b/src/lms7002m/MCU_BD.cpp @@ -20,6 +20,7 @@ using namespace std; #include using namespace lime; +using namespace std::literals::string_literals; MCU_BD::MCU_BD() { @@ -292,12 +293,12 @@ int MCU_BD::Read_IRAM() } ++stepsDone; #ifndef NDEBUG - printf("MCU reading IRAM: %2i/256\r", stepsDone.load()); + lime::debug("MCU reading IRAM: %2i/256\r", stepsDone.load()); #endif Wait_CLK_Cycles(64); } #ifndef NDEBUG - printf("\nMCU reading IRAM finished\n"); + lime::debug("MCU reading IRAM finished"s); #endif return retval; } @@ -327,11 +328,11 @@ int MCU_BD::Erase_IRAM() } ++stepsDone; #ifndef NDEBUG - printf("MCU erasing IRAM: %2i/256\r", stepsDone.load()); + lime::debug("MCU erasing IRAM: %2i/256\r", stepsDone.load()); #endif } #ifndef NDEBUG - printf("\nMCU erasing IRAM finished\n"); + lime::debug("MCU erasing IRAM finished"s); #endif return retval; } @@ -699,7 +700,7 @@ int MCU_BD::Program_MCU(const uint8_t* buffer, const MCU_BD::MCU_PROG_MODE mode) if (callback) abort = callback(i + fifoLen, byte_array_size, ""); #ifndef NDEBUG - printf("MCU programming : %4i/%4li\r", i + fifoLen, long(byte_array_size)); + lime::debug("MCU programming : %4i/%4li\r", i + fifoLen, long(byte_array_size)); #endif }; if (abort) @@ -719,7 +720,7 @@ int MCU_BD::Program_MCU(const uint8_t* buffer, const MCU_BD::MCU_PROG_MODE mode) #ifndef NDEBUG auto timeEnd = std::chrono::high_resolution_clock::now(); - printf("\nMCU Programming finished, %li ms\n", + lime::debug("MCU Programming finished, %li ms", std::chrono::duration_cast(timeEnd - timeStart).count()); #endif if (!programmed) @@ -728,7 +729,7 @@ int MCU_BD::Program_MCU(const uint8_t* buffer, const MCU_BD::MCU_PROG_MODE mode) } catch (std::runtime_error& e) { #ifndef NDEBUG - printf("MCU programming failed : %s", e.what()); + lime::error("MCU programming failed : %s", e.what()); #endif return -1; } @@ -1177,7 +1178,7 @@ void MCU_BD::SetParameter(MCU_Parameter param, float value) mSPI_write(0x0002, x0002reg & ~interupt7); int status = WaitForMCU(10); if (status != 0) - lime::debug("MCU error status 0x%02X\n", status); + lime::debug("MCU error status 0x%02X", status); RunProcedure(9); } if (WaitForMCU(100) != 0) diff --git a/src/lms7002m/MCU_File.cpp b/src/lms7002m/MCU_File.cpp index 7390424b7..0421c1ab7 100644 --- a/src/lms7002m/MCU_File.cpp +++ b/src/lms7002m/MCU_File.cpp @@ -2,8 +2,10 @@ #include #include #include +#include "Logger.h" using namespace std; +using namespace std::literals::string_literals; MCU_File::MCU_File(const char* fileName, const char* mode) { @@ -13,11 +15,7 @@ MCU_File::MCU_File(const char* fileName, const char* mode) return; } - cout << "Error opening"; - //string errorStr = "Error opening "; - //errorStr += fileName; - //errorStr += "\n"; - //throw errorStr; + lime::error("Error opening "s + fileName); } MCU_File::~MCU_File() @@ -39,7 +37,7 @@ void MCU_File::ReadBin(unsigned long limit) m_chunks.push_back(MemBlock()); m_chunks.back().m_startAddress = 0; - cout << "Reading binary file\n"; + lime::debug("Reading binary file"s); int tmp = fgetc(m_file); @@ -51,8 +49,8 @@ void MCU_File::ReadBin(unsigned long limit) { m_chunks.back().m_bytes.pop_back(); m_top = m_chunks.back().m_bytes.size() - 1; - cout << "Ignoring data above address space!\n"; - cout << " Limit: " << limit << "\n"; + lime::error("Ignoring data above address space!"s); + lime::error(" Limit: "s + std::to_string(limit)); return; } @@ -63,7 +61,7 @@ void MCU_File::ReadBin(unsigned long limit) if (!m_chunks.back().m_bytes.size()) { - cout << "No data!\n"; + lime::warning("No data!"s); m_chunks.pop_back(); } @@ -85,7 +83,7 @@ void MCU_File::ReadHex(unsigned long limit) { if (ferror(m_file)) { - throw "Error reading input!\n"; + throw "Error reading input!"s; } continue; } @@ -102,7 +100,7 @@ void MCU_File::ReadHex(unsigned long limit) if (strlen(szLine) == 1023) { - throw "Hex file lines to long!\n"; + throw "Hex file lines to long!"s; } // Ignore blank lines if (szLine[0] == '\n') @@ -114,30 +112,30 @@ void MCU_File::ReadHex(unsigned long limit) { if (szLine[0] != ':' && szLine[0] != 'S') { - cout << "Ignoring garbage line!\n"; + lime::warning("Ignoring garbage line!"s); continue; } if (szLine[0] == 'S') { intel = false; - cout << "Detected S-Record\n"; + lime::info("Detected S-Record"s); } else { intel = true; - cout << "Detected intel hex file\n"; + lime::info("Detected intel hex file"s); } formatDetected = true; } else if ((intel && szLine[0] != ':') || (!intel && szLine[0] != 'S')) { - cout << "Ignoring garbage line!\n"; + lime::warning("Ignoring garbage line!"s); continue; } if (endSeen) { - throw "Hex line after end of file record!\n"; + throw "Hex line after end of file record!"s; } if (intel) @@ -147,12 +145,12 @@ void MCU_File::ReadHex(unsigned long limit) unsigned long type; if (sscanf(&szLine[1], "%2lx%4lx%2lx", &dataBytes, &startAddress, &type) != 3) { - throw "Hex line beginning corrupt!\n"; + throw "Hex line beginning corrupt!"s; } // Check line length if (szLine[11 + dataBytes * 2] != '\n' && szLine[11 + dataBytes * 2] != 0) { - throw "Hex line length incorrect!\n"; + throw "Hex line length incorrect!"s; } // Check line checksum unsigned char checkSum = 0; @@ -161,13 +159,13 @@ void MCU_File::ReadHex(unsigned long limit) { if (sscanf(&szLine[1 + i * 2], "%2lx", &tmp) != 1) { - throw "Hex line data corrupt!\n"; + throw "Hex line data corrupt!"s; } checkSum += (unsigned char)tmp; } if (checkSum != 0) { - throw "Hex line checksum error!\n"; + throw "Hex line checksum error!"s; } switch (type) @@ -181,7 +179,7 @@ void MCU_File::ReadHex(unsigned long limit) test += dataBytes; if (test > 0xffff) { - throw "Can't handle wrapped segments!\n"; + throw "Can't handle wrapped segments!"s; } } if (!m_chunks.size() || @@ -197,9 +195,9 @@ void MCU_File::ReadHex(unsigned long limit) sscanf(&szLine[9 + i * 2], "%2lx", &tmp); if (addressBase + startAddress + i > limit) { - cout << "Ignoring data above address space!\n"; - cout << "Data address: " << addressBase + startAddress + i; - cout << " Limit: " << limit << "\n"; + lime::warning("Ignoring data above address space!"s); + lime::warning("Data address: "s + std::to_string(addressBase + startAddress + i)); + lime::warning("Limit: "s + std::to_string(limit)); if (!m_chunks.back().m_bytes.size()) { m_chunks.pop_back(); @@ -215,11 +213,11 @@ void MCU_File::ReadHex(unsigned long limit) // End-of-file record if (dataBytes != 0) { - cout << "Warning: End of file record not zero length!\n"; + lime::warning("End of file record not zero length!"s); } if (startAddress != 0) { - cout << "Warning: End of file record address not zero!\n"; + lime::warning("End of file record address not zero!"s); } endSeen = true; break; @@ -228,11 +226,11 @@ void MCU_File::ReadHex(unsigned long limit) // Extended segment address record if (dataBytes != 2) { - throw "Length field must be 2 in extended segment address record!\n"; + throw "Length field must be 2 in extended segment address record!"s; } if (startAddress != 0) { - throw "Address field must be zero in extended segment address record!\n"; + throw "Address field must be zero in extended segment address record!"s; } sscanf(&szLine[9], "%4lx", &startAddress); addressBase = startAddress << 4; @@ -243,20 +241,20 @@ void MCU_File::ReadHex(unsigned long limit) // Start segment address record if (dataBytes != 4) { - cout << "Warning: Length field must be 4 in start segment address record!\n"; + lime::warning("Length field must be 4 in start segment address record!"s); } if (startAddress != 0) { - cout << "Warning: Address field must be zero in start segment address record!\n"; + lime::warning("Warning: Address field must be zero in start segment address record!"s); } if (dataBytes == 4) { unsigned long ssa; char ssaStr[16]; sscanf(&szLine[9], "%8lx", &ssa); - sprintf(ssaStr, "%08lX\n", ssa); - cout << "Segment start address (CS/IP): "; - cout << ssaStr; + sprintf(ssaStr, "%08lX", ssa); + lime::debug("Segment start address (CS/IP): "s); + lime::debug("%s", ssaStr); } break; @@ -264,11 +262,11 @@ void MCU_File::ReadHex(unsigned long limit) // Extended linear address record if (dataBytes != 2) { - throw "Length field must be 2 in extended linear address record!\n"; + throw "Length field must be 2 in extended linear address record!"s; } if (startAddress != 0) { - throw "Address field must be zero in extended linear address record!\n"; + throw "Address field must be zero in extended linear address record!"s; } sscanf(&szLine[9], "%4lx", &startAddress); addressBase = ((unsigned long)startAddress) << 16; @@ -279,25 +277,25 @@ void MCU_File::ReadHex(unsigned long limit) // Start linear address record if (dataBytes != 4) { - cout << "Warning: Length field must be 4 in start linear address record!\n"; + lime::warning("Length field must be 4 in start linear address record!"s); } if (startAddress != 0) { - cout << "Warning: Address field must be zero in start linear address record!\n"; + lime::warning("Address field must be zero in start linear address record!"s); } if (dataBytes == 4) { unsigned long lsa; char lsaStr[16]; sscanf(&szLine[9], "%8lx", &lsa); - sprintf(lsaStr, "%08lX\n", lsa); - cout << "Linear start address: "; - cout << lsaStr; + sprintf(lsaStr, "%08lX", lsa); + lime::debug("Linear start address: "s); + lime::debug("%s", lsaStr); } break; default: - cout << "Waring: Unknown record found!\n"; + lime::warning("Unknown record found!"s); } } else @@ -307,12 +305,12 @@ void MCU_File::ReadHex(unsigned long limit) char type; if (sscanf(&szLine[1], "%c%2lx", &type, &count) != 2) { - throw "Hex line beginning corrupt!\n"; + throw "Hex line beginning corrupt!"s; } // Check line length if (szLine[4 + count * 2] != '\n' && szLine[4 + count * 2] != 0) { - throw "Hex line length incorrect!\n"; + throw "Hex line length incorrect!"s; } // Check line checksum unsigned char checkSum = 0; @@ -321,13 +319,13 @@ void MCU_File::ReadHex(unsigned long limit) { if (sscanf(&szLine[2 + i * 2], "%2lx", &tmp) != 1) { - throw "Hex line data corrupt!\n"; + throw "Hex line data corrupt!"s; } checkSum += (unsigned char)tmp; } if (checkSum != 255) { - throw "Hex line checksum error!\n"; + throw "Hex line checksum error!"s; } switch (type) @@ -345,7 +343,7 @@ void MCU_File::ReadHex(unsigned long limit) header[i] = 0; if (i > 0) { - cout << "Module name: " << header << "\n"; + lime::info("Module name: "s + header); } } break; @@ -381,9 +379,9 @@ void MCU_File::ReadHex(unsigned long limit) sscanf(&szLine[8 + i * 2], "%2lx", &tmp); if (startAddress + i > limit) { - cout << "Ignoring data above address space!\n"; - cout << "Data address: " << startAddress + i; - cout << " Limit: " << limit << "\n"; + lime::warning("Ignoring data above address space!"s); + lime::warning("Data address: "s + std::to_string(startAddress + i)); + lime::warning("Limit: "s + std::to_string(limit)); if (!m_chunks.back().m_bytes.size()) { m_chunks.pop_back(); @@ -402,7 +400,7 @@ void MCU_File::ReadHex(unsigned long limit) sscanf(&szLine[4], "%4lx", &address); if (address != dataRecords) { - throw "Wrong number of data records!\n"; + throw "Wrong number of data records!"s; } } break; @@ -411,21 +409,21 @@ void MCU_File::ReadHex(unsigned long limit) case '8': case '9': // Start address record - cout << "Ignoring start address record!\n"; + lime::warning("Ignoring start address record!"s); break; default: - cout << "Unknown record found!\n"; + lime::warning("Unknown record found!"s); } } } if (intel && !endSeen) { - cout << "No end of file record!\n"; + lime::warning("No end of file record!"s); } if (!m_chunks.size()) { - throw "No data in file!\n"; + throw "No data in file!"s; } vector::iterator vi; m_top = 0; @@ -503,4 +501,4 @@ bool MCU_File::BitString(const unsigned long address, const unsigned char bits, mask <<= 1; } return true; -} \ No newline at end of file +} diff --git a/src/lms7suiteApp.cpp b/src/lms7suiteApp.cpp index e93e06fb7..cfb7649fd 100644 --- a/src/lms7suiteApp.cpp +++ b/src/lms7suiteApp.cpp @@ -27,9 +27,12 @@ IMPLEMENT_APP_CONSOLE(lms7suiteApp) IMPLEMENT_APP(lms7suiteApp) #endif +#include "Logger.h" #include "resources/splash.h" #include "resources/LMS_ICO.xpm" +using namespace std::literals::string_literals; + bool lms7suiteApp::OnInit() { wxInitAllImageHandlers(); @@ -41,7 +44,7 @@ bool lms7suiteApp::OnInit() frame->SetIcon(wxICON(LMS_ICO)); #ifndef NDEBUG wxLongLong t1 = wxGetUTCTimeMillis(); - std::cout << "Create time " << (wxGetUTCTimeMillis() - t1).ToString() << " ms\n"; + lime::debug( "Create time "s + (wxGetUTCTimeMillis() - t1).ToString() + " ms"s); #endif splash->Destroy(); frame->Show(); diff --git a/src/lms7suiteAppFrame.cpp b/src/lms7suiteAppFrame.cpp index cb3dd3d56..02843ce9f 100644 --- a/src/lms7suiteAppFrame.cpp +++ b/src/lms7suiteAppFrame.cpp @@ -39,8 +39,12 @@ #include "limesuite/SDRDevice.h" #include "limesuite/DeviceNode.h" //#include "LimeSDR.h" + +#include "Logger.h" + using namespace std; using namespace lime; +using namespace std::literals::string_literals; static constexpr int controlColumn = 1; @@ -187,6 +191,8 @@ LMS7SuiteAppFrame::~LMS7SuiteAppFrame() Disconnect(idMenuQuit, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(LMS7SuiteAppFrame::OnQuit)); Disconnect(idMenuAbout, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(LMS7SuiteAppFrame::OnAbout)); Disconnect(LOG_MESSAGE, wxCommandEventHandler(LMS7SuiteAppFrame::OnLogMessage), 0, this); + + obj_ptr = nullptr; } void LMS7SuiteAppFrame::OnClose(wxCloseEvent& event) @@ -313,7 +319,7 @@ void LMS7SuiteAppFrame::OnDeviceHandleChange(wxCommandEvent& event) Fit(); } catch (std::runtime_error& e) { - printf("Failed to connect %s\n", e.what()); + lime::error("Failed to connect "s + e.what()); } } @@ -346,7 +352,7 @@ void LMS7SuiteAppFrame::OnLogDataTransfer(bool Tx, const uint8_t* data, const ui ss << " " << std::setw(2) << (unsigned short)data[i]; if (repeatedZeros > 2) ss << " (00 x " << std::dec << repeatedZeros << " times)"; - cout << ss.str() << endl; + lime::debug(ss.str()); wxCommandEvent* evt = new wxCommandEvent(); evt->SetString(ss.str()); evt->SetEventObject(obj_ptr); @@ -358,7 +364,7 @@ void LMS7SuiteAppFrame::OnLogDataTransfer(bool Tx, const uint8_t* data, const ui void LMS7SuiteAppFrame::AddModule(IModuleFrame* module, const std::string& title) { wxWindowID moduleId = module->GetId(); - printf("Add module %i\n", moduleId); + lime::debug("Add module %i", moduleId); wxMenuItem* item; item = new wxMenuItem(mnuModules, moduleId, title, wxEmptyString, wxITEM_NORMAL); mnuModules->Append(item); @@ -374,7 +380,7 @@ void LMS7SuiteAppFrame::RemoveModule(IModuleFrame* module) void LMS7SuiteAppFrame::OnModuleClose(wxCloseEvent& event) { - printf("Close module %i\n", event.GetId()); + lime::debug("Close module %i", event.GetId()); IModuleFrame* module = mModules.at(event.GetId()); if (module) { @@ -384,7 +390,7 @@ void LMS7SuiteAppFrame::OnModuleClose(wxCloseEvent& event) void LMS7SuiteAppFrame::OnShowModule(wxCommandEvent& event) { - printf("show module %i\n", event.GetId()); + lime::debug("show module %i", event.GetId()); IModuleFrame* module = mModules.at(event.GetId()); if (module) //it's already opened { @@ -422,7 +428,7 @@ ISOCPanel* CreateGUI(wxWindow* parent, eDeviceNodeClass deviceNodeClass, void* s return sdrPanel; } default: - printf("Unrecognized device class(%u)\n", static_cast(deviceNodeClass)); + lime::warning("Unrecognized device class(%u)", static_cast(deviceNodeClass)); return nullptr; } } diff --git a/src/memory/MemoryPool.cpp b/src/memory/MemoryPool.cpp index f7cdafe27..618606cfd 100644 --- a/src/memory/MemoryPool.cpp +++ b/src/memory/MemoryPool.cpp @@ -1,9 +1,12 @@ #include "MemoryPool.h" + #include #include #include #include +#include "Logger.h" + namespace lime { MemoryPool::MemoryPool(int blockCount, int blockSize, int alignment, const std::string& name) : name(name) @@ -69,7 +72,7 @@ void MemoryPool::Free(void* ptr) { char ctemp[1024]; sprintf(ctemp, - "%s Double free?, allocs: %i , frees: %i, used: %li, free: %li\n ptr: %p", + "%s Double free?, allocs: %i , frees: %i, used: %li, free: %li, ptr: %p", name.c_str(), allocCnt, freeCnt, @@ -77,7 +80,7 @@ void MemoryPool::Free(void* ptr) mFreeBlocks.size(), ptr); for (auto adr : mUsedBlocks) - printf("addrs: %p\n", adr); + lime::error("addrs: %p", adr); throw std::runtime_error(ctemp); } else diff --git a/src/protocols/LMS64CProtocol.cpp b/src/protocols/LMS64CProtocol.cpp index 92a1ee0d0..58a559f2d 100644 --- a/src/protocols/LMS64CProtocol.cpp +++ b/src/protocols/LMS64CProtocol.cpp @@ -19,6 +19,8 @@ const int LMS_RST_DEACTIVATE = 0; const int LMS_RST_ACTIVATE = 1; const int LMS_RST_PULSE = 2; +using namespace std::literals::string_literals; + namespace lime { LMS64CPacket::LMS64CPacket() @@ -512,11 +514,11 @@ int ProgramWrite(ISerialPort& port, auto t2 = std::chrono::high_resolution_clock::now(); if ((device == 2 && prog_mode == 2) == false) lime::log(LogLevel::INFO, - "Programming finished, %li bytes sent! %li ms\n", + "Programming finished, %li bytes sent! %li ms", length, std::chrono::duration_cast(t2 - t1).count()); else - lime::log(LogLevel::INFO, "FPGA configuring initiated\n"); + lime::log(LogLevel::INFO, "FPGA configuring initiated"s); #endif return 0; } diff --git a/src/protocols/PacketsFIFO.h b/src/protocols/PacketsFIFO.h index e761507f2..526f2cbe7 100644 --- a/src/protocols/PacketsFIFO.h +++ b/src/protocols/PacketsFIFO.h @@ -1,15 +1,15 @@ /** @file: PacketsFIFO.h @author: Sander Jobing - + Created on July 29, 2017, 5:17 PM - + This class implements a Single Producer - Single Consumer lock-free and wait-free queue. Only 1 thread can fill the queue, another thread can read from the queue, but no more threads are allowed. This lock-free queue is a fifo queue, the first element inserted is the first element which comes out. - + Thanks to Timur Doumler, Juce https://www.youtube.com/watch?v=qdrp6k4rcP4 */ @@ -20,11 +20,14 @@ #include #include #include +#include +#include +#include #include -#include -#include -#include +#include "Logger.h" + +using namespace std::literals::string_literals; namespace lime { @@ -97,7 +100,7 @@ template class PacketsFIFO { if (canWrite.wait_for(lk, std::chrono::milliseconds(timeout)) == std::cv_status::timeout) { - printf("write fifo timeout\n"); + lime::error("write fifo timeout"s); return false; } } @@ -132,7 +135,7 @@ template class PacketsFIFO // return false; if (canRead.wait_for(lk, std::chrono::milliseconds(timeout)) == std::cv_status::timeout) { - //printf("pop fifo timeout\n"); + //lime::error("pop fifo timeout"s); return false; } } diff --git a/src/protocols/TRXLooper.cpp b/src/protocols/TRXLooper.cpp index a7d42b075..473633103 100644 --- a/src/protocols/TRXLooper.cpp +++ b/src/protocols/TRXLooper.cpp @@ -10,6 +10,7 @@ #include "TRXLooper.h" using namespace std; +using namespace std::literals::string_literals; namespace lime { @@ -607,7 +608,7 @@ void TRXLooper::Stop() mTx.thread.join(); } catch (...) { - printf("Failed to join TRXLooper threads\n"); + lime::error("Failed to join TRXLooper threads"s); } fpga->StopStreaming(); diff --git a/src/utilities_gui/SPI_wxgui.cpp b/src/utilities_gui/SPI_wxgui.cpp index 3fee189c9..4ad82d89f 100644 --- a/src/utilities_gui/SPI_wxgui.cpp +++ b/src/utilities_gui/SPI_wxgui.cpp @@ -2,8 +2,10 @@ #include #include "limesuite/SDRDevice.h" +#include "Logger.h" using namespace lime; +using namespace std::literals::string_literals; void SPI_wxgui::InsertSPIControlsRow(wxWindow* parent, wxWindowID id, wxFlexGridSizer* row, SPI_wxgui::SPIFields* controls) { @@ -165,7 +167,7 @@ void SPI_wxgui::onSPIwrite(wxCommandEvent& event) auto iter = desc.spiSlaveIds.find(std::string(strDevAddr.mb_str())); if (iter == desc.spiSlaveIds.end()) { - printf("Connected device does not have SPI for %s", strDevAddr.mb_str().data()); + lime::warning("Connected device does not have SPI for "s + strDevAddr.mb_str().data()); return; } devAddr = iter->second; @@ -182,7 +184,7 @@ void SPI_wxgui::onSPIwrite(wxCommandEvent& event) } } catch (...) { - printf("No spi controls created for event id: %i", event.GetId()); + lime::error("No spi controls created for event id: %i", event.GetId()); } } @@ -214,7 +216,7 @@ void SPI_wxgui::onSPIread(wxCommandEvent& event) auto iter = desc.spiSlaveIds.find(std::string(strDevAddr.mb_str())); if (iter == desc.spiSlaveIds.end()) { - printf("Connected device does not have SPI for %s", strDevAddr.mb_str().data()); + lime::warning("Connected device does not have SPI for "s + strDevAddr.mb_str().data()); return; } devAddr = iter->second; @@ -233,6 +235,6 @@ void SPI_wxgui::onSPIread(wxCommandEvent& event) } } catch (...) { - printf("No spi controls created for event id: %i", event.GetId()); + lime::error("No spi controls created for event id: %i", event.GetId()); } }