|
@@ -305,39 +305,16 @@ static bool avalon_decode_nonce(struct thr_info *thr, struct avalon_result *ar,
|
|
|
|
|
|
|
|
static void avalon_get_reset(int fd, struct avalon_result *ar)
|
|
static void avalon_get_reset(int fd, struct avalon_result *ar)
|
|
|
{
|
|
{
|
|
|
- int read_amount = AVALON_READ_SIZE;
|
|
|
|
|
- uint8_t result[AVALON_READ_SIZE];
|
|
|
|
|
- struct timeval timeout = {1, 0};
|
|
|
|
|
- ssize_t ret = 0, offset = 0;
|
|
|
|
|
- fd_set rd;
|
|
|
|
|
-
|
|
|
|
|
- memset(result, 0, AVALON_READ_SIZE);
|
|
|
|
|
|
|
+ int ret;
|
|
|
|
|
+ const int read_count = AVALON_RESET_FAULT_DECISECONDS * AVALON_TIME_FACTOR;
|
|
|
|
|
+
|
|
|
memset(ar, 0, AVALON_READ_SIZE);
|
|
memset(ar, 0, AVALON_READ_SIZE);
|
|
|
- FD_ZERO(&rd);
|
|
|
|
|
- FD_SET(fd, &rd);
|
|
|
|
|
- ret = select(fd + 1, &rd, NULL, NULL, &timeout);
|
|
|
|
|
- if (unlikely(ret < 0)) {
|
|
|
|
|
- applog(LOG_WARNING, "Avalon: Error %d on select in avalon_get_reset", errno);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- if (!ret) {
|
|
|
|
|
- applog(LOG_WARNING, "Avalon: Timeout on select in avalon_get_reset");
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- do {
|
|
|
|
|
- ret = read(fd, result + offset, read_amount);
|
|
|
|
|
- if (unlikely(ret < 0)) {
|
|
|
|
|
- applog(LOG_WARNING, "Avalon: Error %d on read in avalon_get_reset", errno);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- read_amount -= ret;
|
|
|
|
|
- offset += ret;
|
|
|
|
|
- } while (read_amount > 0);
|
|
|
|
|
- if (opt_debug) {
|
|
|
|
|
|
|
+ ret = avalon_gets(fd, (uint8_t*)ar, read_count, NULL, NULL);
|
|
|
|
|
+
|
|
|
|
|
+ if (ret == AVA_GETS_OK && opt_debug) {
|
|
|
applog(LOG_DEBUG, "Avalon: get:");
|
|
applog(LOG_DEBUG, "Avalon: get:");
|
|
|
- hexdump((uint8_t *)result, AVALON_READ_SIZE);
|
|
|
|
|
|
|
+ hexdump((uint8_t *)ar, AVALON_READ_SIZE);
|
|
|
}
|
|
}
|
|
|
- memcpy((uint8_t *)ar, result, AVALON_READ_SIZE);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static int avalon_reset(int fd, struct avalon_result *ar)
|
|
static int avalon_reset(int fd, struct avalon_result *ar)
|