diff options
| author | Michael Stapelberg <michael@stapelberg.de> | 2010-12-06 19:55:19 +0100 |
|---|---|---|
| committer | Michael Stapelberg <michael@stapelberg.de> | 2010-12-06 19:55:19 +0100 |
| commit | 0c9d712a77bbede4808142944776d35f502bffa7 (patch) | |
| tree | 1955e375d404308aa1d79b9d355e37dba739b9bf /aufgabe4/statistic.c | |
| parent | 9af2bea582c083653c08abb965eba6f63de997fa (diff) | |
| download | prozesskommunikation-0c9d712a77bbede4808142944776d35f502bffa7.tar.gz prozesskommunikation-0c9d712a77bbede4808142944776d35f502bffa7.tar.bz2 | |
IPC implementiert
Hat noch einen Bug, sollte aber als Beispiel für die anderen Aufgaben gut genug
sein.
Diffstat (limited to 'aufgabe4/statistic.c')
| -rw-r--r-- | aufgabe4/statistic.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/aufgabe4/statistic.c b/aufgabe4/statistic.c index b83776a..cf59217 100644 --- a/aufgabe4/statistic.c +++ b/aufgabe4/statistic.c @@ -1,18 +1,52 @@ /* * vim:ts=4:sw=4:expandtab + * + * © 2010 Michael Stapelberg * */ #include <stdlib.h> #include <stdio.h> #include <unistd.h> +#include "queue.h" + +static uint8_t saved[5]; +static uint8_t cnt; + +/* + * Statistik-Prozess. Empfängt je 5 Werte, bildet das arithmetische Mittel und + * schickt dieses an den Monitor-Prozess. + * + */ void statistic() { - printf("statistic started\n"); + uint8_t c, avg; + + cnt = 0; for (;;) { + /* Wir warten auf Nachrichten des CONV-Prozesses */ + while (queue_get_dir() != D_CONV_TO_STAT) + usleep(1); + + uint8_t data = queue_get_data(); + saved[cnt] = data; + if (cnt == 4) { + /* Wir haben 5 Werte gespeichert, können nun also den Mittelwert + * bilden. */ + avg = 0; + for (c = 0; c < 5; c++) + avg += saved[c]; + avg /= 5; + queue_write(D_STAT_TO_MON, avg); + cnt = 0; + } else cnt++; + } } +/* + * Cleanup-Funktion. Beendet den Prozess. + * + */ void statistic_cleanup() { - printf("statistic cleanup\n"); _exit(EXIT_SUCCESS); } |
