]> sigrok.org Git - libsigrok.git/commitdiff
ipdbg-la: stop-command
authorEva Kissling <redacted>
Mon, 2 Oct 2017 15:17:09 +0000 (17:17 +0200)
committerUwe Hermann <redacted>
Wed, 29 Aug 2018 21:59:32 +0000 (23:59 +0200)
src/hardware/ipdbg-logic-analyser/api.c
src/hardware/ipdbg-logic-analyser/protocol.c
src/hardware/ipdbg-logic-analyser/protocol.h

index db4497a8ff34dc6ab0967552d7533268874d17c1..ecdefa46dda08ada587e53eb1a670455efa90ac8 100644 (file)
@@ -335,10 +335,14 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
     struct ipdbg_org_la_tcp *tcp = sdi->conn;
 
     unsigned char byte;
-    while (devc->num_transfers < devc->limit_samples_max*devc->DATA_WIDTH_BYTES)
+
+    if(devc->num_transfers > 0)
     {
-        ipdbg_org_la_tcp_receive(tcp, &byte, 1);
+        while (devc->num_transfers < devc->limit_samples_max*devc->DATA_WIDTH_BYTES)
+        {
+        ipdbg_org_la_tcp_receive(tcp, &byte);
         devc->num_transfers++;
+        }
     }
 
     ipdbg_org_la_sendReset(tcp);
index de6cc27e48ba270e77f2fafb1c2295bfc9653f21..69dd619814fdcf45e9235b882656a601e2275c22 100644 (file)
@@ -35,6 +35,8 @@
 #include <errno.h>
 #include "protocol.h"
 
+#include <sys/ioctl.h>
+
 #define BUFFER_SIZE 4
 
 
 #define delay                      0x1F
 #define K_Mauslesen                0xAA
 
+int hasData(struct ipdbg_org_la_tcp *tcp)
+{
+#ifdef __WIN32__
+    ioctlsocket(tcp->socket,FIONREAD,&bytes_available);
+#else
+    //ioctl(fd,FIONREAD,&bytes_available);
+    int status;
+
+    //fd = open("/dev/ttyS0", O_RDONLY);
+    if (ioctl(tcp->socket, FIONREAD, &status) < 0) //TIOCMGET
+    {
+           sr_err("FIONREAD failed: %s\n",
+             strerror(errno));
+            return 0;
+    }
+    else
+    {
+        if (status < 1)
+        {
+            return 0;
+        }
+        else
+        {
+            return 1;
+        }
+    }
+
+#endif // __WIN32__
+}
+
 
 SR_PRIV int sendEscaping(struct ipdbg_org_la_tcp *tcp, char *dataToSend, int length);
 
@@ -141,29 +173,49 @@ SR_PRIV int ipdbg_org_la_tcp_send(struct ipdbg_org_la_tcp *tcp, const uint8_t *b
     return SR_OK;
 }
 
-SR_PRIV int ipdbg_org_la_tcp_receive(struct ipdbg_org_la_tcp *tcp, uint8_t *buf, int bufsize)
+SR_PRIV int ipdbg_org_la_tcp_receive_blocking(struct ipdbg_org_la_tcp *tcp, uint8_t *buf, int bufsize)
 {
     int received = 0;
-
-    while(received < bufsize)
+    while (received < bufsize)
     {
-        int len;
-
-        len = recv(tcp->socket, (char*)(buf+received), bufsize-received, 0);
-
-        if (len < 0) {
-            sr_err("Receive error: %s", g_strerror(errno));
-            return SR_ERR;
-        }
-        else
+        int valid = ipdbg_org_la_tcp_receive(tcp, buf);
+        if(valid >0)
         {
-            received += len;
+            ++buf;
+            ++received;
         }
     }
-
     return received;
 }
