aboutsummaryrefslogtreecommitdiff
path: root/aufgabe4/statistic.c
diff options
context:
space:
mode:
Diffstat (limited to 'aufgabe4/statistic.c')
-rw-r--r--aufgabe4/statistic.c38
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);
}