publishing to check changes in cdms code
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE_samp_23SEP_DMA_flag by
COM_SND_TM.h@118:60c5de4cb8ad, 2016-02-06 (annotated)
- Committer:
- krishanprajapat
- Date:
- Sat Feb 06 10:48:07 2016 +0000
- Revision:
- 118:60c5de4cb8ad
- Parent:
- 102:80c911a6e736
- Child:
- 133:56d37aa8a011
- Child:
- 139:1018e1dc82e9
added some function for obsrs tc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aniruddhv | 52:0bd68655c651 | 1 | //void adf_not_SDcard(); |
shreeshas95 | 1:a0055b3280c8 | 2 | |
ee12b079 | 84:b0f7a241ddf3 | 3 | //~ #include"SDcard.h" |
ee12b079 | 86:a26f5f22631d | 4 | /*#define T_frames 30 |
ee12b079 | 84:b0f7a241ddf3 | 5 | unsigned char buffer_112_counter,sent_tm = 0; |
ee12b079 | 84:b0f7a241ddf3 | 6 | int disk_read(uint8_t *, uint64_t),j; |
ee12b079 | 84:b0f7a241ddf3 | 7 | bool new_session = true; |
ee12b079 | 84:b0f7a241ddf3 | 8 | bool last_buffer = false; |
ee12b079 | 84:b0f7a241ddf3 | 9 | bool first_block = true; |
ee12b079 | 84:b0f7a241ddf3 | 10 | bool last_block =false; |
ee12b079 | 84:b0f7a241ddf3 | 11 | bool repeat_T_frame = false; |
ee12b079 | 84:b0f7a241ddf3 | 12 | unsigned int counter_in_block=0,diff_prev=0; |
ee12b079 | 84:b0f7a241ddf3 | 13 | unsigned char EOS_counter = 0; |
ee12b079 | 84:b0f7a241ddf3 | 14 | unsigned char enable_T_frame = false; |
ee12b079 | 84:b0f7a241ddf3 | 15 | uint64_t start_block_num ; // Read from TC |
ee12b079 | 84:b0f7a241ddf3 | 16 | uint64_t end_block_num ; // Read from TC |
ee12b079 | 84:b0f7a241ddf3 | 17 | uint64_t Number_of_blocks_to_read ; |
ee12b079 | 84:b0f7a241ddf3 | 18 | uint64_t block_counter = 0; |
ee12b079 | 84:b0f7a241ddf3 | 19 | unsigned char buffer_512[512], buffer_112[112],counter_in_S_frame=0,counter_in_SCH=0; |
ee12b079 | 84:b0f7a241ddf3 | 20 | unsigned char make_EOS_flag = true; |
ee12b079 | 86:a26f5f22631d | 21 | bool reset = false; */ |
ee12b079 | 84:b0f7a241ddf3 | 22 | |
ee12b079 | 84:b0f7a241ddf3 | 23 | |
ee12b079 | 84:b0f7a241ddf3 | 24 | |
ee12b079 | 84:b0f7a241ddf3 | 25 | |
ee12b079 | 84:b0f7a241ddf3 | 26 | |
ee12b079 | 84:b0f7a241ddf3 | 27 | |
ee12b079 | 84:b0f7a241ddf3 | 28 | |
ee12b079 | 95:42d6747900cb | 29 | bool sent_tmfrom_SDcard; |
ee12b079 | 84:b0f7a241ddf3 | 30 | |
ee12b079 | 84:b0f7a241ddf3 | 31 | |
ee12b079 | 84:b0f7a241ddf3 | 32 | |
shreeshas95 | 1:a0055b3280c8 | 33 | #define S_FRAME_SIZE 48 |
ee12b079 | 9:e9eaada136c6 | 34 | #define ISR 40 |
shreeshas95 | 1:a0055b3280c8 | 35 | #define TM_FRAME_SIZE 134 //in bytes |
shreeshas95 | 1:a0055b3280c8 | 36 | #define T_FRAME_SIZE 159 |
shreeshas95 | 1:a0055b3280c8 | 37 | #define EOS_SIZE 120 |
ee12b079 | 9:e9eaada136c6 | 38 | #define MAX_ADF_LEN 65535 |
ee12b079 | 9:e9eaada136c6 | 39 | |
shreeshas95 | 1:a0055b3280c8 | 40 | 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 | 41 | 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 | 42 | const unsigned char FCCH80[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
shreeshas95 | 1:a0055b3280c8 | 43 | const unsigned char SCH40[] = {0x0a,0x3f,0x46,0xb4,0x00}; |
aniruddhv | 52:0bd68655c651 | 44 | 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}; |
ee12b079 | 9:e9eaada136c6 | 45 | |
krishanprajapat | 118:60c5de4cb8ad | 46 | unsigned char interleave_data[2][144]; |
aniruddhv | 69:20f09a0c3fd2 | 47 | #define print_tm(ptr) {\ |
aniruddhv | 69:20f09a0c3fd2 | 48 | for( int i = 0; i < 134; i++ ){\ |
aniruddhv | 69:20f09a0c3fd2 | 49 | gPC.putc(ptr[i]);\ |
aniruddhv | 69:20f09a0c3fd2 | 50 | }\ |
aniruddhv | 69:20f09a0c3fd2 | 51 | } |
aniruddhv | 69:20f09a0c3fd2 | 52 | |
ee12b079 | 86:a26f5f22631d | 53 | //void send_tm_from_SD_card(){} |
ee12b079 | 84:b0f7a241ddf3 | 54 | |
shreeshas95 | 1:a0055b3280c8 | 55 | class SND_TM{ |
ee12b079 | 9:e9eaada136c6 | 56 | |
ee12b079 | 9:e9eaada136c6 | 57 | Base_tm * head_ptr; |
ee12b079 | 9:e9eaada136c6 | 58 | |
shreeshas95 | 1:a0055b3280c8 | 59 | // transmit data variables |
shreeshas95 | 1:a0055b3280c8 | 60 | unsigned char Tframe_c; //_c represents counter, counts Tframe written in a segment |
shreeshas95 | 1:a0055b3280c8 | 61 | unsigned char EOS_c; //count no of bytes of eos have been weitten in the rolling buffer |
shreeshas95 | 1:a0055b3280c8 | 62 | unsigned char Sframe_c; //count no of bytes of Sframe have been weitten in the rolling buffer |
shreeshas95 | 1:a0055b3280c8 | 63 | unsigned char SCH40_c; //count no of bytes of SCH40 have been weitten in the rolling buffer |
shreeshas95 | 1:a0055b3280c8 | 64 | unsigned char data_c; |
shreeshas95 | 1:a0055b3280c8 | 65 | unsigned char FCCH80_c; |
shreeshas95 | 1:a0055b3280c8 | 66 | unsigned char RB_c; //rolling buffer counter |
shreeshas95 | 1:a0055b3280c8 | 67 | unsigned char segment_c; //counts the numver of segments sent |
shreeshas95 | 1:a0055b3280c8 | 68 | unsigned char MAX_SEGMENT; |
shreeshas95 | 1:a0055b3280c8 | 69 | bool Sframe; //Sframe = 1bit of CF1 |
shreeshas95 | 1:a0055b3280c8 | 70 | bool SCH40_f; |
shreeshas95 | 1:a0055b3280c8 | 71 | bool FCCH80_f; |
shreeshas95 | 1:a0055b3280c8 | 72 | bool data_f; |
ee12b079 | 9:e9eaada136c6 | 73 | bool repeat_data_f; |
shreeshas95 | 1:a0055b3280c8 | 74 | bool transmit_data_f; |
shreeshas95 | 1:a0055b3280c8 | 75 | bool eos_f; |
shreeshas95 | 1:a0055b3280c8 | 76 | bool junk_f; |
ee12b079 | 9:e9eaada136c6 | 77 | bool segment_r; //flag checking if more sessions are required |
ee12b079 | 9:e9eaada136c6 | 78 | |
ee12b079 | 9:e9eaada136c6 | 79 | |
shreeshas95 | 1:a0055b3280c8 | 80 | // type 1 frame |
ee12b079 | 9:e9eaada136c6 | 81 | |
shreeshas95 | 1:a0055b3280c8 | 82 | Base_tm *T0F_pointer ; |
ee12b079 | 9:e9eaada136c6 | 83 | |
shreeshas95 | 1:a0055b3280c8 | 84 | int diff_prev; |
shreeshas95 | 1:a0055b3280c8 | 85 | void differential_encode(unsigned char* ptr, int length){ |
shreeshas95 | 1:a0055b3280c8 | 86 | for(int i=0; i<length;i++){ |
shreeshas95 | 1:a0055b3280c8 | 87 | unsigned char s = ptr[i] , t; |
shreeshas95 | 1:a0055b3280c8 | 88 | t = s ^ (s >> 1); |
shreeshas95 | 1:a0055b3280c8 | 89 | (diff_prev == 0) ? t=t^0x00 : t=t^0x80 ; |
shreeshas95 | 1:a0055b3280c8 | 90 | diff_prev = int(s & 0x01); |
shreeshas95 | 1:a0055b3280c8 | 91 | ptr[i] = t; |
shreeshas95 | 1:a0055b3280c8 | 92 | } |
ee12b079 | 9:e9eaada136c6 | 93 | } |
ee12b079 | 9:e9eaada136c6 | 94 | |
shreeshas95 | 1:a0055b3280c8 | 95 | int type0_no; //number of type zero frames |
ee12b079 | 9:e9eaada136c6 | 96 | int type1_no; |
shreeshas95 | 1:a0055b3280c8 | 97 | int total_frames; //number of type one packe (TMP) |
shreeshas95 | 1:a0055b3280c8 | 98 | int SEGMENT_NO; //number of type one packe (TMP) |
ee12b079 | 9:e9eaada136c6 | 99 | int TOTAL_SEGMENT_NO; |
ee12b079 | 9:e9eaada136c6 | 100 | int LAST_SEGMENT_SIZE; |
shreeshas95 | 1:a0055b3280c8 | 101 | void inline data_number(){ |
shreeshas95 | 1:a0055b3280c8 | 102 | int type1_frame_no; |
shreeshas95 | 1:a0055b3280c8 | 103 | Base_tm*head = head_ptr; |
shreeshas95 | 1:a0055b3280c8 | 104 | type0_no = 0; |
shreeshas95 | 1:a0055b3280c8 | 105 | type1_no = 0; |
aniruddhv | 52:0bd68655c651 | 106 | while(head != NULL){ |
shreeshas95 | 102:80c911a6e736 | 107 | switch( GETshort_or_long_tm(head) ){ |
shreeshas95 | 1:a0055b3280c8 | 108 | case 0: |
shreeshas95 | 1:a0055b3280c8 | 109 | type0_no++; |
shreeshas95 | 1:a0055b3280c8 | 110 | break; |
shreeshas95 | 1:a0055b3280c8 | 111 | case 1: |
shreeshas95 | 1:a0055b3280c8 | 112 | type1_no++; |
shreeshas95 | 1:a0055b3280c8 | 113 | break; |
shreeshas95 | 1:a0055b3280c8 | 114 | } |
ee12b079 | 9:e9eaada136c6 | 115 | |
shreeshas95 | 1:a0055b3280c8 | 116 | head=head->next_TM; |
shreeshas95 | 1:a0055b3280c8 | 117 | } |
shreeshas95 | 1:a0055b3280c8 | 118 | type1_frame_no = ( type1_no % 10 == 0 )? (type1_no / 10) : ( (type1_no / 10) + 1); |
shreeshas95 | 1:a0055b3280c8 | 119 | total_frames = type0_no + type1_frame_no ; |
ee12b079 | 9:e9eaada136c6 | 120 | 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 |
ee12b079 | 9:e9eaada136c6 | 121 | SEGMENT_NO = TOTAL_SEGMENT_NO; |
ee12b079 | 9:e9eaada136c6 | 122 | if(SEGMENT_NO > MAX_SEGMENT) |
ee12b079 | 9:e9eaada136c6 | 123 | { |
ee12b079 | 9:e9eaada136c6 | 124 | SEGMENT_NO = MAX_SEGMENT; |
ee12b079 | 9:e9eaada136c6 | 125 | } |
aniruddhv | 52:0bd68655c651 | 126 | if(SEGMENT_NO == 1) segment_r = 0; else segment_r = 1; |
ee12b079 | 9:e9eaada136c6 | 127 | TOTAL_SEGMENT_NO -= SEGMENT_NO; |
aniruddhv | 52:0bd68655c651 | 128 | LAST_SEGMENT_SIZE = total_frames*2%ISR?total_frames*2%ISR:ISR; |
shreeshas95 | 1:a0055b3280c8 | 129 | } |
ee12b079 | 9:e9eaada136c6 | 130 | |
shreeshas95 | 1:a0055b3280c8 | 131 | #define next_type_structure(ptr){\ |
shreeshas95 | 102:80c911a6e736 | 132 | unsigned char temp = GETshort_or_long_tm(ptr);\ |
shreeshas95 | 1:a0055b3280c8 | 133 | if((temp == 0) && (ptr->next_TM != NULL) ){\ |
shreeshas95 | 1:a0055b3280c8 | 134 | do{\ |
shreeshas95 | 1:a0055b3280c8 | 135 | ptr = ptr->next_TM;\ |
shreeshas95 | 102:80c911a6e736 | 136 | temp = GETshort_or_long_tm(ptr);\ |
shreeshas95 | 1:a0055b3280c8 | 137 | }\ |
shreeshas95 | 1:a0055b3280c8 | 138 | while(temp == 1 && ptr->next_TM != NULL);\ |
shreeshas95 | 1:a0055b3280c8 | 139 | if(temp == 1){\ |
shreeshas95 | 1:a0055b3280c8 | 140 | ptr = NULL;\ |
shreeshas95 | 1:a0055b3280c8 | 141 | }\ |
shreeshas95 | 1:a0055b3280c8 | 142 | }\ |
shreeshas95 | 1:a0055b3280c8 | 143 | else if((temp == 1) && (ptr->next_TM != NULL)){\ |
shreeshas95 | 1:a0055b3280c8 | 144 | do{\ |
shreeshas95 | 1:a0055b3280c8 | 145 | ptr = ptr->next_TM;\ |
shreeshas95 | 102:80c911a6e736 | 146 | temp = GETshort_or_long_tm(ptr);\ |
shreeshas95 | 1:a0055b3280c8 | 147 | }\ |
shreeshas95 | 1:a0055b3280c8 | 148 | while(temp == 0 && ptr->next_TM != NULL);\ |
shreeshas95 | 1:a0055b3280c8 | 149 | if(temp == 0){\ |
ee12b079 | 9:e9eaada136c6 | 150 | ptr = NULL;\ |
shreeshas95 | 1:a0055b3280c8 | 151 | }\ |
shreeshas95 | 1:a0055b3280c8 | 152 | }\ |
shreeshas95 | 1:a0055b3280c8 | 153 | else{\ |
ee12b079 | 9:e9eaada136c6 | 154 | ptr = NULL;\ |
shreeshas95 | 1:a0055b3280c8 | 155 | }\ |
shreeshas95 | 1:a0055b3280c8 | 156 | } |
ee12b079 | 9:e9eaada136c6 | 157 | |
shreeshas95 | 1:a0055b3280c8 | 158 | /* |
shreeshas95 | 1:a0055b3280c8 | 159 | 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 | 160 | parameter: type 0 or 1 |
ee12b079 | 9:e9eaada136c6 | 161 | return: pointer of the first node having same type |
shreeshas95 | 1:a0055b3280c8 | 162 | */ |
aniruddhv | 52:0bd68655c651 | 163 | #define exor(ptr) { for(int i=0 ; i<134; i++ ) ptr[i]=ptr[i]^EXOR_SEQ[i];} |
ee12b079 | 9:e9eaada136c6 | 164 | |
ee12b079 | 9:e9eaada136c6 | 165 | |
shreeshas95 | 1:a0055b3280c8 | 166 | #define first_type_structure( type,return_ptr) {\ |
shreeshas95 | 1:a0055b3280c8 | 167 | Base_tm* temp_ptr = head_ptr;\ |
shreeshas95 | 1:a0055b3280c8 | 168 | if(type == 0){\ |
shreeshas95 | 102:80c911a6e736 | 169 | while(GETshort_or_long_tm(temp_ptr) == 1){\ |
shreeshas95 | 1:a0055b3280c8 | 170 | temp_ptr = temp_ptr->next_TM;\ |
shreeshas95 | 1:a0055b3280c8 | 171 | if(temp_ptr == NULL){\ |
shreeshas95 | 1:a0055b3280c8 | 172 | return_ptr = NULL ;\ |
shreeshas95 | 1:a0055b3280c8 | 173 | }\ |
shreeshas95 | 1:a0055b3280c8 | 174 | }\ |
shreeshas95 | 1:a0055b3280c8 | 175 | }\ |
shreeshas95 | 1:a0055b3280c8 | 176 | else if(type == 1){\ |
shreeshas95 | 102:80c911a6e736 | 177 | while(GETshort_or_long_tm(temp_ptr) == 0){\ |
shreeshas95 | 1:a0055b3280c8 | 178 | temp_ptr = temp_ptr->next_TM;\ |
shreeshas95 | 1:a0055b3280c8 | 179 | if(temp_ptr == NULL){\ |
shreeshas95 | 1:a0055b3280c8 | 180 | return_ptr = NULL;\ |
shreeshas95 | 1:a0055b3280c8 | 181 | }\ |
shreeshas95 | 1:a0055b3280c8 | 182 | }\ |
shreeshas95 | 1:a0055b3280c8 | 183 | }\ |
shreeshas95 | 1:a0055b3280c8 | 184 | return_ptr = temp_ptr;\ |
shreeshas95 | 1:a0055b3280c8 | 185 | } |
ee12b079 | 9:e9eaada136c6 | 186 | |
ee12b079 | 9:e9eaada136c6 | 187 | |
ee12b079 | 9:e9eaada136c6 | 188 | |
shreeshas95 | 1:a0055b3280c8 | 189 | Base_tm *T1F_pointer ; |
shreeshas95 | 1:a0055b3280c8 | 190 | int T1F_counter; |
shreeshas95 | 1:a0055b3280c8 | 191 | unsigned char TMframe_type1[TM_FRAME_SIZE]; |
shreeshas95 | 1:a0055b3280c8 | 192 | bool type1_frame_flag; //should be true for every new list |
ee12b079 | 9:e9eaada136c6 | 193 | |
shreeshas95 | 1:a0055b3280c8 | 194 | #define type1_frame(ptr){\ |
shreeshas95 | 1:a0055b3280c8 | 195 | int i=4;\ |
shreeshas95 | 1:a0055b3280c8 | 196 | if(type1_frame_flag){\ |
shreeshas95 | 1:a0055b3280c8 | 197 | first_type_structure(1,T1F_pointer);\ |
shreeshas95 | 1:a0055b3280c8 | 198 | T1F_counter = 0;\ |
shreeshas95 | 1:a0055b3280c8 | 199 | type1_frame_flag = false;\ |
shreeshas95 | 1:a0055b3280c8 | 200 | }\ |
shreeshas95 | 1:a0055b3280c8 | 201 | for(i = 4 ; (i < 134) && (T1F_pointer != NULL) ; i++){\ |
shreeshas95 | 1:a0055b3280c8 | 202 | TMframe_type1[i] = T1F_pointer->TM_string[T1F_counter];\ |
shreeshas95 | 1:a0055b3280c8 | 203 | if(T1F_counter++ == 12){\ |
shreeshas95 | 1:a0055b3280c8 | 204 | T1F_counter = 0;\ |
shreeshas95 | 1:a0055b3280c8 | 205 | next_type_structure(T1F_pointer);\ |
shreeshas95 | 1:a0055b3280c8 | 206 | }\ |
shreeshas95 | 1:a0055b3280c8 | 207 | }\ |
aniruddhv | 52:0bd68655c651 | 208 | TMframe_type1[0] = (1<<7) + (( (i-4)/13 )<<3);\ |
aniruddhv | 69:20f09a0c3fd2 | 209 | TMframe_type1[3] = crc8_gen(TMframe_type1,3);\ |
shreeshas95 | 1:a0055b3280c8 | 210 | if(T1F_pointer == NULL && i>12){\ |
shreeshas95 | 1:a0055b3280c8 | 211 | for( ; i < 134 ; i++){\ |
shreeshas95 | 1:a0055b3280c8 | 212 | TMframe_type1[i] = TMframe_type1[i-13];\ |
shreeshas95 | 1:a0055b3280c8 | 213 | }\ |
shreeshas95 | 1:a0055b3280c8 | 214 | }\ |
ee12b079 | 9:e9eaada136c6 | 215 | ptr=TMframe_type1;\ |
shreeshas95 | 1:a0055b3280c8 | 216 | } |
ee12b079 | 9:e9eaada136c6 | 217 | |
ee12b079 | 9:e9eaada136c6 | 218 | |
shreeshas95 | 1:a0055b3280c8 | 219 | bool type0_frame_flag; |
ee12b079 | 9:e9eaada136c6 | 220 | |
ee12b079 | 9:e9eaada136c6 | 221 | |
shreeshas95 | 1:a0055b3280c8 | 222 | #define type0_frame(ptr){\ |
shreeshas95 | 1:a0055b3280c8 | 223 | if(type0_frame_flag){\ |
shreeshas95 | 1:a0055b3280c8 | 224 | first_type_structure(0,T0F_pointer);\ |
shreeshas95 | 1:a0055b3280c8 | 225 | type0_frame_flag = false;\ |
shreeshas95 | 1:a0055b3280c8 | 226 | }\ |
shreeshas95 | 1:a0055b3280c8 | 227 | else {\ |
shreeshas95 | 1:a0055b3280c8 | 228 | next_type_structure(T0F_pointer);\ |
shreeshas95 | 1:a0055b3280c8 | 229 | }\ |
shreeshas95 | 1:a0055b3280c8 | 230 | ptr = T0F_pointer->TM_string;\ |
shreeshas95 | 1:a0055b3280c8 | 231 | } |
ee12b079 | 53:18db568f1098 | 232 | |
ee12b079 | 9:e9eaada136c6 | 233 | unsigned char convoluted_frame[270]; |
shreeshas95 | 1:a0055b3280c8 | 234 | Convolution ConvObj2; |
shreeshas95 | 1:a0055b3280c8 | 235 | void convolution (unsigned char * ptr){ |
shreeshas95 | 1:a0055b3280c8 | 236 | ConvObj2.convolutionEncode(ptr, convoluted_frame); |
shreeshas95 | 1:a0055b3280c8 | 237 | ConvObj2.convolutionEncode(ptr + 67, convoluted_frame + 135); |
shreeshas95 | 1:a0055b3280c8 | 238 | } |
ee12b079 | 9:e9eaada136c6 | 239 | |
ee12b079 | 9:e9eaada136c6 | 240 | |
ee12b079 | 9:e9eaada136c6 | 241 | unsigned char interleave_data[2][144]; |
shreeshas95 | 1:a0055b3280c8 | 242 | unsigned char DS_index; |
shreeshas95 | 1:a0055b3280c8 | 243 | bool DS_state; |
shreeshas95 | 1:a0055b3280c8 | 244 | int DS_counter; |
shreeshas95 | 1:a0055b3280c8 | 245 | bool DS_f; |
shreeshas95 | 1:a0055b3280c8 | 246 | bool make_DataStream_f; |
ee12b079 | 9:e9eaada136c6 | 247 | |
ee12b079 | 9:e9eaada136c6 | 248 | #define make_DataStream {\ |
ee12b079 | 9:e9eaada136c6 | 249 | unsigned char* ptr;\ |
ee12b079 | 9:e9eaada136c6 | 250 | if(make_DataStream_f == true){\ |
ee12b079 | 9:e9eaada136c6 | 251 | DS_state = true;\ |
ee12b079 | 9:e9eaada136c6 | 252 | DS_counter = 0;\ |
ee12b079 | 9:e9eaada136c6 | 253 | DS_f = false;\ |
ee12b079 | 9:e9eaada136c6 | 254 | make_DataStream_f = false;\ |
ee12b079 | 9:e9eaada136c6 | 255 | }\ |
ee12b079 | 9:e9eaada136c6 | 256 | if(DS_state){\ |
ee12b079 | 9:e9eaada136c6 | 257 | if(DS_counter < total_frames-type0_no){\ |
ee12b079 | 9:e9eaada136c6 | 258 | type1_frame(ptr); \ |
ee12b079 | 9:e9eaada136c6 | 259 | DS_f = true;\ |
ee12b079 | 9:e9eaada136c6 | 260 | }\ |
ee12b079 | 9:e9eaada136c6 | 261 | else if(DS_counter < total_frames ){\ |
ee12b079 | 9:e9eaada136c6 | 262 | type0_frame(ptr);\ |
ee12b079 | 9:e9eaada136c6 | 263 | DS_f = true;\ |
ee12b079 | 9:e9eaada136c6 | 264 | }\ |
ee12b079 | 9:e9eaada136c6 | 265 | DS_counter++;\ |
ee12b079 | 9:e9eaada136c6 | 266 | }\ |
ee12b079 | 9:e9eaada136c6 | 267 | DS_state = !DS_state;\ |
ee12b079 | 9:e9eaada136c6 | 268 | if (DS_f){\ |
ee12b079 | 9:e9eaada136c6 | 269 | DS_f = false;\ |
aniruddhv | 69:20f09a0c3fd2 | 270 | if(bypass_adf == 1)\ |
aniruddhv | 69:20f09a0c3fd2 | 271 | print_tm(ptr);\ |
aniruddhv | 52:0bd68655c651 | 272 | exor(ptr);\ |
ee12b079 | 9:e9eaada136c6 | 273 | convolution(ptr);\ |
ee12b079 | 9:e9eaada136c6 | 274 | interleave(convoluted_frame,interleave_data[0]);\ |
ee12b079 | 9:e9eaada136c6 | 275 | interleave(convoluted_frame+ 135,interleave_data[1]);}\ |
ee12b079 | 9:e9eaada136c6 | 276 | DS_index = (DS_state==true)?1:0;\ |
ee12b079 | 9:e9eaada136c6 | 277 | } |
ee12b079 | 9:e9eaada136c6 | 278 | |
ee12b079 | 9:e9eaada136c6 | 279 | |
ee12b079 | 9:e9eaada136c6 | 280 | // |
shreeshas95 | 1:a0055b3280c8 | 281 | public: |
ee12b079 | 9:e9eaada136c6 | 282 | |
shreeshas95 | 1:a0055b3280c8 | 283 | bool reset_adf; |
shreeshas95 | 1:a0055b3280c8 | 284 | SND_TM(){ |
rohit3342 | 11:83acbe8e0ad1 | 285 | MAX_SEGMENT = (MAX_ADF_LEN-EOS_SIZE)/( S_FRAME_SIZE + ISR*T_FRAME_SIZE); |
ee12b079 | 9:e9eaada136c6 | 286 | //(max length - eos size)/(sframe length + tFrameLength*ISR) |
shreeshas95 | 1:a0055b3280c8 | 287 | } |
ee12b079 | 9:e9eaada136c6 | 288 | |
shreeshas95 | 1:a0055b3280c8 | 289 | |
ee12b079 | 9:e9eaada136c6 | 290 | |
shreeshas95 | 1:a0055b3280c8 | 291 | void head_pointer(Base_tm* ptr){ |
shreeshas95 | 1:a0055b3280c8 | 292 | head_ptr = ptr ; |
shreeshas95 | 1:a0055b3280c8 | 293 | type1_frame_flag = true; |
shreeshas95 | 1:a0055b3280c8 | 294 | type0_frame_flag = true; |
shreeshas95 | 1:a0055b3280c8 | 295 | make_DataStream_f = true; |
shreeshas95 | 1:a0055b3280c8 | 296 | transmit_data_f = true; |
ee12b079 | 95:42d6747900cb | 297 | sent_tmfrom_SDcard = false; |
shreeshas95 | 1:a0055b3280c8 | 298 | diff_prev = 0; |
shreeshas95 | 1:a0055b3280c8 | 299 | data_number(); |
shreeshas95 | 1:a0055b3280c8 | 300 | } |
ee12b079 | 9:e9eaada136c6 | 301 | |
krishanprajapat | 118:60c5de4cb8ad | 302 | int make_shor_tm(){ |
krishanprajapat | 118:60c5de4cb8ad | 303 | make_DataStream; |
krishanprajapat | 118:60c5de4cb8ad | 304 | return type1_no; |
krishanprajapat | 118:60c5de4cb8ad | 305 | } |
shreeshas95 | 1:a0055b3280c8 | 306 | void inline transmit_data(unsigned char * transmit , bool * last_buffer){ |
shreeshas95 | 1:a0055b3280c8 | 307 | if(transmit_data_f){ |
shreeshas95 | 1:a0055b3280c8 | 308 | RB_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 309 | Sframe_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 310 | SCH40_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 311 | FCCH80_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 312 | Tframe_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 313 | EOS_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 314 | segment_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 315 | data_c = 0; |
ee12b079 | 9:e9eaada136c6 | 316 | |
shreeshas95 | 1:a0055b3280c8 | 317 | Sframe = true; |
shreeshas95 | 1:a0055b3280c8 | 318 | SCH40_f = false; |
shreeshas95 | 1:a0055b3280c8 | 319 | data_f = false; |
shreeshas95 | 1:a0055b3280c8 | 320 | FCCH80_f = false; |
shreeshas95 | 1:a0055b3280c8 | 321 | transmit_data_f = false; |
shreeshas95 | 1:a0055b3280c8 | 322 | reset_adf = false; |
shreeshas95 | 1:a0055b3280c8 | 323 | *last_buffer = false; |
shreeshas95 | 1:a0055b3280c8 | 324 | } |
ee12b079 | 9:e9eaada136c6 | 325 | |
shreeshas95 | 1:a0055b3280c8 | 326 | for(RB_c = 0 ; RB_c<112 ; RB_c++){ |
ee12b079 | 9:e9eaada136c6 | 327 | |
ee12b079 | 9:e9eaada136c6 | 328 | if(junk_f || *last_buffer){ |
ee12b079 | 9:e9eaada136c6 | 329 | transmit[RB_c] = 0x00; |
ee12b079 | 9:e9eaada136c6 | 330 | continue; |
shreeshas95 | 1:a0055b3280c8 | 331 | } |
ee12b079 | 9:e9eaada136c6 | 332 | |
shreeshas95 | 1:a0055b3280c8 | 333 | if(Sframe){ |
shreeshas95 | 1:a0055b3280c8 | 334 | transmit[RB_c] = S_frame[Sframe_c++]; |
shreeshas95 | 1:a0055b3280c8 | 335 | if(Sframe_c == 48){ |
shreeshas95 | 1:a0055b3280c8 | 336 | // printf("exit s frame\n"); |
shreeshas95 | 1:a0055b3280c8 | 337 | Sframe_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 338 | Sframe = false; |
shreeshas95 | 1:a0055b3280c8 | 339 | SCH40_f =true; |
shreeshas95 | 1:a0055b3280c8 | 340 | } |
shreeshas95 | 1:a0055b3280c8 | 341 | continue; |
shreeshas95 | 1:a0055b3280c8 | 342 | } |
ee12b079 | 9:e9eaada136c6 | 343 | // |
shreeshas95 | 1:a0055b3280c8 | 344 | if(SCH40_f){ |
ee12b079 | 9:e9eaada136c6 | 345 | transmit[RB_c] = SCH40[SCH40_c++]; |
shreeshas95 | 1:a0055b3280c8 | 346 | if(SCH40_c == 5 ){ |
shreeshas95 | 1:a0055b3280c8 | 347 | SCH40_c = 0; |
ee12b079 | 9:e9eaada136c6 | 348 | SCH40_f = false; |
ee12b079 | 9:e9eaada136c6 | 349 | |
ee12b079 | 9:e9eaada136c6 | 350 | |
ee12b079 | 9:e9eaada136c6 | 351 | if(Tframe_c >= LAST_SEGMENT_SIZE && segment_r == 0) |
ee12b079 | 9:e9eaada136c6 | 352 | { |
ee12b079 | 9:e9eaada136c6 | 353 | repeat_data_f = true; |
ee12b079 | 9:e9eaada136c6 | 354 | DS_index = !DS_index; |
ee12b079 | 9:e9eaada136c6 | 355 | } |
ee12b079 | 9:e9eaada136c6 | 356 | else |
ee12b079 | 9:e9eaada136c6 | 357 | { |
ee12b079 | 9:e9eaada136c6 | 358 | data_f = true; |
ee12b079 | 9:e9eaada136c6 | 359 | make_DataStream; |
ee12b079 | 9:e9eaada136c6 | 360 | } |
shreeshas95 | 1:a0055b3280c8 | 361 | // printf("exit SCH40 frame\n"); |
shreeshas95 | 1:a0055b3280c8 | 362 | } |
shreeshas95 | 1:a0055b3280c8 | 363 | continue; |
shreeshas95 | 1:a0055b3280c8 | 364 | } |
ee12b079 | 9:e9eaada136c6 | 365 | // |
shreeshas95 | 1:a0055b3280c8 | 366 | if(data_f){ |
shreeshas95 | 1:a0055b3280c8 | 367 | transmit[RB_c] = interleave_data[DS_index][data_c++]; |
shreeshas95 | 1:a0055b3280c8 | 368 | if(data_c == 144){ |
shreeshas95 | 1:a0055b3280c8 | 369 | data_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 370 | FCCH80_f = true; |
shreeshas95 | 1:a0055b3280c8 | 371 | data_f = false; |
shreeshas95 | 1:a0055b3280c8 | 372 | // printf("exit Data\n"); |
shreeshas95 | 1:a0055b3280c8 | 373 | } |
shreeshas95 | 1:a0055b3280c8 | 374 | continue; |
shreeshas95 | 1:a0055b3280c8 | 375 | } |
ee12b079 | 9:e9eaada136c6 | 376 | if(repeat_data_f){ |
ee12b079 | 9:e9eaada136c6 | 377 | transmit[RB_c] = interleave_data[DS_index][data_c++]; |
ee12b079 | 9:e9eaada136c6 | 378 | if(data_c == 144){ |
ee12b079 | 9:e9eaada136c6 | 379 | data_c = 0; |
ee12b079 | 9:e9eaada136c6 | 380 | FCCH80_f = true; |
ee12b079 | 9:e9eaada136c6 | 381 | repeat_data_f = false; |
ee12b079 | 9:e9eaada136c6 | 382 | // printf("exit Data\n"); |
ee12b079 | 9:e9eaada136c6 | 383 | } |
ee12b079 | 9:e9eaada136c6 | 384 | continue; |
ee12b079 | 9:e9eaada136c6 | 385 | } |
ee12b079 | 9:e9eaada136c6 | 386 | |
shreeshas95 | 1:a0055b3280c8 | 387 | if(FCCH80_f){ |
shreeshas95 | 1:a0055b3280c8 | 388 | transmit[RB_c] = FCCH80[FCCH80_c++]; |
shreeshas95 | 1:a0055b3280c8 | 389 | if(FCCH80_c == 10){ |
shreeshas95 | 1:a0055b3280c8 | 390 | FCCH80_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 391 | FCCH80_f = false; |
shreeshas95 | 1:a0055b3280c8 | 392 | // printf("exit FCCH80\n"); |
shreeshas95 | 1:a0055b3280c8 | 393 | if(++Tframe_c != ISR) |
ee12b079 | 9:e9eaada136c6 | 394 | SCH40_f = true; |
shreeshas95 | 1:a0055b3280c8 | 395 | else{ |
shreeshas95 | 1:a0055b3280c8 | 396 | Tframe_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 397 | segment_c++; |
aniruddhv | 52:0bd68655c651 | 398 | if(segment_c >= SEGMENT_NO - 1 && TOTAL_SEGMENT_NO == 0) segment_r = 0; else segment_r = 1; |
ee12b079 | 9:e9eaada136c6 | 399 | if(segment_c == SEGMENT_NO) |
shreeshas95 | 1:a0055b3280c8 | 400 | {eos_f = true;} |
shreeshas95 | 1:a0055b3280c8 | 401 | else{ |
shreeshas95 | 1:a0055b3280c8 | 402 | Sframe = true; |
shreeshas95 | 1:a0055b3280c8 | 403 | } |
shreeshas95 | 1:a0055b3280c8 | 404 | } |
shreeshas95 | 1:a0055b3280c8 | 405 | } |
shreeshas95 | 1:a0055b3280c8 | 406 | continue; |
ee12b079 | 9:e9eaada136c6 | 407 | } |
ee12b079 | 9:e9eaada136c6 | 408 | |
ee12b079 | 9:e9eaada136c6 | 409 | if(eos_f){ |
shreeshas95 | 1:a0055b3280c8 | 410 | transmit[RB_c] = EoS[EOS_c++]; |
shreeshas95 | 1:a0055b3280c8 | 411 | if(EOS_c == EOS_SIZE){ |
shreeshas95 | 1:a0055b3280c8 | 412 | EOS_c = 0; |
shreeshas95 | 1:a0055b3280c8 | 413 | eos_f = false; |
ee12b079 | 9:e9eaada136c6 | 414 | if(segment_c == SEGMENT_NO && segment_r == 0){ |
ee12b079 | 9:e9eaada136c6 | 415 | *last_buffer = true; |
ee12b079 | 9:e9eaada136c6 | 416 | } |
ee12b079 | 9:e9eaada136c6 | 417 | else if(segment_c == SEGMENT_NO && segment_r != 0){ |
ee12b079 | 9:e9eaada136c6 | 418 | segment_c = 0; |
ee12b079 | 9:e9eaada136c6 | 419 | SEGMENT_NO = TOTAL_SEGMENT_NO; |
ee12b079 | 9:e9eaada136c6 | 420 | if(SEGMENT_NO > MAX_SEGMENT) |
ee12b079 | 9:e9eaada136c6 | 421 | { |
ee12b079 | 9:e9eaada136c6 | 422 | SEGMENT_NO = MAX_SEGMENT; |
ee12b079 | 9:e9eaada136c6 | 423 | } |
aniruddhv | 52:0bd68655c651 | 424 | if(SEGMENT_NO == 1) segment_r = 0; else segment_r = 1; |
ee12b079 | 9:e9eaada136c6 | 425 | TOTAL_SEGMENT_NO -= SEGMENT_NO; |
ee12b079 | 9:e9eaada136c6 | 426 | reset_adf = true;//what does this do?? |
ee12b079 | 9:e9eaada136c6 | 427 | Sframe = true; |
ee12b079 | 9:e9eaada136c6 | 428 | } |
shreeshas95 | 1:a0055b3280c8 | 429 | junk_f = true; |
shreeshas95 | 1:a0055b3280c8 | 430 | } |
shreeshas95 | 1:a0055b3280c8 | 431 | continue; |
ee12b079 | 9:e9eaada136c6 | 432 | } |
shreeshas95 | 1:a0055b3280c8 | 433 | } |
shreeshas95 | 1:a0055b3280c8 | 434 | differential_encode(transmit,112); |
shreeshas95 | 1:a0055b3280c8 | 435 | if(reset_adf == true){ |
shreeshas95 | 1:a0055b3280c8 | 436 | diff_prev = 0; |
shreeshas95 | 1:a0055b3280c8 | 437 | junk_f = false; |
shreeshas95 | 1:a0055b3280c8 | 438 | } |
ee12b079 | 9:e9eaada136c6 | 439 | |
shreeshas95 | 1:a0055b3280c8 | 440 | } |
ee12b079 | 9:e9eaada136c6 | 441 | |
shreeshas95 | 1:a0055b3280c8 | 442 | }; |
shreeshas95 | 1:a0055b3280c8 | 443 | SND_TM snd_tm; |