From 724a3dc35605821bf9cf21e2b383c19aa8b3c68b Mon Sep 17 00:00:00 2001 From: PianetaRadio <78976006+PianetaRadio@users.noreply.github.com> Date: Mon, 5 Dec 2022 21:02:58 +0100 Subject: [PATCH] Custom command #22 --- dialogcommand.cpp | 53 +++++++++++++++++++++++++++++++++---------- dialogcommand.ui | 58 +++++++++++++++++++++++++++++++++++------------ mainwindow.cpp | 3 ++- 3 files changed, 87 insertions(+), 27 deletions(-) diff --git a/dialogcommand.cpp b/dialogcommand.cpp index e772481..07b1e2b 100644 --- a/dialogcommand.cpp +++ b/dialogcommand.cpp @@ -22,6 +22,11 @@ #include "rig.h" +#include +#include + +#include + DialogCommand::DialogCommand(RIG *rig, QWidget *parent) : QDialog(parent), @@ -29,6 +34,10 @@ DialogCommand::DialogCommand(RIG *rig, QWidget *parent) : { ui->setupUi(this); my_rig = rig; + int backend = RIG_BACKEND_NUM(my_rig->caps->rig_model); + + if (backend == RIG_YAESU || backend == RIG_KENWOOD) ui->radioButton_yaesu->setChecked(true); + else if (backend == RIG_ICOM) ui->radioButton_icom->setChecked(true); } DialogCommand::~DialogCommand() @@ -38,25 +47,45 @@ DialogCommand::~DialogCommand() void DialogCommand::on_pushButton_send_clicked() { - + bool hex = false; //Flag for Hex command QString sendCmdS = ui->lineEdit_commandSend->text(); - const unsigned char *sendCmd = (unsigned char*)sendCmdS.toLatin1().data(); - int sendCmdLen = sendCmdS.size(); - unsigned char termCmd[] = ";"; + QByteArray sendCmdA; + if (sendCmdS.isEmpty()) return; + if (sendCmdS.contains("0x", Qt::CaseInsensitive)) //Hex input + { + sendCmdS = sendCmdS.mid(2); + sendCmdA = QByteArray::fromHex(sendCmdS.toLatin1()); + hex = true; + } + else sendCmdA = sendCmdS.toUtf8(); //Char input - unsigned char rcvdCmd[100]; + QByteArray termCmdA; + termCmdA.resize(1); + if (ui->radioButton_yaesu->isChecked()) termCmdA[0] = ';'; + else if (ui->radioButton_icom->isChecked()) termCmdA[0] = 0xfd; + else if (ui->radioButton_CR->isChecked()) termCmdA[0] = 0x0d; + else if (ui->radioButton_LF->isChecked()) termCmdA[0] = 0x0a; + else termCmdA[0] = '\0'; + unsigned char *termCmd = (unsigned char*)termCmdA.data(); + sendCmdA.append(termCmdA); + unsigned char *sendCmd = (unsigned char*)sendCmdA.data(); + int sendCmdLen = strlen((char*)sendCmd); + + unsigned char rcvdCmd[200]; int rcvdCmdLen = sizeof(rcvdCmd); - //qDebug()< 0) + { + QString rcvdCmdS; + QByteArray rcvdCmdA(QByteArray::fromRawData((char *)rcvdCmd, retLen)); + if (hex) rcvdCmdS = rcvdCmdA.toHex(); + else rcvdCmdS = rcvdCmdA; + ui->lineEdit_receive->setText(rcvdCmdS); + } //int rig_send_raw(rig, const unsigned char *send, int send_len, unsigned char *reply, int reply_len, unsigned char *term); //send contains the raw command data diff --git a/dialogcommand.ui b/dialogcommand.ui index 35d9503..905965d 100644 --- a/dialogcommand.ui +++ b/dialogcommand.ui @@ -13,49 +13,79 @@ Command - + Command Send + + lineEdit_commandSend + - - + + + + Received + + + lineEdit_receive + + - + Send - - + + - Receive + LF - + + + + + + + Close + + + + + + + CR + + + + true - - + + - Icom + Icom 0xfd - - + + - Close + Yaesu/Kwd ; + + + true diff --git a/mainwindow.cpp b/mainwindow.cpp index 52a9c6d..3e9348d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -81,7 +81,8 @@ MainWindow::MainWindow(QWidget *parent) //* Debug rig_set_debug_level(RIG_DEBUG_WARN); //normal - //rig_set_debug_level(RIG_DEBUG_TRACE); //debug + //rig_set_debug_level(RIG_DEBUG_VERBOSE); //debug verbose + //rig_set_debug_level(RIG_DEBUG_TRACE); //debug trace rig_set_debug_time_stamp(true); if ((debugFile=fopen("catradio.log","w+")) == NULL) rig_set_debug_level(RIG_DEBUG_NONE); else rig_set_debug_file(debugFile);