When the buffer wraps and we do it in 2 steps, we can't actually do the
second part if it fails or if we wrote less bytes than we intended,
otherwise we will corrupt the data being sent.
While at it, just like in the write case, explain why we are stopping.
We can't give the TX buffer 16 bytes more since next time begin() is
called it will compare the buffer size to the value the caller is trying
to set. In this case we would free and alloc the buffer again each time
begin was called.
This patch replaces the 'old style' ringbuffer by the ByteBuffer class.
An effort was made to keep the exchange as close as possible from a
drop-in replacement to minimize the risk of introducing bugs.
Although the exchange opens opportunities for improvement and
simplification of this class.
Now instead of requiring the buffer to fill completely before we can
detect it is not draining, we use a time based mechanism to detect
when none of the first few bytes are transmitted after sitting in our
buffer a half second or more after flow control is enabled. This
huristic is reliable only for the first several chracters because we
believe that the radio must still have plenty of room in it's own
buffers at that time even if it is not able to transmit them to the
other radio yet. Note that the original algorithm made the same
assumption.
The new algorithm is especially helpful for cases where only keepalive
messages are transmitted before other packets can be requested by the
GCS. In this situation, the original code required almost 2 minutes
to disable flow control and allow communication with the GCS.
This commit changes the way libraries headers are included in source files:
- If the header is in the same directory the source belongs to, so the
notation '#include ""' is used with the path relative to the directory
containing the source.
- If the header is outside the directory containing the source, then we use
the notation '#include <>' with the path relative to libraries folder.
Some of the advantages of such approach:
- Only one search path for libraries headers.
- OSs like Windows may have a better lookup time.
The modification allows the read and write functions to be called by any thread but the calling thread must be the last one that called the begin() function.
this avoids writes stalling on the GPS port. We can't afford this
memory on APM2, but we can on PX4, and it means that while the GPS is
blocking at startup it doesn't cause any scheduler slips