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 #1842 from rubenk/declare-loop-variable-in-for-loop-controlling...
[collectd.git]
/
src
/
ted.c
diff --git
a/src/ted.c
b/src/ted.c
index
e76b3c9
..
96c94e5
100644
(file)
--- a/
src/ted.c
+++ b/
src/ted.c
@@
-35,6
+35,7
@@
**/
#include "collectd.h"
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
#include "common.h"
#include "plugin.h"
#include "configfile.h"
@@
-70,11
+71,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
+92,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);
@@
-108,7
+108,6
@@
static int ted_read_value(double *ret_power, double *ret_voltage)
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);
@@
-165,7
+164,7
@@
static int ted_read_value(double *ret_power, double *ret_voltage)
* the beginning of the package has been found. */
escape_flag = 0;
* 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)
{
/* Check if previous byte was the escape byte. */
if (escape_flag == 1)
@@
-263,7
+262,7
@@
static int ted_open_device (void)
return (0);
} /* int ted_open_device */
return (0);
} /* int ted_open_device */
-static void ted_submit (char *type, double value)
+static void ted_submit (c
onst c
har *type, double value)
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
@@
-312,7
+311,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)
@@
-320,7
+318,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)