kopia lustrzana https://gitlab.com/eliggett/wfview
Small fixes for rigctld
rodzic
a115c73848
commit
0e7b63500c
73
rigctld.cpp
73
rigctld.cpp
|
@ -2,7 +2,6 @@
|
||||||
#include "logcategories.h"
|
#include "logcategories.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
rigCtlD::rigCtlD(QObject* parent) :
|
rigCtlD::rigCtlD(QObject* parent) :
|
||||||
QTcpServer(parent)
|
QTcpServer(parent)
|
||||||
{
|
{
|
||||||
|
@ -16,12 +15,15 @@ void rigCtlD::receiveFrequency(freqt freq)
|
||||||
{
|
{
|
||||||
emit setFrequency(freq);
|
emit setFrequency(freq);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rigCtlD::receiveStateInfo(rigStateStruct* state)
|
void rigCtlD::receiveStateInfo(rigStateStruct* state)
|
||||||
{
|
{
|
||||||
qDebug("Setting rig state");
|
qDebug("Setting rig state");
|
||||||
rigState = state;
|
rigState = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int rigCtlD::startServer(qint16 port)
|
int rigCtlD::startServer(qint16 port)
|
||||||
{
|
{
|
||||||
if (!this->listen(QHostAddress::Any, port)) {
|
if (!this->listen(QHostAddress::Any, port)) {
|
||||||
|
@ -55,6 +57,7 @@ void rigCtlD::receiveRigCaps(rigCapabilities caps)
|
||||||
|
|
||||||
rigCtlClient::rigCtlClient(int socketId, rigCapabilities caps, rigStateStruct* state, rigCtlD* parent) : QObject(parent)
|
rigCtlClient::rigCtlClient(int socketId, rigCapabilities caps, rigStateStruct* state, rigCtlD* parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
|
|
||||||
commandBuffer.clear();
|
commandBuffer.clear();
|
||||||
sessionId = socketId;
|
sessionId = socketId;
|
||||||
rigCaps = caps;
|
rigCaps = caps;
|
||||||
|
@ -78,16 +81,24 @@ void rigCtlClient::socketReadyRead()
|
||||||
commandBuffer.append(data);
|
commandBuffer.append(data);
|
||||||
static QString sep = " ";
|
static QString sep = " ";
|
||||||
static int num = 0;
|
static int num = 0;
|
||||||
|
bool longReply = false;
|
||||||
if (commandBuffer.endsWith('\n'))
|
if (commandBuffer.endsWith('\n'))
|
||||||
{
|
{
|
||||||
// Process command
|
qDebug(logRigCtlD()) << sessionId << "command received" << commandBuffer;
|
||||||
|
commandBuffer.chop(1); // Remove \n character
|
||||||
|
if (commandBuffer.endsWith('\r'))
|
||||||
|
{
|
||||||
|
commandBuffer.chop(1); // Remove \n character
|
||||||
|
}
|
||||||
|
|
||||||
|
// We have a full line so process command.
|
||||||
|
|
||||||
if (rigState == Q_NULLPTR)
|
if (rigState == Q_NULLPTR)
|
||||||
{
|
{
|
||||||
qDebug(logRigCtlD()) << "no rigState!";
|
qDebug(logRigCtlD()) << "no rigState!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug(logRigCtlD()) << sessionId << "command received" << commandBuffer;
|
|
||||||
if (commandBuffer[num] == ";" || commandBuffer[num] == "|" || commandBuffer[num] == ",")
|
if (commandBuffer[num] == ";" || commandBuffer[num] == "|" || commandBuffer[num] == ",")
|
||||||
{
|
{
|
||||||
sep = commandBuffer[num].toLatin1();
|
sep = commandBuffer[num].toLatin1();
|
||||||
|
@ -98,45 +109,59 @@ void rigCtlClient::socketReadyRead()
|
||||||
sep = "\n";
|
sep = "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (commandBuffer[num] == "q")
|
else if (commandBuffer[num].toLower() == "q")
|
||||||
{
|
{
|
||||||
closeSocket();
|
closeSocket();
|
||||||
}
|
}
|
||||||
if (commandBuffer.contains("\\chk_vfo"))
|
else if (commandBuffer[num] == "#")
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (commandBuffer[num] == "\\")
|
||||||
|
{
|
||||||
|
num++;
|
||||||
|
longReply = true;
|
||||||
|
}
|
||||||
|
QStringList command = commandBuffer.mid(num).split(" ");
|
||||||
|
|
||||||
|
|
||||||
|
if (command[0] == 0xf0 || command[0]=="chk_vfo")
|
||||||
|
{
|
||||||
|
if (longReply)
|
||||||
|
sendData(QString("0\n"));
|
||||||
|
else
|
||||||
sendData(QString("0\n"));
|
sendData(QString("0\n"));
|
||||||
}
|
}
|
||||||
if (commandBuffer.contains("\\dump_state"))
|
else if (command[0] == "dump_state")
|
||||||
{
|
{
|
||||||
// Currently send "fake" state information until I can work out what is required!
|
// Currently send "fake" state information until I can work out what is required!
|
||||||
sendData(QString("1\n1\n0\n150000.000000 1500000000.000000 0x1ff -1 -1 0x16000003 0xf\n0 0 0 0 0 0 0\n0 0 0 0 0 0 0\n0x1ff 1\n0x1ff 0\n0 0\n0x1e 2400\n0x2 500\n0x1 8000\n0x1 2400\n0x20 15000\n0x20 8000\n0x40 230000\n0 0\n9990\n9990\n10000\n0\n10\n10 20 30\n0x3effffff\n0x3effffff\n0x7fffffff\n0x7fffffff\n0x7fffffff\n0x7fffffff\ndone\n"));
|
sendData(QString("1\n1\n0\n150000.000000 1500000000.000000 0x1ff -1 -1 0x16000003 0xf\n0 0 0 0 0 0 0\n0 0 0 0 0 0 0\n0x1ff 1\n0x1ff 0\n0 0\n0x1e 2400\n0x2 500\n0x1 8000\n0x1 2400\n0x20 15000\n0x20 8000\n0x40 230000\n0 0\n9990\n9990\n10000\n0\n10\n10 20 30\n0x3effffff\n0x3effffff\n0x7fffffff\n0x7fffffff\n0x7fffffff\n0x7fffffff\ndone\n"));
|
||||||
}
|
}
|
||||||
if (commandBuffer[num] == "f" || commandBuffer.contains("\\get_freq"))
|
else if (command[0] == "f" || command[0] == "get_freq")
|
||||||
{
|
{
|
||||||
sendData(QString("%1\n").arg(rigState->vfoAFreq.Hz));
|
sendData(QString("%1\n").arg(rigState->vfoAFreq.Hz));
|
||||||
}
|
}
|
||||||
else if (commandBuffer[num] == "F" || commandBuffer.contains("\\set_freq"))
|
else if (command[0] == "F" || command[0] == "set_freq")
|
||||||
|
{
|
||||||
|
if (command.length()>1)
|
||||||
{
|
{
|
||||||
const QRegExp rx(QLatin1Literal("[^0-9]+"));
|
|
||||||
auto&& parts = commandBuffer.split(rx);
|
|
||||||
freqt freq;
|
freqt freq;
|
||||||
if (parts.length() > 1) {
|
freq.Hz = command[1].toInt();
|
||||||
freq.Hz = parts[1].toInt();
|
|
||||||
emit parent->setFrequency(freq);
|
emit parent->setFrequency(freq);
|
||||||
}
|
}
|
||||||
sendData(QString("RPRT 0\n"));
|
sendData(QString("RPRT 0\n"));
|
||||||
}
|
}
|
||||||
else if (commandBuffer[num] == "1" || commandBuffer.contains("\\dump_caps"))
|
else if (command[0] == "1" || command[0] == "dump_caps")
|
||||||
{
|
{
|
||||||
dumpCaps(sep);
|
dumpCaps(sep);
|
||||||
}
|
}
|
||||||
else if (commandBuffer[num] == "t")
|
else if (command[0] == "t")
|
||||||
{
|
{
|
||||||
sendData(QString("%1\n").arg(rigState->ptt));
|
sendData(QString("%1\n").arg(rigState->ptt));
|
||||||
}
|
}
|
||||||
else if (commandBuffer[num] == "T")
|
else if (command[0] == "T")
|
||||||
{
|
{
|
||||||
if (commandBuffer[num + 2] == "0") {
|
if (command.length()>1 && command[1] == "0") {
|
||||||
emit parent->setPTT(false);
|
emit parent->setPTT(false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -144,26 +169,24 @@ void rigCtlClient::socketReadyRead()
|
||||||
}
|
}
|
||||||
sendData(QString("RPRT 0\n"));
|
sendData(QString("RPRT 0\n"));
|
||||||
}
|
}
|
||||||
else if (commandBuffer[num] == "v")
|
else if (command[0] == "v" || command[0] == "get_vfo")
|
||||||
{
|
{
|
||||||
sendData(QString("VFOA\n"));
|
sendData(QString("VFOA\n"));
|
||||||
}
|
}
|
||||||
else if (commandBuffer[num] == "m")
|
else if (command[0] == "m" || command[0] == "get_mode")
|
||||||
{
|
{
|
||||||
sendData(QString("%1\n%2\n").arg(getMode(rigState->mode,rigState->datamode)).arg(getFilter(rigState->mode,rigState->filter)));
|
sendData(QString("%1\n%2\n").arg(getMode(rigState->mode,rigState->datamode)).arg(getFilter(rigState->mode,rigState->filter)));
|
||||||
}
|
}
|
||||||
else if (commandBuffer[num] == "M")
|
else if (command[0] == "M" || command[0] == "set_mode")
|
||||||
{
|
{
|
||||||
// Set mode
|
// Set mode
|
||||||
const QRegExp rx(QLatin1Literal("\\s+"));
|
if (command.length() > 1) {
|
||||||
auto&& parts = commandBuffer.split(rx);
|
qDebug(logRigCtlD()) << "setting mode: " << getMode(command[1]);
|
||||||
if (parts.length() > 1) {
|
emit parent->setMode(getMode(command[1]), 0x06);
|
||||||
qDebug(logRigCtlD()) << "setting mode: " << getMode(parts[1]);
|
|
||||||
emit parent->setMode(getMode(parts[1]), 0x06);
|
|
||||||
}
|
}
|
||||||
sendData(QString("RPRT 0\n"));
|
sendData(QString("RPRT 0\n"));
|
||||||
}
|
}
|
||||||
else if (commandBuffer[num] == "s")
|
else if (command[0] == "s" || command[0] == "get_split_vfo")
|
||||||
{
|
{
|
||||||
sendData(QString("0\nVFOA\n"));
|
sendData(QString("0\nVFOA\n"));
|
||||||
}
|
}
|
||||||
|
|
35
rigctld.h
35
rigctld.h
|
@ -8,8 +8,40 @@
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
#include <typeindex>
|
||||||
|
|
||||||
#include "rigcommander.h"
|
#include "rigcommander.h"
|
||||||
|
|
||||||
|
typedef void (*voidFunction)(void);
|
||||||
|
struct Interface {
|
||||||
|
|
||||||
|
std::map<std::string, std::pair<voidFunction, std::type_index>> m1;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void insert(std::string s1, std::string s2, T f1) {
|
||||||
|
auto tt = std::type_index(typeid(f1));
|
||||||
|
m1.insert(std::make_pair(s1,
|
||||||
|
std::make_pair((voidFunction)f1, tt)));
|
||||||
|
m1.insert(std::make_pair(s2,
|
||||||
|
std::make_pair((voidFunction)f1, tt)));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, typename... Args>
|
||||||
|
T searchAndCall(std::string s1, Args&&... args) {
|
||||||
|
auto mapIter = m1.find(s1);
|
||||||
|
/*chk if not end*/
|
||||||
|
auto mapVal = mapIter->second;
|
||||||
|
|
||||||
|
// auto typeCastedFun = reinterpret_cast<T(*)(Args ...)>(mapVal.first);
|
||||||
|
auto typeCastedFun = (T(*)(Args ...))(mapVal.first);
|
||||||
|
|
||||||
|
//compare the types is equal or not
|
||||||
|
assert(mapVal.second == std::type_index(typeid(typeCastedFun)));
|
||||||
|
return typeCastedFun(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class rigCtlD : public QTcpServer
|
class rigCtlD : public QTcpServer
|
||||||
{
|
{
|
||||||
|
@ -71,6 +103,9 @@ private:
|
||||||
QString getMode(unsigned char mode, bool datamode);
|
QString getMode(unsigned char mode, bool datamode);
|
||||||
unsigned char getMode(QString modeString);
|
unsigned char getMode(QString modeString);
|
||||||
QString getFilter(unsigned char mode, unsigned char filter);
|
QString getFilter(unsigned char mode, unsigned char filter);
|
||||||
|
|
||||||
|
Interface commands;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Ładowanie…
Reference in New Issue