|
|
@ -46,10 +46,16 @@ |
|
|
|
#include <windows.h> |
|
|
|
#include <windows.h> |
|
|
|
#include <io.h> |
|
|
|
#include <io.h> |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
#ifdef HAVE_SYS_EPOLL_H |
|
|
|
|
|
|
|
#include <sys/epoll.h> |
|
|
|
|
|
|
|
#define HAVE_EPOLL |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#include "elist.h" |
|
|
|
#include "elist.h" |
|
|
|
#include "miner.h" |
|
|
|
#include "miner.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 8 second timeout
|
|
|
|
|
|
|
|
#define ICARUS_READ_FAULT_DECISECONDS (10) |
|
|
|
#define ICARUS_READ_FAULT_COUNT (8) |
|
|
|
#define ICARUS_READ_FAULT_COUNT (8) |
|
|
|
|
|
|
|
|
|
|
|
struct device_api icarus_api; |
|
|
|
struct device_api icarus_api; |
|
|
@ -87,7 +93,7 @@ static int icarus_open(const char *devpath) |
|
|
|
ISTRIP | INLCR | IGNCR | ICRNL | IXON); |
|
|
|
ISTRIP | INLCR | IGNCR | ICRNL | IXON); |
|
|
|
my_termios.c_oflag &= ~OPOST; |
|
|
|
my_termios.c_oflag &= ~OPOST; |
|
|
|
my_termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); |
|
|
|
my_termios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); |
|
|
|
my_termios.c_cc[VTIME] = 10; /* block 1 second */ |
|
|
|
my_termios.c_cc[VTIME] = ICARUS_READ_FAULT_DECISECONDS; |
|
|
|
my_termios.c_cc[VMIN] = 0; |
|
|
|
my_termios.c_cc[VMIN] = 0; |
|
|
|
tcsetattr(serialfd, TCSANOW, &my_termios); |
|
|
|
tcsetattr(serialfd, TCSANOW, &my_termios); |
|
|
|
|
|
|
|
|
|
|
@ -112,8 +118,27 @@ static int icarus_gets(unsigned char *buf, size_t bufLen, int fd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ssize_t ret = 0; |
|
|
|
ssize_t ret = 0; |
|
|
|
int rc = 0; |
|
|
|
int rc = 0; |
|
|
|
|
|
|
|
int epollfd = -1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_EPOLL |
|
|
|
|
|
|
|
struct epoll_event ev, evr; |
|
|
|
|
|
|
|
epollfd = epoll_create(1); |
|
|
|
|
|
|
|
if (epollfd != -1) { |
|
|
|
|
|
|
|
ev.events = EPOLLIN; |
|
|
|
|
|
|
|
ev.data.fd = fd; |
|
|
|
|
|
|
|
if (-1 == epoll_ctl(epollfd, EPOLL_CTL_ADD, fd, &ev)) { |
|
|
|
|
|
|
|
close(epollfd); |
|
|
|
|
|
|
|
epollfd = -1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
while (bufLen) { |
|
|
|
while (bufLen) { |
|
|
|
|
|
|
|
#ifdef HAVE_EPOLL |
|
|
|
|
|
|
|
if (epollfd != -1 && epoll_wait(epollfd, &evr, 1, ICARUS_READ_FAULT_DECISECONDS * 100) != 1) |
|
|
|
|
|
|
|
ret = 0; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
#endif |
|
|
|
ret = read(fd, buf, 1); |
|
|
|
ret = read(fd, buf, 1); |
|
|
|
if (ret == 1) { |
|
|
|
if (ret == 1) { |
|
|
|
bufLen--; |
|
|
|
bufLen--; |
|
|
@ -123,12 +148,17 @@ static int icarus_gets(unsigned char *buf, size_t bufLen, int fd) |
|
|
|
|
|
|
|
|
|
|
|
rc++; |
|
|
|
rc++; |
|
|
|
if (rc == ICARUS_READ_FAULT_COUNT) { |
|
|
|
if (rc == ICARUS_READ_FAULT_COUNT) { |
|
|
|
|
|
|
|
if (epollfd != -1) |
|
|
|
|
|
|
|
close(epollfd); |
|
|
|
applog(LOG_DEBUG, |
|
|
|
applog(LOG_DEBUG, |
|
|
|
"Icarus Read: No data in %d seconds", rc); |
|
|
|
"Icarus Read: No data in %d seconds", rc * ICARUS_READ_FAULT_DECISECONDS / 10); |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (epollfd != -1) |
|
|
|
|
|
|
|
close(epollfd); |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|