sd 32 update
Dependencies: FreescaleIAP mbed-rtos mbed
Fork of COM_MNG_TMTC_SIMPLE by
COM_SND_TM.h
00001 //void adf_not_SDcard(); 00002 00003 #define S_FRAME_SIZE 48 00004 #define ISR 40 00005 #define TM_FRAME_SIZE 134 //in bytes 00006 #define T_FRAME_SIZE 159 00007 #define EOS_SIZE 120 00008 #define MAX_ADF_LEN 65535 00009 00010 const unsigned char S_frame[] = {0x46,0x9D,0xFB,0xF0,0xD2,0xBA,0x89,0xE4,0x46,0x9D,0xFB,0xF0,0xD2,0xBA,0x89,0xE4,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; 00011 const unsigned char EoS[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x1A,0x77,0xEF,0xC3,0x4A,0xEA,0x27,0x91,0x1A,0x77,0xEF,0xC3,0x4A,0xEA,0x27,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x1A,0x77,0xEF,0xC3,0x4A,0xEA,0x27,0x91,0x1A,0x77,0xEF,0xC3,0x4A,0xEA,0x27,0x90,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; 00012 const unsigned char FCCH80[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; 00013 const unsigned char SCH40[] = {0x0a,0x3f,0x46,0xb4,0x00}; 00014 const unsigned char EXOR_SEQ[] = {0x55,0xF1,0x51,0x3D,0xA7,0x42,0xAE,0x2E,0x2E,0x28,0x76,0x80,0x62,0x41,0xC4,0x75,0x4D,0x87,0xDB,0xE1,0x02,0x61,0x60,0x96,0x9C,0xCB,0x8A,0xBD,0x37,0xE4,0x72,0x5D,0xF2,0x19,0x62,0x06,0x9A,0xF9,0x38,0xB0,0x49,0x75,0xD0,0x17,0x1B,0xCC,0x0B,0xEB,0x1B,0x50,0xA2,0x2A,0x8E,0xFA,0x4D,0x6F,0x1B,0xF8,0x0F,0x97,0x39,0x25,0x60,0x55,0x9A,0xDF,0x1D,0x10,0x7F,0xBD,0x3E,0xBF,0xE5,0x68,0x02,0xD1,0x99,0x0D,0xDF,0x84,0x2E,0x15,0xE3,0x08,0xD7,0x44,0x10,0x41,0xCE,0x93,0xF6,0x59,0x71,0xD2,0xF7,0x1C,0x4A,0x44,0x2D,0xA9,0x44,0x98,0x3A,0x00,0x71,0xCC,0x2A,0x35,0xC1,0x81,0xCF,0x44,0xF7,0x6A,0x0E,0xE4,0xF2,0xFC,0xD6,0x0B,0xA8,0x95,0x7B,0x86,0xB5,0xF8,0x33,0xE9,0xBF,0x6A,0x0E,0xE6,0x53,0x82}; 00015 00016 class SND_TM{ 00017 00018 Base_tm * head_ptr; 00019 00020 // transmit data variables 00021 unsigned char Tframe_c; //_c represents counter, counts Tframe written in a segment 00022 unsigned char EOS_c; //count no of bytes of eos have been weitten in the rolling buffer 00023 unsigned char Sframe_c; //count no of bytes of Sframe have been weitten in the rolling buffer 00024 unsigned char SCH40_c; //count no of bytes of SCH40 have been weitten in the rolling buffer 00025 unsigned char data_c; 00026 unsigned char FCCH80_c; 00027 unsigned char RB_c; //rolling buffer counter 00028 unsigned char segment_c; //counts the numver of segments sent 00029 unsigned char MAX_SEGMENT; 00030 bool Sframe; //Sframe = 1bit of CF1 00031 bool SCH40_f; 00032 bool FCCH80_f; 00033 bool data_f; 00034 bool repeat_data_f; 00035 bool transmit_data_f; 00036 bool eos_f; 00037 bool junk_f; 00038 bool segment_r; //flag checking if more sessions are required 00039 00040 00041 // type 1 frame 00042 00043 Base_tm *T0F_pointer ; 00044 00045 int diff_prev; 00046 void differential_encode(unsigned char* ptr, int length){ 00047 for(int i=0; i<length;i++){ 00048 unsigned char s = ptr[i] , t; 00049 t = s ^ (s >> 1); 00050 (diff_prev == 0) ? t=t^0x00 : t=t^0x80 ; 00051 diff_prev = int(s & 0x01); 00052 ptr[i] = t; 00053 } 00054 } 00055 00056 int type0_no; //number of type zero frames 00057 int type1_no; 00058 int total_frames; //number of type one packe (TMP) 00059 int SEGMENT_NO; //number of type one packe (TMP) 00060 int TOTAL_SEGMENT_NO; 00061 int LAST_SEGMENT_SIZE; 00062 void inline data_number(){ 00063 int type1_frame_no; 00064 Base_tm*head = head_ptr; 00065 type0_no = 0; 00066 type1_no = 0; 00067 while(head != NULL){ 00068 switch( GETshort_or_long_tm(head->fields) ){ 00069 case 0: 00070 type0_no++; 00071 break; 00072 case 1: 00073 type1_no++; 00074 break; 00075 } 00076 00077 head=head->next_TM; 00078 } 00079 type1_frame_no = ( type1_no % 10 == 0 )? (type1_no / 10) : ( (type1_no / 10) + 1); 00080 total_frames = type0_no + type1_frame_no ; 00081 TOTAL_SEGMENT_NO = (total_frames*2 % (ISR) == 0) ? ( total_frames*2/(ISR) ) : (total_frames*2/(ISR) + 1); //subtracting 1 since the last SCH40_f is not detected 00082 SEGMENT_NO = TOTAL_SEGMENT_NO; 00083 if(SEGMENT_NO > MAX_SEGMENT) 00084 { 00085 SEGMENT_NO = MAX_SEGMENT; 00086 } 00087 if(SEGMENT_NO == 1) segment_r = 0; else segment_r = 1; 00088 TOTAL_SEGMENT_NO -= SEGMENT_NO; 00089 LAST_SEGMENT_SIZE = total_frames*2%ISR?total_frames*2%ISR:ISR; 00090 } 00091 00092 #define next_type_structure(ptr){\ 00093 unsigned char temp = GETshort_or_long_tm(ptr->fields);\ 00094 if((temp == 0) && (ptr->next_TM != NULL) ){\ 00095 do{\ 00096 ptr = ptr->next_TM;\ 00097 temp = GETshort_or_long_tm(ptr->fields);\ 00098 }\ 00099 while(temp == 1 && ptr->next_TM != NULL);\ 00100 if(temp == 1){\ 00101 ptr = NULL;\ 00102 }\ 00103 }\ 00104 else if((temp == 1) && (ptr->next_TM != NULL)){\ 00105 do{\ 00106 ptr = ptr->next_TM;\ 00107 temp = GETshort_or_long_tm(ptr->fields);\ 00108 }\ 00109 while(temp == 0 && ptr->next_TM != NULL);\ 00110 if(temp == 0){\ 00111 ptr = NULL;\ 00112 }\ 00113 }\ 00114 else{\ 00115 ptr = NULL;\ 00116 }\ 00117 } 00118 00119 /* 00120 brief: take input type 0 or 1 and return the address of the first node in the list that have that type 00121 parameter: type 0 or 1 00122 return: pointer of the first node having same type 00123 */ 00124 #define exor(ptr) { for(int i=0 ; i<134; i++ ) ptr[i]=ptr[i]^EXOR_SEQ[i];} 00125 00126 00127 #define first_type_structure( type,return_ptr) {\ 00128 Base_tm* temp_ptr = head_ptr;\ 00129 if(type == 0){\ 00130 while(GETshort_or_long_tm(temp_ptr->fields) == 1){\ 00131 temp_ptr = temp_ptr->next_TM;\ 00132 if(temp_ptr == NULL){\ 00133 return_ptr = NULL ;\ 00134 }\ 00135 }\ 00136 }\ 00137 else if(type == 1){\ 00138 while(GETshort_or_long_tm(temp_ptr->fields) == 0){\ 00139 temp_ptr = temp_ptr->next_TM;\ 00140 if(temp_ptr == NULL){\ 00141 return_ptr = NULL;\ 00142 }\ 00143 }\ 00144 }\ 00145 return_ptr = temp_ptr;\ 00146 } 00147 00148 00149 00150 Base_tm *T1F_pointer ; 00151 int T1F_counter; 00152 unsigned char TMframe_type1[TM_FRAME_SIZE]; 00153 bool type1_frame_flag; //should be true for every new list 00154 00155 #define type1_frame(ptr){\ 00156 int i=4;\ 00157 if(type1_frame_flag){\ 00158 first_type_structure(1,T1F_pointer);\ 00159 T1F_counter = 0;\ 00160 type1_frame_flag = false;\ 00161 }\ 00162 for(i = 4 ; (i < 134) && (T1F_pointer != NULL) ; i++){\ 00163 TMframe_type1[i] = T1F_pointer->TM_string[T1F_counter];\ 00164 if(T1F_counter++ == 12){\ 00165 T1F_counter = 0;\ 00166 next_type_structure(T1F_pointer);\ 00167 }\ 00168 }\ 00169 TMframe_type1[0] = (1<<7) + (( (i-4)/13 )<<3);\ 00170 TMframe_type1[3] = crc16_gen(TMframe_type1,3);\ 00171 if(T1F_pointer == NULL && i>12){\ 00172 for( ; i < 134 ; i++){\ 00173 TMframe_type1[i] = TMframe_type1[i-13];\ 00174 }\ 00175 }\ 00176 ptr=TMframe_type1;\ 00177 } 00178 00179 00180 bool type0_frame_flag; 00181 00182 00183 #define type0_frame(ptr){\ 00184 if(type0_frame_flag){\ 00185 first_type_structure(0,T0F_pointer);\ 00186 type0_frame_flag = false;\ 00187 }\ 00188 else {\ 00189 next_type_structure(T0F_pointer);\ 00190 }\ 00191 ptr = T0F_pointer->TM_string;\ 00192 } 00193 00194 unsigned char convoluted_frame[270]; 00195 Convolution ConvObj2; 00196 void convolution (unsigned char * ptr){ 00197 ConvObj2.convolutionEncode(ptr, convoluted_frame); 00198 ConvObj2.convolutionEncode(ptr + 67, convoluted_frame + 135); 00199 } 00200 00201 00202 unsigned char interleave_data[2][144]; 00203 unsigned char DS_index; 00204 bool DS_state; 00205 int DS_counter; 00206 bool DS_f; 00207 bool make_DataStream_f; 00208 00209 #define make_DataStream {\ 00210 unsigned char* ptr;\ 00211 if(make_DataStream_f == true){\ 00212 DS_state = true;\ 00213 DS_counter = 0;\ 00214 DS_f = false;\ 00215 make_DataStream_f = false;\ 00216 }\ 00217 if(DS_state){\ 00218 if(DS_counter < total_frames-type0_no){\ 00219 type1_frame(ptr); \ 00220 DS_f = true;\ 00221 }\ 00222 else if(DS_counter < total_frames ){\ 00223 type0_frame(ptr);\ 00224 DS_f = true;\ 00225 }\ 00226 DS_counter++;\ 00227 }\ 00228 DS_state = !DS_state;\ 00229 if (DS_f){\ 00230 DS_f = false;\ 00231 exor(ptr);\ 00232 convolution(ptr);\ 00233 interleave(convoluted_frame,interleave_data[0]);\ 00234 interleave(convoluted_frame+ 135,interleave_data[1]);}\ 00235 DS_index = (DS_state==true)?1:0;\ 00236 } 00237 00238 00239 // 00240 public: 00241 00242 bool reset_adf; 00243 SND_TM(){ 00244 MAX_SEGMENT = (MAX_ADF_LEN-EOS_SIZE)/( S_FRAME_SIZE + ISR*T_FRAME_SIZE); 00245 //(max length - eos size)/(sframe length + tFrameLength*ISR) 00246 } 00247 00248 00249 00250 void head_pointer(Base_tm* ptr){ 00251 head_ptr = ptr ; 00252 type1_frame_flag = true; 00253 type0_frame_flag = true; 00254 make_DataStream_f = true; 00255 transmit_data_f = true; 00256 diff_prev = 0; 00257 data_number(); 00258 } 00259 00260 00261 void inline transmit_data(unsigned char * transmit , bool * last_buffer){ 00262 if(transmit_data_f){ 00263 RB_c = 0; 00264 Sframe_c = 0; 00265 SCH40_c = 0; 00266 FCCH80_c = 0; 00267 Tframe_c = 0; 00268 EOS_c = 0; 00269 segment_c = 0; 00270 data_c = 0; 00271 00272 Sframe = true; 00273 SCH40_f = false; 00274 data_f = false; 00275 FCCH80_f = false; 00276 transmit_data_f = false; 00277 reset_adf = false; 00278 *last_buffer = false; 00279 } 00280 00281 for(RB_c = 0 ; RB_c<112 ; RB_c++){ 00282 00283 if(junk_f || *last_buffer){ 00284 transmit[RB_c] = 0x00; 00285 continue; 00286 } 00287 00288 if(Sframe){ 00289 transmit[RB_c] = S_frame[Sframe_c++]; 00290 if(Sframe_c == 48){ 00291 // printf("exit s frame\n"); 00292 Sframe_c = 0; 00293 Sframe = false; 00294 SCH40_f =true; 00295 } 00296 continue; 00297 } 00298 // 00299 if(SCH40_f){ 00300 transmit[RB_c] = SCH40[SCH40_c++]; 00301 if(SCH40_c == 5 ){ 00302 SCH40_c = 0; 00303 SCH40_f = false; 00304 00305 00306 if(Tframe_c >= LAST_SEGMENT_SIZE && segment_r == 0) 00307 { 00308 repeat_data_f = true; 00309 DS_index = !DS_index; 00310 } 00311 else 00312 { 00313 data_f = true; 00314 make_DataStream; 00315 } 00316 // printf("exit SCH40 frame\n"); 00317 } 00318 continue; 00319 } 00320 // 00321 if(data_f){ 00322 transmit[RB_c] = interleave_data[DS_index][data_c++]; 00323 if(data_c == 144){ 00324 data_c = 0; 00325 FCCH80_f = true; 00326 data_f = false; 00327 // printf("exit Data\n"); 00328 } 00329 continue; 00330 } 00331 if(repeat_data_f){ 00332 transmit[RB_c] = interleave_data[DS_index][data_c++]; 00333 if(data_c == 144){ 00334 data_c = 0; 00335 FCCH80_f = true; 00336 repeat_data_f = false; 00337 // printf("exit Data\n"); 00338 } 00339 continue; 00340 } 00341 00342 if(FCCH80_f){ 00343 transmit[RB_c] = FCCH80[FCCH80_c++]; 00344 if(FCCH80_c == 10){ 00345 FCCH80_c = 0; 00346 FCCH80_f = false; 00347 // printf("exit FCCH80\n"); 00348 if(++Tframe_c != ISR) 00349 SCH40_f = true; 00350 else{ 00351 Tframe_c = 0; 00352 segment_c++; 00353 if(segment_c >= SEGMENT_NO - 1 && TOTAL_SEGMENT_NO == 0) segment_r = 0; else segment_r = 1; 00354 if(segment_c == SEGMENT_NO) 00355 {eos_f = true;} 00356 else{ 00357 Sframe = true; 00358 } 00359 } 00360 } 00361 continue; 00362 } 00363 00364 if(eos_f){ 00365 transmit[RB_c] = EoS[EOS_c++]; 00366 if(EOS_c == EOS_SIZE){ 00367 EOS_c = 0; 00368 eos_f = false; 00369 if(segment_c == SEGMENT_NO && segment_r == 0){ 00370 *last_buffer = true; 00371 } 00372 else if(segment_c == SEGMENT_NO && segment_r != 0){ 00373 segment_c = 0; 00374 SEGMENT_NO = TOTAL_SEGMENT_NO; 00375 if(SEGMENT_NO > MAX_SEGMENT) 00376 { 00377 SEGMENT_NO = MAX_SEGMENT; 00378 } 00379 if(SEGMENT_NO == 1) segment_r = 0; else segment_r = 1; 00380 TOTAL_SEGMENT_NO -= SEGMENT_NO; 00381 reset_adf = true;//what does this do?? 00382 Sframe = true; 00383 } 00384 junk_f = true; 00385 } 00386 continue; 00387 } 00388 } 00389 differential_encode(transmit,112); 00390 if(reset_adf == true){ 00391 diff_prev = 0; 00392 junk_f = false; 00393 } 00394 00395 } 00396 00397 }; 00398 SND_TM snd_tm;
Generated on Tue Jul 12 2022 10:59:21 by 1.7.2