positioning updates
Fork of gnss by
Diff: serial_pipe.cpp
- Revision:
- 2:b10ca4aa2e5e
- Parent:
- 1:ef70a58a6c98
--- a/serial_pipe.cpp Mon Apr 10 11:28:24 2017 +0100 +++ b/serial_pipe.cpp Thu Apr 13 14:45:17 2017 +0000 @@ -20,8 +20,9 @@ _pipeRx( (rx!=NC) ? rxSize : 0), _pipeTx( (tx!=NC) ? txSize : 0) { - if (rx!=NC) - attach(this, &SerialPipe::rxIrqBuf, RxIrq); + if (rx!=NC) { + attach(callback(this, &SerialPipe::rxIrqBuf), RxIrq); + } } SerialPipe::~SerialPipe(void) @@ -47,29 +48,28 @@ { int count = length; const char* ptr = (const char*)buffer; - if (count) - { - do - { + if (count) { + do { int written = _pipeTx.put(ptr, count, false); if (written) { ptr += written; count -= written; txStart(); } - else if (!blocking) + else if (!blocking) { + /* nothing / just wait */; break; - /* nothing / just wait */; + } } while (count); } + return (length - count); } void SerialPipe::txCopy(void) { - while (_SerialPipeBase::writeable() && _pipeTx.readable()) - { + while (_SerialPipeBase::writeable() && _pipeTx.readable()) { char c = _pipeTx.getc(); _SerialPipeBase::_base_putc(c); } @@ -79,8 +79,9 @@ { txCopy(); // detach tx isr if we are done - if (!_pipeTx.readable()) + if (!_pipeTx.readable()) { attach(NULL, TxIrq); + } } void SerialPipe::txStart(void) @@ -89,8 +90,9 @@ attach(NULL, TxIrq); txCopy(); // attach the tx isr to handle the remaining data - if (_pipeTx.readable()) - attach(this, &SerialPipe::txIrqBuf, TxIrq); + if (_pipeTx.readable()) { + attach(callback(this, &SerialPipe::txIrqBuf), TxIrq); + } } // rx channel @@ -101,8 +103,10 @@ int SerialPipe::getc(void) { - if (!_pipeRx.readable()) + if (!_pipeRx.readable()) { return EOF; + } + return _pipeRx.getc(); } @@ -116,10 +120,10 @@ while (_SerialPipeBase::readable()) { char c = _SerialPipeBase::_base_getc(); - if (_pipeRx.writeable()) + if (_pipeRx.writeable()) { _pipeRx.putc(c); - else - /* overflow */; + } else { + /* overflow */ + } } } -