sd 32 update
Dependencies: FreescaleIAP mbed-rtos mbed
Fork of COM_MNG_TMTC_SIMPLE by
COM_SND_TM_functions.h
00001 // ***************************************** CONVOLUTION ***************************************** 00002 class Convolution{ 00003 00004 private: 00005 typedef struct ConvNode{ 00006 //next state 00007 //format : 8 bits mapped as [1]xxxx [0]xxxx 00008 unsigned char nextState; 00009 00010 //output 00011 // format : 8 bits mapped as 00012 // **** xxxx{2} [1]-[0] {1} [1]-[0] i.e. ****xxxx 00013 // x = data, * = junk 00014 unsigned char output; 00015 }ConvNode; 00016 00017 ConvNode convStateList[16]; 00018 00019 public: 00020 /* 00021 @brief: Constructor : Initialise all the variables 00022 @param: none 00023 @return: none 00024 */ 00025 Convolution(){ 00026 00027 convStateList[0].nextState = 0x10; 00028 convStateList[1].nextState = 0x32; 00029 convStateList[2].nextState = 0x54; 00030 convStateList[3].nextState = 0x76; 00031 convStateList[4].nextState = 0x98; 00032 convStateList[5].nextState = 0xBA; 00033 convStateList[6].nextState = 0xDC; 00034 convStateList[7].nextState = 0xFE; 00035 convStateList[8].nextState = 0x10; 00036 convStateList[9].nextState = 0x32; 00037 convStateList[10].nextState = 0x54; 00038 convStateList[11].nextState = 0x76; 00039 convStateList[12].nextState = 0x98; 00040 convStateList[13].nextState = 0xBA; 00041 convStateList[14].nextState = 0xDC; 00042 convStateList[15].nextState = 0xFE; 00043 00044 convStateList[0].output = 0x0A; 00045 convStateList[1].output = 0x06; 00046 convStateList[2].output = 0x06; 00047 convStateList[3].output = 0x0A; 00048 convStateList[4].output = 0x09; 00049 convStateList[5].output = 0x05; 00050 convStateList[6].output = 0x05; 00051 convStateList[7].output = 0x09; 00052 convStateList[8].output = 0x05; 00053 convStateList[9].output = 0x09; 00054 convStateList[10].output = 0x09; 00055 convStateList[11].output = 0x05; 00056 convStateList[12].output = 0x06; 00057 convStateList[13].output = 0x0A; 00058 convStateList[14].output = 0x0A; 00059 convStateList[15].output = 0x06; 00060 } 00061 00062 00063 /* 00064 @brief: convolution encode the input bytes : in sync with => (1-TM-Frame -> 2-T-Frame) 00065 @param: inPtr : pointer to input unsigned char array 00066 inLength : length in bytes of input array 00067 outPtr : pointer to the output bytes, define it outside the function 00068 outLength : length of output array in bytes [call by reference, edited inside the function] 00069 @return: none 00070 */ 00071 void convolutionEncode(unsigned char *input, unsigned char *output){ 00072 00073 // cout << "inside convolution" << endl; 00074 00075 unsigned int convState = 0; 00076 00077 int inBit = 7; 00078 unsigned int inByte = 0; 00079 00080 unsigned int outState = 0; 00081 unsigned int outByte = 0; 00082 00083 for(unsigned int j = 0 ; j < 536 ; ++j){ 00084 // printf("j = %u, inByte = %u\n", j, inByte); 00085 // read a new bit from input stream 00086 // cout << "inByte " <<inByte; 00087 unsigned char tempBit = (input[inByte] >> inBit) & 1; 00088 --inBit; 00089 00090 // convolute and write output 00091 switch(outState){ 00092 case 0: 00093 outState = 2; 00094 output[outByte] = ( (convStateList[convState].output >> tempBit) & 1 ) << 7; 00095 output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ) << 6; 00096 break; 00097 case 2: 00098 outState = 4; 00099 output[outByte] += ( (convStateList[convState].output >> tempBit) & 1 ) << 5; 00100 output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ) << 4; 00101 break; 00102 case 4: 00103 outState = 6; 00104 output[outByte] += ( (convStateList[convState].output >> tempBit) & 1 ) << 3; 00105 output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ) << 2; 00106 break; 00107 case 6: 00108 outState = 0; 00109 output[outByte] += ( (convStateList[convState].output >> tempBit) & 1 ) << 1; 00110 output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ); 00111 ++outByte; 00112 output[outByte] = 0x00; 00113 break; 00114 } 00115 00116 // next state transition 00117 switch(tempBit){ 00118 case 0: 00119 convState = (convStateList[convState].nextState) & 0xF; 00120 break; 00121 case 1: 00122 convState = (convStateList[convState].nextState >> 4) & 0xF; 00123 break; 00124 } 00125 00126 if(inBit == -1){ 00127 // printf("in byte = %u\n", inByte); 00128 ++inByte; 00129 inBit = 7; 00130 } 00131 00132 } 00133 00134 // printf("normal iteration complete, outByte = %u\n", outByte); 00135 00136 for(unsigned int j = 0 ; j < 4 ; ++j){ 00137 // printf("j = %u\n, outByte = %u\n", j, outByte); 00138 // append zero at the end 00139 switch(outState){ 00140 case 0: 00141 outState = 2; 00142 output[outByte] = ( (convStateList[convState].output) & 1 ) << 7; 00143 output[outByte] += ( (convStateList[convState].output >> 2) & 1 ) << 6; 00144 break; 00145 case 2: 00146 outState = 4; 00147 output[outByte] += ( (convStateList[convState].output) & 1 ) << 5; 00148 output[outByte] += ( (convStateList[convState].output >> 2) & 1 ) << 4; 00149 break; 00150 case 4: 00151 outState = 6; 00152 output[outByte] += ( (convStateList[convState].output ) & 1 ) << 3; 00153 output[outByte] += ( (convStateList[convState].output >> 2) & 1 ) << 2; 00154 break; 00155 case 6: 00156 outState = 0; 00157 output[outByte] += ( (convStateList[convState].output ) & 1 ) << 1; 00158 output[outByte] += ( (convStateList[convState].output >> 2) & 1 ); 00159 ++outByte; 00160 // printf("outByte @ end of switch = %u\n", outByte); 00161 break; 00162 } 00163 // next state transition 00164 convState = (convStateList[convState].nextState) & 0xF; 00165 } 00166 // printf("complete\n"); 00167 } 00168 00169 }; 00170 00171 00172 // ******************************************** INTERLEAVE ************************************** 00173 void interleave( unsigned char *input, unsigned char *output ){ 00174 00175 unsigned int outState = 0; 00176 unsigned int outByte = 0; 00177 00178 for( unsigned int i = 0 ; i < 36 ; ++i ){ 00179 for(unsigned int j = 0 ; j < 30 ; ++j){ 00180 unsigned int x = j*36+i; 00181 unsigned char tempBit = ((input[x >> 3]) >> (7-(x % 8))) & 1; 00182 switch(outState){ 00183 case 0: 00184 outState = 1; 00185 output[outByte] = tempBit << 7; 00186 break; 00187 case 1: 00188 outState = 2; 00189 output[outByte] += tempBit << 6; 00190 break; 00191 case 2: 00192 outState = 3; 00193 output[outByte] += tempBit << 5; 00194 break; 00195 case 3: 00196 outState = 4; 00197 output[outByte] += tempBit << 4; 00198 break; 00199 case 4: 00200 outState = 5; 00201 output[outByte] += tempBit << 3; 00202 break; 00203 case 5: 00204 outState = 6; 00205 output[outByte] += tempBit << 2; 00206 break; 00207 case 6: 00208 outState = 7; 00209 output[outByte] += tempBit << 1; 00210 break; 00211 case 7: 00212 outState = 0; 00213 output[outByte] += tempBit; 00214 ++outByte; 00215 break; 00216 } 00217 } 00218 for(unsigned int j = 0 ; j < 2 ; ++j){ 00219 switch(outState){ 00220 case 0: 00221 output[outByte] = 0; 00222 outState = 1; 00223 break; 00224 case 1: 00225 outState = 2; 00226 break; 00227 case 2: 00228 outState = 3; 00229 break; 00230 case 3: 00231 outState = 4; 00232 break; 00233 case 4: 00234 outState = 5; 00235 break; 00236 case 5: 00237 outState = 6; 00238 break; 00239 case 6: 00240 outState = 7; 00241 break; 00242 case 7: 00243 outState = 0; 00244 ++outByte; 00245 break; 00246 } 00247 } 00248 } 00249 }
Generated on Tue Jul 12 2022 10:59:21 by 1.7.2