+SR_PRIV int ipdbg_org_la_tcp_receive(struct ipdbg_org_la_tcp *tcp, uint8_t *buf)
+{
+    int received = 0;
+
+    if (hasData(tcp) == 1)
+    {
+        while(received < 1)
+        {
+            int len = recv(tcp->socket, buf, 1, 0);
+
+            if (len < 0)
+            {
+                sr_err("Receive error: %s", g_strerror(errno));
+                return SR_ERR;
+            }
+            else
+            {
+                received += len;
+            }
+        }
+        return received;
+
+    }
+    else
+    {
+        return -1;
+    }
 
+}
 SR_PRIV int ipdbg_org_la_tcp_close(struct ipdbg_org_la_tcp *tcp)
 {
     int ret = SR_ERR;
@@ -315,7 +367,7 @@ SR_PRIV int ipdbg_org_la_receive_data(int fd, int revents, void *cb_data)
     {
         unsigned char byte;
 
-        if (ipdbg_org_la_tcp_receive(tcp, &byte, 1) == 1)
+        if (ipdbg_org_la_tcp_receive(tcp, &byte) == 1)
         {
             if(devc->num_transfers < devc->limit_samples*devc->DATA_WIDTH_BYTES)
                 devc->raw_sample_buf[devc->num_transfers] = byte;
@@ -503,11 +555,10 @@ SR_PRIV void ipdbg_org_la_get_addrwidth_and_datawidth(struct ipdbg_org_la_tcp *t
     if(ipdbg_org_la_tcp_send(tcp, auslesen, 1) != SR_OK)
         sr_warn("Can't send K_Mauslesen");
 
-
-    /// delay
-    if(ipdbg_org_la_tcp_receive(tcp, buf, 8) != 8)
+    if (ipdbg_org_la_tcp_receive_blocking(tcp, buf,8)!=8)
         sr_warn("getAddrAndDataWidth failed");
 
+
     devc->DATA_WIDTH  =  buf[0]        & 0x000000FF;
     devc->DATA_WIDTH |= (buf[1] <<  8) & 0x0000FF00;
     devc->DATA_WIDTH |= (buf[2] << 16) & 0x00FF0000;
@@ -567,7 +618,7 @@ SR_PRIV int ipdbg_org_la_requestID(struct ipdbg_org_la_tcp *tcp)
         sr_warn("IDBG can't send");
 
     char ID[4];
-    if(ipdbg_org_la_tcp_receive(tcp, (uint8_t*)ID, 4) != 4)
+    if(ipdbg_org_la_tcp_receive_blocking(tcp, (uint8_t*)ID, 4) != 4)
     {
         sr_warn("IDBG can't read");
     }
index cc7e6fc47c5a60595c1f8dea8e31d9c444cabda4..bf57fd5371ef19362459387165a029278b33b2d3 100644 (file)
@@ -61,7 +61,7 @@ SR_PRIV int ipdbg_org_la_tcp_open(struct ipdbg_org_la_tcp *tcp);
 SR_PRIV int ipdbg_org_la_tcp_close(struct ipdbg_org_la_tcp *tcp);
 SR_PRIV void ipdbg_org_la_tcp_free(struct ipdbg_org_la_tcp *tcp);
 SR_PRIV int ipdbg_org_la_tcp_send(struct ipdbg_org_la_tcp *tcp, const uint8_t *buf, size_t len);
-SR_PRIV int ipdbg_org_la_tcp_receive(struct ipdbg_org_la_tcp *tcp, uint8_t *buf, int bufsize);
+SR_PRIV int ipdbg_org_la_tcp_receive(struct ipdbg_org_la_tcp *tcp, uint8_t *buf);
 
 SR_PRIV struct ipdbg_org_la_dev_context *ipdbg_org_la_dev_new(void);
 SR_PRIV void ipdbg_org_la_get_addrwidth_and_datawidth(struct ipdbg_org_la_tcp *tcp, struct ipdbg_org_la_dev_context *devc);
@@ -73,5 +73,7 @@ SR_PRIV int ipdbg_org_la_sendDelay(struct ipdbg_org_la_dev_context *devc, struct
 SR_PRIV int ipdbg_org_la_convert_trigger(const struct sr_dev_inst *sdi);
 SR_PRIV int ipdbg_org_la_receive_data(int fd, int revents, void *cb_data);
 SR_PRIV void ipdbg_org_la_abort_acquisition(const struct sr_dev_inst *sdi);
+SR_PRIV int ipdbg_org_la_tcp_receive_blocking(struct ipdbg_org_la_tcp *tcp, uint8_t *buf, int bufsize);
+int hasData(struct ipdbg_org_la_tcp *tcp);
 
 #endif