Brief description of class still missing. More...
#include <CubeBuffer.h>
Public Member Functions | |
CubeBuffer (int fd, CubeTcpServer *server, CubeDevice *device) | |
unsigned int | frequency () const |
unsigned int | hardwareGain () const |
bool | isRunning () const |
unsigned long int | runningTime () const |
void | sequenceNotAvailable (unsigned int sequenceNumber) |
unsigned int | softwareGain () const |
unsigned int | timeMode () const |
~CubeBuffer () | |
Protected Member Functions | |
virtual int | bytesAvailable (char *buffer, int bytesCount) |
Brief description of class still missing.
Full description of class still missing
CubeBuffer::CubeBuffer | ( | int | fd, |
CubeTcpServer * | server, | ||
CubeDevice * | device | ||
) |
Description of constructor still missing
References NUMBER_OF_CHANNELS, GpCoreTools::MovingStatistics::reset(), and TRACE.
: DynamicBuffer(fd) { TRACE; _server=server; _device=device; _maxPpsBegin=500; // Maximum drift _nextSequence=0; _running=false; _startTime=0; _frequency=0; _period=0; _softGain=0; _hardGain=0; _adcMode=0; _timeMode=0; _deviceNoiseLevel=0.0; // Todo: according to gains, defines significant bits+margin, test it! _sensorConnected=false; _restartCount=0; // Initialize a default size for moving average (2 sec @ 100 Hz) for(int i=0; i<NUMBER_OF_CHANNELS; i++) { _statistics[i].reset(200); } }
int CubeBuffer::bytesAvailable | ( | char * | buffer, |
int | bytesCount | ||
) | [protected, virtual] |
Returns the number of accepted bytes.
Implements GpCoreTools::DynamicBuffer.
References GpCoreTools::DynamicBuffer::debugBuffer(), GpCoreTools::DynamicBuffer::debugEndIgnoreByte(), GpCoreTools::DynamicBuffer::debugIgnoreByte(), GpCoreTools::MessageClassIdHeader::isValid(), GpCoreTools::MessageClassIdHeader::lengthBigEndian(), GpCoreTools::MessageClassIdHeader::messageClass, GpCoreTools::MessageClassIdHeader::messageId, GpCoreTools::DynamicBuffer::read(), and TRACE.
{ TRACE; /*timeval t; gettimeofday(&t, 0); Log::write(8, "t%i %u %u\n", bytesCount, t.tv_sec, t.tv_usec);*/ // If less bytes are available, just wait for more data. int readBytes=MessageClassIdHeader::SynchronizationSize+ MessageClassIdHeader::HeaderSize+ MessageClassIdHeader::CheckSumSize; if(bytesCount<readBytes) { return 0; } // Expects that the buffer begins with the DASCube packet tag 0xB5 0x62 // If there are some garbage at the beginning scan for the first // match of the tag (try to synchronize) MessageClassIdHeader * hdr=reinterpret_cast<MessageClassIdHeader *>(buffer); if(!hdr->isValid()) { debugIgnoreByte(); return 1; } else { debugEndIgnoreByte(); } unsigned short length=hdr->lengthBigEndian(); readBytes+=length; if(bytesCount<readBytes) { return 0; } buffer+=MessageClassIdHeader::SynchronizationSize+MessageClassIdHeader::HeaderSize; char * payload=buffer; buffer+=length; if(hdr->isValid(*reinterpret_cast<const FletcherChecksum *>(buffer), payload, length)) { read(hdr->messageClass(), hdr->messageId(), length, payload); return readBytes; } else { readCorrupted(hdr->messageClass(), hdr->messageId(), length, payload); Log::write(0, "[ERROR] received block class 0x%02hhX id 0x%02hhX with bad checksum\n", hdr->messageClass(), hdr->messageId()); debugBuffer(); // Instead of skipping completely the corrupted block, scan it byte per byte to find 0xB5 0x62 debugIgnoreByte(); return 1; } }
unsigned int CubeBuffer::frequency | ( | ) | const [inline] |
Referenced by CubeDevice::frequency().
{return _frequency;}
unsigned int CubeBuffer::hardwareGain | ( | ) | const [inline] |
Referenced by CubeDevice::hardwareGain().
{return _hardGain;}
bool CubeBuffer::isRunning | ( | ) | const [inline] |
Referenced by CubeDevice::isRunning().
{return _running;}
unsigned long int CubeBuffer::runningTime | ( | ) | const |
Returns the duration of recording since last start in seconds.
References TRACE.
Referenced by CubeDevice::runningTime().
{ TRACE; if(_startTime==0) { return 0; } else { unsigned long int globalSampleIndex; if(_sampleIndexOverflowCount==0) { globalSampleIndex=_sampleIndex; } else { globalSampleIndex=0xFFFFFFFFu; globalSampleIndex*=_sampleIndexOverflowCount; globalSampleIndex+=_sampleIndex; } ldiv_t t0=ldiv(globalSampleIndex, _frequency); return t0.quot; } }
void CubeBuffer::sequenceNotAvailable | ( | unsigned int | sequenceNumber | ) |
References TRACE.
Referenced by ErrorPayload::get().
{ TRACE; std::list<unsigned int>::iterator it; for(it=_missingSequences.begin(); it!=_missingSequences.end(); it++) { if(*it==sequenceNumber) { _missingSequences.erase(it); Log::write(0, "[ERROR] sequence %i not available any more :-(\n", sequenceNumber); return; } } }
unsigned int CubeBuffer::softwareGain | ( | ) | const [inline] |
Referenced by CubeDevice::softwareGain().
{return _softGain;}
unsigned int CubeBuffer::timeMode | ( | ) | const [inline] |
Referenced by CubeDevice::timeMode().
{return _timeMode;}