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