diff --git a/CMakeLists.txt b/CMakeLists.txt index 5194a0bf3..fe747656a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,6 +87,9 @@ if(CMAKE_COMPILER_IS_GNUCXX) add_compile_options(-fvisibility=hidden) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden") + # enable C-style cast warnings in C++ + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wold-style-cast") + #disable gcc caller-saves flag for O2-O3 optimizations #workaround fix for gcc 9.3+ if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") diff --git a/SoapyLMS7/Settings.cpp b/SoapyLMS7/Settings.cpp index 425eba4fa..1e009898b 100644 --- a/SoapyLMS7/Settings.cpp +++ b/SoapyLMS7/Settings.cpp @@ -500,7 +500,7 @@ void SoapyLMS7::setSampleRate(const int direction, const size_t channel, const d throw std::runtime_error("SoapyLMS7::setSampleRate() failed with message " + std::string{ e.what() }); } - sampleRate[bool(direction)] = rate; + sampleRate[static_cast(direction)] = rate; return; } diff --git a/amarisoft-plugin/trx_limesuite.cpp b/amarisoft-plugin/trx_limesuite.cpp index 979ed10a6..abc66d48a 100644 --- a/amarisoft-plugin/trx_limesuite.cpp +++ b/amarisoft-plugin/trx_limesuite.cpp @@ -149,10 +149,10 @@ static_assert(sizeof(txGainTable) / sizeof(TxGainRow) == 51, "missing tx gains r static inline int64_t ts_to_time(int64_t fs, int64_t ts) { - int n, r; + int64_t n, r; n = (ts / fs); r = (ts % fs); - return (int64_t)n * 1000000 + (((int64_t)r * 1000000) / fs); + return n * 1000000 + (r * 1000000 / fs); } struct PortChPair { @@ -297,7 +297,7 @@ static bool OnStreamStatusChange(bool isTx, const SDRDevice::StreamStats* s, voi static TRXStatistics trxstats; static int trx_lms7002m_get_stats(TRXState* s, TRXStatistics* m) { - LimeState* lime = (LimeState*)s->opaque; + LimeState* lime = static_cast(s->opaque); for (long p = 0; p < lime->deviceCount; ++p) { StreamStatus& stats = portStreamStates[p]; @@ -311,7 +311,7 @@ static int trx_lms7002m_get_stats(TRXState* s, TRXStatistics* m) /* Callback must allocate info buffer that will be displayed */ static void trx_lms7002m_dump_info(TRXState* s, trx_printf_cb cb, void* opaque) { - LimeState* lime = (LimeState*)s->opaque; + LimeState* lime = static_cast(s->opaque); std::stringstream ss; for (long p = 0; p < lime->deviceCount; ++p) { @@ -332,7 +332,7 @@ static void trx_lms7002m_dump_info(TRXState* s, trx_printf_cb cb, void* opaque) // TODO: read FIFO usage } const int len = ss.str().length(); - char* buffer = (char*)malloc(len + 1); + char* buffer = static_cast(malloc(len + 1)); cb(buffer, "%s\n", ss.str().c_str()); } @@ -351,7 +351,7 @@ static void trx_lms7002m_write( meta.flush = (md->flags & TRX_WRITE_MD_FLAG_END_OF_BURST); // samples format conversion is done internally - LimeState* lime = (LimeState*)s->opaque; + LimeState* lime = static_cast(s->opaque); int samplesConsumed = lime->device[port]->StreamTx(lime->chipIndex[port], reinterpret_cast(samples), count, &meta); if (logVerbosity == LogLevel::DEBUG && samplesConsumed != count) @@ -372,7 +372,7 @@ static void trx_lms7002m_write( // return number of samples produced static int trx_lms7002m_read(TRXState* s, trx_timestamp_t* ptimestamp, void** samples, int count, int port, TRXReadMetadata* md) { - LimeState* lime = (LimeState*)s->opaque; + LimeState* lime = static_cast(s->opaque); SDRDevice::StreamMeta meta; meta.useTimestamp = false; @@ -497,7 +497,7 @@ static int trx_lms7002m_get_sample_rate(TRXState* s1, TRXFraction* psample_rate, // !!! sometimes trx_lms7002m_write gets calls with samples count more than returned here static int trx_lms7002m_get_tx_samples_per_packet_func(TRXState* s1) { - LimeState* lime = (LimeState*)s1->opaque; + LimeState* lime = static_cast(s1->opaque); int txExpectedSamples = lime->samplesInPacket[0]; if (lime->streamCfg[0].extraConfig.txSamplesInPacket > 0) { @@ -509,7 +509,7 @@ static int trx_lms7002m_get_tx_samples_per_packet_func(TRXState* s1) static int trx_lms7002m_get_abs_rx_power_func(TRXState* s1, float* presult, int channel_num) { - LimeState* s = (LimeState*)s1->opaque; + LimeState* s = static_cast(s1->opaque); const PortChPair& pair = gMapTxChannelToPortCh[channel_num]; if (s->rxPowerAvailable[pair.port][pair.ch]) { @@ -522,7 +522,7 @@ static int trx_lms7002m_get_abs_rx_power_func(TRXState* s1, float* presult, int static int trx_lms7002m_get_abs_tx_power_func(TRXState* s1, float* presult, int channel_num) { - LimeState* s = (LimeState*)s1->opaque; + LimeState* s = static_cast(s1->opaque); const PortChPair& pair = gMapTxChannelToPortCh[channel_num]; if (s->txPowerAvailable[pair.port][pair.ch]) { @@ -537,9 +537,9 @@ static int trx_lms7002m_get_abs_tx_power_func(TRXState* s1, float* presult, int //max gain ~70-76 (higher will probably degrade signal quality to much) static void trx_lms7002m_set_tx_gain_func(TRXState* s1, double gain, int channel_num) { - LimeState* lime = (LimeState*)s1->opaque; + LimeState* lime = static_cast(s1->opaque); int row = gain; - if (row < 0 || row >= (int)(sizeof(txGainTable) / sizeof(TxGainRow))) + if (row < 0 || row >= static_cast(sizeof(txGainTable) / sizeof(TxGainRow))) return; std::lock_guard lk(gainsMutex); @@ -560,9 +560,9 @@ static void trx_lms7002m_set_tx_gain_func(TRXState* s1, double gain, int channel static void trx_lms7002m_set_rx_gain_func(TRXState* s1, double gain, int channel_num) { - LimeState* lime = (LimeState*)s1->opaque; + LimeState* lime = static_cast(s1->opaque); int row = gain; - if (row < 0 || row >= (int)(sizeof(rxGainTable) / sizeof(RxGainRow))) + if (row < 0 || row >= static_cast(sizeof(rxGainTable) / sizeof(RxGainRow))) return; std::lock_guard lk(gainsMutex); @@ -583,7 +583,7 @@ static void trx_lms7002m_set_rx_gain_func(TRXState* s1, double gain, int channel static int trx_lms7002m_start(TRXState* s1, const TRXDriverParams* hostState) { - LimeState* lime = (LimeState*)s1->opaque; + LimeState* lime = static_cast(s1->opaque); try { @@ -598,7 +598,7 @@ static int trx_lms7002m_start(TRXState* s1, const TRXDriverParams* hostState) lime->tx_channel_count[p] = hostState->tx_port_channel_count[p]; lime->rx_channel_count[p] = hostState->rx_port_channel_count[p]; - const double samplingRate = (float)hostState->sample_rate[p].num / hostState->sample_rate[p].den; + const double samplingRate = static_cast(hostState->sample_rate[p].num) / hostState->sample_rate[p].den; config.channel[0].rx.sampleRate = samplingRate; config.channel[0].tx.sampleRate = samplingRate; config.channel[0].rx.oversample = lime->rxOversample[p]; @@ -649,7 +649,7 @@ static int trx_lms7002m_start(TRXState* s1, const TRXDriverParams* hostState) } else sprintf(loFreqStr, "LO: %.3f MHz", freq / 1.0e6); - gMapRxChannelToPortCh[rxChannelOffset + ch] = { (uint8_t)p, (uint8_t)ch }; + gMapRxChannelToPortCh[rxChannelOffset + ch] = { static_cast(p), static_cast(ch) }; Log(LogLevel::INFO, "Port[%i] Rx CH[%i] %s, SR: %.3f MHz BW: %.3f MHz | chipIndex: %i, path: %i('%s')\n", p, @@ -696,7 +696,7 @@ static int trx_lms7002m_start(TRXState* s1, const TRXDriverParams* hostState) } else sprintf(loFreqStr, "LO: %.3f MHz", freq / 1.0e6); - gMapTxChannelToPortCh[txChannelOffset + ch] = { (uint8_t)p, (uint8_t)ch }; + gMapTxChannelToPortCh[txChannelOffset + ch] = { static_cast(p), static_cast(ch) }; Log(LogLevel::INFO, "Port[%i] Tx CH[%i] %s, SR: %.3f MHz BW: %.3f MHz | chipIndex: %i, path: %i('%s')\n", p, @@ -790,7 +790,7 @@ static int trx_lms7002m_start(TRXState* s1, const TRXDriverParams* hostState) } stream.statusCallback = OnStreamStatusChange; - stream.userData = (void*)&portStreamStates[p]; + stream.userData = static_cast(&portStreamStates[p]); stream.hintSampleRate = samplingRate; stream.extraConfig = lime->streamCfg[p].extraConfig; @@ -830,7 +830,7 @@ static int trx_lms7002m_start(TRXState* s1, const TRXDriverParams* hostState) static void trx_lms7002m_end(TRXState* s1) { - LimeState* lime = (LimeState*)s1->opaque; + LimeState* lime = static_cast(s1->opaque); for (int p = 0; p < lime->deviceCount; ++p) { SDRDevice* portDevice = lime->device[p]; diff --git a/src/ADF4002/ADF4002.cpp b/src/ADF4002/ADF4002.cpp index 8a517a5e1..a4f2fa3fe 100644 --- a/src/ADF4002/ADF4002.cpp +++ b/src/ADF4002/ADF4002.cpp @@ -36,7 +36,7 @@ int ADF4002::UploadConfig() std::vector dataWr; for (int i = 0; i < 12; i += 3) - dataWr.push_back((uint32_t)data[i] << 16 | (uint32_t)data[i + 1] << 8 | data[i + 2]); + dataWr.push_back(static_cast(data[i]) << 16 | static_cast(data[i + 1]) << 8 | data[i + 2]); // ADF4002 needs to be writen 4 values of 24 bits mComms->SPI(dataWr.data(), nullptr, 4); @@ -95,7 +95,7 @@ void ADF4002::MakeData() m_registers[0x00] = 0x00; //R Value LSB itmp = txtRCnt; - btmp = (char)itmp; + btmp = static_cast(itmp); btmp = btmp << 2; m_registers[0x00] |= btmp; //Addr @@ -106,20 +106,20 @@ void ADF4002::MakeData() //======= register addr 0x01 ======= m_registers[0x01] = 0x00; //R Value MSB - btmp = (char)(itmp >> 6); + btmp = static_cast((itmp >> 6)); btmp = btmp << 0; m_registers[0x01] |= btmp; //======= register addr 0x02 ======= m_registers[0x02] = 0x00; //Anti-Backlash - btmp = (char)cmbABW; + btmp = static_cast(cmbABW); if (btmp > 0) btmp++; btmp = btmp << 0; m_registers[0x02] |= btmp; //Lock Detact Precision - btmp = (char)cmbLDP; + btmp = static_cast(cmbLDP); btmp = btmp << 4; m_registers[0x02] |= btmp; @@ -134,7 +134,7 @@ void ADF4002::MakeData() m_registers[0x04] = 0x00; //N Value LSB itmp = txtNCnt; - btmp = (char)itmp; + btmp = static_cast(itmp); btmp = btmp << 0; m_registers[0x04] |= btmp; @@ -142,11 +142,11 @@ void ADF4002::MakeData() m_registers[0x05] = 0x00; //N Value MSB itmp = txtNCnt; - btmp = (char)(itmp >> 8); + btmp = static_cast((itmp >> 8)); btmp = btmp << 0; m_registers[0x05] |= btmp; //CP Gain - btmp = (char)cmbCPG; + btmp = static_cast(cmbCPG); btmp = btmp << 5; m_registers[0x05] |= btmp; @@ -157,55 +157,55 @@ void ADF4002::MakeData() btmp = btmp << 0; m_registers[0x06] |= btmp; //Counter Reset - btmp = (char)rgrCR_f; + btmp = static_cast(rgrCR_f); btmp = btmp << 2; m_registers[0x06] |= btmp; //PD 1 - btmp = (char)rgrPD1_f; + btmp = static_cast(rgrPD1_f); btmp = btmp << 3; m_registers[0x06] |= btmp; //Muxout Control - btmp = (char)cmbMOC_f; + btmp = static_cast(cmbMOC_f); btmp = btmp << 4; m_registers[0x06] |= btmp; //PD Polarity - btmp = (char)rgrPDP_f; + btmp = static_cast(rgrPDP_f); btmp = btmp << 7; m_registers[0x06] |= btmp; //======= register addr 0x07 ======= m_registers[0x07] = 0x00; //CP State - btmp = (char)rgrCPS_f; + btmp = static_cast(rgrCPS_f); btmp = btmp << 0; m_registers[0x07] |= btmp; //Fastlock - btmp = (char)cmbFL_f; + btmp = static_cast(cmbFL_f); if (btmp > 0) btmp++; btmp = btmp << 1; m_registers[0x07] |= btmp; //Timer Counter - btmp = (char)cmbTC_f; + btmp = static_cast(cmbTC_f); btmp = btmp << 3; m_registers[0x07] |= btmp; //Current Setting 1 MSB - btmp = (char)cmbCS1_f; + btmp = static_cast(cmbCS1_f); btmp = btmp << 7; m_registers[0x07] |= btmp; //======= register addr 0x08 ======= m_registers[0x08] = 0x00; //Current Setting 1 LSB - btmp = (char)cmbCS1_f; + btmp = static_cast(cmbCS1_f); btmp = btmp >> 1; m_registers[0x08] |= btmp; //Current Setting 2 - btmp = (char)cmbCS2_f; + btmp = static_cast(cmbCS2_f); btmp = btmp << 2; m_registers[0x08] |= btmp; //PD 2 - btmp = (char)rgrPD2_f; + btmp = static_cast(rgrPD2_f); btmp = btmp << 5; m_registers[0x08] |= btmp; @@ -216,55 +216,55 @@ void ADF4002::MakeData() btmp = btmp << 0; m_registers[0x09] |= btmp; //Counter Reset - btmp = (char)rgrCR_i; + btmp = static_cast(rgrCR_i); btmp = btmp << 2; m_registers[0x09] |= btmp; //PD 1 - btmp = (char)rgrPD1_i; + btmp = static_cast(rgrPD1_i); btmp = btmp << 3; m_registers[0x09] |= btmp; //Muxout Control - btmp = (char)cmbMOC_i; + btmp = static_cast(cmbMOC_i); btmp = btmp << 4; m_registers[0x09] |= btmp; //PD Polarity - btmp = (char)rgrPDP_i; + btmp = static_cast(rgrPDP_i); btmp = btmp << 7; m_registers[0x09] |= btmp; //======= register addr 0x0A ======= m_registers[0x0A] = 0x00; //CP State - btmp = (char)rgrCPS_i; + btmp = static_cast(rgrCPS_i); btmp = btmp << 0; m_registers[0x0A] |= btmp; //Fastlock - btmp = (char)cmbFL_i; + btmp = static_cast(cmbFL_i); if (btmp > 0) btmp++; btmp = btmp << 1; m_registers[0x0A] |= btmp; //Timer Counter - btmp = (char)cmbTC_i; + btmp = static_cast(cmbTC_i); btmp = btmp << 3; m_registers[0x0A] |= btmp; //Current Setting 1 MSB - btmp = (char)cmbCS1_i; + btmp = static_cast(cmbCS1_i); btmp = btmp << 7; m_registers[0x0A] |= btmp; //======= register addr 0x0B ======= m_registers[0x0B] = 0x00; //Current Setting 1 LSB - btmp = (char)cmbCS1_i; + btmp = static_cast(cmbCS1_i); btmp = btmp >> 1; m_registers[0x0B] |= btmp; //Current Setting 2 - btmp = (char)cmbCS2_i; + btmp = static_cast(cmbCS2_i); btmp = btmp << 2; m_registers[0x0B] |= btmp; //PD 2 - btmp = (char)rgrPD2_i; + btmp = static_cast(rgrPD2_i); btmp = btmp << 5; m_registers[0x0B] |= btmp; @@ -311,8 +311,8 @@ void ADF4002::CalculateRN() }; Fcomp = (x + y) / 1000000.0; - int R = (int)((txtFref / Fcomp) + 0.5); - int N = (int)((txtFvco / Fcomp) + 0.5); + int R = std::round(txtFref / Fcomp); + int N = std::round(txtFvco / Fcomp); txtRCnt = R; txtNCnt = N; diff --git a/src/ADF4002/ADF4002_wxgui.cpp b/src/ADF4002/ADF4002_wxgui.cpp index 4dd2078f7..853a60aff 100644 --- a/src/ADF4002/ADF4002_wxgui.cpp +++ b/src/ADF4002/ADF4002_wxgui.cpp @@ -509,8 +509,8 @@ ADF4002_wxgui::ADF4002_wxgui(wxWindow* parent, wxWindowID id, const wxPoint& pos FlexGridSizer1->Fit(this); FlexGridSizer1->SetSizeHints(this); - Connect(ID_BUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&ADF4002_wxgui::OnbtnCalcSendClick); - Connect(ID_BUTTON2, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&ADF4002_wxgui::OnbtnUploadClick); + Connect(ID_BUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, reinterpret_cast(&ADF4002_wxgui::OnbtnCalcSendClick)); + Connect(ID_BUTTON2, wxEVT_COMMAND_BUTTON_CLICKED, reinterpret_cast(&ADF4002_wxgui::OnbtnUploadClick)); //*) } diff --git a/src/CDCM6208/CDCM6208_Dev.cpp b/src/CDCM6208/CDCM6208_Dev.cpp index f67db8c25..2943adf73 100644 --- a/src/CDCM6208/CDCM6208_Dev.cpp +++ b/src/CDCM6208/CDCM6208_Dev.cpp @@ -60,25 +60,27 @@ int CDCM_Dev::Reset(double primaryFreq, double secondaryFreq) uint16_t addr; uint16_t val; }; - std::map CDCM_Regs = { { 1, { (uint16_t)(SPI_BASE_ADDR + 1), 0x0000 } }, - { 2, { (uint16_t)(SPI_BASE_ADDR + 2), 0x0018 } }, - { 3, { (uint16_t)(SPI_BASE_ADDR + 3), 0x00F0 } }, - { 4, { (uint16_t)(SPI_BASE_ADDR + 4), 0x20FF } }, - { 6, { (uint16_t)(SPI_BASE_ADDR + 6), 0x0018 } }, - { 8, { (uint16_t)(SPI_BASE_ADDR + 8), 0x0018 } }, - { 9, { (uint16_t)(SPI_BASE_ADDR + 9), 0x0003 } }, - { 10, { (uint16_t)(SPI_BASE_ADDR + 10), 0x0180 } }, - { 11, { (uint16_t)(SPI_BASE_ADDR + 11), 0x0000 } }, - { 12, { (uint16_t)(SPI_BASE_ADDR + 12), 0x0003 } }, - { 13, { (uint16_t)(SPI_BASE_ADDR + 13), 0x0180 } }, - { 14, { (uint16_t)(SPI_BASE_ADDR + 14), 0x0000 } }, - { 15, { (uint16_t)(SPI_BASE_ADDR + 15), 0x0003 } }, - { 16, { (uint16_t)(SPI_BASE_ADDR + 16), 0x0180 } }, - { 17, { (uint16_t)(SPI_BASE_ADDR + 17), 0x0000 } }, - { 18, { (uint16_t)(SPI_BASE_ADDR + 18), 0x0003 } }, - { 19, { (uint16_t)(SPI_BASE_ADDR + 19), 0x0180 } }, - { 20, { (uint16_t)(SPI_BASE_ADDR + 20), 0x0000 } }, - { 23, { (uint16_t)(SPI_BASE_ADDR + 23), 0x010A } } }; + std::map CDCM_Regs = { + { 1, { static_cast(SPI_BASE_ADDR + 1), 0x0000 } }, + { 2, { static_cast(SPI_BASE_ADDR + 2), 0x0018 } }, + { 3, { static_cast(SPI_BASE_ADDR + 3), 0x00F0 } }, + { 4, { static_cast(SPI_BASE_ADDR + 4), 0x20FF } }, + { 6, { static_cast(SPI_BASE_ADDR + 6), 0x0018 } }, + { 8, { static_cast(SPI_BASE_ADDR + 8), 0x0018 } }, + { 9, { static_cast(SPI_BASE_ADDR + 9), 0x0003 } }, + { 10, { static_cast(SPI_BASE_ADDR + 10), 0x0180 } }, + { 11, { static_cast(SPI_BASE_ADDR + 11), 0x0000 } }, + { 12, { static_cast(SPI_BASE_ADDR + 12), 0x0003 } }, + { 13, { static_cast(SPI_BASE_ADDR + 13), 0x0180 } }, + { 14, { static_cast(SPI_BASE_ADDR + 14), 0x0000 } }, + { 15, { static_cast(SPI_BASE_ADDR + 15), 0x0003 } }, + { 16, { static_cast(SPI_BASE_ADDR + 16), 0x0180 } }, + { 17, { static_cast(SPI_BASE_ADDR + 17), 0x0000 } }, + { 18, { static_cast(SPI_BASE_ADDR + 18), 0x0003 } }, + { 19, { static_cast(SPI_BASE_ADDR + 19), 0x0180 } }, + { 20, { static_cast(SPI_BASE_ADDR + 20), 0x0000 } }, + { 23, { static_cast(SPI_BASE_ADDR + 23), 0x010A } }, + }; for (auto reg : CDCM_Regs) if (WriteRegister(reg.second.addr, reg.second.val) != 0) @@ -233,14 +235,14 @@ int CDCM_Dev::SetFrequency(cdcm_output_t output, double frequency, bool upload) } if (Outputs.Y0Y1.used) - Outputs.Y0Y1.divider_val = (int)round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y0Y1.requested_freq); + Outputs.Y0Y1.divider_val = std::round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y0Y1.requested_freq); else - Outputs.Y0Y1.divider_val = (int)round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y0Y1.output_freq); + Outputs.Y0Y1.divider_val = std::round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y0Y1.output_freq); if (Outputs.Y2Y3.used) - Outputs.Y2Y3.divider_val = (int)round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y2Y3.requested_freq); + Outputs.Y2Y3.divider_val = std::round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y2Y3.requested_freq); else - Outputs.Y2Y3.divider_val = (int)round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y2Y3.output_freq); + Outputs.Y2Y3.divider_val = std::round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y2Y3.output_freq); if (Outputs.Y4.used) Outputs.Y4.divider_val = (VCO.output_freq / VCO.prescaler_A) / Outputs.Y4.requested_freq; @@ -303,14 +305,14 @@ int CDCM_Dev::RecalculateFrequencies() } if (Outputs.Y0Y1.used) - Outputs.Y0Y1.divider_val = (int)round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y0Y1.requested_freq); + Outputs.Y0Y1.divider_val = std::round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y0Y1.requested_freq); else - Outputs.Y0Y1.divider_val = (int)round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y0Y1.output_freq); + Outputs.Y0Y1.divider_val = std::round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y0Y1.output_freq); if (Outputs.Y2Y3.used) - Outputs.Y2Y3.divider_val = (int)round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y2Y3.requested_freq); + Outputs.Y2Y3.divider_val = std::round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y2Y3.requested_freq); else - Outputs.Y2Y3.divider_val = (int)round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y2Y3.output_freq); + Outputs.Y2Y3.divider_val = std::round((VCO.output_freq / VCO.prescaler_A) / Outputs.Y2Y3.output_freq); if (Outputs.Y4.used) Outputs.Y4.divider_val = (VCO.output_freq / VCO.prescaler_A) / Outputs.Y4.requested_freq; @@ -458,24 +460,26 @@ int CDCM_Dev::UploadConfiguration() uint16_t val; }; - std::map CDCM_Regs = { { 1, { (uint16_t)(SPI_BASE_ADDR + 1), 0 } }, - { 2, { (uint16_t)(SPI_BASE_ADDR + 2), 0 } }, - { 3, { (uint16_t)(SPI_BASE_ADDR + 3), 0 } }, - { 4, { (uint16_t)(SPI_BASE_ADDR + 4), 0 } }, - { 6, { (uint16_t)(SPI_BASE_ADDR + 6), 0 } }, - { 8, { (uint16_t)(SPI_BASE_ADDR + 8), 0 } }, - { 9, { (uint16_t)(SPI_BASE_ADDR + 9), 0 } }, - { 10, { (uint16_t)(SPI_BASE_ADDR + 10), 0 } }, - { 11, { (uint16_t)(SPI_BASE_ADDR + 11), 0 } }, - { 12, { (uint16_t)(SPI_BASE_ADDR + 12), 0 } }, - { 13, { (uint16_t)(SPI_BASE_ADDR + 13), 0 } }, - { 14, { (uint16_t)(SPI_BASE_ADDR + 14), 0 } }, - { 15, { (uint16_t)(SPI_BASE_ADDR + 15), 0 } }, - { 16, { (uint16_t)(SPI_BASE_ADDR + 16), 0 } }, - { 17, { (uint16_t)(SPI_BASE_ADDR + 17), 0 } }, - { 18, { (uint16_t)(SPI_BASE_ADDR + 18), 0 } }, - { 19, { (uint16_t)(SPI_BASE_ADDR + 19), 0 } }, - { 20, { (uint16_t)(SPI_BASE_ADDR + 20), 0 } } }; + std::map CDCM_Regs = { + { 1, { static_cast(SPI_BASE_ADDR + 1), 0 } }, + { 2, { static_cast(SPI_BASE_ADDR + 2), 0 } }, + { 3, { static_cast(SPI_BASE_ADDR + 3), 0 } }, + { 4, { static_cast(SPI_BASE_ADDR + 4), 0 } }, + { 6, { static_cast(SPI_BASE_ADDR + 6), 0 } }, + { 8, { static_cast(SPI_BASE_ADDR + 8), 0 } }, + { 9, { static_cast(SPI_BASE_ADDR + 9), 0 } }, + { 10, { static_cast(SPI_BASE_ADDR + 10), 0 } }, + { 11, { static_cast(SPI_BASE_ADDR + 11), 0 } }, + { 12, { static_cast(SPI_BASE_ADDR + 12), 0 } }, + { 13, { static_cast(SPI_BASE_ADDR + 13), 0 } }, + { 14, { static_cast(SPI_BASE_ADDR + 14), 0 } }, + { 15, { static_cast(SPI_BASE_ADDR + 15), 0 } }, + { 16, { static_cast(SPI_BASE_ADDR + 16), 0 } }, + { 17, { static_cast(SPI_BASE_ADDR + 17), 0 } }, + { 18, { static_cast(SPI_BASE_ADDR + 18), 0 } }, + { 19, { static_cast(SPI_BASE_ADDR + 19), 0 } }, + { 20, { static_cast(SPI_BASE_ADDR + 20), 0 } }, + }; for (int i = 3; i < 24; i += 3) { @@ -497,12 +501,12 @@ int CDCM_Dev::UploadConfiguration() CDCM_Regs[4].val |= ((VCO.R_div - 1) & 0xF) << 8; CDCM_Regs[4].val |= ((VCO.input_mux - 1) & 1) << 12; - CDCM_Regs[6].val = 0 | ((uint16_t)(Outputs.Y0Y1.divider_val - 1) & 0xFF); + CDCM_Regs[6].val = 0 | (static_cast(Outputs.Y0Y1.divider_val - 1) & 0xFF); - CDCM_Regs[8].val = 0 | ((uint16_t)(Outputs.Y2Y3.divider_val - 1) & 0xFF); + CDCM_Regs[8].val = 0 | (static_cast(Outputs.Y2Y3.divider_val - 1) & 0xFF); CDCM_Regs[9].val &= ~0x1E00; - CDCM_Regs[9].val |= (((int)Outputs.Y4.isFrac) << 9); + CDCM_Regs[9].val |= (static_cast(Outputs.Y4.isFrac)) << 9; CDCM_Regs[9].val |= ((Outputs.Y4.prescaler - 2) & 7) << 10; CDCM_Regs[10].val = 0 | (((Outputs.Y4.integer_part - 1) & 0xFF) << 4); @@ -511,7 +515,7 @@ int CDCM_Dev::UploadConfiguration() CDCM_Regs[11].val = Outputs.Y4.fractional_part & 0xFFFF; CDCM_Regs[12].val &= ~0x1E00; - CDCM_Regs[12].val |= (((int)Outputs.Y5.isFrac) << 9); + CDCM_Regs[12].val |= (static_cast(Outputs.Y5.isFrac)) << 9; CDCM_Regs[12].val |= ((Outputs.Y5.prescaler - 2) & 7) << 10; CDCM_Regs[13].val = 0 | (((Outputs.Y5.integer_part - 1) & 0xFF) << 4); @@ -520,7 +524,7 @@ int CDCM_Dev::UploadConfiguration() CDCM_Regs[14].val = Outputs.Y5.fractional_part & 0xFFFF; CDCM_Regs[15].val &= ~0x1E00; - CDCM_Regs[15].val |= (((int)Outputs.Y6.isFrac) << 9); + CDCM_Regs[15].val |= (static_cast(Outputs.Y6.isFrac)) << 9; CDCM_Regs[15].val |= ((Outputs.Y6.prescaler - 2) & 7) << 10; CDCM_Regs[16].val = 0 | (((Outputs.Y6.integer_part - 1) & 0xFF) << 4); @@ -529,7 +533,7 @@ int CDCM_Dev::UploadConfiguration() CDCM_Regs[17].val = Outputs.Y6.fractional_part & 0xFFFF; CDCM_Regs[18].val &= ~0x1E00; - CDCM_Regs[18].val |= (((int)Outputs.Y7.isFrac) << 9); + CDCM_Regs[18].val |= (static_cast(Outputs.Y7.isFrac)) << 9; CDCM_Regs[18].val |= ((Outputs.Y7.prescaler - 2) & 7) << 10; CDCM_Regs[19].val = 0 | (((Outputs.Y7.integer_part - 1) & 0xFF) << 4); @@ -569,26 +573,28 @@ int CDCM_Dev::DownloadConfiguration() uint16_t val; }; - std::map CDCM_Regs = { { 1, { (uint16_t)(SPI_BASE_ADDR + 1), 0 } }, - { 2, { (uint16_t)(SPI_BASE_ADDR + 2), 0 } }, - { 3, { (uint16_t)(SPI_BASE_ADDR + 3), 0 } }, - { 4, { (uint16_t)(SPI_BASE_ADDR + 4), 0 } }, - { 6, { (uint16_t)(SPI_BASE_ADDR + 6), 0 } }, - { 8, { (uint16_t)(SPI_BASE_ADDR + 8), 0 } }, - { 9, { (uint16_t)(SPI_BASE_ADDR + 9), 0 } }, - { 10, { (uint16_t)(SPI_BASE_ADDR + 10), 0 } }, - { 11, { (uint16_t)(SPI_BASE_ADDR + 11), 0 } }, - { 12, { (uint16_t)(SPI_BASE_ADDR + 12), 0 } }, - { 13, { (uint16_t)(SPI_BASE_ADDR + 13), 0 } }, - { 14, { (uint16_t)(SPI_BASE_ADDR + 14), 0 } }, - { 15, { (uint16_t)(SPI_BASE_ADDR + 15), 0 } }, - { 16, { (uint16_t)(SPI_BASE_ADDR + 16), 0 } }, - { 17, { (uint16_t)(SPI_BASE_ADDR + 17), 0 } }, - { 18, { (uint16_t)(SPI_BASE_ADDR + 18), 0 } }, - { 19, { (uint16_t)(SPI_BASE_ADDR + 19), 0 } }, - { 20, { (uint16_t)(SPI_BASE_ADDR + 20), 0 } }, - { 22, { (uint16_t)(SPI_BASE_ADDR + 22), 0 } }, - { 23, { (uint16_t)(SPI_BASE_ADDR + 23), 0 } } }; + std::map CDCM_Regs = { + { 1, { static_cast(SPI_BASE_ADDR + 1), 0 } }, + { 2, { static_cast(SPI_BASE_ADDR + 2), 0 } }, + { 3, { static_cast(SPI_BASE_ADDR + 3), 0 } }, + { 4, { static_cast(SPI_BASE_ADDR + 4), 0 } }, + { 6, { static_cast(SPI_BASE_ADDR + 6), 0 } }, + { 8, { static_cast(SPI_BASE_ADDR + 8), 0 } }, + { 9, { static_cast(SPI_BASE_ADDR + 9), 0 } }, + { 10, { static_cast(SPI_BASE_ADDR + 10), 0 } }, + { 11, { static_cast(SPI_BASE_ADDR + 11), 0 } }, + { 12, { static_cast(SPI_BASE_ADDR + 12), 0 } }, + { 13, { static_cast(SPI_BASE_ADDR + 13), 0 } }, + { 14, { static_cast(SPI_BASE_ADDR + 14), 0 } }, + { 15, { static_cast(SPI_BASE_ADDR + 15), 0 } }, + { 16, { static_cast(SPI_BASE_ADDR + 16), 0 } }, + { 17, { static_cast(SPI_BASE_ADDR + 17), 0 } }, + { 18, { static_cast(SPI_BASE_ADDR + 18), 0 } }, + { 19, { static_cast(SPI_BASE_ADDR + 19), 0 } }, + { 20, { static_cast(SPI_BASE_ADDR + 20), 0 } }, + { 22, { static_cast(SPI_BASE_ADDR + 22), 0 } }, + { 23, { static_cast(SPI_BASE_ADDR + 23), 0 } }, + }; if (PrepareToReadRegs() != 0) return -1; @@ -620,28 +626,28 @@ int CDCM_Dev::DownloadConfiguration() Outputs.Y0Y1.divider_val = (CDCM_Regs[6].val & 0xFF) + 1; Outputs.Y2Y3.divider_val = (CDCM_Regs[8].val & 0xFF) + 1; - Outputs.Y4.isFrac = (bool)((CDCM_Regs[9].val >> 9) & 1); + Outputs.Y4.isFrac = static_cast((CDCM_Regs[9].val >> 9) & 1); Outputs.Y4.prescaler = ((CDCM_Regs[9].val >> 10) & 7) + 2; Outputs.Y4.integer_part = ((CDCM_Regs[10].val >> 4) & 0xFF) + 1; Outputs.Y4.fractional_part = 0 | ((CDCM_Regs[10].val & 0xF) << 16); Outputs.Y4.fractional_part |= CDCM_Regs[11].val; CalculateFracDiv(&Outputs.Y4); - Outputs.Y5.isFrac = (bool)((CDCM_Regs[12].val >> 9) & 1); + Outputs.Y5.isFrac = static_cast((CDCM_Regs[12].val >> 9) & 1); Outputs.Y5.prescaler = ((CDCM_Regs[12].val >> 10) & 7) + 2; Outputs.Y5.integer_part = ((CDCM_Regs[13].val >> 4) & 0xFF) + 1; Outputs.Y5.fractional_part = 0 | ((CDCM_Regs[13].val & 0xF) << 16); Outputs.Y5.fractional_part |= CDCM_Regs[14].val; CalculateFracDiv(&Outputs.Y5); - Outputs.Y6.isFrac = (bool)((CDCM_Regs[15].val >> 9) & 1); + Outputs.Y6.isFrac = static_cast((CDCM_Regs[15].val >> 9) & 1); Outputs.Y6.prescaler = ((CDCM_Regs[15].val >> 10) & 7) + 2; Outputs.Y6.integer_part = ((CDCM_Regs[16].val >> 4) & 0xFF) + 1; Outputs.Y6.fractional_part = 0 | ((CDCM_Regs[16].val & 0xF) << 16); Outputs.Y6.fractional_part |= CDCM_Regs[17].val; CalculateFracDiv(&Outputs.Y6); - Outputs.Y7.isFrac = (bool)((CDCM_Regs[18].val >> 9) & 1); + Outputs.Y7.isFrac = static_cast((CDCM_Regs[18].val >> 9) & 1); Outputs.Y7.prescaler = ((CDCM_Regs[18].val >> 10) & 7) + 2; Outputs.Y7.integer_part = ((CDCM_Regs[19].val >> 4) & 0xFF) + 1; Outputs.Y7.fractional_part = 0 | ((CDCM_Regs[19].val & 0xF) << 16); @@ -657,7 +663,7 @@ int CDCM_Dev::DownloadConfiguration() return 0; } -/** +/** @brief Finds fractional dividers integer and fractional parts values. @param target The requested fractional divider target. @param[out] Output Output to which fractional divider the value is found. @@ -673,7 +679,7 @@ double CDCM_Dev::SolveFracDiv(double target, CDCM_Output* Output) // 1 0000 0000 1111 1111 1111 1111 1111 // \ int / \ fractional / - double max_fractional_val = (((1 << 28) + ((1 << 20) - 1)) / (double)(1 << 20)) * 3; + double max_fractional_val = (((1 << 28) + ((1 << 20) - 1)) / static_cast(1 << 20)) * 3; double result = target; // Check bounds @@ -693,13 +699,13 @@ double CDCM_Dev::SolveFracDiv(double target, CDCM_Output* Output) div3_result = result / 3; // Cast float into 8.20 fixed point integer - div2_fixed = (int)(div2_result * ((1 << 20) & ((1 << 28) - 1))); + div2_fixed = static_cast(div2_result * ((1 << 20) & ((1 << 28) - 1))); // Recast back - div2_result = (float)div2_fixed / (1 << 20); + div2_result = static_cast(div2_fixed) / (1 << 20); // Cast float into 8.20 fixed point integer - div3_fixed = (int)(div3_result * ((1 << 20) & ((1 << 28) - 1))); + div3_fixed = static_cast(div3_result * ((1 << 20) & ((1 << 28) - 1))); // Recast back - div3_result = (float)div3_fixed / (1 << 20); + div3_result = static_cast(div3_fixed) / (1 << 20); // Find best match double div2_difference = abs(result - (div2_result * 2.0)); double div3_difference = abs(result - (div3_result * 3.0)); @@ -721,7 +727,7 @@ double CDCM_Dev::SolveFracDiv(double target, CDCM_Output* Output) return result; } -/** +/** @brief Finds 8-bit and 10-bit multiplier values. @param Target The requested fractional divider target. @param[out] Mult8bit 8-bit multiplier value. @@ -734,13 +740,13 @@ int CDCM_Dev::SolveN(int Target, int* Mult8bit, int* Mult10bit) double res; for (int i10 = 1; i10 <= 1024; i10++) { - res = double(Target) / i10; + res = static_cast(Target) / i10; if (res < (1 << 8)) // Check max value { // Check if res is integer if (IsInteger(res)) { - *Mult8bit = (int)res; + *Mult8bit = static_cast(res); *Mult10bit = i10; return 0; } @@ -749,7 +755,7 @@ int CDCM_Dev::SolveN(int Target, int* Mult8bit, int* Mult10bit) return -1; } -/** +/** @brief Calculates full divider value based on integer and fractional parts. @param[in] Output CDCM Output. */ @@ -768,7 +774,7 @@ void CDCM_Dev::CalculateFracDiv(CDCM_Output* Output) } } -/** +/** @brief Calculates CDCM output frequencies based on current VCO configuration. */ void CDCM_Dev::UpdateOutputFrequencies() @@ -788,7 +794,7 @@ void CDCM_Dev::UpdateOutputFrequencies() Outputs.Y7.output_freq = (VCO.output_freq / VCO.prescaler_B) / Outputs.Y7.divider_val; } -/** +/** @brief Prepare to read the FPGA registers. @return 0 on success; -1 on failure. */ @@ -813,7 +819,7 @@ int CDCM_Dev::PrepareToReadRegs() return 0; } -/** +/** @brief Calculates numerator and denumenator values from decimal. @param decimal Decimal value. @param[out] num Numerator value. @@ -834,7 +840,7 @@ double CDCM_Dev::DecToFrac(double decimal, int* num, int* den) l_den *= 10; decimal *= 10; } - l_num = (uint64_t)decimal; + l_num = static_cast(decimal); uint64_t gcd = FindGCD(l_num, l_den); l_num /= gcd; @@ -869,13 +875,13 @@ double CDCM_Dev::DecToFrac(double decimal, int* num, int* den) l_num = l_num >> 1; } // Return values - *num = (int)l_num; - *den = (int)l_den; - double result_freq = *num / (double)*den; + *num = static_cast(l_num); + *den = static_cast(l_den); + double result_freq = *num / static_cast(*den); return (fabs(1 - (l_target / result_freq))); } -/** +/** @brief Find all available VCO configurations based on @p lcm value. @param lcm The least common multiple value. @param version VCO version. @@ -912,7 +918,7 @@ std::vector CDCM_Dev::FindValidVCOFreqs(double lcm, int version) return Config_vector; } -/** +/** @brief Euclidean method to find greatest common divisor between two integers. @param a First integer. @param b Second integer. @@ -925,7 +931,7 @@ uint64_t CDCM_Dev::FindGCD(uint64_t a, uint64_t b) return FindGCD(b, a % b); } -/** +/** @brief Finds the index of VCO input vector which has lowest Prescaler A value. @param input Vector of VCO configurations. @return Index of lowest input. @@ -947,7 +953,7 @@ int CDCM_Dev::FindLowestPSAOutput(std::vector input) return index; } -/** +/** @brief Finds the index of VCO input vector which has lowest frequency error. @param input Vector of VCO configurations. @return Index of lowest input. @@ -967,7 +973,7 @@ int CDCM_Dev::GetLowestFreqErr(std::vector input) return index; } -/** +/** @brief Finds best VCO configuration index. @param input Vector of VCO configurations. @param num_errors How many errors there are in all configurations. @@ -997,7 +1003,7 @@ int CDCM_Dev::FindBestVCOConfigIndex(std::vector& input, int num_error } } -/** +/** @brief Finds VCO configuration based on requested output frequencies. @return VCO configuration. */ @@ -1019,7 +1025,7 @@ CDCM_VCO CDCM_Dev::FindVCOConfig() bool do_vco_calc = true; if (Outputs.Y0Y1.used && Outputs.Y2Y3.used) - int_lcm = (l_Y0Y1 * l_Y2Y3) / FindGCD((uint64_t)l_Y0Y1, (uint64_t)l_Y2Y3); + int_lcm = (l_Y0Y1 * l_Y2Y3) / FindGCD(static_cast(l_Y0Y1), static_cast(l_Y2Y3)); else if (Outputs.Y0Y1.used) int_lcm = l_Y0Y1; else if (Outputs.Y2Y3.used) diff --git a/src/CDCM6208/CDCM6208_Dev.h b/src/CDCM6208/CDCM6208_Dev.h index a4078d4ec..7ebe68f84 100644 --- a/src/CDCM6208/CDCM6208_Dev.h +++ b/src/CDCM6208/CDCM6208_Dev.h @@ -3,6 +3,9 @@ #include "limesuite/config.h" #include "FPGA_common.h" +#include +#include + #define CDCM_VCO_MIN_V1 2390 * 1e6 #define CDCM_VCO_MAX_V1 2550 * 1e6 #define CDCM_VCO_MIN_V2 2940 * 1e6 @@ -135,11 +138,11 @@ class LIME_API CDCM_Dev double DecToFrac(double target, int* num, int* den); /** - @brief Checks if the given double is an integer. + @brief Checks if the given double is an integer. @param var The double to check. @return Whether the double is an integer or not. */ - bool IsInteger(double var) { return var == (int64_t)var; } + bool IsInteger(double var) { return var == static_cast(var); } std::vector FindValidVCOFreqs(double lcm, int version); uint64_t FindGCD(uint64_t a, uint64_t b); int GetLowestFreqErr(std::vector input); diff --git a/src/CDCM6208/CDCM6208_panelgui.cpp b/src/CDCM6208/CDCM6208_panelgui.cpp index d8f094be4..e1cc9b9da 100644 --- a/src/CDCM6208/CDCM6208_panelgui.cpp +++ b/src/CDCM6208/CDCM6208_panelgui.cpp @@ -914,18 +914,18 @@ void CDCM6208_panelgui::OnFreqEntry(wxCommandEvent& event) int return_val = -1; CDCM_Outputs Outputs = CDCM->GetOutputs(); - if ((bool)m_Y0Y1_chk->GetValue()) - Outputs.Y0Y1.requested_freq = std::stod((std::string)m_Y0Y1_FREQ_req->GetValue()) * 1e6; - if ((bool)m_Y2Y3_chk->GetValue()) - Outputs.Y2Y3.requested_freq = std::stod((std::string)m_Y2Y3_FREQ_req->GetValue()) * 1e6; - if ((bool)m_Y4_chk->GetValue()) - Outputs.Y4.requested_freq = std::stod((std::string)m_Y4_FREQ_req->GetValue()) * 1e6; - if ((bool)m_Y5_chk->GetValue()) - Outputs.Y5.requested_freq = std::stod((std::string)m_Y5_FREQ_req->GetValue()) * 1e6; - if ((bool)m_Y6_chk->GetValue()) - Outputs.Y6.requested_freq = std::stod((std::string)m_Y6_FREQ_req->GetValue()) * 1e6; - if ((bool)m_Y7_chk->GetValue()) - Outputs.Y7.requested_freq = std::stod((std::string)m_Y7_FREQ_req->GetValue()) * 1e6; + if (static_cast(m_Y0Y1_chk->GetValue())) + Outputs.Y0Y1.requested_freq = std::stod(std::string{ m_Y0Y1_FREQ_req->GetValue() }) * 1e6; + if (static_cast(m_Y2Y3_chk->GetValue())) + Outputs.Y2Y3.requested_freq = std::stod(std::string{ m_Y2Y3_FREQ_req->GetValue() }) * 1e6; + if (static_cast(m_Y4_chk->GetValue())) + Outputs.Y4.requested_freq = std::stod(std::string{ m_Y4_FREQ_req->GetValue() }) * 1e6; + if (static_cast(m_Y5_chk->GetValue())) + Outputs.Y5.requested_freq = std::stod(std::string{ m_Y5_FREQ_req->GetValue() }) * 1e6; + if (static_cast(m_Y6_chk->GetValue())) + Outputs.Y6.requested_freq = std::stod(std::string{ m_Y6_FREQ_req->GetValue() }) * 1e6; + if (static_cast(m_Y7_chk->GetValue())) + Outputs.Y7.requested_freq = std::stod(std::string{ m_Y7_FREQ_req->GetValue() }) * 1e6; CDCM->SetOutputs(Outputs); return_val = CDCM->RecalculateFrequencies(); @@ -953,12 +953,12 @@ void CDCM6208_panelgui::onFP_chk(wxCommandEvent& event) { CDCM_Outputs Outputs = CDCM->GetOutputs(); - Outputs.Y0Y1.used = (bool)m_Y0Y1_chk->GetValue(); - Outputs.Y2Y3.used = (bool)m_Y2Y3_chk->GetValue(); - Outputs.Y4.used = (bool)m_Y4_chk->GetValue(); - Outputs.Y5.used = (bool)m_Y5_chk->GetValue(); - Outputs.Y6.used = (bool)m_Y6_chk->GetValue(); - Outputs.Y7.used = (bool)m_Y7_chk->GetValue(); + Outputs.Y0Y1.used = static_cast(m_Y0Y1_chk->GetValue()); + Outputs.Y2Y3.used = static_cast(m_Y2Y3_chk->GetValue()); + Outputs.Y4.used = static_cast(m_Y4_chk->GetValue()); + Outputs.Y5.used = static_cast(m_Y5_chk->GetValue()); + Outputs.Y6.used = static_cast(m_Y6_chk->GetValue()); + Outputs.Y7.used = static_cast(m_Y7_chk->GetValue()); CDCM->SetOutputs(Outputs); CDCM->UpdateOutputFrequencies(); @@ -1033,7 +1033,7 @@ void CDCM6208_panelgui::UpdateGUI() m_VCOFREQ->SetForegroundColour(wxColour("#000000")); //Y0Y1 divider - str = std::to_string((int)Outputs.Y0Y1.divider_val); + str = std::to_string(static_cast(Outputs.Y0Y1.divider_val)); m_Y0Y1_DIV->SetValue(str); //Y0Y1 Frequency str = std::to_string(Outputs.Y0Y1.output_freq / 1e6); @@ -1043,7 +1043,7 @@ void CDCM6208_panelgui::UpdateGUI() m_Y0Y1_FREQ_req->SetValue(str); //Y2Y3 divider - str = std::to_string((int)Outputs.Y2Y3.divider_val); + str = std::to_string(static_cast(Outputs.Y2Y3.divider_val)); m_Y2Y3_DIV->SetValue(str); //Y2Y3 Frequency str = std::to_string(Outputs.Y2Y3.output_freq / 1e6); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 14a42b03c..c22083de4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -68,7 +68,7 @@ set(LIME_SUITE_SOURCES include/limesuite/SDRDevice.cpp ) -SET_SOURCE_FILES_PROPERTIES( +SET_SOURCE_FILES_PROPERTIES( mcu_program/common_src/lms7002m_calibrations.c mcu_program/common_src/lms7002m_controls.c mcu_program/common_src/lms7002m_filters.c diff --git a/src/DSP/Equalizer.cpp b/src/DSP/Equalizer.cpp index dc4b8ae1f..db5eca52b 100644 --- a/src/DSP/Equalizer.cpp +++ b/src/DSP/Equalizer.cpp @@ -102,7 +102,7 @@ void Equalizer::Configure(const Equalizer::Config& state) const Config::CFR& cfr = state.cfr[ch]; const Config::FIR& fir = state.fir[ch]; - const bool useOversample = std::min(cfr.interpolation, uint8_t(2)) != 1; + const bool useOversample = std::min(cfr.interpolation, 2) != 1; WriteRegister(TX_HB_BYP, !useOversample); WriteRegister(TX_HB_DEL, useOversample); @@ -147,7 +147,7 @@ void Equalizer::UpdateHannCoeff(uint16_t Filt_N) Filt_N = std::min(Filt_N, MaxFilt_N); for (i = 0; i < Filt_N; ++i) - w[i] = (uint16_t)(32768.0 * 0.25 * (1.0 - cos(2.0 * M_PI * i / (Filt_N - 1)))); + w[i] = static_cast(32768.0 * 0.25 * (1.0 - cos(2.0 * M_PI * i / (Filt_N - 1)))); WriteRegister(SLEEP_CFR, 1); msb = lsb = 0; @@ -180,11 +180,11 @@ void Equalizer::UpdateHannCoeff(uint16_t Filt_N) msb = lsb = 0; i = j = 0; offset = 0; - while (i <= (uint16_t)((Filt_N / 2) - 1)) + while (i <= static_cast((Filt_N / 2) - 1)) { addr = (2 << 15) + (maddressf1 << 6) + (msb << 4) + lsb; if (j >= offset) - data = w[(uint16_t)((Filt_N + 1) / 2 + i)]; + data = w[static_cast((Filt_N + 1) / 2 + i)]; else data = 0; mosi.push_back((1 << 31) | addr << 16 | data); @@ -205,7 +205,7 @@ void Equalizer::UpdateHannCoeff(uint16_t Filt_N) msb = lsb = 0; i = j = 0; - offset = (MaxFilt_N / 2) - ((uint16_t)((Filt_N + 1) / 2)); + offset = (MaxFilt_N / 2) - (static_cast((Filt_N + 1) / 2)); while (i < Filt_N) { addr = (2 << 15) + (maddressf0 << 6) + (msb << 4) + lsb; @@ -297,14 +297,14 @@ void Equalizer::SetFIRCoefficients(const int16_t* coefficients, uint16_t count) mosi.clear(); msb = lsb = i = 0; - while (i <= (uint16_t)((Filt_N)-1)) + while (i <= static_cast((Filt_N)-1)) { addr = (maddressf0 << 6) + (msb << 4) + lsb; - data = (uint16_t)coefficients[i]; + data = static_cast(coefficients[i]); mosi.push_back((1 << 31) | addr << 16 | data); addr = (maddressf1 << 6) + (msb << 4) + lsb; - data = (uint16_t)coefficients[i]; + data = static_cast(coefficients[i]); mosi.push_back((1 << 31) | addr << 16 | data); if (lsb >= NN) // 15 { diff --git a/src/FPGA_common/FPGA_common.cpp b/src/FPGA_common/FPGA_common.cpp index f9abae5ed..ce5813d9c 100644 --- a/src/FPGA_common/FPGA_common.cpp +++ b/src/FPGA_common/FPGA_common.cpp @@ -671,7 +671,7 @@ int FPGA::FPGAPacketPayload2Samples(const uint8_t* buffer, int bufLen, bool mimo if (mimo) //uncompressed samples { - complex16_t* ptr = (complex16_t*)buffer; + const complex16_t* ptr = reinterpret_cast(buffer); const int collected = bufLen / sizeof(complex16_t) / 2; for (int i = 0; i < collected; i++) { @@ -721,7 +721,7 @@ int FPGA::FPGAPacketPayload2SamplesFloat(const uint8_t* buffer, int bufLen, bool return collected; } - complex16_t* src = (complex16_t*)buffer; + const complex16_t* src = reinterpret_cast(buffer); if (mimo) //uncompressed samples { const int collected = bufLen / sizeof(complex16_t) / 2; @@ -775,7 +775,7 @@ int FPGA::Samples2FPGAPacketPayloadFloat( return b; } - complex16_t* dest = (complex16_t*)buffer; + complex16_t* dest = reinterpret_cast(buffer); if (mimo) { for (int src = 0; src < samplesCount; ++src) @@ -824,7 +824,7 @@ int FPGA::Samples2FPGAPacketPayload( if (mimo) { - complex16_t* ptr = (complex16_t*)buffer; + complex16_t* ptr = reinterpret_cast(buffer); for (int src = 0; src < samplesCount; ++src) { *ptr++ = samples[0][src]; @@ -942,7 +942,7 @@ OpStatus FPGA::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, double txPha const uint32_t addr = 0x002A; uint32_t val; - val = (1 << 31) | (uint32_t(0x0020) << 16) | 0xFFFD; //msbit 1=SPI write + val = (1 << 31) | (0x0020u << 16) | 0xFFFD; //msbit 1=SPI write WriteLMS7002MSPI(&val, 1); ReadLMS7002MSPI(&addr, &val, 1); bool bypassTx = (val & 0xF0) == 0x00; @@ -1023,7 +1023,7 @@ OpStatus FPGA::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int chipInde dataWr[0] = 0x0020; ReadLMS7002MSPI(dataWr.data(), ®20, 1); - dataWr[0] = (1 << 31) | (uint32_t(0x0020) << 16) | 0xFFFD; //msbit 1=SPI write + dataWr[0] = (1 << 31) | (0x0020u << 16) | 0xFFFD; //msbit 1=SPI write WriteLMS7002MSPI(dataWr.data(), 1); ReadLMS7002MSPI(spiAddr.data(), dataRdA.data(), bakRegCnt); @@ -1036,7 +1036,7 @@ OpStatus FPGA::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int chipInde bypassRx = (val & 0x0F) == 0x0D; } - dataWr[0] = (1 << 31) | (uint32_t(0x0020) << 16) | 0xFFFE; //msbit 1=SPI write + dataWr[0] = (1 << 31) | (0x0020u << 16) | 0xFFFE; //msbit 1=SPI write WriteLMS7002MSPI(dataWr.data(), 1); for (int i = 0; i < bakRegCnt; ++i) @@ -1044,7 +1044,7 @@ OpStatus FPGA::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int chipInde dataRdB.push_back(spiAddr[i]); ReadLMS7002MSPI(dataRdB.data(), dataRdB.data(), dataRdB.size()); - dataWr[0] = (1 << 31) | (uint32_t(0x0020) << 16) | 0xFFFF; //msbit 1=SPI write + dataWr[0] = (1 << 31) | (0x0020u << 16) | 0xFFFF; //msbit 1=SPI write WriteLMS7002MSPI(dataWr.data(), 1); { @@ -1056,7 +1056,7 @@ OpStatus FPGA::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int chipInde //Load test config const int setRegCnt = spiData.size(); for (int i = 0; i < setRegCnt; ++i) - dataWr[i] = (1 << 31) | (uint32_t(spiAddr[i]) << 16) | spiData[i]; //msbit 1=SPI write + dataWr[i] = (1 << 31) | (spiAddr[i] << 16) | spiData[i]; //msbit 1=SPI write WriteLMS7002MSPI(dataWr.data(), setRegCnt); } @@ -1107,7 +1107,7 @@ OpStatus FPGA::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int chipInde //Load test config const int setRegCnt = spiData.size(); for (int i = 0; i < setRegCnt; ++i) - dataWr[i] = (1 << 31) | (uint32_t(spiAddr[i]) << 16) | spiData[i]; //msbit 1=SPI write + dataWr[i] = (1 << 31) | (spiAddr[i] << 16) | spiData[i]; //msbit 1=SPI write WriteLMS7002MSPI(dataWr.data(), setRegCnt); } @@ -1146,23 +1146,23 @@ OpStatus FPGA::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int chipInde } //Restore registers - dataWr[0] = (1 << 31) | (uint32_t(0x0020) << 16) | 0xFFFD; //msbit 1=SPI write + dataWr[0] = (1 << 31) | (0x0020u << 16) | 0xFFFD; //msbit 1=SPI write WriteLMS7002MSPI(dataWr.data(), 1); for (int i = 0; i < bakRegCnt; ++i) - dataWr[i] = (1 << 31) | (uint32_t(spiAddr[i]) << 16) | dataRdA[i]; //msbit 1=SPI write + dataWr[i] = (1 << 31) | (spiAddr[i] << 16) | dataRdA[i]; //msbit 1=SPI write WriteLMS7002MSPI(dataWr.data(), bakRegCnt); - dataWr[0] = (1 << 31) | (uint32_t(0x0020) << 16) | 0xFFFE; //msbit 1=SPI write + dataWr[0] = (1 << 31) | (0x0020u << 16) | 0xFFFE; //msbit 1=SPI write WriteLMS7002MSPI(dataWr.data(), 1); int k = 0; for (int i = 0; i < bakRegCnt; ++i) if (spiAddr[i] >= 0x100) { - dataWr[k] = (1 << 31) | (uint32_t(spiAddr[i]) << 16) | dataRdB[k]; //msbit 1=SPI write + dataWr[k] = (1 << 31) | (spiAddr[i] << 16) | dataRdB[k]; //msbit 1=SPI write k++; } WriteLMS7002MSPI(dataWr.data(), k); - dataWr[0] = (1 << 31) | (uint32_t(0x0020) << 16) | reg20; //msbit 1=SPI write + dataWr[0] = (1 << 31) | (0x0020u << 16) | reg20; //msbit 1=SPI write WriteLMS7002MSPI(dataWr.data(), 1); WriteRegister(0x000A, reg_000A); return status; @@ -1246,7 +1246,7 @@ FPGA::GatewareInfo FPGA::GetGatewareInfo() return info; info.boardID = data[0]; - info.version = (int16_t)data[1]; + info.version = static_cast(data[1]); info.revision = data[2]; info.hardwareVersion = data[3] & 0x7F; return info; @@ -1255,9 +1255,9 @@ FPGA::GatewareInfo FPGA::GetGatewareInfo() void FPGA::GatewareToDescriptor(const FPGA::GatewareInfo& gw, SDRDevice::Descriptor& desc) { desc.gatewareTargetBoard = GetDeviceName(eLMS_DEV(gw.boardID)); - desc.gatewareVersion = std::to_string(int(gw.version)); - desc.gatewareRevision = std::to_string(int(gw.revision)); - desc.hardwareVersion = std::to_string(int(gw.hardwareVersion)); + desc.gatewareVersion = std::to_string(gw.version); + desc.gatewareRevision = std::to_string(gw.revision); + desc.hardwareVersion = std::to_string(gw.hardwareVersion); } } //namespace lime diff --git a/src/FPGAcontrols_wxgui/FPGAcontrols_wxgui.cpp b/src/FPGAcontrols_wxgui/FPGAcontrols_wxgui.cpp index 1ea439172..ef3993eaa 100644 --- a/src/FPGAcontrols_wxgui/FPGAcontrols_wxgui.cpp +++ b/src/FPGAcontrols_wxgui/FPGAcontrols_wxgui.cpp @@ -320,7 +320,9 @@ int FPGAcontrols_wxgui::UploadFile(std::vector isamples, std::vector fifoSize / 2 ? fifoSize / 2 : buffer.size(); - lms_stream_t tx_stream = { 0, true, uint32_t(cmbDevice->GetSelection() * 2), fifoSize, 0.5, lms_stream_t::LMS_FMT_I16 }; + lms_stream_t tx_stream = { + 0, true, static_cast(cmbDevice->GetSelection() * 2), fifoSize, 0.5, lms_stream_t::LMS_FMT_I16 + }; if (LMS_SetupStream(lmsControl, &tx_stream) != 0) { evt = new wxCommandEvent(UPDATE_STATUS); diff --git a/src/LMS_Programing/LMS_Programing_wxgui.cpp b/src/LMS_Programing/LMS_Programing_wxgui.cpp index 14b671590..c5b14131c 100644 --- a/src/LMS_Programing/LMS_Programing_wxgui.cpp +++ b/src/LMS_Programing/LMS_Programing_wxgui.cpp @@ -82,14 +82,20 @@ LMS_Programing_wxgui::LMS_Programing_wxgui( FlexGridSizer1->Fit(this); FlexGridSizer1->SetSizeHints(this); - Connect(ID_BUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&LMS_Programing_wxgui::OnbtnOpenClick); + Connect( + ID_BUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, reinterpret_cast(&LMS_Programing_wxgui::OnbtnOpenClick)); Connect(btnStartStop->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, - (wxObjectEventFunction)&LMS_Programing_wxgui::OnbtnStartProgrammingClick); - Connect(ID_CHOICE2, wxEVT_COMMAND_CHOICE_SELECTED, (wxObjectEventFunction)&LMS_Programing_wxgui::OncmbDeviceSelect); - Connect(ID_PROGRAMING_FINISHED_EVENT, wxEVT_COMMAND_THREAD, (wxObjectEventFunction)&LMS_Programing_wxgui::OnProgramingFinished); - Connect( - ID_PROGRAMING_STATUS_EVENT, wxEVT_COMMAND_THREAD, (wxObjectEventFunction)&LMS_Programing_wxgui::OnProgramingStatusUpdate); + reinterpret_cast(&LMS_Programing_wxgui::OnbtnStartProgrammingClick)); + Connect(ID_CHOICE2, + wxEVT_COMMAND_CHOICE_SELECTED, + reinterpret_cast(&LMS_Programing_wxgui::OncmbDeviceSelect)); + Connect(ID_PROGRAMING_FINISHED_EVENT, + wxEVT_COMMAND_THREAD, + reinterpret_cast(&LMS_Programing_wxgui::OnProgramingFinished)); + Connect(ID_PROGRAMING_STATUS_EVENT, + wxEVT_COMMAND_THREAD, + reinterpret_cast(&LMS_Programing_wxgui::OnProgramingStatusUpdate)); } LMS_Programing_wxgui::~LMS_Programing_wxgui() @@ -211,14 +217,16 @@ void LMS_Programing_wxgui::OnbtnStartProgrammingClick(wxCommandEvent& event) Disconnect(btnStartStop->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, - (wxObjectEventFunction)&LMS_Programing_wxgui::OnbtnStartProgrammingClick); + reinterpret_cast(&LMS_Programing_wxgui::OnbtnStartProgrammingClick)); btnOpen->Disable(); btnStartStop->SetLabel(_("Abort")); mAbortProgramming.store(false); //run programming in separate thread, to prevent GUI freeze mWorkerThread = std::thread(&LMS_Programing_wxgui::DoProgramming, this); - Connect(btnStartStop->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&LMS_Programing_wxgui::OnAbortProgramming); + Connect(btnStartStop->GetId(), + wxEVT_COMMAND_BUTTON_CLICKED, + reinterpret_cast(&LMS_Programing_wxgui::OnAbortProgramming)); } /** @brief Change programming modes according to selected device @@ -240,11 +248,12 @@ void LMS_Programing_wxgui::OnProgramingFinished(wxCommandEvent& event) mWorkerThread.join(); wxMessageBox(event.GetString(), _("INFO"), wxICON_INFORMATION | wxOK); btnOpen->Enable(btnOpenEnb); - Disconnect( - btnStartStop->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&LMS_Programing_wxgui::OnAbortProgramming); + Disconnect(btnStartStop->GetId(), + wxEVT_COMMAND_BUTTON_CLICKED, + reinterpret_cast(&LMS_Programing_wxgui::OnAbortProgramming)); Connect(btnStartStop->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, - (wxObjectEventFunction)&LMS_Programing_wxgui::OnbtnStartProgrammingClick); + reinterpret_cast(&LMS_Programing_wxgui::OnbtnStartProgrammingClick)); btnStartStop->SetLabel(_("Program")); } diff --git a/src/Si5351C/Si5351C.cpp b/src/Si5351C/Si5351C.cpp index b2397707e..7fa913d77 100644 --- a/src/Si5351C/Si5351C.cpp +++ b/src/Si5351C/Si5351C.cpp @@ -26,8 +26,8 @@ using namespace lime; /// Splits float into fraction integers A + B/C void realToFrac(const float real, int& A, int& B, int& C) { - A = (int)real; - B = (int)((real - A) * 1048576 + 0.5); + A = static_cast(real); + B = std::round((real - A) * 1048576); C = 1048576; int a = B; @@ -534,12 +534,12 @@ Si5351C::Status Si5351C::UploadConfiguration() std::vector outBuffer; //Disable outputs outBuffer.push_back(3); - outBuffer.push_back(uint8_t(0xFF)); + outBuffer.push_back(0xFF); //Power down all output drivers for (int i = 0; i < 8; ++i) { outBuffer.push_back(16 + i); - outBuffer.push_back(uint8_t(0x84)); + outBuffer.push_back(0x84); } //write new configuration for (int i = 15; i <= 92; ++i) @@ -553,8 +553,8 @@ Si5351C::Status Si5351C::UploadConfiguration() outBuffer.push_back(m_newConfiguration[i]); } //apply soft reset - outBuffer.push_back(uint8_t(177)); - outBuffer.push_back(uint8_t(0xAC)); + outBuffer.push_back(0XB1); + outBuffer.push_back(0xAC); //Enabe desired outputs outBuffer.push_back(3); outBuffer.push_back(m_newConfiguration[3]); @@ -748,7 +748,7 @@ void Si5351C::FindVCO(Si5351_Channel* clocks, Si5351_PLL* plls, const unsigned l } plls[0].VCO_Hz = bestVCOA; - plls[0].feedbackDivider = (double)bestVCOA / plls[0].inputFreqHz; + plls[0].feedbackDivider = static_cast(bestVCOA) / plls[0].inputFreqHz; for (int i = 0; i < clockCount; ++i) { @@ -764,7 +764,7 @@ void Si5351C::FindVCO(Si5351_Channel* clocks, Si5351_PLL* plls, const unsigned l else { clocks[i].int_mode = false; - clocks[i].multisynthDivider = (double)bestVCOA / clocks[i].outputFreqHz; + clocks[i].multisynthDivider = static_cast(bestVCOA) / clocks[i].outputFreqHz; } clocks[i].pllSource = 0; } @@ -817,7 +817,7 @@ void Si5351C::FindVCO(Si5351_Channel* clocks, Si5351_PLL* plls, const unsigned l 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; - plls[1].feedbackDivider = (double)bestVCOB / plls[0].inputFreqHz; + plls[1].feedbackDivider = static_cast(bestVCOB) / plls[0].inputFreqHz; for (int i = 0; i < clockCount; ++i) { if (clocks[i].outputFreqHz == 0 || !clocks[i].powered) @@ -834,7 +834,7 @@ void Si5351C::FindVCO(Si5351_Channel* clocks, Si5351_PLL* plls, const unsigned l else { clocks[i].int_mode = false; - clocks[i].multisynthDivider = (double)bestVCOB / clocks[i].outputFreqHz; + clocks[i].multisynthDivider = static_cast(bestVCOB) / clocks[i].outputFreqHz; } clocks[i].pllSource = 1; } @@ -889,8 +889,8 @@ Si5351C::Status Si5351C::ConfigureClocks() { if (CLK[i].outputFreqHz <= 150000000) { - unsigned MSX_P1 = 128 * DivA + floor(128 * ((float)DivB / DivC)) - 512; - unsigned MSX_P2 = 128 * DivB - DivC * floor(128 * DivB / DivC); + unsigned MSX_P1 = 128 * DivA + std::floor(128 * (static_cast(DivB) / DivC)) - 512; + unsigned MSX_P2 = 128 * DivB - DivC * std::floor(128 * DivB / DivC); unsigned MSX_P3 = DivC; m_newConfiguration[addr] = MSX_P3 >> 8; @@ -980,8 +980,8 @@ Si5351C::Status Si5351C::ConfigureClocks() DivB, DivC); - MSNx_P1 = 128 * DivA + floor(128 * ((float)DivB / DivC)) - 512; - MSNx_P2 = 128 * DivB - DivC * floor(128 * DivB / DivC); + MSNx_P1 = 128 * DivA + std::floor(128 * (static_cast(DivB) / DivC)) - 512; + MSNx_P2 = 128 * DivB - DivC * std::floor(128 * DivB / DivC); MSNx_P3 = DivC; m_newConfiguration[addr + 4] = MSNx_P1; @@ -1012,8 +1012,7 @@ void Si5351C::SetClock(unsigned char id, unsigned long fOut_Hz, bool enabled, bo { if (fOut_Hz < 8000 || fOut_Hz > 160000000) { - lime::error( - "Si5351C - CLK%d output frequency must be between 8kHz and 160MHz. fOut_MHz = %g", (int)id, fOut_Hz / 1000000.0); + lime::error("Si5351C - CLK%d output frequency must be between 8kHz and 160MHz. fOut_MHz = %g", id, fOut_Hz / 1000000.0); return; } CLK[id].powered = enabled; diff --git a/src/Si5351C/Si5351C_wxgui.cpp b/src/Si5351C/Si5351C_wxgui.cpp index fc05e4a18..ce242dfc5 100644 --- a/src/Si5351C/Si5351C_wxgui.cpp +++ b/src/Si5351C/Si5351C_wxgui.cpp @@ -293,11 +293,17 @@ Si5351C_wxgui::Si5351C_wxgui( FlexGridSizer1->Fit(this); FlexGridSizer1->SetSizeHints(this); - Connect(ID_BUTTON2, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&Si5351C_wxgui::OnbtnLoadFileClick); - Connect(ID_BUTTON4, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&Si5351C_wxgui::OnbtnResetToDefaultsClick); - Connect(ID_BUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&Si5351C_wxgui::OnbtnReadStatusClick); - Connect(ID_BUTTON5, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&Si5351C_wxgui::OnbtnClearStatusClick); - Connect(ID_BUTTON3, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&Si5351C_wxgui::OnbtnConfigureClockClick); + Connect(ID_BUTTON2, wxEVT_COMMAND_BUTTON_CLICKED, reinterpret_cast(&Si5351C_wxgui::OnbtnLoadFileClick)); + Connect(ID_BUTTON4, + wxEVT_COMMAND_BUTTON_CLICKED, + reinterpret_cast(&Si5351C_wxgui::OnbtnResetToDefaultsClick)); + Connect( + ID_BUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, reinterpret_cast(&Si5351C_wxgui::OnbtnReadStatusClick)); + Connect( + ID_BUTTON5, wxEVT_COMMAND_BUTTON_CLICKED, reinterpret_cast(&Si5351C_wxgui::OnbtnClearStatusClick)); + Connect(ID_BUTTON3, + wxEVT_COMMAND_BUTTON_CLICKED, + reinterpret_cast(&Si5351C_wxgui::OnbtnConfigureClockClick)); } void Si5351C_wxgui::Initialize(SDRDevice* pModule) diff --git a/src/boards/LimeSDR/LimeSDR.cpp b/src/boards/LimeSDR/LimeSDR.cpp index 8affef4e6..768c71a82 100644 --- a/src/boards/LimeSDR/LimeSDR.cpp +++ b/src/boards/LimeSDR/LimeSDR.cpp @@ -393,9 +393,9 @@ SDRDevice::Descriptor LimeSDR::GetDeviceInfo(void) deviceDescriptor.name = GetDeviceName(static_cast(info.deviceId)); deviceDescriptor.expansionName = GetExpansionBoardName(static_cast(info.expansionBoardId)); - deviceDescriptor.firmwareVersion = std::to_string(int(info.firmware)); - deviceDescriptor.hardwareVersion = std::to_string(int(info.hardware)); - deviceDescriptor.protocolVersion = std::to_string(int(info.protocol)); + deviceDescriptor.firmwareVersion = std::to_string(info.firmware); + deviceDescriptor.hardwareVersion = std::to_string(info.hardware); + deviceDescriptor.protocolVersion = std::to_string(info.protocol); deviceDescriptor.serialNumber = info.boardSerialNumber; const uint32_t addrs[] = { 0x0000, 0x0001, 0x0002, 0x0003 }; @@ -407,9 +407,9 @@ SDRDevice::Descriptor LimeSDR::GetDeviceInfo(void) auto hwVersion = data[3] & 0x7F; //pkt.inBuffer[15]&0x7F; deviceDescriptor.gatewareTargetBoard = GetDeviceName(boardID); - deviceDescriptor.gatewareVersion = std::to_string(int(gatewareVersion)); - deviceDescriptor.gatewareRevision = std::to_string(int(gatewareRevision)); - deviceDescriptor.hardwareVersion = std::to_string(int(hwVersion)); + deviceDescriptor.gatewareVersion = std::to_string(gatewareVersion); + deviceDescriptor.gatewareRevision = std::to_string(gatewareRevision); + deviceDescriptor.hardwareVersion = std::to_string(hwVersion); return deviceDescriptor; } diff --git a/src/boards/LimeSDR_Mini/FPGA_Mini.cpp b/src/boards/LimeSDR_Mini/FPGA_Mini.cpp index 1b13be3cb..0bbd54dcd 100644 --- a/src/boards/LimeSDR_Mini/FPGA_Mini.cpp +++ b/src/boards/LimeSDR_Mini/FPGA_Mini.cpp @@ -90,7 +90,7 @@ OpStatus FPGA_Mini::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int cha //backup registers dataWr[0] = 0x0020; lms7002mPort->SPI(dataWr.data(), ®20, 1); - dataWr[0] = (1 << 31) | (uint32_t(0x0020) << 16) | 0xFFFD; //msbit 1=SPI write + dataWr[0] = (1 << 31) | (0x0020u << 16) | 0xFFFD; //msbit 1=SPI write lms7002mPort->SPI(dataWr.data(), nullptr, 1); lms7002mPort->SPI(spiAddr.data(), dataRd.data(), bakRegCnt); @@ -102,7 +102,7 @@ OpStatus FPGA_Mini::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int cha for (int i = 0; i < setRegCnt; ++i) { - dataWr[i] = (1 << 31) | (uint32_t(spiAddr[i]) << 16) | spiData[i]; //msbit 1=SPI write + dataWr[i] = (1 << 31) | (spiAddr[i] << 16) | spiData[i]; //msbit 1=SPI write } lms7002mPort->SPI(dataWr.data(), nullptr, setRegCnt); @@ -137,7 +137,7 @@ OpStatus FPGA_Mini::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int cha for (int i = 0; i < setRegCnt; ++i) { - dataWr[i] = (1 << 31) | (uint32_t(spiAddr[i]) << 16) | spiData[i]; //msbit 1=SPI write + dataWr[i] = (1 << 31) | (spiAddr[i] << 16) | spiData[i]; //msbit 1=SPI write } lms7002mPort->SPI(dataWr.data(), nullptr, setRegCnt); @@ -172,12 +172,12 @@ OpStatus FPGA_Mini::SetInterfaceFreq(double txRate_Hz, double rxRate_Hz, int cha //Restore registers for (int i = 0; i < bakRegCnt; ++i) { - dataWr[i] = (1 << 31) | (uint32_t(spiAddr[i]) << 16) | dataRd[i]; //msbit 1=SPI write + dataWr[i] = (1 << 31) | (spiAddr[i] << 16) | dataRd[i]; //msbit 1=SPI write } lms7002mPort->SPI(dataWr.data(), nullptr, bakRegCnt); - dataWr[0] = (1 << 31) | (uint32_t(0x0020) << 16) | reg20; //msbit 1=SPI write + dataWr[0] = (1 << 31) | (0x0020u << 16) | reg20; //msbit 1=SPI write lms7002mPort->SPI(dataWr.data(), nullptr, 1); WriteRegister(0x000A, 0); diff --git a/src/boards/LimeSDR_X3/LimeSDR_X3.cpp b/src/boards/LimeSDR_X3/LimeSDR_X3.cpp index 26f6f2b16..3963c910e 100644 --- a/src/boards/LimeSDR_X3/LimeSDR_X3.cpp +++ b/src/boards/LimeSDR_X3/LimeSDR_X3.cpp @@ -741,7 +741,7 @@ void LimeSDR_X3::SetLMSPath(const TRXDir dir, const SDRDevice::ChannelConfig::Di } else { - path = (dir == TRXDir::Rx) ? uint8_t(ePathLMS2_Rx::NONE) : uint8_t(ePathLMS2_Tx::NONE); + path = (dir == TRXDir::Rx) ? static_cast(ePathLMS2_Rx::NONE) : static_cast(ePathLMS2_Tx::NONE); } LMS2SetPath(dir, ch, path); @@ -1211,7 +1211,7 @@ void LimeSDR_X3::LMS2_SetSampleRate(double f_Hz, uint8_t oversample) double txClock = f_Hz; // Oversample is available only to Tx for LMS#2 - oversample = std::min(oversample, uint8_t(2)); + oversample = std::min(oversample, 2); if (oversample == 2 || oversample == 0) // 0 is "auto", use max oversample txClock *= 2; diff --git a/src/boards/MMX8/MM_X8Entry.cpp b/src/boards/MMX8/MM_X8Entry.cpp index 60e844686..6f4d514a4 100644 --- a/src/boards/MMX8/MM_X8Entry.cpp +++ b/src/boards/MMX8/MM_X8Entry.cpp @@ -135,7 +135,7 @@ class LMS64C_FPGA_Over_PCIe_MMX8 : public lime::IComms const char* data, size_t length, int prog_mode, int target, ProgressCallback callback = nullptr) override { return LMS64CProtocol::ProgramWrite( - pipe, data, length, prog_mode, (LMS64CProtocol::ProgramWriteTarget)target, callback, subdeviceIndex); + pipe, data, length, prog_mode, static_cast(target), callback, subdeviceIndex); } OpStatus MemoryWrite(uint32_t address, const void* data, uint32_t dataLength) diff --git a/src/boards_wxgui/pnlX3.cpp b/src/boards_wxgui/pnlX3.cpp index e696e819a..aa681b97e 100644 --- a/src/boards_wxgui/pnlX3.cpp +++ b/src/boards_wxgui/pnlX3.cpp @@ -193,7 +193,8 @@ pnlX3::pnlX3(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& btnLMS1Settings = new wxButton(this, wxNewId(), _T("Configure")); mainSizer->Add(btnLMS1Settings, 1, wxALIGN_LEFT | wxEXPAND, 5); - Connect(btnLMS1Settings->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&pnlX3::OnLMS1Configure); + Connect( + btnLMS1Settings->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, reinterpret_cast(&pnlX3::OnLMS1Configure)); // end B.J. auto lms1Sizer = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, wxT("LMS1")), wxVERTICAL); @@ -313,7 +314,8 @@ pnlX3::pnlX3(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& btnLMS2Settings = new wxButton(this, wxNewId(), _T("Configure")); mainSizer2->Add(btnLMS2Settings, 1, wxALIGN_LEFT | wxEXPAND, 5); - Connect(btnLMS2Settings->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&pnlX3::OnLMS2Configure); + Connect( + btnLMS2Settings->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, reinterpret_cast(&pnlX3::OnLMS2Configure)); // end B.J. auto lms2Sizer = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, wxT("LMS2")), wxVERTICAL); @@ -573,8 +575,8 @@ void pnlX3::OnLMS1Configure(wxCommandEvent& event) int m_bLMS1ChA, m_bLMS1ChB = 0; Register chkLms1Tx1, cmbLms1Tx1Path, cmbLms1Rx1Path, chkLms1Tx2, cmbLms1Tx2Path, cmbLms1Rx2Path; - m_bLMS1ChA = (int)cbLMS1ChA->GetValue(); - m_bLMS1ChB = (int)cbLMS1ChB->GetValue(); + m_bLMS1ChA = static_cast(cbLMS1ChA->GetValue()); + m_bLMS1ChB = static_cast(cbLMS1ChB->GetValue()); // LMS#1 channel A chkLms1Tx1 = Register(0x00D2, 5, 5, 0); // positive logic @@ -682,8 +684,8 @@ void pnlX3::OnLMS2Configure(wxCommandEvent& event) Register cmbLms2Trx1T, cmbLms2Trx1, cmbLms2Rx1In, cmbLms2Rx1C, cmbLms3Rx1, chkLms2Tx1, chkLms2Lna1; Register cmbLms2Trx2T, cmbLms2Trx2, cmbLms2Rx2In, cmbLms2Rx2C, chkLms2Tx2, chkLms2Lna2; - m_bLMS2ChA = (int)cbLMS2ChA->GetValue(); - m_bLMS2ChB = (int)cbLMS2ChB->GetValue(); + m_bLMS2ChA = static_cast(cbLMS2ChA->GetValue()); + m_bLMS2ChB = static_cast(cbLMS2ChB->GetValue()); // RF2 (log. 0), RF1 (log. 1) // LMS#2 channel A diff --git a/src/cli/limeTRX.cpp b/src/cli/limeTRX.cpp index a9fe0c135..19c7c6379 100644 --- a/src/cli/limeTRX.cpp +++ b/src/cli/limeTRX.cpp @@ -563,7 +563,7 @@ int main(int argc, char** argv) inputFile.seekg(0, std::ios_base::beg); cerr << "File size : " << cnt << " bytes." << endl; txData.resize(cnt / sizeof(complex16_t)); - inputFile.read((char*)txData.data(), cnt); + inputFile.read(reinterpret_cast(txData.data()), cnt); inputFile.close(); } @@ -669,7 +669,7 @@ int main(int argc, char** argv) totalSamplesReceived += samplesRead; if (rxFilename) { - rxFile.write((char*)rxSamples[0], samplesRead * sizeof(lime::complex16_t)); + rxFile.write(reinterpret_cast(rxSamples[0]), samplesRead * sizeof(lime::complex16_t)); } t2 = std::chrono::high_resolution_clock::now(); @@ -686,7 +686,8 @@ int main(int argc, char** argv) m_fftCalcIn[i].r = rxSamples[0][i].i / 32768.0; m_fftCalcIn[i].i = rxSamples[0][i].q / 32768.0; } - kiss_fft(m_fftCalcPlan, (kiss_fft_cpx*)&m_fftCalcIn, (kiss_fft_cpx*)&m_fftCalcOut); + kiss_fft( + m_fftCalcPlan, reinterpret_cast(&m_fftCalcIn), reinterpret_cast(&m_fftCalcOut)); for (unsigned int i = 0; i < fftSize; ++i) { float amplitude = diff --git a/src/comms/PCIe/LitePCIe.cpp b/src/comms/PCIe/LitePCIe.cpp index 7d7d857ff..85c63f3d0 100644 --- a/src/comms/PCIe/LitePCIe.cpp +++ b/src/comms/PCIe/LitePCIe.cpp @@ -79,8 +79,12 @@ int LitePCIe::Open(const std::string& deviceFilename, uint32_t flags) const std::string msg = mFilePath + ": DMA writer request denied"; throw std::runtime_error(msg); } - uint8_t* buf = (uint8_t*)mmap( - NULL, info.dma_rx_buf_size * info.dma_rx_buf_count, PROT_READ, MAP_SHARED, mFileDescriptor, info.dma_rx_buf_offset); + uint8_t* buf = static_cast(mmap(NULL, + info.dma_rx_buf_size * info.dma_rx_buf_count, + PROT_READ, + MAP_SHARED, + mFileDescriptor, + info.dma_rx_buf_offset)); if (buf == MAP_FAILED || buf == nullptr) { const std::string msg = mFilePath + ": failed to MMAP Rx DMA buffer"; @@ -99,12 +103,12 @@ int LitePCIe::Open(const std::string& deviceFilename, uint32_t flags) const std::string msg = mFilePath + ": DMA reader request denied"; throw std::runtime_error(msg); } - uint8_t* buf = (uint8_t*)mmap(NULL, + uint8_t* buf = static_cast(mmap(NULL, info.dma_tx_buf_size * info.dma_tx_buf_count, PROT_WRITE, MAP_SHARED, mFileDescriptor, - info.dma_tx_buf_offset); + info.dma_tx_buf_offset)); if (buf == MAP_FAILED || buf == nullptr) { const std::string msg = mFilePath + ": failed to MMAP Tx DMA buffer"; diff --git a/src/comms/PCIe/PCIeCommon.cpp b/src/comms/PCIe/PCIeCommon.cpp index 666e4a8d8..1a9d67d2c 100644 --- a/src/comms/PCIe/PCIeCommon.cpp +++ b/src/comms/PCIe/PCIeCommon.cpp @@ -58,7 +58,8 @@ OpStatus LMS64C_FPGA_Over_PCIe::CustomParameterRead(std::vector(target), callback); } OpStatus LMS64C_FPGA_Over_PCIe::MemoryWrite(uint32_t address, const void* data, uint32_t dataLength) diff --git a/src/comms/PCIe/TRXLooper_PCIE.cpp b/src/comms/PCIe/TRXLooper_PCIE.cpp index 7b214b20a..db9dfad4a 100644 --- a/src/comms/PCIe/TRXLooper_PCIE.cpp +++ b/src/comms/PCIe/TRXLooper_PCIE.cpp @@ -52,8 +52,8 @@ class AvgRmsCounter { if (counter == 0) return; - avg = avgAccumulator / (double)counter; - rms = sqrt(rmsAccumulator / (double)counter); + avg = avgAccumulator / static_cast(counter); + rms = sqrt(rmsAccumulator / static_cast(counter)); avgAccumulator = 0; rmsAccumulator = 0; counter = 0; @@ -82,16 +82,10 @@ class AvgRmsCounter static inline int64_t ts_to_us(int64_t fs, int64_t ts) { - int n, r; + int64_t n, r; n = (ts / fs); r = (ts % fs); - return (int64_t)n * 1000000 + (((int64_t)r * 1000000) / fs); -} - -template inline static T clamp(T value, T low, T high) -{ - assert(low <= high); - return value < low ? low : (value > high ? high : value); + return n * 1000000 + (r * 1000000 / fs); } TRXLooper_PCIE::TRXLooper_PCIE( @@ -198,7 +192,7 @@ int TRXLooper_PCIE::TxSetup() mTx.packetsToBatch = mConfig.extraConfig.txMaxPacketsInBatch; } - mTx.packetsToBatch = clamp((int)mTx.packetsToBatch, 1, (int)(dma.bufferSize / packetSize)); + mTx.packetsToBatch = std::clamp(mTx.packetsToBatch, 1, dma.bufferSize / packetSize); std::vector dmaBuffers(dma.bufferCount); for (uint32_t i = 0; i < dmaBuffers.size(); ++i) @@ -210,7 +204,7 @@ int TRXLooper_PCIE::TxSetup() mTxArgs.packetsToBatch = mTx.packetsToBatch; mTxArgs.samplesInPacket = samplesInPkt; - float bufferTimeDuration = float(samplesInPkt * mTx.packetsToBatch) / mConfig.hintSampleRate; + float bufferTimeDuration = samplesInPkt * mTx.packetsToBatch / mConfig.hintSampleRate; if (mCallback_logMessage) { char msg[256]; @@ -269,7 +263,7 @@ template class TxBufferManager header = reinterpret_cast(mData); header->Clear(); payloadSize = 0; - payloadPtr = (uint8_t*)header + sizeof(StreamHeader); + payloadPtr = reinterpret_cast(header) + sizeof(StreamHeader); } inline bool hasSpace() const @@ -288,7 +282,7 @@ template class TxBufferManager { header = reinterpret_cast(mData + bytesUsed); header->Clear(); - payloadPtr = (uint8_t*)header + sizeof(StreamHeader); + payloadPtr = reinterpret_cast(header) + sizeof(StreamHeader); payloadSize = 0; } @@ -320,7 +314,7 @@ template class TxBufferManager if (bytesUsed >= mCapacity - sizeof(StreamHeader)) sendBuffer = true; // not enough space for more packets, need to flush - if ((uint64_t)payloadPtr & 0xF) + if (reinterpret_cast(payloadPtr) & 0xF) sendBuffer = true; // next packets payload memory is not suitably aligned for vectorized filling if (sendBuffer) @@ -375,8 +369,8 @@ void FPGATxState(FPGA* fpga) fpga->ReadRegisters(addrs, words, 4); pendingTxTS |= words[0]; pendingTxTS |= words[1] << 16; - pendingTxTS |= (uint64_t)words[2] << 32; - pendingTxTS |= (uint64_t)words[3] << 48; + pendingTxTS |= static_cast(words[2]) << 32; + pendingTxTS |= static_cast(words[3]) << 48; if (i < 4) lime::debug("Buf%i: %08lX", i, pendingTxTS); else @@ -709,7 +703,7 @@ int TRXLooper_PCIE::RxSetup() requestSamplesInPkt = mConfig.extraConfig.rxSamplesInPacket; } - int samplesInPkt = clamp(requestSamplesInPkt, 64, maxSamplesInPkt); + int samplesInPkt = std::clamp(requestSamplesInPkt, 64, maxSamplesInPkt); int payloadSize = requestSamplesInPkt * sampleSize * chCount; // iqSamplesCount must be N*16, or N*8 depending on device BUS width @@ -733,16 +727,16 @@ int TRXLooper_PCIE::RxSetup() mRx.packetsToBatch = mConfig.extraConfig.rxPacketsInBatch; } - mRx.packetsToBatch = clamp((int)mRx.packetsToBatch, 1, (int)(dma.bufferSize / packetSize)); + mRx.packetsToBatch = std::clamp(mRx.packetsToBatch, 1, dma.bufferSize / packetSize); int irqPeriod = 16; float bufferTimeDuration = 0; if (mConfig.hintSampleRate > 0) { - bufferTimeDuration = float(samplesInPkt * mRx.packetsToBatch) / mConfig.hintSampleRate; + bufferTimeDuration = samplesInPkt * mRx.packetsToBatch / mConfig.hintSampleRate; irqPeriod = 80e-6 / bufferTimeDuration; } - irqPeriod = clamp(irqPeriod, 1, 16); + irqPeriod = std::clamp(irqPeriod, 1, 16); irqPeriod = 4; if (mCallback_logMessage) @@ -841,7 +835,7 @@ void TRXLooper_PCIE::ReceivePacketsLoop() dma = mRxArgs.port->GetRxDMAState(); if (dma.hwIndex != lastHwIndex) { - const int bytesTransferred = uint16_t(dma.hwIndex - lastHwIndex) * readSize; + const int bytesTransferred = (dma.hwIndex - lastHwIndex) * readSize; Bps += bytesTransferred; stats.bytesTransferred += bytesTransferred; lastHwIndex = dma.hwIndex; diff --git a/src/comms/USB/LMS64C_FPGA_Over_USB.cpp b/src/comms/USB/LMS64C_FPGA_Over_USB.cpp index 52271812e..95c421a66 100644 --- a/src/comms/USB/LMS64C_FPGA_Over_USB.cpp +++ b/src/comms/USB/LMS64C_FPGA_Over_USB.cpp @@ -50,5 +50,6 @@ OpStatus LMS64C_FPGA_Over_USB::CustomParameterRead(std::vector(target), callback); } diff --git a/src/examples/basicRX.cpp b/src/examples/basicRX.cpp index 936171dc6..a09acda57 100644 --- a/src/examples/basicRX.cpp +++ b/src/examples/basicRX.cpp @@ -143,7 +143,7 @@ int main(int argc, char** argv) m_fftCalcIn[i].r = rxSamples[0][i].i; m_fftCalcIn[i].i = rxSamples[0][i].q; } - kiss_fft(m_fftCalcPlan, (kiss_fft_cpx*)&m_fftCalcIn, (kiss_fft_cpx*)&m_fftCalcOut); + kiss_fft(m_fftCalcPlan, reinterpret_cast(&m_fftCalcIn), reinterpret_cast(&m_fftCalcOut)); for (unsigned int i = 1; i < fftSize; ++i) { float output = diff --git a/src/fftviewer_wxgui/fftviewer_frFFTviewer.cpp b/src/fftviewer_wxgui/fftviewer_frFFTviewer.cpp index 3d0ca4ce6..bd90afb36 100644 --- a/src/fftviewer_wxgui/fftviewer_frFFTviewer.cpp +++ b/src/fftviewer_wxgui/fftviewer_frFFTviewer.cpp @@ -563,7 +563,7 @@ void fftviewer_frFFTviewer::StreamingLoop( { for (unsigned s = 0; s < fftSize; ++s) { - const float div = (float)fftCounter * fftSize * fftSize; + const float div = static_cast(fftCounter) * fftSize * fftSize; localDataResults.fftBins[ch][s] /= div; } } diff --git a/src/gnuPlotPipe.h b/src/gnuPlotPipe.h index 8a32fc5a4..4a417aeed 100644 --- a/src/gnuPlotPipe.h +++ b/src/gnuPlotPipe.h @@ -1,8 +1,8 @@ #ifndef GNUPLOT_PIPE_H #define GNUPLOT_PIPE_H -#include -#include +#include +#include /// @brief A class to pipe data into GNUPlot class GNUPlotPipe diff --git a/src/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp b/src/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp index 6af05b8ba..c8672674c 100644 --- a/src/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp +++ b/src/lms7002_wxgui/lms7002_pnlMCU_BD_view.cpp @@ -509,8 +509,9 @@ void lms7002_pnlMCU_BD_view::OnbtnStartProgrammingClick(wxCommandEvent& event) progressPooler->Start(200); Connect( ID_PROGRAMING_FINISH_EVENT, wxEVT_THREAD, wxThreadEventHandler(lms7002_pnlMCU_BD_view::OnProgrammingfinished), NULL, this); - Connect( - ID_PROGRAMING_STATUS_EVENT, wxEVT_COMMAND_THREAD, (wxObjectEventFunction)&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate); + Connect(ID_PROGRAMING_STATUS_EVENT, + wxEVT_COMMAND_THREAD, + reinterpret_cast(&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate)); obj_ptr = this; mThreadWorking = true; mWorkerThread = std::thread( @@ -655,7 +656,8 @@ void lms7002_pnlMCU_BD_view::OnbtnRunTestClick(wxCommandEvent& event) { if (TestResultArray_code[i] == m_iTestNo) { - retval = mcu->Three_byte_command(0x78, (unsigned char)(TestResultArray_address[i]), 0x00, &tempc1, &tempc2, &tempc3); + retval = mcu->Three_byte_command( + 0x78, static_cast(TestResultArray_address[i]), 0x00, &tempc1, &tempc2, &tempc3); if ((retval == -1) || (tempc3 != TestResultArray_value[i])) m_iError = 1; else @@ -764,8 +766,9 @@ void lms7002_pnlMCU_BD_view::OnViewSFRsClick(wxCommandEvent& event) progressBar->SetValue(0); progressPooler->Start(200); - Connect( - ID_PROGRAMING_STATUS_EVENT, wxEVT_COMMAND_THREAD, (wxObjectEventFunction)&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate); + Connect(ID_PROGRAMING_STATUS_EVENT, + wxEVT_COMMAND_THREAD, + reinterpret_cast(&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate)); Connect(ID_PROGRAMING_FINISH_EVENT, wxEVT_THREAD, wxThreadEventHandler(lms7002_pnlMCU_BD_view::OnReadSFRfinished), NULL, this); mThreadWorking = true; @@ -788,8 +791,9 @@ void lms7002_pnlMCU_BD_view::OnViewIRAMClick(wxCommandEvent& event) progressBar->SetValue(0); progressPooler->Start(200); Connect(ID_PROGRAMING_FINISH_EVENT, wxEVT_THREAD, wxThreadEventHandler(lms7002_pnlMCU_BD_view::OnReadIRAMfinished), NULL, this); - Connect( - ID_PROGRAMING_STATUS_EVENT, wxEVT_COMMAND_THREAD, (wxObjectEventFunction)&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate); + Connect(ID_PROGRAMING_STATUS_EVENT, + wxEVT_COMMAND_THREAD, + reinterpret_cast(&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate)); mThreadWorking = true; mWorkerThread = std::thread( @@ -810,8 +814,9 @@ void lms7002_pnlMCU_BD_view::OnEraseIRAMClick(wxCommandEvent& event) Disable(); progressBar->SetValue(0); progressPooler->Start(200); - Connect( - ID_PROGRAMING_STATUS_EVENT, wxEVT_COMMAND_THREAD, (wxObjectEventFunction)&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate); + Connect(ID_PROGRAMING_STATUS_EVENT, + wxEVT_COMMAND_THREAD, + reinterpret_cast(&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate)); Connect( ID_PROGRAMING_FINISH_EVENT, wxEVT_THREAD, wxThreadEventHandler(lms7002_pnlMCU_BD_view::OnEraseIRAMfinished), NULL, this); @@ -892,7 +897,9 @@ void lms7002_pnlMCU_BD_view::OnReadIRAMfinished(wxThreadEvent& event) mWorkerThread.join(); mThreadWorking = false; progressPooler->Stop(); - Disconnect(ID_PROGRAMING_STATUS_EVENT, wxEVT_THREAD, (wxObjectEventFunction)&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate); + Disconnect(ID_PROGRAMING_STATUS_EVENT, + wxEVT_THREAD, + reinterpret_cast(&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate)); Disconnect( ID_PROGRAMING_FINISH_EVENT, wxEVT_THREAD, wxThreadEventHandler(lms7002_pnlMCU_BD_view::OnReadIRAMfinished), NULL, this); progressBar->SetValue(100); @@ -913,7 +920,9 @@ void lms7002_pnlMCU_BD_view::OnEraseIRAMfinished(wxThreadEvent& event) mWorkerThread.join(); mThreadWorking = false; progressPooler->Stop(); - Disconnect(ID_PROGRAMING_STATUS_EVENT, wxEVT_THREAD, (wxObjectEventFunction)&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate); + Disconnect(ID_PROGRAMING_STATUS_EVENT, + wxEVT_THREAD, + reinterpret_cast(&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate)); Disconnect( ID_PROGRAMING_FINISH_EVENT, wxEVT_THREAD, wxThreadEventHandler(lms7002_pnlMCU_BD_view::OnEraseIRAMfinished), NULL, this); progressBar->SetValue(100); @@ -928,7 +937,9 @@ void lms7002_pnlMCU_BD_view::OnReadSFRfinished(wxThreadEvent& event) mWorkerThread.join(); mThreadWorking = false; progressPooler->Stop(); - Disconnect(ID_PROGRAMING_STATUS_EVENT, wxEVT_THREAD, (wxObjectEventFunction)&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate); + Disconnect(ID_PROGRAMING_STATUS_EVENT, + wxEVT_THREAD, + reinterpret_cast(&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate)); Disconnect( ID_PROGRAMING_FINISH_EVENT, wxEVT_THREAD, wxThreadEventHandler(lms7002_pnlMCU_BD_view::OnReadSFRfinished), NULL, this); progressBar->SetValue(100); @@ -949,7 +960,9 @@ void lms7002_pnlMCU_BD_view::OnProgrammingfinished(wxThreadEvent& event) mWorkerThread.join(); mThreadWorking = false; progressPooler->Stop(); - Disconnect(ID_PROGRAMING_STATUS_EVENT, wxEVT_THREAD, (wxObjectEventFunction)&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate); + Disconnect(ID_PROGRAMING_STATUS_EVENT, + wxEVT_THREAD, + reinterpret_cast(&lms7002_pnlMCU_BD_view::OnProgramingStatusUpdate)); Disconnect( ID_PROGRAMING_FINISH_EVENT, wxEVT_THREAD, wxThreadEventHandler(lms7002_pnlMCU_BD_view::OnProgrammingfinished), NULL, this); progressBar->SetValue(100); diff --git a/src/lms7002_wxgui/lms7002_pnlR3.cpp b/src/lms7002_wxgui/lms7002_pnlR3.cpp index bbb5d3ce9..1e5110227 100644 --- a/src/lms7002_wxgui/lms7002_pnlR3.cpp +++ b/src/lms7002_wxgui/lms7002_pnlR3.cpp @@ -529,11 +529,13 @@ void lms7002_pnlR3_view::MCU_RunProcedure(uint8_t id) const uint16_t x0002reg = temp & 0xFF; const uint16_t interupt6 = 0x0008; const uint16_t addrs[5] = { 0x0006, 0x0, 0x0002, 0x0002, 0x0002 }; - const uint16_t values[5] = { (uint16_t)(id != 0), - (uint16_t)(id), - (uint16_t)(x0002reg & ~interupt6), - (uint16_t)(x0002reg | interupt6), - (uint16_t)(x0002reg & ~interupt6) }; + const uint16_t values[5] = { + static_cast(id != 0), + static_cast(id), + static_cast(x0002reg & ~interupt6), + static_cast(x0002reg | interupt6), + static_cast(x0002reg & ~interupt6), + }; for (int i = 0; i < 5; ++i) lmsControl->SPI_write(addrs[i], values[i]); } diff --git a/src/lms7002_wxgui/lms7002_pnlTxTSP_view.cpp b/src/lms7002_wxgui/lms7002_pnlTxTSP_view.cpp index 6d7c1be7d..ef07df526 100644 --- a/src/lms7002_wxgui/lms7002_pnlTxTSP_view.cpp +++ b/src/lms7002_wxgui/lms7002_pnlTxTSP_view.cpp @@ -1697,25 +1697,25 @@ void lms7002_pnlTXTSP_view::UpdateGUI() cmbHBI_OVR_TXTSP->SetSelection(value2index(hbi, hbi_ovr_txtsp_IndexValuePairs)); int16_t value; - LMS_ReadParam(lmsControl, LMS7param(TSGFCW_TXTSP), (uint16_t*)&value); + LMS_ReadParam(lmsControl, LMS7param(TSGFCW_TXTSP), reinterpret_cast(&value)); rgrTSGFCW_TXTSP->SetSelection(value2index(value, tsgfcw_txtsp_IndexValuePairs)); - LMS_ReadParam(lmsControl, LMS7param(IQCORR_TXTSP), (uint16_t*)&value); + LMS_ReadParam(lmsControl, LMS7param(IQCORR_TXTSP), reinterpret_cast(&value)); int bitsToShift = (15 - LMS7param(IQCORR_TXTSP).msb - LMS7param(IQCORR_TXTSP).lsb); value = value << bitsToShift; value = value >> bitsToShift; cmbIQCORR_TXTSP->SetValue(value); - LMS_ReadParam(lmsControl, LMS7param(SEL_TX), (uint16_t*)&value); + LMS_ReadParam(lmsControl, LMS7param(SEL_TX), reinterpret_cast(&value)); assert(rgrNCOselections.size() == 16); rgrNCOselections[value & 0xF]->SetValue(true); UpdateNCOinputs(); - LMS_ReadParam(lmsControl, LMS7param(DCCORRI_TXTSP), (uint16_t*)&value); + LMS_ReadParam(lmsControl, LMS7param(DCCORRI_TXTSP), reinterpret_cast(&value)); int8_t dccorr = value; cmbDCCORRI_TXTSP->SetValue(dccorr); - LMS_ReadParam(lmsControl, LMS7param(DCCORRQ_TXTSP), (uint16_t*)&value); + LMS_ReadParam(lmsControl, LMS7param(DCCORRQ_TXTSP), reinterpret_cast(&value)); dccorr = value; cmbDCCORRQ_TXTSP->SetValue(dccorr); @@ -1739,10 +1739,10 @@ void lms7002_pnlTXTSP_view::UpdateGUI() //LMS_GetSampleRate(lmsControl, LMS_CH_TX, ch , &sr, nullptr); txtRATEVAL->SetLabel(wxString::Format("%3.3f MHz", sr / 1e6)); //check if B channel is enabled - LMS_ReadParam(lmsControl, LMS7param(MAC), (uint16_t*)&value); + LMS_ReadParam(lmsControl, LMS7param(MAC), reinterpret_cast(&value)); if (value >= 2) { - LMS_ReadParam(lmsControl, LMS7param(MIMO_SISO), (uint16_t*)&value); + LMS_ReadParam(lmsControl, LMS7param(MIMO_SISO), reinterpret_cast(&value)); if (value != 0) wxMessageBox(_("MIMO channel B is disabled"), _("Warning")); } diff --git a/src/lms7002m/LMS7002M.cpp b/src/lms7002m/LMS7002M.cpp index 8c1789e3b..12af82f4c 100644 --- a/src/lms7002m/LMS7002M.cpp +++ b/src/lms7002m/LMS7002M.cpp @@ -19,10 +19,18 @@ #include #include +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wold-style-cast" +#endif #include "cpp-feather-ini-parser/INI.h" -#include "limesuite/IComms.h" -#include "limesuite/commonTypes.h" #include "lms_gfir.h" +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif + +#include "limesuite/commonTypes.h" +#include "limesuite/IComms.h" #include "LMS7002M_RegistersMap.h" #include "Logger.h" #include "mcu_programs.h" @@ -492,14 +500,16 @@ OpStatus LMS7002M::LoadConfigLegacyFile(const std::string& filename) typedef INI ini_t; ini_t parser(filename, true); if (parser.select("FILE INFO") == false) - return ReportError(OpStatus::INVALID_VALUE, "LoadConfigLegacyFile(%s) - invalid format, missing FILE INFO section", filename.c_str()); + return ReportError( + OpStatus::INVALID_VALUE, "LoadConfigLegacyFile(%s) - invalid format, missing FILE INFO section", filename.c_str()); std::string type = ""; type = parser.get("type", "undefined"); if (type.find("LMS7002 configuration") == std::string::npos) { - return ReportError(OpStatus::INVALID_VALUE, "LoadConfigLegacyFile(%s) - invalid format, missing LMS7002 configuration", filename.c_str()); + return ReportError( + OpStatus::INVALID_VALUE, "LoadConfigLegacyFile(%s) - invalid format, missing LMS7002 configuration", filename.c_str()); } int fileVersion = 0; @@ -688,7 +698,8 @@ OpStatus LMS7002M::LoadConfig(const std::string& filename, bool tuneDynamicValue if (type.find("lms7002m_minimal_config") == std::string::npos) { - return ReportError(OpStatus::INVALID_VALUE, "LoadConfig(%s) - invalid format, missing lms7002m_minimal_config", filename.c_str()); + return ReportError( + OpStatus::INVALID_VALUE, "LoadConfig(%s) - invalid format, missing lms7002m_minimal_config", filename.c_str()); } int fileVersion = 0; @@ -789,7 +800,10 @@ OpStatus LMS7002M::ResetLogicregisters() { const uint16_t x0020_value = SPI_read(0x0020); //reset logic registers const uint16_t addr[] = { 0x0020, 0x0020 }; - const uint16_t values[] = { uint16_t(x0020_value & 0x553F), uint16_t(x0020_value | 0xFFC0) }; + const uint16_t values[] = { + static_cast(x0020_value & 0x553F), + static_cast(x0020_value | 0xFFC0), + }; //const uint16_t values[] = {x0020_value & 0x55FF, x0020_value | 0xFF00}; // LRST_TX_B, LRST_TX_A, LRST_RX_B, LRST_RX_A return SPI_write_batch(addr, values, 2); @@ -1186,7 +1200,7 @@ OpStatus LMS7002M::SetTBBIAMP_dB(const float_type gain, const Channel channel) return OpStatus::SUCCESS; } - int g_iamp = (float_type)opt_gain_tbb[ind] * pow(10.0, gain / 20.0) + 0.4; + int g_iamp = static_cast(opt_gain_tbb[ind]) * pow(10.0, gain / 20.0) + 0.4; status = Modify_SPI_Reg_bits(LMS7param(CG_IAMP_TBB), std::clamp(g_iamp, 1, 63), true); return status; @@ -1205,7 +1219,7 @@ float_type LMS7002M::GetTBBIAMP_dB(const Channel channel) return 0.0; Modify_SPI_Reg_bits(LMS7param(CG_IAMP_TBB), g_current, true); //restore } - return 20.0 * log10((float_type)g_current / (float_type)opt_gain_tbb[ind]); + return 20.0 * log10(static_cast(g_current) / static_cast(opt_gain_tbb[ind])); } OpStatus LMS7002M::SetPathRFE(PathRFE path) @@ -1402,18 +1416,18 @@ OpStatus LMS7002M::SetFrequencyCGEN(const float_type freq_Hz, const bool retainN if (dFvco <= gCGEN_VCO_frequencies[0] || dFvco >= gCGEN_VCO_frequencies[1]) return ReportError(OpStatus::ERROR, "SetFrequencyCGEN(%g MHz) - cannot deliver requested frequency", freq_Hz / 1e6); //Integer division - uint16_t gINT = (uint16_t)(dFvco / GetReferenceClk_SX(TRXDir::Rx) - 1); + uint16_t gINT = static_cast(dFvco / GetReferenceClk_SX(TRXDir::Rx) - 1); //Fractional division - dFrac = dFvco / GetReferenceClk_SX(TRXDir::Rx) - (uint32_t)(dFvco / GetReferenceClk_SX(TRXDir::Rx)); - uint32_t gFRAC = (uint32_t)(dFrac * 1048576); + dFrac = dFvco / GetReferenceClk_SX(TRXDir::Rx) - static_cast(dFvco / GetReferenceClk_SX(TRXDir::Rx)); + uint32_t gFRAC = static_cast(dFrac * 1048576); Modify_SPI_Reg_bits(LMS7param(INT_SDM_CGEN), gINT); //INT_SDM_CGEN Modify_SPI_Reg_bits(0x0087, 15, 0, gFRAC & 0xFFFF); //INT_SDM_CGEN[15:0] Modify_SPI_Reg_bits(0x0088, 3, 0, gFRAC >> 16); //INT_SDM_CGEN[19:16] Modify_SPI_Reg_bits(LMS7param(DIV_OUTCH_CGEN), iHdiv); //DIV_OUTCH_CGEN - lime::debug("INT %d, FRAC %d, DIV_OUTCH_CGEN %d", gINT, gFRAC, (uint16_t)iHdiv); + lime::debug("INT %d, FRAC %d, DIV_OUTCH_CGEN %d", gINT, gFRAC, iHdiv); lime::debug("VCO %.2f MHz, RefClk %.2f MHz", dFvco / 1e6, GetReferenceClk_SX(TRXDir::Rx) / 1e6); if (output) @@ -1567,7 +1581,7 @@ OpStatus LMS7002M::TuneVCO(VCO_Module module) // 0-cgen, 1-SXR, 2-SXT { Modify_SPI_Reg_bits(addrCSW_VCO, msb, lsb, 0); std::this_thread::sleep_for(settlingTime); - cmphl = (uint8_t)Get_SPI_Reg_bits(addrCMP, 13, 12, true); + cmphl = static_cast(Get_SPI_Reg_bits(addrCMP, 13, 12, true)); if (cmphl == 3) //VCO too high { this->SetActiveChannel(ch); //restore previously used channel @@ -1576,7 +1590,7 @@ OpStatus LMS7002M::TuneVCO(VCO_Module module) // 0-cgen, 1-SXR, 2-SXT } Modify_SPI_Reg_bits(addrCSW_VCO, msb, lsb, 255); std::this_thread::sleep_for(settlingTime); - cmphl = (uint8_t)Get_SPI_Reg_bits(addrCMP, 13, 12, true); + cmphl = static_cast(Get_SPI_Reg_bits(addrCMP, 13, 12, true)); if (cmphl == 0) //VCO too low { this->SetActiveChannel(ch); //restore previously used channel @@ -1601,8 +1615,8 @@ OpStatus LMS7002M::TuneVCO(VCO_Module module) // 0-cgen, 1-SXR, 2-SXT cswSearch[t].high |= 1 << i; //CSW_VCO=1 Modify_SPI_Reg_bits(addrCSW_VCO, msb, lsb, cswSearch[t].high); std::this_thread::sleep_for(settlingTime); - cmphl = (uint8_t)Get_SPI_Reg_bits(addrCMP, 13, 12, true); - lime::debug("csw=%d\tcmphl=%d", cswSearch[t].high, (int16_t)cmphl); + cmphl = static_cast(Get_SPI_Reg_bits(addrCMP, 13, 12, true)); + lime::debug("csw=%d\tcmphl=%d", cswSearch[t].high, cmphl); if (cmphl & 0x01) // reduce CSW cswSearch[t].high &= ~(1 << i); //CSW_VCO=0 if (cmphl == 2 && cswSearch[t].high < cswSearch[t].low) @@ -1619,7 +1633,7 @@ OpStatus LMS7002M::TuneVCO(VCO_Module module) // 0-cgen, 1-SXR, 2-SXT Modify_SPI_Reg_bits(addrCSW_VCO, msb, lsb, cswSearch[t].low); std::this_thread::sleep_for(settlingTime); const uint8_t tempCMPvalue = Get_SPI_Reg_bits(addrCMP, 13, 12, true); - lime::debug("csw=%d\tcmphl=%d", cswSearch[t].low, (int16_t)tempCMPvalue); + lime::debug("csw=%d\tcmphl=%d", cswSearch[t].low, tempCMPvalue); if (tempCMPvalue != 2) { ++cswSearch[t].low; @@ -1665,7 +1679,7 @@ OpStatus LMS7002M::TuneVCO(VCO_Module module) // 0-cgen, 1-SXR, 2-SXT finalCSW = cswLow; Modify_SPI_Reg_bits(addrCSW_VCO, msb, lsb, cswLow); std::this_thread::sleep_for(settlingTime); - cmphl = (uint8_t)Get_SPI_Reg_bits(addrCMP, 13, 12, true); + cmphl = static_cast(Get_SPI_Reg_bits(addrCMP, 13, 12, true)); if (cmphl != 2) { finalCSW = cswHigh; @@ -1678,7 +1692,7 @@ OpStatus LMS7002M::TuneVCO(VCO_Module module) // 0-cgen, 1-SXR, 2-SXT Modify_SPI_Reg_bits(addrCSW_VCO, msb, lsb, finalCSW); } std::this_thread::sleep_for(settlingTime); - cmphl = (uint8_t)Get_SPI_Reg_bits(addrCMP, 13, 12, true); + cmphl = static_cast(Get_SPI_Reg_bits(addrCMP, 13, 12, true)); this->SetActiveChannel(ch); //restore previously used channel if (cmphl == 2) { @@ -1728,7 +1742,8 @@ OpStatus LMS7002M::Modify_SPI_Reg_bits(const LMS7Parameter& param, const uint16_ @param value new bits value, the value is shifted left by lsb bits @param fromChip read initial value directly from chip */ -OpStatus LMS7002M::Modify_SPI_Reg_bits(const uint16_t address, const uint8_t msb, const uint8_t lsb, const uint16_t value, bool fromChip) +OpStatus LMS7002M::Modify_SPI_Reg_bits( + const uint16_t address, const uint8_t msb, const uint8_t lsb, const uint16_t value, bool fromChip) { uint16_t spiDataReg = SPI_read(address, fromChip); //read current SPI reg data uint16_t spiMask = (~(~0u << (msb - lsb + 1))) << (lsb); // creates bit mask @@ -1743,7 +1758,8 @@ OpStatus LMS7002M::Modify_SPI_Reg_bits(const uint16_t address, const uint8_t msb @param start starting index of given arrays @param stop end index of given arrays */ -OpStatus LMS7002M::Modify_SPI_Reg_mask(const uint16_t* addr, const uint16_t* masks, const uint16_t* values, uint8_t start, uint8_t stop) +OpStatus LMS7002M::Modify_SPI_Reg_mask( + const uint16_t* addr, const uint16_t* masks, const uint16_t* values, uint8_t start, uint8_t stop) { OpStatus status = OpStatus::SUCCESS; uint16_t reg_data; @@ -1824,10 +1840,9 @@ OpStatus LMS7002M::SetFrequencySX(TRXDir dir, float_type freq_Hz, SX_details* ou const float_type refClk_Hz = GetReferenceClk_SX(dir); assert(refClk_Hz > 0); - integerPart = (uint16_t)(VCOfreq / (refClk_Hz * (1 + (VCOfreq > m_dThrF))) - 4); - fractionalPart = (uint32_t)((VCOfreq / (refClk_Hz * (1 + (VCOfreq > m_dThrF))) - - (uint32_t)(VCOfreq / (refClk_Hz * (1 + (VCOfreq > m_dThrF))))) * - 1048576); + double divider = refClk_Hz * (1 + (VCOfreq > m_dThrF)); + integerPart = static_cast(VCOfreq / divider - 4); + fractionalPart = static_cast((VCOfreq / divider - static_cast(VCOfreq / divider)) * 1048576); Channel ch = this->GetActiveChannel(); this->SetActiveChannel(dir == TRXDir::Tx ? Channel::ChSXT : Channel::ChSXR); @@ -1843,7 +1858,7 @@ OpStatus LMS7002M::SetFrequencySX(TRXDir dir, float_type freq_Hz, SX_details* ou freq_Hz / 1e6, integerPart, fractionalPart, - (int16_t)div_loch, + div_loch, (VCOfreq > m_dThrF)); lime::debug("Expected VCO %.2f MHz, RefClk %.2f MHz", VCOfreq / 1e6, refClk_Hz / 1e6); @@ -1871,7 +1886,7 @@ OpStatus LMS7002M::SetFrequencySX(TRXDir dir, float_type freq_Hz, SX_details* ou Modify_SPI_Reg_bits(LMS7param(CSW_VCO).address, LMS7param(CSW_VCO).msb, LMS7param(CSW_VCO).lsb, csw_value); // probably no need for this as the interface is already very slow.. std::this_thread::sleep_for(std::chrono::microseconds(50)); - auto cmphl = (uint8_t)Get_SPI_Reg_bits(LMS7param(VCO_CMPHO).address, 13, 12, true); + auto cmphl = static_cast(Get_SPI_Reg_bits(LMS7param(VCO_CMPHO).address, 13, 12, true)); if (cmphl == 2) { lime::info("Fast Tune success; vco=%d value=%d", tuning_cache_sel_vco[freq_Hz], tuning_cache_csw_value[freq_Hz]); @@ -1899,7 +1914,10 @@ OpStatus LMS7002M::SetFrequencySX(TRXDir dir, float_type freq_Hz, SX_details* ou { tuneScore[sel_vco] = -128 + Get_SPI_Reg_bits(LMS7param(CSW_VCO), true); canDeliverFrequency = true; - lime::debug("%s : csw=%d %s", vcoNames[sel_vco], tuneScore[sel_vco] + 128, (status == OpStatus::SUCCESS ? "tune ok" : "tune fail")); + lime::debug("%s : csw=%d %s", + vcoNames[sel_vco], + tuneScore[sel_vco] + 128, + (status == OpStatus::SUCCESS ? "tune ok" : "tune fail")); } else { @@ -1952,7 +1970,8 @@ OpStatus LMS7002M::SetFrequencySX(TRXDir dir, float_type freq_Hz, SX_details* ou this->SetActiveChannel(ch); //restore used channel if (canDeliverFrequency == false) - return ReportError(OpStatus::ERROR, "SetFrequencySX%s(%g MHz) - cannot deliver frequency", dir == TRXDir::Tx ? "T" : "R", freq_Hz / 1e6); + return ReportError( + OpStatus::ERROR, "SetFrequencySX%s(%g MHz) - cannot deliver frequency", dir == TRXDir::Tx ? "T" : "R", freq_Hz / 1e6); return OpStatus::SUCCESS; } @@ -1977,7 +1996,7 @@ OpStatus LMS7002M::SetFrequencySXWithSpurCancelation(TRXDir dir, float_type freq float newFreq(0); if (needCancelation) { - newFreq = (int)(freq_Hz / refClk + 0.5) * refClk; + newFreq = static_cast(freq_Hz / refClk + 0.5) * refClk; TuneRxFilter(BW - BWOffset + 2 * abs(freq_Hz - newFreq)); status = SetFrequencySX(dir, newFreq); } @@ -2041,9 +2060,9 @@ float_type LMS7002M::GetFrequencySX(TRXDir dir) uint32_t gFRAC = ((gINT & 0xF) * 65536) | Get_SPI_Reg_bits(0x011D, 15, 0); const float_type refClk_Hz = GetReferenceClk_SX(dir); - dMul = (float_type)refClk_Hz / (1 << (Get_SPI_Reg_bits(LMS7param(DIV_LOCH)) + 1)); + dMul = refClk_Hz / (1 << (Get_SPI_Reg_bits(LMS7param(DIV_LOCH)) + 1)); //Calculate real frequency according to the calculated parameters - dMul = dMul * ((gINT >> 4) + 4 + (float_type)gFRAC / 1048576.0) * (Get_SPI_Reg_bits(LMS7param(EN_DIV2_DIVPROG)) + 1); + dMul = dMul * ((gINT >> 4) + 4 + gFRAC / 1048576.0) * (Get_SPI_Reg_bits(LMS7param(EN_DIV2_DIVPROG)) + 1); return dMul; } @@ -2056,16 +2075,16 @@ float_type LMS7002M::GetFrequencySX(TRXDir dir) OpStatus LMS7002M::SetNCOFrequency(TRXDir dir, uint8_t index, float_type freq_Hz) { if (index > 15) - return ReportError(OpStatus::INVALID_VALUE, "SetNCOFrequency(index = %d) - index out of range [0, 15]", int(index)); + return ReportError(OpStatus::INVALID_VALUE, "SetNCOFrequency(index = %d) - index out of range [0, 15]", index); float_type refClk_Hz = GetReferenceClk_TSP(dir); if (freq_Hz < 0 || freq_Hz / refClk_Hz > 0.5) return ReportError(OpStatus::OUT_OF_RANGE, "SetNCOFrequency(index = %d) - Frequency(%g MHz) out of range [0-%g) MHz", - int(index), + index, freq_Hz / 1e6, refClk_Hz / 2e6); uint16_t addr = dir == TRXDir::Tx ? 0x0240 : 0x0440; - uint32_t fcw = uint32_t((freq_Hz / refClk_Hz) * 4294967296); + uint32_t fcw = static_cast((freq_Hz / refClk_Hz) * 4294967296); SPI_write(addr + 2 + index * 2, (fcw >> 16)); //NCO frequency control word register MSB part. SPI_write(addr + 3 + index * 2, fcw); //NCO frequency control word register LSB part. return OpStatus::SUCCESS; @@ -2080,7 +2099,7 @@ OpStatus LMS7002M::SetNCOFrequency(TRXDir dir, uint8_t index, float_type freq_Hz float_type LMS7002M::GetNCOFrequency(TRXDir dir, uint8_t index, bool fromChip) { if (index > 15) - return ReportError(ERANGE, "GetNCOFrequency_MHz(index = %d) - index out of range [0, 15]", int(index)); + return ReportError(ERANGE, "GetNCOFrequency_MHz(index = %d) - index out of range [0, 15]", index); float_type refClk_Hz = GetReferenceClk_TSP(dir); uint16_t addr = dir == TRXDir::Tx ? 0x0240 : 0x0440; uint32_t fcw = 0; @@ -2097,7 +2116,7 @@ float_type LMS7002M::GetNCOFrequency(TRXDir dir, uint8_t index, bool fromChip) OpStatus LMS7002M::SetNCOPhaseOffsetForMode0(TRXDir dir, float_type angle_deg) { uint16_t addr = dir == TRXDir::Tx ? 0x0241 : 0x0441; - uint16_t pho = (uint16_t)(65536 * (angle_deg / 360)); + uint16_t pho = static_cast(65536 * (angle_deg / 360)); SPI_write(addr, pho); return OpStatus::SUCCESS; } @@ -2111,9 +2130,9 @@ OpStatus LMS7002M::SetNCOPhaseOffsetForMode0(TRXDir dir, float_type angle_deg) OpStatus LMS7002M::SetNCOPhaseOffset(TRXDir dir, uint8_t index, float_type angle_deg) { if (index > 15) - return ReportError(OpStatus::INVALID_VALUE, "SetNCOPhaseOffset(index = %d) - index out of range [0, 15]", int(index)); + return ReportError(OpStatus::INVALID_VALUE, "SetNCOPhaseOffset(index = %d) - index out of range [0, 15]", index); uint16_t addr = dir == TRXDir::Tx ? 0x0244 : 0x0444; - uint16_t pho = (uint16_t)(65536 * (angle_deg / 360)); + uint16_t pho = static_cast(65536 * (angle_deg / 360)); SPI_write(addr + index, pho); return OpStatus::SUCCESS; } @@ -2151,7 +2170,7 @@ std::vector LMS7002M::GetNCOPhases(TRXDir dir, float_type* frequency float_type LMS7002M::GetNCOPhaseOffset_Deg(TRXDir dir, uint8_t index) { if (index > 15) - return ReportError(ERANGE, "GetNCOPhaseOffset_Deg(index = %d) - index out of range [0, 15]", int(index)); + return ReportError(ERANGE, "GetNCOPhaseOffset_Deg(index = %d) - index out of range [0, 15]", index); uint16_t addr = dir == TRXDir::Tx ? 0x0244 : 0x0444; uint16_t pho = SPI_read(addr + index); float_type angle = 360 * pho / 65536.0; @@ -2192,7 +2211,7 @@ OpStatus LMS7002M::SetGFIRCoefficients(TRXDir dir, uint8_t gfirIndex, const floa int16_t words[120]; // actual used coefficients count is multiple of 'bankCount' // if coefCount is not multiple, extra '0' coefficients will be written - const uint8_t bankLength = ceil((float)coefCount / bankCount); + const uint8_t bankLength = std::ceil(static_cast(coefCount) / bankCount); const int16_t actualCoefCount = bankLength * bankCount; assert(actualCoefCount <= maxCoefCount); @@ -2221,7 +2240,7 @@ OpStatus LMS7002M::SetGFIRCoefficients(TRXDir dir, uint8_t gfirIndex, const floa gfirL_param.address += gfirIndex + (dir == TRXDir::Tx ? 0 : 0x0200); Modify_SPI_Reg_bits(gfirL_param, bankLength - 1); - return SPI_write_batch(addrs, (const uint16_t*)words, actualCoefCount, true); + return SPI_write_batch(addrs, reinterpret_cast(words), actualCoefCount, true); } /** @brief Returns currently loaded FIR coefficients. @@ -2246,7 +2265,8 @@ OpStatus LMS7002M::GetGFIRCoefficients(TRXDir dir, uint8_t gfirIndex, float_type if (coefCount > coefLimit) { - return ReportError(OpStatus::OUT_OF_RANGE, "GetGFIRCoefficients(coefCount=%d) - exceeds coefLimit=%d", coefCount, coefLimit); + return ReportError( + OpStatus::OUT_OF_RANGE, "GetGFIRCoefficients(coefCount=%d) - exceeds coefLimit=%d", coefCount, coefLimit); } std::vector addresses; @@ -2408,7 +2428,7 @@ OpStatus LMS7002M::SPI_write_batch(const uint16_t* spiAddr, const uint16_t* spiD continue; } - data.push_back((1 << 31) | (uint32_t(spiAddr[i]) << 16) | spiData[i]); //msbit 1=SPI write + data.push_back((1 << 31) | (static_cast(spiAddr[i]) << 16) | spiData[i]); //msbit 1=SPI write if (wr0) mRegistersMap->SetValue(0, spiAddr[i], spiData[i]); if (wr1) @@ -2448,7 +2468,7 @@ OpStatus LMS7002M::SPI_read_batch(const uint16_t* spiAddr, uint16_t* spiData, ui std::vector dataRd(cnt); for (size_t i = 0; i < cnt; ++i) { - dataWr[i] = (uint32_t)(spiAddr[i]); + dataWr[i] = spiAddr[i]; } controlPort->SPI(dataWr.data(), dataRd.data(), cnt); @@ -2756,7 +2776,7 @@ bool LMS7002M::IsSynced() std::vector dataWr(addrToRead.size()); std::vector dataRd(addrToRead.size()); for (size_t i = 0; i < addrToRead.size(); ++i) - dataWr[i] = (uint32_t(addrToRead[i]) << 16); + dataWr[i] = (static_cast(addrToRead[i]) << 16); controlPort->SPI(dataWr.data(), dataRd.data(), dataWr.size()); for (size_t i = 0; i < addrToRead.size(); ++i) @@ -2793,7 +2813,7 @@ bool LMS7002M::IsSynced() dataWr.resize(addrToRead.size()); dataRd.resize(addrToRead.size()); for (size_t i = 0; i < addrToRead.size(); ++i) - dataWr[i] = (uint32_t(addrToRead[i]) << 16); + dataWr[i] = (static_cast(addrToRead[i]) << 16); controlPort->SPI(dataWr.data(), dataRd.data(), dataWr.size()); for (size_t i = 0; i < addrToRead.size(); ++i) dataReceived[i] = dataRd[i] & 0xFFFF; @@ -2941,7 +2961,7 @@ OpStatus LMS7002M::SetInterfaceFrequency(float_type cgen_freq_Hz, const uint8_t } else { - uint8_t divider = (uint8_t)pow(2.0, decimation + siso); + uint8_t divider = static_cast(std::pow(2.0, decimation + siso)); if (divider > 1) Modify_SPI_Reg_bits(LMS7param(RXTSPCLKA_DIV), (divider / 2) - 1); else @@ -2967,7 +2987,7 @@ OpStatus LMS7002M::SetInterfaceFrequency(float_type cgen_freq_Hz, const uint8_t } else { - uint8_t divider = (uint8_t)pow(2.0, interpolation + siso); + uint8_t divider = static_cast(std::pow(2.0, interpolation + siso)); if (divider > 1) Modify_SPI_Reg_bits(LMS7param(TXTSPCLKA_DIV), (divider / 2) - 1); else @@ -3085,8 +3105,8 @@ void LMS7002M::GetDCOffset(TRXDir dir, float_type& I, float_type& Q) { if (dir == TRXDir::Tx) { - I = int8_t(this->Get_SPI_Reg_bits(LMS7param(DCCORRI_TXTSP))) / 127.0; //signed 8-bit - Q = int8_t(this->Get_SPI_Reg_bits(LMS7param(DCCORRQ_TXTSP))) / 127.0; //signed 8-bit + I = static_cast(this->Get_SPI_Reg_bits(LMS7param(DCCORRI_TXTSP))) / 127.0; //signed 8-bit + Q = static_cast(this->Get_SPI_Reg_bits(LMS7param(DCCORRQ_TXTSP))) / 127.0; //signed 8-bit } else { @@ -3115,12 +3135,13 @@ OpStatus LMS7002M::SetIQBalance(const TRXDir dir, const float_type phase, const void LMS7002M::GetIQBalance(const TRXDir dir, float_type& phase, float_type& gainI, float_type& gainQ) { - int iqcorr = int16_t(this->Get_SPI_Reg_bits(dir == TRXDir::Tx ? LMS7param(IQCORR_TXTSP) : LMS7param(IQCORR_RXTSP)) << 4) >> - 4; //sign extend 12-bit - int gcorri = - int16_t(this->Get_SPI_Reg_bits(dir == TRXDir::Tx ? LMS7param(GCORRI_TXTSP) : LMS7param(GCORRI_RXTSP))); //unsigned 11-bit - int gcorrq = - int16_t(this->Get_SPI_Reg_bits(dir == TRXDir::Tx ? LMS7param(GCORRQ_TXTSP) : LMS7param(GCORRQ_RXTSP))); //unsigned 11-bit + int iqcorr = + static_cast(this->Get_SPI_Reg_bits(dir == TRXDir::Tx ? LMS7param(IQCORR_TXTSP) : LMS7param(IQCORR_RXTSP)) << 4) >> + 4; //sign extend 12-bit + int gcorri = static_cast( + this->Get_SPI_Reg_bits(dir == TRXDir::Tx ? LMS7param(GCORRI_TXTSP) : LMS7param(GCORRI_RXTSP))); //unsigned 11-bit + int gcorrq = static_cast( + this->Get_SPI_Reg_bits(dir == TRXDir::Tx ? LMS7param(GCORRQ_TXTSP) : LMS7param(GCORRQ_RXTSP))); //unsigned 11-bit phase = (M_PI / 2) * iqcorr / 2047.0; gainI = gcorri / 2047.0; diff --git a/src/lms7002m/LMS7002M_RxTxCalibrations.cpp b/src/lms7002m/LMS7002M_RxTxCalibrations.cpp index 9d0d1c365..f8709f6e6 100644 --- a/src/lms7002m/LMS7002M_RxTxCalibrations.cpp +++ b/src/lms7002m/LMS7002M_RxTxCalibrations.cpp @@ -60,8 +60,8 @@ static uint8_t GetExtLoopPair(lime::LMS7002M& ctr, bool calibratingTx) */ static inline int16_t signextIqCorr(const uint16_t regVal) { - int16_t signedPhase = int16_t(regVal << 4); - return int16_t(signedPhase) >> 4; + int16_t signedPhase = static_cast(regVal << 4); + return signedPhase >> 4; } const double TrxCalib_RF_LimitLow = 2.5e6; @@ -190,7 +190,7 @@ OpStatus LMS7002M::CalibrateTx(float_type bandwidth_Hz, bool useExtLoopback) return ReportError(OpStatus::INVALID_VALUE, "Tx Calibration: Device not connected"); auto beginTime = std::chrono::high_resolution_clock::now(); int status; - uint8_t ch = (uint8_t)Get_SPI_Reg_bits(LMS7_MAC); + uint8_t ch = static_cast(Get_SPI_Reg_bits(LMS7_MAC)); if (ch == 0 || ch == 3) return ReportError(OpStatus::INVALID_VALUE, "Tx Calibration: Incorrect channel selection MAC %i", ch); @@ -240,7 +240,8 @@ OpStatus LMS7002M::CalibrateTx(float_type bandwidth_Hz, bool useExtLoopback) mcuControl->RunProcedure(useExtLoopback ? MCU_FUNCTION_CALIBRATE_TX_EXTLOOPB : MCU_FUNCTION_CALIBRATE_TX); status = mcuControl->WaitForMCU(1000); if (status != MCU_BD::MCU_NO_ERROR) - return ReportError(OpStatus::INVALID_VALUE, "Tx Calibration: MCU error %i (%s)", status, MCU_BD::MCUStatusMessage(status)); + return ReportError( + OpStatus::INVALID_VALUE, "Tx Calibration: MCU error %i (%s)", status, MCU_BD::MCUStatusMessage(status)); } //sync registers to cache @@ -289,11 +290,11 @@ OpStatus LMS7002M::CalibrateRx(float_type bandwidth_Hz, bool useExtLoopback) auto beginTime = std::chrono::high_resolution_clock::now(); #endif - uint8_t ch = (uint8_t)Get_SPI_Reg_bits(LMS7_MAC); + uint8_t ch = static_cast(Get_SPI_Reg_bits(LMS7_MAC)); if (ch == 0 || ch == 3) return ReportError(OpStatus::INVALID_VALUE, "Rx Calibration: Incorrect channel selection MAC %i", ch); uint8_t channel = ch == 1 ? 0 : 1; - uint8_t lna = (uint8_t)Get_SPI_Reg_bits(LMS7_SEL_PATH_RFE); + uint8_t lna = static_cast(Get_SPI_Reg_bits(LMS7_SEL_PATH_RFE)); double rxFreq = GetFrequencySX(TRXDir::Rx); const char* lnaName; @@ -360,7 +361,8 @@ OpStatus LMS7002M::CalibrateRx(float_type bandwidth_Hz, bool useExtLoopback) mcuControl->RunProcedure(useExtLoopback ? MCU_FUNCTION_CALIBRATE_RX_EXTLOOPB : MCU_FUNCTION_CALIBRATE_RX); int status = mcuControl->WaitForMCU(1000); if (status != MCU_BD::MCU_NO_ERROR) - return ReportError(OpStatus::INVALID_VALUE, "Rx calibration: MCU error %i (%s)", status, MCU_BD::MCUStatusMessage(status)); + return ReportError( + OpStatus::INVALID_VALUE, "Rx calibration: MCU error %i (%s)", status, MCU_BD::MCUStatusMessage(status)); } //sync registers to cache diff --git a/src/lms7002m/MCU_BD.cpp b/src/lms7002m/MCU_BD.cpp index 83f11a86d..63321e9cd 100644 --- a/src/lms7002m/MCU_BD.cpp +++ b/src/lms7002m/MCU_BD.cpp @@ -210,7 +210,7 @@ int MCU_BD::ReadOneByte(unsigned char* data) { // Time out has not occured tempi = mSPI_read(0x0005); // REG5 read // return the read byte - (*data) = (unsigned char)(tempi); + (*data) = static_cast(tempi); } else (*data) = 0; @@ -258,17 +258,17 @@ int MCU_BD::Three_byte_command(unsigned char data1, *rdata2 = 0x00; *rdata3 = 0x00; - mSPI_write(0x8004, (unsigned short)(data1)); //REG4 write + mSPI_write(0x8004, static_cast(data1)); //REG4 write retval = WaitUntilWritten(); if (retval == -1) return -1; - mSPI_write(0x8004, (unsigned short)(data2)); //REG4 write + mSPI_write(0x8004, static_cast(data2)); //REG4 write retval = WaitUntilWritten(); if (retval == -1) return -1; - mSPI_write(0x8004, (unsigned short)(data3)); //REG4 write + mSPI_write(0x8004, static_cast(data3)); //REG4 write retval = WaitUntilWritten(); if (retval == -1) return -1; @@ -316,7 +316,7 @@ int MCU_BD::Read_IRAM() for (i = 0; i <= 255; i++) { // code 0x78 is for reading the IRAM locations - retval = Three_byte_command(0x78, ((unsigned char)(i)), 0x00, &tempc1, &tempc2, &tempc3); + retval = Three_byte_command(0x78, static_cast(i), 0x00, &tempc1, &tempc2, &tempc3); if (retval == 0) m_IRAM[i] = tempc3; else @@ -353,7 +353,7 @@ int MCU_BD::Erase_IRAM() { m_IRAM[i] = 0x00; // code 0x7C is for writing the IRAM locations - retval = Three_byte_command(0x7C, ((unsigned char)(i)), 0x00, &tempc1, &tempc2, &tempc3); + retval = Three_byte_command(0x7C, static_cast(i), 0x00, &tempc1, &tempc2, &tempc3); if (retval == -1) { i = 256; @@ -1004,7 +1004,7 @@ void MCU_BD::SetParameter(MCU_Parameter param, float value) { uint8_t inputRegs[3]; value /= 1e6; - inputRegs[0] = (uint8_t)value; //frequency integer part + inputRegs[0] = static_cast(value); //frequency integer part uint16_t fracPart = value * 1000.0 - inputRegs[0] * 1000.0; inputRegs[1] = (fracPart >> 8) & 0xFF; @@ -1023,7 +1023,7 @@ void MCU_BD::SetParameter(MCU_Parameter param, float value) RunProcedure(3); if (param == MCU_Parameter::MCU_EXT_LOOPBACK_PAIR) { - uint8_t intVal = (int)value; + uint8_t intVal = static_cast(value); mSPI_write(0, intVal); mSPI_write(0x0002, x0002reg | interupt7); mSPI_write(0x0002, x0002reg & ~interupt7); diff --git a/src/lms7002m/MCU_File.cpp b/src/lms7002m/MCU_File.cpp index 0421c1ab7..fee938d47 100644 --- a/src/lms7002m/MCU_File.cpp +++ b/src/lms7002m/MCU_File.cpp @@ -161,7 +161,7 @@ void MCU_File::ReadHex(unsigned long limit) { throw "Hex line data corrupt!"s; } - checkSum += (unsigned char)tmp; + checkSum += static_cast(tmp); } if (checkSum != 0) { @@ -204,7 +204,7 @@ void MCU_File::ReadHex(unsigned long limit) } continue; } - m_chunks.back().m_bytes.push_back((unsigned char)tmp); + m_chunks.back().m_bytes.push_back(static_cast(tmp)); } } break; @@ -269,7 +269,7 @@ void MCU_File::ReadHex(unsigned long limit) throw "Address field must be zero in extended linear address record!"s; } sscanf(&szLine[9], "%4lx", &startAddress); - addressBase = ((unsigned long)startAddress) << 16; + addressBase = startAddress << 16; linear = true; break; @@ -321,7 +321,7 @@ void MCU_File::ReadHex(unsigned long limit) { throw "Hex line data corrupt!"s; } - checkSum += (unsigned char)tmp; + checkSum += static_cast(tmp); } if (checkSum != 255) { @@ -335,10 +335,10 @@ void MCU_File::ReadHex(unsigned long limit) { char header[256]; uint8_t i = 0; - for (i = 0; uint8_t(i + 3) < count; ++i) + for (i = 0; static_cast(i + 3) < count; ++i) { sscanf(&szLine[8 + i * 2], "%2lx", &tmp); - header[i] = (char)tmp; + header[i] = static_cast(tmp); } header[i] = 0; if (i > 0) @@ -373,8 +373,8 @@ void MCU_File::ReadHex(unsigned long limit) m_chunks.push_back(MemBlock()); m_chunks.back().m_startAddress = startAddress; } - unsigned char i = 0; - for (i = uint8_t(type - '1'); uint8_t(i + 3) < count; ++i) + uint8_t i = 0; + for (i = static_cast(type - '1'); static_cast(i + 3) < count; ++i) { sscanf(&szLine[8 + i * 2], "%2lx", &tmp); if (startAddress + i > limit) @@ -388,7 +388,7 @@ void MCU_File::ReadHex(unsigned long limit) } continue; } - m_chunks.back().m_bytes.push_back((unsigned char)tmp); + m_chunks.back().m_bytes.push_back(static_cast(tmp)); } } break; diff --git a/src/lms7suiteAppFrame.cpp b/src/lms7suiteAppFrame.cpp index 02843ce9f..779cf243e 100644 --- a/src/lms7suiteAppFrame.cpp +++ b/src/lms7suiteAppFrame.cpp @@ -59,7 +59,7 @@ void LMS7SuiteAppFrame::OnGlobalLogEvent(const lime::LogLevel level, const char* wxCommandEvent evt; evt.SetString(wxString::FromAscii(message)); evt.SetEventType(LOG_MESSAGE); - evt.SetInt(int(level)); + evt.SetInt(static_cast(level)); wxPostEvent(obj_ptr, evt); } @@ -349,7 +349,7 @@ void LMS7SuiteAppFrame::OnLogDataTransfer(bool Tx, const uint8_t* data, const ui repeatedZeros = repeatedZeros - (repeatedZeros & 0x1); for (size_t i = 0; i < length - repeatedZeros; ++i) //casting to short to print as numbers - ss << " " << std::setw(2) << (unsigned short)data[i]; + ss << " " << std::setw(2) << static_cast(data[i]); if (repeatedZeros > 2) ss << " (00 x " << std::dec << repeatedZeros << " times)"; lime::debug(ss.str()); diff --git a/src/mcu_program/common_src/lms7002m_calibrations.c b/src/mcu_program/common_src/lms7002m_calibrations.c index 8a0934567..6b44e4e41 100644 --- a/src/mcu_program/common_src/lms7002m_calibrations.c +++ b/src/mcu_program/common_src/lms7002m_calibrations.c @@ -4,15 +4,11 @@ #include "lms7002m_controls.h" #include #include "mcu_defines.h" - -#ifndef __cplusplus - #include "lms7002_regx51.h" //MCU timer sfr -#endif +#include #define ENABLE_EXTERNAL_LOOPBACK 1 #ifdef __cplusplus - #include //#define VERBOSE 1 //#define DRAW_GNU_PLOTS @@ -55,6 +51,14 @@ void DrawMeasurement(GNUPlotPipe& gp, const MeasurementsVector& vec) gp.write("e\n"); } +extern "C" { +#else + #define VERBOSE 0 + #define PUSH_GMEASUREMENT_VALUES(value, rssi) + + #include "lms7002_regx51.h" //MCU timer sfr +#endif // __cplusplus + ///APPROXIMATE conversion float ChipRSSI_2_dBFS(uint32_t rssi) { @@ -70,10 +74,6 @@ int16_t toSigned(int16_t val, uint8_t msblsb) val >>= 15 - ((msblsb >> 4) & 0xF); return val; } -#else - #define VERBOSE 0 - #define PUSH_GMEASUREMENT_VALUES(value, rssi) -#endif // __cplusplus float bandwidthRF = 5e6; //Calibration bandwidth uint16_t RSSIDelayCounter = 1; // MCU timer delay between RSSI measurements @@ -981,11 +981,10 @@ uint8_t CalibrateTxSetup(bool extLoopback) uint8_t CalibrateTx(bool extLoopback) { const uint16_t x0020val = SPI_read(0x0020); -#ifdef VERBOSE +#if defined(VERBOSE) && defined(__cplusplus) auto beginTime = std::chrono::high_resolution_clock::now(); #endif #if VERBOSE - uint8_t sel_band1_trf = (uint8_t)Get_SPI_Reg_bits(SEL_BAND1_TRF); printf("Tx ch.%s , BW: %g MHz, RF output: %s, Gain: %i, loopb: %s\n", (x0020val & 3) == 0x1 ? "A" : "B", @@ -1435,7 +1434,7 @@ uint8_t CheckSaturationRx(const float_type bandwidth_Hz, bool extLoopback) uint8_t CalibrateRx(bool extLoopback, bool dcOnly) { -#ifdef VERBOSE +#if defined(VERBOSE) && defined(__cplusplus) auto beginTime = std::chrono::high_resolution_clock::now(); #endif uint8_t status; @@ -1559,3 +1558,7 @@ RxCalibrationEndStage : { #endif //LMS_VERBOSE_OUTPUT return MCU_NO_ERROR; } + +#ifdef __cplusplus +} // extern C +#endif diff --git a/src/mcu_program/common_src/lms7002m_calibrations.h b/src/mcu_program/common_src/lms7002m_calibrations.h index e2c426588..b2a7bbb52 100644 --- a/src/mcu_program/common_src/lms7002m_calibrations.h +++ b/src/mcu_program/common_src/lms7002m_calibrations.h @@ -1,13 +1,18 @@ #ifndef LMS7002M_CALIBRATIONS_H #define LMS7002M_CALIBRATIONS_H -#include "typedefs.h" +#ifdef __cplusplus namespace lime { class LMS7002M; } void SetupCalibrations(lime::LMS7002M* chip, double BW); +extern "C" { +#endif + +#include "typedefs.h" + int16_t ReadAnalogDC(const uint16_t addr); void UpdateRSSIDelay(); uint32_t GetRSSI(); @@ -20,4 +25,8 @@ void CalibrateRxDCAuto(); uint8_t RunAGC(uint32_t wantedRSSI); int16_t clamp(int16_t value, int16_t minBound, int16_t maxBound); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/mcu_program/common_src/lms7002m_controls.c b/src/mcu_program/common_src/lms7002m_controls.c index fae3ceac1..00e8d9798 100644 --- a/src/mcu_program/common_src/lms7002m_controls.c +++ b/src/mcu_program/common_src/lms7002m_controls.c @@ -4,13 +4,15 @@ #include "math.h" #include "typedefs.h" #include "mcu_defines.h" +#include #ifdef __cplusplus - #include - #include -using namespace std; #include #include + #include +using namespace std; + +extern "C" { #else #include "lms7002_regx51.h" //MCU timer sfr uint16_t gComparatorDelayCounter = 0xFF00; // ~100us @ ref 30.72MHz @@ -95,81 +97,414 @@ void SaveChipState(bool wr) SPI_write(0x0020, ch); } +void SetDefaultsSX() +{ + ROM const uint16_t SXAddr[] = { 0x011C, 0x011D, 0x011E, 0x011F, 0x0121, 0x0122, 0x0123 }; + ROM const uint16_t SXdefVals[] = { 0xAD43, 0x0400, 0x0780, 0x3640, 0x3404, 0x033F, 0x067B }; + + uint8_t i; + for (i = sizeof(SXAddr) / sizeof(uint16_t); i; --i) + SPI_write(SXAddr[i - 1], SXdefVals[i - 1]); + //keep 0x0120[7:0]ICT_VCO bias value intact + Modify_SPI_Reg_bits(0x0120, MSB_LSB(15, 8), 0xB9FF); +} + +void ClockLogicResets() +{ + //MCLK2 toggle + uint16_t reg = SPI_read(0x002B); + SPI_write(0x002B, reg ^ (1 << 9)); + SPI_write(0x002B, reg); + + //TSP logic reset + reg = SPI_read(0x0020); + SPI_write(0x0020, reg & ~0xAA00); + SPI_write(0x0020, reg); +} + +float_type GetFrequencyCGEN() +{ + const float_type dMul = (RefClk / 2.0) / (Get_SPI_Reg_bits(DIV_OUTCH_CGEN) + 1); //DIV_OUTCH_CGEN + const uint16_t gINT = Get_SPI_Reg_bits(0x0088, MSB_LSB(13, 0)); //read whole register to reduce SPI transfers + const uint32_t gFRAC = ((uint32_t)(gINT & 0xF) << 16) | Get_SPI_Reg_bits(0x0087, MSB_LSB(15, 0)); + return dMul * (((gINT >> 4) + 1 + gFRAC / 1048576.0)); +} + +uint8_t SetFrequencyCGEN(float_type freq) +{ + float_type dFvco; + float_type intpart; + //VCO frequency selection according to F_CLKH + { + uint8_t iHdiv_high = (2.94e9 / 2 / freq) - 1; + uint8_t iHdiv_low = (1.93e9 / 2 / freq); + uint8_t iHdiv = (iHdiv_low + iHdiv_high) / 2; + dFvco = 2 * (iHdiv + 1) * freq; + Modify_SPI_Reg_bits(DIV_OUTCH_CGEN, iHdiv); + } + //Integer division + intpart = dFvco / RefClk; + Modify_SPI_Reg_bits(INT_SDM_CGEN, intpart - 1); //INT_SDM_CGEN + //Fractional division + { + const float_type dFrac = intpart - (uint32_t)(dFvco / RefClk); + const uint32_t gFRAC = (uint32_t)(dFrac * 1048576); + Modify_SPI_Reg_bits(0x0087, MSB_LSB(15, 0), gFRAC & 0xFFFF); //INT_SDM_CGEN[15:0] + Modify_SPI_Reg_bits(0x0088, MSB_LSB(3, 0), gFRAC >> 16); //INT_SDM_CGEN[19:16] + } + +#if VERBOSE + //printf("CGEN: Freq=%g MHz, VCO=%g GHz, INT=%i, FRAC=%i, DIV_OUTCH_CGEN=%i\n", freq/1e6, dFvco/1e9, gINT, gFRAC, iHdiv); +#endif // NDEBUG + if (TuneVCO(VCO_CGEN) != 0) + return MCU_CGEN_TUNE_FAILED; + return 0; +} + +float_type GetReferenceClk_TSP_MHz(bool tx) +{ + const float_type cgenFreq = GetFrequencyCGEN(); + const float_type clklfreq = cgenFreq / pow2(Get_SPI_Reg_bits(CLKH_OV_CLKL_CGEN)); + if (Get_SPI_Reg_bits(EN_ADCCLKH_CLKGN) == 0) + return tx ? clklfreq : cgenFreq / 4; + else + return tx ? cgenFreq : clklfreq / 4; +} + +void SetNCOFrequency(const bool tx, const float freq, uint8_t index) +{ + const uint16_t addr = (tx ? 0x0242 : 0x0442) + index * 2; + const uint32_t fcw = (uint32_t)((freq / GetReferenceClk_TSP_MHz(tx)) * 4294967296.0); + SPI_write(addr, (fcw >> 16)); //NCO frequency control word register MSB part. + SPI_write(addr + 1, fcw); //NCO frequency control word register LSB part. +} + +float_type GetFrequencySX(const bool Tx) +{ + const uint16_t ch = SPI_read(0x0020); //(uint8_t)Get_SPI_Reg_bits(MAC); //remember previously used channel + Modify_SPI_Reg_bits(MAC, Tx ? 2 : 1); // Rx mac = 1, Tx mac = 2 + { + const uint16_t gINT = Get_SPI_Reg_bits(0x011E, MSB_LSB(13, 0)); // read whole register to reduce SPI transfers + const uint32_t gFRAC = ((uint32_t)(gINT & 0xF) << 16) | SPI_read(0x011D); + const uint8_t enDiv2 = Get_SPI_Reg_bits(EN_DIV2_DIVPROG) + 1; + const uint8_t divLoch = Get_SPI_Reg_bits(DIV_LOCH) + 1; + SPI_write(0x0020, ch); + //Calculate real frequency according to the calculated parameters + return (enDiv2) * (RefClk / pow2(divLoch)) * ((gINT >> 4) + 4 + (gFRAC / 1048576.0)); + } +} + +uint8_t SetFrequencySX(const bool tx, const float_type freq_Hz) +{ + int16_t tuneScore[3] = { 255, 255, 255 }; // best is closest to 0 + const uint16_t macBck = SPI_read(0x0020); + bool canDeliverFrequency = false; + + Modify_SPI_Reg_bits(MAC, tx ? 2 : 1); + //find required VCO frequency + { + float_type VCOfreq; + float_type temp; + { + uint8_t div_loch; + for (div_loch = 7; div_loch; --div_loch) + { + VCOfreq = pow2(div_loch) * freq_Hz; + if ((VCOfreq >= 3800e6) && (VCOfreq <= 7714e6)) + break; + } + Modify_SPI_Reg_bits(DIV_LOCH, div_loch - 1); + } + { + uint32_t fractionalPart; + const uint8_t enDiv2 = (VCOfreq > 5500e6) ? 1 : 0; + Modify_SPI_Reg_bits(EN_DIV2_DIVPROG, enDiv2); //EN_DIV2_DIVPROG + temp = VCOfreq / (RefClk * (1 + enDiv2)); + fractionalPart = (uint32_t)((temp - (uint32_t)(temp)) * 1048576); + + Modify_SPI_Reg_bits(INT_SDM, (uint16_t)(temp - 4)); //INT_SDM + Modify_SPI_Reg_bits(0x011E, MSB_LSB(3, 0), (fractionalPart >> 16)); //FRAC_SDM[19:16] + SPI_write(0x011D, fractionalPart & 0xFFFF); //FRAC_SDM[15:0] + } + } + while (1) + { + uint8_t sel_vco; + uint8_t bestvco = 0; + for (sel_vco = 0; sel_vco < 3; ++sel_vco) + { + Modify_SPI_Reg_bits(SEL_VCO, sel_vco); + if (TuneVCO(1) == MCU_NO_ERROR) + { + tuneScore[sel_vco] = Get_SPI_Reg_bits(CSW_VCO) - 128; + canDeliverFrequency = true; + } + if (abs(tuneScore[sel_vco]) < abs(tuneScore[bestvco])) + bestvco = sel_vco; + } + if (canDeliverFrequency) + { + Modify_SPI_Reg_bits(SEL_VCO, bestvco); + Modify_SPI_Reg_bits(CSW_VCO, tuneScore[bestvco] + 128); + break; + } + { + uint16_t bias = Get_SPI_Reg_bits(ICT_VCO); + if (bias == 255) + break; + Modify_SPI_Reg_bits(ICT_VCO, bias + 32 > 255 ? 255 : bias + 32); + } + } + SPI_write(0x0020, macBck); + if (canDeliverFrequency == false) + return tx ? MCU_SXT_TUNE_FAILED : MCU_SXR_TUNE_FAILED; + return MCU_NO_ERROR; +} + +static uint8_t ReadCMP(const bool SX) +{ #ifdef __cplusplus - #include -void SetDefaults(uint16_t start, uint16_t end) + std::this_thread::sleep_for(std::chrono::microseconds(100)); +#else + TR0 = 0; //stop timer 0 + TH0 = (gComparatorDelayCounter >> 8); + TL0 = (gComparatorDelayCounter & 0xFF); + TF0 = 0; // clear overflow + TR0 = 1; //start timer 0 + while (!TF0) + ; // wait for timer overflow +#endif + return (uint8_t)(Get_SPI_Reg_bits(SX ? 0x0123 : 0x008C, MSB_LSB(13, 12))); +} + +uint8_t TuneVCO(bool SX) // 0-cgen, 1-SXR, 2-SXT { - ROM const uint16_t defaultAddrs[] = { 0x0020, - 0x0021, - 0x0022, - 0x0023, - 0x0024, - 0x0025, - 0x0026, - 0x0027, - 0x0028, - 0x0029, - 0x002A, - 0x002B, - 0x002C, - 0x002E, - 0x002F, - 0x0081, - 0x0082, - 0x0084, - 0x0085, - 0x0086, - 0x0087, - 0x0088, - 0x0089, - 0x008A, - 0x008B, - 0x008C, - 0x0092, - 0x0093, - 0x0094, - 0x0095, - 0x0096, - 0x0097, - 0x0098, - 0x0099, - 0x009A, - 0x009B, - 0x009C, - 0x009D, - 0x009E, - 0x009F, - 0x00A0, - 0x00A1, - 0x00A2, - 0x00A3, - 0x00A4, - 0x00A5, - 0x00A6, - 0x00A7, - 0x00A8, - 0x00AA, - 0x00AB, - 0x00AD, - 0x00AE, - 0x0100, - 0x0101, - 0x0102, - 0x0103, - 0x0104, - 0x0105, - 0x0106, - 0x0107, - 0x0108, - 0x0109, - 0x010A, - 0x010B, - 0x010C, - 0x010D, - 0x010E, - 0x010F, - 0x0110, - 0x0111, + typedef struct { + uint8_t high; + uint8_t low; + uint8_t hasLock; + } CSWInteval; + + uint16_t addrCSW_VCO; + uint8_t msblsb; + + CSWInteval cswSearch[2]; + cswSearch[0].high = 0; //search interval lowest value + cswSearch[0].low = 127; + cswSearch[1].high = 128; + cswSearch[1].low = 255; + cswSearch[1].hasLock = cswSearch[0].hasLock = false; + + if (SX) + { + addrCSW_VCO = 0x0121; + msblsb = MSB_LSB(10, 3); //CSW msb lsb + //assuming the active channel is already correct + Modify_SPI_Reg_bits(0x011C, MSB_LSB(2, 1), 0); //activate VCO and comparator + } + else //CGEN + { + addrCSW_VCO = 0x008B; + msblsb = MSB_LSB(8, 1); //CSW msb lsb + Modify_SPI_Reg_bits(0x0086, MSB_LSB(2, 1), 0); //activate VCO and comparator + } +#ifndef __cplusplus + gComparatorDelayCounter = 0xFFFF - (uint16_t)((0.0009 / 12) * RefClk); // ~900us +#endif + //check if lock is within VCO range + Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, 0); + if (ReadCMP(SX) == 3) //VCO too high + return MCU_ERROR; + Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, 255); + if (ReadCMP(SX) == 0) //VCO too low + return MCU_ERROR; + + //search intervals [0-127][128-255] + { + uint8_t t; + for (t = 0; t < 2; ++t) + { + uint8_t mask; + for (mask = (1 << 6); mask; mask >>= 1) + { + uint8_t cmpValue; + cswSearch[t].high |= mask; // CSW_VCO=1 + Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, cswSearch[t].high); + cmpValue = ReadCMP(SX); + if (cmpValue == 0x03) // reduce CSW + cswSearch[t].high ^= mask; // CSW_VCO=0 + else if (cmpValue == 0x02 && cswSearch[t].high <= cswSearch[t].low) + { + cswSearch[t].hasLock = true; + cswSearch[t].low = cswSearch[t].high; + } + } + for (; cswSearch[t].low; --cswSearch[t].low) + { + Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, cswSearch[t].low); + if (ReadCMP(SX) != 0x2) + { + if (cswSearch[t].low < cswSearch[t].high) + ++cswSearch[t].low; + break; + } + } + } + } + { + uint8_t cswValue; + //compare which interval is wider + { + if (cswSearch[1].hasLock && (cswSearch[1].high - cswSearch[1].low >= cswSearch[0].high - cswSearch[0].low)) + cswValue = cswSearch[1].low + ((cswSearch[1].high - cswSearch[1].low) >> 1); + else + cswValue = cswSearch[0].low + ((cswSearch[0].high - cswSearch[0].low) >> 1); + } + + Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, cswValue); + if (ReadCMP(SX) != 0x2) //just in case high-low==1, if low fails, check if high locks + Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, ++cswValue); + } + if (ReadCMP(SX) == 0x2) + return MCU_NO_ERROR; + return MCU_ERROR; +} + +void WriteMaskedRegs(const RegisterBatch ROM* regs) +{ + uint8_t i; + uint8_t index; + for (i = regs->cnt; i; --i) + { + index = i - 1; + SPI_write(regs->addr[index], (SPI_read(regs->addr[index]) & ~regs->mask[index]) | regs->val[index]); + } + for (i = regs->wrOnlyAddrCnt; i; --i) + { + index = i - 1; + SPI_write(regs->wrOnlyAddr[index], i > regs->wrOnlyDataCnt ? 0 : regs->wrOnlyData[index]); + } +} + +uint8_t GetValueOf_c_ctl_pga_rbb(uint8_t g_pga_rbb) +{ + if (g_pga_rbb < 21) + return 1; + if (g_pga_rbb < 13) + return 2; + if (g_pga_rbb < 8) + return 3; + return 0; +} + +void EnableChannelPowerControls() +{ + uint16_t afe = SPI_read(0x0082); + uint16_t value = SPI_read(0x0020); + if ((value & 3) == 1) + { + value = value | 0x0014; + afe &= ~0x14; + } + else + { + value = value | 0x0028; + afe &= ~0x0A; + } + SPI_write(0x0020, value); + SPI_write(0x0082, afe); +} + +void EnableMIMOBuffersIfNecessary() +{ + //modifications when calibrating channel B + uint16_t x0020val = SPI_read(0x0020); + if ((x0020val & 0x3) == 2) + { + Modify_SPI_Reg_bits(MAC, 1); + Modify_SPI_Reg_bits(EN_NEXTRX_RFE, 1); + Modify_SPI_Reg_bits(EN_NEXTTX_TRF, 1); + SPI_write(0x0020, x0020val); + } +} + +#ifdef __cplusplus +} // extern C +#endif + +void SetDefaults(uint16_t start, uint16_t end) +{ + ROM const uint16_t defaultAddrs[] = { 0x0020, + 0x0021, + 0x0022, + 0x0023, + 0x0024, + 0x0025, + 0x0026, + 0x0027, + 0x0028, + 0x0029, + 0x002A, + 0x002B, + 0x002C, + 0x002E, + 0x002F, + 0x0081, + 0x0082, + 0x0084, + 0x0085, + 0x0086, + 0x0087, + 0x0088, + 0x0089, + 0x008A, + 0x008B, + 0x008C, + 0x0092, + 0x0093, + 0x0094, + 0x0095, + 0x0096, + 0x0097, + 0x0098, + 0x0099, + 0x009A, + 0x009B, + 0x009C, + 0x009D, + 0x009E, + 0x009F, + 0x00A0, + 0x00A1, + 0x00A2, + 0x00A3, + 0x00A4, + 0x00A5, + 0x00A6, + 0x00A7, + 0x00A8, + 0x00AA, + 0x00AB, + 0x00AD, + 0x00AE, + 0x0100, + 0x0101, + 0x0102, + 0x0103, + 0x0104, + 0x0105, + 0x0106, + 0x0107, + 0x0108, + 0x0109, + 0x010A, + 0x010B, + 0x010C, + 0x010D, + 0x010E, + 0x010F, + 0x0110, + 0x0111, 0x0112, 0x0113, 0x0114, @@ -509,7 +844,7 @@ void SetDefaults(uint16_t start, uint16_t end) 0x0000, 0x00A0, 0x1020 }; - #ifdef __cplusplus +#ifdef __cplusplus //int status = 0; std::vector addrs; std::vector values; @@ -527,338 +862,7 @@ void SetDefaults(uint16_t start, uint16_t end) } } SPI_write_batch(addrs.data(), values.data(), addrs.size()); - #else +#else - #endif -} #endif -void SetDefaultsSX() -{ - ROM const uint16_t SXAddr[] = { 0x011C, 0x011D, 0x011E, 0x011F, 0x0121, 0x0122, 0x0123 }; - ROM const uint16_t SXdefVals[] = { 0xAD43, 0x0400, 0x0780, 0x3640, 0x3404, 0x033F, 0x067B }; - - uint8_t i; - for (i = sizeof(SXAddr) / sizeof(uint16_t); i; --i) - SPI_write(SXAddr[i - 1], SXdefVals[i - 1]); - //keep 0x0120[7:0]ICT_VCO bias value intact - Modify_SPI_Reg_bits(0x0120, MSB_LSB(15, 8), 0xB9FF); -} - -void ClockLogicResets() -{ - //MCLK2 toggle - uint16_t reg = SPI_read(0x002B); - SPI_write(0x002B, reg ^ (1 << 9)); - SPI_write(0x002B, reg); - - //TSP logic reset - reg = SPI_read(0x0020); - SPI_write(0x0020, reg & ~0xAA00); - SPI_write(0x0020, reg); -} - -float_type GetFrequencyCGEN() -{ - const float_type dMul = (RefClk / 2.0) / (Get_SPI_Reg_bits(DIV_OUTCH_CGEN) + 1); //DIV_OUTCH_CGEN - const uint16_t gINT = Get_SPI_Reg_bits(0x0088, MSB_LSB(13, 0)); //read whole register to reduce SPI transfers - const uint32_t gFRAC = ((uint32_t)(gINT & 0xF) << 16) | Get_SPI_Reg_bits(0x0087, MSB_LSB(15, 0)); - return dMul * (((gINT >> 4) + 1 + gFRAC / 1048576.0)); -} - -uint8_t SetFrequencyCGEN(float_type freq) -{ - float_type dFvco; - float_type intpart; - //VCO frequency selection according to F_CLKH - { - uint8_t iHdiv_high = (2.94e9 / 2 / freq) - 1; - uint8_t iHdiv_low = (1.93e9 / 2 / freq); - uint8_t iHdiv = (iHdiv_low + iHdiv_high) / 2; - dFvco = 2 * (iHdiv + 1) * freq; - Modify_SPI_Reg_bits(DIV_OUTCH_CGEN, iHdiv); - } - //Integer division - intpart = dFvco / RefClk; - Modify_SPI_Reg_bits(INT_SDM_CGEN, intpart - 1); //INT_SDM_CGEN - //Fractional division - { - const float_type dFrac = intpart - (uint32_t)(dFvco / RefClk); - const uint32_t gFRAC = (uint32_t)(dFrac * 1048576); - Modify_SPI_Reg_bits(0x0087, MSB_LSB(15, 0), gFRAC & 0xFFFF); //INT_SDM_CGEN[15:0] - Modify_SPI_Reg_bits(0x0088, MSB_LSB(3, 0), gFRAC >> 16); //INT_SDM_CGEN[19:16] - } - -#if VERBOSE - //printf("CGEN: Freq=%g MHz, VCO=%g GHz, INT=%i, FRAC=%i, DIV_OUTCH_CGEN=%i\n", freq/1e6, dFvco/1e9, gINT, gFRAC, iHdiv); -#endif // NDEBUG - if (TuneVCO(VCO_CGEN) != 0) - return MCU_CGEN_TUNE_FAILED; - return 0; -} - -float_type GetReferenceClk_TSP_MHz(bool tx) -{ - const float_type cgenFreq = GetFrequencyCGEN(); - const float_type clklfreq = cgenFreq / pow2(Get_SPI_Reg_bits(CLKH_OV_CLKL_CGEN)); - if (Get_SPI_Reg_bits(EN_ADCCLKH_CLKGN) == 0) - return tx ? clklfreq : cgenFreq / 4; - else - return tx ? cgenFreq : clklfreq / 4; -} - -void SetNCOFrequency(const bool tx, const float freq, uint8_t index) -{ - const uint16_t addr = (tx ? 0x0242 : 0x0442) + index * 2; - const uint32_t fcw = (uint32_t)((freq / GetReferenceClk_TSP_MHz(tx)) * 4294967296.0); - SPI_write(addr, (fcw >> 16)); //NCO frequency control word register MSB part. - SPI_write(addr + 1, fcw); //NCO frequency control word register LSB part. -} - -float_type GetFrequencySX(const bool Tx) -{ - const uint16_t ch = SPI_read(0x0020); //(uint8_t)Get_SPI_Reg_bits(MAC); //remember previously used channel - Modify_SPI_Reg_bits(MAC, Tx ? 2 : 1); // Rx mac = 1, Tx mac = 2 - { - const uint16_t gINT = Get_SPI_Reg_bits(0x011E, MSB_LSB(13, 0)); // read whole register to reduce SPI transfers - const uint32_t gFRAC = ((uint32_t)(gINT & 0xF) << 16) | SPI_read(0x011D); - const uint8_t enDiv2 = Get_SPI_Reg_bits(EN_DIV2_DIVPROG) + 1; - const uint8_t divLoch = Get_SPI_Reg_bits(DIV_LOCH) + 1; - SPI_write(0x0020, ch); - //Calculate real frequency according to the calculated parameters - return (enDiv2) * (RefClk / pow2(divLoch)) * ((gINT >> 4) + 4 + (gFRAC / 1048576.0)); - } -} - -uint8_t SetFrequencySX(const bool tx, const float_type freq_Hz) -{ - int16_t tuneScore[3] = { 255, 255, 255 }; // best is closest to 0 - const uint16_t macBck = SPI_read(0x0020); - bool canDeliverFrequency = false; - - Modify_SPI_Reg_bits(MAC, tx ? 2 : 1); - //find required VCO frequency - { - float_type VCOfreq; - float_type temp; - { - uint8_t div_loch; - for (div_loch = 7; div_loch; --div_loch) - { - VCOfreq = pow2(div_loch) * freq_Hz; - if ((VCOfreq >= 3800e6) && (VCOfreq <= 7714e6)) - break; - } - Modify_SPI_Reg_bits(DIV_LOCH, div_loch - 1); - } - { - uint32_t fractionalPart; - const uint8_t enDiv2 = (VCOfreq > 5500e6) ? 1 : 0; - Modify_SPI_Reg_bits(EN_DIV2_DIVPROG, enDiv2); //EN_DIV2_DIVPROG - temp = VCOfreq / (RefClk * (1 + enDiv2)); - fractionalPart = (uint32_t)((temp - (uint32_t)(temp)) * 1048576); - - Modify_SPI_Reg_bits(INT_SDM, (uint16_t)(temp - 4)); //INT_SDM - Modify_SPI_Reg_bits(0x011E, MSB_LSB(3, 0), (fractionalPart >> 16)); //FRAC_SDM[19:16] - SPI_write(0x011D, fractionalPart & 0xFFFF); //FRAC_SDM[15:0] - } - } - while (1) - { - uint8_t sel_vco; - uint8_t bestvco = 0; - for (sel_vco = 0; sel_vco < 3; ++sel_vco) - { - Modify_SPI_Reg_bits(SEL_VCO, sel_vco); - if (TuneVCO(1) == MCU_NO_ERROR) - { - tuneScore[sel_vco] = Get_SPI_Reg_bits(CSW_VCO) - 128; - canDeliverFrequency = true; - } - if (abs(tuneScore[sel_vco]) < abs(tuneScore[bestvco])) - bestvco = sel_vco; - } - if (canDeliverFrequency) - { - Modify_SPI_Reg_bits(SEL_VCO, bestvco); - Modify_SPI_Reg_bits(CSW_VCO, tuneScore[bestvco] + 128); - break; - } - { - uint16_t bias = Get_SPI_Reg_bits(ICT_VCO); - if (bias == 255) - break; - Modify_SPI_Reg_bits(ICT_VCO, bias + 32 > 255 ? 255 : bias + 32); - } - } - SPI_write(0x0020, macBck); - if (canDeliverFrequency == false) - return tx ? MCU_SXT_TUNE_FAILED : MCU_SXR_TUNE_FAILED; - return MCU_NO_ERROR; -} - -static uint8_t ReadCMP(const bool SX) -{ -#ifdef __cplusplus - std::this_thread::sleep_for(std::chrono::microseconds(100)); -#else - TR0 = 0; //stop timer 0 - TH0 = (gComparatorDelayCounter >> 8); - TL0 = (gComparatorDelayCounter & 0xFF); - TF0 = 0; // clear overflow - TR0 = 1; //start timer 0 - while (!TF0) - ; // wait for timer overflow -#endif - return (uint8_t)Get_SPI_Reg_bits(SX ? 0x0123 : 0x008C, MSB_LSB(13, 12)); -} - -uint8_t TuneVCO(bool SX) // 0-cgen, 1-SXR, 2-SXT -{ - typedef struct { - uint8_t high; - uint8_t low; - uint8_t hasLock; - } CSWInteval; - - uint16_t addrCSW_VCO; - uint8_t msblsb; - - CSWInteval cswSearch[2]; - cswSearch[0].high = 0; //search interval lowest value - cswSearch[0].low = 127; - cswSearch[1].high = 128; - cswSearch[1].low = 255; - cswSearch[1].hasLock = cswSearch[0].hasLock = false; - - if (SX) - { - addrCSW_VCO = 0x0121; - msblsb = MSB_LSB(10, 3); //CSW msb lsb - //assuming the active channel is already correct - Modify_SPI_Reg_bits(0x011C, MSB_LSB(2, 1), 0); //activate VCO and comparator - } - else //CGEN - { - addrCSW_VCO = 0x008B; - msblsb = MSB_LSB(8, 1); //CSW msb lsb - Modify_SPI_Reg_bits(0x0086, MSB_LSB(2, 1), 0); //activate VCO and comparator - } -#ifndef __cplusplus - gComparatorDelayCounter = 0xFFFF - (uint16_t)((0.0009 / 12) * RefClk); // ~900us -#endif - //check if lock is within VCO range - Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, 0); - if (ReadCMP(SX) == 3) //VCO too high - return MCU_ERROR; - Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, 255); - if (ReadCMP(SX) == 0) //VCO too low - return MCU_ERROR; - - //search intervals [0-127][128-255] - { - uint8_t t; - for (t = 0; t < 2; ++t) - { - uint8_t mask; - for (mask = (1 << 6); mask; mask >>= 1) - { - uint8_t cmpValue; - cswSearch[t].high |= mask; // CSW_VCO=1 - Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, cswSearch[t].high); - cmpValue = ReadCMP(SX); - if (cmpValue == 0x03) // reduce CSW - cswSearch[t].high ^= mask; // CSW_VCO=0 - else if (cmpValue == 0x02 && cswSearch[t].high <= cswSearch[t].low) - { - cswSearch[t].hasLock = true; - cswSearch[t].low = cswSearch[t].high; - } - } - for (; cswSearch[t].low; --cswSearch[t].low) - { - Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, cswSearch[t].low); - if (ReadCMP(SX) != 0x2) - { - if (cswSearch[t].low < cswSearch[t].high) - ++cswSearch[t].low; - break; - } - } - } - } - { - uint8_t cswValue; - //compare which interval is wider - { - if (cswSearch[1].hasLock && (cswSearch[1].high - cswSearch[1].low >= cswSearch[0].high - cswSearch[0].low)) - cswValue = cswSearch[1].low + ((cswSearch[1].high - cswSearch[1].low) >> 1); - else - cswValue = cswSearch[0].low + ((cswSearch[0].high - cswSearch[0].low) >> 1); - } - - Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, cswValue); - if (ReadCMP(SX) != 0x2) //just in case high-low==1, if low fails, check if high locks - Modify_SPI_Reg_bits(addrCSW_VCO, msblsb, ++cswValue); - } - if (ReadCMP(SX) == 0x2) - return MCU_NO_ERROR; - return MCU_ERROR; -} - -void WriteMaskedRegs(const RegisterBatch ROM* regs) -{ - uint8_t i; - uint8_t index; - for (i = regs->cnt; i; --i) - { - index = i - 1; - SPI_write(regs->addr[index], (SPI_read(regs->addr[index]) & ~regs->mask[index]) | regs->val[index]); - } - for (i = regs->wrOnlyAddrCnt; i; --i) - { - index = i - 1; - SPI_write(regs->wrOnlyAddr[index], i > regs->wrOnlyDataCnt ? 0 : regs->wrOnlyData[index]); - } -} - -uint8_t GetValueOf_c_ctl_pga_rbb(uint8_t g_pga_rbb) -{ - if (g_pga_rbb < 21) - return 1; - if (g_pga_rbb < 13) - return 2; - if (g_pga_rbb < 8) - return 3; - return 0; -} - -void EnableChannelPowerControls() -{ - uint16_t afe = SPI_read(0x0082); - uint16_t value = SPI_read(0x0020); - if ((value & 3) == 1) - { - value = value | 0x0014; - afe &= ~0x14; - } - else - { - value = value | 0x0028; - afe &= ~0x0A; - } - SPI_write(0x0020, value); - SPI_write(0x0082, afe); -} - -void EnableMIMOBuffersIfNecessary() -{ - //modifications when calibrating channel B - uint16_t x0020val = SPI_read(0x0020); - if ((x0020val & 0x3) == 2) - { - Modify_SPI_Reg_bits(MAC, 1); - Modify_SPI_Reg_bits(EN_NEXTRX_RFE, 1); - Modify_SPI_Reg_bits(EN_NEXTTX_TRF, 1); - SPI_write(0x0020, x0020val); - } } diff --git a/src/mcu_program/common_src/lms7002m_filters.c b/src/mcu_program/common_src/lms7002m_filters.c index e655d951a..0510aa2da 100644 --- a/src/mcu_program/common_src/lms7002m_filters.c +++ b/src/mcu_program/common_src/lms7002m_filters.c @@ -6,6 +6,10 @@ #include #include "mcu_defines.h" +#ifdef __cplusplus +extern "C" { +#endif + enum { SEARCH_SUCCESS = 0, SEARCH_NEED_TO_DECREASE, SEARCH_NEED_TO_INCREASE }; //rx lpf range limits @@ -20,14 +24,14 @@ static ROM const float_type TxLPF_RF_LimitHigh = 130e6; static uint8_t ConfigCGEN_ForLPF_IF(float IF_Hz) { - uint8_t cgenMultiplier = clamp(IF_Hz * 20 / 46.08e6 + 0.5, 2, 13); + uint8_t cgenMultiplier = clamp(round(IF_Hz * 20 / 46.08e6), 2, 13); return SetFrequencyCGEN(46.08e6 * cgenMultiplier + 10e6); } static uint8_t RxFilterSearch(const uint16_t addr, const uint8_t msblsb, const uint16_t rssi_3dB, const uint16_t stepLimit) { const bool doDecrement = GetRSSI() < rssi_3dB; - int16_t value = Get_SPI_Reg_bits(addr, msblsb); + uint16_t value = Get_SPI_Reg_bits(addr, msblsb); const uint16_t maxValue = pow2((msblsb >> 4) - (msblsb & 0xF) + 1) - 1; uint16_t stepSize = 1; while (1) @@ -805,7 +809,7 @@ static uint8_t SearchTxFilterCCAL_RCAL(uint16_t addr, uint8_t msblsb) else if (needToChangeCCAL) { uint8_t ccal_lpflad_tbb = Get_SPI_Reg_bits(CCAL_LPFLAD_TBB); - ccal_lpflad_tbb = clamp(++ccal_lpflad_tbb, 0, 31); + ccal_lpflad_tbb = clamp(ccal_lpflad_tbb + 1, 0, 31); Modify_SPI_Reg_bits(CCAL_LPFLAD_TBB, ccal_lpflad_tbb); } --iterationsLeft; @@ -861,3 +865,7 @@ TxFilterSearchEndStage : { return MCU_NO_ERROR; } + +#ifdef __cplusplus +} +#endif diff --git a/src/mcu_program/common_src/lms7002m_filters.h b/src/mcu_program/common_src/lms7002m_filters.h index 68e36cf71..9d59019e5 100644 --- a/src/mcu_program/common_src/lms7002m_filters.h +++ b/src/mcu_program/common_src/lms7002m_filters.h @@ -3,7 +3,15 @@ #include "typedefs.h" +#ifdef __cplusplus +extern "C" { +#endif + uint8_t TuneTxFilter(const float_type bandwidth); uint8_t TuneRxFilter(const float_type rx_lpf_freq_RF); +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/mcu_program/spi.cpp b/src/mcu_program/spi.cpp index 24590a6b1..e2f8f2e1e 100644 --- a/src/mcu_program/spi.cpp +++ b/src/mcu_program/spi.cpp @@ -5,8 +5,8 @@ static lime::LMS7002M* serPort; -extern float bandwidthRF; -extern float RefClk; +extern "C" float bandwidthRF; +extern "C" float RefClk; void SetupCalibrations(lime::LMS7002M* chip, double BW) { diff --git a/src/oglGraph/GLFont.cpp b/src/oglGraph/GLFont.cpp index 4c6e25b40..cf638f1c5 100644 --- a/src/oglGraph/GLFont.cpp +++ b/src/oglGraph/GLFont.cpp @@ -6,6 +6,18 @@ #include using namespace std; +static constexpr bool IsGlew1_5() +{ +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wold-style-cast" +#endif + return GLEW_VERSION_1_5; +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif +} + /** @brief Construct a new GLFont::GLFont object */ GLFont::GLFont() : m_texID(0) @@ -67,25 +79,25 @@ bool GLFont::load(const char* file) in.read(reserved, 16); unsigned char fontSize = 0; - in.read((char*)&fontSize, 1); + in.read(reinterpret_cast(&fontSize), sizeof(fontSize)); m_fontSize = fontSize; unsigned short glyphCount = 0; - in.read((char*)&glyphCount, 2); + in.read(reinterpret_cast(&glyphCount), sizeof(glyphCount)); for (int i = 0; i < m_glyphCount; ++i) m_glyphs[i].reset(); GLGlyph tempGlyph; for (unsigned int i = 0; i < glyphCount; ++i) { - in.read((char*)&tempGlyph.id, sizeof(unsigned short)); - in.read((char*)&tempGlyph.width, sizeof(unsigned short)); - in.read((char*)&tempGlyph.height, sizeof(unsigned short)); - in.read((char*)&tempGlyph.u, sizeof(unsigned short)); - in.read((char*)&tempGlyph.v, sizeof(unsigned short)); - in.read((char*)&tempGlyph.offset_x, sizeof(short)); - in.read((char*)&tempGlyph.offset_y, sizeof(short)); - in.read((char*)&tempGlyph.advance_x, sizeof(short)); + in.read(reinterpret_cast(&tempGlyph.id), sizeof(tempGlyph.id)); + in.read(reinterpret_cast(&tempGlyph.width), sizeof(tempGlyph.width)); + in.read(reinterpret_cast(&tempGlyph.height), sizeof(tempGlyph.height)); + in.read(reinterpret_cast(&tempGlyph.u), sizeof(tempGlyph.u)); + in.read(reinterpret_cast(&tempGlyph.v), sizeof(tempGlyph.v)); + in.read(reinterpret_cast(&tempGlyph.offset_x), sizeof(tempGlyph.offset_x)); + in.read(reinterpret_cast(&tempGlyph.offset_y), sizeof(tempGlyph.offset_y)); + in.read(reinterpret_cast(&tempGlyph.advance_x), sizeof(tempGlyph.advance_x)); tempGlyph.advance_x = tempGlyph.advance_x >> 6; m_glyphs[tempGlyph.id] = tempGlyph; } @@ -94,14 +106,15 @@ bool GLFont::load(const char* file) unsigned short texHeight = 0; char bpp = 0; - in.read((char*)&texWidth, sizeof(unsigned short)); + in.read(reinterpret_cast(&texWidth), sizeof(texWidth)); m_texwidth = texWidth; - in.read((char*)&texHeight, sizeof(unsigned short)); + in.read(reinterpret_cast(&texHeight), sizeof(texHeight)); m_texheight = texHeight; - in.read(&bpp, sizeof(char)); + in.read(&bpp, sizeof(bpp)); - unsigned char* bitmap = new unsigned char[texWidth * texHeight]; - in.read((char*)bitmap, texWidth * texHeight); + const int bitmapSize = texWidth * texHeight; + unsigned char* bitmap = new unsigned char[bitmapSize]; + in.read(reinterpret_cast(bitmap), bitmapSize); in.close(); glEnable(GL_TEXTURE_2D); @@ -118,7 +131,7 @@ bool GLFont::load(const char* file) glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, texWidth, texHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap); glBindTexture(GL_TEXTURE_2D, 0); - if (!m_vboID && GLEW_VERSION_1_5) + if (!m_vboID && IsGlew1_5()) { glGenBuffers(1, &m_vboID); glBindBuffer(GL_ARRAY_BUFFER, m_vboID); @@ -157,25 +170,25 @@ bool GLFont::loadFromArray(const char* array, unsigned int size) in.read(reserved, 16); unsigned char fontSize = 0; - in.read((char*)&fontSize, 1); + in.read(reinterpret_cast(&fontSize), sizeof(fontSize)); m_fontSize = fontSize; unsigned short glyphCount = 0; - in.read((char*)&glyphCount, 2); + in.read(reinterpret_cast(&glyphCount), sizeof(glyphCount)); for (int i = 0; i < m_glyphCount; ++i) m_glyphs[i].reset(); GLGlyph tempGlyph; for (unsigned int i = 0; i < glyphCount; ++i) { - in.read((char*)&tempGlyph.id, sizeof(unsigned short)); - in.read((char*)&tempGlyph.width, sizeof(unsigned short)); - in.read((char*)&tempGlyph.height, sizeof(unsigned short)); - in.read((char*)&tempGlyph.u, sizeof(unsigned short)); - in.read((char*)&tempGlyph.v, sizeof(unsigned short)); - in.read((char*)&tempGlyph.offset_x, sizeof(short)); - in.read((char*)&tempGlyph.offset_y, sizeof(short)); - in.read((char*)&tempGlyph.advance_x, sizeof(short)); + in.read(reinterpret_cast(&tempGlyph.id), sizeof(tempGlyph.id)); + in.read(reinterpret_cast(&tempGlyph.width), sizeof(tempGlyph.width)); + in.read(reinterpret_cast(&tempGlyph.height), sizeof(tempGlyph.height)); + in.read(reinterpret_cast(&tempGlyph.u), sizeof(tempGlyph.u)); + in.read(reinterpret_cast(&tempGlyph.v), sizeof(tempGlyph.v)); + in.read(reinterpret_cast(&tempGlyph.offset_x), sizeof(tempGlyph.offset_x)); + in.read(reinterpret_cast(&tempGlyph.offset_y), sizeof(tempGlyph.offset_y)); + in.read(reinterpret_cast(&tempGlyph.advance_x), sizeof(tempGlyph.advance_x)); tempGlyph.advance_x = tempGlyph.advance_x >> 6; m_glyphs[tempGlyph.id] = tempGlyph; } @@ -184,14 +197,15 @@ bool GLFont::loadFromArray(const char* array, unsigned int size) unsigned short texHeight = 0; char bpp = 0; - in.read((char*)&texWidth, sizeof(unsigned short)); + in.read(reinterpret_cast(&texWidth), sizeof(texWidth)); m_texwidth = texWidth; - in.read((char*)&texHeight, sizeof(unsigned short)); + in.read(reinterpret_cast(&texHeight), sizeof(texHeight)); m_texheight = texHeight; - in.read(&bpp, sizeof(char)); + in.read(&bpp, sizeof(bpp)); - unsigned char* bitmap = new unsigned char[texWidth * texHeight]; - in.read((char*)bitmap, texWidth * texHeight); + const int bitmapSize = texWidth * texHeight; + unsigned char* bitmap = new unsigned char[bitmapSize]; + in.read(reinterpret_cast(bitmap), bitmapSize); glEnable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); @@ -207,7 +221,7 @@ bool GLFont::loadFromArray(const char* array, unsigned int size) glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, texWidth, texHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap); glBindTexture(GL_TEXTURE_2D, 0); - if (!m_vboID && GLEW_VERSION_1_5) + if (!m_vboID && IsGlew1_5()) { glGenBuffers(1, &m_vboID); glBindBuffer(GL_ARRAY_BUFFER, m_vboID); @@ -244,17 +258,19 @@ void GLFont::render_textWorldSpace(const char* text, float x, float y, float fon GLGlyph* g = NULL; glBindTexture(GL_TEXTURE_2D, m_texID); - if (GLEW_VERSION_1_5) + if (IsGlew1_5()) + { glBindBuffer(GL_ARRAY_BUFFER, m_vboID); + } glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glVertexPointer(2, GL_FLOAT, 4 * sizeof(float), (char*)0); - glTexCoordPointer(2, GL_FLOAT, 4 * sizeof(float), (char*)0 + 2 * sizeof(float)); + glVertexPointer(2, GL_FLOAT, 4 * sizeof(float), static_cast(0)); + glTexCoordPointer(2, GL_FLOAT, 4 * sizeof(float), static_cast(0) + 2 * sizeof(float)); const char* p; for (p = text; *p; ++p) { - g = &m_glyphs[(unsigned char)*p]; - if ((char)*p == '\n') + g = &m_glyphs[static_cast(*p)]; + if (*p == '\n') { x = startx; y = y - lineHeight() * scale; @@ -282,7 +298,7 @@ void GLFont::render_textWorldSpace(const char* text, float x, float y, float fon vbodata[14] = vbodata[6]; vbodata[15] = vbodata[11]; - // if(GLEW_VERSION_1_5) + // if(IsGlew1_5()) // { // glBufferData( GL_ARRAY_BUFFER, 16*sizeof(float), NULL, GL_DYNAMIC_DRAW ); // glBufferData( GL_ARRAY_BUFFER, 16*sizeof(float), vbodata, GL_DYNAMIC_DRAW ); @@ -335,17 +351,19 @@ void GLFont::render_textScreenSpace(const char* text, float x, float y, float fo GLGlyph* g = NULL; glBindTexture(GL_TEXTURE_2D, m_texID); - if (GLEW_VERSION_1_5) + if (IsGlew1_5()) + { glBindBuffer(GL_ARRAY_BUFFER, m_vboID); + } glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glVertexPointer(2, GL_FLOAT, 4 * sizeof(float), (char*)0); - glTexCoordPointer(2, GL_FLOAT, 4 * sizeof(float), (char*)0 + 2 * sizeof(float)); + glVertexPointer(2, GL_FLOAT, 4 * sizeof(float), 0); + glTexCoordPointer(2, GL_FLOAT, 4 * sizeof(float), static_cast(0) + 2 * sizeof(float)); const char* p; for (p = text; *p; ++p) { - g = &m_glyphs[(unsigned char)*p]; - if ((char)*p == '\n') + g = &m_glyphs[static_cast(*p)]; + if (*p == '\n') { x = startx; y = y + lineHeight() * scale; @@ -374,7 +392,7 @@ void GLFont::render_textScreenSpace(const char* text, float x, float y, float fo vbodata[14] = vbodata[6]; vbodata[15] = vbodata[11]; - // if(GLEW_VERSION_1_5) + // if(IsGlew1_5()) // { // glBufferData( GL_ARRAY_BUFFER, 16*sizeof(float), (char*)0, GL_DYNAMIC_DRAW ); // glBufferData( GL_ARRAY_BUFFER, 16*sizeof(float), vbodata, GL_DYNAMIC_DRAW ); @@ -414,17 +432,17 @@ unsigned int GLFont::lineHeight() const } /** - @brief Gets the width of a given character. + @brief Gets the width of a given character. @param c The character to get the width of. @return The width of @p c . */ unsigned int GLFont::char_width(const char c) const { - return m_glyphs[(unsigned char)c].advance_x; + return m_glyphs[static_cast(c)].advance_x; } /** - @brief Gets the width of a given string. + @brief Gets the width of a given string. @param str The string to get the width of. @return The width of @p str . */ @@ -432,7 +450,7 @@ unsigned int GLFont::string_width(const char* str) const { unsigned int width = 0; for (unsigned int i = 0; i < strlen(str); ++i) - width += m_glyphs[(unsigned char)str[i]].advance_x; + width += m_glyphs[static_cast(str[i])].advance_x; return width; } @@ -454,10 +472,10 @@ void GLFont::getTextSize(const char* str, int& width, int& height, float fontSiz for (int i = 0; i < len; ++i) { if (i > len - 1) - width += m_glyphs[(unsigned char)str[i]].width; + width += m_glyphs[static_cast(str[i])].width; else - width += m_glyphs[(unsigned char)str[i]].advance_x; - glyphH = m_glyphs[(unsigned char)str[i]].height; + width += m_glyphs[static_cast(str[i])].advance_x; + glyphH = m_glyphs[static_cast(str[i])].height; if (glyphH > height) height = glyphH; } diff --git a/src/oglGraph/OpenGLGraph.cpp b/src/oglGraph/OpenGLGraph.cpp index 345e120f0..eb5a353a9 100644 --- a/src/oglGraph/OpenGLGraph.cpp +++ b/src/oglGraph/OpenGLGraph.cpp @@ -32,6 +32,18 @@ const int OpenGLGraph::GLCanvasAttributes[8] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_DEPTH_SIZE, 16, WX_GL_STENCIL_SIZE, 0, 0, 0 }; +static constexpr bool IsGlew1_5() +{ +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wold-style-cast" +#endif + return GLEW_VERSION_1_5; +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif +} + GLG_settings::GLG_settings() : title("") , titleXaxis("") @@ -173,7 +185,7 @@ bool OpenGLGraph::Initialize(int width, int height) } char userOGLversion[255]; - strcpy(userOGLversion, (const char*)glGetString(GL_VERSION)); + strcpy(userOGLversion, reinterpret_cast(glGetString(GL_VERSION))); oglOk = glewIsSupported("GL_VERSION_2_0"); @@ -207,7 +219,7 @@ bool OpenGLGraph::Initialize(int width, int height) initialized = true; m_font = new GLFont(); - m_font->loadFromArray((const char*)standardStaticFont, sizeof(standardStaticFont)); + m_font->loadFromArray(reinterpret_cast(standardStaticFont), sizeof(standardStaticFont)); return true; } @@ -594,8 +606,8 @@ void OpenGLGraph::CalculateGrid() } while (interval / divisor > 10 * xlines) divisor *= 10; - settings.gridXspacing = divisor * mult[int(0.5f + interval / xlines / divisor)]; - settings.gridXstart = (int)(settings.visibleArea.x1 / settings.gridXspacing) * settings.gridXspacing; + settings.gridXspacing = divisor * mult[static_cast(0.5f + interval / xlines / divisor)]; + settings.gridXstart = static_cast(settings.visibleArea.x1 / settings.gridXspacing) * settings.gridXspacing; } else settings.gridXspacing = interval; @@ -614,8 +626,8 @@ void OpenGLGraph::CalculateGrid() } while (interval / divisor > 10 * ylines) divisor *= 10; - settings.gridYspacing = divisor * mult[int(0.5f + interval / ylines / divisor)]; - settings.gridYstart = (int)(settings.visibleArea.y1 / settings.gridYspacing) * settings.gridYspacing; + settings.gridYspacing = divisor * mult[static_cast(0.5f + interval / ylines / divisor)]; + settings.gridYstart = static_cast(settings.visibleArea.y1 / settings.gridYspacing) * settings.gridYspacing; } else settings.gridYspacing = interval; @@ -683,7 +695,8 @@ void OpenGLGraph::Draw() //draw series data switchToDataView(); - if (settings.useVBO && GLEW_VERSION_1_5) + + if (settings.useVBO && IsGlew1_5()) { for (unsigned int i = 0; i < series.size(); i++) { @@ -1030,8 +1043,8 @@ void OpenGLGraph::OnMouseMove(int X, int Y) m_MouseCoord.y2 = Y; spanx = settings.visibleArea.x2 - settings.visibleArea.x1; spany = settings.visibleArea.y2 - settings.visibleArea.y1; - sx = 1 + ((float)(m_MouseCoord.x1 - m_MouseCoord.x2)) / settings.dataViewWidth; - sy = 1 + ((float)(m_MouseCoord.y1 - m_MouseCoord.y2)) / settings.dataViewHeight; + sx = 1 + static_cast(m_MouseCoord.x1 - m_MouseCoord.x2) / settings.dataViewWidth; + sy = 1 + static_cast(m_MouseCoord.y1 - m_MouseCoord.y2) / settings.dataViewHeight; Zoom(settings.visibleArea.x1 + spanx / 2, settings.visibleArea.y1 + spany / 2, m_lastSpanX * sx, m_lastSpanY * sy); break; default: @@ -1673,7 +1686,7 @@ bool OpenGLGraph::SearchPeak() void OpenGLGraph::SetMarker(int id, float xValue, bool enabled, bool show) { - if (id >= 0 && id < (int)markers.size()) + if (id >= 0 && id < static_cast(markers.size())) { ChangeMarker(id, xValue); markers[id].used = enabled; @@ -1683,7 +1696,7 @@ void OpenGLGraph::SetMarker(int id, float xValue, bool enabled, bool show) void OpenGLGraph::GetMarker(int id, float& xValue, float& yValue, bool& enabled, bool& show) { - if (id >= 0 && id < (int)markers.size()) + if (id >= 0 && id < static_cast(markers.size())) { xValue = markers[id].posX; yValue = markers[id].posY; diff --git a/src/oglGraph/OpenGLGraph.h b/src/oglGraph/OpenGLGraph.h index 24aa2dfe0..b8ecdb452 100644 --- a/src/oglGraph/OpenGLGraph.h +++ b/src/oglGraph/OpenGLGraph.h @@ -86,10 +86,10 @@ struct GLG_color { unsigned int getColor4b() { unsigned int color = 0; - color |= (unsigned int)(255 * red) << 24; - color |= (unsigned int)(255 * green) << 16; - color |= (unsigned int)(255 * blue) << 8; - color |= (unsigned int)(255 * alpha); + color |= static_cast(255 * red) << 24; + color |= static_cast(255 * green) << 16; + color |= static_cast(255 * blue) << 8; + color |= static_cast(255 * alpha); return color; } diff --git a/src/oglGraph/StaticFontHeader.h b/src/oglGraph/StaticFontHeader.h index 74eb20237..e6be3c55a 100644 --- a/src/oglGraph/StaticFontHeader.h +++ b/src/oglGraph/StaticFontHeader.h @@ -1,7 +1,8 @@ #ifndef STATIC_FONT_HEADER_H #define STATIC_FONT_HEADER_H +// clang-format off const unsigned char standardStaticFont[] = {79,112,101,110,71,76,32,70,111,110,116,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,96,0,32,0,0,0,0,0,5,0,25,0,0,0,0,0,192,1,33,0,1,0,8,0,4,0,48,0,3,0,8,0,192,1,34,0,3,0,3,0,0,0,60,0,2,0,9,0,192,1,35,0,7,0,8,0,37,0,0,0,0,0,8,0,192,1,36,0,5,0,9,0,23,0,0,0,1,0,8,0,192,1,37,0,7,0,8,0,29,0,54,0,0,0,8,0,192,1,38,0,6,0,8,0,52,0,18,0,1,0,8,0,192,1,39,0,1,0,3,0,4,0,60,0,3,0,9,0,192,1,40,0,3,0,11,0,6,0,12,0,2,0,9,0,192,1,41,0,3,0,11,0,6,0,0,0,2,0,9,0,192,1,42,0,5,0,5,0,65,0,41,0,1,0,6,0,192,1,43,0,5,0,5,0,65,0,35,0,1,0,6,0,192,1,44,0,2,0,4,0,125,0,0,0,1,0,2,0,192,1,45,0,5,0,1,0,10,0,62,0,1,0,4,0,192,1,46,0,1,0,2,0,4,0,57,0,2,0,2,0,192,1,47,0,5,0,10,0,10,0,11,0,1,0,9,0,192,1,48,0,5,0,8,0,59,0,27,0,1,0,8,0,192,1,49,0,5,0,8,0,59,0,18,0,1,0,8,0,192,1,50,0,5,0,8,0,59,0,9,0,1,0,8,0,192,1,51,0,5,0,8,0,59,0,0,0,1,0,8,0,192,1,52,0,6,0,8,0,52,0,9,0,1,0,8,0,192,1,53,0,5,0,8,0,52,0,54,0,1,0,8,0,192,1,54,0,5,0,8,0,52,0,45,0,1,0,8,0,192,1,55,0,5,0,8,0,52,0,36,0,1,0,8,0,192,1,56,0,5,0,8,0,52,0,27,0,1,0,8,0,192,1,57,0,5,0,8,0,23,0,55,0,1,0,8,0,192,1,58,0,1,0,6,0,123,0,0,0,3,0,6,0,192,1,59,0,2,0,8,0,6,0,53,0,1,0,6,0,192,1,60,0,6,0,5,0,78,0,7,0,0,0,6,0,192,1,61,0,6,0,3,0,16,0,60,0,1,0,5,0,192,1,62,0,6,0,5,0,71,0,7,0,1,0,6,0,192,1,63,0,5,0,8,0,23,0,46,0,1,0,8,0,192,1,64,0,7,0,8,0,29,0,45,0,0,0,8,0,192,1,65,0,6,0,8,0,52,0,0,0,1,0,8,0,192,1,66,0,6,0,8,0,45,0,54,0,1,0,8,0,192,1,67,0,6,0,8,0,45,0,45,0,1,0,8,0,192,1,68,0,6,0,8,0,45,0,36,0,1,0,8,0,192,1,69,0,5,0,8,0,23,0,37,0,1,0,8,0,192,1,70,0,5,0,8,0,23,0,28,0,1,0,8,0,192,1,71,0,6,0,8,0,45,0,27,0,1,0,8,0,192,1,72,0,6,0,8,0,45,0,18,0,1,0,8,0,192,1,73,0,3,0,8,0,6,0,44,0,2,0,8,0,192,1,74,0,4,0,8,0,59,0,45,0,1,0,8,0,192,1,75,0,6,0,8,0,45,0,9,0,1,0,8,0,192,1,76,0,5,0,8,0,23,0,19,0,1,0,8,0,192,1,77,0,7,0,8,0,29,0,36,0,0,0,8,0,192,1,78,0,6,0,8,0,45,0,0,0,1,0,8,0,192,1,79,0,6,0,8,0,37,0,54,0,1,0,8,0,192,1,80,0,5,0,8,0,23,0,10,0,1,0,8,0,192,1,81,0,6,0,9,0,16,0,0,0,1,0,8,0,192,1,82,0,6,0,8,0,37,0,45,0,1,0,8,0,192,1,83,0,6,0,8,0,37,0,36,0,1,0,8,0,192,1,84,0,7,0,8,0,29,0,27,0,0,0,8,0,192,1,85,0,6,0,8,0,37,0,27,0,1,0,8,0,192,1,86,0,7,0,8,0,29,0,18,0,0,0,8,0,192,1,87,0,7,0,8,0,29,0,9,0,0,0,8,0,192,1,88,0,6,0,8,0,37,0,18,0,1,0,8,0,192,1,89,0,7,0,8,0,29,0,0,0,0,0,8,0,192,1,90,0,6,0,8,0,37,0,9,0,1,0,8,0,192,1,91,0,3,0,11,0,0,0,48,0,2,0,9,0,192,1,92,0,5,0,10,0,10,0,0,0,1,0,9,0,192,1,93,0,3,0,11,0,0,0,36,0,2,0,9,0,192,1,94,0,5,0,6,0,65,0,28,0,1,0,9,0,192,1,95,0,7,0,1,0,85,0,10,0,0,0,0,0,192,1,96,0,2,0,2,0,59,0,61,0,2,0,9,0,192,1,97,0,5,0,6,0,65,0,21,0,1,0,6,0,192,1,98,0,5,0,9,0,16,0,50,0,1,0,9,0,192,1,99,0,5,0,6,0,65,0,14,0,1,0,6,0,192,1,100,0,5,0,9,0,16,0,40,0,1,0,9,0,192,1,101,0,5,0,6,0,65,0,7,0,1,0,6,0,192,1,102,0,5,0,9,0,16,0,30,0,1,0,9,0,192,1,103,0,5,0,9,0,16,0,20,0,1,0,6,0,192,1,104,0,5,0,9,0,16,0,10,0,1,0,9,0,192,1,105,0,2,0,9,0,6,0,34,0,2,0,9,0,192,1,106,0,4,0,11,0,0,0,24,0,1,0,9,0,192,1,107,0,5,0,9,0,10,0,52,0,1,0,9,0,192,1,108,0,2,0,9,0,6,0,24,0,2,0,9,0,192,1,109,0,7,0,6,0,73,0,0,0,0,0,6,0,192,1,110,0,5,0,6,0,117,0,0,0,1,0,6,0,192,1,111,0,5,0,6,0,111,0,0,0,1,0,6,0,192,1,112,0,5,0,9,0,10,0,42,0,1,0,6,0,192,1,113,0,5,0,9,0,10,0,32,0,1,0,6,0,192,1,114,0,5,0,6,0,105,0,0,0,1,0,6,0,192,1,115,0,5,0,6,0,99,0,0,0,1,0,6,0,192,1,116,0,4,0,8,0,59,0,36,0,2,0,8,0,192,1,117,0,5,0,6,0,93,0,0,0,1,0,6,0,192,1,118,0,5,0,6,0,87,0,0,0,1,0,6,0,192,1,119,0,7,0,6,0,65,0,0,0,0,0,6,0,192,1,120,0,5,0,6,0,81,0,0,0,1,0,6,0,192,1,121,0,5,0,9,0,10,0,22,0,1,0,6,0,192,1,122,0,5,0,6,0,59,0,54,0,1,0,6,0,192,1,123,0,5,0,11,0,0,0,12,0,1,0,9,0,192,1,124,0,1,0,11,0,4,0,36,0,3,0,9,0,192,1,125,0,5,0,11,0,0,0,0,0,1,0,9,0,192,1,126,0,7,0,2,0,85,0,7,0,0,0,5,0,192,1,127,0,0,0,0,0,5,0,24,0,0,0,0,0,192,1,128,0,64,0,8,255,255,0,0,0,0,255,0,0,0,0,0,0,0,255,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,255,0,0,0,0,0,255,0,255,0,0,0,0,255,0,0,0,255,255,0,255,0,0,0,0,255,0,0,255,255,255,0,0,0,255,0,0,0,255,0,0,255,0,0,255,0,0,255,0,255,0,0,0,255,0,0,0,255,0,0,0,0,255,255,255,255,0,255,255,255,255,0,0,255,0,0,0,0,0,0,255,255,255,0,0,255,0,0,0,255,0,255,0,255,0,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,255,0,0,0,255,255,0,255,0,255,255,255,255,0,0,0,0,0,255,0,0,0,0,0,255,0,255,0,0,0,0,255,0,0,0,255,255,0,255,0,0,0,0,255,0,255,0,0,0,255,0,0,255,255,0,255,255,0,0,255,0,0,255,0,0,255,0,0,255,0,255,0,0,0,0,255,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,255,0,0,0,0,0,255,0,0,0,255,0,255,0,0,0,255,0,255,0,0,255,0,0,0,255,0,0,0,0,255,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,255,0,255,0,0,0,0,255,0,0,0,0,255,255,255,255,255,255,0,0,255,0,0,255,0,255,0,255,0,0,0,0,255,0,0,0,0,0,255,0,255,0,255,0,255,0,255,0,255,0,0,255,0,0,255,0,0,0,255,0,0,0,0,255,0,255,0,0,255,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,255,0,0,0,255,0,255,0,0,0,0,255,0,0,0,0,0,0,255,0,255,0,0,0,255,0,0,255,0,255,0,0,255,255,255,255,0,0,0,0,0,0,255,0,255,0,0,255,0,0,255,0,255,0,0,255,0,0,255,0,0,0,255,0,0,0,0,255,0,255,0,0,255,0,0,0,255,0,0,255,255,0,0,0,255,0,0,0,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,255,0,0,0,255,0,0,0,0,255,0,0,255,255,255,0,0,0,0,255,0,255,0,0,0,0,0,255,0,255,0,0,0,255,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,255,255,0,0,255,0,0,255,0,0,255,0,255,0,0,255,0,0,255,0,0,255,0,255,0,0,255,0,0,0,255,0,255,0,0,0,255,0,255,0,0,0,0,0,255,255,0,0,255,0,255,0,0,0,255,0,255,0,0,0,255,0,255,0,0,0,0,0,0,0,255,255,0,0,0,255,0,0,0,255,0,0,0,255,0,0,0,0,255,0,255,0,255,0,0,0,0,255,0,0,0,255,0,0,0,255,255,255,255,255,255,0,255,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,0,255,0,255,0,0,0,0,0,255,0,255,255,255,0,255,255,0,0,255,0,0,0,255,0,255,0,0,0,255,0,255,0,0,0,255,0,0,255,255,255,255,0,255,0,255,255,0,0,0,255,255,255,0,0,255,255,255,255,0,0,255,0,0,0,0,0,0,255,0,0,0,0,0,255,0,0,255,0,0,0,0,255,0,0,0,0,255,0,255,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,0,255,0,255,0,0,255,255,0,0,0,255,0,0,0,255,255,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,255,0,0,255,0,0,0,0,0,255,0,0,255,0,0,0,255,255,255,255,0,255,0,0,0,0,0,255,0,0,0,0,255,0,255,0,0,255,255,0,0,0,255,0,0,0,255,255,0,0,0,0,255,255,255,0,0,0,255,255,255,0,0,255,255,0,0,0,0,0,0,0,0,0,255,255,0,255,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,0,0,0,255,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,255,255,0,0,0,0,0,255,255,0,0,0,0,255,255,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,255,255,255,255,255,0,0,255,0,0,0,0,255,0,0,0,0,0,255,0,0,255,255,255,255,255,0,255,0,0,0,0,0,0,0,0,0,255,255,0,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,255,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,255,255,255,255,255,0,0,0,255,255,0,0,0,0,0,255,255,0,0,0,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,0,255,255,0,255,255,0,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,255,255,255,255,255,255,0,0,255,0,0,0,0,255,0,0,0,255,0,255,255,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,255,0,255,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,255,0,255,0,255,0,255,0,0,0,255,0,0,0,0,0,255,255,255,0,0,0,0,255,0,0,0,255,0,0,0,0,255,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,255,255,255,255,0,0,255,0,255,0,255,0,255,0,0,0,0,255,0,0,0,0,255,0,255,0,0,0,0,0,255,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,255,0,0,255,0,0,255,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,255,0,255,0,0,0,0,0,0,255,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,255,255,255,255,0,0,0,255,0,0,0,255,0,255,0,0,255,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,255,0,0,0,0,0,255,255,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,255,0,0,0,255,0,255,0,0,0,0,0,255,0,255,255,255,255,255,255,0,0,255,0,0,0,0,255,0,0,0,0,0,255,0,0,0,255,255,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,0,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,255,0,0,255,255,255,0,255,0,255,255,255,255,255,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,255,255,255,255,255,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,255,0,255,0,0,0,255,0,0,0,0,255,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,255,0,0,255,255,255,0,0,0,255,0,0,0,0,0,0,0,255,0,255,0,0,0,0,255,0,0,255,0,0,0,255,0,0,0,0,255,0,255,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,0,0,255,0,255,0,0,0,0,0,255,255,0,0,0,0,255,0,0,0,0,255,0,255,0,0,255,0,255,0,0,0,255,0,0,0,0,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,255,0,0,255,255,255,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,255,255,0,0,0,0,255,255,255,255,255,255,0,0,255,255,0,0,255,0,0,0,255,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,255,255,255,0,0,255,0,0,0,0,0,0,255,0,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,0,0,0,255,0,255,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,255,0,0,0,0,0,0,255,0,255,0,0,0,255,0,0,255,0,0,0,0,0,255,0,0,0,0,0,255,0,255,0,0,0,0,255,0,0,255,0,0,0,0,255,0,255,0,0,255,0,0,0,0,255,255,0,0,0,0,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,255,255,255,255,0,255,0,0,0,255,0,0,255,0,0,0,0,0,255,0,0,0,0,0,255,0,255,0,0,0,0,255,0,0,255,0,0,0,0,255,0,0,255,255,0,0,0,0,0,0,255,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,255,255,255,255,0,0,0,0,0,255,255,255,0,0,0,255,255,255,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,0,255,255,255,255,0,0,255,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,255,0,255,0,0,0,255,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,255,0,0,255,255,255,0,255,0,0,0,255,0,0,255,0,255,0,255,0,0,255,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,255,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,0,0,0,255,255,255,0,0,0,255,0,255,0,255,0,0,255,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,255,255,255,255,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,255,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,255,0,0,0,0,0,255,255,255,255,255,255,255,0,255,0,0,0,0,255,0,0,0,0,255,255,255,0,0,0,255,255,255,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,255,255,255,0,255,255,255,255,0,0,0,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,255,0,0,255,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,255,0,0,255,255,255,255,0,0,0,255,255,255,255,0,0,0,0,255,0,0,0,0,0,0,255,255,255,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,255,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,255,255,255,255,255,0,255,0,0,0,0,0,255,0,255,0,0,0,0,255,0,0,255,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,255,0,0,255,0,0,0,255,0,0,0,255,255,255,0,0,255,0,0,0,0,0,255,0,0,255,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,0,255,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,255,255,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,255,0,0,0,0,0,255,0,0,255,0,0,255,0,0,0,0,255,255,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,0,0,0,0,255,255,255,255,0,0,255,255,255,255,0,0,255,0,0,0,0,0,255,0,255,0,255,0,255,0,0,255,255,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,255,255,255,0,0,255,0,255,0,255,0,255,0,255,0,0,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,0,255,255,255,255,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,255,0,0,255,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,255,255,0,0,0,255,255,0,255,0,0,0,0,255,0,0,255,0,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,255,0,255,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,0,0,0,255,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,255,255,0,0,0,255,255,0,0,255,255,255,255,0,0,0,255,255,255,255,0,0,0,255,255,255,255,255,0,0,255,0,0,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,255,255,255,0,255,0,0,0,0,0,255,0,0,0,255,0,0,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,0,255,0,0,255,255,255,255,0,0,0,255,255,255,255,0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,255,0,0,0,0,255,0,0,0,0,255,255,255,0,0,0,255,255,255,0,0,0,255,255,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,255,0,0,255,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,255,0,0,255,255,255,0,0,255,0,0,255,0,0,0,0,255,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,255,0,0,255,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,0,255,0,0,0,255,0,255,0,255,0,255,0,255,255,255,255,0,0,0,0,255,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,255,0,255,0,255,0,255,0,0,0,255,0,0,0,255,0,0,0,0,0,0,255,255,255,255,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,255,255,255,255,0,0,255,255,255,255,0,0,0,0,0,0,255,0,0,255,0,0,255,255,0,255,0,255,0,0,0,255,0,0,0,255,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,255,255,255,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,255,0,0,0,255,0,0,0,255,255,255,0,0,0,255,255,255,255,0,0,0,0,0,0,255,255,255,0,0,0,0,255,255,0,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,255,0,0,0,255,0,0,255,0,0,255,0,0,0,255,0,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,255,255,255,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,255,255,0,0,0,0,255,255,255,255,255,0,0,0,255,255,255,0,0,0,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,255,0,255,0,0,0,255,255,255,255,0,0,0,0,255,255,0,0,0,0,0,255,0,255,0,255,0,0,255,0,0,255,0,0,0,255,0,0,0,0,255,0,255,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,255,0,0,255,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,255,0,255,0,255,0,0,0,0,255,0,0,255,0,0,0,0,255,0,0,0,0,0,255,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,0,0,0,255,0,0,0,255,0,255,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,255,0,255,0,0,255,0,0,0,0,255,0,0,255,0,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,255,0,0,0,0,0,255,0,0,0,0,0,255,0,0,0,0,0,0,0,255,255,255,255,0,0,255,0,255,0,0,0,0,255,0,0,0,0,255,0,0,255,255,255,255,255,0,0,255,255,255,255,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,255,0,255,0,255,0,0,0,255,0,0,0,0,255,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,0,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,255,0,0,255,0,0,255,0,0,0,0,0,255,255,255,255,255,255,0,255,0,0,0,255,0,255,0,255,0,255,0,0,0,0,255,0,0,255,0,0,0,255,0,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,255,0,0,255,0,0,0,255,0,0,0,0,255,255,0,0,0,0,255,255,255,255,0,0,0,255,255,255,255,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,0,255,0,0,0,0,0,255,255,255,255,255,0,255,255,255,255,255,255,0,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255}; +// clang-format on #endif // STATIC_FONT_HEADER_H - diff --git a/src/oglGraph/dlgMarkers.cpp b/src/oglGraph/dlgMarkers.cpp index 80334048b..be76e9417 100644 --- a/src/oglGraph/dlgMarkers.cpp +++ b/src/oglGraph/dlgMarkers.cpp @@ -35,7 +35,7 @@ dlgMarkers::dlgMarkers(wxWindow* parent, wxWindowID id, const wxPoint& pos, cons void dlgMarkers::BuildContent(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size) { - parent_graph = (OpenGLGraph*)parent; + parent_graph = static_cast(parent); //(*Initialize(dlgMarkers) Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER, _T("id")); SetClientSize(wxDefaultSize); @@ -56,7 +56,7 @@ void dlgMarkers::BuildContent(wxWindow* parent, wxWindowID id, const wxPoint& po FlexGridSizer1->Fit(this); FlexGridSizer1->SetSizeHints(this); - Connect(ID_BUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&dlgMarkers::OnbtnCloseClick); + Connect(ID_BUTTON1, wxEVT_COMMAND_BUTTON_CLICKED, reinterpret_cast(&dlgMarkers::OnbtnCloseClick)); //*) } @@ -95,8 +95,8 @@ void dlgMarkers::AddMarker(int id) marker_valuesA.push_back(0); marker_valuesB.push_back(0); FlexGridSizer3->Add(StaticText4, 1, wxALL | wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL, 5); - Connect(markerId, wxEVT_CHECKBOX, (wxObjectEventFunction)&dlgMarkers::OnMarkerChange); - Connect(markerId, wxEVT_COMMAND_TEXT_UPDATED, (wxObjectEventFunction)&dlgMarkers::OnMarkerChange); + Connect(markerId, wxEVT_CHECKBOX, reinterpret_cast(&dlgMarkers::OnMarkerChange)); + Connect(markerId, wxEVT_COMMAND_TEXT_UPDATED, reinterpret_cast(&dlgMarkers::OnMarkerChange)); pnl->SetSizer(FlexGridSizer3); sizerMarkerList->Add(pnl, 1, wxALIGN_LEFT | wxALIGN_TOP, 5); pnl->Layout(); diff --git a/src/protocols/BufferInterleaving.cpp b/src/protocols/BufferInterleaving.cpp index 27d9e98fc..aed3b1b23 100644 --- a/src/protocols/BufferInterleaving.cpp +++ b/src/protocols/BufferInterleaving.cpp @@ -40,7 +40,7 @@ template int ParseRxPayload(const ui if (mimo) //uncompressed samples { - complex16_t* ptr = (complex16_t*)buffer; + const complex16_t* ptr = reinterpret_cast(buffer); const int collected = bufLen / sizeof(complex16_t) / 2; for (int i = 0; i < collected; i++) { @@ -66,10 +66,11 @@ int Deinterleave(const DataConversion& fmt, const uint8_t* buffer, uint32_t leng { samplesProduced = length / sizeof(complex16_t); if (!mimo) - complex16_to_complex32f(dest[0], (const complex16_t*)buffer, length / sizeof(complex16_t)); + complex16_to_complex32f(dest[0], reinterpret_cast(buffer), length / sizeof(complex16_t)); else { - complex16_to_complex32f_unzip(dest[0], dest[1], (const complex16_t*)buffer, length / sizeof(complex16_t)); + complex16_to_complex32f_unzip( + dest[0], dest[1], reinterpret_cast(buffer), length / sizeof(complex16_t)); samplesProduced /= 2; } } @@ -97,10 +98,10 @@ int Interleave(TRXLooper::SamplesPacketType* input, uint32_t count, const DataCo { bytesProduced = count * sizeof(complex16_t); if (!mimo) - complex32f_to_complex16((complex16_t*)buffer, src[0], count); + complex32f_to_complex16(reinterpret_cast(buffer), src[0], count); else { - complex32f_to_complex16_zip((complex16_t*)buffer, src[0], src[1], count); + complex32f_to_complex16_zip(reinterpret_cast(buffer), src[0], src[1], count); bytesProduced *= 2; } } diff --git a/src/protocols/LMS64CProtocol.cpp b/src/protocols/LMS64CProtocol.cpp index ba734bc1a..57b28cb1b 100644 --- a/src/protocols/LMS64CProtocol.cpp +++ b/src/protocols/LMS64CProtocol.cpp @@ -238,9 +238,9 @@ void FirmwareToDescriptor(const FirmwareInfo& fw, SDRDevice::Descriptor& descrip } else descriptor.expansionName = GetExpansionBoardName(static_cast(fw.expansionBoardId)); - descriptor.firmwareVersion = std::to_string(int(fw.firmware)); - descriptor.hardwareVersion = std::to_string(int(fw.hardware)); - descriptor.protocolVersion = std::to_string(int(fw.protocol)); + descriptor.firmwareVersion = std::to_string(fw.firmware); + descriptor.hardwareVersion = std::to_string(fw.hardware); + descriptor.protocolVersion = std::to_string(fw.protocol); descriptor.serialNumber = fw.boardSerialNumber; } @@ -700,9 +700,9 @@ OpStatus MemoryWrite(ISerialPort& port, uint32_t address, const void* data, size progView.SetData(src, chunkSize); src += chunkSize; - if (port.Write((uint8_t*)&packet, sizeof(packet), timeout_ms) != sizeof(packet)) + if (port.Write(reinterpret_cast(&packet), sizeof(packet), timeout_ms) != sizeof(packet)) return OpStatus::IO_FAILURE; - if (port.Read((uint8_t*)&inPacket, sizeof(inPacket), timeout_ms) != sizeof(inPacket)) + if (port.Read(reinterpret_cast(&inPacket), sizeof(inPacket), timeout_ms) != sizeof(inPacket)) return OpStatus::IO_FAILURE; if (inPacket.status != STATUS_COMPLETED_CMD) @@ -739,9 +739,9 @@ OpStatus MemoryRead(ISerialPort& port, uint32_t address, void* data, size_t data writeView.SetAddress(address + bytesGot); writeView.SetChunkSize(std::min(dataLen - bytesGot, chunkSize)); - if (port.Write((uint8_t*)&packet, sizeof(packet), timeout_ms) != sizeof(packet)) + if (port.Write(reinterpret_cast(&packet), sizeof(packet), timeout_ms) != sizeof(packet)) return OpStatus::IO_FAILURE; - if (port.Read((uint8_t*)&inPacket, sizeof(inPacket), timeout_ms) != sizeof(inPacket)) + if (port.Read(reinterpret_cast(&inPacket), sizeof(inPacket), timeout_ms) != sizeof(inPacket)) return OpStatus::IO_FAILURE; if (inPacket.status != STATUS_COMPLETED_CMD) diff --git a/src/utilities/rfTest.cpp b/src/utilities/rfTest.cpp index 0e2d20783..b6ddde260 100644 --- a/src/utilities/rfTest.cpp +++ b/src/utilities/rfTest.cpp @@ -92,7 +92,7 @@ bool OnStreamStatusChange(bool isTx, const SDRDevice::StreamStats* s, void* user // s->isTx, don't care now if it's comming from Rx or Tx bool streamIssues = s->late | s->loss | s->overrun; if (userData) - *(bool*)userData = streamIssues; // report that there were issues with stream + *static_cast(userData) = streamIssues; // report that there were issues with stream return false; } @@ -144,11 +144,11 @@ bool FullStreamTxRx(SDRDevice& dev, bool MIMO) const int samplesInPkt = 256; //(stream.linkFormat == SDRDevice::StreamConfig::I12 ? 1360 : 1020)/channelCount; const float rxBufferTime = 0.002; // max buffer size in time (seconds) - const uint32_t samplesToBuffer = (int)(rxBufferTime * sampleRate / samplesInPkt) * samplesInPkt; + const uint32_t samplesToBuffer = static_cast(rxBufferTime * sampleRate / samplesInPkt) * samplesInPkt; assert(samplesToBuffer > 0); const float txTimeOffset = 0.005; // tx packets delay in time (seconds), will be rounded to even packets count - const int64_t txDeltaTS = (int)(txTimeOffset * sampleRate / samplesInPkt) * samplesInPkt; + const int64_t txDeltaTS = static_cast(txTimeOffset * sampleRate / samplesInPkt) * samplesInPkt; printf("TxDeltaTS +%li, (+%.3fms) %li packets\n", txDeltaTS, 1000.0 * txDeltaTS / sampleRate, txDeltaTS / samplesInPkt); // const int alignment = 4096; @@ -332,15 +332,15 @@ bool TxTiming(SDRDevice& dev, bool MIMO, float tsDelay_ms) (stream.linkFormat == SDRDevice::StreamConfig::DataFormat::I12 ? 1360 : 1020) / stream.channels.at(lime::TRXDir::Rx).size(); const float rxBufferTime = 0.005; // max buffer size in time (seconds) - const uint32_t samplesToBuffer = (int)(rxBufferTime * sampleRate / samplesInPkt) * samplesInPkt; + const uint32_t samplesToBuffer = static_cast(rxBufferTime * sampleRate / samplesInPkt) * samplesInPkt; assert(samplesToBuffer > 0); const float txTimeOffset = 0.001 * tsDelay_ms; // tx packets delay in time (seconds) - const int64_t txDeltaTS = (int)(txTimeOffset * sampleRate); + const int64_t txDeltaTS = static_cast(txTimeOffset * sampleRate); printf("\nusing TxOffsetTS +%li (%+.3fms) (%+.3f packets)\n", txDeltaTS, 1000.0 * txDeltaTS / sampleRate, - (float)txDeltaTS / samplesInPkt); + static_cast(txDeltaTS) / samplesInPkt); std::vector> rxSamples(2); // allocate two channels for simplicity for (size_t i = 0; i < rxSamples.size(); ++i) @@ -454,7 +454,7 @@ bool TxTiming(SDRDevice& dev, bool MIMO, float tsDelay_ms) txMeta.timestamp, diff, 1000.0 * diff / sampleRate, - float(diff) / samplesInPkt); + static_cast(diff) / samplesInPkt); txPending = false; done = true; break;