diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-03-04 00:16:08 -0600 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-03-04 00:16:08 -0600 |
commit | fda60e9d28ae1a5d2bbf6fb108de89d0f6304c5a (patch) | |
tree | f98393f7f18fa3168282a3c52009bb9dbc534054 /servers/fpga_server_lin/src/fpga_conn.cpp | |
parent | 40c129a8eb0f0e20ec82316f80de9d3a6852f311 (diff) | |
download | ulab-fda60e9d28ae1a5d2bbf6fb108de89d0f6304c5a.tar.gz ulab-fda60e9d28ae1a5d2bbf6fb108de89d0f6304c5a.zip |
Work around data transfer problems in FTDI serial converters
Fix glitches in FPGA viewer part
Diffstat (limited to 'servers/fpga_server_lin/src/fpga_conn.cpp')
-rw-r--r-- | servers/fpga_server_lin/src/fpga_conn.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/servers/fpga_server_lin/src/fpga_conn.cpp b/servers/fpga_server_lin/src/fpga_conn.cpp index 0570cff..ed4c012 100644 --- a/servers/fpga_server_lin/src/fpga_conn.cpp +++ b/servers/fpga_server_lin/src/fpga_conn.cpp @@ -29,10 +29,12 @@ #include <arpa/inet.h> #include <netdb.h> #include <fcntl.h> +#include <errno.h> #include <termios.h> #include <unistd.h> #include <sys/signal.h> #include <sys/types.h> +#include <sys/ioctl.h> #include <tqtimer.h> @@ -40,6 +42,10 @@ #include "fpga_conn.h" +#define FLUSH_IN 0 +#define FLUSH_OUT 1 +#define FLUSH_BOTH 2 + #define ABORT_SOCKET(s) s->close(); \ s->disconnect(); \ delete s; \ @@ -195,14 +201,15 @@ int FPGASocket::setupSerial() { void FPGASocket::commandLoop() { int cc; - char buffer[10000]; + int ret; + char buffer[1024]; bool transferred_data; m_criticalSection++; try { transferred_data = false; if (state() == TQSocket::Connected) { - cc = read(m_fd_tty, buffer, 10000); + cc = read(m_fd_tty, buffer, 1024); if (cc > 0) { writeBlock(buffer, cc); flush(); @@ -210,11 +217,26 @@ void FPGASocket::commandLoop() { printf("[DEBUG] Got %d bytes from the serial port\n\r", cc); fflush(stdout); } if (canReadData()) { - cc = readBlock(buffer, 10000); + cc = readBlock(buffer, 1024); if (cc > 0) { - if (write(m_fd_tty, buffer, cc) < 0) { + ret = write(m_fd_tty, buffer, cc); + + // HACK + // This works around a buffer overflow on FTDI serial devices + // It may not be sufficient for baudrates less than 115200! + if (cc > 128) { + usleep(100000); + } + + while ((ret < 0) && (errno == EAGAIN)) { + usleep(1000); + ret = write(m_fd_tty, buffer, cc); + } + if (ret < 0) { // ERROR + printf("[ERROR] Failed to transmit data to serial port (%s, code %d)! Continuing, but data was likely lost\n\r", strerror(errno), errno); fflush(stdout); } + ioctl(m_fd_tty, TCFLSH, FLUSH_OUT); transferred_data = true; printf("[DEBUG] Got %d bytes from the network interface\n\r", cc); fflush(stdout); } @@ -280,4 +302,4 @@ void FPGAServer::newConnection(int socket) { void FPGAServer::remoteConnectionClosed() { m_numberOfConnections--; -}
\ No newline at end of file +} |