Conflicts:
	examples/sdr_afsk1200.cc
master
Hannes Matuschek 12 years ago
commit 6455423383

@ -73,38 +73,44 @@ public:
throw err;
}
// The sample rate
// The input sample rate
_sampleRate = src_cfg.sampleRate();
// Symbols per bit (limit to 32 symbols per bit)
_corrLen = std::min(int(_sampleRate/_baud), 32);
// Compute symbol rate:
_symbolRate = _baud*_corrLen;
// Samples per symbol (fractional):
// The resulting sub-sampling will have a symbol rate of _corrLen*_baud
_mu = 0.0; _muIncr = _sampleRate/(_corrLen*_baud);
_mu = 0.0; _muIncr = _sampleRate/_symbolRate;
// Delayline for interpolating sub-sampler
_dl = Buffer<float>(2*8);
for (size_t i=0; i<2*8; i++) { _dl[i] = 0; }
for (size_t i=0; i<(2*8); i++) { _dl[i] = 0; }
_dl_idx = 0;
// Assemble phase LUT:
double phiMark=0, phiSpace=0;
_markLUT = Buffer< std::complex<float> >(_corrLen);
_spaceLUT = Buffer< std::complex<float> >(_corrLen);
// Allocate ring-buffers for mark and space symbols
_markHist = Buffer< std::complex<float> >(_corrLen);
_spaceHist = Buffer< std::complex<float> >(_corrLen);
// Initialize LUTs and ring-buffers
double phiMark=0, phiSpace=0;
for (size_t i=0; i<_corrLen; i++) {
_markLUT[i] = std::exp(std::complex<float>(0.0, phiMark));
_spaceLUT[i] = std::exp(std::complex<float>(0.0, phiSpace));
phiMark += (2.*M_PI*_Fmark)/(_baud*_corrLen);
phiSpace += (2.*M_PI*_Fspace)/(_baud*_corrLen);
phiMark += (2.*M_PI*_Fmark)/_symbolRate;
phiSpace += (2.*M_PI*_Fspace)/_symbolRate;
_markHist[i] = 0; _spaceHist[i] = 0;
}
_lutIdx = 0;
// Get phase increment per symbol
_phase = 0; _phaseInc = _phasePeriod/_corrLen;
_phase = 0; _phaseInc = _phaseMask/_corrLen;
// Allocate output buffer:
_buffer = Buffer<uint8_t>(src_cfg.bufferSize()/_corrLen + 1);
@ -114,7 +120,7 @@ public:
<< " input sample rate: " << _sampleRate << "Hz" << std::endl
<< " samples per symbol: " << _muIncr << std::endl
<< " symbols per bit: " << _corrLen << std::endl
<< " symbol rate: " << (_corrLen*_baud) << "Hz" << std::endl
<< " symbol rate: " << _symbolRate << "Hz" << std::endl
<< " Phase incr/symbol: " << float(_phaseInc)/_phasePeriod;
Logger::get().log(msg);
@ -145,9 +151,9 @@ public:
_symbols <<= 1; _symbols |= (f>0);
// If transition
if ((_symbols ^ (_symbols >> 1)) & 0x1u) {
if ((_symbols ^ (_symbols >> 1)) & 1) {
// Phase correction
if (_phase < (_phasePeriod/2 + _phaseInc/2)) {
if (_phase < (_phasePeriod/2)) {
_phase += _phaseInc/8;
} else {
_phase -= _phaseInc/8;
@ -157,6 +163,7 @@ public:
// Advance phase
_phase += _phaseInc;
// Sample bit
if (_phase >= _phasePeriod) {
// Modulo 2 pi
_phase &= _phaseMask;
@ -172,23 +179,22 @@ public:
protected:
inline float _getSymbol() {
std::complex<float> markSum(0), spaceSum(0);
inline double _getSymbol() {
std::complex<double> markSum(0), spaceSum(0);
for (size_t i=0; i<_corrLen; i++) {
markSum += _markHist[i]/float(1<<16);
spaceSum += _spaceHist[i]/float(1<<16);
markSum += _markHist[i];
spaceSum += _spaceHist[i];
}
markSum /= float(_corrLen); spaceSum /= float(_corrLen);
float f = markSum.real()*markSum.real() +
markSum.imag()*markSum.imag()
- spaceSum.real()*spaceSum.real() -
double f = markSum.real()*markSum.real() +
markSum.imag()*markSum.imag() -
spaceSum.real()*spaceSum.real() -
spaceSum.imag()*spaceSum.imag();
return f;
}
protected:
float _sampleRate;
float _sampleRate, _symbolRate;
float _baud;
float _Fmark, _Fspace;
@ -246,18 +252,15 @@ public:
_ptr = _rxbuffer;
}
virtual void process(const Buffer<uint8_t> &buffer, bool allow_overwrite)
{
for (size_t i=0; i<buffer.size(); )
{
_bitstream <<= 1; _bitstream |= !!(buffer[i]&0x1u); i++;
virtual void process(const Buffer<uint8_t> &buffer, bool allow_overwrite) {
for (size_t i=0; i<buffer.size(); i++) {
_bitstream <<= 1; _bitstream |= buffer[i];
if ((_bitstream & 0xffu) == 0x7eu) {
if ((_bitstream & 0xff) == 0x7e) {
if (_state && ((_ptr - _rxbuffer) > 2)) {
*_ptr = 0;
if (! check_crc_ccitt(_rxbuffer, _ptr-_rxbuffer)) {
std::cerr << "Got invalid buffer (" << std::dec << (_ptr-_rxbuffer)
<< "): " << _rxbuffer << std::endl;
std::cerr << "Got invalid buffer: " << _rxbuffer << std::endl;
} else {
std::cerr << "GOT: " << _rxbuffer << std::endl;
}
@ -275,10 +278,10 @@ public:
if ((_bitstream & 0x3f) == 0x3e) { /* stuffed bit */ continue; }
if (_bitstream & 1) { _bitbuffer |= 0x100u; }
if (_bitstream & 1) { _bitbuffer |= 0x100; }
if (_bitbuffer & 1) {
if ((_ptr-_rxbuffer) > 512) {
if ((_ptr-_rxbuffer) >= 512) {
Logger::get().log(LogMessage(LOG_ERROR, "AX.25 packet too long."));
_state = 0; continue;
}

Loading…
Cancel
Save