Public Member Functions | Protected Member Functions
CrystalfontzBuffer Class Reference

Brief description of class still missing. More...

#include <CrystalfontzBuffer.h>

Inheritance diagram for CrystalfontzBuffer:
GpCoreTools::DynamicBuffer

List of all members.

Public Member Functions

 CrystalfontzBuffer (int fileDescriptor, CrystalfontzDevice *device)
 ~CrystalfontzBuffer ()

Protected Member Functions

int bytesAvailable (char *buffer, int byteCount)

Detailed Description

Brief description of class still missing.

Full description of class still missing


Constructor & Destructor Documentation

CrystalfontzBuffer::CrystalfontzBuffer ( int  fileDescriptor,
CrystalfontzDevice device 
)

Description of constructor still missing

References TRACE.

  : DynamicBuffer(fileDescriptor)
{
  TRACE;
  _device=device;
}

Description of destructor still missing

References TRACE.

{
  TRACE;
}

Member Function Documentation

int CrystalfontzBuffer::bytesAvailable ( char *  buffer,
int  byteCount 
) [protected, virtual]

Returns the number of accepted bytes. Bytes received are always ignored.

Implements GpCoreTools::DynamicBuffer.

References GpCoreTools::MessageRawHeader::isValid(), GpCoreTools::MessageRawHeader::lengthLittleEndian(), TRACE, and GpCoreTools::Serial::write().

{
  TRACE;
  // If less bytes are available, just wait for more data.
  int readBytes=MessageRawHeader::SynchronizationSize+
                MessageRawHeader::HeaderSize+
                MessageRawHeader::CheckSumSize;
  if(byteCount<readBytes) {
    return 0;
  }
  // Expects that the buffer begins with the packet tag 0xB5 0x62
  // If there are some garbage at the beginning scan for the first
  // match of the tag (try to synchronize)
  MessageRawHeader * hdr=reinterpret_cast<MessageRawHeader *>(buffer);
  if(!hdr->isValid()) {
    return 1;
  }
  // The buffer contains a valid header, continue parsing
  // Now the total lenght of the packet is known, check if it is
  // available.
  unsigned short length=hdr->lengthLittleEndian();
  readBytes+=length;
  if(byteCount<readBytes) {
    return 0;
  }
  buffer+=MessageRawHeader::SynchronizationSize+MessageRawHeader::HeaderSize;
  char * payload=buffer;
  buffer+=length;
  if(hdr->isValid(*reinterpret_cast<const FletcherChecksum *>(buffer), payload, length)) {
    _device->write(payload, length);
  }
  return readBytes;
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines