kopia lustrzana https://github.com/PianetaRadio/CatRadio
Debug log file
rodzic
b113f5d101
commit
d45bd0c2a1
|
@ -4,6 +4,7 @@ Change log
|
|||
(+ New, * Updated, - Removed)
|
||||
|
||||
1.5.0 - 2025-xx-xx
|
||||
+ Debug log file
|
||||
+ Voice memory keyer (radio or CatRadio)
|
||||
+ CW memory keyer (radio or WinKeyer)
|
||||
+ Check hamlib version on startup
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
/**
|
||||
** This file is part of the CatRadio project.
|
||||
** Copyright 2022-2025 Gianfranco Sordetti IZ8EWD <iz8ewd@pianetaradio.it>.
|
||||
**
|
||||
** This program is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
|
||||
#include "debuglogger.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QTextStream>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
QFile debugLogger::logFile;
|
||||
QMutex debugLogger::mutex;
|
||||
QtMsgType debugLogger::currentDebugLevel = QtInfoMsg; //defaul debug level
|
||||
|
||||
|
||||
debugLogger::debugLogger() {}
|
||||
|
||||
|
||||
void debugLogger::install(QString fileName) //Install the debug message handler
|
||||
{
|
||||
logFile.setFileName(fileName); //Set debug log file
|
||||
if (logFile.open(QIODevice::WriteOnly | QIODevice::Text)) logFile.close();
|
||||
|
||||
qInstallMessageHandler(debugLogger::messageHandler); //Message handler
|
||||
}
|
||||
|
||||
|
||||
void debugLogger::setDebugLevel(QtMsgType level) //Select debug level
|
||||
{
|
||||
//QMutexLocker locker(&mutex);
|
||||
currentDebugLevel = level;
|
||||
}
|
||||
|
||||
|
||||
void debugLogger::messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) //Message handler
|
||||
{
|
||||
QString timestamp = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzztt");
|
||||
QString txt;
|
||||
|
||||
QString contextInfo = QString(" (%1:%2 %3 [%4])")
|
||||
.arg(context.file ? context.file : "unknown")
|
||||
.arg(context.line)
|
||||
.arg(context.function ? context.function : "unknown")
|
||||
.arg(context.category ? context.category : "default");
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case QtDebugMsg: //0
|
||||
fprintf(stderr, "[Debug] %s\n", msg.toLocal8Bit().constData());
|
||||
return;
|
||||
case QtInfoMsg: //4
|
||||
txt = QString("%1: [Info] %2 %3").arg(timestamp, msg, contextInfo);
|
||||
break;
|
||||
case QtWarningMsg: //1
|
||||
txt = QString("%1: [Warning] %2 %3").arg(timestamp, msg, contextInfo);
|
||||
break;
|
||||
case QtCriticalMsg: //2
|
||||
txt = QString("%1: [Critical] %2 %3").arg(timestamp, msg, contextInfo);
|
||||
break;
|
||||
case QtFatalMsg: //3
|
||||
txt = QString("%1: [Fatal] %2 %3").arg(timestamp, msg, contextInfo);
|
||||
break;
|
||||
}
|
||||
|
||||
QMutexLocker locker(&mutex);
|
||||
|
||||
if (type <= currentDebugLevel)
|
||||
{
|
||||
if (logFile.open(QIODevice::Append | QIODevice::Text))
|
||||
{
|
||||
QTextStream out(&logFile);
|
||||
out << txt << Qt::endl;
|
||||
logFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (type == QtFatalMsg)
|
||||
{
|
||||
abort();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
** This file is part of the CatRadio project.
|
||||
** Copyright 2022-2025 Gianfranco Sordetti IZ8EWD <iz8ewd@pianetaradio.it>.
|
||||
**
|
||||
** This program is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
**/
|
||||
|
||||
|
||||
#ifndef DEBUGLOGGER_H
|
||||
#define DEBUGLOGGER_H
|
||||
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
#include <QMutex>
|
||||
#include <QtGlobal>
|
||||
|
||||
|
||||
class debugLogger
|
||||
{
|
||||
public:
|
||||
debugLogger();
|
||||
static void install(QString fileName);
|
||||
static void setDebugLevel(QtMsgType level);
|
||||
|
||||
private:
|
||||
static QFile logFile;
|
||||
static QMutex mutex;
|
||||
static QtMsgType currentDebugLevel;
|
||||
|
||||
static void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
|
||||
};
|
||||
|
||||
#endif // DEBUGLOGGER_H
|
|
@ -32,6 +32,7 @@
|
|||
#include "guidata.h"
|
||||
#include "rigcommand.h"
|
||||
#include "winkeyer.h"
|
||||
#include "debuglogger.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMessageBox>
|
||||
|
@ -86,9 +87,15 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
//* Debug
|
||||
debugLogger::install("catradio.log");
|
||||
if (guiConf.debugMode) debugLogger::setDebugLevel(QtInfoMsg);
|
||||
else debugLogger::setDebugLevel(QtFatalMsg);
|
||||
|
||||
//display name and version in the window title
|
||||
QString version = QString::number(VERSION_MAJ)+"."+QString::number(VERSION_MIN)+"."+QString::number(VERSION_MIC);
|
||||
this->setWindowTitle("CatRadio v."+version+" (Beta)");
|
||||
qInfo() << "CatRadio v."+version;
|
||||
|
||||
QDir::setCurrent(QCoreApplication::applicationDirPath()); //set current path = application path
|
||||
|
||||
|
@ -132,13 +139,13 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
loadCwKeyerConfig("catradio.ini"); //load CW Keyer config
|
||||
}
|
||||
|
||||
//* Debug
|
||||
//* Debug Hamlib
|
||||
if (guiConf.debugMode) rig_set_debug_level(RIG_DEBUG_VERBOSE); //debug verbose
|
||||
else rig_set_debug_level(RIG_DEBUG_WARN); //normal
|
||||
//rig_set_debug_level(RIG_DEBUG_VERBOSE); //debug verbose
|
||||
//rig_set_debug_level(RIG_DEBUG_TRACE); //debug trace
|
||||
rig_set_debug_time_stamp(true);
|
||||
if ((debugFile=fopen("catradio.log","w+")) == NULL) rig_set_debug_level(RIG_DEBUG_NONE);
|
||||
if ((debugFile=fopen("hamlib.log","w+")) == NULL) rig_set_debug_level(RIG_DEBUG_NONE);
|
||||
else rig_set_debug_file(debugFile);
|
||||
|
||||
//* Style
|
||||
|
@ -224,7 +231,7 @@ MainWindow::~MainWindow()
|
|||
rig_cleanup(my_rig); //Release rig handle and free associated memory
|
||||
}
|
||||
|
||||
fclose(debugFile); //Close debug.log
|
||||
fclose(debugFile); //Close hamlib.log
|
||||
|
||||
if (guiConf.cwKeyerMode == 1)
|
||||
{
|
||||
|
@ -245,6 +252,8 @@ MainWindow::~MainWindow()
|
|||
configFile.setValue("WindowSettings/state", saveState());
|
||||
|
||||
delete ui;
|
||||
|
||||
qInfo() << "Close CatRadio";
|
||||
}
|
||||
|
||||
|
||||
|
@ -252,6 +261,8 @@ MainWindow::~MainWindow()
|
|||
|
||||
void MainWindow::guiInit()
|
||||
{
|
||||
qInfo() << "guiInit";
|
||||
|
||||
//* Power on/off cap
|
||||
if (rig_has_set_func(my_rig, RIG_FUNCTION_SET_POWERSTAT)==0)
|
||||
//if (my_rig->caps->set_powerstat == NULL)
|
||||
|
@ -1008,6 +1019,8 @@ bool MainWindow::checkHamlibVersion(int major, int minor, int revision)
|
|||
|
||||
void MainWindow::on_pushButton_Connect_toggled(bool checked)
|
||||
{
|
||||
qInfo() << "Connect" << checked;
|
||||
|
||||
QString connectMsg;
|
||||
|
||||
if (checked && rigCom.connected == 0)
|
||||
|
@ -1022,6 +1035,8 @@ void MainWindow::on_pushButton_Connect_toggled(bool checked)
|
|||
connectMsg = "Connection error: ";
|
||||
connectMsg.append(rigerror(retcode));
|
||||
ui->pushButton_Connect->setChecked(false); //Uncheck the button
|
||||
|
||||
qCritical() << connectMsg;
|
||||
}
|
||||
else //Rig connected
|
||||
{
|
||||
|
@ -1095,6 +1110,8 @@ void MainWindow::on_pushButton_Connect_toggled(bool checked)
|
|||
|
||||
void MainWindow::on_pushButton_Power_toggled(bool checked)
|
||||
{
|
||||
qInfo() << "Power" << checked;
|
||||
|
||||
if (checked && !rigGet.onoff)
|
||||
{
|
||||
retcode = rig_set_powerstat(my_rig, RIG_POWER_ON);
|
||||
|
|
Ładowanie…
Reference in New Issue