Hi Shubham I am just using this to test PYLD code
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of COM_MNG_TMTC_SIMPLE by
COM_SND_TM.h
00001 //void adf_not_SDcard(); 00002 00003 //~ #include"SDcard.h" 00004 /*#define T_frames 30 00005 unsigned char buffer_112_counter,sent_tm = 0; 00006 int disk_read(uint8_t *, uint64_t),j; 00007 bool new_session = true; 00008 bool last_buffer = false; 00009 bool first_block = true; 00010 bool last_block =false; 00011 bool repeat_T_frame = false; 00012 unsigned int counter_in_block=0,diff_prev=0; 00013 unsigned char EOS_counter = 0; 00014 unsigned char enable_T_frame = false; 00015 uint64_t start_block_num ; // Read from TC 00016 uint64_t end_block_num ; // Read from TC 00017 uint64_t Number_of_blocks_to_read ; 00018 uint64_t block_counter = 0; 00019 unsigned char buffer_512[512], buffer_112[112],counter_in_S_frame=0,counter_in_SCH=0; 00020 unsigned char make_EOS_flag = true; 00021 bool reset = false; */ 00022 00023 00024 00025 00026 00027 00028 00029 bool sent_tmfrom_SDcard; 00030 00031 00032 00033 #define S_FRAME_SIZE 48 00034 #define ISR 40 00035 #define TM_FRAME_SIZE 134 //in bytes 00036 #define T_FRAME_SIZE 159 00037 #define EOS_SIZE 120 00038 #define MAX_ADF_LEN 65535 00039 00040 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}; 00041 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}; 00042 const unsigned char FCCH80[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; 00043 const unsigned char SCH40[] = {0x0a,0x3f,0x46,0xb4,0x00}; 00044 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}; 00045 00046 unsigned char interleave_data[2][144]; 00047 #define print_tm(ptr) {\ 00048 for( int i = 0; i < 134; i++ ){\ 00049 gPC.putc(ptr[i]);\ 00050 }\ 00051 } 00052 00053 //void send_tm_from_SD_card(){} 00054 00055 class SND_TM{ 00056 00057 Base_tm * head_ptr; 00058 00059 // transmit data variables 00060 unsigned char Tframe_c; //_c represents counter, counts Tframe written in a segment 00061 unsigned char EOS_c; //count no of bytes of eos have been weitten in the rolling buffer 00062 unsigned char Sframe_c; //count no of bytes of Sframe have been weitten in the rolling buffer 00063 unsigned char SCH40_c; //count no of bytes of SCH40 have been weitten in the rolling buffer 00064 unsigned char data_c; 00065 unsigned char FCCH80_c; 00066 unsigned char RB_c; //rolling buffer counter 00067 unsigned char segment_c; //counts the numver of segments sent 00068 unsigned char MAX_SEGMENT; 00069 bool Sframe; //Sframe = 1bit of CF1 00070 bool SCH40_f; 00071 bool FCCH80_f; 00072 bool data_f; 00073 bool repeat_data_f; 00074 bool transmit_data_f; 00075 bool eos_f; 00076 bool junk_f; 00077 bool segment_r; //flag checking if more sessions are required 00078 00079 00080 // type 1 frame 00081 00082 Base_tm *T0F_pointer ; 00083 00084 int diff_prev; 00085 void differential_encode(unsigned char* ptr, int length){ 00086 for(int i=0; i<length;i++){ 00087 unsigned char s = ptr[i] , t; 00088 t = s ^ (s >> 1); 00089 (diff_prev == 0) ? t=t^0x00 : t=t^0x80 ; 00090 diff_prev = int(s & 0x01); 00091 ptr[i] = t; 00092 } 00093 } 00094 00095 int type0_no; //number of type zero frames 00096 int type1_no; 00097 int total_frames; //number of type one packe (TMP) 00098 int SEGMENT_NO; //number of type one packe (TMP) 00099 int TOTAL_SEGMENT_NO; 00100 int LAST_SEGMENT_SIZE; 00101 void inline data_number(){ 00102 int type1_frame_no; 00103 Base_tm*head = head_ptr; 00104 type0_no = 0; 00105 type1_no = 0; 00106 while(head != NULL){ 00107 switch( GETshort_or_long_tm(head) ){ 00108 case 0: 00109 type0_no++; 00110 break; 00111 case 1: 00112 type1_no++; 00113 break; 00114 } 00115 00116 head=head->next_TM; 00117 } 00118 type1_frame_no = ( type1_no % 10 == 0 )? (type1_no / 10) : ( (type1_no / 10) + 1); 00119 total_frames = type0_no + type1_frame_no ; 00120 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 00121 SEGMENT_NO = TOTAL_SEGMENT_NO; 00122 if(SEGMENT_NO > MAX_SEGMENT) 00123 { 00124 SEGMENT_NO = MAX_SEGMENT; 00125 } 00126 if(SEGMENT_NO == 1) segment_r = 0; else segment_r = 1; 00127 TOTAL_SEGMENT_NO -= SEGMENT_NO; 00128 LAST_SEGMENT_SIZE = total_frames*2%ISR?total_frames*2%ISR:ISR; 00129 } 00130 00131 #define next_type_structure(ptr){\ 00132 unsigned char temp = GETshort_or_long_tm(ptr);\ 00133 if((temp == 0) && (ptr->next_TM != NULL) ){\ 00134 do{\ 00135 ptr = ptr->next_TM;\ 00136 temp = GETshort_or_long_tm(ptr);\ 00137 }\ 00138 while(temp == 1 && ptr->next_TM != NULL);\ 00139 if(temp == 1){\ 00140 ptr = NULL;\ 00141 }\ 00142 }\ 00143 else if((temp == 1) && (ptr->next_TM != NULL)){\ 00144 do{\ 00145 ptr = ptr->next_TM;\ 00146 temp = GETshort_or_long_tm(ptr);\ 00147 }\ 00148 while(temp == 0 && ptr->next_TM != NULL);\ 00149 if(temp == 0){\ 00150 ptr = NULL;\ 00151 }\ 00152 }\ 00153 else{\ 00154 ptr = NULL;\ 00155 }\ 00156 } 00157 00158 /* 00159 brief: take input type 0 or 1 and return the address of the first node in the list that have that type 00160 parameter: type 0 or 1 00161 return: pointer of the first node having same type 00162 */ 00163 #define exor(ptr) { for(int i=0 ; i<134; i++ ) ptr[i]=ptr[i]^EXOR_SEQ[i];} 00164 00165 00166 #define first_type_structure( type,return_ptr) {\ 00167 Base_tm* temp_ptr = head_ptr;\ 00168 if(type == 0){\ 00169 while(GETshort_or_long_tm(temp_ptr) == 1){\ 00170 temp_ptr = temp_ptr->next_TM;\ 00171 if(temp_ptr == NULL){\ 00172 return_ptr = NULL ;\ 00173 }\ 00174 }\ 00175 }\ 00176 else if(type == 1){\ 00177 while(GETshort_or_long_tm(temp_ptr) == 0){\ 00178 temp_ptr = temp_ptr->next_TM;\ 00179 if(temp_ptr == NULL){\ 00180 return_ptr = NULL;\ 00181 }\ 00182 }\ 00183 }\ 00184 return_ptr = temp_ptr;\ 00185 } 00186 00187 00188 00189 Base_tm *T1F_pointer ; 00190 int T1F_counter; 00191 unsigned char TMframe_type1[TM_FRAME_SIZE]; 00192 bool type1_frame_flag; //should be true for every new list 00193 00194 #define type1_frame(ptr){\ 00195 int i=4;\ 00196 if(type1_frame_flag){\ 00197 first_type_structure(1,T1F_pointer);\ 00198 T1F_counter = 0;\ 00199 type1_frame_flag = false;\ 00200 }\ 00201 for(i = 4 ; (i < 134) && (T1F_pointer != NULL) ; i++){\ 00202 TMframe_type1[i] = T1F_pointer->TM_string[T1F_counter];\ 00203 if(T1F_counter++ == 12){\ 00204 T1F_counter = 0;\ 00205 next_type_structure(T1F_pointer);\ 00206 }\ 00207 }\ 00208 TMframe_type1[0] = (1<<7) + (( (i-4)/13 )<<3);\ 00209 TMframe_type1[3] = crc8_gen(TMframe_type1,3);\ 00210 if(T1F_pointer == NULL && i>12){\ 00211 for( ; i < 134 ; i++){\ 00212 TMframe_type1[i] = TMframe_type1[i-13];\ 00213 }\ 00214 }\ 00215 ptr=TMframe_type1;\ 00216 } 00217 00218 00219 bool type0_frame_flag; 00220 00221 00222 #define type0_frame(ptr){\ 00223 if(type0_frame_flag){\ 00224 first_type_structure(0,T0F_pointer);\ 00225 type0_frame_flag = false;\ 00226 }\ 00227 else {\ 00228 next_type_structure(T0F_pointer);\ 00229 }\ 00230 ptr = T0F_pointer->TM_string;\ 00231 } 00232 00233 unsigned char convoluted_frame[270]; 00234 Convolution ConvObj2; 00235 void convolution (unsigned char * ptr){ 00236 ConvObj2.convolutionEncode(ptr, convoluted_frame); 00237 ConvObj2.convolutionEncode(ptr + 67, convoluted_frame + 135); 00238 } 00239 00240 00241 unsigned char interleave_data[2][144]; 00242 unsigned char DS_index; 00243 bool DS_state; 00244 int DS_counter; 00245 bool DS_f; 00246 bool make_DataStream_f; 00247 00248 #define make_DataStream {\ 00249 unsigned char* ptr;\ 00250 if(make_DataStream_f == true){\ 00251 DS_state = true;\ 00252 DS_counter = 0;\ 00253 DS_f = false;\ 00254 make_DataStream_f = false;\ 00255 }\ 00256 if(DS_state){\ 00257 if(DS_counter < total_frames-type0_no){\ 00258 type1_frame(ptr); \ 00259 DS_f = true;\ 00260 }\ 00261 else if(DS_counter < total_frames ){\ 00262 type0_frame(ptr);\ 00263 DS_f = true;\ 00264 }\ 00265 DS_counter++;\ 00266 }\ 00267 DS_state = !DS_state;\ 00268 if (DS_f){\ 00269 DS_f = false;\ 00270 exor(ptr);\ 00271 convolution(ptr);\ 00272 interleave(convoluted_frame,interleave_data[0]);\ 00273 interleave(convoluted_frame+ 135,interleave_data[1]);}\ 00274 DS_index = (DS_state==true)?1:0;\ 00275 } 00276 00277 00278 // 00279 public: 00280 00281 bool reset_adf; 00282 SND_TM(){ 00283 MAX_SEGMENT = (MAX_ADF_LEN-EOS_SIZE)/( S_FRAME_SIZE + ISR*T_FRAME_SIZE); 00284 //(max length - eos size)/(sframe length + tFrameLength*ISR) 00285 } 00286 00287 00288 00289 void head_pointer(Base_tm* ptr){ 00290 head_ptr = ptr ; 00291 type1_frame_flag = true; 00292 type0_frame_flag = true; 00293 make_DataStream_f = true; 00294 transmit_data_f = true; 00295 sent_tmfrom_SDcard = false; 00296 diff_prev = 0; 00297 data_number(); 00298 } 00299 00300 int make_shor_tm(){ 00301 make_DataStream; 00302 return type1_no; 00303 } 00304 void inline transmit_data(unsigned char * transmit , bool * last_buffer){ 00305 if(transmit_data_f){ 00306 RB_c = 0; 00307 Sframe_c = 0; 00308 SCH40_c = 0; 00309 FCCH80_c = 0; 00310 Tframe_c = 0; 00311 EOS_c = 0; 00312 segment_c = 0; 00313 data_c = 0; 00314 00315 Sframe = true; 00316 SCH40_f = false; 00317 data_f = false; 00318 FCCH80_f = false; 00319 transmit_data_f = false; 00320 reset_adf = false; 00321 *last_buffer = false; 00322 } 00323 00324 for(RB_c = 0 ; RB_c<112 ; RB_c++){ 00325 00326 if(junk_f || *last_buffer){ 00327 transmit[RB_c] = 0x00; 00328 continue; 00329 } 00330 00331 if(Sframe){ 00332 transmit[RB_c] = S_frame[Sframe_c++]; 00333 if(Sframe_c == 48){ 00334 // printf("exit s frame\n"); 00335 Sframe_c = 0; 00336 Sframe = false; 00337 SCH40_f =true; 00338 } 00339 continue; 00340 } 00341 // 00342 if(SCH40_f){ 00343 transmit[RB_c] = SCH40[SCH40_c++]; 00344 if(SCH40_c == 5 ){ 00345 SCH40_c = 0; 00346 SCH40_f = false; 00347 00348 00349 if(Tframe_c >= LAST_SEGMENT_SIZE && segment_r == 0) 00350 { 00351 repeat_data_f = true; 00352 DS_index = !DS_index; 00353 } 00354 else 00355 { 00356 data_f = true; 00357 make_DataStream; 00358 } 00359 // printf("exit SCH40 frame\n"); 00360 } 00361 continue; 00362 } 00363 // 00364 if(data_f){ 00365 transmit[RB_c] = interleave_data[DS_index][data_c++]; 00366 if(data_c == 144){ 00367 data_c = 0; 00368 FCCH80_f = true; 00369 data_f = false; 00370 // printf("exit Data\n"); 00371 } 00372 continue; 00373 } 00374 if(repeat_data_f){ 00375 transmit[RB_c] = interleave_data[DS_index][data_c++]; 00376 if(data_c == 144){ 00377 data_c = 0; 00378 FCCH80_f = true; 00379 repeat_data_f = false; 00380 // printf("exit Data\n"); 00381 } 00382 continue; 00383 } 00384 00385 if(FCCH80_f){ 00386 transmit[RB_c] = FCCH80[FCCH80_c++]; 00387 if(FCCH80_c == 10){ 00388 FCCH80_c = 0; 00389 FCCH80_f = false; 00390 // printf("exit FCCH80\n"); 00391 if(++Tframe_c != ISR) 00392 SCH40_f = true; 00393 else{ 00394 Tframe_c = 0; 00395 segment_c++; 00396 if(segment_c >= SEGMENT_NO - 1 && TOTAL_SEGMENT_NO == 0) segment_r = 0; else segment_r = 1; 00397 if(segment_c == SEGMENT_NO) 00398 {eos_f = true;} 00399 else{ 00400 Sframe = true; 00401 } 00402 } 00403 } 00404 continue; 00405 } 00406 00407 if(eos_f){ 00408 transmit[RB_c] = EoS[EOS_c++]; 00409 if(EOS_c == EOS_SIZE){ 00410 EOS_c = 0; 00411 eos_f = false; 00412 if(segment_c == SEGMENT_NO && segment_r == 0){ 00413 *last_buffer = true; 00414 } 00415 else if(segment_c == SEGMENT_NO && segment_r != 0){ 00416 segment_c = 0; 00417 SEGMENT_NO = TOTAL_SEGMENT_NO; 00418 if(SEGMENT_NO > MAX_SEGMENT) 00419 { 00420 SEGMENT_NO = MAX_SEGMENT; 00421 } 00422 if(SEGMENT_NO == 1) segment_r = 0; else segment_r = 1; 00423 TOTAL_SEGMENT_NO -= SEGMENT_NO; 00424 reset_adf = true;//what does this do?? 00425 Sframe = true; 00426 } 00427 junk_f = true; 00428 } 00429 continue; 00430 } 00431 } 00432 differential_encode(transmit,112); 00433 if(reset_adf == true){ 00434 diff_prev = 0; 00435 junk_f = false; 00436 } 00437 00438 } 00439 00440 }; 00441 SND_TM snd_tm;
Generated on Wed Jul 13 2022 02:12:45 by 1.7.2