pelican/examples/tutorial/src/SignalDataAdapter.cpp
// Called to de-serialise a chunk of data from the input device.
Called to de-serialise a chunk of data from the input device.
Called to de - serialise a chunk of data from the input device .
void SignalDataAdapter::deserialise(QIODevice* device)
{
    SignalData* blob = (SignalData*) dataBlob();
    unsigned packets = chunkSize() / _packetSize;
    blob->resize(packets * _samplesPerPacket);
    char headerData[_headerSize];
    char* data = (char*) blob->ptr();
    unsigned bytesRead = 0;
    for (unsigned p = 0; p < packets; ++p)
    {
        while (device->bytesAvailable() < _packetSize)
            device->waitForReadyRead(-1);
        device->read(headerData, _headerSize);
        bytesRead += device->read(data + bytesRead, _packetSize - _headerSize);
    }
}
void SignalDataAdapter :: deserialise ( QIODevice * device ) { SignalData * blob = ( SignalData * ) dataBlob ( ) ; unsigned packets = chunkSize ( ) / _packetSize ; blob -> resize ( packets * _samplesPerPacket ) ; char headerData [ _headerSize ] ; char * data = ( char * ) blob -> ptr ( ) ; unsigned bytesRead = 0 ; for ( unsigned p = 0 ; p < packets ; ++ p ) { while ( device -> bytesAvailable ( ) < _packetSize ) device -> waitForReadyRead ( -1 ) ; device -> read ( headerData , _headerSize ) ; bytesRead += device -> read ( data + bytesRead , _packetSize - _headerSize ) ; } }
Called to de-serialise a chunk of data from the input device.
Called to de - serialise a chunk of data from the input device .
// A pointer to the data blob to fill should be obtained by calling the // dataBlob() inherited method. This returns a pointer to an // abstract DataBlob, which should be cast to the appropriate type. // Set the size of the data blob to fill. // The chunk size is obtained by calling the chunkSize() inherited method. // Create a temporary buffer to read out the packet headers, and // get the pointer to the data array in the data blob being filled. // Loop over the UDP packets in the chunk. // Ensure there is enough data to read from the device. // Read the packet header from the input device and dump it. // Read the packet data from the input device into the data blob.