From: Eva Kissling Date: Mon, 2 Oct 2017 15:17:09 +0000 (+0200) Subject: ipdbg-la: stop-command X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=b51288e3da87626637d8c11a5cb22918d0e60ba8;hp=b8fa29a1756eaa4a58b2556dc23dc8089447d549 ipdbg-la: stop-command --- diff --git a/src/hardware/ipdbg-logic-analyser/api.c b/src/hardware/ipdbg-logic-analyser/api.c index db4497a8..ecdefa46 100644 --- a/src/hardware/ipdbg-logic-analyser/api.c +++ b/src/hardware/ipdbg-logic-analyser/api.c @@ -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); diff --git a/src/hardware/ipdbg-logic-analyser/protocol.c b/src/hardware/ipdbg-logic-analyser/protocol.c index de6cc27e..69dd6198 100644 --- a/src/hardware/ipdbg-logic-analyser/protocol.c +++ b/src/hardware/ipdbg-logic-analyser/protocol.c @@ -35,6 +35,8 @@ #include #include "protocol.h" +#include + #define BUFFER_SIZE 4 @@ -66,6 +68,36 @@ #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"); } diff --git a/src/hardware/ipdbg-logic-analyser/protocol.h b/src/hardware/ipdbg-logic-analyser/protocol.h index cc7e6fc4..bf57fd53 100644 --- a/src/hardware/ipdbg-logic-analyser/protocol.h +++ b/src/hardware/ipdbg-logic-analyser/protocol.h @@ -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