src/Makefile: Don't set subdir-objects.
[collectd.git] / src / multimeter.c
index 9c9c2c1..6953750 100644 (file)
 
 static int fd = -1;
 
-static int multimeter_timeval_sub (struct timeval *tv1, struct timeval *tv2,
-                struct timeval *res)
-{
-        if ((tv1->tv_sec < tv2->tv_sec) ||
-           ((tv1->tv_sec == tv2->tv_sec) && (tv1->tv_usec < tv2->tv_usec)))
-               return (-1);
-
-        res->tv_sec  = tv1->tv_sec  - tv2->tv_sec;
-        res->tv_usec = tv1->tv_usec - tv2->tv_usec;
-
-        assert ((res->tv_sec > 0) || ((res->tv_sec == 0) && (res->tv_usec > 0)));
-
-        while (res->tv_usec < 0)
-        {
-               res->tv_usec += 1000000;
-                res->tv_sec--;
-        }
-       return (0);
-}
-
 #define LINE_LENGTH 14
 static int multimeter_read_value(double *value)
 {
@@ -105,7 +85,7 @@ static int multimeter_read_value(double *value)
                                                        sizeof (errbuf)));
                                return (-1);
                        }
-                       if (multimeter_timeval_sub (&time_end, &time_now, &timeout) == -1)
+                       if (timeval_cmp (time_end, time_now, &timeout) < 0)
                                break;
 
                        status = select(fd+1, &rfds, NULL, NULL, &timeout);
@@ -173,17 +153,18 @@ static int multimeter_init (void)
 
        for (i = 0; i < 10; i++)
        {
-               device[strlen(device)-1] = i + '0'; 
+               device[strlen(device)-1] = i + '0';
 
-               if ((fd = open(device, O_RDWR | O_NOCTTY)) > 0)
+               if ((fd = open(device, O_RDWR | O_NOCTTY)) != -1)
                {
                        struct termios tios;
                        int rts = TIOCM_RTS;
                        double value;
 
+                       memset (&tios, 0, sizeof (tios));
                        tios.c_cflag = B1200 | CS7 | CSTOPB | CREAD | CLOCAL;
                        tios.c_iflag = IGNBRK | IGNPAR;
-                       tios.c_oflag = 0;
+                       tios.c_oflag = 0;
                        tios.c_lflag = 0;
                        tios.c_cc[VTIME] = 3;
                        tios.c_cc[VMIN]  = LINE_LENGTH;
@@ -191,7 +172,7 @@ static int multimeter_init (void)
                        tcflush(fd, TCIFLUSH);
                        tcsetattr(fd, TCSANOW, &tios);
                        ioctl(fd, TIOCMBIC, &rts);
-                       
+
                        if (multimeter_read_value (&value) < -1)
                        {
                                close (fd);
@@ -220,7 +201,6 @@ static void multimeter_submit (double value)
 
        vl.values = values;
        vl.values_len = 1;
-       vl.time = time (NULL);
        sstrncpy (vl.host, hostname_g, sizeof (vl.host));
        sstrncpy (vl.plugin, "multimeter", sizeof (vl.plugin));
        sstrncpy (vl.type, "multimeter", sizeof (vl.type));