/* descramble.h */ // Functions for processing the radio-header: // descramble // deinterleave // FECdecoder // (C) 2011 Jonathan Naylor G4KLX /* * 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; version 2 of the License. * * 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 for more details. */ // This code was originally written by JOnathan Naylor, G4KLX, as part // of the "pcrepeatercontroller" project // More info: // http://groups.yahoo.com/group/pcrepeatercontroller // Changes: // Convert C++ to C // Version 20111106: initial release #include #include // function traceBack int traceBack (int * out, int * m_pathMemory0, int * m_pathMemory1, int * m_pathMemory2, int * m_pathMemory3) { enum FEC_STATE { S0, S1, S2, S3 } state; int loop; int length=0; state=S0; for (loop=329; loop >= 0; loop--, length++) { switch (state) { case S0: // if state S0 if (m_pathMemory0[loop]) { state = S2; // lower path } else { state = S0; // upper path }; // end else - if out[loop]=0; break; case S1: // if state S1 if (m_pathMemory1[loop]) { state = S2; // lower path } else { state = S0; // upper path }; // end else - if out[loop]=1; break; case S2: // if state S2 if (m_pathMemory2[loop]) { state = S3; // lower path } else { state = S1; // upper path }; // end else - if out[loop]=0; break; case S3: // if state S3 if (m_pathMemory3[loop]) { state = S3; // lower path } else { state = S1; // upper path }; // end else - if out[loop]=1; break; }; // end switch }; // end for return(length); }; // end function // function viterbiDecode void viterbiDecode (int n, int *data, int *m_pathMemory0, int *m_pathMemory1, int *m_pathMemory2, int *m_pathMemory3, int *m_pathMetric) { int tempMetric[4]; int metric[8]; int loop; int m1; int m2; metric[0]=(data[1]^0)+(data[0]^0); metric[1]=(data[1]^1)+(data[0]^1); metric[2]=(data[1]^1)+(data[0]^0); metric[3]=(data[1]^0)+(data[0]^1); metric[4]=(data[1]^1)+(data[0]^1); metric[5]=(data[1]^0)+(data[0]^0); metric[6]=(data[1]^0)+(data[0]^1); metric[7]=(data[1]^1)+(data[0]^0); // Pres. state = S0, Prev. state = S0 & S2 m1=metric[0]+m_pathMetric[0]; m2=metric[4]+m_pathMetric[2]; if (m1= 672) { k -= 671; } else if (k >= 660) { k -= 647; }; // end elsif - if }; // end for }; // end function deinterleave /// function scramble void scramble (int * in,int * out) { static const int SCRAMBLER_TABLE_BITS[] = { 0,0,0,0,1,1,1,0,1,1,1,1,0,0,1,0,1,1,0,0,1,0,0,1,0,0,0,0,0,0,1,0, 0,0,1,0,0,1,1,0,0,0,1,0,1,1,1,0,1,0,1,1,0,1,1,0,0,0,0,0,1,1,0,0, 1,1,0,1,0,1,0,0,1,1,1,0,0,1,1,1,1,0,1,1,0,1,0,0,0,0,1,0,1,0,1,0, 1,1,1,1,1,0,1,0,0,1,0,1,0,0,0,1,1,0,1,1,1,0,0,0,1,1,1,1,1,1,1,0, 0,0,0,1,1,1,0,1,1,1,1,0,0,1,0,1,1,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0, 0,1,0,0,1,1,0,0,0,1,0,1,1,1,0,1,0,1,1,0,1,1,0,0,0,0,0,1,1,0,0,1, 1,0,1,0,1,0,0,1,1,1,0,0,1,1,1,1,0,1,1,0,1,0,0,0,0,1,0,1,0,1,0,1, 1,1,1,1,0,1,0,0,1,0,1,0,0,0,1,1,0,1,1,1,0,0,0,1,1,1,1,1,1,1,0,0, 0,0,1,1,1,0,1,1,1,1,0,0,1,0,1,1,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,0, 1,0,0,1,1,0,0,0,1,0,1,1,1,0,1,0,1,1,0,1,1,0,0,0,0,0,1,1,0,0,1,1, 0,1,0,1,0,0,1,1,1,0,0,1,1,1,1,0,1,1,0,1,0,0,0,0,1,0,1,0,1,0,1,1, 1,1,1,0,1,0,0,1,0,1,0,0,0,1,1,0,1,1,1,0,0,0,1,1,1,1,1,1,1,0,0,0, 0,1,1,1,0,1,1,1,1,0,0,1,0,1,1,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,0,1, 0,0,1,1,0,0,0,1,0,1,1,1,0,1,0,1,1,0,1,1,0,0,0,0,0,1,1,0,0,1,1,0, 1,0,1,0,0,1,1,1,0,0,1,1,1,1,0,1,1,0,1,0,0,0,0,1,0,1,0,1,0,1,1,1, 1,1,0,1,0,0,1,0,1,0,0,0,1,1,0,1,1,1,0,0,0,1,1,1,1,1,1,1,0,0,0,0, 1,1,1,0,1,1,1,1,0,0,1,0,1,1,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,0,1,0, 0,1,1,0,0,0,1,0,1,1,1,0,1,0,1,1,0,1,1,0,0,0,0,0,1,1,0,0,1,1,0,1, 0,1,0,0,1,1,1,0,0,1,1,1,1,0,1,1,0,1,0,0,0,0,1,0,1,0,1,0,1,1,1,1, 1,0,1,0,0,1,0,1,0,0,0,1,1,0,1,1,1,0,0,0,1,1,1,1,1,1,1,0,0,0,0,1, 1,1,0,1,1,1,1,0,0,1,0,1,1,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,0,1,0,0, 1,1,0,0,0,1,0,1,1,1,0,1,0,1,1,0,1,1,0,0,0,0,0,1,1,0,0,1,1,0,1,0, 1,0,0,1,1,1,0,0,1,1,1,1,0,1,1,0}; const int SCRAMBLER_TABLE_BITS_LENGTH=720; int loop=0; int m_count=0; for (loop=0; loop < 660; loop++) { out[loop] = in[loop] ^ SCRAMBLER_TABLE_BITS[m_count++]; if (m_count >= SCRAMBLER_TABLE_BITS_LENGTH) { m_count = 0U; }; // end if }; // end for }; // end function scramble