![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Repository for testing ADF code of COM_TMTC_SIMPLE
Fork of COM_MNG_TMTC_SIMPLE by
Diff: SDCread.h
- Revision:
- 1:a0055b3280c8
diff -r f016e9e8d48b -r a0055b3280c8 SDCread.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDCread.h Mon Dec 14 12:04:01 2015 +0000 @@ -0,0 +1,190 @@ +// It takes 276us to read from sd card and write in 112 buffer + +//~ #include"SDcard.h" +#define T_frames 30 +unsigned char buffer_112_counter,sent_tm = 0; +int disk_read(uint8_t *, uint64_t),j; +bool new_session = true; +bool last_buffer = false; +bool first_block = true; +bool last_block =false; +bool repeat_T_frame = false; +unsigned int counter_in_block=0,diff_prev=0; +unsigned char EOS_counter = 0; +unsigned char enable_T_frame = false; +uint64_t start_block_num ; // Read from TC +uint64_t end_block_num ; // Read from TC +uint64_t Number_of_blocks_to_read ; +uint64_t block_counter = 0; +unsigned char buffer_512[512], buffer_112[112],counter_in_S_frame=0,counter_in_SCH=0; +unsigned char make_EOS_flag = true; +bool reset = false; + +void differential_encode(unsigned char* ptr, int length){ + + for(int i=0; i<length;i++){ + + unsigned char s = ptr[i] , t; + t = s ^ (s >> 1); + (diff_prev == 0) ? t=t^0x00 : t=t^0x80 ; + diff_prev = int(s & 0x01); + ptr[i] = t; + } + + } + +void send_tm_from_SD_card(){ + + if(make_EOS_flag == true){ + make_EOS_flag = false; + Number_of_blocks_to_read = end_block_num - start_block_num +1; + } + + + for(buffer_112_counter=0;buffer_112_counter<112;buffer_112_counter++){ + + + if(new_session == true){ //check if it is beginnig of session + + buffer_112[buffer_112_counter]=S_frame[counter_in_S_frame++]; // sending S frame + + if(counter_in_S_frame==48){ +// cout<<"new_session_over\n"; + counter_in_S_frame=0; + new_session = false; + enable_T_frame = true; +// enable_SCH = true; + } + } + else if(enable_T_frame == true){ // To send t frames + + if(block_counter != Number_of_blocks_to_read){ + + if(first_block){ // Read first block +// cout<<"brooooooo"<<start_block_num<<"yo"<<endl; + SPI_mutex.lock(); + disk_read(buffer_512,start_block_num ); + SPI_mutex.unlock(); + counter_in_block = 0; + block_counter++; + + first_block = false; +// cout<<"first block exit\n"; +// cout<<Number_of_blocks_to_read; + + //printf("\n"); +// for(int j=0;j<512;j++){ +// printf("%02X ",buffer_512[j]); +// } +// printf("\n"); +// if(block_counter == Number_of_blocks_to_read){ +// last_block = true; +// } + + + } + if((counter_in_block == 318 )&&(sent_tm<38)){ // Read next block + +// cout<<"next block exit\n"; + SPI_mutex.lock(); + disk_read(buffer_512,start_block_num + block_counter ); + SPI_mutex.unlock(); + counter_in_block = 0; + block_counter++; + if(block_counter == Number_of_blocks_to_read){ + last_block = true; + } + } + } + + if(!last_block){ + + // cout<<int(sent_tm)<<" "; + if(sent_tm<38){ + buffer_112[buffer_112_counter] = buffer_512[counter_in_block++]; // sending T frames +// cout<<int (counter_in_block)<<" "; + if(counter_in_block == 318){ + + sent_tm = sent_tm + 2; + } + } + else if(sent_tm == (T_frames-1)){ + buffer_112[buffer_112_counter] = buffer_512[(counter_in_block++ )-159]; + if(counter_in_block == 318){ +// cout<<"last block exit\n"; + sent_tm = T_frames; + } + } + else if(sent_tm == T_frames){ // Give eos and start new session + buffer_112[buffer_112_counter]=EoS[EOS_counter++]; + if(EOS_counter == 120){ + enable_T_frame = false; + new_session = true; + EOS_counter =0; + sent_tm=0; + repeat_T_frame = false; +// cout<<"eos exit\n"; + } + } + } + if(last_block){ +// cout<<"lb"; + if(sent_tm == (T_frames-1) && (repeat_T_frame == false)){ + buffer_112[buffer_112_counter] = buffer_512[(counter_in_block++ )-159]; + if(counter_in_block == 318){ +// cout<<"repeat block exit\n"; + sent_tm = T_frames; + } + } + if((sent_tm == T_frames) && (repeat_T_frame == false)){ // Give eos and start new session + buffer_112[buffer_112_counter]=EoS[EOS_counter++]; + if(EOS_counter == 120){ +// cout<<"eos exit"; + enable_T_frame = false; + new_session = true; + EOS_counter =0; + sent_tm=0; + } + } + else if((sent_tm < (T_frames-1)) && (repeat_T_frame == false)){ + buffer_112[buffer_112_counter] = buffer_512[counter_in_block++]; // sending last two T frames + if(counter_in_block == 318){ + sent_tm = sent_tm + 2; + repeat_T_frame= true; + } + } + else if((sent_tm< T_frames) && (repeat_T_frame == true)){ + buffer_112[buffer_112_counter] = buffer_512[(counter_in_block++ )-159]; + if(counter_in_block == 477){ + sent_tm = sent_tm +1; + counter_in_block = counter_in_block-159; + } + } + else if((sent_tm == T_frames ) && (repeat_T_frame == true)){ // Give eos and start new session + + buffer_112[buffer_112_counter]=EoS[EOS_counter++]; + if(EOS_counter == 120){ + enable_T_frame = false; + new_session = true; + EOS_counter =0; +// printf("yoooo %d",int(sent_tm)); + sent_tm=0; + + last_block = false; + last_buffer = true; + printf("?\r\n"); + break; + } + } + + } + + } + + } + differential_encode(buffer_112, 112); + if(last_buffer ==true){ + diff_prev=0; + } + +} \ No newline at end of file