int SyncDetected(float[] incomingSamples, int startingIndex, int numSamples) { if (numSamples == 0) { // Adjust demodulator Demodulator.RotateCorrection = SyncCorr.RotateCorrection; // Frequency Correction on receiving the first Sync block // Only apply correction if the accumulated error will be more that 45 degrees if (Math.Abs(SyncCorr.FrequencyCorrection.Degrees * SyncCorr.CorrelationMaxLength) > 45) { Demodulator.FrequencyCorrection = SyncCorr.FrequencyCorrection; } // Get the last 15*32 symbols SyncCorr.GetLastData(SyncCorr.CorrelationMaxIndex, PreambleBlock, 15 * 32); int D1, D2, Z, Cnt; ProcessPreamble(out D1, out D2, out Cnt, out Z); // Check for the reasonable values that we extracted from the preamble // Get the mode from D1 and D2, verify counter ModeInfo mi = MILSTD188_110B.modemModes[D1, D2]; if (Z == 0 && mi != null && Cnt < mi.PreambleSize) { this.CurrentMode = mi; PreambuleCounter = Cnt; if (PreambuleCounter == 0) { InitReceiveData(); NextFunction = ReceiveData; numSamples = 0; } else { PreambleIdx = 0; SyncCorr.StartCorrectionProcess(); } } else { NextFunction = LookForSymbolSync; numSamples = 0; } } int i, nProc; for (i = 0; i < numSamples; i += nProc) { // Decode the preamble chunks nProc = Math.Min(numSamples - i, DECFACTOR); int nSym = Demodulator.Process(incomingSamples, startingIndex + i, nProc); while (nSym-- > 0) { IQ IQData = Demodulator.GetData(); PreambleBlock[PreambleIdx++] = IQData; SyncCorr.Process(IQData); if (PreambleIdx >= PreambleBlock.Length) { // Do demodulator correction Demodulator.RotateCorrection *= SyncCorr.RotateCorrection; Demodulator.FrequencyCorrection *= (IQ.UNITY + 0.05f * SyncCorr.FrequencyCorrection) / 1.05f; int D1, D2, Z, Cnt; ProcessPreamble(out D1, out D2, out Cnt, out Z); // Check the values that we extracted from the preambule // Get the mode from D1 and D2, verify counter if (Z == 0 && D1 == CurrentMode.D1 && D2 == CurrentMode.D2 && Cnt == (PreambuleCounter - 1)) { PreambuleCounter = Cnt; if (PreambuleCounter == 0) { InitReceiveData(); NextFunction = ReceiveData; numSamples = 0; break; } else { PreambleIdx = 0; SyncCorr.StartCorrectionProcess(); } } else { NextFunction = LookForSymbolSync; numSamples = 0; break; } } } } return(i); }
public void Add(ModeInfo data) { ModeArray.Add(data); }