first steps

This commit is contained in:
Gerhard Hoffmann 2024-03-11 12:14:28 +01:00
parent 9d4775314c
commit 3568c8ecfb
12 changed files with 239 additions and 193 deletions

View File

@ -1,3 +1,3 @@
TEMPLATE = subdirs
CONFIG += ordered
SUBDIRS = Calculator Utilities CalculatorCInterface
SUBDIRS = Calculator CalculatorCInterface

View File

@ -1,84 +1,23 @@
QT += core
QT+=core
TARGET = calc
CONFIG+=c++20 console
VERSION="0.1.0"
INCLUDEPATH+="../CalculatorCInterface"
win32 {
BUILD_DATE=$$system("date /t")
BUILD_TIME=$$system("time /t")
} else {
BUILD_DATE=$$system("date +%d-%m-%y")
BUILD_TIME=$$system("date +%H:%M:%S")
}
#LIBS += "C:\build-ATBTariffCalculator-Desktop_Qt_6_5_0_MinGW_64_bit-Debug\CalculatorCInterface\debug\libCalculatorCInterface.a"
#LIBS += "C:\build-ATBTariffCalculator-Desktop_Qt_6_5_0_MinGW_64_bit-Debug\CalculatorCInterface\debug\CalculatorCInterface.dll"
GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1")
EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"
CONFIG += c++17
DEFINES+=APP_VERSION=\\\"$$VERSION\\\"
DEFINES+=APP_BUILD_DATE=\\\"$$BUILD_DATE\\\"
DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\"
DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\"
# keep comments, as /* fall through */
QMAKE_CXXFLAGS += -C
QMAKE_CXXFLAGS += -g
QMAKE_CXXFLAGS += -Wno-deprecated-copy -O
INCLUDEPATH+=$$_PRO_FILE_PWD_/../CalculatorCInterface/
LIB_BUILD_DIR="/opt/ptu5/opt/build-ATBTariffCalculator-Desktop_Qt_5_12_12_GCC_64bit-Debug/CalculatorCInterface"
LIBS += -L$$LIB_BUILD_DIR -lCalculatorCInterface
contains( CONFIG, PTU5 ) {
greaterThan(QT_MAJOR_VERSION, 4): QT += serialport
CONFIG += link_pkgconfig
lessThan(QT_MAJOR_VERSION, 5): PKGCONFIG += qextserialport
QMAKE_CXXFLAGS += -O2 -std=c++17 # for GCC >= 4.7
# QMAKE_CXXFLAGS += -Wno-deprecated-copy
ARCH = PTU5
DEFINES+=PTU5
}
contains( CONFIG, PTU5_YOCTO ) {
greaterThan(QT_MAJOR_VERSION, 4): QT += serialport
QMAKE_CXXFLAGS += -std=c++17 # for GCC >= 4.7
# QMAKE_CXXFLAGS += -Wno-deprecated-copy
PTU5BASEPATH = /opt/devel/ptu5
ARCH = PTU5
DEFINES+=PTU5
# add qmqtt lib
#LIBS += -lQt5Qmqtt
}
contains( CONFIG, DesktopLinux ) {
greaterThan(QT_MAJOR_VERSION, 4): QT += serialport
lessThan(QT_MAJOR_VERSION, 5): CONFIG += extserialport
# QMAKE_CC = ccache $$QMAKE_CC
# QMAKE_CXX = ccache $$QMAKE_CXX
QMAKE_CXXFLAGS += -std=c++17
# QMAKE_CXXFLAGS += -Wno-deprecated-copy
linux-clang { QMAKE_CXXFLAGS += -Qunused-arguments }
ARCH = DesktopLinux
DEFINES+=DesktopLinux
}
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp
main.cpp \
message_handler.cpp
# HEADERS += \
# tariff_json_template.h \
# tariff_editor.h
HEADERS += message_handler.h
##########################################################################################
# for running program on target through QtCreator
contains( CONFIG, PTU5 ) {
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/app/tools/atbupdate/
!isEmpty(target.path): INSTALLS += target
}
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

