diff options
author | Anton Luka Šijanec <anton@sijanec.eu> | 2022-10-15 19:15:27 +0200 |
---|---|---|
committer | Anton Luka Šijanec <anton@sijanec.eu> | 2022-10-15 19:15:27 +0200 |
commit | a622a8159ac7e093ed0239d4de4502e393d332cc (patch) | |
tree | 4f2087567fcbbb6e80b51d4173579173b2765f31 /srv/c.c | |
parent | reports us (diff) | |
download | števec-a622a8159ac7e093ed0239d4de4502e393d332cc.tar števec-a622a8159ac7e093ed0239d4de4502e393d332cc.tar.gz števec-a622a8159ac7e093ed0239d4de4502e393d332cc.tar.bz2 števec-a622a8159ac7e093ed0239d4de4502e393d332cc.tar.lz števec-a622a8159ac7e093ed0239d4de4502e393d332cc.tar.xz števec-a622a8159ac7e093ed0239d4de4502e393d332cc.tar.zst števec-a622a8159ac7e093ed0239d4de4502e393d332cc.zip |
Diffstat (limited to '')
-rw-r--r-- | srv/c.c | 30 |
1 files changed, 25 insertions, 5 deletions
@@ -29,11 +29,14 @@ int najdi (struct entry * db, int first, int last, long long int čas) { int main (int argc, char ** argv) { int r = 0; if (argc < 1+2) - error_at_line(1, 0, __FILE__, __LINE__, "uporaba: %s db informacije/preveri/rast/seštevek [natančnost=0] [začetek UNIXsek] [konec UNIXsek]\n\t" + error_at_line(1, 0, __FILE__, __LINE__, +"uporaba: %s db infor/preveri/rast/seštevek [natančnost] [začetek UNIX] [konec UNIX]\n\t" "informacije: pove UNIXus prvega in UNIXus zadnjega zapisa\n\t" "preveri: pove, če čas ni naraščajoč in kdaj se je števec resetiral\n\t" "rast: TSV s podatki <UNIXus>:<Wh skupno> najgosteje na [natančnost=0] ms\n\t" -"seštevek: TSV s podatki <UNIXus>:<vatnih ur v [natančnost=10e3] ms>", S0(argv[0])); +"seštevek: TSV s podatki <UNIXus>:<vatnih ur v [natančnost=10e3] ms>\n\t" +"če je nastavljena okoljska spremenljivka SEK, bodo izhodni časi v UNIX sekundah", + S0(argv[0])); int fd = -1; struct entry * db = NULL; if ((fd = open(argv[1], O_RDONLY | O_CLOEXEC)) == -1) @@ -51,7 +54,15 @@ int main (int argc, char ** argv) { goto r; } if (argv[2][0] == 'i') { - printf("začetek\t%" PRIu64 " UNIXus\t%" PRIu64 " Wh\nkonec\t%" PRIu64 " UNIXus\t%" PRIu64 " Wh\nzapisov: %u\n", be64toh(db[0].time), be64toh(db[0].value), be64toh(db[entries-1].time), be64toh(db[entries-1].value), entries); + uint64_t začetek = be64toh(db[0].time); + uint64_t konec = be64toh(db[entries-1].time); + char * enota = "us"; + if (getenv("SEK")) { + začetek /= 1e6; + konec /= 1e6; + enota = ""; + } + printf("začetek\t%" PRIu64 " UNIX%s\t%" PRIu64 " Wh\nkonec\t%" PRIu64 " UNIX%s\t%" PRIu64 " Wh\nzapisov: %u\n", začetek, enota, be64toh(db[0].value), konec, enota, be64toh(db[entries-1].value), entries); goto r; } if (argv[2][0] == 'p') { @@ -85,7 +96,13 @@ int main (int argc, char ** argv) { unsigned long long prev_value = be64toh(db[začetek].value); for (unsigned i = začetek; i <= konec; i++) { if (us + (be64toh(db[i].time)-prev_time) >= natančnost*1000) { - printf("%" PRIu64 "\t%" PRIu64 "\t%" PRIu64 "\t%" PRIu64 "\n", be64toh(db[i].time)-us, Wh, be64toh(db[i].time), us); + uint64_t čas_začetek = be64toh(db[i].time)-us; + uint64_t čas_konec = be64toh(db[i].time); + if (getenv("SEK")) { + čas_začetek /= 1e6; + čas_konec /= 1e6; + } + printf("%" PRIu64 "\t%" PRIu64 "\t%" PRIu64 "\t%" PRIu64 "\n", čas_začetek, Wh, čas_konec, us); us = 0; Wh = 0; } @@ -98,7 +115,10 @@ int main (int argc, char ** argv) { unsigned long long prev_print = 0; for (unsigned i = začetek; i <= konec; i++) { if (be64toh(db[i].time)-prev_print > natančnost*1000) { - printf("%" PRIu64 "\t%" PRIu64 "\n", be64toh(db[i].time), be64toh(db[i].value)); + uint64_t čas = be64toh(db[i].time); + if (getenv("SEK")) + čas /= 1e6; + printf("%" PRIu64 "\t%" PRIu64 "\n", čas, be64toh(db[i].value)); prev_print = be64toh(db[i].time); } } |