diff --git a/printhex.h b/printhex.h new file mode 100644 index 0000000..57878b1 --- /dev/null +++ b/printhex.h @@ -0,0 +1,42 @@ +#ifndef PRINTHEX_H +#define PRINTHEX_H +#include +#include + +#include "logcategories.h" + +QString inline getHex(const QByteArray &pdata) +{ + QString head = "---- Begin hex dump -----:\n"; + QString sdata("DATA: "); + QString index("INDEX: "); + + for(int i=0; i < pdata.length(); i++) + { + sdata.append(QString("%1 ").arg((unsigned char)pdata[i], 2, 16, QChar('0')) ); + index.append(QString("%1 ").arg(i, 2, 10, QChar('0'))); + } + + sdata.append("\n"); + index.append("\n"); + + QString tail = "----- End hex dump -----\n"; + return head + sdata + index + tail; +} + +void inline printHexNow(const QByteArray &pdata, const QLoggingCategory &cat) +{ + QString d = getHex(pdata); + // These lines are needed to keep the formatting as expected in the log file + if(d.endsWith("\n")) + { + d.chop(1); + } + QStringList s = d.split("\n"); + for(int i=0; i < s.length(); i++) + { + qDebug(cat) << s.at(i); + } +} + +#endif // PRINTHEX_H diff --git a/rigcommander.cpp b/rigcommander.cpp index ad33356..0f441e0 100644 --- a/rigcommander.cpp +++ b/rigcommander.cpp @@ -3,6 +3,7 @@ #include "rigidentities.h" #include "logcategories.h" +#include "printhex.h" // Copyright 2017-2020 Elliott H. Liggett @@ -307,8 +308,10 @@ void rigCommander::prepDataAndSend(QByteArray data) if(data[4] != '\x15') { // We don't print out requests for meter levels - qDebug(logRig()) << "Final payload in rig commander to be sent to rig: "; - printHex(data); + qDebug(logRigTraffic()) << "Final payload in rig commander to be sent to rig: "; + //printHex(data); + //printHex(data, logRigTraffic()); + printHexNow(data, logRigTraffic()); } emit dataForComm(data); @@ -1390,7 +1393,8 @@ void rigCommander::parseCommand() { // We do not log spectrum and meter data, // as they tend to clog up any useful logging. - printHex(payloadIn); + qDebug(logRigTraffic()) << "Received from radio:"; + printHexNow(payloadIn, logRigTraffic()); } switch(payloadIn[00]) diff --git a/wfmain.cpp b/wfmain.cpp index 34e3d15..49ea802 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -8201,15 +8201,13 @@ void wfmain::messageHandler(QtMsgType type, const QMessageLogContext& context, c out << context.category << ": " << msg << "\n"; out.flush(); // Clear the buffered data - if(QString(context.category) != QString("rigTraffic")) - { - text.append(context.category); - text.append(": "); - text.append(msg); - logTextMutex.lock(); - logStringBuffer.push_front(text); - logTextMutex.unlock(); - } + text.append(context.category); + text.append(": "); + text.append(msg); + logTextMutex.lock(); + logStringBuffer.push_front(text); + logTextMutex.unlock(); + } void wfmain::on_customEdgeBtn_clicked() diff --git a/wfview.pro b/wfview.pro index 84fd14f..416674c 100644 --- a/wfview.pro +++ b/wfview.pro @@ -238,6 +238,7 @@ HEADERS += wfmain.h \ cwsender.h \ loggingwindow.h \ prefs.h \ + printhex.h \ rigcommander.h \ freqmemory.h \ rigidentities.h \