The serial library provides a very simple device driver that uses UDP/IP
to send data, without error correction or packet loss detection, to the
AOS06 port (UDP 26706) on your development machine. The port
number was chosen to be easy to remember; Imagine you are dialing 'AOS06',
the port number is the series of digits you dialled.
struct serial * serial_init()
serial_init initalises the state of the serial driver and
returns a handle that must be passed to other serial functions.
int serial_send(struct serial *serial, char *data, int
serial_send will write
len bytes of
data to the AOS06 port (UDP 26706) on your
development machine. This function returns the number of bytes written,
which may be less than
len. This occurs if the serial driver's
internal buffer fills faster than it can actually output data. In this case
it is up to the calling code to handle the situation, either by retrying or
returning an error to the user.
You can see this output by running netcat:
nc -lup 26706 in
a terminal window.
int serial_register_handler(struct serial *serial, void
(*handler)((struct serial *) serial, char c));
To receive input from the netcat terminal you must register a
handler function, which will be called by the serial driver
when the network makes data available. The provided function simply takes
the inputted character as it's only argument. This function will be called
during an interrupt context so it should be reasonably light-weight.
What's really happening here
Due to historical reasons we call this driver a serial driver,
even though it has nothing to do with serial ports anymore. The
serial_send() function, in the driver, takes a block of data,
wraps it into a single UDP frame and sends it to 192.168.168.1:26706. You
should be aware that LWIP is not particularly smart and it will not break
up large buffers for you. Limit your buffer size to 1450 bytes or so.
netcat(nc) is a pretty cool program, once it has received data
from a particular machine it will
connect() to the machine and
send all input data onto your service. However this comes with some pretty
serious limitations, as the networking stacks on your machine will happilly
do IP break up of protocol packet. This is good and to be expected, but
LWIP can't deal with the deluge and will just drop everything on the floor.
If needed you will have to write your own bulk transfer protocol.
21 Jul 2006.