From: Michael Gernoth Date: Thu, 6 Mar 2014 21:37:49 +0000 (+0100) Subject: increase timeout granularity to handle missing acks on culfw-devices X-Git-Tag: v0.100~19 X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/hmcfgusb/commitdiff_plain/3b35a8c145cb567b625d32030ba3a287b478dd43 increase timeout granularity to handle missing acks on culfw-devices --- diff --git a/culfw.c b/culfw.c index a4c949b..6cfa975 100644 --- a/culfw.c +++ b/culfw.c @@ -141,7 +141,7 @@ int culfw_poll(struct culfw_dev *dev, int timeout) pfds[0].fd = dev->fd; pfds[0].events = POLLIN; - ret = poll(pfds, 1, timeout * 1000); + ret = poll(pfds, 1, timeout); if (ret == -1) return -1; diff --git a/flash-hmcfgusb.c b/flash-hmcfgusb.c index 45d467f..0f0b9ce 100644 --- a/flash-hmcfgusb.c +++ b/flash-hmcfgusb.c @@ -134,7 +134,7 @@ int main(int argc, char **argv) printf("Waiting for ack...\n"); do { errno = 0; - pfd = hmcfgusb_poll(dev, 1); + pfd = hmcfgusb_poll(dev, 1000); if ((pfd < 0) && errno) { if (errno != ETIMEDOUT) { perror("\n\nhmcfgusb_poll"); diff --git a/flash-ota.c b/flash-ota.c index 31e2ab5..634e19b 100644 --- a/flash-ota.c +++ b/flash-ota.c @@ -228,7 +228,7 @@ int send_hm_message(struct ota_dev *dev, struct recv_data *rdata, uint8_t *msg) } } errno = 0; - pfd = hmcfgusb_poll(dev->hmcfgusb, 1); + pfd = hmcfgusb_poll(dev->hmcfgusb, 1000); if ((pfd < 0) && errno) { if (errno != ETIMEDOUT) { perror("\n\nhmcfgusb_poll"); @@ -263,7 +263,7 @@ int send_hm_message(struct ota_dev *dev, struct recv_data *rdata, uint8_t *msg) int pfd; do { errno = 0; - pfd = culfw_poll(dev->culfw, 1); + pfd = culfw_poll(dev->culfw, 200); if ((pfd < 0) && errno) { if (errno != ETIMEDOUT) { perror("\n\nculfw_poll"); @@ -305,7 +305,7 @@ static int switch_speed(struct ota_dev *dev, struct recv_data *rdata, uint8_t sp while (1) { errno = 0; - pfd = hmcfgusb_poll(dev->hmcfgusb, 1); + pfd = hmcfgusb_poll(dev->hmcfgusb, 1000); if ((pfd < 0) && errno) { if (errno != ETIMEDOUT) { perror("\n\nhmcfgusb_poll"); @@ -420,7 +420,7 @@ int main(int argc, char **argv) culfw_send(dev.culfw, "V\r\n", 3); errno = 0; - pfd = culfw_poll(dev.culfw, 1); + pfd = culfw_poll(dev.culfw, 1000); if ((pfd < 0) && errno) { if (errno != ETIMEDOUT) { perror("\n\nhmcfgusb_poll"); @@ -486,7 +486,7 @@ int main(int argc, char **argv) while (1) { errno = 0; - pfd = hmcfgusb_poll(dev.hmcfgusb, 1); + pfd = hmcfgusb_poll(dev.hmcfgusb, 1000); if ((pfd < 0) && errno) { if (errno != ETIMEDOUT) { perror("\n\nhmcfgusb_poll"); @@ -516,11 +516,11 @@ int main(int argc, char **argv) errno = 0; switch (dev.type) { case DEVICE_TYPE_CULFW: - pfd = culfw_poll(dev.culfw, 1); + pfd = culfw_poll(dev.culfw, 1000); break; case DEVICE_TYPE_HMCFGUSB: default: - pfd = hmcfgusb_poll(dev.hmcfgusb, 1); + pfd = hmcfgusb_poll(dev.hmcfgusb, 1000); break; } @@ -713,11 +713,11 @@ int main(int argc, char **argv) errno = 0; switch(dev.type) { case DEVICE_TYPE_CULFW: - pfd = culfw_poll(dev.culfw, 1); + pfd = culfw_poll(dev.culfw, 1000); break; case DEVICE_TYPE_HMCFGUSB: default: - pfd = hmcfgusb_poll(dev.hmcfgusb, 1); + pfd = hmcfgusb_poll(dev.hmcfgusb, 1000); break; } if ((pfd < 0) && errno) { diff --git a/hmcfgusb.c b/hmcfgusb.c index c90410a..0e11866 100644 --- a/hmcfgusb.c +++ b/hmcfgusb.c @@ -433,13 +433,11 @@ int hmcfgusb_poll(struct hmcfgusb_dev *dev, int timeout) return -1; } else if (err == 0) { /* No pending timeout or a sane platform */ - tv.tv_sec = timeout; } else { if ((tv.tv_sec == 0) && (tv.tv_usec == 0)) { usb_event = 1; - } else if (tv.tv_sec > timeout) { - tv.tv_sec = timeout; - tv.tv_usec = 0; + } else if ((tv.tv_sec * 1000) < timeout) { + timeout = tv.tv_sec * 1000; } } @@ -448,7 +446,7 @@ int hmcfgusb_poll(struct hmcfgusb_dev *dev, int timeout) dev->pfd[i].revents = 0; } - n = poll(dev->pfd, dev->n_pfd, tv.tv_sec * 1000); + n = poll(dev->pfd, dev->n_pfd, timeout); if (n < 0) { perror("poll"); errno = 0; diff --git a/hmland.c b/hmland.c index fd2d09e..38cd7a3 100644 --- a/hmland.c +++ b/hmland.c @@ -508,7 +508,7 @@ static int comm(int fd_in, int fd_out, int master_socket, int flags) while(!quit) { int fd; - fd = hmcfgusb_poll(dev, 1); /* Wakeup device/bus at least once a second */ + fd = hmcfgusb_poll(dev, 1000); /* Wakeup device/bus at least once a second */ if (fd >= 0) { if (fd == master_socket) { int client; diff --git a/hmsniff.c b/hmsniff.c index 39133d3..a3cbe7a 100644 --- a/hmsniff.c +++ b/hmsniff.c @@ -201,7 +201,7 @@ int main(int argc, char **argv) rdata.wrong_hmid = 0; hmcfgusb_send(dev, (unsigned char*)"K", 1, 1); } - fd = hmcfgusb_poll(dev, 1); + fd = hmcfgusb_poll(dev, 1000); if (fd >= 0) { fprintf(stderr, "activity on unknown fd %d!\n", fd); continue;