Dummy program to demonstrate problems: working code
Dependencies: SLCD mbed-rtos mbed
Fork of MNG_TC by
Convolution.h
00001 00002 00003 class Convolution{ 00004 00005 private: 00006 typedef struct ConvNode{ 00007 //next state 00008 //format : 8 bits mapped as [1]xxxx [0]xxxx 00009 unsigned char nextState; 00010 00011 //output 00012 // format : 8 bits mapped as 00013 // **** xxxx{2} [1]-[0] {1} [1]-[0] i.e. ****xxxx 00014 // x = data, * = junk 00015 unsigned char output; 00016 }ConvNode; 00017 00018 ConvNode convStateList[16]; 00019 00020 public: 00021 /* 00022 @brief: Constructor : Initialise all the variables 00023 @param: none 00024 @return: none 00025 */ 00026 Convolution(){ 00027 00028 convStateList[0].nextState = 0x10; 00029 convStateList[1].nextState = 0x32; 00030 convStateList[2].nextState = 0x54; 00031 convStateList[3].nextState = 0x76; 00032 convStateList[4].nextState = 0x98; 00033 convStateList[5].nextState = 0xBA; 00034 convStateList[6].nextState = 0xDC; 00035 convStateList[7].nextState = 0xFE; 00036 convStateList[8].nextState = 0x10; 00037 convStateList[9].nextState = 0x32; 00038 convStateList[10].nextState = 0x54; 00039 convStateList[11].nextState = 0x76; 00040 convStateList[12].nextState = 0x98; 00041 convStateList[13].nextState = 0xBA; 00042 convStateList[14].nextState = 0xDC; 00043 convStateList[15].nextState = 0xFE; 00044 00045 convStateList[0].output = 0x0A; 00046 convStateList[1].output = 0x06; 00047 convStateList[2].output = 0x06; 00048 convStateList[3].output = 0x0A; 00049 convStateList[4].output = 0x09; 00050 convStateList[5].output = 0x05; 00051 convStateList[6].output = 0x05; 00052 convStateList[7].output = 0x09; 00053 convStateList[8].output = 0x05; 00054 convStateList[9].output = 0x09; 00055 convStateList[10].output = 0x09; 00056 convStateList[11].output = 0x05; 00057 convStateList[12].output = 0x06; 00058 convStateList[13].output = 0x0A; 00059 convStateList[14].output = 0x0A; 00060 convStateList[15].output = 0x06; 00061 } 00062 00063 00064 /* 00065 @brief: convolution encode the input bytes : in sync with => (1-TM-Frame -> 2-T-Frame) 00066 @param: inPtr : pointer to input unsigned char array 00067 inLength : length in bytes of input array 00068 outPtr : pointer to the output bytes, define it outside the function 00069 outLength : length of output array in bytes [call by reference, edited inside the function] 00070 @return: none 00071 */ 00072 void convolutionEncode(unsigned char *input, unsigned char *output){ 00073 00074 // cout << "inside convolution" << endl; 00075 00076 unsigned int convState = 0; 00077 00078 int inBit = 7; 00079 unsigned int inByte = 0; 00080 00081 unsigned int outState = 0; 00082 unsigned int outByte = 0; 00083 00084 for(unsigned int j = 0 ; j < 536 ; ++j){ 00085 // printf("j = %u, inByte = %u\n", j, inByte); 00086 // read a new bit from input stream 00087 // cout << "inByte " <<inByte; 00088 unsigned char tempBit = (input[inByte] >> inBit) & 1; 00089 --inBit; 00090 00091 // convolute and write output 00092 switch(outState){ 00093 case 0: 00094 outState = 2; 00095 output[outByte] = ( (convStateList[convState].output >> tempBit) & 1 ) << 7; 00096 output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ) << 6; 00097 break; 00098 case 2: 00099 outState = 4; 00100 output[outByte] += ( (convStateList[convState].output >> tempBit) & 1 ) << 5; 00101 output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ) << 4; 00102 break; 00103 case 4: 00104 outState = 6; 00105 output[outByte] += ( (convStateList[convState].output >> tempBit) & 1 ) << 3; 00106 output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ) << 2; 00107 break; 00108 case 6: 00109 outState = 0; 00110 output[outByte] += ( (convStateList[convState].output >> tempBit) & 1 ) << 1; 00111 output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ); 00112 ++outByte; 00113 output[outByte] = 0x00; 00114 break; 00115 } 00116 00117 // next state transition 00118 switch(tempBit){ 00119 case 0: 00120 convState = (convStateList[convState].nextState) & 0xF; 00121 break; 00122 case 1: 00123 convState = (convStateList[convState].nextState >> 4) & 0xF; 00124 break; 00125 } 00126 00127 if(inBit == -1){ 00128 // printf("in byte = %u\n", inByte); 00129 ++inByte; 00130 inBit = 7; 00131 } 00132 00133 } 00134 00135 // printf("normal iteration complete, outByte = %u\n", outByte); 00136 00137 for(unsigned int j = 0 ; j < 4 ; ++j){ 00138 // printf("j = %u\n, outByte = %u\n", j, outByte); 00139 // append zero at the end 00140 switch(outState){ 00141 case 0: 00142 outState = 2; 00143 output[outByte] = ( (convStateList[convState].output) & 1 ) << 7; 00144 output[outByte] += ( (convStateList[convState].output >> 2) & 1 ) << 6; 00145 break; 00146 case 2: 00147 outState = 4; 00148 output[outByte] += ( (convStateList[convState].output) & 1 ) << 5; 00149 output[outByte] += ( (convStateList[convState].output >> 2) & 1 ) << 4; 00150 break; 00151 case 4: 00152 outState = 6; 00153 output[outByte] += ( (convStateList[convState].output ) & 1 ) << 3; 00154 output[outByte] += ( (convStateList[convState].output >> 2) & 1 ) << 2; 00155 break; 00156 case 6: 00157 outState = 0; 00158 output[outByte] += ( (convStateList[convState].output ) & 1 ) << 1; 00159 output[outByte] += ( (convStateList[convState].output >> 2) & 1 ); 00160 ++outByte; 00161 // printf("outByte @ end of switch = %u\n", outByte); 00162 break; 00163 } 00164 // next state transition 00165 convState = (convStateList[convState].nextState) & 0xF; 00166 } 00167 // printf("complete\n"); 00168 } 00169 00170 };
Generated on Thu Jul 21 2022 03:45:37 by 1.7.2