![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Repo for COM_MNG_TMTC_SIMPLE for integration with adf
Fork of COM_MNG_TMTC_SIMPLE by
COM_SND_TM.h@9:9dbd59a6cc30, 2015-12-31 (annotated)
- Committer:
- shekhar
- Date:
- Thu Dec 31 09:53:39 2015 +0000
- Revision:
- 9:9dbd59a6cc30
- Parent:
- 8:d1951bbdcdd8
Final codes for adf.h and COM_SND_TM.h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shreeshas95 | 1:a0055b3280c8 | 1 | void adf_not_SDcard(); |
shekhar | 8:d1951bbdcdd8 | 2 | |
shreeshas95 | 1:a0055b3280c8 | 3 | #define S_FRAME_SIZE 48 |
shekhar | 9:9dbd59a6cc30 | 4 | #define ISR 40 |
shreeshas95 | 1:a0055b3280c8 | 5 | #define TM_FRAME_SIZE 134 //in bytes |
shreeshas95 | 1:a0055b3280c8 | 6 | #define T_FRAME_SIZE 159 |
shreeshas95 | 1:a0055b3280c8 | 7 | #define EOS_SIZE 120 |
shekhar | 8:d1951bbdcdd8 | 8 | #define MAX_ADF_LEN 65535 |
shreeshas95 | 1:a0055b3280c8 | 9 | |
shreeshas95 | 1:a0055b3280c8 | 10 | 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}; |
shreeshas95 | 1:a0055b3280c8 | 11 | 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}; |
shreeshas95 | 1:a0055b3280c8 | 12 | const unsigned char FCCH80[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
shreeshas95 | 1:a0055b3280c8 | 13 | const unsigned char SCH40[] = {0x0a,0x3f,0x46,0xb4,0x00}; |
shreeshas95 | 1:a0055b3280c8 | 14 | |
shreeshas95 | 1:a0055b3280c8 | 15 | class SND_TM{ |
shekhar | 8:d1951bbdcdd8 | 16 | |
shekhar | 8:d1951bbdcdd8 | 17 | Base_tm * head_ptr; |
shekhar | 8:d1951bbdcdd8 | 18 | |
shreeshas95 | 1:a0055b3280c8 | 19 | // transmit data variables |
shreeshas95 | 1:a0055b3280c8 | 20 | unsigned char Tframe_c; //_c represents counter, counts Tframe written in a segment |
shreeshas95 | 1:a0055b3280c8 | 21 | unsigned char EOS_c; //count no of bytes of eos have been weitten in the rolling buffer |
shreeshas95 | 1:a0055b3280c8 | 22 | unsigned char Sframe_c; //count no of bytes of Sframe have been weitten in the rolling buffer |
shreeshas95 | 1:a0055b3280c8 | 23 | unsigned char SCH40_c; //count no of bytes of SCH40 have been weitten in the rolling buffer |
shreeshas95 | 1:a0055b3280c8 | 24 | unsigned char data_c; |
shreeshas95 | 1:a0055b3280c8 | 25 | unsigned char FCCH80_c; |
shreeshas95 | 1:a0055b3280c8 | 26 | unsigned char RB_c; //rolling buffer counter |
shreeshas95 | 1:a0055b3280c8 | 27 | unsigned char segment_c; //counts the numver of segments sent |
shreeshas95 | 1:a0055b3280c8 | 28 | unsigned char MAX_SEGMENT; |
shreeshas95 | 1:a0055b3280c8 | 29 | bool Sframe; //Sframe = 1bit of CF1 |
shreeshas95 | 1:a0055b3280c8 | 30 | bool SCH40_f; |
shreeshas95 | 1:a0055b3280c8 | 31 | bool FCCH80_f; |
shreeshas95 | 1:a0055b3280c8 | 32 | bool data_f; |
shekhar | 8:d1951bbdcdd8 | 33 | bool repeat_data_f; |
shreeshas95 | 1:a0055b3280c8 | 34 | bool transmit_data_f; |
shreeshas95 | 1:a0055b3280c8 | 35 | bool eos_f; |
shreeshas95 | 1:a0055b3280c8 | 36 | bool junk_f; |
shekhar | 8:d1951bbdcdd8 | 37 | bool segment_r; //flag checking if more sessions are required |
shreeshas95 | 1:a0055b3280c8 | 38 | |
shekhar | 8:d1951bbdcdd8 | 39 | |
shreeshas95 | 1:a0055b3280c8 | 40 | // type 1 frame |
shreeshas95 | 1:a0055b3280c8 | 41 | |
shreeshas95 | 1:a0055b3280c8 | 42 | Base_tm *T0F_pointer ; |
shekhar | 8:d1951bbdcdd8 | 43 | |
shreeshas95 | 1:a0055b3280c8 | 44 | int diff_prev; |
shreeshas95 | 1:a0055b3280c8 | 45 | void differential_encode(unsigned char* ptr, int length){ |
shreeshas95 | 1:a0055b3280c8 | 46 | for(int i=0; i<length;i++){ |
shreeshas95 | 1:a0055b3280c8 | 47 | unsigned char s = ptr[i] , t; |
shreeshas95 | 1:a0055b3280c8 | 48 | t = s ^ (s >> 1); |
shreeshas95 | 1:a0055b3280c8 | 49 | (diff_prev == 0) ? t=t^0x00 : t=t^0x80 ; |
shreeshas95 | 1:a0055b3280c8 | 50 | diff_prev = int(s & 0x01); |
shreeshas95 | 1:a0055b3280c8 | 51 | ptr[i] = t; |
shreeshas95 | 1:a0055b3280c8 | 52 | } |
shekhar | 8:d1951bbdcdd8 | 53 | } |
shekhar | 8:d1951bbdcdd8 | 54 | |
shreeshas95 | 1:a0055b3280c8 | 55 | int type0_no; //number of type zero frames |
shekhar | 8:d1951bbdcdd8 | 56 | int type1_no; |
shreeshas95 | 1:a0055b3280c8 | 57 | int total_frames; //number of type one packe (TMP) |
shreeshas95 | 1:a0055b3280c8 | 58 | int SEGMENT_NO; //number of type one packe (TMP) |
shekhar | 8:d1951bbdcdd8 | 59 | int TOTAL_SEGMENT_NO; |
shekhar | 8:d1951bbdcdd8 | 60 | int LAST_SEGMENT_SIZE; |
shreeshas95 | 1:a0055b3280c8 | 61 | void inline data_number(){ |
shreeshas95 | 1:a0055b3280c8 | 62 | int type1_frame_no; |
shreeshas95 | 1:a0055b3280c8 | 63 | Base_tm*head = head_ptr; |
shreeshas95 | 1:a0055b3280c8 | 64 | type0_no = 0; |
shreeshas95 | 1:a0055b3280c8 | 65 | type1_no = 0; |
shekhar | 8:d1951bbdcdd8 | 66 | while(head->next_TM != NULL){ |
shreeshas95 | 1:a0055b3280c8 | 67 | switch( GETshort_or_long_tm(head->fields) ){ |
shreeshas95 | 1:a0055b3280c8 | 68 | case 0: |
shreeshas95 | 1:a0055b3280c8 | 69 | type0_no++; |
shreeshas95 | 1:a0055b3280c8 | 70 | break; |
shreeshas95 | 1:a0055b3280c8 | 71 | case 1: |
shreeshas95 | 1:a0055b3280c8 | 72 | type1_no++; |
shreeshas95 | 1:a0055b3280c8 | 73 | break; |
shreeshas95 | 1:a0055b3280c8 | 74 | } |
shekhar | 8:d1951bbdcdd8 | 75 | |
shreeshas95 | 1:a0055b3280c8 | 76 | head=head->next_TM; |
shreeshas95 | 1:a0055b3280c8 | 77 | } |
shreeshas95 | 1:a0055b3280c8 | 78 | type1_frame_no = ( type1_no % 10 == 0 )? (type1_no / 10) : ( (type1_no / 10) + 1); |
shreeshas95 | 1:a0055b3280c8 | 79 | total_frames = type0_no + type1_frame_no ; |
shekhar | 8:d1951bbdcdd8 | 80 | 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 |
shekhar | 8:d1951bbdcdd8 | 81 | SEGMENT_NO = TOTAL_SEGMENT_NO; |
shekhar | 8:d1951bbdcdd8 | 82 | if(SEGMENT_NO > MAX_SEGMENT) |
shekhar | 8:d1951bbdcdd8 | 83 | { |
shekhar | 8:d1951bbdcdd8 | 84 | SEGMENT_NO = MAX_SEGMENT; |
shekhar | 8:d1951bbdcdd8 | 85 | segment_r = 1; |
shekhar | 8:d1951bbdcdd8 | 86 | } |
shekhar | 8:d1951bbdcdd8 | 87 | else segment_r = 0; |
shekhar | 8:d1951bbdcdd8 | 88 | TOTAL_SEGMENT_NO -= SEGMENT_NO; |
shekhar | 8:d1951bbdcdd8 | 89 | LAST_SEGMENT_SIZE = total_frames*2%ISR; |
shreeshas95 | 1:a0055b3280c8 | 90 | } |
shekhar | 8:d1951bbdcdd8 | 91 | |
shreeshas95 | 1:a0055b3280c8 | 92 | #define next_type_structure(ptr){\ |
shreeshas95 | 1:a0055b3280c8 | 93 | unsigned char temp = GETshort_or_long_tm(ptr->fields);\ |
shreeshas95 | 1:a0055b3280c8 | 94 | if((temp == 0) && (ptr->next_TM != NULL) ){\ |
shreeshas95 | 1:a0055b3280c8 | 95 | do{\ |
shreeshas95 | 1:a0055b3280c8 | 96 | ptr = ptr->next_TM;\ |
shreeshas95 | 1:a0055b3280c8 | 97 | temp = GETshort_or_long_tm(ptr->fields);\ |
shreeshas95 | 1:a0055b3280c8 | 98 | }\ |
shreeshas95 | 1:a0055b3280c8 | 99 | while(temp == 1 && ptr->next_TM != NULL);\ |
shreeshas95 | 1:a0055b3280c8 | 100 | if(temp == 1){\ |
shreeshas95 | 1:a0055b3280c8 | 101 | ptr = NULL;\ |
shreeshas95 | 1:a0055b3280c8 | 102 | }\ |
shreeshas95 | 1:a0055b3280c8 | 103 | }\ |
shreeshas95 | 1:a0055b3280c8 | 104 | else if((temp == 1) && (ptr->next_TM != NULL)){\ |
shreeshas95 | 1:a0055b3280c8 | 105 | do{\ |
shreeshas95 | 1:a0055b3280c8 | 106 | ptr = ptr->next_TM;\ |
shreeshas95 | 1:a0055b3280c8 | 107 | temp = GETshort_or_long_tm(ptr->fields);\ |
shreeshas95 | 1:a0055b3280c8 | 108 | }\ |
shreeshas95 | 1:a0055b3280c8 | 109 | while(temp == 0 && ptr->next_TM != NULL);\ |
shreeshas95 | 1:a0055b3280c8 | 110 | if(temp == 0){\ |
shekhar | 8:d1951bbdcdd8 | 111 | ptr = NULL;\ |
shreeshas95 | 1:a0055b3280c8 | 112 | }\ |
shreeshas95 | 1:a0055b3280c8 | 113 | }\ |
shreeshas95 | 1:a0055b3280c8 | 114 | else{\ |
shekhar | 8:d1951bbdcdd8 | 115 | ptr = NULL;\ |
shreeshas95 | 1:a0055b3280c8 | 116 | }\ |
shreeshas95 | 1:a0055b3280c8 | 117 | } |
shekhar | 8:d1951bbdcdd8 | 118 | |
shreeshas95 | 1:a0055b3280c8 | 119 | /* |
shreeshas95 | 1:a0055b3280c8 | 120 | brief: take input type 0 or 1 and return the address of the first node in the list that have that type |
shreeshas95 | 1:a0055b3280c8 | 121 | parameter: type 0 or 1 |
shekhar | 8:d1951bbdcdd8 | 122 | return: pointer of the first node having same type |
shreeshas95 | 1:a0055b3280c8 | 123 | */ |
shreeshas95 | 1:a0055b3280c8 | 124 | // Base_tm* first_type_structure(int type){ |
shreeshas95 | 1:a0055b3280c8 | 125 | // Base_tm* temp_ptr = head_ptr; |
shreeshas95 | 1:a0055b3280c8 | 126 | // if(type == 0){ |
shreeshas95 | 1:a0055b3280c8 | 127 | // while(GETshort_or_long_tm(temp_ptr->fields) == 1){ |
shreeshas95 | 1:a0055b3280c8 | 128 | // temp_ptr = temp_ptr->next_TM; |
shreeshas95 | 1:a0055b3280c8 | 129 | // if(temp_ptr == NULL){ |
shreeshas95 | 1:a0055b3280c8 | 130 | // return NULL ; |
shekhar | 8:d1951bbdcdd8 | 131 | // } |
shekhar | 8:d1951bbdcdd8 | 132 | // } |
shreeshas95 | 1:a0055b3280c8 | 133 | // } |
shreeshas95 | 1:a0055b3280c8 | 134 | // else if(type == 1){ |
shreeshas95 | 1:a0055b3280c8 | 135 | // while(GETshort_or_long_tm(temp_ptr->fields) == 0){ |
shreeshas95 | 1:a0055b3280c8 | 136 | // temp_ptr = temp_ptr->next_TM; |
shreeshas95 | 1:a0055b3280c8 | 137 | // if(temp_ptr == NULL){ |
shekhar | 8:d1951bbdcdd8 | 138 | // return NULL; |
shekhar | 8:d1951bbdcdd8 | 139 | // } |
shekhar | 8:d1951bbdcdd8 | 140 | // } |
shekhar | 8:d1951bbdcdd8 | 141 | // } |
shreeshas95 | 1:a0055b3280c8 | 142 | // return temp_ptr; |
shreeshas95 | 1:a0055b3280c8 | 143 | // } |
shreeshas95 | 1:a0055b3280c8 | 144 | |
shreeshas95 | 1:a0055b3280c8 | 145 | |
shreeshas95 | 1:a0055b3280c8 | 146 | #define first_type_structure( type,return_ptr) {\ |
shreeshas95 | 1:a0055b3280c8 | 147 | Base_tm* temp_ptr = head_ptr;\ |
shreeshas95 | 1:a0055b3280c8 | 148 | if(type == 0){\ |
shreeshas95 | 1:a0055b3280c8 | 149 | while(GETshort_or_long_tm(temp_ptr->fields) == 1){\ |
shreeshas95 | 1:a0055b3280c8 | 150 | temp_ptr = temp_ptr->next_TM;\ |
shreeshas95 | 1:a0055b3280c8 | 151 | if(temp_ptr == NULL){\ |
shreeshas95 | 1:a0055b3280c8 | 152 | return_ptr = NULL ;\ |
shreeshas95 | 1:a0055b3280c8 | 153 | }\ |
shreeshas95 | 1:a0055b3280c8 | 154 | }\ |
shreeshas95 | 1:a0055b3280c8 | 155 | }\ |
shreeshas95 | 1:a0055b3280c8 | 156 | else if(type == 1){\ |
shreeshas95 | 1:a0055b3280c8 | 157 | while(GETshort_or_long_tm(temp_ptr->fields) == 0){\ |
shreeshas95 | 1:a0055b3280c8 | 158 | temp_ptr = temp_ptr->next_TM;\ |
shreeshas95 | 1:a0055b3280c8 | 159 | if(temp_ptr == NULL){\ |
shreeshas95 | 1:a0055b3280c8 | 160 | return_ptr = NULL;\ |
shreeshas95 | 1:a0055b3280c8 | 161 | }\ |
shreeshas95 | 1:a0055b3280c8 | 162 | }\ |
shreeshas95 | 1:a0055b3280c8 | 163 | }\ |
shreeshas95 | 1:a0055b3280c8 | 164 | return_ptr = temp_ptr;\ |
shreeshas95 | 1:a0055b3280c8 | 165 | } |
shreeshas95 | 1:a0055b3280c8 | 166 | |
shreeshas95 | 1:a0055b3280c8 | 167 | |
shekhar | 8:d1951bbdcdd8 | 168 | |
shreeshas95 | 1:a0055b3280c8 | 169 | Base_tm *T1F_pointer ; |
shreeshas95 | 1:a0055b3280c8 | 170 | int T1F_counter; |
shreeshas95 | 1:a0055b3280c8 | 171 | unsigned char TMframe_type1[TM_FRAME_SIZE]; |
shreeshas95 | 1:a0055b3280c8 | 172 | bool type1_frame_flag; //should be true for every new list |
shekhar | 8:d1951bbdcdd8 | 173 | |
shreeshas95 | 1:a0055b3280c8 | 174 | #define type1_frame(ptr){\ |
shreeshas95 | 1:a0055b3280c8 | 175 | int i=4;\ |
shreeshas95 | 1:a0055b3280c8 | 176 | if(type1_frame_flag){\ |
shreeshas95 | 1:a0055b3280c8 | 177 | first_type_structure(1,T1F_pointer);\ |
shreeshas95 | 1:a0055b3280c8 | 178 | T1F_counter = 0;\ |
shreeshas95 | 1:a0055b3280c8 | 179 | type1_frame_flag = false;\ |
shreeshas95 | 1:a0055b3280c8 | 180 | }\ |
shreeshas95 | 1:a0055b3280c8 | 181 | for(i = 4 ; (i < 134) && (T1F_pointer != NULL) ; i++){\ |
shreeshas95 | 1:a0055b3280c8 | 182 | TMframe_type1[i] = T1F_pointer->TM_string[T1F_counter];\ |
shreeshas95 | 1:a0055b3280c8 | 183 | if(T1F_counter++ == 12){\ |
shreeshas95 | 1:a0055b3280c8 | 184 | T1F_counter = 0;\ |
shreeshas95 | 1:a0055b3280c8 | 185 | next_type_structure(T1F_pointer);\ |
shreeshas95 | 1:a0055b3280c8 | 186 | }\ |
shreeshas95 | 1:a0055b3280c8 | 187 | }\ |
shreeshas95 | 1:a0055b3280c8 | 188 | TMframe_type1[0] = 1<<7 + ( (i-4)/10 )<<3;\ |
shreeshas95 | 1:a0055b3280c8 | 189 | TMframe_type1[3] = crc16_gen(TMframe_type1,3);\ |
shreeshas95 | 1:a0055b3280c8 | 190 | if(T1F_pointer == NULL && i>12){\ |
shreeshas95 | 1:a0055b3280c8 | 191 | for( ; i < 134 ; i++){\ |
shreeshas95 | 1:a0055b3280c8 | 192 | TMframe_type1[i] = TMframe_type1[i-13];\ |
shreeshas95 | 1:a0055b3280c8 | 193 | }\ |
shreeshas95 | 1:a0055b3280c8 | 194 | }\ |
shekhar | 8:d1951bbdcdd8 | 195 | ptr=TMframe_type1;\ |
shreeshas95 | 1:a0055b3280c8 | 196 | } |
shekhar | 8:d1951bbdcdd8 | 197 | |
shekhar | 8:d1951bbdcdd8 | 198 | |
shreeshas95 | 1:a0055b3280c8 | 199 | // unsigned char * type1_frame(){ |
shreeshas95 | 1:a0055b3280c8 | 200 | // int i=4; |
shreeshas95 | 1:a0055b3280c8 | 201 | // if(type1_frame_flag){ |
shreeshas95 | 1:a0055b3280c8 | 202 | // T1F_pointer = first_type_structure(1); |
shreeshas95 | 1:a0055b3280c8 | 203 | // T1F_counter = 0; |
shreeshas95 | 1:a0055b3280c8 | 204 | // type1_frame_flag = false; |
shreeshas95 | 1:a0055b3280c8 | 205 | // } |
shreeshas95 | 1:a0055b3280c8 | 206 | // for(i = 4 ; (i < 134) && (T1F_pointer != NULL) ; i++){ |
shreeshas95 | 1:a0055b3280c8 | 207 | // TMframe_type1[i] = T1F_pointer->TM_string[T1F_counter]; |
shreeshas95 | 1:a0055b3280c8 | 208 | // if(T1F_counter++ == 12){ |
shreeshas95 | 1:a0055b3280c8 | 209 | // T1F_counter = 0; |
shreeshas95 | 1:a0055b3280c8 | 210 | // T1F_pointer = next_type_structure(T1F_pointer); |
shreeshas95 | 1:a0055b3280c8 | 211 | // } |
shreeshas95 | 1:a0055b3280c8 | 212 | // } |
shreeshas95 | 1:a0055b3280c8 | 213 | // // header |
shreeshas95 | 1:a0055b3280c8 | 214 | // TMframe_type1[0] = 1<<7 + ( (i-4)/10 )<<3; //( (i-4)/10 ) gives number of packets in the frame |
shreeshas95 | 1:a0055b3280c8 | 215 | // //insert time ; |
shreeshas95 | 1:a0055b3280c8 | 216 | // TMframe_type1[3] = CRC::crc16_gen(TMframe_type1,3); |
shreeshas95 | 1:a0055b3280c8 | 217 | // //end header |
shreeshas95 | 1:a0055b3280c8 | 218 | // if(T1F_pointer == NULL && i>12){ |
shreeshas95 | 1:a0055b3280c8 | 219 | // for( ; i < 134 ; i++){ //repeating ;ast packet to fill up the extra space |
shekhar | 8:d1951bbdcdd8 | 220 | // TMframe_type1[i] = TMframe_type1[i-13]; |
shreeshas95 | 1:a0055b3280c8 | 221 | // } |
shreeshas95 | 1:a0055b3280c8 | 222 | // } |
shreeshas95 | 1:a0055b3280c8 | 223 | // return TMframe_type1; |
shreeshas95 | 1:a0055b3280c8 | 224 | // } |
shekhar | 8:d1951bbdcdd8 | 225 | |
shreeshas95 | 1:a0055b3280c8 | 226 | bool type0_frame_flag; |
shekhar | 8:d1951bbdcdd8 | 227 | |
shekhar | 8:d1951bbdcdd8 | 228 | |
shreeshas95 | 1:a0055b3280c8 | 229 | #define type0_frame(ptr){\ |
shreeshas95 | 1:a0055b3280c8 | 230 | if(type0_frame_flag){\ |
shreeshas95 | 1:a0055b3280c8 | 231 | first_type_structure(0,T0F_pointer);\ |
shreeshas95 | 1:a0055b3280c8 | 232 | type0_frame_flag = false;\ |
shreeshas95 | 1:a0055b3280c8 | 233 | }\ |
shreeshas95 | 1:a0055b3280c8 | 234 | else {\ |
shreeshas95 | 1:a0055b3280c8 | 235 | next_type_structure(T0F_pointer);\ |
shreeshas95 | 1:a0055b3280c8 | 236 | }\ |
shreeshas95 | 1:a0055b3280c8 | 237 | ptr = T0F_pointer->TM_string;\ |
shreeshas95 | 1:a0055b3280c8 | 238 | } |
shekhar | 8:d1951bbdcdd8 | 239 | |
shekhar | 8:d1951bbdcdd8 | 240 | |
shreeshas95 | 1:a0055b3280c8 | 241 | // unsigned char* type0_frame(){ |
shreeshas95 | 1:a0055b3280c8 | 242 | // if(type0_frame_flag){ |
shekhar | 8:d1951bbdcdd8 | 243 | // T0F_pointer = first_type_structure(0); |
shreeshas95 | 1:a0055b3280c8 | 244 | // type0_frame_flag = false; |
shekhar | 8:d1951bbdcdd8 | 245 | // } |
shreeshas95 | 1:a0055b3280c8 | 246 | // else { |
shreeshas95 | 1:a0055b3280c8 | 247 | // T0F_pointer = next_type_structure(T0F_pointer); |
shreeshas95 | 1:a0055b3280c8 | 248 | // } |
shreeshas95 | 1:a0055b3280c8 | 249 | // return T0F_pointer->TM_string; |
shreeshas95 | 1:a0055b3280c8 | 250 | // } |
shekhar | 8:d1951bbdcdd8 | 251 | |
shekhar | 8:d1951bbdcdd8 | 252 | unsigned char convoluted_frame[270]; |
shreeshas95 | 1:a0055b3280c8 | 253 | Convolution ConvObj2; |
shreeshas95 | 1:a0055b3280c8 | 254 | void convolution (unsigned char * ptr){ |
shreeshas95 | 1:a0055b3280c8 | 255 | ConvObj2.convolutionEncode(ptr, convoluted_frame); |
shreeshas95 | 1:a0055b3280c8 | 256 | ConvObj2.convolutionEncode(ptr + 67, convoluted_frame + 135); |
shreeshas95 | 1:a0055b3280c8 | 257 | } |
shekhar | 8:d1951bbdcdd8 | 258 | |
shekhar | 8:d1951bbdcdd8 | 259 | |
shekhar | 8:d1951bbdcdd8 | 260 | unsigned char interleave_data[2][144]; |
shreeshas95 | 1:a0055b3280c8 | 261 | unsigned char DS_index; |
shreeshas95 | 1:a0055b3280c8 | 262 | bool DS_state; |
shreeshas95 | 1:a0055b3280c8 | 263 | int DS_counter; |
shreeshas95 | 1:a0055b3280c8 | 264 | bool DS_f; |
shreeshas95 | 1:a0055b3280c8 | 265 | bool make_DataStream_f; |
shreeshas95 | 1:a0055b3280c8 | 266 | // #define make_DataStream {\ |
shreeshas95 | 1:a0055b3280c8 | 267 | // unsigned char* ptr;\ |
shreeshas95 | 1:a0055b3280c8 | 268 | // if(make_DataStream_f == true){\ |
shreeshas95 | 1:a0055b3280c8 | 269 | // DS_state = true;\ |
shreeshas95 | 1:a0055b3280c8 | 270 | // DS_counter = 0;\ |
shreeshas95 | 1:a0055b3280c8 | 271 | // DS_f = false;\ |
shreeshas95 | 1:a0055b3280c8 | 272 | // make_DataStream_f = false;\ |
shreeshas95 | 1:a0055b3280c8 | 273 | // }\ |
shreeshas95 | 1:a0055b3280c8 | 274 | // if(DS_state){\ |
shreeshas95 | 1:a0055b3280c8 | 275 | // if(DS_counter < total_frames-type0_no){\ |
shreeshas95 | 1:a0055b3280c8 | 276 | // type1_frame(ptr); \ |
shreeshas95 | 1:a0055b3280c8 | 277 | // DS_f = true;\ |
shreeshas95 | 1:a0055b3280c8 | 278 | // }\ |
shreeshas95 | 1:a0055b3280c8 | 279 | // else if(DS_counter < total_frames ){\ |
shreeshas95 | 1:a0055b3280c8 | 280 | // type0_frame(ptr);\ |
shreeshas95 | 1:a0055b3280c8 | 281 | // DS_f = true;\ |
shreeshas95 | 1:a0055b3280c8 | 282 | // }\ |
shreeshas95 | 1:a0055b3280c8 | 283 | // DS_counter++;\ |
shreeshas95 | 1:a0055b3280c8 | 284 | // }\ |
shreeshas95 | 1:a0055b3280c8 | 285 | // DS_state = !DS_state;\ |
shreeshas95 | 1:a0055b3280c8 | 286 | // if (DS_f){\ |
shreeshas95 | 1:a0055b3280c8 | 287 | // DS_f = false;\ |
shreeshas95 | 1:a0055b3280c8 | 288 | // convolution(ptr);\ |
shreeshas95 | 1:a0055b3280c8 | 289 | // interleave(convoluted_frame,interleave_data[0]);\ |
shreeshas95 | 1:a0055b3280c8 | 290 | // interleave(convoluted_frame+ 135,interleave_data[1]);\ |
shreeshas95 | 1:a0055b3280c8 | 291 | // }\ |
shreeshas95 | 1:a0055b3280c8 | 292 | // DS_index = (DS_state==true)?1:0;\ |
shreeshas95 | 1:a0055b3280c8 | 293 | // } |
shekhar | 8:d1951bbdcdd8 | 294 | |
shekhar | 8:d1951bbdcdd8 | 295 | #define make_DataStream {\ |
shekhar | 8:d1951bbdcdd8 | 296 | unsigned char* ptr;\ |
shekhar | 8:d1951bbdcdd8 | 297 | if(make_DataStream_f == true){\ |
shekhar | 8:d1951bbdcdd8 | 298 | DS_state = true;\ |
shekhar | 8:d1951bbdcdd8 | 299 | DS_counter = 0;\ |
shekhar | 8:d1951bbdcdd8 | 300 | DS_f = false;\ |
shekhar | 8:d1951bbdcdd8 | 301 | make_DataStream_f = false;\ |
shekhar | 8:d1951bbdcdd8 | 302 | }\ |
shekhar | 8:d1951bbdcdd8 | 303 | if(DS_state){\ |
shekhar | 9:9dbd59a6cc30 | 304 | if(DS_counter < total_frames-type0_no){\ |
shekhar | 9:9dbd59a6cc30 | 305 | type1_frame(ptr); \ |
shekhar | 8:d1951bbdcdd8 | 306 | DS_f = true;\ |
shekhar | 8:d1951bbdcdd8 | 307 | }\ |
shekhar | 8:d1951bbdcdd8 | 308 | else if(DS_counter < total_frames ){\ |
shekhar | 9:9dbd59a6cc30 | 309 | type0_frame(ptr);\ |
shekhar | 8:d1951bbdcdd8 | 310 | DS_f = true;\ |
shekhar | 8:d1951bbdcdd8 | 311 | }\ |
shekhar | 8:d1951bbdcdd8 | 312 | DS_counter++;\ |
shekhar | 8:d1951bbdcdd8 | 313 | }\ |
shekhar | 8:d1951bbdcdd8 | 314 | DS_state = !DS_state;\ |
shekhar | 8:d1951bbdcdd8 | 315 | if (DS_f){\ |
shekhar | 8:d1951bbdcdd8 | 316 | DS_f = false;\ |
shekhar | 8:d1951bbdcdd8 | 317 | convolution(ptr);\ |
shekhar | 8:d1951bbdcdd8 | 318 | interleave(convoluted_frame,interleave_data[0]);\ |
shekhar | 8:d1951bbdcdd8 | 319 | interleave(convoluted_frame+ 135,interleave_data[1]);}\ |
shekhar | 8:d1951bbdcdd8 | 320 | DS_index = (DS_state==true)?1:0;\ |
shekhar | 8:d1951bbdcdd8 | 321 | } |
shekhar | 8:d1951bbdcdd8 | 322 | |
shekhar | 8:d1951bbdcdd8 | 323 | |
shekhar | 8:d1951bbdcdd8 | 324 | // |
shreeshas95 | 1:a0055b3280c8 | 325 | public: |
shekhar | 8:d1951bbdcdd8 | 326 | |
shreeshas95 | 1:a0055b3280c8 | 327 | bool reset_adf; |
shreeshas95 | 1:a0055b3280c8 | 328 | SND_TM(){ |
shekhar | 9:9dbd59a6cc30 | 329 | MAX_SEGMENTMAX_SEGMENT = (MAX_ADF_LEN-EOS_SIZE)/( S_FRAME_SIZE + ISR*T_FRAME_SIZE); |
shekhar | 9:9dbd59a6cc30 | 330 | //MAX_SEGMENT = 1; |
shekhar | 8:d1951bbdcdd8 | 331 | //(max length - eos size)/(sframe length + tFrameLength*ISR) |
shreeshas95 | 1:a0055b3280c8 | 332 | // cout<<int(MAX_SEGMENT)<<endl; |
shreeshas95 | 1:a0055b3280c8 | 333 | } |
shekhar | 8:d1951bbdcdd8 | 334 | |
shekhar | 8:d1951bbdcdd8 | 335 | |
shekhar | 8:d1951bbdcdd8 | 336 | |
shreeshas95 | 1:a0055b3280c8 | 337 | void head_pointer(Base_tm* ptr){ |
shreeshas95 | 1:a0055b3280c8 | 338 | head_ptr = ptr ; |
shreeshas95 | 1:a0055b3280c8 | 339 | type1_frame_flag = true; |
shreeshas95 | 1:a0055b3280c8 | 340 | type0_frame_flag = true; |
shreeshas95 | 1:a0055b3280c8 | 341 | make_DataStream_f = true; |
shreeshas95 | 1:a0055b3280c8 | 342 | transmit_data_f = true; |
shreeshas95 | 1:a0055b3280c8 | 343 | diff_prev = 0; |
shreeshas95 | 1:a0055b3280c8 | 344 | data_number(); |
shekhar | 8:d1951bbdcdd8 | 345 | // make_DataStream; |
shekhar | 8:d1951bbdcdd8 | 346 | // gPC.putc('z'); |
shreeshas95 | 1:a0055b3280c8 | 347 | } |
shekhar | 8:d1951bbdcdd8 | 348 | |
shekhar | 8:d1951bbdcdd8 | 349 | |
shreeshas95 | 1:a0055b3280c8 | 350 | void inline transmit_data(unsigned char * transmit , bool * last_buffer){ |
shreeshas95 | 1:a0055b3280c8 | 351 | if(transmit_data_f){ |
shreeshas95 | 1:a0055b3280c8 | 352 | RB_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 353 | Sframe_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 354 | SCH40_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 355 | FCCH80_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 356 | Tframe_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 357 | EOS_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 358 | segment_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 359 | data_c = 0; |
shekhar | 8:d1951bbdcdd8 | 360 | |
shreeshas95 | 1:a0055b3280c8 | 361 | Sframe = true; |
shreeshas95 | 1:a0055b3280c8 | 362 | SCH40_f = false; |
shreeshas95 | 1:a0055b3280c8 | 363 | data_f = false; |
shreeshas95 | 1:a0055b3280c8 | 364 | FCCH80_f = false; |
shreeshas95 | 1:a0055b3280c8 | 365 | transmit_data_f = false; |
shreeshas95 | 1:a0055b3280c8 | 366 | reset_adf = false; |
shreeshas95 | 1:a0055b3280c8 | 367 | *last_buffer = false; |
shreeshas95 | 1:a0055b3280c8 | 368 | } |
shekhar | 8:d1951bbdcdd8 | 369 | |
shreeshas95 | 1:a0055b3280c8 | 370 | for(RB_c = 0 ; RB_c<112 ; RB_c++){ |
shekhar | 8:d1951bbdcdd8 | 371 | |
shekhar | 9:9dbd59a6cc30 | 372 | if(junk_f || *last_buffer){ |
shekhar | 8:d1951bbdcdd8 | 373 | transmit[RB_c] = 0x00; |
shekhar | 8:d1951bbdcdd8 | 374 | continue; |
shreeshas95 | 1:a0055b3280c8 | 375 | } |
shekhar | 8:d1951bbdcdd8 | 376 | |
shreeshas95 | 1:a0055b3280c8 | 377 | if(Sframe){ |
shreeshas95 | 1:a0055b3280c8 | 378 | transmit[RB_c] = S_frame[Sframe_c++]; |
shreeshas95 | 1:a0055b3280c8 | 379 | if(Sframe_c == 48){ |
shreeshas95 | 1:a0055b3280c8 | 380 | // printf("exit s frame\n"); |
shreeshas95 | 1:a0055b3280c8 | 381 | Sframe_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 382 | Sframe = false; |
shreeshas95 | 1:a0055b3280c8 | 383 | SCH40_f =true; |
shreeshas95 | 1:a0055b3280c8 | 384 | } |
shreeshas95 | 1:a0055b3280c8 | 385 | continue; |
shreeshas95 | 1:a0055b3280c8 | 386 | } |
shekhar | 8:d1951bbdcdd8 | 387 | // |
shreeshas95 | 1:a0055b3280c8 | 388 | if(SCH40_f){ |
shekhar | 8:d1951bbdcdd8 | 389 | transmit[RB_c] = SCH40[SCH40_c++]; |
shreeshas95 | 1:a0055b3280c8 | 390 | if(SCH40_c == 5 ){ |
shreeshas95 | 1:a0055b3280c8 | 391 | SCH40_c = 0; |
shekhar | 8:d1951bbdcdd8 | 392 | SCH40_f = false; |
shekhar | 8:d1951bbdcdd8 | 393 | |
shekhar | 8:d1951bbdcdd8 | 394 | |
shekhar | 9:9dbd59a6cc30 | 395 | if(Tframe_c >= LAST_SEGMENT_SIZE && segment_r == 0) |
shekhar | 8:d1951bbdcdd8 | 396 | { |
shekhar | 8:d1951bbdcdd8 | 397 | repeat_data_f = true; |
shekhar | 8:d1951bbdcdd8 | 398 | DS_index = !DS_index; |
shekhar | 8:d1951bbdcdd8 | 399 | } |
shekhar | 8:d1951bbdcdd8 | 400 | else |
shekhar | 8:d1951bbdcdd8 | 401 | { |
shekhar | 8:d1951bbdcdd8 | 402 | data_f = true; |
shekhar | 8:d1951bbdcdd8 | 403 | make_DataStream; |
shekhar | 8:d1951bbdcdd8 | 404 | } |
shreeshas95 | 1:a0055b3280c8 | 405 | // printf("exit SCH40 frame\n"); |
shreeshas95 | 1:a0055b3280c8 | 406 | } |
shreeshas95 | 1:a0055b3280c8 | 407 | continue; |
shreeshas95 | 1:a0055b3280c8 | 408 | } |
shekhar | 8:d1951bbdcdd8 | 409 | // |
shreeshas95 | 1:a0055b3280c8 | 410 | if(data_f){ |
shreeshas95 | 1:a0055b3280c8 | 411 | transmit[RB_c] = interleave_data[DS_index][data_c++]; |
shreeshas95 | 1:a0055b3280c8 | 412 | if(data_c == 144){ |
shreeshas95 | 1:a0055b3280c8 | 413 | data_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 414 | FCCH80_f = true; |
shreeshas95 | 1:a0055b3280c8 | 415 | data_f = false; |
shreeshas95 | 1:a0055b3280c8 | 416 | // printf("exit Data\n"); |
shreeshas95 | 1:a0055b3280c8 | 417 | } |
shreeshas95 | 1:a0055b3280c8 | 418 | continue; |
shreeshas95 | 1:a0055b3280c8 | 419 | } |
shekhar | 8:d1951bbdcdd8 | 420 | if(repeat_data_f){ |
shekhar | 8:d1951bbdcdd8 | 421 | transmit[RB_c] = interleave_data[DS_index][data_c++]; |
shekhar | 8:d1951bbdcdd8 | 422 | if(data_c == 144){ |
shekhar | 8:d1951bbdcdd8 | 423 | data_c = 0; |
shekhar | 8:d1951bbdcdd8 | 424 | FCCH80_f = true; |
shekhar | 8:d1951bbdcdd8 | 425 | repeat_data_f = false; |
shekhar | 8:d1951bbdcdd8 | 426 | // printf("exit Data\n"); |
shekhar | 8:d1951bbdcdd8 | 427 | } |
shekhar | 8:d1951bbdcdd8 | 428 | continue; |
shekhar | 8:d1951bbdcdd8 | 429 | } |
shreeshas95 | 1:a0055b3280c8 | 430 | |
shreeshas95 | 1:a0055b3280c8 | 431 | if(FCCH80_f){ |
shreeshas95 | 1:a0055b3280c8 | 432 | transmit[RB_c] = FCCH80[FCCH80_c++]; |
shreeshas95 | 1:a0055b3280c8 | 433 | if(FCCH80_c == 10){ |
shreeshas95 | 1:a0055b3280c8 | 434 | FCCH80_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 435 | FCCH80_f = false; |
shreeshas95 | 1:a0055b3280c8 | 436 | // printf("exit FCCH80\n"); |
shreeshas95 | 1:a0055b3280c8 | 437 | if(++Tframe_c != ISR) |
shekhar | 8:d1951bbdcdd8 | 438 | SCH40_f = true; |
shreeshas95 | 1:a0055b3280c8 | 439 | else{ |
shreeshas95 | 1:a0055b3280c8 | 440 | Tframe_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 441 | segment_c++; |
shekhar | 8:d1951bbdcdd8 | 442 | if(segment_c == SEGMENT_NO) |
shreeshas95 | 1:a0055b3280c8 | 443 | {eos_f = true;} |
shreeshas95 | 1:a0055b3280c8 | 444 | else{ |
shreeshas95 | 1:a0055b3280c8 | 445 | Sframe = true; |
shreeshas95 | 1:a0055b3280c8 | 446 | } |
shreeshas95 | 1:a0055b3280c8 | 447 | } |
shreeshas95 | 1:a0055b3280c8 | 448 | } |
shreeshas95 | 1:a0055b3280c8 | 449 | continue; |
shekhar | 8:d1951bbdcdd8 | 450 | } |
shekhar | 8:d1951bbdcdd8 | 451 | |
shekhar | 8:d1951bbdcdd8 | 452 | if(eos_f){ |
shreeshas95 | 1:a0055b3280c8 | 453 | transmit[RB_c] = EoS[EOS_c++]; |
shreeshas95 | 1:a0055b3280c8 | 454 | if(EOS_c == EOS_SIZE){ |
shreeshas95 | 1:a0055b3280c8 | 455 | EOS_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 456 | eos_f = false; |
shreeshas95 | 1:a0055b3280c8 | 457 | // printf("exit EOS\n"); |
shekhar | 8:d1951bbdcdd8 | 458 | // if(segment_c == MAX_SEGMENT){ |
shekhar | 8:d1951bbdcdd8 | 459 | // segment_c = 0; |
shekhar | 8:d1951bbdcdd8 | 460 | // SEGMENT_NO = SEGMENT_NO - MAX_SEGMENT; |
shekhar | 8:d1951bbdcdd8 | 461 | // reset_adf = true;//what does this do?? |
shekhar | 8:d1951bbdcdd8 | 462 | // Sframe = true; |
shekhar | 8:d1951bbdcdd8 | 463 | // }else{ |
shekhar | 8:d1951bbdcdd8 | 464 | // *last_buffer = true; |
shekhar | 8:d1951bbdcdd8 | 465 | // } |
shekhar | 8:d1951bbdcdd8 | 466 | if(segment_c == SEGMENT_NO && segment_r == 0){ |
shekhar | 8:d1951bbdcdd8 | 467 | *last_buffer = true; |
shekhar | 8:d1951bbdcdd8 | 468 | } |
shekhar | 8:d1951bbdcdd8 | 469 | else if(segment_c == SEGMENT_NO && segment_r != 0){ |
shekhar | 8:d1951bbdcdd8 | 470 | segment_c = 0; |
shekhar | 8:d1951bbdcdd8 | 471 | SEGMENT_NO = TOTAL_SEGMENT_NO; |
shekhar | 8:d1951bbdcdd8 | 472 | if(SEGMENT_NO > MAX_SEGMENT) |
shekhar | 8:d1951bbdcdd8 | 473 | { |
shekhar | 8:d1951bbdcdd8 | 474 | SEGMENT_NO = MAX_SEGMENT; |
shekhar | 8:d1951bbdcdd8 | 475 | segment_r = 1; |
shekhar | 8:d1951bbdcdd8 | 476 | } |
shekhar | 8:d1951bbdcdd8 | 477 | else segment_r = 0; |
shekhar | 8:d1951bbdcdd8 | 478 | TOTAL_SEGMENT_NO -= SEGMENT_NO; |
shekhar | 8:d1951bbdcdd8 | 479 | reset_adf = true;//what does this do?? |
shekhar | 8:d1951bbdcdd8 | 480 | Sframe = true; |
shekhar | 8:d1951bbdcdd8 | 481 | } |
shreeshas95 | 1:a0055b3280c8 | 482 | junk_f = true; |
shreeshas95 | 1:a0055b3280c8 | 483 | } |
shreeshas95 | 1:a0055b3280c8 | 484 | continue; |
shekhar | 8:d1951bbdcdd8 | 485 | } |
shreeshas95 | 1:a0055b3280c8 | 486 | } |
shreeshas95 | 1:a0055b3280c8 | 487 | differential_encode(transmit,112); |
shreeshas95 | 1:a0055b3280c8 | 488 | if(reset_adf == true){ |
shreeshas95 | 1:a0055b3280c8 | 489 | diff_prev = 0; |
shreeshas95 | 1:a0055b3280c8 | 490 | junk_f = false; |
shreeshas95 | 1:a0055b3280c8 | 491 | } |
shekhar | 8:d1951bbdcdd8 | 492 | |
shreeshas95 | 1:a0055b3280c8 | 493 | } |
shekhar | 8:d1951bbdcdd8 | 494 | |
shreeshas95 | 1:a0055b3280c8 | 495 | }; |
shekhar | 8:d1951bbdcdd8 | 496 | SND_TM snd_tm; |