Fix: Read PTU zone info

This commit is contained in:
Siegfried Siegert 2023-05-05 13:19:02 +02:00
parent db1b64649b
commit 30af400779
Signed by: SiegfriedSiegert
GPG Key ID: 68371E015E8F0B03

View File

@ -16,7 +16,10 @@ int CALCULATE_LIBRARY_API get_zone_nr() {
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();
} }
} }
} }
@ -27,7 +30,12 @@ bool CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff, char const *co
*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,7 +44,7 @@ bool CALCULATE_LIBRARY_API init_tariff(parking_tariff_t **tariff, char const *co
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;