#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;
#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)
{
*name = "outside";
return val + 0.44;
default:
+#ifdef IGNORE_UNKNOWN_SENSORS
+ *name = NULL;
+#endif
return val;
}
}
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);
}
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)