|
@@ -40,6 +40,8 @@ static libusb_context *usb_ctxt;
|
|
|
static libusb_device_handle *devh;
|
|
|
|
|
|
static int use_syslog;
|
|
|
+static int use_rrd;
|
|
|
+static int use_storelatest;
|
|
|
static int debug_mode;
|
|
|
static int debug_packets;
|
|
|
static int debug_raw_data;
|
|
@@ -170,6 +172,24 @@ static void rrd_point(time_t t, const char *name, double val, char *unit)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+static void store_latest(time_t t, int id, const char *name, int raw, double val, double val2, char *unit, int q)
|
|
|
+{
|
|
|
+ char fileName[64];
|
|
|
+ char buffer[250];
|
|
|
+
|
|
|
+ snprintf(fileName, sizeof(fileName), "/tmp/sensor_%d", id);
|
|
|
+ FILE *f = fopen("/tmp/tl-500.tmp", "w");
|
|
|
+ if(f == NULL)
|
|
|
+ return;
|
|
|
+
|
|
|
+ // snprintf(buffer, sizeof(buffer), "%s %d %d %2.1f C\n", system_time(), sensor, value, temperature);
|
|
|
+ snprintf(buffer, sizeof(buffer), "%u Sensor:%d Raw:%d Value:%.2f Unit:%s Name:\"%s\" Value2:%.2f Q:%d", (unsigned)t, id, raw, val, unit, name, val2, q);
|
|
|
+
|
|
|
+ fprintf(f, buffer);
|
|
|
+ fclose(f);
|
|
|
+ rename("/tmp/tl-500.tmp", fileName);
|
|
|
+}
|
|
|
+
|
|
|
/*** Transforms ***/
|
|
|
|
|
|
#define TIME_OFFSET 946681200 // Timestamp of 2000-01-01 00:00:00
|
|
@@ -207,7 +227,7 @@ static double correct_point(int id, double val, const char **name)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static void cooked_point(time_t t, int id, double val, char *unit, int q)
|
|
|
+static void cooked_point(time_t t, int id, int raw, double val, char *unit, int q)
|
|
|
{
|
|
|
char namebuf[16];
|
|
|
snprintf(namebuf, sizeof(namebuf), "%d", id);
|
|
@@ -237,7 +257,12 @@ static void cooked_point(time_t t, int id, double val, char *unit, int q)
|
|
|
}
|
|
|
|
|
|
data_point_counter++;
|
|
|
- rrd_point(t, name, val2, unit);
|
|
|
+ if (use_rrd) {
|
|
|
+ rrd_point(t, name, val2, unit);
|
|
|
+ }
|
|
|
+ if (use_storelatest) {
|
|
|
+ store_latest(t, id, name, raw, val, val2, unit, q);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
static void raw_point(int t, int id, int raw, int q)
|
|
@@ -329,7 +354,7 @@ static void raw_point(int t, int id, int raw, int q)
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- cooked_point(t + TIME_OFFSET, id, z, unit, q);
|
|
|
+ cooked_point(t + TIME_OFFSET, id, raw, z, unit, q);
|
|
|
}
|
|
|
|
|
|
/*** USB interface ***/
|
|
@@ -599,6 +624,8 @@ static void interruptible_msleep(int ms)
|
|
|
}
|
|
|
|
|
|
static const struct option long_options[] = {
|
|
|
+ { "rrd", 0, NULL, 'R' },
|
|
|
+ { "storelatest", 0, NULL, 'S' },
|
|
|
{ "debug", 0, NULL, 'd' },
|
|
|
{ "log-dir", 1, NULL, 'l' },
|
|
|
{ "debug-packets", 0, NULL, 'p' },
|
|
@@ -613,6 +640,8 @@ static void usage(void)
|
|
|
Usage: arexxd <options>\n\
|
|
|
\n\
|
|
|
Options:\n\
|
|
|
+-R, --rrd Store data in RRD\n\
|
|
|
+-S, --storelatest Store latest value in files\n\
|
|
|
-d, --debug Debug mode (no chdir, no fork, no syslog)\n\
|
|
|
-l, --log-dir=<dir> Directory where all received data should be stored\n\
|
|
|
-p, --debug-packets Log all packets sent and received\n\
|
|
@@ -626,8 +655,14 @@ Options:\n\
|
|
|
int main(int argc, char **argv)
|
|
|
{
|
|
|
int opt;
|
|
|
- while ((opt = getopt_long(argc, argv, "dl:pruV", long_options, NULL)) >= 0)
|
|
|
+ while ((opt = getopt_long(argc, argv, "RSdl:pruV", long_options, NULL)) >= 0)
|
|
|
switch (opt) {
|
|
|
+ case 'R':
|
|
|
+ use_rrd++;
|
|
|
+ break;
|
|
|
+ case 'S':
|
|
|
+ use_storelatest++;
|
|
|
+ break;
|
|
|
case 'd':
|
|
|
debug_mode++;
|
|
|
break;
|