Skip to content

Commit

Permalink
Merge pull request #1343 from gqrx-sdr/rc-process-multiple-lines
Browse files Browse the repository at this point in the history
Allow remote control commands to be pipelined
  • Loading branch information
argilo authored Mar 20, 2024
2 parents da7012d + ce929ff commit 05dae44
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 66 deletions.
1 change: 1 addition & 0 deletions resources/news.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

NEW: PlutoSDR and LimeSDR support in AppImage release, via SoapySDR.
IMPROVED: Updated GNU Radio, SDR driver, and Qt versions in AppImage release.
FIXED: Respond correctly to pipelined remote control commands.
REMOVED: FreeSRP support in AppImage release.


Expand Down
134 changes: 68 additions & 66 deletions src/applications/gqrx/remote_control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,80 +193,82 @@ void RemoteControl::acceptConnection()
*/
void RemoteControl::startRead()
{
char buffer[1024] = {0};
int bytes_read;
QString answer = "";
while (rc_socket->canReadLine()) {
char buffer[1024] = {0};
int bytes_read;
QString answer = "";

bytes_read = rc_socket->readLine(buffer, 1024);
if (bytes_read < 2) // command + '\n'
return;
bytes_read = rc_socket->readLine(buffer, 1024);
if (bytes_read < 2) // command + '\n'
continue;

#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
QStringList cmdlist = QString(buffer).trimmed().split(" ", QString::SkipEmptyParts);
QStringList cmdlist = QString(buffer).trimmed().split(" ", QString::SkipEmptyParts);
#else
QStringList cmdlist = QString(buffer).trimmed().split(" ", Qt::SkipEmptyParts);
QStringList cmdlist = QString(buffer).trimmed().split(" ", Qt::SkipEmptyParts);
#endif

if (cmdlist.size() == 0)
return;
if (cmdlist.size() == 0)
continue;

QString cmd = cmdlist[0];
if (cmd == "f")
answer = cmd_get_freq();
else if (cmd == "F")
answer = cmd_set_freq(cmdlist);
else if (cmd == "m")
answer = cmd_get_mode();
else if (cmd == "M")
answer = cmd_set_mode(cmdlist);
else if (cmd == "l")
answer = cmd_get_level(cmdlist);
else if (cmd == "L")
answer = cmd_set_level(cmdlist);
else if (cmd == "u")
answer = cmd_get_func(cmdlist);
else if (cmd == "U")
answer = cmd_set_func(cmdlist);
else if (cmd == "v")
answer = cmd_get_vfo();
else if (cmd == "V")
answer = cmd_set_vfo(cmdlist);
else if (cmd == "s")
answer = cmd_get_split_vfo();
else if (cmd == "S")
answer = cmd_set_split_vfo();
else if (cmd == "p")
answer = cmd_get_param(cmdlist);
else if (cmd == "_")
answer = cmd_get_info();
else if (cmd == "AOS")
answer = cmd_AOS();
else if (cmd == "LOS")
answer = cmd_LOS();
else if (cmd == "LNB_LO")
answer = cmd_lnb_lo(cmdlist);
else if (cmd == "\\chk_vfo")
answer = QString("0\n");
else if (cmd == "\\dump_state")
answer = cmd_dump_state();
else if (cmd == "\\get_powerstat")
answer = QString("1\n");
else if (cmd == "q" || cmd == "Q")
{
// FIXME: for now we assume 'close' command
rc_socket->close();
rc_socket->deleteLater();
rc_socket = 0;
return;
}
else
{
// print unknown command and respond with an error
qWarning() << "Unknown remote command:" << cmdlist;
answer = QString("RPRT 1\n");
}

QString cmd = cmdlist[0];
if (cmd == "f")
answer = cmd_get_freq();
else if (cmd == "F")
answer = cmd_set_freq(cmdlist);
else if (cmd == "m")
answer = cmd_get_mode();
else if (cmd == "M")
answer = cmd_set_mode(cmdlist);
else if (cmd == "l")
answer = cmd_get_level(cmdlist);
else if (cmd == "L")
answer = cmd_set_level(cmdlist);
else if (cmd == "u")
answer = cmd_get_func(cmdlist);
else if (cmd == "U")
answer = cmd_set_func(cmdlist);
else if (cmd == "v")
answer = cmd_get_vfo();
else if (cmd == "V")
answer = cmd_set_vfo(cmdlist);
else if (cmd == "s")
answer = cmd_get_split_vfo();
else if (cmd == "S")
answer = cmd_set_split_vfo();
else if (cmd == "p")
answer = cmd_get_param(cmdlist);
else if (cmd == "_")
answer = cmd_get_info();
else if (cmd == "AOS")
answer = cmd_AOS();
else if (cmd == "LOS")
answer = cmd_LOS();
else if (cmd == "LNB_LO")
answer = cmd_lnb_lo(cmdlist);
else if (cmd == "\\chk_vfo")
answer = QString("0\n");
else if (cmd == "\\dump_state")
answer = cmd_dump_state();
else if (cmd == "\\get_powerstat")
answer = QString("1\n");
else if (cmd == "q" || cmd == "Q")
{
// FIXME: for now we assume 'close' command
rc_socket->close();
rc_socket->deleteLater();
rc_socket = 0;
return;
rc_socket->write(answer.toLatin1());
}
else
{
// print unknown command and respond with an error
qWarning() << "Unknown remote command:" << cmdlist;
answer = QString("RPRT 1\n");
}

rc_socket->write(answer.toLatin1());
}

/*! \brief Slot called when the receiver is tuned to a new frequency.
Expand Down

0 comments on commit 05dae44

Please sign in to comment.