]> sigrok.org Git - libsigrok.git/commitdiff
ipdbg-la: Allow rx to time out and handle invalid data properly
authorSoeren Apel <redacted>
Tue, 21 Aug 2018 09:12:12 +0000 (11:12 +0200)
committerUwe Hermann <redacted>
Wed, 29 Aug 2018 21:59:48 +0000 (23:59 +0200)
This is required for when we connect to invalid devices, e.g.
port 4243 of the IPDBG host instead of 4242.

src/hardware/ipdbg-logic-analyser/api.c
src/hardware/ipdbg-logic-analyser/protocol.c

index 17a900e52f8ca28c80b00f8eba44f5b50244aa3c..81d28337ecca3ac6d80ba5c5afb64ec9274b106b 100644 (file)
@@ -92,7 +92,9 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
        ipdbg_org_la_send_reset(tcp);
        ipdbg_org_la_send_reset(tcp);
-       ipdbg_org_la_request_id(tcp);
+
+       if (ipdbg_org_la_request_id(tcp) != SR_OK)
+               return NULL;
 
        struct sr_dev_inst *sdi = g_malloc0(sizeof(struct sr_dev_inst));
        if (!sdi) {
index 46b5a57ef9b7f211d158c3c0819fd922457a0557..3cfc9b1e4075027c3a9a5131e7af553849dfa088 100644 (file)
@@ -178,11 +178,16 @@ SR_PRIV int ipdbg_org_la_tcp_receive_blocking(struct ipdbg_org_la_tcp *tcp,
        uint8_t *buf, int bufsize)
 {
        int received = 0;
+       int error_count = 0;
 
-       while (received < bufsize) {
+       /* Timeout after 500ms of not receiving data */
+       while ((received < bufsize) && (error_count < 500)) {
                if (ipdbg_org_la_tcp_receive(tcp, buf) > 0) {
                        buf++;
                        received++;
+               } else {
+                       error_count++;
+                       g_usleep(1000);  /* Sleep for 1ms */
                }
        }
 
@@ -532,8 +537,10 @@ SR_PRIV int ipdbg_org_la_request_id(struct ipdbg_org_la_tcp *tcp)
                sr_warn("Couldn't send ID request");
 
        char id[4];
-       if (ipdbg_org_la_tcp_receive_blocking(tcp, (uint8_t *) id, 4) != 4)
-               sr_warn("Couldn't read device ID");
+       if (ipdbg_org_la_tcp_receive_blocking(tcp, (uint8_t*)id, 4) != 4) {
+               sr_err("Couldn't read device ID");
+               return SR_ERR;
+       }
 
        if (strncmp(id, "IDBG", 4)) {
                sr_err("Invalid device ID: expected 'IDBG', got '%c%c%c%c'.",