pl ack in tmtc

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of COM_MNG_TMTC_SIMPLE_pl123 by shubham c

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers COM_SND_TM.h Source File

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