From 0ae620b73203eedaa10421f14906c0161e625fed Mon Sep 17 00:00:00 2001 From: PianetaRadio <78976006+PianetaRadio@users.noreply.github.com> Date: Sun, 25 Feb 2024 20:52:04 +0100 Subject: [PATCH] Code optimization Use has_get/set_func instead of rig cap --- dialogconfig.cpp | 12 +++++++- mainwindow.cpp | 40 +++++++++++++++++--------- rigdaemon.cpp | 75 ++++++++++++++++++++++++++++++++---------------- 3 files changed, 88 insertions(+), 39 deletions(-) diff --git a/dialogconfig.cpp b/dialogconfig.cpp index 18a9443..70329c4 100644 --- a/dialogconfig.cpp +++ b/dialogconfig.cpp @@ -187,13 +187,23 @@ void DialogConfig::on_buttonBox_accepted() configFile.setValue("autoPowerOn", ui->checkBox_autoPowerOn->isChecked()); } -int printRigList(const struct rig_caps *rigCaps, void *data) //Load rig list from hamlib and save into file rig.lst +#ifdef RIGCAPS_NOT_CONST //rig_caps is no longer constant starting from hamlib v.4.6 +int printRigList(struct rig_caps *rigCaps, void *data) //Load rig list from hamlib and save into file rig.lst { if (data) return 0; QTextStream stream(&rigFile); stream << rigCaps->rig_model << " " << rigCaps->mfg_name << " " << rigCaps->model_name << "\n"; return 1; } +#else +int printRigList(const struct rig_caps *rigCaps, void *data) +{ + if (data) return 0; + QTextStream stream(&rigFile); + stream << rigCaps->rig_model << " " << rigCaps->mfg_name << " " << rigCaps->model_name << "\n"; + return 1; +} +#endif bool createRigFile() { diff --git a/mainwindow.cpp b/mainwindow.cpp index 00a25f0..272e15f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,6 +1,6 @@ /** ** This file is part of the CatRadio project. - ** Copyright 2022 Gianfranco Sordetti IZ8EWD . + ** Copyright 2022-2024 Gianfranco Sordetti IZ8EWD . ** ** This program is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -217,8 +217,8 @@ MainWindow::~MainWindow() void MainWindow::guiInit() { //* Power on/off cap - //if (rig_has_set_func(my_rig, RIG_FUNCTION_SET_POWERSTAT)==0) - if (my_rig->caps->set_powerstat == NULL) + if (rig_has_set_func(my_rig, RIG_FUNCTION_SET_POWERSTAT)==0) + //if (my_rig->caps->set_powerstat == NULL) { ui->pushButton_Power->setDisabled(true); //Power pushbutton disabled rigCap.onoff = 0; @@ -230,8 +230,8 @@ void MainWindow::guiInit() } //* PTT cap - //if (rig_has_set_func(my_rig, RIG_FUNCTION_SET_PTT)==0) - if (my_rig->caps->set_ptt == NULL) + if (rig_has_set_func(my_rig, RIG_FUNCTION_SET_PTT)==0) + //if (my_rig->caps->set_ptt == NULL) { ui->pushButton_PTT->setDisabled(true); //PTT pushbutton disabled rigCap.ptt = 0; @@ -268,16 +268,24 @@ void MainWindow::guiInit() guiCmd.bwidthList = 1; //Command to populate BW combobox in guiUpdate() } + //* ANT comboBox + ui->comboBox_Ant->clear(); + if (!rig_has_set_func(my_rig, RIG_FUNCTION_SET_ANT)) ui->comboBox_Ant->setEnabled(false); + //* AGC level comboBox ui->comboBox_AGC->clear(); - for (i = 0; i < HAMLIB_MAX_AGC_LEVELS && i < my_rig->caps->agc_level_count; i++) ui->comboBox_AGC->addItem(rig_stragclevel(my_rig->caps->agc_levels[i])); - if (i==0) //Print all levels if list is not specified + if (!rig_has_set_level(my_rig, RIG_LEVEL_AGC)) ui->comboBox_AGC->setEnabled(false); + else { - ui->comboBox_AGC->addItem(rig_stragclevel(RIG_AGC_OFF)); - ui->comboBox_AGC->addItem(rig_stragclevel(RIG_AGC_AUTO)); - ui->comboBox_AGC->addItem(rig_stragclevel(RIG_AGC_FAST)); - ui->comboBox_AGC->addItem(rig_stragclevel(RIG_AGC_MEDIUM)); - ui->comboBox_AGC->addItem(rig_stragclevel(RIG_AGC_SLOW)); + for (i = 0; i < HAMLIB_MAX_AGC_LEVELS && i < my_rig->state.agc_level_count; i++) ui->comboBox_AGC->addItem(rig_stragclevel(my_rig->state.agc_levels[i])); + if (i==0) //Print all levels if list is not specified + { + ui->comboBox_AGC->addItem(rig_stragclevel(RIG_AGC_OFF)); + ui->comboBox_AGC->addItem(rig_stragclevel(RIG_AGC_AUTO)); + ui->comboBox_AGC->addItem(rig_stragclevel(RIG_AGC_FAST)); + ui->comboBox_AGC->addItem(rig_stragclevel(RIG_AGC_MEDIUM)); + ui->comboBox_AGC->addItem(rig_stragclevel(RIG_AGC_SLOW)); + } } //* Meters & Sub-meter comboBox @@ -296,6 +304,7 @@ void MainWindow::guiInit() //* Attenuator comboBox ui->comboBox_Att->clear(); + if (!rig_has_set_level(my_rig, RIG_LEVEL_ATT)) ui->comboBox_Att->setEnabled(false); ui->comboBox_Att->addItem("0"); for (i = 0; i < HAMLIB_MAXDBLSTSIZ && my_rig->state.attenuator[i] != 0; i++) { @@ -304,6 +313,7 @@ void MainWindow::guiInit() //* Preamp comboBox ui->comboBox_Preamp->clear(); + if (!rig_has_set_level(my_rig, RIG_LEVEL_PREAMP)) ui->comboBox_Preamp->setEnabled(false); ui->comboBox_Preamp->addItem("0"); for (i = 0; i < HAMLIB_MAXDBLSTSIZ && my_rig->state.preamp[i] != 0; i++) { @@ -519,6 +529,7 @@ void MainWindow::guiUpdate() { for (i=0; istate.tx_range_list[i].startf<state.tx_range_list[i].endf; if (rigGet.freqMain >= my_rig->state.tx_range_list[i].startf && rigGet.freqMain <= my_rig->state.tx_range_list[i].endf) break; } rigGet.rangeListTxIndex = i; @@ -537,7 +548,8 @@ void MainWindow::guiUpdate() if (guiCmd.antList) { ui->comboBox_Ant->clear(); - if (my_rig->state.tx_range_list[rigGet.rangeListRxIndex].ant == RIG_ANT_NONE) ui->comboBox_Ant->addItem("NONE"); //RIG_ANT_NONE + if (!rig_has_get_func(my_rig, RIG_FUNCTION_GET_ANT)) ui->comboBox_Ant->addItem(""); + else if (my_rig->state.tx_range_list[rigGet.rangeListRxIndex].ant == RIG_ANT_NONE) ui->comboBox_Ant->addItem("NONE"); //RIG_ANT_NONE else for (i=0; i < RIG_ANT_MAX; i++) { if (my_rig->state.tx_range_list[rigGet.rangeListRxIndex].ant & (1UL << i)) @@ -804,7 +816,7 @@ void MainWindow::on_pushButton_Connect_toggled(bool checked) rigCom.connected = 1; guiInit(); connectMsg = "Connected to "; - connectMsg.append(my_rig->caps->model_name); + connectMsg.append(my_rig->state.model_name); if (rigCap.onoff == 0 || rigGet.onoff == RIG_POWER_ON || rigGet.onoff == RIG_POWER_UNKNOWN) { freq_t retfreq; diff --git a/rigdaemon.cpp b/rigdaemon.cpp index 06ae74b..703f7a3 100644 --- a/rigdaemon.cpp +++ b/rigdaemon.cpp @@ -90,7 +90,8 @@ RIG *RigDaemon::rigConnect(int *retcode) if (*retcode != RIG_OK) return nullptr; //Rig not connected else //Rig connected { - if (my_rig->caps->get_powerstat != NULL) rig_get_powerstat(my_rig, &rigGet.onoff); + if (rig_has_get_func(my_rig, RIG_FUNCTION_GET_POWERSTAT)) rig_get_powerstat(my_rig, &rigGet.onoff); + //if (my_rig->caps->get_powerstat != NULL) rig_get_powerstat(my_rig, &rigGet.onoff); else rigGet.onoff = RIG_POWER_UNKNOWN; return my_rig; } @@ -225,7 +226,7 @@ void RigDaemon::rigUpdate(RIG *my_rig) //* VFO Exchange if (rigCmd.vfoXchange) { - if (my_rig->caps->vfo_ops & RIG_OP_XCHG) + if (my_rig->state.vfo_ops & RIG_OP_XCHG) { mode_t tempMode = rigGet.mode; retcode = rig_vfo_op(my_rig, RIG_VFO_CURR, RIG_OP_XCHG); @@ -237,7 +238,7 @@ void RigDaemon::rigUpdate(RIG *my_rig) } } - else if (my_rig->caps->vfo_ops & RIG_OP_TOGGLE) + else if (my_rig->state.vfo_ops & RIG_OP_TOGGLE) { freq_t tempFreq = rigGet.freqMain; mode_t tempMode = rigGet.mode; @@ -256,7 +257,7 @@ void RigDaemon::rigUpdate(RIG *my_rig) //* VFO Copy if (rigCmd.vfoCopy) { - if (my_rig->caps->vfo_ops & RIG_OP_CPY) + if (my_rig->state.vfo_ops & RIG_OP_CPY) { retcode = rig_vfo_op(my_rig, RIG_VFO_CURR, RIG_OP_CPY); if (retcode == RIG_OK) @@ -285,7 +286,7 @@ void RigDaemon::rigUpdate(RIG *my_rig) //* Band Up if (rigCmd.bandUp) { - if (my_rig->caps->vfo_ops & RIG_OP_BAND_UP) + if (my_rig->state.vfo_ops & RIG_OP_BAND_UP) { retcode = rig_vfo_op(my_rig, RIG_VFO_CURR, RIG_OP_BAND_UP); if (retcode == RIG_OK) indexCmd = 21; @@ -296,7 +297,7 @@ void RigDaemon::rigUpdate(RIG *my_rig) //* Band Down if (rigCmd.bandDown) { - if (my_rig->caps->vfo_ops & RIG_OP_BAND_DOWN) + if (my_rig->state.vfo_ops & RIG_OP_BAND_DOWN) { retcode = rig_vfo_op(my_rig, RIG_VFO_CURR, RIG_OP_BAND_DOWN); if (retcode == RIG_OK) indexCmd = 21; @@ -323,7 +324,7 @@ void RigDaemon::rigUpdate(RIG *my_rig) //* Tune if (rigCmd.tune) { - if (my_rig->caps->vfo_ops & RIG_OP_TUNE) rig_vfo_op(my_rig, RIG_VFO_CURR, RIG_OP_TUNE); + if (my_rig->state.vfo_ops & RIG_OP_TUNE) rig_vfo_op(my_rig, RIG_VFO_CURR, RIG_OP_TUNE); rigCmd.tune = 0; } @@ -541,7 +542,8 @@ void RigDaemon::rigUpdate(RIG *my_rig) //* Repeater shift if (rigCmd.rptShift) { - if (my_rig->caps->set_rptr_shift) + if (rig_has_set_func(my_rig, RIG_FUNCTION_SET_RPTR_SHIFT)) + //if (my_rig->caps->set_rptr_shift) { retcode = rig_set_rptr_shift(my_rig, RIG_VFO_CURR, rigSet.rptShift); if (retcode == RIG_OK) rigGet.rptShift = rigSet.rptShift; @@ -551,7 +553,8 @@ void RigDaemon::rigUpdate(RIG *my_rig) //* Repeater offset if (rigCmd.rptOffset) { - if (my_rig->caps->set_rptr_offs) + if (rig_has_set_func(my_rig, RIG_FUNCTION_SET_RPTR_OFFS)) + //if (my_rig->caps->set_rptr_offs) { retcode = rig_set_rptr_offs(my_rig, RIG_VFO_CURR, rigSet.rptOffset); if (retcode == RIG_OK) rigGet.rptOffset = rigSet.rptOffset; @@ -651,55 +654,79 @@ void RigDaemon::rigUpdate(RIG *my_rig) if ((indexCmd == 3 && !rigGet.ptt && rigCom.fullPoll) || indexCmd == 0) rig_get_func(my_rig, RIG_VFO_CURR, RIG_FUNC_TUNER, &rigGet.tuner); //* Antenna - if ((indexCmd == 4 && !rigGet.ptt && rigCom.fullPoll) || indexCmd == 0) rig_get_ant(my_rig, RIG_VFO_CURR, RIG_ANT_CURR, &retvalue, &rigGet.ant, &rigGet.antTx, &rigGet.antRx); + if ((indexCmd == 4 && !rigGet.ptt && rigCom.fullPoll) || indexCmd == 0) + { + if (rig_has_get_func(my_rig, RIG_FUNCTION_GET_ANT)) rig_get_ant(my_rig, RIG_VFO_CURR, RIG_ANT_CURR, &retvalue, &rigGet.ant, &rigGet.antTx, &rigGet.antRx); + } //* AGC if ((indexCmd == 5 && !rigGet.ptt && rigCom.fullPoll) || indexCmd == 0) { - rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_AGC, &retvalue); - rigGet.agc = levelagcvalue(retvalue.i); + if (rig_has_get_level(my_rig, RIG_LEVEL_AGC)) + { + rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_AGC, &retvalue); + rigGet.agc = levelagcvalue(retvalue.i); + } } //* Attenuator if ((indexCmd == 6 && !rigGet.ptt && rigCom.fullPoll) || indexCmd == 0) { - rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_ATT, &retvalue); - rigGet.att = retvalue.i; + if (rig_has_get_level(my_rig, RIG_LEVEL_ATT)) + { + rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_ATT, &retvalue); + rigGet.att = retvalue.i; + } } //* Preamp if ((indexCmd == 7 && !rigGet.ptt && rigCom.fullPoll) || indexCmd == 0) { - rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_PREAMP, &retvalue); - rigGet.pre = retvalue.i; + if (rig_has_get_level(my_rig, RIG_LEVEL_PREAMP)) + { + rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_PREAMP, &retvalue); + rigGet.pre = retvalue.i; + } } //* RF power if ((indexCmd == 8 && !rigGet.ptt && rigCom.fullPoll) || indexCmd == 0) { - rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_RFPOWER, &retvalue); - rigGet.rfPower = retvalue.f; + if (rig_has_get_level(my_rig, RIG_LEVEL_RFPOWER)) + { + rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_RFPOWER, &retvalue); + rigGet.rfPower = retvalue.f; + } } //* RF gain if ((indexCmd == 9 && !rigGet.ptt && rigCom.fullPoll) || indexCmd == 0) { - rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_RF, &retvalue); - rigGet.rfGain = retvalue.f; + if (rig_has_get_level(my_rig, RIG_LEVEL_RF)) + { + rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_RF, &retvalue); + rigGet.rfGain = retvalue.f; + } } //* AF gain if ((indexCmd == 10 && !rigGet.ptt && rigCom.fullPoll) || indexCmd == 0) { - rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_AF, &retvalue); - rigGet.afGain = retvalue.f; + if (rig_has_get_level(my_rig, RIG_LEVEL_AF)) + { + rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_AF, &retvalue); + rigGet.afGain = retvalue.f; + } } //* Squelch if ((indexCmd == 11 && !rigGet.ptt && rigCom.fullPoll) || indexCmd == 0) { - rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_SQL, &retvalue); - rigGet.squelch = retvalue.f; + if (rig_has_get_level(my_rig, RIG_LEVEL_SQL)) + { + rig_get_level(my_rig, RIG_VFO_CURR, RIG_LEVEL_SQL, &retvalue); + rigGet.squelch = retvalue.f; + } } //* MIC