![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Dummy program to demonstrate problems: working code
Dependencies: SLCD mbed-rtos mbed
Fork of MNG_TC by
Diff: snd_tm_class.h
- Revision:
- 14:a4c259ca0325
- Parent:
- 13:7b27a8e9cbb4
--- a/snd_tm_class.h Mon Aug 03 14:29:35 2015 +0000 +++ b/snd_tm_class.h Mon Aug 17 12:05:09 2015 +0000 @@ -16,7 +16,37 @@ TM_list * list_ptr; unsigned char SCH40[5]; unsigned char FCCH80[10]; - bool reset_flag; //for reseting all the static variables when new list is given. + bool reset_flag; //for reseting all the variables when new list is given. + + +// transmit data variables + int Tframe_counter; //contains the number of Tframes in a segment had been written + int EOS_counter; //count no of byres of eos have been weitten in the buffer + int Sframe_Counter; + int SCH40_counter; + int string_space_counter; + int FCCH80_counter; + int rolling_buffer_counter; //maximum it can be 1152 bits + bool Sframe_flag; + bool new_Tframe_flag; + bool FCCH80_flag; + bool data_flag; + int uv; + bool repete_data_flag; + int segment_counter; + bool diff_enc_flag; + +// make_DataStream variables + bool state; + int DS_counter; + unsigned char * DS_ptr; + bool DS_flag; + +// type 1 frame + TM_list *T1F_pointer ; + int T1F_counter; + + TM_list *T0F_pointer ; void differential_encode(unsigned char* ptr, int length){ @@ -57,7 +87,7 @@ return type; } - void data_number(){ + void inline data_number(){ int type1_frame_no; TM_list *head = list_ptr; @@ -170,23 +200,21 @@ unsigned char * type1_frame(){ int i; - static TM_list *pointer ; - static int counter = 0; if(type1_frame_flag){ - pointer = first_type_structure(1); - counter = 0; + T1F_pointer = first_type_structure(1); + T1F_counter = 0; type1_frame_flag = false; } - for(i = 4 ; (i < 134) && (pointer != NULL) ; i++){ - TMframe_type1[i] = pointer->TM_string[counter]; + for(i = 4 ; (i < 134) && (T1F_pointer != NULL) ; i++){ + TMframe_type1[i] = T1F_pointer->TM_string[T1F_counter]; - if(counter++ == 12){ - counter = 0; - pointer = next_type_structure(pointer); + if(T1F_counter++ == 12){ + T1F_counter = 0; + T1F_pointer = next_type_structure(T1F_pointer); } } @@ -196,7 +224,7 @@ TMframe_type1[3] = CRC::crc16_gen(TMframe_type1,3); //end header - if(pointer == NULL){ + if(T1F_pointer == NULL){ for( ; i < 134 ; i++){ //repeating ;ast packet to fill up the extra space TMframe_type1[i] = TMframe_type1[i-13]; } @@ -209,18 +237,18 @@ bool type0_frame_flag; unsigned char* type0_frame(){ - static TM_list *pointer ; + if(type0_frame_flag){ - pointer = first_type_structure(0); + T0F_pointer = first_type_structure(0); type0_frame_flag = false; } else { - pointer = next_type_structure(pointer); + T0F_pointer = next_type_structure(T0F_pointer); } - return pointer->TM_string; + return T0F_pointer->TM_string; } @@ -313,6 +341,30 @@ unsigned char EoS[EoS_SIZE]; SND_TM(){ + //transmit + Tframe_counter = 0; //contains the number of Tframes in a segment had been written + EOS_counter = 0; //count no of byres of eos have been weitten in the buffer + Sframe_Counter = 0; + SCH40_counter = 0; + string_space_counter = 0; + FCCH80_counter = 0; + rolling_buffer_counter = 0; //maximum it can be 1152 bits + Sframe_flag = true; + new_Tframe_flag = false; + FCCH80_flag = false; + data_flag = false; + repete_data_flag = false; + segment_counter = 0; + diff_enc_flag = false; + + + state = true; + DS_counter = 0; + DS_flag = false; + +// type_1_frame + T1F_counter = 0; + // list_ptr = x; diff_prev = 0; @@ -414,7 +466,10 @@ } - void head_pointer(TM_list * ptr){ + bool transmit_data_flag; + +// void head_pointer(TM_list * ptr){ + void head_pointer(TM_list *ptr){ list_ptr = ptr ; type1_frame_flag = true; type0_frame_flag = true; @@ -426,91 +481,98 @@ unsigned char convoluted_frame[270]; - Convolution ConvObj; + Convolution ConvObj2; void convolution (unsigned char * ptr){ - ConvObj.convolutionEncode(ptr, convoluted_frame); - ConvObj.convolutionEncode(ptr + 67, convoluted_frame + 135); + ConvObj2.convolutionEncode(ptr, convoluted_frame); + ConvObj2.convolutionEncode(ptr + 67, convoluted_frame + 135); } unsigned char interleave_data[2][144]; //initialize to zero how; bool make_DataStream_flag; - int make_DataStream(){ - static bool state = true; - static int counter = 0; - static unsigned char * ptr; - static bool flag = false; - - if(make_DataStream_flag){ - data_number(); - state = true; - counter = 0; - flag = false; - make_DataStream_flag = false; - } - - if(state){ - - if(counter < type0_no){ - ptr = type0_frame(); - flag = true; - - } - - else if(counter < total_frames ){ - ptr = type1_frame(); - flag = true; - } - - counter++; - - } - - state = !state; - - if (flag){ -// cout<<"i m here"; - -// printf("------inside convolution\r\n"); - convolution(ptr); -// printf("-------out of convolution\n"); - interleave(convoluted_frame,interleave_data[0]); - interleave(convoluted_frame+ 135,interleave_data[1]); -// printf("completed intrleave\n"); - flag = false; - - } - - - int temp = (state == false) ? 0 : 1 ; - - return temp; - - } +// int inline make_DataStream(){ +// +// if(make_DataStream_flag){ +//// data_number(); +// +// int type1_frame_no; +// TM_list *head = list_ptr; +// +// type0_no = 0; +// type1_no = 0; +// +// do{ +// +// switch( decide_type(head->tmid) ){ +// case 0: +// type0_no++; +// break; +// case 1: +// type1_no++; +// } +// +// head=head->next_TM; +// +// } +// while(head->next_TM != NULL); +// +// type1_frame_no = ( type1_no % 10 == 0 )? (type1_no / 10) : ( (type1_no / 10) + 1); +// total_frames = type0_no + type1_frame_no ; +// segment_no = (total_frames*2 % (SEGMENT_SIZE-1) == 0) ? ( total_frames*2/(SEGMENT_SIZE-1) ) : (total_frames*2/(SEGMENT_SIZE-1) + 1); //subtracting 1 since the last Tframe is not detected +// +// +// state = true; +// DS_counter = 0; +// DS_flag = false; +// make_DataStream_flag = false; +// } +//// +// if(state){ +// +// if(DS_counter < type0_no){ +// DS_ptr = type0_frame(); +// DS_flag = true; +// +// } +// +// else if(DS_counter < total_frames ){ +// DS_ptr = type1_frame(); +// DS_flag = true; +// } +// +// DS_counter++; +// +// } +// +// state = !state; +// +// if (DS_flag){ +//// cout<<"i m here"; +// +//// printf("------inside convolution\r\n"); +// convolution(DS_ptr); +//// printf("-------out of convolution\n"); +// interleave(convoluted_frame,interleave_data[0]); +// interleave(convoluted_frame+ 135,interleave_data[1]); +//// printf("completed intrleave\n"); +// DS_flag = false; +// +// } +//// +//// +// int temp = (state == false) ? 0 : 1 ; +// +// return temp; +// +// } //112 bytes - half rolling buffer - bool transmit_data_flag; + - void transmit_data(unsigned char * transmit , bool * last_buffer){ - static int Tframe_counter = 0; //contains the number of Tframes in a segment had been written - static int EOS_counter = 0; //count no of byres of eos have been weitten in the buffer - static int Sframe_Counter = 0; - static int SCH40_counter = 0; - static int string_space_counter = 0; - static int FCCH80_counter = 0; - int rolling_buffer_counter = 0; //maximum it can be 1152 bits - static bool Sframe_flag = true; - static bool new_Tframe_flag = false; - static bool FCCH80_flag = false; - static bool data_flag = false; - static int i; - static bool repete_data_flag = false; - static int segment_counter = 0; - static bool diff_enc_flag = false; - + void inline transmit_data(unsigned char * transmit , bool * last_buffer){ if(transmit_data_flag){ rolling_buffer_counter = 0; Sframe_Counter = 0; @@ -530,13 +592,13 @@ diff_enc_flag = false; } - for(rolling_buffer_counter = 0 ; rolling_buffer_counter<112 ; rolling_buffer_counter++){ - + for(rolling_buffer_counter = 0 ; rolling_buffer_counter<112 ; rolling_buffer_counter++){ +// if(diff_enc_flag){ transmit[rolling_buffer_counter] = 0; continue; } - +// if(Sframe_flag){ transmit[rolling_buffer_counter] = S_frame[Sframe_Counter++]; @@ -548,7 +610,7 @@ } } - +// else if(new_Tframe_flag){ transmit[rolling_buffer_counter] = SCH40[SCH40_counter++]; @@ -565,25 +627,118 @@ } } - +// else if(data_flag){ - if(!string_space_counter ){ - i = make_DataStream(); + if(string_space_counter == 0 ){ + +//--------------------------------------------------------------------------------------- + if(make_DataStream_flag){ + int type1_frame_no; + TM_list *head = list_ptr; + + type0_no = 0; + type1_no = 0; + + while(head != NULL){ + unsigned char tmid = head->tmid; + int type = 0; + + switch(tmid){ + case 0x1: + case 0x2: + case 0x3: + case 0x4: + case 0x5: + case 0x6: + case 0x7: + case 0x8: + type = 0; + break; + case 0xA: + case 0xB: + case 0xC: + case 0xD: + case 0xE: + type = 1; + break; + } + + + switch( type ){ + case 0: + type0_no++; + break; + case 1: + type1_no++; + } + + head=head->next_TM; + + } + + + type1_frame_no = ( type1_no % 10 == 0 )? (type1_no / 10) : ( (type1_no / 10) + 1); + total_frames = type0_no + type1_frame_no ; + segment_no = (total_frames*2 % (SEGMENT_SIZE-1) == 0) ? ( total_frames*2/(SEGMENT_SIZE-1) ) : (total_frames*2/(SEGMENT_SIZE-1) + 1); //subtracting 1 since the last Tframe is not detected + + + state = true; + DS_counter = 0; + DS_flag = false; + make_DataStream_flag = false; + } + // + if(state){ + + if(DS_counter < type0_no){ + DS_ptr = type0_frame(); + DS_flag = true; + + } + + else if(DS_counter < total_frames ){ + DS_ptr = type1_frame(); + DS_flag = true; + } + + DS_counter++; + + } + + state = !state; + + if (DS_flag){ + // cout<<"i m here"; + + // printf("------inside convolution\r\n"); + convolution(DS_ptr); + // printf("-------out of convolution\n"); + interleave(convoluted_frame,interleave_data[0]); + interleave(convoluted_frame+ 135,interleave_data[1]); + // printf("completed intrleave\n"); + DS_flag = false; + + } + + // + int temp = (state == false) ? 0 : 1 ; +//--------------------------------------------------------------------------------------- + uv = temp ; } - - transmit[rolling_buffer_counter] = interleave_data[i][string_space_counter++]; +// + transmit[rolling_buffer_counter] = interleave_data[uv][string_space_counter++]; if(string_space_counter == 144){ // printf("data_flag quit\n"); string_space_counter = 0; FCCH80_flag = true; data_flag = false; } - +// } - +// else if(repete_data_flag){ - transmit[rolling_buffer_counter] = interleave_data[i][string_space_counter];; + transmit[rolling_buffer_counter] = interleave_data[uv][string_space_counter];; if(++string_space_counter == 144){ repete_data_flag = false; FCCH80_flag = true; @@ -618,7 +773,6 @@ diff_enc_flag = true; Tframe_counter = 0; EOS_counter = 0; - if(++segment_counter == segment_no){ // cout<<"transmit_counter = "<<++transmit_counter; *last_buffer = true; @@ -636,8 +790,8 @@ } - +// printf("a"); differential_encode(transmit,112); if(diff_enc_flag){ @@ -648,5 +802,21 @@ } } + +// void inline printhaha(void){ +//// TM_list *ptr = NULL; +// printf("c"); +// // list_ptr = ptr ; +// type1_frame_flag = true; +// type0_frame_flag = true; +// make_DataStream_flag = true; +// transmit_data_flag = true; +// transmission_done=false; +// printf("b"); +// adf_not_SDcard(); +// printf("a"); +// } -}snd_tm; \ No newline at end of file +}; + +SND_TM snd_tm; \ No newline at end of file