projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #1899 from rubenk/python-fixes-for-interactive-sessions
[collectd.git]
/
src
/
ted.c
diff --git
a/src/ted.c
b/src/ted.c
index
57c8889
..
5ed6c27
100644
(file)
--- a/
src/ted.c
+++ b/
src/ted.c
@@
-35,9
+35,9
@@
**/
#include "collectd.h"
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "common.h"
#include "plugin.h"
-#include "configfile.h"
#if HAVE_TERMIOS_H && HAVE_SYS_IOCTL_H && HAVE_MATH_H
# include <termios.h>
#if HAVE_TERMIOS_H && HAVE_SYS_IOCTL_H && HAVE_MATH_H
# include <termios.h>
@@
-70,11
+70,15
@@
static int ted_read_value(double *ret_power, double *ret_voltage)
{
unsigned char receive_buffer[300];
unsigned char package_buffer[300];
{
unsigned char receive_buffer[300];
unsigned char package_buffer[300];
- char pkt_request[1] = {0xAA};
+
unsigned
char pkt_request[1] = {0xAA};
int package_buffer_pos;
fd_set input;
int package_buffer_pos;
fd_set input;
- struct timeval timeout;
+
+ /* Initialize timeout structure, set to 2 seconds */
+ struct timeval timeout = {
+ .tv_sec = 2
+ };
int end_flag;
int escape_flag;
int end_flag;
int escape_flag;
@@
-87,11
+91,6
@@
static int ted_read_value(double *ret_power, double *ret_voltage)
FD_ZERO (&input);
FD_SET (fd, &input);
FD_ZERO (&input);
FD_SET (fd, &input);
- /* Initialize timeout structure, set to 2 seconds */
- memset (&timeout, 0, sizeof (timeout));
- timeout.tv_sec = 2;
- timeout.tv_usec = 0;
-
/* clear out anything in the buffer */
tcflush (fd, TCIFLUSH);
/* clear out anything in the buffer */
tcflush (fd, TCIFLUSH);
@@
-104,12
+103,10
@@
static int ted_read_value(double *ret_power, double *ret_voltage)
/* Loop until we find the end of the package */
end_flag = 0;
/* Loop until we find the end of the package */
end_flag = 0;
- escape_flag = 0;
- package_buffer_pos = -1;
+ package_buffer_pos = 0;
while (end_flag == 0)
{
ssize_t receive_buffer_length;
while (end_flag == 0)
{
ssize_t receive_buffer_length;
- ssize_t i;
/* check for timeout or input error*/
status = select (fd + 1, &input, NULL, NULL, &timeout);
/* check for timeout or input error*/
status = select (fd + 1, &input, NULL, NULL, &timeout);
@@
-148,19
+145,12
@@
static int ted_read_value(double *ret_power, double *ret_voltage)
WARNING ("ted plugin: Received EOF from file descriptor.");
return (-1);
}
WARNING ("ted plugin: Received EOF from file descriptor.");
return (-1);
}
- else if (
receive_buffer_length
> sizeof (receive_buffer))
+ else if (
((size_t) receive_buffer_length)
> sizeof (receive_buffer))
{
ERROR ("ted plugin: read(2) returned invalid value %zi.",
receive_buffer_length);
return (-1);
}
{
ERROR ("ted plugin: read(2) returned invalid value %zi.",
receive_buffer_length);
return (-1);
}
- else if (receive_buffer_length < EXPECTED_PACKAGE_LENGTH)
- {
- WARNING ("ted plugin: read(2) returned %zi bytes, "
- "but at least %i are necessary for a valid packet.",
- receive_buffer_length, EXPECTED_PACKAGE_LENGTH);
- return (-1);
- }
/*
* packet filter loop
/*
* packet filter loop
@@
-171,9
+161,9
@@
static int ted_read_value(double *ret_power, double *ret_voltage)
/* We need to see the begin sequence first. When we receive `ESCAPE
* PKT_BEGIN', we set `package_buffer_pos' to zero to signal that
* the beginning of the package has been found. */
/* We need to see the begin sequence first. When we receive `ESCAPE
* PKT_BEGIN', we set `package_buffer_pos' to zero to signal that
* the beginning of the package has been found. */
- package_buffer_pos = -1;
+
escape_flag = 0;
escape_flag = 0;
- for (i = 0; i < receive_buffer_length; i++)
+ for (
ssize_t
i = 0; i < receive_buffer_length; i++)
{
/* Check if previous byte was the escape byte. */
if (escape_flag == 1)
{
/* Check if previous byte was the escape byte. */
if (escape_flag == 1)
@@
-216,16
+206,15
@@
static int ted_read_value(double *ret_power, double *ret_voltage)
} /* while (end_flag == 0) */
/* Check for errors inside the loop. */
} /* while (end_flag == 0) */
/* Check for errors inside the loop. */
- if (
end_flag == 0
)
+ if (
(end_flag == 0) || (package_buffer_pos != EXPECTED_PACKAGE_LENGTH)
)
return (-1);
return (-1);
- /*
+ /*
* Power is at positions 247 and 248 (LSB first) in [10kW].
* Voltage is at positions 251 and 252 (LSB first) in [.1V].
*
* Power is at positions 247 and 248 (LSB first) in [10kW].
* Voltage is at positions 251 and 252 (LSB first) in [.1V].
*
- * According to Eric's patch the power is in 10kW steps, but according to a
- * Python module I've found, it's in 0.01kW == 10W. IMHO the Python scale
- * is more realistic. -octo
+ * Power is in 10 Watt steps
+ * Voltage is in volts
*/
*ret_power = 10.0 * (double) ((((int) package_buffer[248]) * 256)
+ ((int) package_buffer[247]));
*/
*ret_power = 10.0 * (double) ((((int) package_buffer[248]) * 256)
+ ((int) package_buffer[247]));
@@
-272,7
+261,7
@@
static int ted_open_device (void)
return (0);
} /* int ted_open_device */
return (0);
} /* int ted_open_device */
-static void ted_submit (c
har *type_instanc
e, double value)
+static void ted_submit (c
onst char *typ
e, double value)
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
@@
-283,8
+272,7
@@
static void ted_submit (char *type_instance, double value)
vl.values_len = 1;
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "ted", sizeof (vl.plugin));
vl.values_len = 1;
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "ted", sizeof (vl.plugin));
- sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
- sstrncpy (vl.type, "ted", sizeof (vl.type));
+ sstrncpy (vl.type, type, sizeof (vl.type));
plugin_dispatch_values (&vl);
}
plugin_dispatch_values (&vl);
}
@@
-322,7
+310,6
@@
static int ted_read (void)
double power;
double voltage;
int status;
double power;
double voltage;
int status;
- int i;
status = ted_open_device ();
if (status != 0)
status = ted_open_device ();
if (status != 0)
@@
-330,7
+317,7
@@
static int ted_read (void)
power = NAN;
voltage = NAN;
power = NAN;
voltage = NAN;
- for (i = 0; i <= conf_retries; i++)
+ for (i
nt i
= 0; i <= conf_retries; i++)
{
status = ted_read_value (&power, &voltage);
if (status == 0)
{
status = ted_read_value (&power, &voltage);
if (status == 0)