Compare commits
12 Commits
197be17615
...
0.0.1
Author | SHA1 | Date | |
---|---|---|---|
b422f82dea
|
|||
30af400779
|
|||
db1b64649b | |||
adce2983ce | |||
568d7d8680 | |||
f650612a63 | |||
129c474691 | |||
a8fa4c2613 | |||
194ecd2771 | |||
a7d7e61d9b | |||
4a3d313deb | |||
ce930f1931 |
@@ -3,3 +3,7 @@ CONFIG += ordered
|
|||||||
SUBDIRS = library main
|
SUBDIRS = library main
|
||||||
|
|
||||||
main.depends = library
|
main.depends = library
|
||||||
|
|
||||||
|
contains( CONFIG, PTU5_YOCTO ) {
|
||||||
|
SUBDIRS = library
|
||||||
|
}
|
@@ -4,6 +4,16 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#ifdef CALCULATE_LIBRARY_EXPORTS
|
||||||
|
#define CALCULATE_LIBRARY_API __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define CALCULATE_LIBRARY_API __declspec(dllimport)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define CALCULATE_LIBRARY_API
|
||||||
|
#endif
|
||||||
|
|
||||||
class Configuration;
|
class Configuration;
|
||||||
|
|
||||||
typedef Configuration parking_tariff_t;
|
typedef Configuration parking_tariff_t;
|
||||||
@@ -12,7 +22,7 @@ typedef Configuration parking_tariff_t;
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct price_t {
|
struct CALCULATE_LIBRARY_API price_t {
|
||||||
uint32_t units;
|
uint32_t units;
|
||||||
double netto;
|
double netto;
|
||||||
double brutto;
|
double brutto;
|
||||||
@@ -20,11 +30,11 @@ struct price_t {
|
|||||||
double vat;
|
double vat;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool init_tariff(parking_tariff_t **tariff, char const *config_file);
|
bool CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff, char const *config_file);
|
||||||
void free_tariff(parking_tariff_t *tariff);
|
void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff);
|
||||||
int get_zone_nr();
|
int CALCULATE_LIBRARY_API get_zone_nr();
|
||||||
|
|
||||||
bool compute_price_for_parking_ticket(parking_tariff_t *tariff,
|
bool CALCULATE_LIBRARY_API compute_price_for_parking_ticket(parking_tariff_t *tariff,
|
||||||
time_t start_parking_time,
|
time_t start_parking_time,
|
||||||
time_t end_parking_time,
|
time_t end_parking_time,
|
||||||
struct price_t *price);
|
struct price_t *price);
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
TARGET = mobility_calc
|
TARGET = mobilisis_calc
|
||||||
# CONFIG += staticlib
|
# CONFIG += staticlib
|
||||||
|
|
||||||
QMAKE_CXXFLAGS += -std=c++17 -g -O0
|
QMAKE_CXXFLAGS += -std=c++17 -g -O0
|
||||||
@@ -8,6 +8,17 @@ INCLUDEPATH += $$_PRO_FILE_PWD_/include
|
|||||||
INCLUDEPATH += $$_PRO_FILE_PWD_/include/mobilisis
|
INCLUDEPATH += $$_PRO_FILE_PWD_/include/mobilisis
|
||||||
INCLUDEPATH += $$_PRO_FILE_PWD_/include/rapidjson
|
INCLUDEPATH += $$_PRO_FILE_PWD_/include/rapidjson
|
||||||
|
|
||||||
|
CONFIG(debug, debug|release) {
|
||||||
|
win32 {
|
||||||
|
QMAKE_CXXFLAGS += -DCALCULATE_LIBRARY_EXPORTS
|
||||||
|
QMAKE_LFLAGS += -Wl,--out-implib,debug\libmobilisis_calc.a
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
win32 {
|
||||||
|
QMAKE_CXXFLAGS += -DCALCULATE_LIBRARY_EXPORTS
|
||||||
|
QMAKE_LFLAGS += -Wl,--out-implib,release\libmobilisis_calc.a
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
src/calculator_functions.cpp \
|
src/calculator_functions.cpp \
|
||||||
|
@@ -10,24 +10,32 @@
|
|||||||
|
|
||||||
static Calculator calculator;
|
static Calculator calculator;
|
||||||
|
|
||||||
int get_zone_nr() {
|
int CALCULATE_LIBRARY_API get_zone_nr() {
|
||||||
QFile zone("/etc/zone_nr");
|
QFile zone("/etc/zone_nr");
|
||||||
if (zone.exists()) {
|
if (zone.exists()) {
|
||||||
QFileInfo finfo(zone);
|
QFileInfo finfo(zone);
|
||||||
if (finfo.size() <= 4) { // decimal 000\n
|
if (finfo.size() <= 4) { // decimal 000\n
|
||||||
if (zone.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
if (zone.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
return zone.readLine().toInt();
|
|
||||||
|
QTextStream in(&zone);
|
||||||
|
return in.readLine(100).toInt();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool init_tariff(parking_tariff_t **tariff, char const *config_file) {
|
bool CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff, char const *config_file) {
|
||||||
*tariff = new Configuration();
|
*tariff = new Configuration();
|
||||||
|
|
||||||
int const zone = get_zone_nr();
|
int const zone = get_zone_nr();
|
||||||
if (zone == -1) {
|
|
||||||
|
// DEBUG
|
||||||
|
qCritical() << "init_tariff:";
|
||||||
|
qCritical() << " ... zone = " << zone;
|
||||||
|
|
||||||
|
if (zone <= 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,27 +44,41 @@ bool init_tariff(parking_tariff_t **tariff, char const *config_file) {
|
|||||||
confFile += "/";
|
confFile += "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
char buffer[16];
|
char buffer[32];
|
||||||
memset(buffer, 0x00, sizeof(buffer));
|
memset(buffer, 0x00, sizeof(buffer));
|
||||||
snprintf(buffer, sizeof(buffer)-1, "tariff%02d.json", zone);
|
snprintf(buffer, sizeof(buffer)-1, "tariff%02d.json", zone);
|
||||||
confFile += buffer;
|
confFile += buffer;
|
||||||
|
|
||||||
|
// DEBUG
|
||||||
|
qCritical() << " ... confFile = " << confFile;
|
||||||
|
|
||||||
QFile fname(confFile);
|
QFile fname(confFile);
|
||||||
if (fname.exists()) {
|
if (fname.exists()) {
|
||||||
|
|
||||||
|
// DEBUG
|
||||||
|
qCritical() << " ... confFile exists";
|
||||||
|
|
||||||
if (fname.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
if (fname.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
|
||||||
|
// DEBUG
|
||||||
|
qCritical() << " ... confFile is open";
|
||||||
|
|
||||||
QString json = fname.readAll();
|
QString json = fname.readAll();
|
||||||
return (*tariff)->ParseJson(*tariff, json.toStdString().c_str());
|
return (*tariff)->ParseJson(*tariff, json.toStdString().c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qCritical() << "init_tariff: Parsing tariff config (" << confFile << ") failed!";
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void free_tariff(parking_tariff_t *tariff) {
|
void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff) {
|
||||||
delete tariff;
|
delete tariff;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool compute_price_for_parking_ticket(parking_tariff_t *tariff,
|
bool CALCULATE_LIBRARY_API compute_price_for_parking_ticket(
|
||||||
|
parking_tariff_t *tariff,
|
||||||
time_t start_parking_time, // in minutes
|
time_t start_parking_time, // in minutes
|
||||||
time_t end_parking_time, // in minutes
|
time_t end_parking_time, // in minutes
|
||||||
struct price_t *price) {
|
struct price_t *price) {
|
||||||
|
@@ -10,16 +10,16 @@ INCLUDEPATH += $$_PRO_FILE_PWD_/../../MOBILISIS-Calculator/library/include/mobil
|
|||||||
INCLUDEPATH += .
|
INCLUDEPATH += .
|
||||||
|
|
||||||
unix {
|
unix {
|
||||||
LIBS += -L$$OUT_PWD/../library/ -lmobility_calc
|
LIBS += -L$$OUT_PWD/../library/ -lmobilisis_calc
|
||||||
}
|
}
|
||||||
|
|
||||||
CONFIG(debug, debug|release) {
|
CONFIG(debug, debug|release) {
|
||||||
win32 {
|
win32 {
|
||||||
LIBS += -L$$OUT_PWD/../library/debug/ -lmobility_calc
|
LIBS += -L$$OUT_PWD/../library/debug/ -lmobilisis_calc
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
win32 {
|
win32 {
|
||||||
LIBS += -L$$OUT_PWD/../library/release/ -lmobility_calc
|
LIBS += -L$$OUT_PWD/../library/release/ -lmobilisis_calc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1
tariffs/tariff04.json
Normal file
1
tariffs/tariff04.json
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user