Software Architecture Advice
Posted: Mon Apr 01, 2013 9:13 am
I've got an app I need to build on an SB70LC. This app will use both serial ports running at 115200 with no handshaking. The Ethernet interface will have upwards of three sockets, one outbound (connection triggered by the state of an I/O line), and two inbound, one of which will only be listening when the other is connected (complicated reasoning behind that). This application is being built to emulate a competitors product (Lantronix) that I can no longer use, with the goal to not have to change the code in the device it is connected to.
I've built a first pass at this using a single task with nothing but select(). The timeout for select() is fairly short, and when it times out, I check the I/O line to see if I need to make or drop the outbound connection. The application works fine unless there is a large amount of data sent over the serial port in a single burst. When this happens, I miss some of the serial data. The connected device will send about 4K of data in one burst. At best, I usually only get about 3.8K of it, missing some of the data in the middle. My code double buffers the data, in that I read() into one buffer, and transfer that data to another buffer, which is then used by the write() to the appropriate socket. This is a circular buffer that has head and tail pointers and I am careful to handle the wrap appropriately, and is larger than this burst of data.
My question is, is using select() this way the most efficient way to handle reading large amounts of serial data over two ports? Or should I break this application down into multiple tasks? Perhaps one task per serial port, or even one task per file descriptor? Would doing this enable me to process data faster and not miss any like my first pass attempt?
I've built a first pass at this using a single task with nothing but select(). The timeout for select() is fairly short, and when it times out, I check the I/O line to see if I need to make or drop the outbound connection. The application works fine unless there is a large amount of data sent over the serial port in a single burst. When this happens, I miss some of the serial data. The connected device will send about 4K of data in one burst. At best, I usually only get about 3.8K of it, missing some of the data in the middle. My code double buffers the data, in that I read() into one buffer, and transfer that data to another buffer, which is then used by the write() to the appropriate socket. This is a circular buffer that has head and tail pointers and I am careful to handle the wrap appropriately, and is larger than this burst of data.
My question is, is using select() this way the most efficient way to handle reading large amounts of serial data over two ports? Or should I break this application down into multiple tasks? Perhaps one task per serial port, or even one task per file descriptor? Would doing this enable me to process data faster and not miss any like my first pass attempt?