View File

@ -1,10 +1,55 @@
#include <QCoreApplication>
#include <QString>
#include <QDebug>
#include <QLibrary>
#include <stdio.h>
#include <stdlib.h>
#include "message_handler.h"
#include "calculator_c_interface_lib.h"
int main() {
//#include "tariff_calculator.h"
qCritical() << "initTariffEditor" << initTariffEditor();
typedef TariffCalculator *TariffCalculatorHandle;
typedef TariffCalculatorHandle (*NewTariffCalculatorFunc)();
typedef void (*DeleteTariffCalculatorFunc)(TariffCalculatorHandle handle);
//extern "C" {
//#include "calculator_c_interface_lib.h"
//bool __declspec(dllimport) initTariffEditor();
//}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
if (!messageHandlerInstalled()) {
atbInstallMessageHandler(atbDebugOutput);
//setDebugLevel(LOG_NOTICE);
}
QLibrary library("C:\\build-ATBTariffCalculator-Desktop_Qt_6_5_0_MinGW_64_bit-Release\\CalculatorCInterface\\release\\CalculatorCInterface.dll");
if (library.load()) {
qCritical() << "loaded";
NewTariffCalculatorFunc f = (NewTariffCalculatorFunc) library.resolve("NewTariffCalculator");
TariffCalculatorHandle handle = 0;
if (f) {
qCritical() << "resolved";
handle = f();
}
DeleteTariffCalculatorFunc d = (DeleteTariffCalculatorFunc) library.resolve("DeleteTariffCalculator");
if (d) {
qCritical() << "resolved";
d(handle);
}
}
//initTariffEditor();
return 0; // a.exec();
return 0;
}

View File

@ -0,0 +1,107 @@
#include "message_handler.h"
#include <QDateTime>
#include <cstring>
#include <QString>
#include <QFileInfo>
#include <QMessageLogContext>
#define LOG_EMERG 0
#define LOG_ALERT 1
#define LOG_CRIT 2
#define LOG_ERR 3
#define LOG_WARNING 4
#define LOG_NOTICE 5
#define LOG_INFO 6
#define LOG_DEBUG 7
static char const *DBG_NAME[] = { "DBG ", "WARN ", "CRIT ", "FATAL", "INFO " };
static bool installedMsgHandler = false;
static int debugLevel = LOG_NOTICE;
int getDebugLevel() { return debugLevel; }
void setDebugLevel(int newDebugLevel) {
debugLevel = newDebugLevel;
}
bool messageHandlerInstalled() {
return installedMsgHandler;
}
QtMessageHandler atbInstallMessageHandler(QtMessageHandler handler) {
installedMsgHandler = (handler != 0);
static QtMessageHandler prevHandler = nullptr;
if (handler) {
prevHandler = qInstallMessageHandler(handler);
return prevHandler;
} else {
return qInstallMessageHandler(prevHandler);
}
}
///
/// \brief Print message according to given debug level.
///
/// \note Install this function using qInstallMsgHandler().
///
/// int main(int argc, char **argv) {
/// installMsgHandler(atbDebugOutput);
/// QApplication app(argc, argv);
/// ...
/// return app.exec();
/// }
///
//#if (QT_VERSION > QT_VERSION_CHECK(5, 0, 0) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
void atbDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
Q_UNUSED(context);
QString const localMsg = QString(DBG_NAME[type]) + msg.toLocal8Bit();
switch (debugLevel) {
case LOG_DEBUG: { // debug-level message
fprintf(stderr, "LOG_DEBUG %s\n", localMsg.toStdString().c_str());
} break;
case LOG_INFO: { // informational message
if (type != QtDebugMsg) {
fprintf(stderr, "LOG_INFO %s\n", localMsg.toStdString().c_str());
}
} break;
case LOG_NOTICE: { // normal, but significant, condition
if (type != QtDebugMsg) {
fprintf(stderr, "LOG_NOTICE %s\n", localMsg.toStdString().c_str());
}
} break;
case LOG_WARNING: { // warning conditions
if (type != QtInfoMsg && type != QtDebugMsg) {
fprintf(stderr, "LOG_WARN %s\n", localMsg.toStdString().c_str());
}
} break;
case LOG_ERR: { // error conditions
if (type != QtInfoMsg && type != QtDebugMsg && type != QtWarningMsg) {
fprintf(stderr, "LOG_ERR %s\n", localMsg.toStdString().c_str());
}
} break;
case LOG_CRIT: { // critical conditions
if (type != QtInfoMsg && type != QtDebugMsg && type != QtWarningMsg) {
fprintf(stderr, "LOG_CRIT %s\n", localMsg.toStdString().c_str());
}
} break;
case LOG_ALERT: { // action must be taken immediately
if (type != QtInfoMsg && type != QtDebugMsg && type != QtWarningMsg) {
fprintf(stderr, "LOG_ALERT %s\n", localMsg.toStdString().c_str());
}
} break;
case LOG_EMERG: { // system is unusable
if (type != QtInfoMsg && type != QtDebugMsg && type != QtWarningMsg) {
fprintf(stderr, "LOG_EMERG %s\n", localMsg.toStdString().c_str());
}
} break;
default: {
//fprintf(stderr, "%s No ErrorLevel defined! %s\n",
// datetime.toStdString().c_str(), msg.toStdString().c_str());
}
}
}
//#endif

