Improve logging and some code cleanup

half-duplex
Phil Taylor 2022-04-27 12:56:54 +01:00
rodzic 7f003c588e
commit eb85bb1802
7 zmienionych plików z 74 dodań i 39 usunięć

Wyświetl plik

@ -9,3 +9,4 @@ Q_LOGGING_CATEGORY(logUdp, "udp")
Q_LOGGING_CATEGORY(logUdpServer, "udp.server")
Q_LOGGING_CATEGORY(logRigCtlD, "rigctld")
Q_LOGGING_CATEGORY(logTcpServer, "tcpserver")
Q_LOGGING_CATEGORY(logUsbControl, "usbcontrol")

Wyświetl plik

@ -12,6 +12,7 @@ Q_DECLARE_LOGGING_CATEGORY(logUdp)
Q_DECLARE_LOGGING_CATEGORY(logUdpServer)
Q_DECLARE_LOGGING_CATEGORY(logRigCtlD)
Q_DECLARE_LOGGING_CATEGORY(logTcpServer)
Q_DECLARE_LOGGING_CATEGORY(logUsbControl)
#if defined(Q_OS_WIN) && !defined(__PRETTY_FUNCTION__)

Wyświetl plik

@ -72,9 +72,8 @@ void shuttleSetup::mousePressed(QPoint p)
void shuttleSetup::onEventIndexChanged(int index) {
qDebug() << "On Event for button" << currentButton->num << "Event" << index;
if (currentButton != Q_NULLPTR && index < commands->size()) {
currentButton->onCommand = commands->at(index);
currentButton->onText->setPlainText(currentButton->onCommand.text);
currentButton->onCommand.index = index;
currentButton->onCommand = &commands->at(index);
currentButton->onText->setPlainText(currentButton->onCommand->text);
}
}
@ -82,9 +81,8 @@ void shuttleSetup::onEventIndexChanged(int index) {
void shuttleSetup::offEventIndexChanged(int index) {
qDebug() << "Off Event for button" << currentButton->num << "Event" << index;
if (currentButton != Q_NULLPTR && index < commands->size()) {
currentButton->offCommand = commands->at(index);
currentButton->offText->setPlainText(currentButton->offCommand.text);
currentButton->offCommand.index = index;
currentButton->offCommand = &commands->at(index);
currentButton->offText->setPlainText(currentButton->offCommand->text);
}
}
@ -142,12 +140,14 @@ void shuttleSetup::newDevice(unsigned char devType, QVector<BUTTON>* but, QVecto
// Set button text
for (BUTTON& b : *buttons)
{
b.onText = new QGraphicsTextItem(commands->at(0).text);
b.onCommand = &commands->at(0);
b.onText = new QGraphicsTextItem(b.onCommand->text);
b.onText->setDefaultTextColor(b.textColour);
scene->addItem(b.onText);
b.onText->setPos(b.pos.x(), b.pos.y());
b.offText = new QGraphicsTextItem(commands->at(0).text);
b.offCommand = &commands->at(0);
b.offText = new QGraphicsTextItem(b.offCommand->text);
b.offText->setDefaultTextColor(b.textColour);
scene->addItem(b.offText);
b.offText->setPos(b.pos.x(), b.pos.y()+10);

Wyświetl plik

@ -2,14 +2,16 @@
#include "usbcontroller.h"
#include <QDebug>
#include "logcategories.h"
usbController::usbController()
{
qInfo() << "Starting HID USB device detection";
qInfo(logUsbControl()) << "Starting usbController()";
}
usbController::~usbController()
{
qDebug() << "************ Ending HID";
qInfo(logUsbControl) << "Ending usbController()";
hid_close(handle);
hid_exit();
for (BUTTON& b : buttonList)
@ -131,6 +133,12 @@ void usbController::run()
}
else {
usbDevice = shuttleXpress;
buttonList.append(BUTTON(0, QRect(60, 66, 40, 30), Qt::red));
buttonList.append(BUTTON(1, QRect(114, 50, 40, 30), Qt::red));
buttonList.append(BUTTON(2, QRect(169, 47, 40, 30), Qt::red));
buttonList.append(BUTTON(3, QRect(225, 59, 40, 30), Qt::red));
buttonList.append(BUTTON(4, QRect(41, 132, 40, 30), Qt::red));
}
if (handle)
@ -138,9 +146,27 @@ void usbController::run()
int res;
wchar_t manufacturer[MAX_STR];
wchar_t product[MAX_STR];
wchar_t serial[MAX_STR];
res = hid_get_manufacturer_string(handle, manufacturer, MAX_STR);
if (res > -1)
{
this->manufacturer = QString::fromWCharArray(manufacturer);
}
res = hid_get_product_string(handle, product, MAX_STR);
qInfo() << QString("Found Device: %0 from %1").arg(QString::fromWCharArray(product)).arg(QString::fromWCharArray(manufacturer));
if (res > -1)
{
this->product = QString::fromWCharArray(product);
}
res = hid_get_serial_number_string(handle, serial, MAX_STR);
if (res > -1)
{
this->serial = QString::fromWCharArray(serial);
}
qInfo(logUsbControl()) << QString("Found Device: %0 from %1 S/N %2").arg(this->product).arg(this->manufacturer).arg(this->serial);
hid_set_nonblocking(handle, 1);
emit newDevice(usbDevice,&buttonList, &commands); // Let the UI know we have a new controller
QTimer::singleShot(0, this, SLOT(runTimer()));
@ -155,8 +181,11 @@ void usbController::runTimer()
res = hid_read(handle, (unsigned char*)data.data(), HIDDATALENGTH);
if (res < 0)
{
qInfo() << "USB Device disconnected?";
qInfo(logUsbControl()) << "USB Device disconnected" << this->product;
emit newDevice(0,&buttonList,&commands);
this->product = "";
this->manufacturer = "";
this->serial = "<none>";
hid_close(handle);
QTimer::singleShot(1000, this, SLOT(run()));
return;
@ -165,7 +194,7 @@ void usbController::runTimer()
{
data.resize(res);
/*qDebug() << "usbController Data received " << hex << (unsigned char)data[0] << ":"
/*qDebug(logUsbControl()) << "usbController Data received " << hex << (unsigned char)data[0] << ":"
<< hex << (unsigned char)data[1] << ":"
<< hex << (unsigned char)data[2] << ":"
<< hex << (unsigned char)data[3] << ":"
@ -178,11 +207,11 @@ void usbController::runTimer()
if (tempJogpos == jogpos + 1 || (tempJogpos == 0 && jogpos == 0xff))
{
jogCounter++;
//qDebug() << "JOG PLUS" << jogCounter;
//qDebug(logUsbControl()) << "JOG PLUS" << jogCounter;
}
else if (tempJogpos != jogpos) {
jogCounter--;
//qDebug() << "JOG MINUS" << jogCounter;
//qDebug(logUsbControl()) << "JOG MINUS" << jogCounter;
}
/* Button matrix:
@ -205,23 +234,23 @@ void usbController::runTimer()
*/
if (buttons != tempButtons)
{
//qDebug() << "BUTTON: " << qSetFieldWidth(16) << bin << tempButtons;
//qDebug(logUsbControl()) << "BUTTON: " << qSetFieldWidth(16) << bin << tempButtons;
// Step through all buttons and emit ones that have been pressed.
for (unsigned char i = 0; i < 16; i++)
{
if ((tempButtons >> i & 1) && !(buttons >> i & 1))
{
if (i < buttonList.size()) {
qDebug() << "On Button event:" << buttonList[i].onCommand.text;
emit button(&buttonList[i].onCommand);
if (i < buttonList.size() && buttonList[i].onCommand != Q_NULLPTR && buttonList[i].onCommand->index > 0) {
qDebug() << "On Button event:" << buttonList[i].onCommand->text;
emit button(buttonList[i].onCommand);
}
}
else if ((buttons >> i & 1) && !(tempButtons >> i & 1))
{
if (i < buttonList.size()) {
qDebug() << "Off Button event:" << buttonList[i].offCommand.text;
emit button(&buttonList[i].offCommand);
if (i < buttonList.size() && buttonList[i].offCommand != Q_NULLPTR && buttonList[i].offCommand->index > 0) {
qDebug() << "Off Button event:" << buttonList[i].offCommand->text;
emit button(buttonList[i].offCommand);
}
}
}
@ -270,13 +299,13 @@ void usbController::runTimer()
{
if ((unsigned char)data[3] == 0x01)
{
//qDebug() << "Frequency UP";
//qDebug(logUsbControl()) << "Frequency UP";
jogCounter++;
//emit jogPlus();
}
else if ((unsigned char)data[3] == 0x02)
{
//qDebug() << "Frequency DOWN";
//qDebug(logUsbControl()) << "Frequency DOWN";
emit jogMinus();
jogCounter--;
}
@ -291,17 +320,17 @@ void usbController::runTimer()
{
shutMult = shutpos;
emit doShuttle(true, shutMult);
//qInfo() << "Shuttle PLUS" << shutMult;
//qDebug(logUsbControl()) << "Shuttle PLUS" << shutMult;
}
else if (shutpos > 0xEF) {
shutMult = abs(shutpos - 0xff) + 1;
emit doShuttle(false, shutMult);
//qInfo() << "Shuttle MINUS" << shutMult;
//qDebug(logUsbControl()) << "Shuttle MINUS" << shutMult;
}
if (jogCounter != 0) {
emit sendJog(jogCounter);
//qInfo() << "Change Frequency by" << jogCounter << "hz";
qDebug(logUsbControl()) << "Change Frequency by" << jogCounter << "hz";
jogCounter = 0;
}
@ -328,10 +357,10 @@ void usbController::ledControl(bool on, unsigned char num)
int res = hid_write(handle, (const unsigned char*)data.constData(), 8);
if (res < 0) {
qDebug() << "Unable to write(), Error:" << hid_error(handle);
qDebug(logUsbControl()) << "Unable to write(), Error:" << hid_error(handle);
return;
}
qDebug() << "write() success";
qDebug(logUsbControl()) << "write() success";
}
}

Wyświetl plik

@ -80,8 +80,8 @@ struct BUTTON {
const QColor textColour;
int onEvent = 0;
int offEvent = 0;
COMMAND onCommand;
COMMAND offCommand;
const COMMAND* onCommand=Q_NULLPTR;
const COMMAND* offCommand=Q_NULLPTR;
QGraphicsTextItem* onText;
QGraphicsTextItem* offText;
};
@ -108,7 +108,7 @@ signals:
void doShuttle(bool plus, quint8 level);
void setBand(int band);
void button(COMMAND* cmd);
void button(const COMMAND* cmd);
void newDevice(unsigned char devType, QVector<BUTTON>* but,QVector<COMMAND>* cmd);
private:
hid_device* handle;
@ -124,6 +124,9 @@ private:
unsigned char lastDialPos=0;
QVector<BUTTON> buttonList;
QVector<COMMAND> commands;
QString product="";
QString manufacturer="";
QString serial="<none>";
protected:
};

Wyświetl plik

@ -48,7 +48,7 @@ wfmain::wfmain(const QString serialPortCL, const QString hostCL, const QString s
qRegisterMetaType<QList<radio_cap_packet>>();
qRegisterMetaType<QVector<BUTTON>*>();
qRegisterMetaType<QVector<COMMAND>*>();
qRegisterMetaType<COMMAND*>();
qRegisterMetaType<const COMMAND*>();
qRegisterMetaType<networkStatus>();
haveRigCaps = false;
@ -1291,7 +1291,7 @@ void wfmain::setupUsbControllerDevice()
connect(usbControllerThread, SIGNAL(finished()), usbControllerDev, SLOT(deleteLater()));
connect(usbControllerDev, SIGNAL(sendJog(int)), this, SLOT(changeFrequency(int)));
connect(usbControllerDev, SIGNAL(doShuttle(bool, unsigned char)), this, SLOT(doShuttle(bool, unsigned char)));
connect(usbControllerDev, SIGNAL(button(COMMAND*)), this, SLOT(buttonControl(COMMAND*)));
connect(usbControllerDev, SIGNAL(button(const COMMAND*)), this, SLOT(buttonControl(const COMMAND*)));
connect(usbControllerDev, SIGNAL(setBand(int)), this, SLOT(setBand(int)));
connect(this, SIGNAL(shuttleLed(bool, unsigned char)), usbControllerDev, SLOT(ledControl(bool, unsigned char)));
connect(usbControllerDev, SIGNAL(newDevice(unsigned char, QVector<BUTTON>*, QVector<COMMAND>*)), shut, SLOT(newDevice(unsigned char, QVector<BUTTON>*,QVector<COMMAND>*)));
@ -1337,14 +1337,15 @@ void wfmain::doShuttle(bool up, unsigned char level)
shortcutControlMinus();
}
void wfmain::buttonControl(COMMAND* cmd)
void wfmain::buttonControl(const COMMAND* cmd)
{
if (!cmd->bandswitch) {
qDebug() << "Other command";
//qDebug() << "Other command";
issueCmdUniquePriority((cmds)cmd->command, cmd->suffix);
}
else {
qDebug() << "Bandswitch";
//qDebug() << "Bandswitch";
issueCmdUniquePriority((cmds)cmd->command, (char)cmd->band);
}
}

Wyświetl plik

@ -294,7 +294,7 @@ private slots:
void setRadioTimeDateSend();
void buttonControl(COMMAND* cmd);
void buttonControl(const COMMAND* cmd);
// void on_getFreqBtn_clicked();
@ -927,7 +927,7 @@ Q_DECLARE_METATYPE(QList<radio_cap_packet>)
Q_DECLARE_METATYPE(rigstate*)
Q_DECLARE_METATYPE(QVector <BUTTON>*)
Q_DECLARE_METATYPE(QVector <COMMAND>*)
Q_DECLARE_METATYPE(COMMAND*)
Q_DECLARE_METATYPE(const COMMAND*)
#endif // WFMAIN_H
#endif