PikeAero::CCommunication Class Reference

base class for communications which require a ring buffer for tx and rx. More...

#include <ccommunication.h>

Inheritance diagram for PikeAero::CCommunication:

Inheritance graph
[legend]
Collaboration diagram for PikeAero::CCommunication:

Collaboration graph
[legend]

Public Member Functions

 CCommunication ()
virtual void flush ()
 Flush transmitter andf receiver.
virtual CMachine::ubit32 rx (CByteArray *buffer, CMachine::ubit32 count=(-1))
 Receive maximum of count bytes into a CByteArray.
virtual CMachine::ubit8 rx ()
 Receive a sinlge byte.
virtual void rxFlush ()
 Flush receiver.
virtual CMachine::ubit32 rxReady ()
 Return the state of the receiver buffer.
virtual CMachine::ubit32 tx (CMachine::bit8 *str)
 Transmit a string and append a newline - may yield CPU time if transmitter ring buffer is full.
virtual CMachine::ubit32 tx (CString &str)
 Transmit a string - may yield CPU time if transmitter ring buffer is full.
virtual CMachine::ubit32 tx (CByteArray *bytes)
 Transmit a byte array - may yield CPU time if transmitter ring buffer is full.
virtual CMachine::ubit8 tx (CMachine::ubit8 ch)
 transmit a single byte - may yield CPU time if transmitter ring buffer is full.
virtual void txFlush ()
 Flush transmitter.
virtual CMachine::ubit32 txnl (CMachine::bit8 *str)
 Transmit a string and append a newline - may yield CPU time if transmitter ring buffer is full.
virtual CMachine::ubit32 txnl (CString &str)
 Transmit a string - may yield CPU time if transmitter ring buffer is full.
virtual CMachine::ubit32 txReady ()
 Return the state of the transmitter buffer.
virtual ~CCommunication ()

Protected Member Functions

CRingBufferrxRingBuffer ()
CRingBuffertxRingBuffer ()

Private Attributes

CRingBuffer mRxRingBuffer
CRingBuffer mTxRingBuffer

Detailed Description

base class for communications which require a ring buffer for tx and rx.

Author:
Michael Sharkey <mike@pikeaero.com>

Definition at line 35 of file ccommunication.h.


Constructor & Destructor Documentation

PikeAero::CCommunication::CCommunication (  ) 

Definition at line 25 of file ccommunication.cpp.

References mRxRingBuffer, mTxRingBuffer, and PikeAero::CByteArray::resize().

00026  : CObject()
00027 {
00028     mRxRingBuffer.resize(16);
00029     mTxRingBuffer.resize(16);
00030 }

Here is the call graph for this function:

PikeAero::CCommunication::~CCommunication (  )  [virtual]

Definition at line 33 of file ccommunication.cpp.

References PikeAero::CByteArray::clear(), mRxRingBuffer, and mTxRingBuffer.

00034 {
00035     mRxRingBuffer.clear();
00036     mTxRingBuffer.clear();
00037 }

Here is the call graph for this function:


Member Function Documentation

virtual void PikeAero::CCommunication::flush (  )  [inline, virtual]

Flush transmitter andf receiver.

Definition at line 107 of file ccommunication.h.

References rxFlush(), and txFlush().

00107 {txFlush(); rxFlush();}

Here is the call graph for this function:

CMachine::ubit32 PikeAero::CCommunication::rx ( CByteArray buffer,
CMachine::ubit32  count = (-1) 
) [virtual]

Receive maximum of count bytes into a CByteArray.

Parameters:
buffer The CByteArray object to receive the bytes.
count Receive a maximum of this many bytes (-1 means unlimited).
Returns:
The number of bytes returned.

Definition at line 140 of file ccommunication.cpp.

References PikeAero::CByteArray::append(), PikeAero::CByteArray::clear(), rx(), and rxReady().

00141 {
00142     CMachine::ubit32 rc = 0;
00143     buffer->clear();
00144     for ( rc = 0; rc < count; rc++ )
00145     {
00146         if ( !rxReady() )
00147             break;
00148         buffer->append( rx() );
00149     }
00150     return rc;
00151 }

Here is the call graph for this function:

CMachine::ubit8 PikeAero::CCommunication::rx (  )  [virtual]

Receive a sinlge byte.

Returns:
Next byte in queue of '' if queue is empty.

Reimplemented in PikeAero::CCommunicationPacket.

Definition at line 129 of file ccommunication.cpp.

References PikeAero::CRingBuffer::remove(), and rxRingBuffer().

Referenced by PikeAero::CTaskConsolePacket::run(), PikeAero::CTaskConsole::run(), and rx().

