Brief description of class still missing. More...
#include <CrystalfontzBuffer.h>
Public Member Functions | |
| CrystalfontzBuffer (int fileDescriptor, CrystalfontzDevice *device) | |
| ~CrystalfontzBuffer () | |
Protected Member Functions | |
| int | bytesAvailable (char *buffer, int byteCount) |
Brief description of class still missing.
Full description of class still missing
| CrystalfontzBuffer::CrystalfontzBuffer | ( | int | fileDescriptor, |
| CrystalfontzDevice * | device | ||
| ) |
Description of constructor still missing
References TRACE.
: DynamicBuffer(fileDescriptor) { TRACE; _device=device; }
| 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;
}