]> mj.ucw.cz Git - arexx.git/commitdiff
Added filtering of obviously bogus data points
authorMartin Mares <mj@ucw.cz>
Mon, 9 Apr 2012 15:30:26 +0000 (17:30 +0200)
committerMartin Mares <mj@ucw.cz>
Mon, 9 Apr 2012 15:30:26 +0000 (17:30 +0200)
TODO
arexxd.c

diff --git a/TODO b/TODO
index 71d089ea7dbefb58151caceeb4ac27e9dbdb435d..f8cc1347a34d0bbe61768e43e9e5d60808a622d6 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1 +1,4 @@
 - Multiple receivers?
+- Configuration files
+- CSV output
+- Rotation of debug logs
index 76cbc3fd5b81028e2c169c9d3079788c4ef4a3e0..a84d9ffb17a8326f602150787829a06162b59ea8 100644 (file)
--- a/arexxd.c
+++ b/arexxd.c
 
 #define DEFAULT_LOG_DIR "/var/log/arexxd"
 
+/*
+ *  Data points received from the logger are sometimes corrupted by noise.
+ *  This effects not only the measured values, but also sensor IDs and timestamps.
+ *  Since rrdtool cannot skip back in time, a random timestamp in the future can
+ *  cause all further measurements to be dropped. To minimize impact of these
+ *  problems, we drop data points which are too far in the past or in the future.
+ *
+ *  Furthermore, you can ignore data from unrecognized sensors, i.e., those
+ *  which are not handled by correct_point().
+ */
+#define MAX_PAST_TIME 30*86400
+#define MAX_FUTURE_TIME 300
+#undef IGNORE_UNKNOWN_SENSORS
+
 typedef unsigned char byte;
 static libusb_context *usb_ctxt;
 static libusb_device_handle *devh;
@@ -161,6 +175,7 @@ static void rrd_point(time_t t, const char *name, double val, char *unit)
 #define TIME_OFFSET 946681200          // Timestamp of 2000-01-01 00:00:00
 
 static int data_point_counter;         // Since last log message
+static time_t packet_rx_time;
 
 static double correct_point(int id, double val, const char **name)
 {
@@ -185,6 +200,9 @@ static double correct_point(int id, double val, const char **name)
                        *name = "outside";
                        return val + 0.44;
                default:
+#ifdef IGNORE_UNKNOWN_SENSORS
+                       *name = NULL;
+#endif
                        return val;
        }
 }
@@ -205,6 +223,19 @@ static void cooked_point(time_t t, int id, double val, char *unit, int q)
                printf("== %s id=%d name=%s val=%.3f val2=%.3f unit=%s q=%d\n", tbuf, id, name, val, val2, unit, q);
        }
 
+       if (!name) {
+               log_error("Ignored data from unknown sensor %d", id);
+               return;
+       }
+       if (t < packet_rx_time - MAX_PAST_TIME) {
+               log_error("Data point from sensor %d too far in the past (%d sec)", packet_rx_time - t);
+               return;
+       }
+       if (t > packet_rx_time + MAX_FUTURE_TIME) {
+               log_error("Data point from sensor %d too far in the future (%d sec)", t - packet_rx_time);
+               return;
+       }
+
        data_point_counter++;
        rrd_point(t, name, val2, unit);
 }
@@ -452,6 +483,7 @@ static int send_and_receive(byte *req, byte *reply)
                log_error("Receive error: %d", err);
                return err;
        }
+       packet_rx_time = time(NULL);
        if (debug_packets)
                log_pkt("<< recv %d bytes\n", transferred);
        while (transferred < 64)