checkin to test under windows

This commit is contained in:
Gerhard Hoffmann 2024-03-04 16:23:10 +01:00
parent 05c9a1dcf2
commit 6f338cc389
7 changed files with 560 additions and 5693 deletions

View File

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

View File

@ -0,0 +1,84 @@
QT += core
TARGET = calc
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
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
}
SOURCES += \
main.cpp
# HEADERS += \
# tariff_json_template.h \
# tariff_editor.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
}

View File

@ -1,7 +1,6 @@
QT += core
QT += serialport network
TARGET = ATBDownloadDCFirmware
TARGET = util
VERSION="0.1.0"
win32 {
@ -63,11 +62,11 @@ contains( CONFIG, DesktopLinux ) {
SOURCES += \
main.cpp \
tariff_json_template.cpp \
tariff_json_parser.cpp
tariff_editor.cpp
HEADERS += \
tariff_json_template.h \
tariff_json_parser.h
tariff_editor.h
OTHER_FILES += \
tariff.json \

View File

@ -1,9 +1,15 @@
#include <QtGlobal>
#include <QDebug>
#include "tariff_editor.h"
int main(int argc, char **argv) {
Q_UNUSED(argc);
Q_UNUSED(argv);
TariffEditor editor;
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,423 @@
#include "tariff_editor.h"
#include <QDebug>
#include <QFile>
#include <QTextStream>
#include <QDateTime>
#include <QJsonDocument>
#include <QJsonParseError>
#include <QJsonArray>
#include <QJsonObject>
#include <QJsonValue>
QByteArray TariffEditor::readJson(QString const &filename) {
QFile f(filename);
if (f.exists()) {
if (f.open(QFile::ReadOnly | QFile::Text)) {
QTextStream in(&f);
return in.readAll().toUtf8();
} else {
qCritical() << filename << "not readable";
}
} else {
qCritical() << filename << "does not exist";
}
return QByteArray();
}
TariffEditor::TariffEditor() {
// QByteArray ba = readJson("/opt/ptu5/opt/ATBTariffCalculator/Utilities/tariff.template.json");
//QJsonParseError pe;
//m_jsonDoc = QJsonDocument::fromJson(ba, &pe);
//if (pe.error == QJsonParseError::NoError) {
// qCritical().noquote() << m_jsonDoc.toJson(QJsonDocument::JsonFormat::Indented);
//} else {
// qCritical() << __func__ << pe.errorString();
//
//}
m_a = QJsonArray();
createJsonValue("Project", "Szeged");
createJsonValue("Version", "1.0.0");
createJsonValue("Date", "01.01.1970");
createJsonValue("Committer", "");
createJsonValue("Info", "");
createJsonValue("Products");
createJsonValue("Accuracy");
createJsonValue("Type");
createJsonValue("Price");
createJsonValue("Config");
createJsonValue("TimeRanges");
createJsonValue("Periods");
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) {
if ((key.compare("Project", Qt::CaseInsensitive) == 0)
|| (key.compare("Version", Qt::CaseInsensitive) == 0)
|| (key.compare("Date", Qt::CaseInsensitive) == 0)
|| (key.compare("Committer", Qt::CaseInsensitive) == 0)
|| (key.compare("Info", Qt::CaseInsensitive) == 0)) {
m_a.push_back(QJsonValue({QPair(key, QJsonValue(value))}));
} else
if (key.compare("Accuracy", Qt::CaseInsensitive) == 0) {
QJsonObject o({
QPair(QString("accuracy_id"), QJsonValue(1)),
QPair(QString("accuracy_label"), QJsonValue(QString("computation-to-the-minute"))),
QPair(QString("accuracy_value"), QJsonValue(1)),
QPair(QString("comment"), QJsonValue(QString("accuracy of tariff computation is individual minutes")))});
m_a.push_back(QJsonObject({QPair(key, QJsonValue(o))}));
} else
if (key.compare("Type", Qt::CaseInsensitive) == 0) {
QJsonObject o({
QPair(QString("type_id"), QJsonValue(1)),
QPair(QString("type_label"), QJsonValue(QString("uniform-minutes"))),
QPair(QString("comment"), QJsonValue(QString("same price for all minutes")))});
m_a.push_back(QJsonObject({QPair(key, QJsonValue(o))}));
} else
if (key.compare("Price", Qt::CaseInsensitive) == 0) {
QJsonObject o1({
QPair(QString("price_id"), QJsonValue(1)),
QPair(QString("price"), QJsonValue(165)),
QPair(QString("editable"), QJsonValue(true)),
QPair(QString("comment"), QJsonValue(QString("price per hour as provided by customer")))});
QJsonObject o2({
QPair(QString("price_id"), QJsonValue(2)),
QPair(QString("price"), QJsonValue(990)),
QPair(QString("editable"), QJsonValue(true)),
QPair(QString("comment"), QJsonValue(QString("price for dayticket as provided by customer")))});
QJsonArray a;
a.push_back(o1);
a.push_back(o2);
m_a.push_back(QJsonObject({QPair(key, QJsonValue(a))}));
} else
if (key.compare("Config", Qt::CaseInsensitive) == 0) {
QJsonObject o1({
QPair(QString("value"), QJsonValue(15)),
QPair(QString("editable"), QJsonValue(true)),
QPair(QString("comment"), QJsonValue(QString("minimal parking time in minutes (net)")))});
QJsonObject o2({
QPair(QString("value"), QJsonValue(360)),
QPair(QString("editable"), QJsonValue(true)),
QPair(QString("comment"), QJsonValue(QString("maximal parking time in minutes (net)")))});
QJsonObject o3({
QPair(QString("value"), QJsonValue(1)),
QPair(QString("comment"), QJsonValue(QString("price-id of customer entered price (for hour) expressed in minimal time: 15*(165/60) = 41.25")))});
QJsonObject o4({
QPair(QString("value"), QJsonValue(1)),
QPair(QString("comment"), QJsonValue(QString("price-id of customer entered price (for hour) expressed in maximal time: 360*(165/60) = 990")))});
QJsonObject o5({
QPair(QString("comment"), QJsonValue(QString("general tariff config"))),
QPair(QString("config_id"), QJsonValue(1)),
QPair(QString("config_label"), QJsonValue("Tariff Config 1")),
QPair(QString("config_tariff_accuracy"), QJsonValue(1)),
QPair(QString("config_tariff_type"), QJsonValue(1)),
QPair(QString("config_carry_over"), QJsonValue(true)),
QPair(QString("config_prepaid"), QJsonValue(true)),
QPair(QString("MinimalTime"), QJsonValue(o1)),
QPair(QString("MaximalTime"), QJsonValue(o2)),
QPair(QString("MinimalPrice"), QJsonValue(o3)),
QPair(QString("MinimalPrice"), QJsonValue(o4))});
m_a.push_back(QJsonObject({QPair(key, QJsonValue(o5))}));
} else
if (key.compare("Products", Qt::CaseInsensitive) == 0) {
QJsonObject o1({
QPair(QString("product_id"), QJsonValue(1)),
QPair(QString("product_price_id"), QJsonValue(1)),
QPair(QString("product_label"), QJsonValue(QString("SHORT_TIME_PARKING")))});
QJsonObject o2({
QPair(QString("product_id"), QJsonValue(2)),
QPair(QString("product_price_id"), QJsonValue(2)),
QPair(QString("product_time_ranges"), QJsonArray({QJsonValue(100001)})),
QPair(QString("product_label"), QJsonValue(QString("DAY_TICKET")))});
QJsonArray a;
a.push_back(o1);
a.push_back(o2);
m_a.push_back(QJsonObject({QPair(key, QJsonValue(a))}));
} else
if (key.compare("TimeRanges", Qt::CaseInsensitive) == 0) {
QJsonObject o1({
QPair(QString("range_id"), QJsonValue(1)),
QPair(QString("range_price_id"), QJsonValue(0)),
QPair(QString("range_start"), QJsonValue(QString("00:00:00"))),
QPair(QString("range_end"), QJsonValue(QString("00:00:00"))),
QPair(QString("comment"), QJsonValue(QString("[ 00:00-00:00 [ = [ 00:00-24:00 [")))});
QJsonObject o2({
QPair(QString("range_id"), QJsonValue(1)),
QPair(QString("range_price_id"), QJsonValue(1)),
QPair(QString("range_start"), QJsonValue(QString("00:00:00"))),
QPair(QString("range_end"), QJsonValue(QString("08:00:00"))),
QPair(QString("comment"), QJsonValue(QString("[ 00:00-08:00 [")))});
QJsonObject o3({
QPair(QString("range_id"), QJsonValue(1)),
QPair(QString("range_price_id"), QJsonValue(2)),
QPair(QString("range_start"), QJsonValue(QString("18:00:00"))),
QPair(QString("range_end"), QJsonValue(QString("00:00:00"))),
QPair(QString("comment"), QJsonValue(QString("[ 18:00-00:00 [")))});
QJsonObject o4({
QPair(QString("range_id"), QJsonValue(1)),
QPair(QString("range_price_id"), QJsonValue(3)),
QPair(QString("range_start"), QJsonValue(QString("12:00:00"))),
QPair(QString("range_end"), QJsonValue(QString("00:00:00"))),
QPair(QString("comment"), QJsonValue(QString("[ 12:00-00:00 [")))});
QJsonArray a;
a.push_back(o1);
a.push_back(o2);
a.push_back(o3);
a.push_back(o4);
QTime const t(8,0,0);
QJsonArray b;
for (int i=0; i<600; ++i) {
QTime const &start = t.addSecs(i*60);
QTime const &end = t.addSecs((i+1)*60);
QJsonObject o({
QPair(QString("range_id"), QJsonValue(i)),
QPair(QString("range_price_id"), QJsonValue(0)),
QPair(QString("range_start"), QJsonValue(start.toString(Qt::ISODate))),
QPair(QString("range_end"), QJsonValue(end.toString(Qt::ISODate)))});
b.push_back(o);
}
a.push_back(b);
m_a.push_back(QJsonObject({QPair(key, QJsonValue(a))}));
} else
if (key.compare("Periods", Qt::CaseInsensitive) == 0) {
QJsonObject o1({
QPair(QString("period_id"), QJsonValue(1)),
QPair(QString("period_label"), QJsonValue("1st quarter")),
QPair(QString("period_from"), QJsonValue(QString("1970-01-01"))),
QPair(QString("period_until"), QJsonValue(QString("1970-03-31")))});
QJsonObject o2({
QPair(QString("period_id"), QJsonValue(2)),
QPair(QString("period_label"), QJsonValue("2nd quarter")),
QPair(QString("period_from"), QJsonValue(QString("1970-04-01"))),
QPair(QString("period_until"), QJsonValue(QString("1970-06-30")))});
QJsonObject o3({
QPair(QString("period_id"), QJsonValue(3)),
QPair(QString("period_label"), QJsonValue("3rd quarter")),
QPair(QString("period_from"), QJsonValue(QString("1970-07-01"))),
QPair(QString("period_until"), QJsonValue(QString("1970-09-30")))});
QJsonObject o4({
QPair(QString("period_id"), QJsonValue(4)),
QPair(QString("period_label"), QJsonValue("4th quarter")),
QPair(QString("period_from"), QJsonValue(QString("1970-10-01"))),
QPair(QString("period_until"), QJsonValue(QString("1970-12-31")))});
QJsonObject o5({
QPair(QString("period_id"), QJsonValue(5)),
QPair(QString("period_label"), QJsonValue("1st half-year")),
QPair(QString("period_from"), QJsonValue(QString("1970-01-01"))),
QPair(QString("period_until"), QJsonValue(QString("1970-06-30")))});
QJsonObject o6({
QPair(QString("period_id"), QJsonValue(6)),
QPair(QString("period_label"), QJsonValue("2nd half-year")),
QPair(QString("period_from"), QJsonValue(QString("1970-07-01"))),
QPair(QString("period_until"), QJsonValue(QString("1970-12-31")))});
QJsonArray a;
a.push_back(o1);
a.push_back(o2);
a.push_back(o3);
a.push_back(o4);
a.push_back(o5);
a.push_back(o6);
m_a.push_back(QJsonObject({QPair(key, QJsonValue(a))}));
} else
if (key.compare("DayConfigs", Qt::CaseInsensitive) == 0) {
QJsonArray b;
b.push_back(QJsonValue(100002));
for (int i=0; i<600; ++i) {
b.push_back(QJsonValue(i));
}
b.push_back(QJsonValue(100003));
QJsonArray c;
c.push_back(QJsonValue(100001));
QJsonObject o1({
QPair(QString("day_config_id"), QJsonValue(1)),
QPair(QString("day_config_range"), QJsonValue(6)),
QPair(QString("day_config_product_ids"), QJsonArray({QJsonValue(0), QJsonValue(1)})),
QPair(QString("day_config_short_time_parking"), b),
QPair(QString("day_config_day_ticket"), c)});
QJsonObject o2({QPair(QString("DayConfig_1"), QJsonValue(o1))});
QJsonObject o3({
QPair(QString("day_config_id"), QJsonValue(2)),
QPair(QString("day_config_range"), QJsonValue(6)),
QPair(QString("day_config_product_ids"), QJsonArray({QJsonValue(1)})),
QPair(QString("day_config_day_ticket"), c)});
QJsonObject o4({QPair(QString("DayConfig_2"), QJsonValue(o3))});
QJsonArray a;
a.push_back(o2);
a.push_back(o4);
m_a.push_back(QJsonObject({QPair(key, QJsonValue(a))}));
} else
if (key.compare("Days", Qt::CaseInsensitive) == 0) {
QJsonArray b;
for (int i=1; i < 8; ++i) {
QJsonObject o1({
QPair(QString("day_id"), QJsonValue(1)),
QPair(QString("day_config_id"), QJsonValue(0))});
switch(i) {
case Qt::Monday: {
QJsonObject o2({QPair(QString("Mon"), QJsonValue(o1))});
b.push_back(o2);
} break;
case Qt::Tuesday: {
QJsonObject o2({QPair(QString("Tue"), QJsonValue(o1))});
b.push_back(o2);
} break;
case Qt::Wednesday: {
QJsonObject o2({QPair(QString("Wed"), QJsonValue(o1))});
b.push_back(o2);
} break;
case Qt::Thursday: {
QJsonObject o2({QPair(QString("Thu"), QJsonValue(o1))});
b.push_back(o2);
} break;
case Qt::Friday: {
QJsonObject o2({QPair(QString("Fri"), QJsonValue(o1))});
b.push_back(o2);
} break;
case Qt::Saturday: {
QJsonObject o2({QPair(QString("Sat"), QJsonValue(o1))});
b.push_back(o2);
} break;
case Qt::Sunday: {
QJsonObject o2({QPair(QString("Sun"), QJsonValue(o1))});
b.push_back(o2);
} break;
}
}
QJsonArray c;
QJsonObject o1({
QPair(QString("day_id"), QJsonValue(1)),
QPair(QString("day_config_id"), QJsonValue(1)),
QPair(QString("day_date"), QJsonValue(QString("2024-12-25"))),
QPair(QString("day_movable"), QJsonValue(false))});
QJsonObject o2({
QPair(QString("day_id"), QJsonValue(2)),
QPair(QString("day_config_id"), QJsonValue(1)),
QPair(QString("day_date"), QJsonValue(QString("2024-12-26"))),
QPair(QString("day_movable"), QJsonValue(false))});
c.push_back(o1);
c.push_back(o2);
QJsonObject o3({QPair(QString("Weekdays"), b),
QPair(QString("Holidays"), c)});
//"Christmas_1st_day": {
// "day_id": 8,
// "day_config_id": 1,
// "day_date": "2024-12-25",
// "day_moveable": false
//},
//"Christmas_2nd_day": {
// "day_id": 9,
// "day_config_id": 1,
// "day_date": "2024-12-26",
// "day_moveable": false
//}
m_a.push_back(QJsonObject({QPair(key, QJsonValue(o3))}));
}
#if 0
"TariffDays": [
"Mon": {
"day_id": 1,
"day_config_id": 0
},
"Tue": {
"day_id": 2,
"day_config_id": 0
},
"Wed": {
"day_id": 3,
"day_config_id": 0
},
"Thu": {
"day_id": 4,
"day_config_id": 0
},
"Fri": {
"day_id": 5,
"day_config_id": 0
},
"Sat": {
"day_id": 6,
"day_config_id": 0
},
"Sun": {
"day_id": 7,
"day_config_id": 0
},
"Christmas_1st_day": {
"day_id": 8,
"day_config_id": 1,
"day_date": "2024-12-25",
"day_moveable": false
},
"Christmas_2nd_day": {
"day_id": 9,
"day_config_id": 1,
"day_date": "2024-12-26",
"day_moveable": false
}
// usw. die anderen Feiertage un
"DayConfig_1": {
"day_config_id": 0,
"day_config_date_range": 6,
"comment_1": "day config is valid for the whole year",
"day_config_product_ids": [0, 1],
"comment_2": "short-time-parking or day-ticket on this day",
#endif
}

View File

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