diff --git a/dialogcommand.cpp b/dialogcommand.cpp new file mode 100644 index 0000000..c181d38 --- /dev/null +++ b/dialogcommand.cpp @@ -0,0 +1,50 @@ +/** + ** This file is part of the CatRadio project. + ** Copyright 2022 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 + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program. If not, see . + **/ + + +#include "dialogcommand.h" +#include "ui_dialogcommand.h" + +#include "rig.h" + +DialogCommand::DialogCommand(QWidget *parent) : + QDialog(parent), + ui(new Ui::DialogCommand) +{ + ui->setupUi(this); +} + +DialogCommand::~DialogCommand() +{ + delete ui; +} + +void DialogCommand::on_pushButton_send_clicked() +{ + //int rig_send_raw(rig, unsigned char *send, int send_len, unsigned char *reply, int reply_len, unsigned char term); + //send contains the raw command data + //send_len is the # of bytes to send + //If reply is NULL no answer is expected + //reply should be as long as need for any reply + //term is the command termination char -- could be semicolon, CR, or 0xfd for Icom rigs +} + +void DialogCommand::on_pushButton_close_clicked() +{ + this->close(); +} diff --git a/dialogcommand.h b/dialogcommand.h new file mode 100644 index 0000000..2939eee --- /dev/null +++ b/dialogcommand.h @@ -0,0 +1,46 @@ +/** + ** This file is part of the CatRadio project. + ** Copyright 2022 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 + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** This program is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with this program. If not, see . + **/ + + +#ifndef DIALOGCOMMAND_H +#define DIALOGCOMMAND_H + +#include + +namespace Ui { +class DialogCommand; +} + +class DialogCommand : public QDialog +{ + Q_OBJECT + +public: + explicit DialogCommand(QWidget *parent = nullptr); + ~DialogCommand(); + +private slots: + void on_pushButton_close_clicked(); + + void on_pushButton_send_clicked(); + +private: + Ui::DialogCommand *ui; +}; + +#endif // DIALOGCOMMAND_H diff --git a/dialogcommand.ui b/dialogcommand.ui new file mode 100644 index 0000000..35d9503 --- /dev/null +++ b/dialogcommand.ui @@ -0,0 +1,66 @@ + + + DialogCommand + + + + 0 + 0 + 400 + 140 + + + + Command + + + + + + Command Send + + + + + + + + + + Send + + + + + + + Receive + + + + + + + true + + + + + + + Icom + + + + + + + Close + + + + + + + + diff --git a/mainwindow.cpp b/mainwindow.cpp index c899277..96dd131 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -21,6 +21,7 @@ #include "ui_mainwindow.h" #include "dialogconfig.h" #include "dialogsetup.h" +#include "dialogcommand.h" #include "rigdaemon.h" #include "rigdata.h" #include "guidata.h" @@ -40,7 +41,7 @@ #include //Hamlib -extern RIG *my_rig; //Defined in rigdaemon.cpp +RIG *my_rig; extern rigConnect rigCom; extern rigSettings rigGet; @@ -61,6 +62,8 @@ FILE* debugFile; QThread workerThread; // RigDaemon *rigDaemon = new RigDaemon; +QDialog *command = nullptr; + //***** MainWindow ***** @@ -99,7 +102,7 @@ MainWindow::MainWindow(QWidget *parent) //* Thread for RigDaemon rigDaemon->moveToThread(&workerThread); // connect(&workerThread, &QThread::finished, rigDaemon, &QObject::deleteLater); - connect(timer, &QTimer::timeout, rigDaemon, &RigDaemon::rigUpdate); + connect(timer, &QTimer::timeout, this, &MainWindow::rigUpdate); connect(rigDaemon, &RigDaemon::resultReady, this, &MainWindow::on_rigDaemonResultReady); workerThread.start(); @@ -604,6 +607,10 @@ void MainWindow::guiUpdate() else if (rigGet.toneType == 4) ui->comboBox_toneFreq->setCurrentText(QString::number(rigGet.tone)); //DCS } +void MainWindow::rigUpdate() +{ + rigDaemon->rigUpdate(my_rig); +} //* RigDaemon handle results void MainWindow::on_rigDaemonResultReady() @@ -678,23 +685,25 @@ void MainWindow::on_pushButton_Connect_toggled(bool checked) if (checked && rigCom.connected == 0) { - retcode = rigDaemon->rigConnect(); //Open Rig connection + int retcode; - if (retcode != RIG_OK) //Connection error - { - rigCom.connected = 0; - connectMsg = "Connection error: "; - connectMsg.append(rigerror(retcode)); - ui->pushButton_Connect->setChecked(false); //Uncheck the button - } - else //Rig connected - { - rigCom.connected = 1; - guiInit(); - connectMsg = "Connected to "; - connectMsg.append(my_rig->caps->model_name); - if (rigCap.onoff == 0 || rigGet.onoff == RIG_POWER_ON || rigGet.onoff == RIG_POWER_UNKNOWN) timer->start(rigCom.rigRefresh); - } + my_rig = rigDaemon->rigConnect(&retcode); //Open Rig connection + + if (retcode != RIG_OK) //Connection error + { + rigCom.connected = 0; + connectMsg = "Connection error: "; + connectMsg.append(rigerror(retcode)); + ui->pushButton_Connect->setChecked(false); //Uncheck the button + } + else //Rig connected + { + rigCom.connected = 1; + guiInit(); + connectMsg = "Connected to "; + connectMsg.append(my_rig->caps->model_name); + if (rigCap.onoff == 0 || rigGet.onoff == RIG_POWER_ON || rigGet.onoff == RIG_POWER_UNKNOWN) timer->start(rigCom.rigRefresh); + } } else if (rigCom.connected) //Button unchecked { @@ -1432,6 +1441,22 @@ void MainWindow::on_action_Setup_triggered() ui->lineEdit_vfoSub->setMode(guiConf.vfoDisplayMode); } +void MainWindow::on_actionCommand_triggered() +{ + //DialogCommand command; + //command.setModal(true); + //command.exec(); + + if (!command) + { + command = new DialogCommand(this); + } + command->setModal(false); + command->show(); + command->raise(); + command->activateWindow(); +} + void MainWindow::on_action_AboutCatRadio_triggered() { QMessageBox msgBox; diff --git a/mainwindow.h b/mainwindow.h index fc85e05..6ce8b66 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -44,6 +44,7 @@ public: public slots: void guiUpdate(); + void rigUpdate(); //Slot for QTimer void on_rigDaemonResultReady(); //Slot for rigDaemon resultReady void on_vfoDisplayMainValueChanged(int value); //Slot for vfoDisplay Main valueChanged void on_vfoDisplaySubValueChanged(int value); //Slot for vfoDisplay Sub valueChanged @@ -203,6 +204,8 @@ private slots: void on_checkBox_micMonitor_toggled(bool checked); + void on_actionCommand_triggered(); + private: Ui::MainWindow *ui; QTimer *timer; diff --git a/mainwindow.ui b/mainwindow.ui index 9597015..69966d0 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -2058,13 +2058,19 @@ - + + + Utility + + + + @@ -2098,9 +2104,9 @@ CatRadio homepage - + - Radio Info + Command diff --git a/rigdaemon.cpp b/rigdaemon.cpp index 49db42e..4712632 100644 --- a/rigdaemon.cpp +++ b/rigdaemon.cpp @@ -28,9 +28,6 @@ #include - -RIG *my_rig; - extern rigConnect rigCom; extern rigSettings rigGet; extern rigSettings rigSet; @@ -46,11 +43,9 @@ RigDaemon::RigDaemon(QObject *parent) : QObject(parent) } -int RigDaemon::rigConnect() +RIG *RigDaemon::rigConnect(int *retcode) { - int retcode; - - my_rig = rig_init(rigCom.rigModel); //Allocate rig handle + RIG *my_rig = rig_init(rigCom.rigModel); //Allocate rig handle if (!my_rig) //Wrong Rig number { @@ -61,7 +56,8 @@ int RigDaemon::rigConnect() msgBox.setStandardButtons(QMessageBox::Ok); msgBox.exec(); - return -1; //RIG_EINVAL, Invalid parameter + *retcode = RIG_EINVAL; //RIG_EINVAL, Invalid parameter + return nullptr; } else { @@ -89,20 +85,19 @@ int RigDaemon::rigConnect() } } - retcode = rig_open(my_rig); + *retcode = rig_open(my_rig); - if (retcode != RIG_OK) return retcode; //Rig not connected + 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); else rigGet.onoff = RIG_POWER_UNKNOWN; - return 0; + return my_rig; } - } } -void RigDaemon::rigUpdate() +void RigDaemon::rigUpdate(RIG *my_rig) { int retcode; value_t retvalue; @@ -305,7 +300,6 @@ void RigDaemon::rigUpdate() if (retcode == RIG_OK) { rigGet.band = rigSet.band; - indexCmd = 21; } } diff --git a/rigdaemon.h b/rigdaemon.h index 4020535..6ce8f73 100644 --- a/rigdaemon.h +++ b/rigdaemon.h @@ -29,10 +29,10 @@ class RigDaemon : public QObject public: explicit RigDaemon(QObject *parent = nullptr); - int rigConnect(); + RIG *rigConnect(int *retcode); + void rigUpdate(RIG *my_rig); public slots: - void rigUpdate(); signals: void resultReady();