#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;
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 */
{
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;
}
/*
/* 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].
((int)package_buffer[251]));
/* success */
- return (0);
+ return 0;
} /* int ted_read_value */
static int ted_open_device(void) {
struct termios options;
if (fd >= 0)
- return (0);
+ return 0;
dev = DEFAULT_DEVICE;
if (conf_device != NULL)
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... */
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) {
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) {
status = ted_open_device();
if (status != 0)
- return (-1);
+ return -1;
power = NAN;
voltage = NAN;
}
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) {
fd = -1;
}
- return (0);
+ return 0;
} /* int ted_shutdown */
void module_register(void) {