1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-10-02 09:46:38 -04:00

SDRdaemonFEC plugin: check frame and block sequence

This commit is contained in:
f4exb 2016-07-15 19:44:02 +02:00
parent 806a3fb87d
commit 1b8199df89
2 changed files with 44 additions and 27 deletions

View File

@ -109,16 +109,16 @@ void SDRdaemonFECBuffer::rwCorrectionEstimate(int slotIndex)
float rwRatio = (float) (m_nbWrites * sizeof(BufferFrame)) / (float) (m_nbReads * m_readNbBytes); float rwRatio = (float) (m_nbWrites * sizeof(BufferFrame)) / (float) (m_nbReads * m_readNbBytes);
qDebug() << "SDRdaemonFECBuffer::rwCorrectionEstimate: " // qDebug() << "SDRdaemonFECBuffer::rwCorrectionEstimate: "
<< " m_nbReads: " << m_nbReads // << " m_nbReads: " << m_nbReads
<< " m_nbWrites: " << m_nbWrites // << " m_nbWrites: " << m_nbWrites
<< " rwDelta: " << rwDelta // << " rwDelta: " << rwDelta
<< " targetPivotSlot: " << targetPivotSlot // << " targetPivotSlot: " << targetPivotSlot
<< " targetPivotIndex: " << targetPivotIndex // << " targetPivotIndex: " << targetPivotIndex
<< " m_readIndex: " << m_readIndex // << " m_readIndex: " << m_readIndex
<< " normalizedReadIndex: " << normalizedReadIndex // << " normalizedReadIndex: " << normalizedReadIndex
<< " dBytes: " << dBytes // << " dBytes: " << dBytes
<< " m_balCorrection: " << m_balCorrection; // << " m_balCorrection: " << m_balCorrection;
//m_balCorrection = dBytes / (int) (m_iqSampleSize * m_nbReads); //m_balCorrection = dBytes / (int) (m_iqSampleSize * m_nbReads);
m_nbReads = 0; m_nbReads = 0;
@ -186,6 +186,7 @@ void SDRdaemonFECBuffer::writeData(char *array, uint32_t length)
{ {
SuperBlock *superBlock = (SuperBlock *) array; SuperBlock *superBlock = (SuperBlock *) array;
int frameIndex = superBlock->header.frameIndex; int frameIndex = superBlock->header.frameIndex;
int blockIndex = superBlock->header.blockIndex;
int decoderIndex = frameIndex % nbDecoderSlots; int decoderIndex = frameIndex % nbDecoderSlots;
if (m_frameHead == -1) // initial state if (m_frameHead == -1) // initial state
@ -194,8 +195,19 @@ void SDRdaemonFECBuffer::writeData(char *array, uint32_t length)
m_frameHead = frameIndex; m_frameHead = frameIndex;
initReadIndex(); // reset read index initReadIndex(); // reset read index
initDecodeAllSlots(); // initialize all slots initDecodeAllSlots(); // initialize all slots
m_blockIndex = 0;
} }
else if (m_frameHead != frameIndex) // frame break => new frame starts else if (m_frameHead != frameIndex) // frame break => new frame starts
{
if (frameIndex != m_frameHead + 1)
{
qDebug() << "SDRdaemonFECBuffer::writeData: new frame problem start over: " << frameIndex << ":" << m_frameHead << ":" << blockIndex;
m_decoderIndexHead = decoderIndex; // new decoder slot head
m_frameHead = frameIndex;
initReadIndex(); // reset read index
initDecodeAllSlots(); // initialize all slots
}
else
{ {
m_decoderIndexHead = decoderIndex; // new decoder slot head m_decoderIndexHead = decoderIndex; // new decoder slot head
m_frameHead = frameIndex; // new frame head m_frameHead = frameIndex; // new frame head
@ -204,12 +216,13 @@ void SDRdaemonFECBuffer::writeData(char *array, uint32_t length)
initDecodeSlot(decoderIndex); // collect stats and re-initialize current slot initDecodeSlot(decoderIndex); // collect stats and re-initialize current slot
} }
m_blockIndex = 0;
}
if (m_decoderSlots[decoderIndex].m_blockCount < m_nbOriginalBlocks) // not enough blocks to decode -> store data if (m_decoderSlots[decoderIndex].m_blockCount < m_nbOriginalBlocks) // not enough blocks to decode -> store data
{ {
int blockCount = m_decoderSlots[decoderIndex].m_blockCount; int blockCount = m_decoderSlots[decoderIndex].m_blockCount;
int recoveryCount = m_decoderSlots[decoderIndex].m_recoveryCount; int recoveryCount = m_decoderSlots[decoderIndex].m_recoveryCount;
int blockIndex = superBlock->header.blockIndex;
m_decoderSlots[decoderIndex].m_cm256DescriptorBlocks[blockCount].Index = blockIndex; m_decoderSlots[decoderIndex].m_cm256DescriptorBlocks[blockCount].Index = blockIndex;
if (blockIndex == 0) // first block with meta if (blockIndex == 0) // first block with meta
@ -241,24 +254,27 @@ void SDRdaemonFECBuffer::writeData(char *array, uint32_t length)
m_decoderSlots[decoderIndex].m_recoveryCount++; m_decoderSlots[decoderIndex].m_recoveryCount++;
} }
m_decoderSlots[decoderIndex].m_blockCount++; if ((blockIndex > 0) && (blockIndex <= m_blockIndex))
{
qDebug() << "SDRdaemonFECBuffer::writeData: block out of sequence: " << blockIndex << ":" << m_blockIndex;
} }
}
m_decoderSlots[decoderIndex].m_blockCount++;
m_blockIndex = blockIndex;
if (m_decoderSlots[decoderIndex].m_blockCount == m_nbOriginalBlocks) // ready to decode if (m_decoderSlots[decoderIndex].m_blockCount == m_nbOriginalBlocks) // ready to decode
{ {
m_decoderSlots[decoderIndex].m_decoded = true; m_decoderSlots[decoderIndex].m_decoded = true;
if (m_decoderSlots[decoderIndex].m_recoveryCount > 0) // recovery data used => need to decode FEC
{
if (m_decoderSlots[decoderIndex].m_metaRetrieved) // block zero with its meta data has been received if (m_decoderSlots[decoderIndex].m_metaRetrieved) // block zero with its meta data has been received
{ {
MetaDataFEC *metaData = (MetaDataFEC *) &m_decoderSlots[decoderIndex].m_blockZero; m_currentMeta = *((MetaDataFEC *) &m_decoderSlots[decoderIndex].m_blockZero);
m_paramsCM256.RecoveryCount = metaData->m_nbFECBlocks;
} }
else
if (m_decoderSlots[decoderIndex].m_recoveryCount > 0) // recovery data used => need to decode FEC
{ {
m_paramsCM256.RecoveryCount = m_currentMeta.m_nbFECBlocks; // take last stored value for number of FEC blocks m_paramsCM256.RecoveryCount = m_currentMeta.m_nbFECBlocks; // take last stored value for number of FEC blocks
}
if (cm256_decode(m_paramsCM256, m_decoderSlots[decoderIndex].m_cm256DescriptorBlocks)) // failure to decode if (cm256_decode(m_paramsCM256, m_decoderSlots[decoderIndex].m_cm256DescriptorBlocks)) // failure to decode
{ {

View File

@ -165,6 +165,7 @@ private:
int m_readIndex; //!< current byte read index in frames buffer int m_readIndex; //!< current byte read index in frames buffer
int m_wrDeltaEstimate; //!< Sampled estimate of write to read indexes difference int m_wrDeltaEstimate; //!< Sampled estimate of write to read indexes difference
int m_readNbBytes; //!< Nominal number of bytes per read (50ms) int m_readNbBytes; //!< Nominal number of bytes per read (50ms)
int m_blockIndex; //!< Stored block index for verification
uint32_t m_throttlemsNominal; //!< Initial throttle in ms uint32_t m_throttlemsNominal; //!< Initial throttle in ms
uint8_t* m_readBuffer; //!< Read buffer to hold samples when looping back to beginning of raw buffer uint8_t* m_readBuffer; //!< Read buffer to hold samples when looping back to beginning of raw buffer