00130 {
00131     return rxRingBuffer()->remove();
00132 }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void PikeAero::CCommunication::rxFlush (  )  [inline, virtual]

Flush receiver.

Reimplemented in PikeAero::CCommunicationPacket.

Definition at line 102 of file ccommunication.h.

Referenced by flush().

00102 {}

Here is the caller graph for this function:

CMachine::ubit32 PikeAero::CCommunication::rxReady (  )  [virtual]

Return the state of the receiver buffer.

Returns:
If the receiver has a ring buffer, return the number of available bytes, or else 1 for data available, 0 means receiver is empty.

Definition at line 166 of file ccommunication.cpp.

References PikeAero::CRingBuffer::length(), and rxRingBuffer().

Referenced by rx().

00167 {
00168     return rxRingBuffer()->length();
00169 }

Here is the call graph for this function:

Here is the caller graph for this function:

CRingBuffer* PikeAero::CCommunication::rxRingBuffer (  )  [inline, protected]

Definition at line 110 of file ccommunication.h.

References mRxRingBuffer.

Referenced by PikeAero::CCommunicationUART::irq(), rx(), and rxReady().

00110 {return &mRxRingBuffer;}

Here is the caller graph for this function:

CMachine::ubit32 PikeAero::CCommunication::tx ( CMachine::bit8 str  )  [virtual]

Transmit a string and append a newline - may yield CPU time if transmitter ring buffer is full.

Transmit a string.

Returns:
The number of bytes transmitted less the newline.

true indicates successful operation, otherwise a failure occured.

Definition at line 100 of file ccommunication.cpp.

References strlen, and tx().

00101 {
00102     CMachine::ubit32 len = strlen((const char*)str);
00103     for(CMachine::bit32 n=0; n < len; n++)
00104     {
00105         tx(str[n]);
00106     }
00107     return len;
00108 }

Here is the call graph for this function:

CMachine::ubit32 PikeAero::CCommunication::tx ( CString str  )  [virtual]

Transmit a string - may yield CPU time if transmitter ring buffer is full.

Transmit a string.

Returns:
The number of bytes transmitted.

true indicates successful operation, otherwise a failure occured.

Definition at line 71 of file ccommunication.cpp.

References PikeAero::CByteArray::at(), PikeAero::CString::length(), and tx().

00072 {
00073     CMachine::ubit32 len = str.length();
00074     for(CMachine::ubit32 n=0; n < len; n++)
00075     {
00076         tx(str.at(n));
00077     }
00078     return len;
00079 }

Here is the call graph for this function:

CMachine::ubit32 PikeAero::CCommunication::tx ( CByteArray bytes  )  [virtual]

Transmit a byte array - may yield CPU time if transmitter ring buffer is full.

Transmit a byte array.

Returns:
The number of bytes transmitted.

true indicates successful operation, otherwise a failure occured.

Definition at line 57 of file ccommunication.cpp.

References PikeAero::CByteArray::at(), PikeAero::CByteArray::length(), and tx().

00058 {
00059     CMachine::ubit32 len = bytes->length();
00060     for(CMachine::ubit32 n=0; n < len; n++)
00061     {
00062         tx(bytes->at(n));
00063     }
00064     return len;
00065 }

Here is the call graph for this function:

CMachine::ubit8 PikeAero::CCommunication::tx ( CMachine::ubit8  ch  )  [virtual]

transmit a single byte - may yield CPU time if transmitter ring buffer is full.

Returns:
The same byte.

While the transmitter ring buffer is full, yield CPU time.

Reimplemented in PikeAero::CCommunicationPacket, and PikeAero::CCommunicationUART.

Definition at line 43 of file ccommunication.cpp.

References txRingBuffer(), and PikeAero::CTaskScheduler::yield().

Referenced by PikeAero::CTaskTerminal::clearAttributes(), PikeAero::CTaskConsole::commandHelp(), PikeAero::CTaskTerminal::cursorMoveAbsolute(), PikeAero::CTaskTerminal::cursorMoveBackward(), PikeAero::CTaskTerminal::cursorMoveDown(), PikeAero::CTaskTerminal::cursorMoveForward(), PikeAero::CTaskTerminal::cursorMoveUp(), PikeAero::CTaskConsole::drawCommandPrompt(), PikeAero::CTaskConsole::drawStatusBar(), PikeAero::CTaskTerminal::eraseDisplay(), PikeAero::CTaskTerminal::eraseLine(), PikeAero::CTaskConsolePacket::monitor(), PikeAero::CTaskConsole::monitor(), PikeAero::CTaskConsole::run(), PikeAero::CTaskTerminal::setAttributeReverseVideo(), tx(), and txnl().