View File

@ -0,0 +1,23 @@
#ifndef MESSAGE_HANDLER_H_INCLUDED
#define MESSAGE_HANDLER_H_INCLUDED
#include <QtGlobal>
#ifdef __linux__
#include <syslog.h>
#endif
int getDebugLevel();
void setDebugLevel(int newDebugLevel);
bool messageHandlerInstalled();
QtMessageHandler atbInstallMessageHandler(QtMessageHandler handler);
//#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
// typedef void (*QtMessageHandler)(QtMsgType, const char *);
//void atbDebugOutput(QtMsgType type, const char *msg);
//#elif QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// typedef void (*QtMessageHandler)(QtMsgType, const QMessageLogContext &, const QString &);
void atbDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg);
//#endif
#endif // MESSAGE_HANDLER_H_INCLUDED

View File

@ -1,13 +1,13 @@
QT -= gui
QT+=core
TEMPLATE = lib
DEFINES += CACULATOR_C_INTERFACE_LIBRARY
DEFINES += CALCULATOR_C_INTERFACE_LIBRARY
# INCLUDEPATH+=$$_PRO_FILE_PWD_/../Utilities/
CONFIG += c++17
QMAKE_CXX=x86_64-w64-mingw32-g++
CONFIG += c++20 console
#QMAKE_CXX=C:\Qt\Tools\mingw1120_64\g++.exe
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
@ -15,12 +15,12 @@ QMAKE_CXX=x86_64-w64-mingw32-g++
SOURCES += \
calculator_c_interface_lib.cpp \
tariff_editor.cpp
tariff_calculator.cpp
HEADERS += \
calculator_c_interface_lib.h \
calculator_c_interface_lib_global.h
tariff_editor.h
calculator_c_interface_lib_global.h \
tariff_calculator.h
# Default rules for deployment.
unix {

View File

@ -1,18 +1,19 @@
#include "calculator_c_interface_lib.h"
#include "tariff_editor.h"
#ifdef __cplusplus
extern "C" {
#endif
bool CACULATOR_C_INTERFACE_LIB_EXPORT initTariffEditor() {
TariffEditor editor;
return true;
TariffCalculatorHandle CALCULATOR_C_INTERFACE_LIB_EXPORT NewTariffCalculator(void) {
return new TariffCalculator();
}
void CALCULATOR_C_INTERFACE_LIB_EXPORT DeleteTariffCalculator(TariffCalculatorHandle handle) {
delete handle;
}
#ifdef __cplusplus
}
#endif

View File

@ -2,19 +2,20 @@
#define CALCULATOR_C_INTERFACE_LIB_H_INCLUDED
#include "calculator_c_interface_lib_global.h"
#include "tariff_calculator.h"
typedef TariffCalculator *TariffCalculatorHandle;
#ifdef __cplusplus
extern "C" {
#endif
bool CACULATOR_C_INTERFACE_LIB_EXPORT initTariffEditor();
TariffCalculatorHandle CALCULATOR_C_INTERFACE_LIB_EXPORT NewTariffCalculator(void);
void CALCULATOR_C_INTERFACE_LIB_EXPORT DeleteTariffCalculator(TariffCalculatorHandle handle);
#ifdef __cplusplus
}
#endif
//{
//public:
// Testlib();
//};
#endif // CALCULATOR_C_INTERFACE_LIB_H_INCLUDED

View File

@ -3,10 +3,10 @@
#include <QtCore/qglobal.h>
#if defined(CACULATOR_C_INTERFACE_LIBRARY)
#define CACULATOR_C_INTERFACE_LIB_EXPORT Q_DECL_EXPORT
#if defined(CALCULATOR_C_INTERFACE_LIBRARY)
#define CALCULATOR_C_INTERFACE_LIB_EXPORT Q_DECL_EXPORT __stdcall
#else
#define CACULATOR_C_INTERFACE_LIB_EXPORT Q_DECL_IMPORT
#define CALCULATOR_C_INTERFACE_LIB_EXPORT Q_DECL_IMPORT __stdcall
#endif
#endif // CALCULATOR_C_INTERFACE_GLOBAL_H

View File

@ -1,4 +1,4 @@
#include "tariff_editor.h"
#include "tariff_calculator.h"
#include <QDebug>
#include <QFile>
@ -10,7 +10,8 @@
#include <QJsonObject>
#include <QJsonValue>
QByteArray TariffEditor::readJson(QString const &filename) {
#if 0
QByteArray TariffCalculator::readJson(QString const &filename) {
QFile f(filename);
if (f.exists()) {
if (f.open(QFile::ReadOnly | QFile::Text)) {
@ -25,10 +26,15 @@ QByteArray TariffEditor::readJson(QString const &filename) {
return QByteArray();
}
#endif
TariffCalculator::~TariffCalculator() {
qCritical() << __func__;
}
TariffEditor::TariffEditor() {
TariffCalculator::TariffCalculator() {
qCritical() << __func__;
return;
// QByteArray ba = readJson("/opt/ptu5/opt/ATBTariffCalculator/Utilities/tariff.template.json");
//QJsonParseError pe;
@ -41,6 +47,7 @@ TariffEditor::TariffEditor() {
//}
m_a = QJsonArray();
createJsonValue("Project", "Szeged");
createJsonValue("Version", "1.0.0");
createJsonValue("Date", "01.01.1970");
@ -56,11 +63,14 @@ TariffEditor::TariffEditor() {
createJsonValue("DayConfigs");
createJsonValue("Days");
m_jsonDoc.setArray(m_a);
qCritical().noquote() << m_jsonDoc.toJson(QJsonDocument::JsonFormat::Indented);
}
void TariffEditor::createJsonValue(QString const &key, QString const &value) {
void TariffCalculator::createJsonValue(QString const &key, QString const &value) {
if ((key.compare("Project", Qt::CaseInsensitive) == 0)
|| (key.compare("Version", Qt::CaseInsensitive) == 0)
@ -421,3 +431,4 @@ void TariffEditor::createJsonValue(QString const &key, QString const &value) {
#endif
}

View File

@ -1,5 +1,5 @@
#ifndef TARIFF_EDITOR_H_INCLUDED
#define TARIFF_EDITOR_H_INCLUDED
#ifndef TARIFF_CALCULATOR_H_INCLUDED
#define TARIFF_CALCULATOR_H_INCLUDED
#include <QByteArray>
#include <QString>
@ -7,14 +7,15 @@
#include <QJsonDocument>
#include <QJsonArray>
class TariffEditor {
class TariffCalculator {
QJsonArray m_a;
QJsonDocument m_jsonDoc;
void createJsonValue(QString const &key, QString const &value = "");
public:
explicit TariffEditor();
explicit TariffCalculator();
~TariffCalculator();
static QByteArray readJson(QString const &filename);
};
#endif // TARIFF_EDITOR_H_INCLUDED
#endif // TARIFF_CALCULATOR_H_INCLUDED

View File

@ -1,82 +0,0 @@
QT += core
TARGET = util
VERSION="0.1.0"
win32 {
BUILD_DATE=$$system("date /t")
BUILD_TIME=$$system("time /t")
} else {
BUILD_DATE=$$system("date +%d-%m-%y")
BUILD_TIME=$$system("date +%H:%M:%S")
}
GIT_COMMIT=$$system("git log -1 --format=oneline | cut -d' ' -f1")
EXTENDED_VERSION="$${VERSION}-$${GIT_COMMIT}"
CONFIG += c++17
DEFINES+=APP_VERSION=\\\"$$VERSION\\\"
DEFINES+=APP_BUILD_DATE=\\\"$$BUILD_DATE\\\"
DEFINES+=APP_BUILD_TIME=\\\"$$BUILD_TIME\\\"
DEFINES+=APP_EXTENDED_VERSION=\\\"$$EXTENDED_VERSION\\\"
# keep comments, as /* fall through */
QMAKE_CXXFLAGS += -C
QMAKE_CXXFLAGS += -g
QMAKE_CXXFLAGS += -Wno-deprecated-copy -O
contains( CONFIG, PTU5 ) {
greaterThan(QT_MAJOR_VERSION, 4): QT += serialport
CONFIG += link_pkgconfig
lessThan(QT_MAJOR_VERSION, 5): PKGCONFIG += qextserialport
QMAKE_CXXFLAGS += -O2 -std=c++17 # for GCC >= 4.7
# QMAKE_CXXFLAGS += -Wno-deprecated-copy
ARCH = PTU5
DEFINES+=PTU5
}
contains( CONFIG, PTU5_YOCTO ) {
greaterThan(QT_MAJOR_VERSION, 4): QT += serialport
QMAKE_CXXFLAGS += -std=c++17 # for GCC >= 4.7
# QMAKE_CXXFLAGS += -Wno-deprecated-copy
PTU5BASEPATH = /opt/devel/ptu5
ARCH = PTU5
DEFINES+=PTU5
# add qmqtt lib
#LIBS += -lQt5Qmqtt
}
contains( CONFIG, DesktopLinux ) {
greaterThan(QT_MAJOR_VERSION, 4): QT += serialport
lessThan(QT_MAJOR_VERSION, 5): CONFIG += extserialport
# QMAKE_CC = ccache $$QMAKE_CC
# QMAKE_CXX = ccache $$QMAKE_CXX
QMAKE_CXXFLAGS += -std=c++17
# QMAKE_CXXFLAGS += -Wno-deprecated-copy
linux-clang { QMAKE_CXXFLAGS += -Qunused-arguments }
ARCH = DesktopLinux
DEFINES+=DesktopLinux
}
SOURCES += \
main.cpp \
tariff_json_template.cpp \
tariff_editor.cpp
HEADERS += \
tariff_json_template.h \
tariff_editor.h
OTHER_FILES += \
tariff.json \
tariff.template.json
##########################################################################################
# for running program on target through QtCreator
contains( CONFIG, PTU5 ) {
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/app/tools/atbupdate/
!isEmpty(target.path): INSTALLS += target
}