Compare commits
15 Commits
43aac674d1
...
0.0.1
Author | SHA1 | Date | |
---|---|---|---|
b422f82dea
|
|||
30af400779
|
|||
db1b64649b | |||
adce2983ce | |||
568d7d8680 | |||
f650612a63 | |||
129c474691 | |||
a8fa4c2613 | |||
194ecd2771 | |||
a7d7e61d9b | |||
4a3d313deb | |||
ce930f1931 | |||
197be17615 | |||
f69ced3151 | |||
68eed56130 |
@@ -3,3 +3,7 @@ CONFIG += ordered
|
||||
SUBDIRS = library main
|
||||
|
||||
main.depends = library
|
||||
|
||||
contains( CONFIG, PTU5_YOCTO ) {
|
||||
SUBDIRS = library
|
||||
}
|
@@ -4,6 +4,16 @@
|
||||
#include <time.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;
|
||||
|
||||
typedef Configuration parking_tariff_t;
|
||||
@@ -12,7 +22,7 @@ typedef Configuration parking_tariff_t;
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct price_t {
|
||||
struct CALCULATE_LIBRARY_API price_t {
|
||||
uint32_t units;
|
||||
double netto;
|
||||
double brutto;
|
||||
@@ -20,11 +30,11 @@ struct price_t {
|
||||
double vat;
|
||||
};
|
||||
|
||||
bool init_tariff(parking_tariff_t **tariff, char const *config_file);
|
||||
void free_tariff(parking_tariff_t *tariff);
|
||||
int get_zone_nr();
|
||||
bool CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff, char const *config_file);
|
||||
void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *tariff);
|
||||
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 end_parking_time,
|
||||
struct price_t *price);
|
||||
|
@@ -1,12 +1,24 @@
|
||||
TEMPLATE = lib
|
||||
TARGET = mobility_calc
|
||||
TARGET = mobilisis_calc
|
||||
# CONFIG += staticlib
|
||||
|
||||
QMAKE_CXXFLAGS += -std=c++11 -g -O0
|
||||
QMAKE_CXXFLAGS += -std=c++17 -g -O0
|
||||
|
||||
INCLUDEPATH += $$_PRO_FILE_PWD_/include
|
||||
INCLUDEPATH += $$_PRO_FILE_PWD_/include/rapidjson
|
||||
INCLUDEPATH += $$_PRO_FILE_PWD_/include/mobilisis
|
||||
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 += \
|
||||
src/calculator_functions.cpp \
|
||||
|
@@ -10,24 +10,32 @@
|
||||
|
||||
static Calculator calculator;
|
||||
|
||||
int get_zone_nr() {
|
||||
int CALCULATE_LIBRARY_API get_zone_nr() {
|
||||
QFile zone("/etc/zone_nr");
|
||||
if (zone.exists()) {
|
||||
QFileInfo finfo(zone);
|
||||
if (finfo.size() <= 4) { // decimal 000\n
|
||||
if (zone.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
return zone.readLine().toInt();
|
||||
|
||||
QTextStream in(&zone);
|
||||
return in.readLine(100).toInt();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
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();
|
||||
|
||||
int const zone = get_zone_nr();
|
||||
if (zone == -1) {
|
||||
|
||||
// DEBUG
|
||||
qCritical() << "init_tariff:";
|
||||
qCritical() << " ... zone = " << zone;
|
||||
|
||||
if (zone <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -36,27 +44,41 @@ bool init_tariff(parking_tariff_t **tariff, char const *config_file) {
|
||||
confFile += "/";
|
||||
}
|
||||
|
||||
char buffer[16];
|
||||
char buffer[32];
|
||||
memset(buffer, 0x00, sizeof(buffer));
|
||||
snprintf(buffer, sizeof(buffer)-1, "tariff%02d.json", zone);
|
||||
confFile += buffer;
|
||||
|
||||
// DEBUG
|
||||
qCritical() << " ... confFile = " << confFile;
|
||||
|
||||
QFile fname(confFile);
|
||||
if (fname.exists()) {
|
||||
|
||||
// DEBUG
|
||||
qCritical() << " ... confFile exists";
|
||||
|
||||
if (fname.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
|
||||
// DEBUG
|
||||
qCritical() << " ... confFile is open";
|
||||
|
||||
QString json = fname.readAll();
|
||||
return (*tariff)->ParseJson(*tariff, json.toStdString().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
qCritical() << "init_tariff: Parsing tariff config (" << confFile << ") failed!";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void free_tariff(parking_tariff_t *tariff) {
|
||||
void CALCULATE_LIBRARY_API free_tariff(parking_tariff_t *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 end_parking_time, // in minutes
|
||||
struct price_t *price) {
|
||||
|
@@ -1,4 +1,29 @@
|
||||
#include "calculate_price.h"
|
||||
#include <calculate_price.h>
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#include <time.h>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
extern "C" char* strptime(const char* s,
|
||||
const char* f,
|
||||
struct tm* tm) {
|
||||
// Isn't the C++ standard lib nice? std::get_time is defined such that its
|
||||
// format parameters are the exact same as strptime. Of course, we have to
|
||||
// create a string stream first, and imbue it with the current C locale, and
|
||||
// we also have to make sure we return the right things if it fails, or
|
||||
// if it succeeds, but this is still far simpler an implementation than any
|
||||
// of the versions in any of the C standard libraries.
|
||||
std::istringstream input(s);
|
||||
input.imbue(std::locale(setlocale(LC_ALL, nullptr)));
|
||||
input >> std::get_time(tm, f);
|
||||
if (input.fail()) {
|
||||
return nullptr;
|
||||
}
|
||||
return (char*)(s + input.tellg());
|
||||
}
|
||||
#endif
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDateTime>
|
||||
|
@@ -6,9 +6,22 @@ CONFIG += -std=c++11
|
||||
QMAKE_CFLAGS = -c -pipe -std=c11 -g -O0 -Wall -Wno-attributes -W -DDEBUG -D_REENTRANT -fPIC
|
||||
QMAKE_CXX_FLAGS += -std=c11
|
||||
|
||||
INCLUDEPATH += $$_PRO_FILE_PWD_/../../MOBILISIS_Calculator/library/include/mobilisis/
|
||||
INCLUDEPATH += $$_PRO_FILE_PWD_/../../MOBILISIS-Calculator/library/include/mobilisis/
|
||||
INCLUDEPATH += .
|
||||
LIBS += -L$$OUT_PWD/../library/ -lmobility_calc
|
||||
|
||||
unix {
|
||||
LIBS += -L$$OUT_PWD/../library/ -lmobilisis_calc
|
||||
}
|
||||
|
||||
CONFIG(debug, debug|release) {
|
||||
win32 {
|
||||
LIBS += -L$$OUT_PWD/../library/debug/ -lmobilisis_calc
|
||||
}
|
||||
} else {
|
||||
win32 {
|
||||
LIBS += -L$$OUT_PWD/../library/release/ -lmobilisis_calc
|
||||
}
|
||||
}
|
||||
|
||||
SOURCES += main.cpp
|
||||
|
||||
|
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