00044 {
00045     while(!txRingBuffer()->insert(ch))
00046     {
00047         /** While the transmitter ring buffer is full, yield CPU time. */
00048         CTaskScheduler::yield();
00049     }
00050     return ch;
00051 }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual void PikeAero::CCommunication::txFlush (  )  [inline, virtual]

Flush transmitter.

Reimplemented in PikeAero::CCommunicationPacket.

Definition at line 97 of file ccommunication.h.

Referenced by flush().

00097 {}

Here is the caller graph for this function:

CMachine::ubit32 PikeAero::CCommunication::txnl ( CMachine::bit8 str  )  [virtual]

Transmit a string and append a newline - may yield CPU time if transmitter ring buffer is full.

Returns:
The number of bytes transmitted less the newline.

Definition at line 114 of file ccommunication.cpp.

References strlen, and tx().

00115 {
00116     CMachine::ubit32 len = strlen((const char*)str);
00117     for(CMachine::bit32 n=0; n < len; n++)
00118     {
00119         tx(str[n]);
00120     }
00121     tx("\r\n");
00122     return len;
00123 }

Here is the call graph for this function:

CMachine::ubit32 PikeAero::CCommunication::txnl ( CString str  )  [virtual]

Transmit a string - may yield CPU time if transmitter ring buffer is full.

Transmit a string and append a newline.

Returns:
The number of bytes transmitted.

true indicates successful operation, otherwise a failure occured.

Definition at line 85 of file ccommunication.cpp.

References PikeAero::CByteArray::at(), PikeAero::CString::length(), and tx().

Referenced by PikeAero::CCommandHandler::commandQM2C(), PikeAero::CCommandHandler::commandQM2S(), PikeAero::CCommandHandler::commandQMC(), PikeAero::CCommandHandler::commandQMDT(), PikeAero::CCommandHandler::commandQMS(), PikeAero::CCommandHandler::commandQSM2C(), PikeAero::CCommandHandler::commandQSM2S(), PikeAero::CCommandHandler::commandQSM2X(), PikeAero::CCommandHandler::commandQSM2Y(), PikeAero::CCommandHandler::commandQSMC(), PikeAero::CCommandHandler::commandQSMS(), PikeAero::CCommandHandler::commandQSMV(), PikeAero::CCommandHandler::commandSM2C(), PikeAero::CCommandHandler::commandSM2S(), PikeAero::CCommandHandler::commandSMC(), PikeAero::CCommandHandler::commandSMDT(), PikeAero::CCommandHandler::commandSMS(), PikeAero::CCommandHandler::commandSSM2C(), PikeAero::CCommandHandler::commandSSM2S(), PikeAero::CCommandHandler::commandSSM2X(), PikeAero::CCommandHandler::commandSSM2Y(), PikeAero::CCommandHandler::commandSSMC(), PikeAero::CCommandHandler::commandSSMS(), PikeAero::CCommandHandler::commandSSMV(), and PikeAero::CCommandHandler::replyReturn().

00086 {
00087     CMachine::ubit32 len = str.length();
00088     for(CMachine::ubit32 n=0; n < len; n++)
00089     {
00090         tx(str.at(n));
00091     }
00092     tx("\r\n");
00093     return len;
00094 }

Here is the call graph for this function:

Here is the caller graph for this function:

CMachine::ubit32 PikeAero::CCommunication::txReady (  )  [virtual]

Return the state of the transmitter buffer.

Returns:
If transmitter has a ring buffer, return number of free bytes, or else 1 for empty, 0 means transmitter is full

Definition at line 157 of file ccommunication.cpp.

References PikeAero::CRingBuffer::free(), and txRingBuffer().

00158 {
00159     return txRingBuffer()->free();
00160 }

Here is the call graph for this function:

CRingBuffer* PikeAero::CCommunication::txRingBuffer (  )  [inline, protected]

Definition at line 111 of file ccommunication.h.

References mTxRingBuffer.

Referenced by PikeAero::CCommunicationUART::irq(), PikeAero::CCommunicationUART::tx(), tx(), and txReady().

00111 {return &mTxRingBuffer;}

Here is the caller graph for this function:


Field Documentation

Definition at line 114 of file ccommunication.h.

Referenced by CCommunication(), rxRingBuffer(), and ~CCommunication().

Definition at line 115 of file ccommunication.h.

Referenced by CCommunication(), txRingBuffer(), and ~CCommunication().


The documentation for this class was generated from the following files:

Generated on Sun Oct 25 13:59:52 2009 for stingray3 by  doxygen 1.5.8