|
@@ -21,6 +21,20 @@
|
|
|
|
|
|
#define DEFAULT_LOG_DIR "/var/log/arexxd"
|
|
#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;
|
|
typedef unsigned char byte;
|
|
static libusb_context *usb_ctxt;
|
|
static libusb_context *usb_ctxt;
|
|
static libusb_device_handle *devh;
|
|
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
|
|
#define TIME_OFFSET 946681200
|
|
|
|
|
|
static int data_point_counter;
|
|
static int data_point_counter;
|
|
|
|
+static time_t packet_rx_time;
|
|
|
|
|
|
static double correct_point(int id, double val, const char **name)
|
|
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";
|
|
*name = "outside";
|
|
return val + 0.44;
|
|
return val + 0.44;
|
|
default:
|
|
default:
|
|
|
|
+#ifdef IGNORE_UNKNOWN_SENSORS
|
|
|
|
+ *name = NULL;
|
|
|
|
+#endif
|
|
return val;
|
|
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);
|
|
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++;
|
|
data_point_counter++;
|
|
rrd_point(t, name, val2, unit);
|
|
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);
|
|
log_error("Receive error: %d", err);
|
|
return err;
|
|
return err;
|
|
}
|
|
}
|
|
|
|
+ packet_rx_time = time(NULL);
|
|
if (debug_packets)
|
|
if (debug_packets)
|
|
log_pkt("<< recv %d bytes\n", transferred);
|
|
log_pkt("<< recv %d bytes\n", transferred);
|
|
while (transferred < 64)
|
|
while (transferred < 64)
|