X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fted.c;h=b5fa4c1ece7c86ed9e59583ec481d3c905d0fb4e;hp=fbfd95dbd78680f9b121d533501e13323519ebe3;hb=ec51ddee94fa2ba1e01fe0e336ccc9c190a198ff;hpb=c6baff42e7e8e547eb7ca7817c0e0e07ccea95db diff --git a/src/ted.c b/src/ted.c index fbfd95db..b5fa4c1e 100644 --- a/src/ted.c +++ b/src/ted.c @@ -53,8 +53,8 @@ #define DEFAULT_DEVICE "/dev/ttyUSB0" -static char *conf_device = NULL; -static int conf_retries = 0; +static char *conf_device; +static int conf_retries; static int fd = -1; @@ -88,8 +88,8 @@ static int ted_read_value(double *ret_power, double *ret_voltage) { status = write(fd, pkt_request, sizeof(pkt_request)); if (status <= 0) { - ERROR("ted plugin: swrite failed."); - return (-1); + ERROR("ted plugin: write failed."); + return -1; } /* Loop until we find the end of the package */ @@ -104,33 +104,29 @@ static int ted_read_value(double *ret_power, double *ret_voltage) { { WARNING("ted plugin: Timeout while waiting for file descriptor " "to become ready."); - return (-1); + return -1; } else if ((status < 0) && ((errno == EAGAIN) || (errno == EINTR))) { /* Some signal or something. Start over.. */ continue; } else if (status < 0) { - char errbuf[1024]; - ERROR("ted plugin: select failed: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); - return (-1); + ERROR("ted plugin: select failed: %s", STRERRNO); + return -1; } receive_buffer_length = read(fd, receive_buffer, sizeof(receive_buffer)); if (receive_buffer_length < 0) { - char errbuf[1024]; if ((errno == EAGAIN) || (errno == EINTR)) continue; - ERROR("ted plugin: read(2) failed: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); - return (-1); + ERROR("ted plugin: read(2) failed: %s", STRERRNO); + return -1; } else if (receive_buffer_length == 0) { /* Should we close the FD in this case? */ WARNING("ted plugin: Received EOF from file descriptor."); - return (-1); + return -1; } else if (((size_t)receive_buffer_length) > sizeof(receive_buffer)) { ERROR("ted plugin: read(2) returned invalid value %zi.", receive_buffer_length); - return (-1); + return -1; } /* @@ -175,7 +171,7 @@ static int ted_read_value(double *ret_power, double *ret_voltage) { /* Check for errors inside the loop. */ 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]. @@ -190,7 +186,7 @@ static int ted_read_value(double *ret_power, double *ret_voltage) { ((int)package_buffer[251])); /* success */ - return (0); + return 0; } /* int ted_read_value */ static int ted_open_device(void) { @@ -198,7 +194,7 @@ static int ted_open_device(void) { struct termios options; if (fd >= 0) - return (0); + return 0; dev = DEFAULT_DEVICE; if (conf_device != NULL) @@ -207,7 +203,7 @@ static int ted_open_device(void) { fd = open(dev, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK); if (fd < 0) { ERROR("ted plugin: Unable to open device %s.", dev); - return (-1); + return -1; } /* Get the current options for the port... */ @@ -224,7 +220,7 @@ static int ted_open_device(void) { tcsetattr(fd, TCSANOW, &options); INFO("ted plugin: Successfully opened %s.", dev); - return (0); + return 0; } /* int ted_open_device */ static void ted_submit(const char *type, double value) { @@ -248,15 +244,15 @@ static int ted_config(const char *key, const char *value) { tmp = atoi(value); if (tmp < 0) { WARNING("ted plugin: Invalid retry count: %i", tmp); - return (1); + return 1; } conf_retries = tmp; } else { ERROR("ted plugin: Unknown config option: %s", key); - return (-1); + return -1; } - return (0); + return 0; } /* int ted_config */ static int ted_read(void) { @@ -266,7 +262,7 @@ static int ted_read(void) { status = ted_open_device(); if (status != 0) - return (-1); + return -1; power = NAN; voltage = NAN; @@ -277,12 +273,12 @@ static int ted_read(void) { } if (status != 0) - return (-1); + return -1; ted_submit("power", power); ted_submit("voltage", voltage); - return (0); + return 0; } /* int ted_read */ static int ted_shutdown(void) { @@ -291,7 +287,7 @@ static int ted_shutdown(void) { fd = -1; } - return (0); + return 0; } /* int ted_shutdown */ void module_register(void) {