increase timeout granularity to handle missing acks on culfw-devices
authorMichael Gernoth <michael@gernoth.net>
Thu, 6 Mar 2014 21:37:49 +0000 (22:37 +0100)
committerMichael Gernoth <michael@gernoth.net>
Thu, 6 Mar 2014 21:37:49 +0000 (22:37 +0100)
culfw.c
flash-hmcfgusb.c
flash-ota.c
hmcfgusb.c
hmland.c
hmsniff.c

diff --git a/culfw.c b/culfw.c
index a4c949b..6cfa975 100644 (file)
--- 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;
 
index 45d467f..0f0b9ce 100644 (file)
@@ -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");
index 31e2ab5..634e19b 100644 (file)
@@ -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) {
index c90410a..0e11866 100644 (file)
@@ -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;
index fd2d09e..38cd7a3 100644 (file)
--- 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;
index 39133d3..a3cbe7a 100644 (file)
--- 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;
Impressum, Datenschutz