1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 17:28:50 -05:00

SDRdaemon plugin: new classes

This commit is contained in:
f4exb 2016-01-24 23:38:55 +01:00
parent 1850452601
commit 7a6882829a
8 changed files with 717 additions and 66 deletions

View File

@ -126,6 +126,7 @@ set(sdrbase_SOURCES
sdrbase/settings/preset.cpp
sdrbase/settings/mainsettings.cpp
sdrbase/util/CRC64.cpp
sdrbase/util/db.cpp
sdrbase/util/message.cpp
sdrbase/util/messagequeue.cpp
@ -208,7 +209,8 @@ set(sdrbase_HEADERS
include/settings/preset.h
include/settings/mainsettings.h
include/util/db.h
include/util/CRC64.h
include/util/db.h
include/util/export.h
include/util/message.h
include/util/messagequeue.h

38
include/util/CRC64.h Normal file
View File

@ -0,0 +1,38 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDE_CRC64_H_
#define INCLUDE_CRC64_H_
#include <stdint.h>
class CRC64
{
public:
CRC64();
~CRC64();
uint64_t calculate_crc(uint8_t *stream, int length);
private:
void build_crc_table();
uint64_t m_crcTable[256];
static const uint64_t m_poly;
};
#endif /* INCLUDE_CRC64_H_ */

View File

@ -3,6 +3,7 @@ project(sdrdaemon)
find_package(LZ4)
set(sdrdaemon_SOURCES
sdrdaemonbuffer.cpp
sdrdaemongui.cpp
sdrdaemoninput.cpp
sdrdaemonplugin.cpp
@ -10,6 +11,7 @@ set(sdrdaemon_SOURCES
)
set(sdrdaemon_HEADERS
sdrdaemonbuffer.h
sdrdaemongui.h
sdrdaemoninput.h
sdrdaemonplugin.h

View File

@ -0,0 +1,232 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <cassert>
#include <cstring>
#include <iostream>
#include "sdrdaemonbuffer.h"
SDRdaemonBuffer::SDRdaemonBuffer(std::size_t blockSize) :
m_blockSize(blockSize),
m_sync(false),
m_lz4(false),
m_lz4InBuffer(0),
m_lz4InCount(0),
m_lz4InSize(0),
m_lz4OutBuffer(0),
m_lz4OutSize(0),
m_nbDecodes(0),
m_nbSuccessfulDecodes(0),
m_nbCRCOK(0),
m_dataCRC(0)
{
m_buf = new uint8_t[blockSize];
m_currentMeta.init();
}
SDRdaemonBuffer::~SDRdaemonBuffer()
{
delete[] m_buf;
}
bool SDRdaemonBuffer::writeAndRead(uint8_t *array, std::size_t length, uint8_t *data, std::size_t& dataLength)
{
assert(length == m_blockSize); // TODO: allow fragmented blocks with larger size
MetaData *metaData = (MetaData *) array;
if (m_crc64.calculate_crc(array, sizeof(MetaData) - 8) == metaData->m_crc)
{
dataLength = 0;
memcpy((void *) &m_dataCRC, (const void *) &array[sizeof(MetaData)], 8);
if (!(m_currentMeta == *metaData))
{
std::cerr << "SDRdaemonBuffer::writeAndRead: ";
printMeta(metaData);
}
m_currentMeta = *metaData;
// sanity checks
if (metaData->m_blockSize == m_blockSize) // sent blocksize matches given blocksize
{
if (metaData->m_sampleBytes & 0x10)
{
m_lz4 = true;
updateSizes(metaData);
}
else
{
m_lz4 = false;
}
m_sync = true;
}
else
{
m_sync = false;
}
return false;
}
else
{
if (m_sync)
{
if (m_lz4)
{
return writeAndReadLZ4(array, length, data, dataLength);
}
else
{
std::memcpy((void *) data, (const void *) array, length);
dataLength = length;
return true;
}
}
else
{
dataLength = 0;
return false;
}
}
}
bool SDRdaemonBuffer::writeAndReadLZ4(uint8_t *array, std::size_t length, uint8_t *data, std::size_t& dataLength)
{
if (m_lz4InCount + length < m_lz4InSize)
{
std::memcpy((void *) &m_lz4InBuffer[m_lz4InCount], (const void *) array, length); // copy data in compressed Buffer
dataLength = 0;
m_lz4InCount += length;
}
else
{
std::memcpy((void *) &m_lz4InBuffer[m_lz4InCount], (const void *) array, m_lz4InSize - m_lz4InCount); // copy rest of data in compressed Buffer
m_lz4InCount += length;
}
if (m_lz4InCount >= m_lz4InSize) // full input compressed block retrieved
{
if (m_nbDecodes == 100)
{
std::cerr << "SDRdaemonBuffer::writeAndReadLZ4:"
<< " decoding: " << m_nbCRCOK
<< ":" << m_nbSuccessfulDecodes
<< "/" << m_nbDecodes
<< std::endl;
m_nbDecodes = 0;
m_nbSuccessfulDecodes = 0;
m_nbCRCOK = 0;
}
uint64_t crc64 = m_crc64.calculate_crc(m_lz4InBuffer, m_lz4InSize);
//uint64_t crc64 = 0x0123456789ABCDEF;
if (memcmp(&crc64, &m_dataCRC, 8) == 0)
{
m_nbCRCOK++;
}
int compressedSize = LZ4_decompress_fast((const char*) m_lz4InBuffer, (char*) m_lz4OutBuffer, m_lz4OutSize);
m_nbDecodes++;
if (compressedSize == m_lz4InSize)
{
/*
std::cerr << "SDRdaemonBuffer::writeAndReadLZ4: decoding OK:"
<< " read: " << compressedSize
<< " expected: " << m_lz4InSize
<< " out: " << m_lz4OutSize
<< std::endl;
*/
std::memcpy((void *) data, (const void *) m_lz4OutBuffer, m_lz4OutSize); // send what is in buffer
dataLength = m_lz4OutSize;
m_nbSuccessfulDecodes++;
}
else
{
// std::cerr << "SDRdaemonBuffer::writeAndReadLZ4: decoding error:"
// << " read: " << compressedSize
// << " expected: " << m_lz4InSize
// << " out: " << m_lz4OutSize
// << std::endl;
//if (compressedSize > 0)
//{
std::memcpy((void *) data, (const void *) m_lz4OutBuffer, m_lz4OutSize); // send what is in buffer
dataLength = m_lz4OutSize;
//}
//else
//{
// dataLength = 0;
//}
}
m_lz4InCount = 0;
}
return dataLength != 0;
}
void SDRdaemonBuffer::updateSizes(MetaData *metaData)
{
m_lz4InSize = metaData->m_nbBytes; // compressed input size
uint32_t sampleBytes = metaData->m_sampleBytes & 0x0F;
uint32_t originalSize = sampleBytes * 2 * metaData->m_nbSamples * metaData->m_nbBlocks;
if (originalSize != m_lz4OutSize)
{
uint32_t masInputSize = LZ4_compressBound(originalSize);
if (m_lz4InBuffer) {
delete[] m_lz4InBuffer;
}
m_lz4InBuffer = new uint8_t[m_lz4InSize]; // provide extra space for a full UDP block
if (m_lz4OutBuffer) {
delete[] m_lz4OutBuffer;
}
m_lz4OutBuffer = new uint8_t[originalSize];
m_lz4OutSize = originalSize;
}
m_lz4InCount = 0;
}
void SDRdaemonBuffer::printMeta(MetaData *metaData)
{
std::cerr
<< "|" << metaData->m_centerFrequency
<< ":" << metaData->m_sampleRate
<< ":" << (int) (metaData->m_sampleBytes & 0xF)
<< ":" << (int) metaData->m_sampleBits
<< ":" << metaData->m_blockSize
<< ":" << metaData->m_nbSamples
<< "||" << metaData->m_nbBlocks
<< ":" << metaData->m_nbBytes
<< "|" << metaData->m_tv_sec
<< ":" << metaData->m_tv_usec
<< std::endl;
}

View File

@ -0,0 +1,94 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef PLUGINS_SAMPLESOURCE_SDRDAEMON_SDRDAEMONBUFFER_H_
#define PLUGINS_SAMPLESOURCE_SDRDAEMON_SDRDAEMONBUFFER_H_
#include <stdint.h>
#include <cstring>
#include <cstddef>
#include <lz4.h>
#include "util/CRC64.h"
class SDRdaemonBuffer
{
public:
#pragma pack(push, 1)
struct MetaData
{
// critical data
uint64_t m_centerFrequency; //!< center frequency in Hz
uint32_t m_sampleRate; //!< sample rate in Hz
uint8_t m_sampleBytes; //!< MSB(4): indicators, LSB(4) number of bytes per sample
uint8_t m_sampleBits; //!< number of effective bits per sample
uint16_t m_blockSize; //!< payload size
uint32_t m_nbSamples; //!< number of samples in a hardware block
// end of critical data
uint16_t m_nbBlocks; //!< number of hardware blocks in the frame
uint32_t m_nbBytes; //!< total number of bytes in the frame
uint32_t m_tv_sec; //!< seconds of timestamp at start time of frame processing
uint32_t m_tv_usec; //!< microseconds of timestamp at start time of frame processing
uint64_t m_crc; //!< 64 bit CRC of the above
bool operator==(const MetaData& rhs)
{
return (memcmp((const void *) this, (const void *) &rhs, 20) == 0); // Only the 20 first bytes are relevant (critical)
}
void init()
{
memset((void *) this, 0, sizeof(MetaData));
}
void operator=(const MetaData& rhs)
{
memcpy((void *) this, (const void *) &rhs, sizeof(MetaData));
}
};
#pragma pack(pop)
SDRdaemonBuffer(std::size_t blockSize);
~SDRdaemonBuffer();
bool writeAndRead(uint8_t *array, std::size_t length, uint8_t *data, std::size_t& dataLength);
const MetaData& getCurrentMeta() const { return m_currentMeta; }
private:
bool writeAndReadLZ4(uint8_t *array, std::size_t length, uint8_t *data, std::size_t& dataLength);
void updateSizes(MetaData *metaData);
void printMeta(MetaData *metaData);
std::size_t m_blockSize; //!< UDP block (payload) size
bool m_sync; //!< Meta data acquired (Stream synchronized)
bool m_lz4; //!< Stream is compressed with LZ4
MetaData m_currentMeta; //!< Stored current meta data
CRC64 m_crc64; //!< CRC64 calculator
uint8_t *m_buf; //!< UDP block buffer
uint8_t *m_lz4InBuffer; //!< Buffer for LZ4 compressed input
uint32_t m_lz4InCount; //!< Current position in LZ4 input buffer
uint32_t m_lz4InSize; //!< Size in bytes of the LZ4 input data
uint8_t *m_lz4OutBuffer; //!< Buffer for LZ4 uncompressed output
uint32_t m_lz4OutSize; //!< Size in bytes of the LZ4 output data (original uncomressed data)
uint32_t m_nbDecodes;
uint32_t m_nbSuccessfulDecodes;
uint32_t m_nbCRCOK;
uint64_t m_dataCRC;
};
#endif /* PLUGINS_SAMPLESOURCE_SDRDAEMON_SDRDAEMONBUFFER_H_ */

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>198</width>
<height>133</height>
<width>343</width>
<height>207</height>
</rect>
</property>
<property name="sizePolicy">
@ -23,22 +23,13 @@
</font>
</property>
<property name="windowTitle">
<string>BladeRF</string>
<string>SDRdaemon</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>2</number>
</property>
<item>
@ -119,6 +110,187 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="addressLayout">
<item>
<widget class="QLabel" name="addressLabel">
<property name="text">
<string>Addr:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="address">
<property name="minimumSize">
<size>
<width>120</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="portLabel">
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="port">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="addressApplyButton">
<property name="maximumSize">
<size>
<width>30</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>OK</string>
</property>
</widget>
</item>
<item>
<spacer name="iaddressSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="rateTimeLayout">
<item>
<widget class="QLabel" name="sampleRateText">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="toolTip">
<string>Record sample rate</string>
</property>
<property name="text">
<string>0k</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="Line" name="absTimeLine">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="absTimeText">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Record absolute time</string>
</property>
<property name="text">
<string>20150101 00:00:00.000</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="decimLayout">
<item>
<widget class="QLabel" name="label_decim">
<property name="text">
<string>Dec.</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="decim">
<property name="toolTip">
<string>Decimation factor</string>
</property>
<property name="maximum">
<number>6</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="value">
<number>0</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="decimText">
<property name="text">
<string>1</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="decimRate">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>0k</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="fileSelectionLayout">
<item>
@ -172,58 +344,6 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="rateTimeLayout">
<item>
<widget class="QLabel" name="sampleRateText">
<property name="font">
<font>
<pointsize>8</pointsize>
</font>
</property>
<property name="toolTip">
<string>Record sample rate</string>
</property>
<property name="text">
<string>0k</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="Line" name="absTimeLine">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="absTimeText">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Record absolute time</string>
</property>
<property name="text">
<string>20150101 00:00:00.000</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_rate">
<property name="orientation">

View File

@ -21,6 +21,7 @@
#include <QMutex>
#include <QWaitCondition>
#include <QTimer>
#include <iostream>
#include <fstream>
#include <cstdlib>
@ -29,6 +30,8 @@
#define SDRDAEMON_THROTTLE_MS 50
class QUdpSocket;
class SDRdaemonThread : public QThread {
Q_OBJECT
@ -50,6 +53,7 @@ private:
bool m_running;
std::ifstream* m_ifstream;
QUdpSocket *m_dataSocket;
quint8 *m_buf;
std::size_t m_bufsize;
std::size_t m_chunksize;

159
sdrbase/util/CRC64.cpp Normal file
View File

@ -0,0 +1,159 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2016 Edouard Griffiths, F4EXB //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include "util/CRC64.h"
/**
* poly is: x^64 + x^62 + x^57 + x^55 + x^54 + x^53 + x^52 + x^47 + x^46 + x^45 + x^40 + x^39 +
* x^38 + x^37 + x^35 + x^33 + x^32 + x^31 + x^29 + x^27 + x^24 + x^23 + x^22 + x^21 +
* x^19 + x^17 + x^13 + x^12 + x^10 + x^9 + x^7 + x^4 + x^1 + 1
*
* represented here with lsb = highest degree term
*
* 1100100101101100010101111001010111010111100001110000111101000010_
* || | | || || | | |||| | | ||| | |||| ||| |||| | | |
* || | | || || | | |||| | | ||| | |||| ||| |||| | | +- x^64 (implied)
* || | | || || | | |||| | | ||| | |||| ||| |||| | |
* || | | || || | | |||| | | ||| | |||| ||| |||| | +--- x^62
* || | | || || | | |||| | | ||| | |||| ||| |||| +-------- x^57
* .......................................................................
* ||
* |+---------------------------------------------------------------- x^1
* +----------------------------------------------------------------- x^0 (1)
*/
const uint64_t CRC64::m_poly = 0xC96C5795D7870F42ull;
CRC64::CRC64()
{
build_crc_table();
}
CRC64::~CRC64()
{}
/**
* input is dividend: as 0000000000000000000000000000000000000000000000000000000000000000<8-bit byte>
* where the lsb of the 8-bit byte is the coefficient of the highest degree term (x^71) of the dividend
* so division is really for input byte * x^64
*
* you may wonder how 72 bits will fit in 64-bit data type... well as the shift-right occurs, 0's are supplied
* on the left (most significant) side ... when the 8 shifts are done, the right side (where the input
* byte was placed) is discarded
*
* when done, table[XX] (where XX is a byte) is equal to the CRC of 00 00 00 00 00 00 00 00 XX
*/
void CRC64::build_crc_table()
{
for(int i = 0; i < 256; ++i)
{
uint64_t crc = i;
for(unsigned int j = 0; j < 8; ++j)
{
if(crc & 1) // is current coefficient set?
{
crc >>= 1; // yes, then assume it gets zero'd (by implied x^64 coefficient of dividend)
crc ^= m_poly; // and add rest of the divisor
}
else // no? then move to next coefficient
{
crc >>= 1;
}
}
m_crcTable[i] = crc;
}
}
/**
* will give an example CRC calculation for input array {0xDE, 0xAD}
*
* each byte represents a group of 8 coefficients for 8 dividend terms
*
* the actual polynomial dividend is:
*
* = DE AD 00 00 00 00 00 00 00 00 (hex)
* = 11011110 10101101 0000000000000000000...0 (binary)
* || |||| | | || |
* || |||| | | || +------------------------ x^71
* || |||| | | |+-------------------------- x^69
* || |||| | | +--------------------------- x^68
* || |||| | +----------------------------- x^66
* || |||| +------------------------------- x^64
* || ||||
* || |||+---------------------------------- x^78
* || ||+----------------------------------- x^77
* || |+------------------------------------ x^76
* || +------------------------------------- x^75
* |+--------------------------------------- x^73
* +---------------------------------------- x^72
*
*
* the basic idea behind how the table lookup results can be used with one
* another is that:
*
* Mod(A * x^n, P(x)) = Mod(x^n * Mod(A, P(X)), P(X))
*
* in other words, an input data shifted towards the higher degree terms
* changes the pre-computed crc of the input data by shifting it also
* the same amount towards higher degree terms (mod the polynomial)
*
* here is an example:
*
* 1) input:
*
* 00 00 00 00 00 00 00 00 AD DE
*
* 2) index crc table for byte DE (really for dividend 00 00 00 00 00 00 00 00 DE)
*
* we get A8B4AFBDC5A6ACA4
*
* 3) apply that to the input stream:
*
* 00 00 00 00 00 00 00 00 AD DE
* A8 B4 AF BD C5 A6 AC A4
* -----------------------------
* 00 A8 B4 AF BD C5 A6 AC 09
*
* 4) index crc table for byte 09 (really for dividend 00 00 00 00 00 00 00 00 09)
*
* we get 448FCBB7FCB9E309
*
* 5) apply that to the input stream
*
* 00 A8 B4 AF BD C5 A6 AC 09
* 44 8F CB B7 FC B9 E3 09
* --------------------------
* 44 27 7F 18 41 7C 45 A5
*
*/
uint64_t CRC64::calculate_crc(uint8_t *stream, int length)
{
uint64_t crc = 0;
for (int i = 0 ; i < length; ++i)
{
uint8_t index = stream[i] ^ crc;
uint64_t lookup = m_crcTable[index];
crc >>= 8;
crc ^= lookup;
}
return crc;
}