**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
{
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;
- struct timeval timeout;
+
+ /* Initialize timeout structure, set to 2 seconds */
+ struct timeval timeout = {
+ .tv_sec = 2
+ };
int end_flag;
int escape_flag;
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);
/* Loop until we find the end of the package */
end_flag = 0;
- escape_flag = 0;
package_buffer_pos = 0;
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);
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);
/* 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. */
-
+
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)
}
else if (receive_buffer[i] == PKT_END)
{
- end_flag = 1;
+ end_flag = 1;
break;
}
else
} /* while (end_flag == 0) */
/* Check for errors inside the loop. */
- if ((end_flag == 0) | (package_buffer_pos != 278))
+ if ((end_flag == 0) || (package_buffer_pos != EXPECTED_PACKAGE_LENGTH))
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 in 1Watt steps
+ * Power is in 10 Watt steps
* Voltage is in volts
*/
- *ret_power = 10 * (double) ((((int) package_buffer[248]) * 256)
+ *ret_power = 10.0 * (double) ((((int) package_buffer[248]) * 256)
+ ((int) package_buffer[247]));
*ret_voltage = 0.1 * (double) ((((int) package_buffer[252]) * 256)
+ ((int) package_buffer[251]));
return (0);
} /* int ted_open_device */
-static void ted_submit (char *type, double value)
-{
+static void ted_submit (const char *type, double value)
+{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
values[0].gauge = value;
- vl.time = time (NULL);
vl.values = values;
vl.values_len = 1;
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
double power;
double voltage;
int status;
- int i;
status = ted_open_device ();
if (status != 0)
power = NAN;
voltage = NAN;
- for (i = 0; i <= conf_retries; i++)
+ for (int i = 0; i <= conf_retries; i++)
{
status = ted_read_value (&power, &voltage);
if (status == 0)