Пример #1
0
/* Set level */
QString RemoteControl::cmd_set_level(QStringList cmdlist)
{
    QString answer;
    QString lvl = cmdlist.value(1, "");

    if (lvl == "?")
        answer = QString("SQL\n");
    else if (lvl.compare("SQL", Qt::CaseInsensitive) == 0)
    {
        bool ok;
        double squelch = cmdlist.value(2, "ERR").toDouble(&ok);
        if (ok)
        {
            answer = QString("RPRT 0\n");
            squelch_level = std::max<double>(-150, std::min<double>(0, squelch));
            emit newSquelchLevel(squelch_level);
        }
        else
        {
            answer = QString("RPRT 1\n");
        }
    }
    else
    {
        answer = QString("RPRT 1\n");
    }

    return answer;
}
Пример #2
0
/*! \brief Start reading from the socket.
 *
 * This slot is called when the client TCP socket emits a readyRead() signal,
 * i.e. when there is data to read.
 */
void RemoteControl::startRead()
{
    char    buffer[1024] = {0};
    int     bytes_read;

    bool ok = true;

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

    QStringList cmdlist = QString(buffer).trimmed().split(" ", QString::SkipEmptyParts);

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

    // Set new frequency
    if (cmdlist[0] == "F")
    {
        double freq = cmdlist.value(1, "ERR").toDouble(&ok);
        if (ok)
        {
            setNewRemoteFreq((qint64)freq);
            rc_socket->write("RPRT 0\n");
        }
        else
        {
            rc_socket->write("RPRT 1\n");
        }
    }
    // Get frequency
    else if (cmdlist[0] == "f")
    {
        rc_socket->write(QString("%1\n").arg(rc_freq).toLatin1());
    }
    else if (cmdlist[0] == "c")
    {
        // FIXME: for now we assume 'close' command
        rc_socket->close();
    }
    // Set level
    else if (cmdlist[0] == "L")
    {
        QString lvl = cmdlist.value(1, "");
        if (lvl == "?")
        {
            rc_socket->write("SQL\n");
        }
        else if (lvl.compare("SQL", Qt::CaseInsensitive) == 0)
        {
            double squelch = cmdlist.value(2, "ERR").toDouble(&ok);
            if (ok)
            {
                rc_socket->write("RPRT 0\n");
                squelch_level = std::max<double>(-150, std::min<double>(0, squelch));
                emit newSquelchLevel(squelch_level);
            }
            else
            {
                rc_socket->write("RPRT 1\n");
            }
        }
        else
        {
            rc_socket->write("RPRT 1\n");
        }
    }
    // Get level
    else if (cmdlist[0] == "l")
    {
        QString lvl = cmdlist.value(1, "");
        if (lvl == "?")
            rc_socket->write("SQL STRENGTH\n");
        else if (lvl.compare("STRENGTH", Qt::CaseInsensitive) == 0 || lvl.isEmpty())
            rc_socket->write(QString("%1\n").arg(signal_level, 0, 'f', 1).toLatin1());
        else if (lvl.compare("SQL", Qt::CaseInsensitive) == 0)
            rc_socket->write(QString("%1\n").arg(squelch_level, 0, 'f', 1).toLatin1());
        else
            rc_socket->write("RPRT 1\n");
    }
    // Mode and filter
    else if (cmdlist[0] == "M")
    {
        int mode = modeStrToInt(cmdlist.value(1, ""));
        if (mode == -1)
        {
            // invalid string
            rc_socket->write("RPRT 1\n");
        }
        else
        {
            rc_socket->write("RPRT 0\n");
            rc_mode = mode;

            if (rc_mode < 2)
                audio_recorder_status = false;

            emit newMode(rc_mode);
        }
    }
    else if (cmdlist[0] == "m")
    {
        rc_socket->write(QString("%1\n").arg(intToModeStr(rc_mode)).toLatin1());
    }
    else if (cmdlist[0] == "U")
    {
        QString func = cmdlist.value(1, "");
        bool ok;
        int status = cmdlist.value(2, "").toInt(&ok);

        if (func == "?")
        {
            rc_socket->write("RECORD\n");
        }
        else if (func == "" || !ok)
        {
            rc_socket->write("RPRT 1\n");
        }
        else if (func.compare("RECORD", Qt::CaseInsensitive) == 0)
        {
            if (rc_mode < 2 || !receiver_running)
            {
                rc_socket->write("RPRT 1\n");
            }
            else
            {
                rc_socket->write("RPRT 0\n");
                audio_recorder_status = status;
                if (status)
                    emit startAudioRecorderEvent();
                else
                    emit stopAudioRecorderEvent();
            }
        }
        else
        {
            rc_socket->write("RPRT 1\n");
        }
    }
    else if (cmdlist[0] == "u")
    {
        QString func = cmdlist.value(1, "");

        if (func == "?")
            rc_socket->write("RECORD\n");
        else if (func.compare("RECORD", Qt::CaseInsensitive) == 0)
            rc_socket->write(QString("%1\n").arg(audio_recorder_status).toLatin1());
        else
            rc_socket->write("RPRT 1\n");
    }


    // Gpredict / Gqrx specific commands:
    //   AOS  - satellite AOS event
    //   LOS  - satellite LOS event
    else if (cmdlist[0] == "AOS")
    {
        if (rc_mode >= 2 && receiver_running)
        {
            emit startAudioRecorderEvent();
            audio_recorder_status = true;
        }
        rc_socket->write("RPRT 0\n");

    }
    else if (cmdlist[0] == "LOS")
    {
        emit stopAudioRecorderEvent();
        audio_recorder_status = false;
        rc_socket->write("RPRT 0\n");

    }

    /* dump_state used by some clients, e.g. xdx
     * For now just some quick hack that works taken from
     * https://github.com/hexameron/rtl-sdrangelove/blob/master/plugins/channel/tcpsrc/rigctl.cpp
     *
     * More info in tests/rigctl_parse.c
     */
    else if (cmdlist[0] == "\\dump_state")
    {
        rc_socket->write("0\n"
                         "2\n"
                         "1\n"
                         "150000.000000 30000000.000000  0x900af -1 -1 0x10000003 0x3\n"
                         "0 0 0 0 0 0 0\n"
                         "150000.000000 30000000.000000  0x900af -1 -1 0x10000003 0x3\n"
                         "0 0 0 0 0 0 0\n"
                         "0 0\n"
                         "0 0\n"
                         "0\n"
                         "0\n"
                         "0\n"
                         "0\n"
                         "\n"
                         "\n"
                         "0x0\n"
                         "0x0\n"
                         "0x0\n"
                         "0x0\n"
                         "0x0\n"
                         "0\n");
    }

    else
    {
        // print unknown command and respond with an error
        qWarning() << "Unknown remote command:"
                << cmdlist;
        rc_socket->write("RPRT 1\n");
    }
}