![](/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_functions.h@0:f016e9e8d48b, 2015-12-01 (annotated)
- Committer:
- shreeshas95
- Date:
- Tue Dec 01 10:56:10 2015 +0000
- Revision:
- 0:f016e9e8d48b
- Child:
- 1:a0055b3280c8
Working without COM_SND_TM
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shreeshas95 | 0:f016e9e8d48b | 1 | // ********************************** COMPRESSION ********************************** |
shreeshas95 | 0:f016e9e8d48b | 2 | int disk_write(const uint8_t *, uint64_t); |
shreeshas95 | 0:f016e9e8d48b | 3 | uint64_t RTC_TIME; //need to be changed to uint_64 |
shreeshas95 | 0:f016e9e8d48b | 4 | unsigned char SDcard_lastWritten[512] = {0}; |
shreeshas95 | 0:f016e9e8d48b | 5 | |
shreeshas95 | 0:f016e9e8d48b | 6 | namespace Science_TMframe { |
shreeshas95 | 0:f016e9e8d48b | 7 | |
shreeshas95 | 0:f016e9e8d48b | 8 | #define OUTLENGTH 360 //length of the output frame after convolution |
shreeshas95 | 0:f016e9e8d48b | 9 | #define SDcard_block 512 //block size of the sd card |
shreeshas95 | 0:f016e9e8d48b | 10 | |
shreeshas95 | 0:f016e9e8d48b | 11 | Convolution ConvObj; //object which stores the frame after convolution |
shreeshas95 | 0:f016e9e8d48b | 12 | bool fresh[3] = {true,true,true}; // True only for the first time |
shreeshas95 | 0:f016e9e8d48b | 13 | unsigned char frames[3][134] = {0}; // "frame" stores the address of the current frame...."first_frame_address" stores the address of the first node made. |
shreeshas95 | 0:f016e9e8d48b | 14 | unsigned int FCN[4] = {0}; //frame count number |
shreeshas95 | 0:f016e9e8d48b | 15 | unsigned int data_starting_point[3] = {8,5,10}; |
shreeshas95 | 0:f016e9e8d48b | 16 | unsigned int max_data[3] = {124,127,122}; //number of bytes in each frame excluding TMID,FCN,first_header_point,crc |
shreeshas95 | 0:f016e9e8d48b | 17 | unsigned char TM_convoluted_data[270] = {0}; //270 bytes is the size after convolution of 1072 bits |
shreeshas95 | 0:f016e9e8d48b | 18 | unsigned char complete_frame[SDcard_block] = {0}; |
shreeshas95 | 0:f016e9e8d48b | 19 | uint64_t SDC_address = 200; |
shreeshas95 | 0:f016e9e8d48b | 20 | bool SCH_FCCH_FLAG = true; |
shreeshas95 | 0:f016e9e8d48b | 21 | |
shreeshas95 | 0:f016e9e8d48b | 22 | |
shreeshas95 | 0:f016e9e8d48b | 23 | void add_SCH_FCCH(){ |
shreeshas95 | 0:f016e9e8d48b | 24 | int i = 0; |
shreeshas95 | 0:f016e9e8d48b | 25 | complete_frame[0] = 0x0a; |
shreeshas95 | 0:f016e9e8d48b | 26 | complete_frame[1] = 0x3f;; |
shreeshas95 | 0:f016e9e8d48b | 27 | complete_frame[2] = 0x46; |
shreeshas95 | 0:f016e9e8d48b | 28 | complete_frame[3] = 0xb4; |
shreeshas95 | 0:f016e9e8d48b | 29 | complete_frame[4] = 0x00; |
shreeshas95 | 0:f016e9e8d48b | 30 | |
shreeshas95 | 0:f016e9e8d48b | 31 | for(i = 149 ; i < 159 ; i ++){ |
shreeshas95 | 0:f016e9e8d48b | 32 | complete_frame[i] = 0 ; |
shreeshas95 | 0:f016e9e8d48b | 33 | } |
shreeshas95 | 0:f016e9e8d48b | 34 | |
shreeshas95 | 0:f016e9e8d48b | 35 | complete_frame[159] = 0x0a; |
shreeshas95 | 0:f016e9e8d48b | 36 | complete_frame[160] = 0x3f;; |
shreeshas95 | 0:f016e9e8d48b | 37 | complete_frame[161] = 0x46; |
shreeshas95 | 0:f016e9e8d48b | 38 | complete_frame[162] = 0xb4; |
shreeshas95 | 0:f016e9e8d48b | 39 | complete_frame[163] = 0x00; |
shreeshas95 | 0:f016e9e8d48b | 40 | |
shreeshas95 | 0:f016e9e8d48b | 41 | for(i = 308 ; i < 318 ; i ++){ |
shreeshas95 | 0:f016e9e8d48b | 42 | complete_frame[i] = 0 ; |
shreeshas95 | 0:f016e9e8d48b | 43 | } |
shreeshas95 | 0:f016e9e8d48b | 44 | |
shreeshas95 | 0:f016e9e8d48b | 45 | } |
shreeshas95 | 0:f016e9e8d48b | 46 | |
shreeshas95 | 0:f016e9e8d48b | 47 | void making_frameHeader(unsigned char TMID){ |
shreeshas95 | 0:f016e9e8d48b | 48 | |
shreeshas95 | 0:f016e9e8d48b | 49 | unsigned char frame_type_identifier = 0; // not conform about the values , yet to be done |
shreeshas95 | 0:f016e9e8d48b | 50 | frames[TMID][0] = (frame_type_identifier<<7) + ( (TMID + 1)<<3 ) + ( (FCN[TMID]>>24) & 0x7 ); //frame number should be less than 2^23 since 23 bits are assigned for that |
shreeshas95 | 0:f016e9e8d48b | 51 | frames[TMID][1] = ((FCN[TMID]>>16) & 0xff ); |
shreeshas95 | 0:f016e9e8d48b | 52 | frames[TMID][2] = ( (FCN[TMID]>>8 )& 0xff ); |
shreeshas95 | 0:f016e9e8d48b | 53 | frames[TMID][3] = ( FCN[TMID] & 0xff ); // first bit for (frame identifier), next 4 for (TMID) and next 27 for FCN |
shreeshas95 | 0:f016e9e8d48b | 54 | |
shreeshas95 | 0:f016e9e8d48b | 55 | if(TMID == 0){ |
shreeshas95 | 0:f016e9e8d48b | 56 | frames[TMID][5] =( (RTC_TIME>>29) & 0xff ); |
shreeshas95 | 0:f016e9e8d48b | 57 | frames[TMID][6] =( (RTC_TIME>>21) & 0xff ); |
shreeshas95 | 0:f016e9e8d48b | 58 | frames[TMID][7] =( (RTC_TIME>>13) & 0xff ); |
shreeshas95 | 0:f016e9e8d48b | 59 | |
shreeshas95 | 0:f016e9e8d48b | 60 | }else if(TMID == 2){ |
shreeshas95 | 0:f016e9e8d48b | 61 | frames[TMID][5] =( (RTC_TIME>>32) & 0xff ); |
shreeshas95 | 0:f016e9e8d48b | 62 | frames[TMID][6] =( (RTC_TIME>>24) & 0xff ); |
shreeshas95 | 0:f016e9e8d48b | 63 | frames[TMID][7] =( (RTC_TIME>>16) & 0xff ); |
shreeshas95 | 0:f016e9e8d48b | 64 | frames[TMID][8] =( (RTC_TIME>>8 ) & 0xff ); |
shreeshas95 | 0:f016e9e8d48b | 65 | frames[TMID][9] =( (RTC_TIME ) & 0xff ); |
shreeshas95 | 0:f016e9e8d48b | 66 | } |
shreeshas95 | 0:f016e9e8d48b | 67 | |
shreeshas95 | 0:f016e9e8d48b | 68 | } |
shreeshas95 | 0:f016e9e8d48b | 69 | |
shreeshas95 | 0:f016e9e8d48b | 70 | void convolution (unsigned char * ptr){ |
shreeshas95 | 0:f016e9e8d48b | 71 | |
shreeshas95 | 0:f016e9e8d48b | 72 | ConvObj.convolutionEncode(ptr , TM_convoluted_data); |
shreeshas95 | 0:f016e9e8d48b | 73 | ConvObj.convolutionEncode(ptr + 67, TM_convoluted_data + 135); |
shreeshas95 | 0:f016e9e8d48b | 74 | |
shreeshas95 | 0:f016e9e8d48b | 75 | } |
shreeshas95 | 0:f016e9e8d48b | 76 | |
shreeshas95 | 0:f016e9e8d48b | 77 | /* |
shreeshas95 | 0:f016e9e8d48b | 78 | @brief : take the address of array of LCR or HCR and stores it into a frame |
shreeshas95 | 0:f016e9e8d48b | 79 | @parameters: type->L or H , deprnding on wheather it is LCR or HCR respectively |
shreeshas95 | 0:f016e9e8d48b | 80 | @return: nothing |
shreeshas95 | 0:f016e9e8d48b | 81 | */ |
shreeshas95 | 0:f016e9e8d48b | 82 | |
shreeshas95 | 0:f016e9e8d48b | 83 | // type 2 yet to be done |
shreeshas95 | 0:f016e9e8d48b | 84 | void making_frame(unsigned char TMID ,unsigned char type, unsigned char* pointer){ |
shreeshas95 | 0:f016e9e8d48b | 85 | |
shreeshas95 | 0:f016e9e8d48b | 86 | TMID--; //TMID goes from 1 to 3 , convinient to ue from 0 to 2 |
shreeshas95 | 0:f016e9e8d48b | 87 | static int frame_space_number[3] = {0}; //this variable represents the register number of the frame in which LCR or HCR data to be written not including header |
shreeshas95 | 0:f016e9e8d48b | 88 | int packet_len = 0; |
shreeshas95 | 0:f016e9e8d48b | 89 | int copy_count = 0 ; |
shreeshas95 | 0:f016e9e8d48b | 90 | |
shreeshas95 | 0:f016e9e8d48b | 91 | switch(int(TMID)){ |
shreeshas95 | 0:f016e9e8d48b | 92 | case 0: //SCP |
shreeshas95 | 0:f016e9e8d48b | 93 | if(type == 'L'){ //below threshold |
shreeshas95 | 0:f016e9e8d48b | 94 | packet_len = 22; |
shreeshas95 | 0:f016e9e8d48b | 95 | } |
shreeshas95 | 0:f016e9e8d48b | 96 | else if(type == 'H'){ //above threshold |
shreeshas95 | 0:f016e9e8d48b | 97 | packet_len = 26; |
shreeshas95 | 0:f016e9e8d48b | 98 | } |
shreeshas95 | 0:f016e9e8d48b | 99 | break; |
shreeshas95 | 0:f016e9e8d48b | 100 | |
shreeshas95 | 0:f016e9e8d48b | 101 | case 1: //SFP above threshold |
shreeshas95 | 0:f016e9e8d48b | 102 | packet_len = 35; |
shreeshas95 | 0:f016e9e8d48b | 103 | break; |
shreeshas95 | 0:f016e9e8d48b | 104 | |
shreeshas95 | 0:f016e9e8d48b | 105 | case 2: //SFP below threshold |
shreeshas95 | 0:f016e9e8d48b | 106 | packet_len = 23; |
shreeshas95 | 0:f016e9e8d48b | 107 | break; |
shreeshas95 | 0:f016e9e8d48b | 108 | } |
shreeshas95 | 0:f016e9e8d48b | 109 | |
shreeshas95 | 0:f016e9e8d48b | 110 | if(SCH_FCCH_FLAG){ |
shreeshas95 | 0:f016e9e8d48b | 111 | add_SCH_FCCH(); |
shreeshas95 | 0:f016e9e8d48b | 112 | SCH_FCCH_FLAG = false; |
shreeshas95 | 0:f016e9e8d48b | 113 | } |
shreeshas95 | 0:f016e9e8d48b | 114 | |
shreeshas95 | 0:f016e9e8d48b | 115 | if(fresh[TMID]){ |
shreeshas95 | 0:f016e9e8d48b | 116 | //welcome to first frame |
shreeshas95 | 0:f016e9e8d48b | 117 | making_frameHeader(TMID); |
shreeshas95 | 0:f016e9e8d48b | 118 | frames[TMID][4] = 0; |
shreeshas95 | 0:f016e9e8d48b | 119 | fresh[TMID] = false; |
shreeshas95 | 0:f016e9e8d48b | 120 | } |
shreeshas95 | 0:f016e9e8d48b | 121 | |
shreeshas95 | 0:f016e9e8d48b | 122 | |
shreeshas95 | 0:f016e9e8d48b | 123 | while(copy_count < packet_len){ // 22 bytes is the size of the LCR |
shreeshas95 | 0:f016e9e8d48b | 124 | frames[TMID][ frame_space_number[TMID] + data_starting_point[TMID] ]= *(pointer + copy_count); |
shreeshas95 | 0:f016e9e8d48b | 125 | frame_space_number[TMID]++; |
shreeshas95 | 0:f016e9e8d48b | 126 | copy_count++; |
shreeshas95 | 0:f016e9e8d48b | 127 | if( frame_space_number[TMID] == max_data[TMID] ){ //frame space number can go from 0 to 126 as data is written from 0+5 to 126+5 |
shreeshas95 | 0:f016e9e8d48b | 128 | FCN[TMID]++; |
shreeshas95 | 0:f016e9e8d48b | 129 | // convolution and save frame in the sd card |
shreeshas95 | 0:f016e9e8d48b | 130 | |
shreeshas95 | 0:f016e9e8d48b | 131 | // copying crc in 132 and 133 |
shreeshas95 | 0:f016e9e8d48b | 132 | int temp_crc; |
shreeshas95 | 0:f016e9e8d48b | 133 | temp_crc = CRC::crc16_gen(frames[TMID],132); |
shreeshas95 | 0:f016e9e8d48b | 134 | frames[TMID][132] = temp_crc>>8; |
shreeshas95 | 0:f016e9e8d48b | 135 | frames[TMID][133] = temp_crc & 0xff; |
shreeshas95 | 0:f016e9e8d48b | 136 | // xor |
shreeshas95 | 0:f016e9e8d48b | 137 | for(int j = 0 ; j < 134 ; j++){ |
shreeshas95 | 0:f016e9e8d48b | 138 | // frames[TMID][j] = frames[TMID][j]^exorThisWithTMFrame[j]; |
shreeshas95 | 0:f016e9e8d48b | 139 | } |
shreeshas95 | 0:f016e9e8d48b | 140 | //convolution and interleaving |
shreeshas95 | 0:f016e9e8d48b | 141 | convolution(frames[TMID]); |
shreeshas95 | 0:f016e9e8d48b | 142 | interleave(TM_convoluted_data , complete_frame + 5); |
shreeshas95 | 0:f016e9e8d48b | 143 | interleave(TM_convoluted_data+ 135,complete_frame + 164); |
shreeshas95 | 0:f016e9e8d48b | 144 | |
shreeshas95 | 0:f016e9e8d48b | 145 | // writing the SDC_address in a buffer , to store it in SDcard at address 5 |
shreeshas95 | 0:f016e9e8d48b | 146 | SDcard_lastWritten[0] = SDC_address>>56; |
shreeshas95 | 0:f016e9e8d48b | 147 | SDcard_lastWritten[1] = (SDC_address>>48)&0xFF; |
shreeshas95 | 0:f016e9e8d48b | 148 | SDcard_lastWritten[2] = (SDC_address>>40)&0xFF; |
shreeshas95 | 0:f016e9e8d48b | 149 | SDcard_lastWritten[3] = (SDC_address>>32)&0xFF; |
shreeshas95 | 0:f016e9e8d48b | 150 | SDcard_lastWritten[4] = (SDC_address>>24)&0xFF; |
shreeshas95 | 0:f016e9e8d48b | 151 | SDcard_lastWritten[5] = (SDC_address>>16)&0xFF; |
shreeshas95 | 0:f016e9e8d48b | 152 | SDcard_lastWritten[6] = (SDC_address>>8)&0xFF; |
shreeshas95 | 0:f016e9e8d48b | 153 | SDcard_lastWritten[7] = (SDC_address)&0xFF; |
shreeshas95 | 0:f016e9e8d48b | 154 | |
shreeshas95 | 0:f016e9e8d48b | 155 | SPI_mutex.lock(); |
shreeshas95 | 0:f016e9e8d48b | 156 | disk_write(complete_frame , SDC_address); |
shreeshas95 | 0:f016e9e8d48b | 157 | SPI_mutex.unlock(); |
shreeshas95 | 0:f016e9e8d48b | 158 | SDC_address++; |
shreeshas95 | 0:f016e9e8d48b | 159 | |
shreeshas95 | 0:f016e9e8d48b | 160 | |
shreeshas95 | 0:f016e9e8d48b | 161 | |
shreeshas95 | 0:f016e9e8d48b | 162 | //now save to the sd card TM_convoluted_data |
shreeshas95 | 0:f016e9e8d48b | 163 | // std::bitset<8> b; |
shreeshas95 | 0:f016e9e8d48b | 164 | // printf("\nthis is frame %d\n",TMID); //for printing frame |
shreeshas95 | 0:f016e9e8d48b | 165 | // for(int j =0; j<134;j++){ |
shreeshas95 | 0:f016e9e8d48b | 166 | // printf(" %d",frames[TMID][j]); |
shreeshas95 | 0:f016e9e8d48b | 167 | //// b = frames[TMID][j]; |
shreeshas95 | 0:f016e9e8d48b | 168 | //// cout<<b; |
shreeshas95 | 0:f016e9e8d48b | 169 | // } |
shreeshas95 | 0:f016e9e8d48b | 170 | |
shreeshas95 | 0:f016e9e8d48b | 171 | frame_space_number[TMID] = 0; |
shreeshas95 | 0:f016e9e8d48b | 172 | making_frameHeader(TMID); |
shreeshas95 | 0:f016e9e8d48b | 173 | frames[TMID][4]=packet_len - copy_count; |
shreeshas95 | 0:f016e9e8d48b | 174 | //write time here also |
shreeshas95 | 0:f016e9e8d48b | 175 | continue; |
shreeshas95 | 0:f016e9e8d48b | 176 | } |
shreeshas95 | 0:f016e9e8d48b | 177 | } |
shreeshas95 | 0:f016e9e8d48b | 178 | |
shreeshas95 | 0:f016e9e8d48b | 179 | // printf("\nthis is frame %d\n",TMID); //for printing frame |
shreeshas95 | 0:f016e9e8d48b | 180 | // for(int j =0; j<134;j++){ |
shreeshas95 | 0:f016e9e8d48b | 181 | // printf(" %d",frames[TMID][j]); |
shreeshas95 | 0:f016e9e8d48b | 182 | // } |
shreeshas95 | 0:f016e9e8d48b | 183 | |
shreeshas95 | 0:f016e9e8d48b | 184 | } |
shreeshas95 | 0:f016e9e8d48b | 185 | |
shreeshas95 | 0:f016e9e8d48b | 186 | |
shreeshas95 | 0:f016e9e8d48b | 187 | } |
shreeshas95 | 0:f016e9e8d48b | 188 | |
shreeshas95 | 0:f016e9e8d48b | 189 | |
shreeshas95 | 0:f016e9e8d48b | 190 | |
shreeshas95 | 0:f016e9e8d48b | 191 | // *************************************************** COMPRESSION *************************************************** |
shreeshas95 | 0:f016e9e8d48b | 192 | |
shreeshas95 | 0:f016e9e8d48b | 193 | namespace Science_Data_Compression{ |
shreeshas95 | 0:f016e9e8d48b | 194 | |
shreeshas95 | 0:f016e9e8d48b | 195 | # define PACKET_SEQUENCE_COUNT 1 //1 byte |
shreeshas95 | 0:f016e9e8d48b | 196 | # define NUM_PROTON_BIN 17 //2 byte each |
shreeshas95 | 0:f016e9e8d48b | 197 | # define NUM_ELECTRON_BIN 14 //2 byte each |
shreeshas95 | 0:f016e9e8d48b | 198 | # define VETO 1 //2 byte |
shreeshas95 | 0:f016e9e8d48b | 199 | # define FASTCHAIN 2 //4 byte each |
shreeshas95 | 0:f016e9e8d48b | 200 | #define RAW_PACKET_LENGTH 73 //73 bytes |
shreeshas95 | 0:f016e9e8d48b | 201 | |
shreeshas95 | 0:f016e9e8d48b | 202 | // #define PACKET_SEQ_COUNT 1 |
shreeshas95 | 0:f016e9e8d48b | 203 | // #define PROTON_BIN_SIZE 2 |
shreeshas95 | 0:f016e9e8d48b | 204 | // #define ELECTRON_BIN_SIZE 2 |
shreeshas95 | 0:f016e9e8d48b | 205 | // #define VETO 2 |
shreeshas95 | 0:f016e9e8d48b | 206 | // #define FAST_CHAIN 4 |
shreeshas95 | 0:f016e9e8d48b | 207 | |
shreeshas95 | 0:f016e9e8d48b | 208 | |
shreeshas95 | 0:f016e9e8d48b | 209 | /* |
shreeshas95 | 0:f016e9e8d48b | 210 | @brief: read one uint16_t equivalent of first two chars from the stream. short int because 16 bits |
shreeshas95 | 0:f016e9e8d48b | 211 | @param: pointer to the start of the short int |
shreeshas95 | 0:f016e9e8d48b | 212 | @return: uint16_t |
shreeshas95 | 0:f016e9e8d48b | 213 | */ |
shreeshas95 | 0:f016e9e8d48b | 214 | |
shreeshas95 | 0:f016e9e8d48b | 215 | |
shreeshas95 | 0:f016e9e8d48b | 216 | unsigned int read_2byte(unsigned char* ptr){ |
shreeshas95 | 0:f016e9e8d48b | 217 | unsigned int output = (unsigned int) *(ptr+1); |
shreeshas95 | 0:f016e9e8d48b | 218 | output += ( (unsigned int)(*ptr) ) << 8; |
shreeshas95 | 0:f016e9e8d48b | 219 | return output; |
shreeshas95 | 0:f016e9e8d48b | 220 | } |
shreeshas95 | 0:f016e9e8d48b | 221 | |
shreeshas95 | 0:f016e9e8d48b | 222 | /* |
shreeshas95 | 0:f016e9e8d48b | 223 | @brief: read one int equivalent of first four chars from the stream. int because 32 bits |
shreeshas95 | 0:f016e9e8d48b | 224 | @param: pointer to the start of the short int |
shreeshas95 | 0:f016e9e8d48b | 225 | @return: unsigned int |
shreeshas95 | 0:f016e9e8d48b | 226 | */ |
shreeshas95 | 0:f016e9e8d48b | 227 | |
shreeshas95 | 0:f016e9e8d48b | 228 | unsigned int read_4byte(unsigned char* ptr){ |
shreeshas95 | 0:f016e9e8d48b | 229 | unsigned int output = (unsigned int) *(ptr+3); |
shreeshas95 | 0:f016e9e8d48b | 230 | output += (unsigned int)*(ptr+2)<<8; |
shreeshas95 | 0:f016e9e8d48b | 231 | output += (unsigned int)*(ptr+1)<<16; |
shreeshas95 | 0:f016e9e8d48b | 232 | output += (unsigned int)*(ptr)<<24; |
shreeshas95 | 0:f016e9e8d48b | 233 | return output; |
shreeshas95 | 0:f016e9e8d48b | 234 | } |
shreeshas95 | 0:f016e9e8d48b | 235 | |
shreeshas95 | 0:f016e9e8d48b | 236 | unsigned int SFP_thresholds[35]={0 ,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100,100};//threashold values |
shreeshas95 | 0:f016e9e8d48b | 237 | unsigned int SCP_thresholds[35]={0 ,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,0 ,0 ,0 }; |
shreeshas95 | 0:f016e9e8d48b | 238 | unsigned int SFP_bin[35]; |
shreeshas95 | 0:f016e9e8d48b | 239 | unsigned int SCP_bin[35]={0}; |
shreeshas95 | 0:f016e9e8d48b | 240 | unsigned char SFP_outputBT[23]; //BT = below threshold |
shreeshas95 | 0:f016e9e8d48b | 241 | unsigned char SFP_outputAT[35]; |
shreeshas95 | 0:f016e9e8d48b | 242 | unsigned char SCP_outputLCR[22]; |
shreeshas95 | 0:f016e9e8d48b | 243 | unsigned char SCP_outputHCR[26]; |
shreeshas95 | 0:f016e9e8d48b | 244 | |
shreeshas95 | 0:f016e9e8d48b | 245 | |
shreeshas95 | 0:f016e9e8d48b | 246 | //********************************************************************************************************************************************************************** |
shreeshas95 | 0:f016e9e8d48b | 247 | //lots of compression functions are listed below |
shreeshas95 | 0:f016e9e8d48b | 248 | |
shreeshas95 | 0:f016e9e8d48b | 249 | |
shreeshas95 | 0:f016e9e8d48b | 250 | unsigned char SFP_compress4_BT(unsigned int input){ //for veto |
shreeshas95 | 0:f016e9e8d48b | 251 | int de_4 = 0; |
shreeshas95 | 0:f016e9e8d48b | 252 | unsigned char output; |
shreeshas95 | 0:f016e9e8d48b | 253 | |
shreeshas95 | 0:f016e9e8d48b | 254 | if(input<= 3){ |
shreeshas95 | 0:f016e9e8d48b | 255 | // DE = 0; |
shreeshas95 | 0:f016e9e8d48b | 256 | output = 0x0; |
shreeshas95 | 0:f016e9e8d48b | 257 | de_4 = 0; |
shreeshas95 | 0:f016e9e8d48b | 258 | } |
shreeshas95 | 0:f016e9e8d48b | 259 | else if(input <= 12){ |
shreeshas95 | 0:f016e9e8d48b | 260 | // DE = 01; |
shreeshas95 | 0:f016e9e8d48b | 261 | output = 0x1; |
shreeshas95 | 0:f016e9e8d48b | 262 | de_4 = 2; |
shreeshas95 | 0:f016e9e8d48b | 263 | } |
shreeshas95 | 0:f016e9e8d48b | 264 | else if(input <= 48){ |
shreeshas95 | 0:f016e9e8d48b | 265 | // DE = 10 |
shreeshas95 | 0:f016e9e8d48b | 266 | output = 0x2; |
shreeshas95 | 0:f016e9e8d48b | 267 | de_4 = 4; |
shreeshas95 | 0:f016e9e8d48b | 268 | } |
shreeshas95 | 0:f016e9e8d48b | 269 | else { |
shreeshas95 | 0:f016e9e8d48b | 270 | // DE = 11 |
shreeshas95 | 0:f016e9e8d48b | 271 | output = 0x3; |
shreeshas95 | 0:f016e9e8d48b | 272 | de_4 = 6; |
shreeshas95 | 0:f016e9e8d48b | 273 | } |
shreeshas95 | 0:f016e9e8d48b | 274 | |
shreeshas95 | 0:f016e9e8d48b | 275 | unsigned short int temp = input >> de_4; |
shreeshas95 | 0:f016e9e8d48b | 276 | output += (temp ) << 2; |
shreeshas95 | 0:f016e9e8d48b | 277 | return output; |
shreeshas95 | 0:f016e9e8d48b | 278 | } |
shreeshas95 | 0:f016e9e8d48b | 279 | |
shreeshas95 | 0:f016e9e8d48b | 280 | |
shreeshas95 | 0:f016e9e8d48b | 281 | unsigned char SFP_compress5_BT(unsigned int input){ |
shreeshas95 | 0:f016e9e8d48b | 282 | int de_4 = 0; //number by which bin value need to be shifted |
shreeshas95 | 0:f016e9e8d48b | 283 | unsigned char output; |
shreeshas95 | 0:f016e9e8d48b | 284 | |
shreeshas95 | 0:f016e9e8d48b | 285 | if(input <= 15){ |
shreeshas95 | 0:f016e9e8d48b | 286 | // D = 0 [0] |
shreeshas95 | 0:f016e9e8d48b | 287 | output = 0x0; |
shreeshas95 | 0:f016e9e8d48b | 288 | de_4 = 0; |
shreeshas95 | 0:f016e9e8d48b | 289 | } |
shreeshas95 | 0:f016e9e8d48b | 290 | else if(input <= 60){ |
shreeshas95 | 0:f016e9e8d48b | 291 | // D = 1 |
shreeshas95 | 0:f016e9e8d48b | 292 | output = 0x1; |
shreeshas95 | 0:f016e9e8d48b | 293 | de_4 = 2; |
shreeshas95 | 0:f016e9e8d48b | 294 | } |
shreeshas95 | 0:f016e9e8d48b | 295 | |
shreeshas95 | 0:f016e9e8d48b | 296 | unsigned short int temp = input >> de_4; |
shreeshas95 | 0:f016e9e8d48b | 297 | output += (temp ) << 1; |
shreeshas95 | 0:f016e9e8d48b | 298 | |
shreeshas95 | 0:f016e9e8d48b | 299 | return output; |
shreeshas95 | 0:f016e9e8d48b | 300 | }; |
shreeshas95 | 0:f016e9e8d48b | 301 | |
shreeshas95 | 0:f016e9e8d48b | 302 | |
shreeshas95 | 0:f016e9e8d48b | 303 | unsigned char SFP_compress6_BT(unsigned int input){ |
shreeshas95 | 0:f016e9e8d48b | 304 | int de_4 = 0;; |
shreeshas95 | 0:f016e9e8d48b | 305 | unsigned char output; |
shreeshas95 | 0:f016e9e8d48b | 306 | |
shreeshas95 | 0:f016e9e8d48b | 307 | if(input <= 31){ |
shreeshas95 | 0:f016e9e8d48b | 308 | // E = 0 [0] |
shreeshas95 | 0:f016e9e8d48b | 309 | output = 0x0; |
shreeshas95 | 0:f016e9e8d48b | 310 | de_4 = 0; |
shreeshas95 | 0:f016e9e8d48b | 311 | } |
shreeshas95 | 0:f016e9e8d48b | 312 | else if(input <= 124){ |
shreeshas95 | 0:f016e9e8d48b | 313 | // E = 1 |
shreeshas95 | 0:f016e9e8d48b | 314 | output = 0x1; |
shreeshas95 | 0:f016e9e8d48b | 315 | de_4 = 2; |
shreeshas95 | 0:f016e9e8d48b | 316 | } |
shreeshas95 | 0:f016e9e8d48b | 317 | |
shreeshas95 | 0:f016e9e8d48b | 318 | |
shreeshas95 | 0:f016e9e8d48b | 319 | unsigned short int temp = input >> de_4; |
shreeshas95 | 0:f016e9e8d48b | 320 | output += (temp ) << 1; |
shreeshas95 | 0:f016e9e8d48b | 321 | |
shreeshas95 | 0:f016e9e8d48b | 322 | return output; |
shreeshas95 | 0:f016e9e8d48b | 323 | }; |
shreeshas95 | 0:f016e9e8d48b | 324 | |
shreeshas95 | 0:f016e9e8d48b | 325 | unsigned char SFP_compress7_AT(unsigned int input){ |
shreeshas95 | 0:f016e9e8d48b | 326 | int de_4 = 0; |
shreeshas95 | 0:f016e9e8d48b | 327 | unsigned char output; |
shreeshas95 | 0:f016e9e8d48b | 328 | |
shreeshas95 | 0:f016e9e8d48b | 329 | if(input <= 31){ |
shreeshas95 | 0:f016e9e8d48b | 330 | // DE = 00 [0] |
shreeshas95 | 0:f016e9e8d48b | 331 | output = 0x0; |
shreeshas95 | 0:f016e9e8d48b | 332 | de_4 = 0; |
shreeshas95 | 0:f016e9e8d48b | 333 | } |
shreeshas95 | 0:f016e9e8d48b | 334 | else if(input <= 124){ |
shreeshas95 | 0:f016e9e8d48b | 335 | // DE = 01 [1] |
shreeshas95 | 0:f016e9e8d48b | 336 | output = 0x1; |
shreeshas95 | 0:f016e9e8d48b | 337 | de_4 = 2; |
shreeshas95 | 0:f016e9e8d48b | 338 | } |
shreeshas95 | 0:f016e9e8d48b | 339 | |
shreeshas95 | 0:f016e9e8d48b | 340 | else if(input <= 496){ |
shreeshas95 | 0:f016e9e8d48b | 341 | // DE = 10 [2] |
shreeshas95 | 0:f016e9e8d48b | 342 | output = 0x2; |
shreeshas95 | 0:f016e9e8d48b | 343 | de_4 = 4; |
shreeshas95 | 0:f016e9e8d48b | 344 | } |
shreeshas95 | 0:f016e9e8d48b | 345 | |
shreeshas95 | 0:f016e9e8d48b | 346 | else if(input <= 1984){ |
shreeshas95 | 0:f016e9e8d48b | 347 | // DE = 11 [3] |
shreeshas95 | 0:f016e9e8d48b | 348 | output = 0x3; |
shreeshas95 | 0:f016e9e8d48b | 349 | de_4 = 6; |
shreeshas95 | 0:f016e9e8d48b | 350 | } |
shreeshas95 | 0:f016e9e8d48b | 351 | |
shreeshas95 | 0:f016e9e8d48b | 352 | unsigned short int temp = input >> de_4; |
shreeshas95 | 0:f016e9e8d48b | 353 | output += (temp ) << 2; |
shreeshas95 | 0:f016e9e8d48b | 354 | |
shreeshas95 | 0:f016e9e8d48b | 355 | return output; |
shreeshas95 | 0:f016e9e8d48b | 356 | |
shreeshas95 | 0:f016e9e8d48b | 357 | }; |
shreeshas95 | 0:f016e9e8d48b | 358 | |
shreeshas95 | 0:f016e9e8d48b | 359 | |
shreeshas95 | 0:f016e9e8d48b | 360 | unsigned char SFP_compress8_AT(unsigned int input){ |
shreeshas95 | 0:f016e9e8d48b | 361 | |
shreeshas95 | 0:f016e9e8d48b | 362 | int de_4 = 0;; |
shreeshas95 | 0:f016e9e8d48b | 363 | unsigned char output; |
shreeshas95 | 0:f016e9e8d48b | 364 | |
shreeshas95 | 0:f016e9e8d48b | 365 | if(input <= 63){ |
shreeshas95 | 0:f016e9e8d48b | 366 | // DE = 00 [0] |
shreeshas95 | 0:f016e9e8d48b | 367 | output = 0x0; |
shreeshas95 | 0:f016e9e8d48b | 368 | de_4 = 0; |
shreeshas95 | 0:f016e9e8d48b | 369 | } |
shreeshas95 | 0:f016e9e8d48b | 370 | else if(input <= 252){ |
shreeshas95 | 0:f016e9e8d48b | 371 | // DE = 01 [1] |
shreeshas95 | 0:f016e9e8d48b | 372 | output = 0x1; |
shreeshas95 | 0:f016e9e8d48b | 373 | de_4 = 2; |
shreeshas95 | 0:f016e9e8d48b | 374 | } |
shreeshas95 | 0:f016e9e8d48b | 375 | |
shreeshas95 | 0:f016e9e8d48b | 376 | else if(input <= 1008){ |
shreeshas95 | 0:f016e9e8d48b | 377 | // DE = 10 [2] |
shreeshas95 | 0:f016e9e8d48b | 378 | output = 0x2; |
shreeshas95 | 0:f016e9e8d48b | 379 | de_4 = 4; |
shreeshas95 | 0:f016e9e8d48b | 380 | } |
shreeshas95 | 0:f016e9e8d48b | 381 | |
shreeshas95 | 0:f016e9e8d48b | 382 | else { |
shreeshas95 | 0:f016e9e8d48b | 383 | // DE = 11 [3] |
shreeshas95 | 0:f016e9e8d48b | 384 | output = 0x3; |
shreeshas95 | 0:f016e9e8d48b | 385 | de_4 = 6; |
shreeshas95 | 0:f016e9e8d48b | 386 | } |
shreeshas95 | 0:f016e9e8d48b | 387 | |
shreeshas95 | 0:f016e9e8d48b | 388 | unsigned short int temp = input >> de_4; |
shreeshas95 | 0:f016e9e8d48b | 389 | output += (temp ) << 2; |
shreeshas95 | 0:f016e9e8d48b | 390 | |
shreeshas95 | 0:f016e9e8d48b | 391 | return output; |
shreeshas95 | 0:f016e9e8d48b | 392 | }; |
shreeshas95 | 0:f016e9e8d48b | 393 | |
shreeshas95 | 0:f016e9e8d48b | 394 | unsigned char SFP_compress5_AT(unsigned int input){ |
shreeshas95 | 0:f016e9e8d48b | 395 | int de_4 = 0;; |
shreeshas95 | 0:f016e9e8d48b | 396 | unsigned char output; |
shreeshas95 | 0:f016e9e8d48b | 397 | |
shreeshas95 | 0:f016e9e8d48b | 398 | if(input <= 3){ |
shreeshas95 | 0:f016e9e8d48b | 399 | // DE = 000 [0] |
shreeshas95 | 0:f016e9e8d48b | 400 | output = 0x0; |
shreeshas95 | 0:f016e9e8d48b | 401 | de_4 = 0; |
shreeshas95 | 0:f016e9e8d48b | 402 | } |
shreeshas95 | 0:f016e9e8d48b | 403 | else if(input <= 12){ |
shreeshas95 | 0:f016e9e8d48b | 404 | // DE = 001 [1] |
shreeshas95 | 0:f016e9e8d48b | 405 | output = 0x1; |
shreeshas95 | 0:f016e9e8d48b | 406 | de_4 = 2; |
shreeshas95 | 0:f016e9e8d48b | 407 | } |
shreeshas95 | 0:f016e9e8d48b | 408 | |
shreeshas95 | 0:f016e9e8d48b | 409 | else if(input <= 48){ |
shreeshas95 | 0:f016e9e8d48b | 410 | // DE = 010 [2] |
shreeshas95 | 0:f016e9e8d48b | 411 | output = 0x2; |
shreeshas95 | 0:f016e9e8d48b | 412 | de_4 = 4; |
shreeshas95 | 0:f016e9e8d48b | 413 | } |
shreeshas95 | 0:f016e9e8d48b | 414 | |
shreeshas95 | 0:f016e9e8d48b | 415 | else if(input <= 192) { |
shreeshas95 | 0:f016e9e8d48b | 416 | // DE = 011 [3] |
shreeshas95 | 0:f016e9e8d48b | 417 | output = 0x3; |
shreeshas95 | 0:f016e9e8d48b | 418 | de_4 = 6; |
shreeshas95 | 0:f016e9e8d48b | 419 | } |
shreeshas95 | 0:f016e9e8d48b | 420 | |
shreeshas95 | 0:f016e9e8d48b | 421 | else if(input <= 768) { |
shreeshas95 | 0:f016e9e8d48b | 422 | // DE = 100 [4] |
shreeshas95 | 0:f016e9e8d48b | 423 | output = 0x4; |
shreeshas95 | 0:f016e9e8d48b | 424 | de_4 = 8; |
shreeshas95 | 0:f016e9e8d48b | 425 | } |
shreeshas95 | 0:f016e9e8d48b | 426 | |
shreeshas95 | 0:f016e9e8d48b | 427 | else if(input <= 3072) { |
shreeshas95 | 0:f016e9e8d48b | 428 | // DE = 101 [5] |
shreeshas95 | 0:f016e9e8d48b | 429 | output = 0x5; |
shreeshas95 | 0:f016e9e8d48b | 430 | de_4 = 10; |
shreeshas95 | 0:f016e9e8d48b | 431 | } |
shreeshas95 | 0:f016e9e8d48b | 432 | |
shreeshas95 | 0:f016e9e8d48b | 433 | else if(input <= 12288) { |
shreeshas95 | 0:f016e9e8d48b | 434 | // DE = 110 [6] |
shreeshas95 | 0:f016e9e8d48b | 435 | output = 0x6; |
shreeshas95 | 0:f016e9e8d48b | 436 | de_4 = 12; |
shreeshas95 | 0:f016e9e8d48b | 437 | } |
shreeshas95 | 0:f016e9e8d48b | 438 | |
shreeshas95 | 0:f016e9e8d48b | 439 | else { |
shreeshas95 | 0:f016e9e8d48b | 440 | // DE = 111 [7] |
shreeshas95 | 0:f016e9e8d48b | 441 | output = 0x7; |
shreeshas95 | 0:f016e9e8d48b | 442 | de_4 = 14; |
shreeshas95 | 0:f016e9e8d48b | 443 | } |
shreeshas95 | 0:f016e9e8d48b | 444 | |
shreeshas95 | 0:f016e9e8d48b | 445 | unsigned short int temp = input >> de_4; |
shreeshas95 | 0:f016e9e8d48b | 446 | output += (temp ) << 3; |
shreeshas95 | 0:f016e9e8d48b | 447 | |
shreeshas95 | 0:f016e9e8d48b | 448 | return output; |
shreeshas95 | 0:f016e9e8d48b | 449 | } |
shreeshas95 | 0:f016e9e8d48b | 450 | |
shreeshas95 | 0:f016e9e8d48b | 451 | unsigned char SFP_compress7FC_AT(unsigned int input){ // for fast chain above threshold |
shreeshas95 | 0:f016e9e8d48b | 452 | int de_4 = 0;; |
shreeshas95 | 0:f016e9e8d48b | 453 | unsigned char output; |
shreeshas95 | 0:f016e9e8d48b | 454 | |
shreeshas95 | 0:f016e9e8d48b | 455 | if(input <= 15){ |
shreeshas95 | 0:f016e9e8d48b | 456 | // DE = 000 [0] |
shreeshas95 | 0:f016e9e8d48b | 457 | output = 0x0; |
shreeshas95 | 0:f016e9e8d48b | 458 | de_4 = 0; |
shreeshas95 | 0:f016e9e8d48b | 459 | } |
shreeshas95 | 0:f016e9e8d48b | 460 | else if(input <= 60){ |
shreeshas95 | 0:f016e9e8d48b | 461 | // DE = 001 [1] |
shreeshas95 | 0:f016e9e8d48b | 462 | output = 0x1; |
shreeshas95 | 0:f016e9e8d48b | 463 | de_4 = 2; |
shreeshas95 | 0:f016e9e8d48b | 464 | } |
shreeshas95 | 0:f016e9e8d48b | 465 | |
shreeshas95 | 0:f016e9e8d48b | 466 | else if(input <= 240){ |
shreeshas95 | 0:f016e9e8d48b | 467 | // DE = 010 [2] |
shreeshas95 | 0:f016e9e8d48b | 468 | output = 0x2; |
shreeshas95 | 0:f016e9e8d48b | 469 | de_4 = 4; |
shreeshas95 | 0:f016e9e8d48b | 470 | } |
shreeshas95 | 0:f016e9e8d48b | 471 | |
shreeshas95 | 0:f016e9e8d48b | 472 | else if(input <= 960) { |
shreeshas95 | 0:f016e9e8d48b | 473 | // DE = 011 [3] |
shreeshas95 | 0:f016e9e8d48b | 474 | output = 0x3; |
shreeshas95 | 0:f016e9e8d48b | 475 | de_4 = 6; |
shreeshas95 | 0:f016e9e8d48b | 476 | } |
shreeshas95 | 0:f016e9e8d48b | 477 | |
shreeshas95 | 0:f016e9e8d48b | 478 | else if(input <= 3840) { |
shreeshas95 | 0:f016e9e8d48b | 479 | // DE = 100 [4] |
shreeshas95 | 0:f016e9e8d48b | 480 | output = 0x4; |
shreeshas95 | 0:f016e9e8d48b | 481 | de_4 = 8; |
shreeshas95 | 0:f016e9e8d48b | 482 | } |
shreeshas95 | 0:f016e9e8d48b | 483 | |
shreeshas95 | 0:f016e9e8d48b | 484 | else if(input <= 15360) { |
shreeshas95 | 0:f016e9e8d48b | 485 | // DE = 101 [5] |
shreeshas95 | 0:f016e9e8d48b | 486 | output = 0x5; |
shreeshas95 | 0:f016e9e8d48b | 487 | de_4 = 10; |
shreeshas95 | 0:f016e9e8d48b | 488 | } |
shreeshas95 | 0:f016e9e8d48b | 489 | |
shreeshas95 | 0:f016e9e8d48b | 490 | else if(input <= 61440) { |
shreeshas95 | 0:f016e9e8d48b | 491 | // DE = 110 [6] |
shreeshas95 | 0:f016e9e8d48b | 492 | output = 0x6; |
shreeshas95 | 0:f016e9e8d48b | 493 | de_4 = 12; |
shreeshas95 | 0:f016e9e8d48b | 494 | } |
shreeshas95 | 0:f016e9e8d48b | 495 | |
shreeshas95 | 0:f016e9e8d48b | 496 | else { |
shreeshas95 | 0:f016e9e8d48b | 497 | // DE = 111 [7] |
shreeshas95 | 0:f016e9e8d48b | 498 | output = 0x7; |
shreeshas95 | 0:f016e9e8d48b | 499 | de_4 = 14; |
shreeshas95 | 0:f016e9e8d48b | 500 | } |
shreeshas95 | 0:f016e9e8d48b | 501 | |
shreeshas95 | 0:f016e9e8d48b | 502 | unsigned short int temp = input >> de_4; |
shreeshas95 | 0:f016e9e8d48b | 503 | output += (temp ) << 3; |
shreeshas95 | 0:f016e9e8d48b | 504 | |
shreeshas95 | 0:f016e9e8d48b | 505 | return output; |
shreeshas95 | 0:f016e9e8d48b | 506 | } |
shreeshas95 | 0:f016e9e8d48b | 507 | |
shreeshas95 | 0:f016e9e8d48b | 508 | |
shreeshas95 | 0:f016e9e8d48b | 509 | |
shreeshas95 | 0:f016e9e8d48b | 510 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
shreeshas95 | 0:f016e9e8d48b | 511 | unsigned char SCP_compress6(unsigned int input){ |
shreeshas95 | 0:f016e9e8d48b | 512 | int ef_4; |
shreeshas95 | 0:f016e9e8d48b | 513 | unsigned char output; |
shreeshas95 | 0:f016e9e8d48b | 514 | |
shreeshas95 | 0:f016e9e8d48b | 515 | if(input <= 15){ |
shreeshas95 | 0:f016e9e8d48b | 516 | // EF = 00 |
shreeshas95 | 0:f016e9e8d48b | 517 | output = 0x0; |
shreeshas95 | 0:f016e9e8d48b | 518 | ef_4 = 0; |
shreeshas95 | 0:f016e9e8d48b | 519 | } |
shreeshas95 | 0:f016e9e8d48b | 520 | |
shreeshas95 | 0:f016e9e8d48b | 521 | else if(input <= 60 ){ |
shreeshas95 | 0:f016e9e8d48b | 522 | // EF = 01 [1] |
shreeshas95 | 0:f016e9e8d48b | 523 | output = 0x01; |
shreeshas95 | 0:f016e9e8d48b | 524 | ef_4 = 2; |
shreeshas95 | 0:f016e9e8d48b | 525 | } |
shreeshas95 | 0:f016e9e8d48b | 526 | else if(input <= 240){ |
shreeshas95 | 0:f016e9e8d48b | 527 | // EF = 10 [2] |
shreeshas95 | 0:f016e9e8d48b | 528 | output = 0x02; |
shreeshas95 | 0:f016e9e8d48b | 529 | ef_4 = 4; |
shreeshas95 | 0:f016e9e8d48b | 530 | } |
shreeshas95 | 0:f016e9e8d48b | 531 | else{ |
shreeshas95 | 0:f016e9e8d48b | 532 | // EF = 11 [3] |
shreeshas95 | 0:f016e9e8d48b | 533 | output = 0x03; |
shreeshas95 | 0:f016e9e8d48b | 534 | ef_4 = 6; |
shreeshas95 | 0:f016e9e8d48b | 535 | } |
shreeshas95 | 0:f016e9e8d48b | 536 | |
shreeshas95 | 0:f016e9e8d48b | 537 | unsigned short int temp = input >> ef_4; |
shreeshas95 | 0:f016e9e8d48b | 538 | output += (temp & 0xf) << 2; |
shreeshas95 | 0:f016e9e8d48b | 539 | |
shreeshas95 | 0:f016e9e8d48b | 540 | return output; |
shreeshas95 | 0:f016e9e8d48b | 541 | } |
shreeshas95 | 0:f016e9e8d48b | 542 | |
shreeshas95 | 0:f016e9e8d48b | 543 | unsigned char SCP_compress5(unsigned int input){ |
shreeshas95 | 0:f016e9e8d48b | 544 | |
shreeshas95 | 0:f016e9e8d48b | 545 | int de_4 = 0;; |
shreeshas95 | 0:f016e9e8d48b | 546 | unsigned char output; |
shreeshas95 | 0:f016e9e8d48b | 547 | |
shreeshas95 | 0:f016e9e8d48b | 548 | if(input <= 7){ |
shreeshas95 | 0:f016e9e8d48b | 549 | // DE = 00 [0] |
shreeshas95 | 0:f016e9e8d48b | 550 | output = 0x0; |
shreeshas95 | 0:f016e9e8d48b | 551 | de_4 = 0; |
shreeshas95 | 0:f016e9e8d48b | 552 | } |
shreeshas95 | 0:f016e9e8d48b | 553 | |
shreeshas95 | 0:f016e9e8d48b | 554 | else if(input <= 28){ |
shreeshas95 | 0:f016e9e8d48b | 555 | // DE = 01 [1] |
shreeshas95 | 0:f016e9e8d48b | 556 | output = 0x01; |
shreeshas95 | 0:f016e9e8d48b | 557 | de_4 = 2; |
shreeshas95 | 0:f016e9e8d48b | 558 | } |
shreeshas95 | 0:f016e9e8d48b | 559 | else if(input <= 112){ |
shreeshas95 | 0:f016e9e8d48b | 560 | // DE = 10 [2] |
shreeshas95 | 0:f016e9e8d48b | 561 | output = 0x02; |
shreeshas95 | 0:f016e9e8d48b | 562 | de_4 = 4; |
shreeshas95 | 0:f016e9e8d48b | 563 | } |
shreeshas95 | 0:f016e9e8d48b | 564 | else{ |
shreeshas95 | 0:f016e9e8d48b | 565 | // DE = 11 [3] |
shreeshas95 | 0:f016e9e8d48b | 566 | output = 0x03; |
shreeshas95 | 0:f016e9e8d48b | 567 | de_4 = 6; |
shreeshas95 | 0:f016e9e8d48b | 568 | } |
shreeshas95 | 0:f016e9e8d48b | 569 | |
shreeshas95 | 0:f016e9e8d48b | 570 | unsigned short int temp = input >> de_4; |
shreeshas95 | 0:f016e9e8d48b | 571 | output += (temp & 0x7) << 2; |
shreeshas95 | 0:f016e9e8d48b | 572 | |
shreeshas95 | 0:f016e9e8d48b | 573 | return output; |
shreeshas95 | 0:f016e9e8d48b | 574 | } |
shreeshas95 | 0:f016e9e8d48b | 575 | |
shreeshas95 | 0:f016e9e8d48b | 576 | unsigned char SCP_compress6h(unsigned int input) { |
shreeshas95 | 0:f016e9e8d48b | 577 | |
shreeshas95 | 0:f016e9e8d48b | 578 | int ef_4; |
shreeshas95 | 0:f016e9e8d48b | 579 | unsigned char output; |
shreeshas95 | 0:f016e9e8d48b | 580 | |
shreeshas95 | 0:f016e9e8d48b | 581 | if(input <=7){ |
shreeshas95 | 0:f016e9e8d48b | 582 | // EF = 000 [0] |
shreeshas95 | 0:f016e9e8d48b | 583 | output = 0x00; |
shreeshas95 | 0:f016e9e8d48b | 584 | ef_4 = 0; |
shreeshas95 | 0:f016e9e8d48b | 585 | } |
shreeshas95 | 0:f016e9e8d48b | 586 | |
shreeshas95 | 0:f016e9e8d48b | 587 | else if(input <=28){ |
shreeshas95 | 0:f016e9e8d48b | 588 | // EF = 001 [1] |
shreeshas95 | 0:f016e9e8d48b | 589 | output = 0x01; |
shreeshas95 | 0:f016e9e8d48b | 590 | ef_4 = 2; |
shreeshas95 | 0:f016e9e8d48b | 591 | } |
shreeshas95 | 0:f016e9e8d48b | 592 | else if(input <= 112){ |
shreeshas95 | 0:f016e9e8d48b | 593 | |
shreeshas95 | 0:f016e9e8d48b | 594 | // EF = 010 [2] |
shreeshas95 | 0:f016e9e8d48b | 595 | output = 0x02; |
shreeshas95 | 0:f016e9e8d48b | 596 | ef_4 = 4; |
shreeshas95 | 0:f016e9e8d48b | 597 | } |
shreeshas95 | 0:f016e9e8d48b | 598 | else if(input <= 448){ |
shreeshas95 | 0:f016e9e8d48b | 599 | // EF = 011 [3] |
shreeshas95 | 0:f016e9e8d48b | 600 | output = 0x03; |
shreeshas95 | 0:f016e9e8d48b | 601 | ef_4 = 6; |
shreeshas95 | 0:f016e9e8d48b | 602 | } |
shreeshas95 | 0:f016e9e8d48b | 603 | else if(input <= 1792){ |
shreeshas95 | 0:f016e9e8d48b | 604 | // EF = 100 [4] |
shreeshas95 | 0:f016e9e8d48b | 605 | output = 0x04; |
shreeshas95 | 0:f016e9e8d48b | 606 | ef_4 = 8; |
shreeshas95 | 0:f016e9e8d48b | 607 | |
shreeshas95 | 0:f016e9e8d48b | 608 | } |
shreeshas95 | 0:f016e9e8d48b | 609 | else if(input <= 7168){ |
shreeshas95 | 0:f016e9e8d48b | 610 | // EF = 101 [5] |
shreeshas95 | 0:f016e9e8d48b | 611 | output = 0x05; |
shreeshas95 | 0:f016e9e8d48b | 612 | ef_4 = 10; |
shreeshas95 | 0:f016e9e8d48b | 613 | |
shreeshas95 | 0:f016e9e8d48b | 614 | } |
shreeshas95 | 0:f016e9e8d48b | 615 | else if(input <= 28672){ |
shreeshas95 | 0:f016e9e8d48b | 616 | // EF = 110 [6] |
shreeshas95 | 0:f016e9e8d48b | 617 | output = 0x06; |
shreeshas95 | 0:f016e9e8d48b | 618 | ef_4 = 12; |
shreeshas95 | 0:f016e9e8d48b | 619 | } |
shreeshas95 | 0:f016e9e8d48b | 620 | else{ |
shreeshas95 | 0:f016e9e8d48b | 621 | // EF = 111 [7] |
shreeshas95 | 0:f016e9e8d48b | 622 | output = 0x07; |
shreeshas95 | 0:f016e9e8d48b | 623 | ef_4 =14; |
shreeshas95 | 0:f016e9e8d48b | 624 | } |
shreeshas95 | 0:f016e9e8d48b | 625 | |
shreeshas95 | 0:f016e9e8d48b | 626 | unsigned short int temp = input >> ef_4; |
shreeshas95 | 0:f016e9e8d48b | 627 | output += (temp & 0x7) << 3; |
shreeshas95 | 0:f016e9e8d48b | 628 | |
shreeshas95 | 0:f016e9e8d48b | 629 | return output; |
shreeshas95 | 0:f016e9e8d48b | 630 | |
shreeshas95 | 0:f016e9e8d48b | 631 | } |
shreeshas95 | 0:f016e9e8d48b | 632 | |
shreeshas95 | 0:f016e9e8d48b | 633 | |
shreeshas95 | 0:f016e9e8d48b | 634 | unsigned char SCP_compress7h(unsigned int input) { |
shreeshas95 | 0:f016e9e8d48b | 635 | |
shreeshas95 | 0:f016e9e8d48b | 636 | int fg_4; |
shreeshas95 | 0:f016e9e8d48b | 637 | unsigned char output; |
shreeshas95 | 0:f016e9e8d48b | 638 | |
shreeshas95 | 0:f016e9e8d48b | 639 | if(input <= 15){ |
shreeshas95 | 0:f016e9e8d48b | 640 | // EF = 000 [0] |
shreeshas95 | 0:f016e9e8d48b | 641 | output = 0x0; |
shreeshas95 | 0:f016e9e8d48b | 642 | fg_4 = 0; |
shreeshas95 | 0:f016e9e8d48b | 643 | } |
shreeshas95 | 0:f016e9e8d48b | 644 | |
shreeshas95 | 0:f016e9e8d48b | 645 | else if(input <= 60){ |
shreeshas95 | 0:f016e9e8d48b | 646 | // EF = 001 [1] |
shreeshas95 | 0:f016e9e8d48b | 647 | output = 0x01; |
shreeshas95 | 0:f016e9e8d48b | 648 | fg_4 = 2; |
shreeshas95 | 0:f016e9e8d48b | 649 | } |
shreeshas95 | 0:f016e9e8d48b | 650 | else if(input <= 240){ |
shreeshas95 | 0:f016e9e8d48b | 651 | |
shreeshas95 | 0:f016e9e8d48b | 652 | // EF = 010 [2] |
shreeshas95 | 0:f016e9e8d48b | 653 | output = 0x02; |
shreeshas95 | 0:f016e9e8d48b | 654 | fg_4 = 4; |
shreeshas95 | 0:f016e9e8d48b | 655 | } |
shreeshas95 | 0:f016e9e8d48b | 656 | else if(input <= 960){ |
shreeshas95 | 0:f016e9e8d48b | 657 | // EF = 011 [3] |
shreeshas95 | 0:f016e9e8d48b | 658 | output = 0x03; |
shreeshas95 | 0:f016e9e8d48b | 659 | fg_4 = 6; |
shreeshas95 | 0:f016e9e8d48b | 660 | } |
shreeshas95 | 0:f016e9e8d48b | 661 | else if(input <= 3840){ |
shreeshas95 | 0:f016e9e8d48b | 662 | // EF = 100 [4] |
shreeshas95 | 0:f016e9e8d48b | 663 | output = 0x04; |
shreeshas95 | 0:f016e9e8d48b | 664 | fg_4 = 8; |
shreeshas95 | 0:f016e9e8d48b | 665 | |
shreeshas95 | 0:f016e9e8d48b | 666 | } |
shreeshas95 | 0:f016e9e8d48b | 667 | else if(input <= 15360){ |
shreeshas95 | 0:f016e9e8d48b | 668 | // EF = 101 [5] |
shreeshas95 | 0:f016e9e8d48b | 669 | output = 0x05; |
shreeshas95 | 0:f016e9e8d48b | 670 | fg_4 = 10; |
shreeshas95 | 0:f016e9e8d48b | 671 | |
shreeshas95 | 0:f016e9e8d48b | 672 | } |
shreeshas95 | 0:f016e9e8d48b | 673 | else if(input <= 61440){ |
shreeshas95 | 0:f016e9e8d48b | 674 | // EF = 110 [6] |
shreeshas95 | 0:f016e9e8d48b | 675 | output = 0x06; |
shreeshas95 | 0:f016e9e8d48b | 676 | fg_4 = 12; |
shreeshas95 | 0:f016e9e8d48b | 677 | } |
shreeshas95 | 0:f016e9e8d48b | 678 | else{ |
shreeshas95 | 0:f016e9e8d48b | 679 | // EF = 111 [7] |
shreeshas95 | 0:f016e9e8d48b | 680 | output = 0x07; |
shreeshas95 | 0:f016e9e8d48b | 681 | fg_4 =14; |
shreeshas95 | 0:f016e9e8d48b | 682 | } |
shreeshas95 | 0:f016e9e8d48b | 683 | |
shreeshas95 | 0:f016e9e8d48b | 684 | unsigned short int temp = input >> fg_4; |
shreeshas95 | 0:f016e9e8d48b | 685 | output += (temp & 0xf) << 3; |
shreeshas95 | 0:f016e9e8d48b | 686 | |
shreeshas95 | 0:f016e9e8d48b | 687 | return output; |
shreeshas95 | 0:f016e9e8d48b | 688 | |
shreeshas95 | 0:f016e9e8d48b | 689 | } |
shreeshas95 | 0:f016e9e8d48b | 690 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
shreeshas95 | 0:f016e9e8d48b | 691 | void SCP_compress_data(); |
shreeshas95 | 0:f016e9e8d48b | 692 | void SFP_compress_data(unsigned char* input){ |
shreeshas95 | 0:f016e9e8d48b | 693 | |
shreeshas95 | 0:f016e9e8d48b | 694 | bool LCR = true; |
shreeshas95 | 0:f016e9e8d48b | 695 | int i = 0; |
shreeshas95 | 0:f016e9e8d48b | 696 | static int packet_no = 0; //takes value from 0 to 29 |
shreeshas95 | 0:f016e9e8d48b | 697 | //TRAVERSE THE LIST TO DETERMINE LCR OR HCR and stroing the values in proton_bin and electron bin |
shreeshas95 | 0:f016e9e8d48b | 698 | SFP_bin[0] = *input; |
shreeshas95 | 0:f016e9e8d48b | 699 | for(i=1 ; i<= NUM_PROTON_BIN + NUM_ELECTRON_BIN + VETO ; ++i){ //storing the bin values into an array name bin |
shreeshas95 | 0:f016e9e8d48b | 700 | SFP_bin[i]=read_2byte(input+1+((i-1)<<1)); //proton bin and elecron bin are 2 byte, hence read_2byte and |
shreeshas95 | 0:f016e9e8d48b | 701 | SCP_bin[i]+=SFP_bin[i]; |
shreeshas95 | 0:f016e9e8d48b | 702 | if(SFP_bin[i] > SFP_thresholds[i]){ //fast cahin is 4 byte hence read_4byte |
shreeshas95 | 0:f016e9e8d48b | 703 | LCR = false; // if a single value is above threshold then lcr becomes false |
shreeshas95 | 0:f016e9e8d48b | 704 | i++; |
shreeshas95 | 0:f016e9e8d48b | 705 | break; |
shreeshas95 | 0:f016e9e8d48b | 706 | } |
shreeshas95 | 0:f016e9e8d48b | 707 | } |
shreeshas95 | 0:f016e9e8d48b | 708 | |
shreeshas95 | 0:f016e9e8d48b | 709 | for( ; i<= NUM_PROTON_BIN + NUM_ELECTRON_BIN + VETO ; ++i){ |
shreeshas95 | 0:f016e9e8d48b | 710 | SCP_bin[i]+=SFP_bin[i]; |
shreeshas95 | 0:f016e9e8d48b | 711 | SFP_bin[i] = read_2byte(input + 1 + ( (i-1)<<1) ); |
shreeshas95 | 0:f016e9e8d48b | 712 | } |
shreeshas95 | 0:f016e9e8d48b | 713 | |
shreeshas95 | 0:f016e9e8d48b | 714 | SFP_bin[i] = read_4byte(input+1+ ((i-1)<<1)) ; |
shreeshas95 | 0:f016e9e8d48b | 715 | SCP_bin[i]+=SFP_bin[i]; |
shreeshas95 | 0:f016e9e8d48b | 716 | |
shreeshas95 | 0:f016e9e8d48b | 717 | if(SFP_bin[i]>SFP_thresholds[i]) |
shreeshas95 | 0:f016e9e8d48b | 718 | LCR = false; //since veto starts from location (input + 65) and (input + 69) |
shreeshas95 | 0:f016e9e8d48b | 719 | |
shreeshas95 | 0:f016e9e8d48b | 720 | SFP_bin[i+1] = read_4byte(input+69); |
shreeshas95 | 0:f016e9e8d48b | 721 | SCP_bin[i]+=SFP_bin[i]; |
shreeshas95 | 0:f016e9e8d48b | 722 | |
shreeshas95 | 0:f016e9e8d48b | 723 | if(SFP_bin[i]>SFP_thresholds[i]) |
shreeshas95 | 0:f016e9e8d48b | 724 | LCR = false; |
shreeshas95 | 0:f016e9e8d48b | 725 | |
shreeshas95 | 0:f016e9e8d48b | 726 | |
shreeshas95 | 0:f016e9e8d48b | 727 | // printf("\n"); //for printing the sfp bin |
shreeshas95 | 0:f016e9e8d48b | 728 | // for (i=0;i<35;i++){ |
shreeshas95 | 0:f016e9e8d48b | 729 | // printf("sfp[%d] = %d",i,SFP_bin[i]); |
shreeshas95 | 0:f016e9e8d48b | 730 | // } |
shreeshas95 | 0:f016e9e8d48b | 731 | // printf("\n"); |
shreeshas95 | 0:f016e9e8d48b | 732 | |
shreeshas95 | 0:f016e9e8d48b | 733 | if(LCR){ |
shreeshas95 | 0:f016e9e8d48b | 734 | |
shreeshas95 | 0:f016e9e8d48b | 735 | SFP_outputBT[0] = (packet_no<<3) + ( SFP_compress5_BT(SFP_bin[1])>>2 ); |
shreeshas95 | 0:f016e9e8d48b | 736 | SFP_outputBT[1] = ( SFP_compress5_BT(SFP_bin[1])<<6 ) + ( SFP_compress5_BT(SFP_bin[2])<<1 ) + ( SFP_compress5_BT(SFP_bin[3])>>4 ); |
shreeshas95 | 0:f016e9e8d48b | 737 | SFP_outputBT[2] = ( SFP_compress5_BT(SFP_bin[3])<<4 ) + ( SFP_compress5_BT(SFP_bin[4])>>1 ); |
shreeshas95 | 0:f016e9e8d48b | 738 | SFP_outputBT[3] = ( SFP_compress5_BT(SFP_bin[4])<<7 ) + ( SFP_compress5_BT(SFP_bin[5])<<2 ) + ( SFP_compress5_BT(SFP_bin[6])>>3 ); |
shreeshas95 | 0:f016e9e8d48b | 739 | SFP_outputBT[4] = ( SFP_compress5_BT(SFP_bin[6])<<5 ) + ( SFP_compress5_BT(SFP_bin[7]) ); |
shreeshas95 | 0:f016e9e8d48b | 740 | SFP_outputBT[5] = ( SFP_compress5_BT(SFP_bin[8])<<3 ) + ( SFP_compress5_BT(SFP_bin[9])>>2 ); |
shreeshas95 | 0:f016e9e8d48b | 741 | SFP_outputBT[6] = ( SFP_compress5_BT(SFP_bin[9])<<6 ) + ( SFP_compress5_BT(SFP_bin[10])<<1 ) + ( SFP_compress5_BT(SFP_bin[11])>>4 ); |
shreeshas95 | 0:f016e9e8d48b | 742 | SFP_outputBT[7] = ( SFP_compress5_BT(SFP_bin[11])<<4 ) + ( SFP_compress5_BT(SFP_bin[12])>>1 ); |
shreeshas95 | 0:f016e9e8d48b | 743 | SFP_outputBT[8] = ( SFP_compress5_BT(SFP_bin[12])<<7 ) + ( SFP_compress5_BT(SFP_bin[13])<<2 ) + ( SFP_compress5_BT(SFP_bin[14])>>3 ); |
shreeshas95 | 0:f016e9e8d48b | 744 | SFP_outputBT[9] = ( SFP_compress5_BT(SFP_bin[14])<<5 ) + ( SFP_compress5_BT(SFP_bin[15]) ); |
shreeshas95 | 0:f016e9e8d48b | 745 | SFP_outputBT[10] = ( SFP_compress5_BT(SFP_bin[16])<<3 ) + ( SFP_compress5_BT(SFP_bin[17])>>2 ); |
shreeshas95 | 0:f016e9e8d48b | 746 | SFP_outputBT[11] = ( SFP_compress5_BT(SFP_bin[17])<<6 ) + ( SFP_compress6_BT(SFP_bin[18]) ); |
shreeshas95 | 0:f016e9e8d48b | 747 | SFP_outputBT[12] = ( SFP_compress6_BT(SFP_bin[19])<<2 ) + ( SFP_compress6_BT(SFP_bin[20])>>4 ); |
shreeshas95 | 0:f016e9e8d48b | 748 | SFP_outputBT[13] = ( SFP_compress6_BT(SFP_bin[20])<<4 ) + ( SFP_compress5_BT(SFP_bin[21])>>1 ); |
shreeshas95 | 0:f016e9e8d48b | 749 | SFP_outputBT[14] = ( SFP_compress5_BT(SFP_bin[21])<<7 ) + ( SFP_compress5_BT(SFP_bin[22])<<2 ) + ( SFP_compress5_BT(SFP_bin[23])>>3 ); |
shreeshas95 | 0:f016e9e8d48b | 750 | SFP_outputBT[15] = ( SFP_compress5_BT(SFP_bin[23])<<5 ) + ( SFP_compress5_BT(SFP_bin[24]) ); |
shreeshas95 | 0:f016e9e8d48b | 751 | SFP_outputBT[16] = ( SFP_compress5_BT(SFP_bin[25])<<3 ) + ( SFP_compress5_BT(SFP_bin[26])>>2 ); |
shreeshas95 | 0:f016e9e8d48b | 752 | SFP_outputBT[17] = ( SFP_compress5_BT(SFP_bin[26])<<6 ) + ( SFP_compress5_BT(SFP_bin[27])<<1 ) + ( SFP_compress5_BT(SFP_bin[28])>>4); |
shreeshas95 | 0:f016e9e8d48b | 753 | SFP_outputBT[18] = ( SFP_compress5_BT(SFP_bin[28])<<4 ) + ( SFP_compress5_BT(SFP_bin[29])>>1) ; |
shreeshas95 | 0:f016e9e8d48b | 754 | SFP_outputBT[19] = ( SFP_compress5_BT(SFP_bin[29])<<7 ) + ( SFP_compress5_BT(SFP_bin[30])<<2 ) + ( SFP_compress5_BT(SFP_bin[31])>>3) ; |
shreeshas95 | 0:f016e9e8d48b | 755 | SFP_outputBT[20] = ( SFP_compress5_BT(SFP_bin[31])<<5 ) + ( SFP_compress4_BT(SFP_bin[32])<<1) + ( SCP_compress5(SFP_bin[33])>>4 ) ; // |
shreeshas95 | 0:f016e9e8d48b | 756 | SFP_outputBT[21] = ( SCP_compress5(SFP_bin[33])<<4 ) + ( SCP_compress5(SFP_bin[34])>>1 ); //here intentionally SCP_compress is used instead of SCP_compress5 is different than SFP_compress5 |
shreeshas95 | 0:f016e9e8d48b | 757 | SFP_outputBT[22] = ( SCP_compress5(SFP_bin[34])<<7 ); //7 bits are spare |
shreeshas95 | 0:f016e9e8d48b | 758 | |
shreeshas95 | 0:f016e9e8d48b | 759 | Science_TMframe::making_frame(3,'L',SFP_outputBT); |
shreeshas95 | 0:f016e9e8d48b | 760 | if(++packet_no == 30){ |
shreeshas95 | 0:f016e9e8d48b | 761 | packet_no=0; |
shreeshas95 | 0:f016e9e8d48b | 762 | SCP_compress_data(); |
shreeshas95 | 0:f016e9e8d48b | 763 | for(i=0;i<PACKET_SEQUENCE_COUNT + NUM_PROTON_BIN + NUM_ELECTRON_BIN + VETO + FASTCHAIN;i++){ |
shreeshas95 | 0:f016e9e8d48b | 764 | if(packet_no==0){ |
shreeshas95 | 0:f016e9e8d48b | 765 | SCP_bin[i]=0; |
shreeshas95 | 0:f016e9e8d48b | 766 | } |
shreeshas95 | 0:f016e9e8d48b | 767 | } |
shreeshas95 | 0:f016e9e8d48b | 768 | } |
shreeshas95 | 0:f016e9e8d48b | 769 | |
shreeshas95 | 0:f016e9e8d48b | 770 | |
shreeshas95 | 0:f016e9e8d48b | 771 | } |
shreeshas95 | 0:f016e9e8d48b | 772 | |
shreeshas95 | 0:f016e9e8d48b | 773 | else { |
shreeshas95 | 0:f016e9e8d48b | 774 | |
shreeshas95 | 0:f016e9e8d48b | 775 | |
shreeshas95 | 0:f016e9e8d48b | 776 | SFP_outputAT[0] = (RTC_TIME>>27)&(0xff); |
shreeshas95 | 0:f016e9e8d48b | 777 | SFP_outputAT[1] = (RTC_TIME>>19)&(0xff); |
shreeshas95 | 0:f016e9e8d48b | 778 | SFP_outputAT[2] = (RTC_TIME>>11)&(0xff); |
shreeshas95 | 0:f016e9e8d48b | 779 | SFP_outputAT[3] = (RTC_TIME>>3 )&(0xff); |
shreeshas95 | 0:f016e9e8d48b | 780 | SFP_outputAT[4] = (RTC_TIME<<5 )&(0xff) + (packet_no); |
shreeshas95 | 0:f016e9e8d48b | 781 | SFP_outputAT[5] = ( SFP_compress7_AT(SFP_bin[1])<<1 ) + ( SFP_compress7_AT(SFP_bin[2])>>6 ); |
shreeshas95 | 0:f016e9e8d48b | 782 | SFP_outputAT[6] = ( SFP_compress7_AT(SFP_bin[2])<<2 ) + ( SFP_compress7_AT(SFP_bin[3])>>5 ); |
shreeshas95 | 0:f016e9e8d48b | 783 | SFP_outputAT[7] = ( SFP_compress7_AT(SFP_bin[3])<<3 ) + ( SFP_compress7_AT(SFP_bin[4])>>4 ); |
shreeshas95 | 0:f016e9e8d48b | 784 | SFP_outputAT[8] = ( SFP_compress7_AT(SFP_bin[4])<<4 ) + ( SFP_compress7_AT(SFP_bin[5])>>3 ); |
shreeshas95 | 0:f016e9e8d48b | 785 | SFP_outputAT[9] = ( SFP_compress7_AT(SFP_bin[5])<<5 ) + ( SFP_compress7_AT(SFP_bin[6])>>2 ); |
shreeshas95 | 0:f016e9e8d48b | 786 | SFP_outputAT[10] = ( SFP_compress7_AT(SFP_bin[6])<<6 ) + ( SFP_compress7_AT(SFP_bin[7])>>1 ); |
shreeshas95 | 0:f016e9e8d48b | 787 | SFP_outputAT[11] = ( SFP_compress7_AT(SFP_bin[7])<<7 ) + ( SFP_compress7_AT(SFP_bin[8]) ); |
shreeshas95 | 0:f016e9e8d48b | 788 | SFP_outputAT[12] = ( SFP_compress7_AT(SFP_bin[9])<<1 ) + ( SFP_compress7_AT(SFP_bin[10])>>6); |
shreeshas95 | 0:f016e9e8d48b | 789 | SFP_outputAT[13] = ( SFP_compress7_AT(SFP_bin[10])<<2 ) + ( SFP_compress7_AT(SFP_bin[11])>>5); |
shreeshas95 | 0:f016e9e8d48b | 790 | SFP_outputAT[14] = ( SFP_compress7_AT(SFP_bin[11])<<3 ) + ( SFP_compress7_AT(SFP_bin[12])>>4); |
shreeshas95 | 0:f016e9e8d48b | 791 | SFP_outputAT[15] = ( SFP_compress7_AT(SFP_bin[12])<<4 ) + ( SFP_compress7_AT(SFP_bin[13])>>3); |
shreeshas95 | 0:f016e9e8d48b | 792 | SFP_outputAT[16] = ( SFP_compress7_AT(SFP_bin[13])<<5 ) + ( SFP_compress7_AT(SFP_bin[14])>>2); |
shreeshas95 | 0:f016e9e8d48b | 793 | SFP_outputAT[17] = ( SFP_compress7_AT(SFP_bin[14])<<6 ) + ( SFP_compress7_AT(SFP_bin[15])>>1); |
shreeshas95 | 0:f016e9e8d48b | 794 | SFP_outputAT[18] = ( SFP_compress7_AT(SFP_bin[15])<<7 ) + ( SFP_compress7_AT(SFP_bin[16])); |
shreeshas95 | 0:f016e9e8d48b | 795 | SFP_outputAT[19] = ( SFP_compress7_AT(SFP_bin[17])<<1 ) + ( SFP_compress8_AT(SFP_bin[18])>>7 ); |
shreeshas95 | 0:f016e9e8d48b | 796 | SFP_outputAT[20] = ( SFP_compress8_AT(SFP_bin[18])<<1 ) + ( SFP_compress8_AT(SFP_bin[19])>>7 ); |
shreeshas95 | 0:f016e9e8d48b | 797 | SFP_outputAT[21] = ( SFP_compress8_AT(SFP_bin[19])<<1 ) + ( SFP_compress8_AT(SFP_bin[20])>>7 ); |
shreeshas95 | 0:f016e9e8d48b | 798 | SFP_outputAT[22] = ( SFP_compress8_AT(SFP_bin[20])<<1 ) + ( SFP_compress7_AT(SFP_bin[21])>>6 ); |
shreeshas95 | 0:f016e9e8d48b | 799 | SFP_outputAT[23] = ( SFP_compress7_AT(SFP_bin[21])<<2 ) + ( SFP_compress7_AT(SFP_bin[22])>>5 ); |
shreeshas95 | 0:f016e9e8d48b | 800 | SFP_outputAT[24] = ( SFP_compress7_AT(SFP_bin[22])<<3 ) + ( SFP_compress7_AT(SFP_bin[23])>>4 ); |
shreeshas95 | 0:f016e9e8d48b | 801 | SFP_outputAT[25] = ( SFP_compress7_AT(SFP_bin[23])<<4 ) + ( SFP_compress7_AT(SFP_bin[24])>>3 ); |
shreeshas95 | 0:f016e9e8d48b | 802 | SFP_outputAT[26] = ( SFP_compress7_AT(SFP_bin[24])<<5 ) + ( SFP_compress7_AT(SFP_bin[25])>>2 ); |
shreeshas95 | 0:f016e9e8d48b | 803 | SFP_outputAT[27] = ( SFP_compress7_AT(SFP_bin[25])<<6 ) + ( SFP_compress7_AT(SFP_bin[26])>>1 ); |
shreeshas95 | 0:f016e9e8d48b | 804 | SFP_outputAT[28] = ( SFP_compress7_AT(SFP_bin[26])<<7 ) + ( SFP_compress7_AT(SFP_bin[27]) ); |
shreeshas95 | 0:f016e9e8d48b | 805 | SFP_outputAT[29] = ( SFP_compress7_AT(SFP_bin[28])<<1 ) + ( SFP_compress7_AT(SFP_bin[29])>>6); |
shreeshas95 | 0:f016e9e8d48b | 806 | SFP_outputAT[30] = ( SFP_compress7_AT(SFP_bin[29])<<2 ) + ( SFP_compress7_AT(SFP_bin[30])>>5); |
shreeshas95 | 0:f016e9e8d48b | 807 | SFP_outputAT[31] = ( SFP_compress7_AT(SFP_bin[30])<<3 ) +( SFP_compress7_AT(SFP_bin[31])>>4); |
shreeshas95 | 0:f016e9e8d48b | 808 | SFP_outputAT[32] = ( SFP_compress7_AT(SFP_bin[31])<<4 ) +( SFP_compress5_AT(SFP_bin[32])>>1); |
shreeshas95 | 0:f016e9e8d48b | 809 | SFP_outputAT[33] = ( SFP_compress5_AT(SFP_bin[32])<<7 ) +( SFP_compress7FC_AT(SFP_bin[33])); |
shreeshas95 | 0:f016e9e8d48b | 810 | SFP_outputAT[34] = ( SFP_compress7FC_AT(SFP_bin[34])<<1 ); // 1 bit is spare |
shreeshas95 | 0:f016e9e8d48b | 811 | |
shreeshas95 | 0:f016e9e8d48b | 812 | Science_TMframe::making_frame(2,'H',SFP_outputAT); |
shreeshas95 | 0:f016e9e8d48b | 813 | if(++packet_no == 30){ |
shreeshas95 | 0:f016e9e8d48b | 814 | packet_no=0; |
shreeshas95 | 0:f016e9e8d48b | 815 | SCP_compress_data(); |
shreeshas95 | 0:f016e9e8d48b | 816 | for(i=0;i<PACKET_SEQUENCE_COUNT + NUM_PROTON_BIN + NUM_ELECTRON_BIN + VETO + FASTCHAIN;i++){ |
shreeshas95 | 0:f016e9e8d48b | 817 | if(packet_no==0){ |
shreeshas95 | 0:f016e9e8d48b | 818 | SCP_bin[i]=0; |
shreeshas95 | 0:f016e9e8d48b | 819 | } |
shreeshas95 | 0:f016e9e8d48b | 820 | } |
shreeshas95 | 0:f016e9e8d48b | 821 | } |
shreeshas95 | 0:f016e9e8d48b | 822 | |
shreeshas95 | 0:f016e9e8d48b | 823 | } |
shreeshas95 | 0:f016e9e8d48b | 824 | |
shreeshas95 | 0:f016e9e8d48b | 825 | } |
shreeshas95 | 0:f016e9e8d48b | 826 | |
shreeshas95 | 0:f016e9e8d48b | 827 | |
shreeshas95 | 0:f016e9e8d48b | 828 | /* |
shreeshas95 | 0:f016e9e8d48b | 829 | brief: takes the pointer of the raw data string and return the address of the array which stores the address of 30 packets. |
shreeshas95 | 0:f016e9e8d48b | 830 | input: pointer to the raw data. |
shreeshas95 | 0:f016e9e8d48b | 831 | output : void |
shreeshas95 | 0:f016e9e8d48b | 832 | */ |
shreeshas95 | 0:f016e9e8d48b | 833 | |
shreeshas95 | 0:f016e9e8d48b | 834 | void complete_compression(unsigned char *SRP,uint64_t x){ |
shreeshas95 | 0:f016e9e8d48b | 835 | RTC_TIME = x; |
shreeshas95 | 0:f016e9e8d48b | 836 | int i; //30 times because 3 second data |
shreeshas95 | 0:f016e9e8d48b | 837 | |
shreeshas95 | 0:f016e9e8d48b | 838 | for(i=0;i<30;i++){ |
shreeshas95 | 0:f016e9e8d48b | 839 | SFP_compress_data(SRP + 73*i); |
shreeshas95 | 0:f016e9e8d48b | 840 | } |
shreeshas95 | 0:f016e9e8d48b | 841 | |
shreeshas95 | 0:f016e9e8d48b | 842 | } |
shreeshas95 | 0:f016e9e8d48b | 843 | |
shreeshas95 | 0:f016e9e8d48b | 844 | |
shreeshas95 | 0:f016e9e8d48b | 845 | |
shreeshas95 | 0:f016e9e8d48b | 846 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
shreeshas95 | 0:f016e9e8d48b | 847 | |
shreeshas95 | 0:f016e9e8d48b | 848 | |
shreeshas95 | 0:f016e9e8d48b | 849 | |
shreeshas95 | 0:f016e9e8d48b | 850 | /* |
shreeshas95 | 0:f016e9e8d48b | 851 | @brief: compresses the given input stream and return output packet |
shreeshas95 | 0:f016e9e8d48b | 852 | @param: pointer to input stream. Input stream always has the fixed size of RAW_PACKET_LENGTH |
shreeshas95 | 0:f016e9e8d48b | 853 | @return: pointer to output stream. Output stream has the size of 22 or 26 bytes |
shreeshas95 | 0:f016e9e8d48b | 854 | */ |
shreeshas95 | 0:f016e9e8d48b | 855 | void SCP_compress_data(){ |
shreeshas95 | 0:f016e9e8d48b | 856 | |
shreeshas95 | 0:f016e9e8d48b | 857 | bool LCR = true; |
shreeshas95 | 0:f016e9e8d48b | 858 | int i = 0; |
shreeshas95 | 0:f016e9e8d48b | 859 | |
shreeshas95 | 0:f016e9e8d48b | 860 | for(i=1;i<=PACKET_SEQUENCE_COUNT + NUM_PROTON_BIN + NUM_ELECTRON_BIN + VETO + FASTCHAIN ;i++){ |
shreeshas95 | 0:f016e9e8d48b | 861 | if(SCP_bin[i]>SCP_thresholds[i]){ |
shreeshas95 | 0:f016e9e8d48b | 862 | LCR = false; |
shreeshas95 | 0:f016e9e8d48b | 863 | break; |
shreeshas95 | 0:f016e9e8d48b | 864 | } |
shreeshas95 | 0:f016e9e8d48b | 865 | } |
shreeshas95 | 0:f016e9e8d48b | 866 | // printf("\n"); //for printing the scp bin |
shreeshas95 | 0:f016e9e8d48b | 867 | // for (i=0;i<35;i++){ |
shreeshas95 | 0:f016e9e8d48b | 868 | // printf(" scp[%d] = %d ",i,SCP_bin[i]); |
shreeshas95 | 0:f016e9e8d48b | 869 | // } |
shreeshas95 | 0:f016e9e8d48b | 870 | // printf("\n"); |
shreeshas95 | 0:f016e9e8d48b | 871 | // compressing the data |
shreeshas95 | 0:f016e9e8d48b | 872 | if(LCR){ |
shreeshas95 | 0:f016e9e8d48b | 873 | SCP_outputLCR[0] = (RTC_TIME>>5)&(0xff); //first 13 bits for time tagging |
shreeshas95 | 0:f016e9e8d48b | 874 | SCP_outputLCR[1] = (RTC_TIME<<3)&(0xff); //then 4 bits for attitude tag |
shreeshas95 | 0:f016e9e8d48b | 875 | SCP_outputLCR[2] = 0x00; //only attitude tag is left |
shreeshas95 | 0:f016e9e8d48b | 876 | SCP_outputLCR[2] += ( SCP_compress5(SCP_bin[0])<<1 ) + ( SCP_compress5(SCP_bin[1])>>4 ); |
shreeshas95 | 0:f016e9e8d48b | 877 | SCP_outputLCR[3] = ( SCP_compress5(SCP_bin[1])<<4 ) + ( SCP_compress5(SCP_bin[2])>>1 ); |
shreeshas95 | 0:f016e9e8d48b | 878 | SCP_outputLCR[4] = ( SCP_compress5(SCP_bin[2])<<7 ) + ( SCP_compress5(SCP_bin[3])<<2 ) + ( SCP_compress5(SCP_bin[4])>>3 ); |
shreeshas95 | 0:f016e9e8d48b | 879 | SCP_outputLCR[5] = ( SCP_compress5(SCP_bin[4])<<5 ) + ( SCP_compress5(SCP_bin[5]) ); |
shreeshas95 | 0:f016e9e8d48b | 880 | SCP_outputLCR[6] = ( SCP_compress5(SCP_bin[6])<<3 ) + ( SCP_compress5(SCP_bin[7])>>2 ); |
shreeshas95 | 0:f016e9e8d48b | 881 | SCP_outputLCR[7] = ( SCP_compress5(SCP_bin[7])<<6 ) + ( SCP_compress5(SCP_bin[8])<<1 ) + ( SCP_compress5(SCP_bin[9])>>4 ); |
shreeshas95 | 0:f016e9e8d48b | 882 | SCP_outputLCR[8] = ( SCP_compress5(SCP_bin[9])<<4 ) + ( SCP_compress5(SCP_bin[10])>>1 ); |
shreeshas95 | 0:f016e9e8d48b | 883 | SCP_outputLCR[9] = ( SCP_compress5(SCP_bin[10])<<7 ) + ( SCP_compress5(SCP_bin[11])<<2) + ( SCP_compress5(SCP_bin[12])>>3 ); |
shreeshas95 | 0:f016e9e8d48b | 884 | SCP_outputLCR[10] = ( SCP_compress5(SCP_bin[12])<<5 ) + ( SCP_compress5(SCP_bin[13]) ); |
shreeshas95 | 0:f016e9e8d48b | 885 | SCP_outputLCR[11] = ( SCP_compress5(SCP_bin[14])<<3 ) + ( SCP_compress5(SCP_bin[15])>>2 ); |
shreeshas95 | 0:f016e9e8d48b | 886 | SCP_outputLCR[12] = ( SCP_compress5(SCP_bin[15])<<6 ) + ( SCP_compress5(SCP_bin[16])<<1) + ( SCP_compress6(SCP_bin[17])>>5 ); |
shreeshas95 | 0:f016e9e8d48b | 887 | SCP_outputLCR[13] = ( SCP_compress6(SCP_bin[17])<<3 ) + ( SCP_compress6(SCP_bin[18])>>3 ); |
shreeshas95 | 0:f016e9e8d48b | 888 | SCP_outputLCR[14] = ( SCP_compress5(SCP_bin[18])<<5 ) + ( SCP_compress6(SCP_bin[19])>>1 ); |
shreeshas95 | 0:f016e9e8d48b | 889 | SCP_outputLCR[15] = ( SCP_compress6(SCP_bin[19])<<7 ) + ( SCP_compress5(SCP_bin[20])<<2 ) + ( SCP_compress5(SCP_bin[21])>>3 ); |
shreeshas95 | 0:f016e9e8d48b | 890 | SCP_outputLCR[16] = ( SCP_compress5(SCP_bin[21])<<5 ) + ( SCP_compress5(SCP_bin[22]) ); |
shreeshas95 | 0:f016e9e8d48b | 891 | SCP_outputLCR[17] = ( SCP_compress5(SCP_bin[23])<<3 ) + ( SCP_compress5(SCP_bin[24])>>2 ); |
shreeshas95 | 0:f016e9e8d48b | 892 | SCP_outputLCR[18] = ( SCP_compress5(SCP_bin[24])<<6 ) + ( SCP_compress5(SCP_bin[25])<<1) + ( SCP_compress5(SCP_bin[26])>>4 ); |
shreeshas95 | 0:f016e9e8d48b | 893 | SCP_outputLCR[19] = ( SCP_compress5(SCP_bin[26])<<4 ) + ( SCP_compress5(SCP_bin[27])>>1 ); |
shreeshas95 | 0:f016e9e8d48b | 894 | SCP_outputLCR[20] = ( SCP_compress5(SCP_bin[27])<<7 ) + ( SCP_compress5(SCP_bin[28])<<2 ) + ( SCP_compress5(SCP_bin[29])>>3 ); |
shreeshas95 | 0:f016e9e8d48b | 895 | SCP_outputLCR[21] = ( SCP_compress5(SCP_bin[29])<<5 ) + ( SCP_compress5(SCP_bin[30]) ); |
shreeshas95 | 0:f016e9e8d48b | 896 | |
shreeshas95 | 0:f016e9e8d48b | 897 | Science_TMframe::making_frame(1,'L',SCP_outputLCR); |
shreeshas95 | 0:f016e9e8d48b | 898 | } |
shreeshas95 | 0:f016e9e8d48b | 899 | else{ |
shreeshas95 | 0:f016e9e8d48b | 900 | |
shreeshas95 | 0:f016e9e8d48b | 901 | SCP_outputLCR[0] = (RTC_TIME>>5)&(0xff); //first 13 bits for time tagging |
shreeshas95 | 0:f016e9e8d48b | 902 | SCP_outputLCR[1] = (RTC_TIME<<3)&(0xff); |
shreeshas95 | 0:f016e9e8d48b | 903 | SCP_outputHCR[2] = 0x40; |
shreeshas95 | 0:f016e9e8d48b | 904 | SCP_outputHCR[2] += ( SCP_compress6h(SCP_bin[0])<<6 ) ; |
shreeshas95 | 0:f016e9e8d48b | 905 | SCP_outputHCR[3] = ( SCP_compress6h(SCP_bin[1])<<2 ) + ( SCP_compress6h(SCP_bin[2])>>4) ; |
shreeshas95 | 0:f016e9e8d48b | 906 | SCP_outputHCR[4] = ( SCP_compress6h(SCP_bin[2])<<4 ) + ( SCP_compress6h(SCP_bin[3])>>2) ; |
shreeshas95 | 0:f016e9e8d48b | 907 | SCP_outputHCR[5] = ( SCP_compress6h(SCP_bin[3])<<6 ) + ( SCP_compress6h(SCP_bin[4])) ; |
shreeshas95 | 0:f016e9e8d48b | 908 | SCP_outputHCR[6] = ( SCP_compress6h(SCP_bin[5])<<2 ) + ( SCP_compress6h(SCP_bin[6])>>4) ; |
shreeshas95 | 0:f016e9e8d48b | 909 | SCP_outputHCR[7] = ( SCP_compress6h(SCP_bin[6])<<4 ) + ( SCP_compress6h(SCP_bin[7])>>2) ; |
shreeshas95 | 0:f016e9e8d48b | 910 | SCP_outputHCR[8] = ( SCP_compress6h(SCP_bin[7])<<6 ) + ( SCP_compress6h(SCP_bin[8])) ; |
shreeshas95 | 0:f016e9e8d48b | 911 | SCP_outputHCR[9] = ( SCP_compress6h(SCP_bin[9])<<2 ) + ( SCP_compress6h(SCP_bin[10])>>4) ; |
shreeshas95 | 0:f016e9e8d48b | 912 | SCP_outputHCR[10] = ( SCP_compress6h(SCP_bin[10])<<4 ) + ( SCP_compress6h(SCP_bin[11])>>2); |
shreeshas95 | 0:f016e9e8d48b | 913 | SCP_outputHCR[11] = ( SCP_compress6h(SCP_bin[11])<<6 ) + ( SCP_compress6h(SCP_bin[12])) ; |
shreeshas95 | 0:f016e9e8d48b | 914 | SCP_outputHCR[12] = ( SCP_compress6h(SCP_bin[13])<<2 ) + ( SCP_compress6h(SCP_bin[14])>>4) ; |
shreeshas95 | 0:f016e9e8d48b | 915 | SCP_outputHCR[13] = ( SCP_compress6h(SCP_bin[14])<<4 ) + ( SCP_compress6h(SCP_bin[15])>>2) ; |
shreeshas95 | 0:f016e9e8d48b | 916 | SCP_outputHCR[14] = ( SCP_compress6h(SCP_bin[15])<<6 ) + ( SCP_compress6h(SCP_bin[16])) ; |
shreeshas95 | 0:f016e9e8d48b | 917 | SCP_outputHCR[15] = ( SCP_compress7h(SCP_bin[17])<<1 ) + ( SCP_compress7h(SCP_bin[18])>>6) ; |
shreeshas95 | 0:f016e9e8d48b | 918 | SCP_outputHCR[16] = ( SCP_compress7h(SCP_bin[18])<<2 ) + ( SCP_compress7h(SCP_bin[19])>>5) ; |
shreeshas95 | 0:f016e9e8d48b | 919 | SCP_outputHCR[17] = ( SCP_compress7h(SCP_bin[19])<<3 ) + ( SCP_compress6h(SCP_bin[20])>>3) ; |
shreeshas95 | 0:f016e9e8d48b | 920 | SCP_outputHCR[18] = ( SCP_compress6h(SCP_bin[20])<<5 ) + ( SCP_compress6h(SCP_bin[21])>>1) ; |
shreeshas95 | 0:f016e9e8d48b | 921 | SCP_outputHCR[19] = ( SCP_compress6h(SCP_bin[21])<<7 ) + ( SCP_compress6h(SCP_bin[22])<<1) + ( SCP_compress6h(SCP_bin[23])>>5) ; |
shreeshas95 | 0:f016e9e8d48b | 922 | SCP_outputHCR[20] = ( SCP_compress6h(SCP_bin[23])<<3 ) + ( SCP_compress6h(SCP_bin[24])>>3) ; |
shreeshas95 | 0:f016e9e8d48b | 923 | SCP_outputHCR[21] = ( SCP_compress6h(SCP_bin[24])<<5 ) + ( SCP_compress6h(SCP_bin[25])>>1) ; |
shreeshas95 | 0:f016e9e8d48b | 924 | SCP_outputHCR[22] = ( SCP_compress6h(SCP_bin[25])<<7 ) + ( SCP_compress6h(SCP_bin[26])<<1) + ( SCP_compress6h(SCP_bin[27])>>5) ; |
shreeshas95 | 0:f016e9e8d48b | 925 | SCP_outputHCR[23] = ( SCP_compress6h(SCP_bin[27])<<3 ) + ( SCP_compress6h(SCP_bin[28])>>3) ; |
shreeshas95 | 0:f016e9e8d48b | 926 | SCP_outputHCR[24] = ( SCP_compress6h(SCP_bin[28])<<5 ) + ( SCP_compress6h(SCP_bin[29])>>1) ; |
shreeshas95 | 0:f016e9e8d48b | 927 | SCP_outputHCR[25] = ( SCP_compress6h(SCP_bin[29])<<7 ) + ( SCP_compress6h(SCP_bin[30])<<1) ; //last bit is empty |
shreeshas95 | 0:f016e9e8d48b | 928 | |
shreeshas95 | 0:f016e9e8d48b | 929 | /* for (i=0;i<26;i++){ |
shreeshas95 | 0:f016e9e8d48b | 930 | printf("\nscp[%d] = %d",i,SCP_outputHCR[i]); |
shreeshas95 | 0:f016e9e8d48b | 931 | }*/ |
shreeshas95 | 0:f016e9e8d48b | 932 | Science_TMframe::making_frame(1,'H',SCP_outputHCR); |
shreeshas95 | 0:f016e9e8d48b | 933 | } |
shreeshas95 | 0:f016e9e8d48b | 934 | } |
shreeshas95 | 0:f016e9e8d48b | 935 | |
shreeshas95 | 0:f016e9e8d48b | 936 | } |
shreeshas95 | 0:f016e9e8d48b | 937 | |
shreeshas95 | 0:f016e9e8d48b | 938 | |
shreeshas95 | 0:f016e9e8d48b | 939 | // ******************************************** INTERLEAVE ************************************** |
shreeshas95 | 0:f016e9e8d48b | 940 | void interleave( unsigned char *input, unsigned char *output ){ |
shreeshas95 | 0:f016e9e8d48b | 941 | |
shreeshas95 | 0:f016e9e8d48b | 942 | unsigned int outState = 0; |
shreeshas95 | 0:f016e9e8d48b | 943 | unsigned int outByte = 0; |
shreeshas95 | 0:f016e9e8d48b | 944 | |
shreeshas95 | 0:f016e9e8d48b | 945 | for( unsigned int i = 0 ; i < 36 ; ++i ){ |
shreeshas95 | 0:f016e9e8d48b | 946 | for(unsigned int j = 0 ; j < 30 ; ++j){ |
shreeshas95 | 0:f016e9e8d48b | 947 | unsigned int x = j*36+i; |
shreeshas95 | 0:f016e9e8d48b | 948 | unsigned char tempBit = ((input[x >> 3]) >> (7-(x % 8))) & 1; |
shreeshas95 | 0:f016e9e8d48b | 949 | switch(outState){ |
shreeshas95 | 0:f016e9e8d48b | 950 | case 0: |
shreeshas95 | 0:f016e9e8d48b | 951 | outState = 1; |
shreeshas95 | 0:f016e9e8d48b | 952 | output[outByte] = tempBit << 7; |
shreeshas95 | 0:f016e9e8d48b | 953 | break; |
shreeshas95 | 0:f016e9e8d48b | 954 | case 1: |
shreeshas95 | 0:f016e9e8d48b | 955 | outState = 2; |
shreeshas95 | 0:f016e9e8d48b | 956 | output[outByte] += tempBit << 6; |
shreeshas95 | 0:f016e9e8d48b | 957 | break; |
shreeshas95 | 0:f016e9e8d48b | 958 | case 2: |
shreeshas95 | 0:f016e9e8d48b | 959 | outState = 3; |
shreeshas95 | 0:f016e9e8d48b | 960 | output[outByte] += tempBit << 5; |
shreeshas95 | 0:f016e9e8d48b | 961 | break; |
shreeshas95 | 0:f016e9e8d48b | 962 | case 3: |
shreeshas95 | 0:f016e9e8d48b | 963 | outState = 4; |
shreeshas95 | 0:f016e9e8d48b | 964 | output[outByte] += tempBit << 4; |
shreeshas95 | 0:f016e9e8d48b | 965 | break; |
shreeshas95 | 0:f016e9e8d48b | 966 | case 4: |
shreeshas95 | 0:f016e9e8d48b | 967 | outState = 5; |
shreeshas95 | 0:f016e9e8d48b | 968 | output[outByte] += tempBit << 3; |
shreeshas95 | 0:f016e9e8d48b | 969 | break; |
shreeshas95 | 0:f016e9e8d48b | 970 | case 5: |
shreeshas95 | 0:f016e9e8d48b | 971 | outState = 6; |
shreeshas95 | 0:f016e9e8d48b | 972 | output[outByte] += tempBit << 2; |
shreeshas95 | 0:f016e9e8d48b | 973 | break; |
shreeshas95 | 0:f016e9e8d48b | 974 | case 6: |
shreeshas95 | 0:f016e9e8d48b | 975 | outState = 7; |
shreeshas95 | 0:f016e9e8d48b | 976 | output[outByte] += tempBit << 1; |
shreeshas95 | 0:f016e9e8d48b | 977 | break; |
shreeshas95 | 0:f016e9e8d48b | 978 | case 7: |
shreeshas95 | 0:f016e9e8d48b | 979 | outState = 0; |
shreeshas95 | 0:f016e9e8d48b | 980 | output[outByte] += tempBit; |
shreeshas95 | 0:f016e9e8d48b | 981 | ++outByte; |
shreeshas95 | 0:f016e9e8d48b | 982 | break; |
shreeshas95 | 0:f016e9e8d48b | 983 | } |
shreeshas95 | 0:f016e9e8d48b | 984 | } |
shreeshas95 | 0:f016e9e8d48b | 985 | for(unsigned int j = 0 ; j < 2 ; ++j){ |
shreeshas95 | 0:f016e9e8d48b | 986 | switch(outState){ |
shreeshas95 | 0:f016e9e8d48b | 987 | case 0: |
shreeshas95 | 0:f016e9e8d48b | 988 | output[outByte] = 0; |
shreeshas95 | 0:f016e9e8d48b | 989 | outState = 1; |
shreeshas95 | 0:f016e9e8d48b | 990 | break; |
shreeshas95 | 0:f016e9e8d48b | 991 | case 1: |
shreeshas95 | 0:f016e9e8d48b | 992 | outState = 2; |
shreeshas95 | 0:f016e9e8d48b | 993 | break; |
shreeshas95 | 0:f016e9e8d48b | 994 | case 2: |
shreeshas95 | 0:f016e9e8d48b | 995 | outState = 3; |
shreeshas95 | 0:f016e9e8d48b | 996 | break; |
shreeshas95 | 0:f016e9e8d48b | 997 | case 3: |
shreeshas95 | 0:f016e9e8d48b | 998 | outState = 4; |
shreeshas95 | 0:f016e9e8d48b | 999 | break; |
shreeshas95 | 0:f016e9e8d48b | 1000 | case 4: |
shreeshas95 | 0:f016e9e8d48b | 1001 | outState = 5; |
shreeshas95 | 0:f016e9e8d48b | 1002 | break; |
shreeshas95 | 0:f016e9e8d48b | 1003 | case 5: |
shreeshas95 | 0:f016e9e8d48b | 1004 | outState = 6; |
shreeshas95 | 0:f016e9e8d48b | 1005 | break; |
shreeshas95 | 0:f016e9e8d48b | 1006 | case 6: |
shreeshas95 | 0:f016e9e8d48b | 1007 | outState = 7; |
shreeshas95 | 0:f016e9e8d48b | 1008 | break; |
shreeshas95 | 0:f016e9e8d48b | 1009 | case 7: |
shreeshas95 | 0:f016e9e8d48b | 1010 | outState = 0; |
shreeshas95 | 0:f016e9e8d48b | 1011 | ++outByte; |
shreeshas95 | 0:f016e9e8d48b | 1012 | break; |
shreeshas95 | 0:f016e9e8d48b | 1013 | } |
shreeshas95 | 0:f016e9e8d48b | 1014 | } |
shreeshas95 | 0:f016e9e8d48b | 1015 | } |
shreeshas95 | 0:f016e9e8d48b | 1016 | } |
shreeshas95 | 0:f016e9e8d48b | 1017 | |
shreeshas95 | 0:f016e9e8d48b | 1018 | // CONVOLUTION |
shreeshas95 | 0:f016e9e8d48b | 1019 | class Convolution{ |
shreeshas95 | 0:f016e9e8d48b | 1020 | |
shreeshas95 | 0:f016e9e8d48b | 1021 | private: |
shreeshas95 | 0:f016e9e8d48b | 1022 | typedef struct ConvNode{ |
shreeshas95 | 0:f016e9e8d48b | 1023 | //next state |
shreeshas95 | 0:f016e9e8d48b | 1024 | //format : 8 bits mapped as [1]xxxx [0]xxxx |
shreeshas95 | 0:f016e9e8d48b | 1025 | unsigned char nextState; |
shreeshas95 | 0:f016e9e8d48b | 1026 | |
shreeshas95 | 0:f016e9e8d48b | 1027 | //output |
shreeshas95 | 0:f016e9e8d48b | 1028 | // format : 8 bits mapped as |
shreeshas95 | 0:f016e9e8d48b | 1029 | // **** xxxx{2} [1]-[0] {1} [1]-[0] i.e. ****xxxx |
shreeshas95 | 0:f016e9e8d48b | 1030 | // x = data, * = junk |
shreeshas95 | 0:f016e9e8d48b | 1031 | unsigned char output; |
shreeshas95 | 0:f016e9e8d48b | 1032 | }ConvNode; |
shreeshas95 | 0:f016e9e8d48b | 1033 | |
shreeshas95 | 0:f016e9e8d48b | 1034 | ConvNode convStateList[16]; |
shreeshas95 | 0:f016e9e8d48b | 1035 | |
shreeshas95 | 0:f016e9e8d48b | 1036 | public: |
shreeshas95 | 0:f016e9e8d48b | 1037 | /* |
shreeshas95 | 0:f016e9e8d48b | 1038 | @brief: Constructor : Initialise all the variables |
shreeshas95 | 0:f016e9e8d48b | 1039 | @param: none |
shreeshas95 | 0:f016e9e8d48b | 1040 | @return: none |
shreeshas95 | 0:f016e9e8d48b | 1041 | */ |
shreeshas95 | 0:f016e9e8d48b | 1042 | Convolution(){ |
shreeshas95 | 0:f016e9e8d48b | 1043 | |
shreeshas95 | 0:f016e9e8d48b | 1044 | convStateList[0].nextState = 0x10; |
shreeshas95 | 0:f016e9e8d48b | 1045 | convStateList[1].nextState = 0x32; |
shreeshas95 | 0:f016e9e8d48b | 1046 | convStateList[2].nextState = 0x54; |
shreeshas95 | 0:f016e9e8d48b | 1047 | convStateList[3].nextState = 0x76; |
shreeshas95 | 0:f016e9e8d48b | 1048 | convStateList[4].nextState = 0x98; |
shreeshas95 | 0:f016e9e8d48b | 1049 | convStateList[5].nextState = 0xBA; |
shreeshas95 | 0:f016e9e8d48b | 1050 | convStateList[6].nextState = 0xDC; |
shreeshas95 | 0:f016e9e8d48b | 1051 | convStateList[7].nextState = 0xFE; |
shreeshas95 | 0:f016e9e8d48b | 1052 | convStateList[8].nextState = 0x10; |
shreeshas95 | 0:f016e9e8d48b | 1053 | convStateList[9].nextState = 0x32; |
shreeshas95 | 0:f016e9e8d48b | 1054 | convStateList[10].nextState = 0x54; |
shreeshas95 | 0:f016e9e8d48b | 1055 | convStateList[11].nextState = 0x76; |
shreeshas95 | 0:f016e9e8d48b | 1056 | convStateList[12].nextState = 0x98; |
shreeshas95 | 0:f016e9e8d48b | 1057 | convStateList[13].nextState = 0xBA; |
shreeshas95 | 0:f016e9e8d48b | 1058 | convStateList[14].nextState = 0xDC; |
shreeshas95 | 0:f016e9e8d48b | 1059 | convStateList[15].nextState = 0xFE; |
shreeshas95 | 0:f016e9e8d48b | 1060 | |
shreeshas95 | 0:f016e9e8d48b | 1061 | convStateList[0].output = 0x0A; |
shreeshas95 | 0:f016e9e8d48b | 1062 | convStateList[1].output = 0x06; |
shreeshas95 | 0:f016e9e8d48b | 1063 | convStateList[2].output = 0x06; |
shreeshas95 | 0:f016e9e8d48b | 1064 | convStateList[3].output = 0x0A; |
shreeshas95 | 0:f016e9e8d48b | 1065 | convStateList[4].output = 0x09; |
shreeshas95 | 0:f016e9e8d48b | 1066 | convStateList[5].output = 0x05; |
shreeshas95 | 0:f016e9e8d48b | 1067 | convStateList[6].output = 0x05; |
shreeshas95 | 0:f016e9e8d48b | 1068 | convStateList[7].output = 0x09; |
shreeshas95 | 0:f016e9e8d48b | 1069 | convStateList[8].output = 0x05; |
shreeshas95 | 0:f016e9e8d48b | 1070 | convStateList[9].output = 0x09; |
shreeshas95 | 0:f016e9e8d48b | 1071 | convStateList[10].output = 0x09; |
shreeshas95 | 0:f016e9e8d48b | 1072 | convStateList[11].output = 0x05; |
shreeshas95 | 0:f016e9e8d48b | 1073 | convStateList[12].output = 0x06; |
shreeshas95 | 0:f016e9e8d48b | 1074 | convStateList[13].output = 0x0A; |
shreeshas95 | 0:f016e9e8d48b | 1075 | convStateList[14].output = 0x0A; |
shreeshas95 | 0:f016e9e8d48b | 1076 | convStateList[15].output = 0x06; |
shreeshas95 | 0:f016e9e8d48b | 1077 | } |
shreeshas95 | 0:f016e9e8d48b | 1078 | |
shreeshas95 | 0:f016e9e8d48b | 1079 | |
shreeshas95 | 0:f016e9e8d48b | 1080 | /* |
shreeshas95 | 0:f016e9e8d48b | 1081 | @brief: convolution encode the input bytes : in sync with => (1-TM-Frame -> 2-T-Frame) |
shreeshas95 | 0:f016e9e8d48b | 1082 | @param: inPtr : pointer to input unsigned char array |
shreeshas95 | 0:f016e9e8d48b | 1083 | inLength : length in bytes of input array |
shreeshas95 | 0:f016e9e8d48b | 1084 | outPtr : pointer to the output bytes, define it outside the function |
shreeshas95 | 0:f016e9e8d48b | 1085 | outLength : length of output array in bytes [call by reference, edited inside the function] |
shreeshas95 | 0:f016e9e8d48b | 1086 | @return: none |
shreeshas95 | 0:f016e9e8d48b | 1087 | */ |
shreeshas95 | 0:f016e9e8d48b | 1088 | void convolutionEncode(unsigned char *input, unsigned char *output){ |
shreeshas95 | 0:f016e9e8d48b | 1089 | |
shreeshas95 | 0:f016e9e8d48b | 1090 | // cout << "inside convolution" << endl; |
shreeshas95 | 0:f016e9e8d48b | 1091 | |
shreeshas95 | 0:f016e9e8d48b | 1092 | unsigned int convState = 0; |
shreeshas95 | 0:f016e9e8d48b | 1093 | |
shreeshas95 | 0:f016e9e8d48b | 1094 | int inBit = 7; |
shreeshas95 | 0:f016e9e8d48b | 1095 | unsigned int inByte = 0; |
shreeshas95 | 0:f016e9e8d48b | 1096 | |
shreeshas95 | 0:f016e9e8d48b | 1097 | unsigned int outState = 0; |
shreeshas95 | 0:f016e9e8d48b | 1098 | unsigned int outByte = 0; |
shreeshas95 | 0:f016e9e8d48b | 1099 | |
shreeshas95 | 0:f016e9e8d48b | 1100 | for(unsigned int j = 0 ; j < 536 ; ++j){ |
shreeshas95 | 0:f016e9e8d48b | 1101 | // printf("j = %u, inByte = %u\n", j, inByte); |
shreeshas95 | 0:f016e9e8d48b | 1102 | // read a new bit from input stream |
shreeshas95 | 0:f016e9e8d48b | 1103 | // cout << "inByte " <<inByte; |
shreeshas95 | 0:f016e9e8d48b | 1104 | unsigned char tempBit = (input[inByte] >> inBit) & 1; |
shreeshas95 | 0:f016e9e8d48b | 1105 | --inBit; |
shreeshas95 | 0:f016e9e8d48b | 1106 | |
shreeshas95 | 0:f016e9e8d48b | 1107 | // convolute and write output |
shreeshas95 | 0:f016e9e8d48b | 1108 | switch(outState){ |
shreeshas95 | 0:f016e9e8d48b | 1109 | case 0: |
shreeshas95 | 0:f016e9e8d48b | 1110 | outState = 2; |
shreeshas95 | 0:f016e9e8d48b | 1111 | output[outByte] = ( (convStateList[convState].output >> tempBit) & 1 ) << 7; |
shreeshas95 | 0:f016e9e8d48b | 1112 | output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ) << 6; |
shreeshas95 | 0:f016e9e8d48b | 1113 | break; |
shreeshas95 | 0:f016e9e8d48b | 1114 | case 2: |
shreeshas95 | 0:f016e9e8d48b | 1115 | outState = 4; |
shreeshas95 | 0:f016e9e8d48b | 1116 | output[outByte] += ( (convStateList[convState].output >> tempBit) & 1 ) << 5; |
shreeshas95 | 0:f016e9e8d48b | 1117 | output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ) << 4; |
shreeshas95 | 0:f016e9e8d48b | 1118 | break; |
shreeshas95 | 0:f016e9e8d48b | 1119 | case 4: |
shreeshas95 | 0:f016e9e8d48b | 1120 | outState = 6; |
shreeshas95 | 0:f016e9e8d48b | 1121 | output[outByte] += ( (convStateList[convState].output >> tempBit) & 1 ) << 3; |
shreeshas95 | 0:f016e9e8d48b | 1122 | output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ) << 2; |
shreeshas95 | 0:f016e9e8d48b | 1123 | break; |
shreeshas95 | 0:f016e9e8d48b | 1124 | case 6: |
shreeshas95 | 0:f016e9e8d48b | 1125 | outState = 0; |
shreeshas95 | 0:f016e9e8d48b | 1126 | output[outByte] += ( (convStateList[convState].output >> tempBit) & 1 ) << 1; |
shreeshas95 | 0:f016e9e8d48b | 1127 | output[outByte] += ( (convStateList[convState].output >> (tempBit + 2)) & 1 ); |
shreeshas95 | 0:f016e9e8d48b | 1128 | ++outByte; |
shreeshas95 | 0:f016e9e8d48b | 1129 | output[outByte] = 0x00; |
shreeshas95 | 0:f016e9e8d48b | 1130 | break; |
shreeshas95 | 0:f016e9e8d48b | 1131 | } |
shreeshas95 | 0:f016e9e8d48b | 1132 | |
shreeshas95 | 0:f016e9e8d48b | 1133 | // next state transition |
shreeshas95 | 0:f016e9e8d48b | 1134 | switch(tempBit){ |
shreeshas95 | 0:f016e9e8d48b | 1135 | case 0: |
shreeshas95 | 0:f016e9e8d48b | 1136 | convState = (convStateList[convState].nextState) & 0xF; |
shreeshas95 | 0:f016e9e8d48b | 1137 | break; |
shreeshas95 | 0:f016e9e8d48b | 1138 | case 1: |
shreeshas95 | 0:f016e9e8d48b | 1139 | convState = (convStateList[convState].nextState >> 4) & 0xF; |
shreeshas95 | 0:f016e9e8d48b | 1140 | break; |
shreeshas95 | 0:f016e9e8d48b | 1141 | } |
shreeshas95 | 0:f016e9e8d48b | 1142 | |
shreeshas95 | 0:f016e9e8d48b | 1143 | if(inBit == -1){ |
shreeshas95 | 0:f016e9e8d48b | 1144 | // printf("in byte = %u\n", inByte); |
shreeshas95 | 0:f016e9e8d48b | 1145 | ++inByte; |
shreeshas95 | 0:f016e9e8d48b | 1146 | inBit = 7; |
shreeshas95 | 0:f016e9e8d48b | 1147 | } |
shreeshas95 | 0:f016e9e8d48b | 1148 | |
shreeshas95 | 0:f016e9e8d48b | 1149 | } |
shreeshas95 | 0:f016e9e8d48b | 1150 | |
shreeshas95 | 0:f016e9e8d48b | 1151 | // printf("normal iteration complete, outByte = %u\n", outByte); |
shreeshas95 | 0:f016e9e8d48b | 1152 | |
shreeshas95 | 0:f016e9e8d48b | 1153 | for(unsigned int j = 0 ; j < 4 ; ++j){ |
shreeshas95 | 0:f016e9e8d48b | 1154 | // printf("j = %u\n, outByte = %u\n", j, outByte); |
shreeshas95 | 0:f016e9e8d48b | 1155 | // append zero at the end |
shreeshas95 | 0:f016e9e8d48b | 1156 | switch(outState){ |
shreeshas95 | 0:f016e9e8d48b | 1157 | case 0: |
shreeshas95 | 0:f016e9e8d48b | 1158 | outState = 2; |
shreeshas95 | 0:f016e9e8d48b | 1159 | output[outByte] = ( (convStateList[convState].output) & 1 ) << 7; |
shreeshas95 | 0:f016e9e8d48b | 1160 | output[outByte] += ( (convStateList[convState].output >> 2) & 1 ) << 6; |
shreeshas95 | 0:f016e9e8d48b | 1161 | break; |
shreeshas95 | 0:f016e9e8d48b | 1162 | case 2: |
shreeshas95 | 0:f016e9e8d48b | 1163 | outState = 4; |
shreeshas95 | 0:f016e9e8d48b | 1164 | output[outByte] += ( (convStateList[convState].output) & 1 ) << 5; |
shreeshas95 | 0:f016e9e8d48b | 1165 | output[outByte] += ( (convStateList[convState].output >> 2) & 1 ) << 4; |
shreeshas95 | 0:f016e9e8d48b | 1166 | break; |
shreeshas95 | 0:f016e9e8d48b | 1167 | case 4: |
shreeshas95 | 0:f016e9e8d48b | 1168 | outState = 6; |
shreeshas95 | 0:f016e9e8d48b | 1169 | output[outByte] += ( (convStateList[convState].output ) & 1 ) << 3; |
shreeshas95 | 0:f016e9e8d48b | 1170 | output[outByte] += ( (convStateList[convState].output >> 2) & 1 ) << 2; |
shreeshas95 | 0:f016e9e8d48b | 1171 | break; |
shreeshas95 | 0:f016e9e8d48b | 1172 | case 6: |
shreeshas95 | 0:f016e9e8d48b | 1173 | outState = 0; |
shreeshas95 | 0:f016e9e8d48b | 1174 | output[outByte] += ( (convStateList[convState].output ) & 1 ) << 1; |
shreeshas95 | 0:f016e9e8d48b | 1175 | output[outByte] += ( (convStateList[convState].output >> 2) & 1 ); |
shreeshas95 | 0:f016e9e8d48b | 1176 | ++outByte; |
shreeshas95 | 0:f016e9e8d48b | 1177 | // printf("outByte @ end of switch = %u\n", outByte); |
shreeshas95 | 0:f016e9e8d48b | 1178 | break; |
shreeshas95 | 0:f016e9e8d48b | 1179 | } |
shreeshas95 | 0:f016e9e8d48b | 1180 | // next state transition |
shreeshas95 | 0:f016e9e8d48b | 1181 | convState = (convStateList[convState].nextState) & 0xF; |
shreeshas95 | 0:f016e9e8d48b | 1182 | } |
shreeshas95 | 0:f016e9e8d48b | 1183 | // printf("complete\n"); |
shreeshas95 | 0:f016e9e8d48b | 1184 | } |
shreeshas95 | 0:f016e9e8d48b | 1185 | |
shreeshas95 | 0:f016e9e8d48b | 1186 | }; |