From 0c9d712a77bbede4808142944776d35f502bffa7 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 6 Dec 2010 19:55:19 +0100 Subject: IPC implementiert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hat noch einen Bug, sollte aber als Beispiel für die anderen Aufgaben gut genug sein. --- aufgabe4/statistic.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'aufgabe4/statistic.c') 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 #include #include +#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); } -- cgit v1.2.3-70-g09d2