![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Repository for testing ADF code of COM_TMTC_SIMPLE
Fork of COM_MNG_TMTC_SIMPLE by
Compression.h@4:e37674541504, 2015-12-24 (annotated)
- Committer:
- shekhar
- Date:
- Thu Dec 24 18:38:12 2015 +0000
- Revision:
- 4:e37674541504
- Parent:
- 1:a0055b3280c8
ADF code to be tested
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shreeshas95 | 1:a0055b3280c8 | 1 | int disk_write(const uint8_t *, uint64_t); |
shreeshas95 | 1:a0055b3280c8 | 2 | uint64_t RTC_TIME; //need to be changed to uint_64 |
shreeshas95 | 1:a0055b3280c8 | 3 | unsigned char SDcard_lastWritten[512] = {0}; |
shreeshas95 | 1:a0055b3280c8 | 4 | |
shreeshas95 | 1:a0055b3280c8 | 5 | namespace Science_TMframe { |
shreeshas95 | 1:a0055b3280c8 | 6 | |
shreeshas95 | 1:a0055b3280c8 | 7 | #define OUTLENGTH 360 //length of the output frame after convolution |
shreeshas95 | 1:a0055b3280c8 | 8 | #define SDcard_block 512 //block size of the sd card |
shreeshas95 | 1:a0055b3280c8 | 9 | |
shreeshas95 | 1:a0055b3280c8 | 10 | Convolution ConvObj; //object which stores the frame after convolution |
shreeshas95 | 1:a0055b3280c8 | 11 | bool fresh[3] = {true,true,true}; // True only for the first time |
shreeshas95 | 1:a0055b3280c8 | 12 | 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 | 1:a0055b3280c8 | 13 | unsigned int FCN[4] = {0}; //frame count number |
shreeshas95 | 1:a0055b3280c8 | 14 | unsigned int data_starting_point[3] = {8,5,10}; |
shreeshas95 | 1:a0055b3280c8 | 15 | unsigned int max_data[3] = {124,127,122}; //number of bytes in each frame excluding TMID,FCN,first_header_point,crc |
shreeshas95 | 1:a0055b3280c8 | 16 | unsigned char TM_convoluted_data[270] = {0}; //270 bytes is the size after convolution of 1072 bits |
shreeshas95 | 1:a0055b3280c8 | 17 | unsigned char complete_frame[SDcard_block] = {0}; |
shreeshas95 | 1:a0055b3280c8 | 18 | uint64_t SDC_address = 200; |
shreeshas95 | 1:a0055b3280c8 | 19 | bool SCH_FCCH_FLAG = true; |
shreeshas95 | 1:a0055b3280c8 | 20 | |
shreeshas95 | 1:a0055b3280c8 | 21 | |
shreeshas95 | 1:a0055b3280c8 | 22 | void add_SCH_FCCH(){ |
shreeshas95 | 1:a0055b3280c8 | 23 | int i = 0; |
shreeshas95 | 1:a0055b3280c8 | 24 | complete_frame[0] = 0x0a; |
shreeshas95 | 1:a0055b3280c8 | 25 | complete_frame[1] = 0x3f;; |
shreeshas95 | 1:a0055b3280c8 | 26 | complete_frame[2] = 0x46; |
shreeshas95 | 1:a0055b3280c8 | 27 | complete_frame[3] = 0xb4; |
shreeshas95 | 1:a0055b3280c8 | 28 | complete_frame[4] = 0x00; |
shreeshas95 | 1:a0055b3280c8 | 29 | |
shreeshas95 | 1:a0055b3280c8 | 30 | for(i = 149 ; i < 159 ; i ++){ |
shreeshas95 | 1:a0055b3280c8 | 31 | complete_frame[i] = 0 ; |
shreeshas95 | 1:a0055b3280c8 | 32 | } |
shreeshas95 | 1:a0055b3280c8 | 33 | |
shreeshas95 | 1:a0055b3280c8 | 34 | complete_frame[159] = 0x0a; |
shreeshas95 | 1:a0055b3280c8 | 35 | complete_frame[160] = 0x3f;; |
shreeshas95 | 1:a0055b3280c8 | 36 | complete_frame[161] = 0x46; |
shreeshas95 | 1:a0055b3280c8 | 37 | complete_frame[162] = 0xb4; |
shreeshas95 | 1:a0055b3280c8 | 38 | complete_frame[163] = 0x00; |
shreeshas95 | 1:a0055b3280c8 | 39 | |
shreeshas95 | 1:a0055b3280c8 | 40 | for(i = 308 ; i < 318 ; i ++){ |
shreeshas95 | 1:a0055b3280c8 | 41 | complete_frame[i] = 0 ; |
shreeshas95 | 1:a0055b3280c8 | 42 | } |
shreeshas95 | 1:a0055b3280c8 | 43 | |
shreeshas95 | 1:a0055b3280c8 | 44 | } |
shreeshas95 | 1:a0055b3280c8 | 45 | |
shreeshas95 | 1:a0055b3280c8 | 46 | void making_frameHeader(unsigned char TMID){ |
shreeshas95 | 1:a0055b3280c8 | 47 | |
shreeshas95 | 1:a0055b3280c8 | 48 | unsigned char frame_type_identifier = 0; // not conform about the values , yet to be done |
shreeshas95 | 1:a0055b3280c8 | 49 | 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 | 1:a0055b3280c8 | 50 | frames[TMID][1] = ((FCN[TMID]>>16) & 0xff ); |
shreeshas95 | 1:a0055b3280c8 | 51 | frames[TMID][2] = ( (FCN[TMID]>>8 )& 0xff ); |
shreeshas95 | 1:a0055b3280c8 | 52 | frames[TMID][3] = ( FCN[TMID] & 0xff ); // first bit for (frame identifier), next 4 for (TMID) and next 27 for FCN |
shreeshas95 | 1:a0055b3280c8 | 53 | |
shreeshas95 | 1:a0055b3280c8 | 54 | if(TMID == 0){ |
shreeshas95 | 1:a0055b3280c8 | 55 | frames[TMID][5] =( (RTC_TIME>>29) & 0xff ); |
shreeshas95 | 1:a0055b3280c8 | 56 | frames[TMID][6] =( (RTC_TIME>>21) & 0xff ); |
shreeshas95 | 1:a0055b3280c8 | 57 | frames[TMID][7] =( (RTC_TIME>>13) & 0xff ); |
shreeshas95 | 1:a0055b3280c8 | 58 | |
shreeshas95 | 1:a0055b3280c8 | 59 | }else if(TMID == 2){ |
shreeshas95 | 1:a0055b3280c8 | 60 | frames[TMID][5] =( (RTC_TIME>>32) & 0xff ); |
shreeshas95 | 1:a0055b3280c8 | 61 | frames[TMID][6] =( (RTC_TIME>>24) & 0xff ); |
shreeshas95 | 1:a0055b3280c8 | 62 | frames[TMID][7] =( (RTC_TIME>>16) & 0xff ); |
shreeshas95 | 1:a0055b3280c8 | 63 | frames[TMID][8] =( (RTC_TIME>>8 ) & 0xff ); |
shreeshas95 | 1:a0055b3280c8 | 64 | frames[TMID][9] =( (RTC_TIME ) & 0xff ); |
shreeshas95 | 1:a0055b3280c8 | 65 | } |
shreeshas95 | 1:a0055b3280c8 | 66 | |
shreeshas95 | 1:a0055b3280c8 | 67 | } |
shreeshas95 | 1:a0055b3280c8 | 68 | |
shreeshas95 | 1:a0055b3280c8 | 69 | void convolution (unsigned char * ptr){ |
shreeshas95 | 1:a0055b3280c8 | 70 | |
shreeshas95 | 1:a0055b3280c8 | 71 | ConvObj.convolutionEncode(ptr , TM_convoluted_data); |
shreeshas95 | 1:a0055b3280c8 | 72 | ConvObj.convolutionEncode(ptr + 67, TM_convoluted_data + 135); |
shreeshas95 | 1:a0055b3280c8 | 73 | |
shreeshas95 | 1:a0055b3280c8 | 74 | } |
shreeshas95 | 1:a0055b3280c8 | 75 | |
shreeshas95 | 1:a0055b3280c8 | 76 | /* |
shreeshas95 | 1:a0055b3280c8 | 77 | @brief : take the address of array of LCR or HCR and stores it into a frame |
shreeshas95 | 1:a0055b3280c8 | 78 | @parameters: type->L or H , deprnding on wheather it is LCR or HCR respectively |
shreeshas95 | 1:a0055b3280c8 | 79 | @return: nothing |
shreeshas95 | 1:a0055b3280c8 | 80 | */ |
shreeshas95 | 1:a0055b3280c8 | 81 | |
shreeshas95 | 1:a0055b3280c8 | 82 | // type 2 yet to be done |
shreeshas95 | 1:a0055b3280c8 | 83 | void making_frame(unsigned char TMID ,unsigned char type, unsigned char* pointer){ |
shreeshas95 | 1:a0055b3280c8 | 84 | |
shreeshas95 | 1:a0055b3280c8 | 85 | TMID--; //TMID goes from 1 to 3 , convinient to ue from 0 to 2 |
shreeshas95 | 1:a0055b3280c8 | 86 | 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 | 1:a0055b3280c8 | 87 | int packet_len = 0; |
shreeshas95 | 1:a0055b3280c8 | 88 | int copy_count = 0 ; |
shreeshas95 | 1:a0055b3280c8 | 89 | |
shreeshas95 | 1:a0055b3280c8 | 90 | switch(int(TMID)){ |
shreeshas95 | 1:a0055b3280c8 | 91 | case 0: //SCP |
shreeshas95 | 1:a0055b3280c8 | 92 | if(type == 'L'){ //below threshold |
shreeshas95 | 1:a0055b3280c8 | 93 | packet_len = 22; |
shreeshas95 | 1:a0055b3280c8 | 94 | } |
shreeshas95 | 1:a0055b3280c8 | 95 | else if(type == 'H'){ //above threshold |
shreeshas95 | 1:a0055b3280c8 | 96 | packet_len = 26; |
shreeshas95 | 1:a0055b3280c8 | 97 | } |
shreeshas95 | 1:a0055b3280c8 | 98 | break; |
shreeshas95 | 1:a0055b3280c8 | 99 | |
shreeshas95 | 1:a0055b3280c8 | 100 | case 1: //SFP above threshold |
shreeshas95 | 1:a0055b3280c8 | 101 | packet_len = 35; |
shreeshas95 | 1:a0055b3280c8 | 102 | break; |
shreeshas95 | 1:a0055b3280c8 | 103 | |
shreeshas95 | 1:a0055b3280c8 | 104 | case 2: //SFP below threshold |
shreeshas95 | 1:a0055b3280c8 | 105 | packet_len = 23; |
shreeshas95 | 1:a0055b3280c8 | 106 | break; |
shreeshas95 | 1:a0055b3280c8 | 107 | } |
shreeshas95 | 1:a0055b3280c8 | 108 | |
shreeshas95 | 1:a0055b3280c8 | 109 | if(SCH_FCCH_FLAG){ |
shreeshas95 | 1:a0055b3280c8 | 110 | add_SCH_FCCH(); |
shreeshas95 | 1:a0055b3280c8 | 111 | SCH_FCCH_FLAG = false; |
shreeshas95 | 1:a0055b3280c8 | 112 | } |
shreeshas95 | 1:a0055b3280c8 | 113 | |
shreeshas95 | 1:a0055b3280c8 | 114 | if(fresh[TMID]){ |
shreeshas95 | 1:a0055b3280c8 | 115 | //welcome to first frame |
shreeshas95 | 1:a0055b3280c8 | 116 | making_frameHeader(TMID); |
shreeshas95 | 1:a0055b3280c8 | 117 | frames[TMID][4] = 0; |
shreeshas95 | 1:a0055b3280c8 | 118 | fresh[TMID] = false; |
shreeshas95 | 1:a0055b3280c8 | 119 | } |
shreeshas95 | 1:a0055b3280c8 | 120 | |
shreeshas95 | 1:a0055b3280c8 | 121 | |
shreeshas95 | 1:a0055b3280c8 | 122 | while(copy_count < packet_len){ // 22 bytes is the size of the LCR |
shreeshas95 | 1:a0055b3280c8 | 123 | frames[TMID][ frame_space_number[TMID] + data_starting_point[TMID] ]= *(pointer + copy_count); |
shreeshas95 | 1:a0055b3280c8 | 124 | frame_space_number[TMID]++; |
shreeshas95 | 1:a0055b3280c8 | 125 | copy_count++; |
shreeshas95 | 1:a0055b3280c8 | 126 | 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 | 1:a0055b3280c8 | 127 | FCN[TMID]++; |
shreeshas95 | 1:a0055b3280c8 | 128 | // convolution and save frame in the sd card |
shreeshas95 | 1:a0055b3280c8 | 129 | |
shreeshas95 | 1:a0055b3280c8 | 130 | // copying crc in 132 and 133 |
shreeshas95 | 1:a0055b3280c8 | 131 | int temp_crc; |
shreeshas95 | 1:a0055b3280c8 | 132 | temp_crc = crc16_gen(frames[TMID],132); |
shreeshas95 | 1:a0055b3280c8 | 133 | frames[TMID][132] = temp_crc>>8; |
shreeshas95 | 1:a0055b3280c8 | 134 | frames[TMID][133] = temp_crc & 0xff; |
shreeshas95 | 1:a0055b3280c8 | 135 | // xor |
shreeshas95 | 1:a0055b3280c8 | 136 | for(int j = 0 ; j < 134 ; j++){ |
shreeshas95 | 1:a0055b3280c8 | 137 | // frames[TMID][j] = frames[TMID][j]^exorThisWithTMFrame[j]; |
shreeshas95 | 1:a0055b3280c8 | 138 | } |
shreeshas95 | 1:a0055b3280c8 | 139 | //convolution and interleaving |
shreeshas95 | 1:a0055b3280c8 | 140 | convolution(frames[TMID]); |
shreeshas95 | 1:a0055b3280c8 | 141 | interleave(TM_convoluted_data , complete_frame + 5); |
shreeshas95 | 1:a0055b3280c8 | 142 | interleave(TM_convoluted_data+ 135,complete_frame + 164); |
shreeshas95 | 1:a0055b3280c8 | 143 | |
shreeshas95 | 1:a0055b3280c8 | 144 | // writing the SDC_address in a buffer , to store it in SDcard at address 5 |
shreeshas95 | 1:a0055b3280c8 | 145 | SDcard_lastWritten[0] = SDC_address>>56; |
shreeshas95 | 1:a0055b3280c8 | 146 | SDcard_lastWritten[1] = (SDC_address>>48)&0xFF; |
shreeshas95 | 1:a0055b3280c8 | 147 | SDcard_lastWritten[2] = (SDC_address>>40)&0xFF; |
shreeshas95 | 1:a0055b3280c8 | 148 | SDcard_lastWritten[3] = (SDC_address>>32)&0xFF; |
shreeshas95 | 1:a0055b3280c8 | 149 | SDcard_lastWritten[4] = (SDC_address>>24)&0xFF; |
shreeshas95 | 1:a0055b3280c8 | 150 | SDcard_lastWritten[5] = (SDC_address>>16)&0xFF; |
shreeshas95 | 1:a0055b3280c8 | 151 | SDcard_lastWritten[6] = (SDC_address>>8)&0xFF; |
shreeshas95 | 1:a0055b3280c8 | 152 | SDcard_lastWritten[7] = (SDC_address)&0xFF; |
shreeshas95 | 1:a0055b3280c8 | 153 | |
shreeshas95 | 1:a0055b3280c8 | 154 | SPI_mutex.lock(); |
shreeshas95 | 1:a0055b3280c8 | 155 | disk_write(complete_frame , SDC_address); |
shreeshas95 | 1:a0055b3280c8 | 156 | SPI_mutex.unlock(); |
shreeshas95 | 1:a0055b3280c8 | 157 | SDC_address++; |
shreeshas95 | 1:a0055b3280c8 | 158 | |
shreeshas95 | 1:a0055b3280c8 | 159 | |
shreeshas95 | 1:a0055b3280c8 | 160 | |
shreeshas95 | 1:a0055b3280c8 | 161 | //now save to the sd card TM_convoluted_data |
shreeshas95 | 1:a0055b3280c8 | 162 | // std::bitset<8> b; |
shreeshas95 | 1:a0055b3280c8 | 163 | // printf("\nthis is frame %d\n",TMID); //for printing frame |
shreeshas95 | 1:a0055b3280c8 | 164 | // for(int j =0; j<134;j++){ |
shreeshas95 | 1:a0055b3280c8 | 165 | // printf(" %d",frames[TMID][j]); |
shreeshas95 | 1:a0055b3280c8 | 166 | //// b = frames[TMID][j]; |
shreeshas95 | 1:a0055b3280c8 | 167 | //// cout<<b; |
shreeshas95 | 1:a0055b3280c8 | 168 | // } |
shreeshas95 | 1:a0055b3280c8 | 169 | |
shreeshas95 | 1:a0055b3280c8 | 170 | frame_space_number[TMID] = 0; |
shreeshas95 | 1:a0055b3280c8 | 171 | making_frameHeader(TMID); |
shreeshas95 | 1:a0055b3280c8 | 172 | frames[TMID][4]=packet_len - copy_count; |
shreeshas95 | 1:a0055b3280c8 | 173 | //write time here also |
shreeshas95 | 1:a0055b3280c8 | 174 | continue; |
shreeshas95 | 1:a0055b3280c8 | 175 | } |
shreeshas95 | 1:a0055b3280c8 | 176 | } |
shreeshas95 | 1:a0055b3280c8 | 177 | |
shreeshas95 | 1:a0055b3280c8 | 178 | // printf("\nthis is frame %d\n",TMID); //for printing frame |
shreeshas95 | 1:a0055b3280c8 | 179 | // for(int j =0; j<134;j++){ |
shreeshas95 | 1:a0055b3280c8 | 180 | // printf(" %d",frames[TMID][j]); |
shreeshas95 | 1:a0055b3280c8 | 181 | // } |
shreeshas95 | 1:a0055b3280c8 | 182 | |
shreeshas95 | 1:a0055b3280c8 | 183 | } |
shreeshas95 | 1:a0055b3280c8 | 184 | |
shreeshas95 | 1:a0055b3280c8 | 185 | |
shreeshas95 | 1:a0055b3280c8 | 186 | } |
shreeshas95 | 1:a0055b3280c8 | 187 | |
shreeshas95 | 1:a0055b3280c8 | 188 | |
shreeshas95 | 1:a0055b3280c8 | 189 | |
shreeshas95 | 1:a0055b3280c8 | 190 | |
shreeshas95 | 1:a0055b3280c8 | 191 | |
shreeshas95 | 1:a0055b3280c8 | 192 | namespace Science_Data_Compression{ |
shreeshas95 | 1:a0055b3280c8 | 193 | |
shreeshas95 | 1:a0055b3280c8 | 194 | # define PACKET_SEQUENCE_COUNT 1 //1 byte |
shreeshas95 | 1:a0055b3280c8 | 195 | # define NUM_PROTON_BIN 17 //2 byte each |
shreeshas95 | 1:a0055b3280c8 | 196 | # define NUM_ELECTRON_BIN 14 //2 byte each |
shreeshas95 | 1:a0055b3280c8 | 197 | # define VETO 1 //2 byte |
shreeshas95 | 1:a0055b3280c8 | 198 | # define FASTCHAIN 2 //4 byte each |
shreeshas95 | 1:a0055b3280c8 | 199 | #define RAW_PACKET_LENGTH 73 //73 bytes |
shreeshas95 | 1:a0055b3280c8 | 200 | |
shreeshas95 | 1:a0055b3280c8 | 201 | // #define PACKET_SEQ_COUNT 1 |
shreeshas95 | 1:a0055b3280c8 | 202 | // #define PROTON_BIN_SIZE 2 |
shreeshas95 | 1:a0055b3280c8 | 203 | // #define ELECTRON_BIN_SIZE 2 |
shreeshas95 | 1:a0055b3280c8 | 204 | // #define VETO 2 |
shreeshas95 | 1:a0055b3280c8 | 205 | // #define FAST_CHAIN 4 |
shreeshas95 | 1:a0055b3280c8 | 206 | |
shreeshas95 | 1:a0055b3280c8 | 207 | |
shreeshas95 | 1:a0055b3280c8 | 208 | /* |
shreeshas95 | 1:a0055b3280c8 | 209 | @brief: read one uint16_t equivalent of first two chars from the stream. short int because 16 bits |
shreeshas95 | 1:a0055b3280c8 | 210 | @param: pointer to the start of the short int |
shreeshas95 | 1:a0055b3280c8 | 211 | @return: uint16_t |
shreeshas95 | 1:a0055b3280c8 | 212 | */ |
shreeshas95 | 1:a0055b3280c8 | 213 | |
shreeshas95 | 1:a0055b3280c8 | 214 | |
shreeshas95 | 1:a0055b3280c8 | 215 | unsigned int read_2byte(unsigned char* ptr){ |
shreeshas95 | 1:a0055b3280c8 | 216 | unsigned int output = (unsigned int) *(ptr+1); |
shreeshas95 | 1:a0055b3280c8 | 217 | output += ( (unsigned int)(*ptr) ) << 8; |
shreeshas95 | 1:a0055b3280c8 | 218 | return output; |
shreeshas95 | 1:a0055b3280c8 | 219 | } |
shreeshas95 | 1:a0055b3280c8 | 220 | |
shreeshas95 | 1:a0055b3280c8 | 221 | /* |
shreeshas95 | 1:a0055b3280c8 | 222 | @brief: read one int equivalent of first four chars from the stream. int because 32 bits |
shreeshas95 | 1:a0055b3280c8 | 223 | @param: pointer to the start of the short int |
shreeshas95 | 1:a0055b3280c8 | 224 | @return: unsigned int |
shreeshas95 | 1:a0055b3280c8 | 225 | */ |
shreeshas95 | 1:a0055b3280c8 | 226 | |
shreeshas95 | 1:a0055b3280c8 | 227 | unsigned int read_4byte(unsigned char* ptr){ |
shreeshas95 | 1:a0055b3280c8 | 228 | unsigned int output = (unsigned int) *(ptr+3); |
shreeshas95 | 1:a0055b3280c8 | 229 | output += (unsigned int)*(ptr+2)<<8; |
shreeshas95 | 1:a0055b3280c8 | 230 | output += (unsigned int)*(ptr+1)<<16; |
shreeshas95 | 1:a0055b3280c8 | 231 | output += (unsigned int)*(ptr)<<24; |
shreeshas95 | 1:a0055b3280c8 | 232 | return output; |
shreeshas95 | 1:a0055b3280c8 | 233 | } |
shreeshas95 | 1:a0055b3280c8 | 234 | |
shreeshas95 | 1:a0055b3280c8 | 235 | 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 | 1:a0055b3280c8 | 236 | 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 | 1:a0055b3280c8 | 237 | unsigned int SFP_bin[35]; |
shreeshas95 | 1:a0055b3280c8 | 238 | unsigned int SCP_bin[35]={0}; |
shreeshas95 | 1:a0055b3280c8 | 239 | unsigned char SFP_outputBT[23]; //BT = below threshold |
shreeshas95 | 1:a0055b3280c8 | 240 | unsigned char SFP_outputAT[35]; |
shreeshas95 | 1:a0055b3280c8 | 241 | unsigned char SCP_outputLCR[22]; |
shreeshas95 | 1:a0055b3280c8 | 242 | unsigned char SCP_outputHCR[26]; |
shreeshas95 | 1:a0055b3280c8 | 243 | |
shreeshas95 | 1:a0055b3280c8 | 244 | |
shreeshas95 | 1:a0055b3280c8 | 245 | //********************************************************************************************************************************************************************** |
shreeshas95 | 1:a0055b3280c8 | 246 | //lots of compression functions are listed below |
shreeshas95 | 1:a0055b3280c8 | 247 | |
shreeshas95 | 1:a0055b3280c8 | 248 | |
shreeshas95 | 1:a0055b3280c8 | 249 | unsigned char SFP_compress4_BT(unsigned int input){ //for veto |
shreeshas95 | 1:a0055b3280c8 | 250 | int de_4 = 0; |
shreeshas95 | 1:a0055b3280c8 | 251 | unsigned char output; |
shreeshas95 | 1:a0055b3280c8 | 252 | |
shreeshas95 | 1:a0055b3280c8 | 253 | if(input<= 3){ |
shreeshas95 | 1:a0055b3280c8 | 254 | // DE = 0; |
shreeshas95 | 1:a0055b3280c8 | 255 | output = 0x0; |
shreeshas95 | 1:a0055b3280c8 | 256 | de_4 = 0; |
shreeshas95 | 1:a0055b3280c8 | 257 | } |
shreeshas95 | 1:a0055b3280c8 | 258 | else if(input <= 12){ |
shreeshas95 | 1:a0055b3280c8 | 259 | // DE = 01; |
shreeshas95 | 1:a0055b3280c8 | 260 | output = 0x1; |
shreeshas95 | 1:a0055b3280c8 | 261 | de_4 = 2; |
shreeshas95 | 1:a0055b3280c8 | 262 | } |
shreeshas95 | 1:a0055b3280c8 | 263 | else if(input <= 48){ |
shreeshas95 | 1:a0055b3280c8 | 264 | // DE = 10 |
shreeshas95 | 1:a0055b3280c8 | 265 | output = 0x2; |
shreeshas95 | 1:a0055b3280c8 | 266 | de_4 = 4; |
shreeshas95 | 1:a0055b3280c8 | 267 | } |
shreeshas95 | 1:a0055b3280c8 | 268 | else { |
shreeshas95 | 1:a0055b3280c8 | 269 | // DE = 11 |
shreeshas95 | 1:a0055b3280c8 | 270 | output = 0x3; |
shreeshas95 | 1:a0055b3280c8 | 271 | de_4 = 6; |
shreeshas95 | 1:a0055b3280c8 | 272 | } |
shreeshas95 | 1:a0055b3280c8 | 273 | |
shreeshas95 | 1:a0055b3280c8 | 274 | unsigned short int temp = input >> de_4; |
shreeshas95 | 1:a0055b3280c8 | 275 | output += (temp ) << 2; |
shreeshas95 | 1:a0055b3280c8 | 276 | return output; |
shreeshas95 | 1:a0055b3280c8 | 277 | } |
shreeshas95 | 1:a0055b3280c8 | 278 | |
shreeshas95 | 1:a0055b3280c8 | 279 | |
shreeshas95 | 1:a0055b3280c8 | 280 | unsigned char SFP_compress5_BT(unsigned int input){ |
shreeshas95 | 1:a0055b3280c8 | 281 | int de_4 = 0; //number by which bin value need to be shifted |
shreeshas95 | 1:a0055b3280c8 | 282 | unsigned char output; |
shreeshas95 | 1:a0055b3280c8 | 283 | |
shreeshas95 | 1:a0055b3280c8 | 284 | if(input <= 15){ |
shreeshas95 | 1:a0055b3280c8 | 285 | // D = 0 [0] |
shreeshas95 | 1:a0055b3280c8 | 286 | output = 0x0; |
shreeshas95 | 1:a0055b3280c8 | 287 | de_4 = 0; |
shreeshas95 | 1:a0055b3280c8 | 288 | } |
shreeshas95 | 1:a0055b3280c8 | 289 | else if(input <= 60){ |
shreeshas95 | 1:a0055b3280c8 | 290 | // D = 1 |
shreeshas95 | 1:a0055b3280c8 | 291 | output = 0x1; |
shreeshas95 | 1:a0055b3280c8 | 292 | de_4 = 2; |
shreeshas95 | 1:a0055b3280c8 | 293 | } |
shreeshas95 | 1:a0055b3280c8 | 294 | |
shreeshas95 | 1:a0055b3280c8 | 295 | unsigned short int temp = input >> de_4; |
shreeshas95 | 1:a0055b3280c8 | 296 | output += (temp ) << 1; |
shreeshas95 | 1:a0055b3280c8 | 297 | |
shreeshas95 | 1:a0055b3280c8 | 298 | return output; |
shreeshas95 | 1:a0055b3280c8 | 299 | }; |
shreeshas95 | 1:a0055b3280c8 | 300 | |
shreeshas95 | 1:a0055b3280c8 | 301 | |
shreeshas95 | 1:a0055b3280c8 | 302 | unsigned char SFP_compress6_BT(unsigned int input){ |
shreeshas95 | 1:a0055b3280c8 | 303 | int de_4 = 0;; |
shreeshas95 | 1:a0055b3280c8 | 304 | unsigned char output; |
shreeshas95 | 1:a0055b3280c8 | 305 | |
shreeshas95 | 1:a0055b3280c8 | 306 | if(input <= 31){ |
shreeshas95 | 1:a0055b3280c8 | 307 | // E = 0 [0] |
shreeshas95 | 1:a0055b3280c8 | 308 | output = 0x0; |
shreeshas95 | 1:a0055b3280c8 | 309 | de_4 = 0; |
shreeshas95 | 1:a0055b3280c8 | 310 | } |
shreeshas95 | 1:a0055b3280c8 | 311 | else if(input <= 124){ |
shreeshas95 | 1:a0055b3280c8 | 312 | // E = 1 |
shreeshas95 | 1:a0055b3280c8 | 313 | output = 0x1; |
shreeshas95 | 1:a0055b3280c8 | 314 | de_4 = 2; |
shreeshas95 | 1:a0055b3280c8 | 315 | } |
shreeshas95 | 1:a0055b3280c8 | 316 | |
shreeshas95 | 1:a0055b3280c8 | 317 | |
shreeshas95 | 1:a0055b3280c8 | 318 | unsigned short int temp = input >> de_4; |
shreeshas95 | 1:a0055b3280c8 | 319 | output += (temp ) << 1; |
shreeshas95 | 1:a0055b3280c8 | 320 | |
shreeshas95 | 1:a0055b3280c8 | 321 | return output; |
shreeshas95 | 1:a0055b3280c8 | 322 | }; |
shreeshas95 | 1:a0055b3280c8 | 323 | |
shreeshas95 | 1:a0055b3280c8 | 324 | unsigned char SFP_compress7_AT(unsigned int input){ |
shreeshas95 | 1:a0055b3280c8 | 325 | int de_4 = 0; |
shreeshas95 | 1:a0055b3280c8 | 326 | unsigned char output; |
shreeshas95 | 1:a0055b3280c8 | 327 | |
shreeshas95 | 1:a0055b3280c8 | 328 | if(input <= 31){ |
shreeshas95 | 1:a0055b3280c8 | 329 | // DE = 00 [0] |
shreeshas95 | 1:a0055b3280c8 | 330 | output = 0x0; |
shreeshas95 | 1:a0055b3280c8 | 331 | de_4 = 0; |
shreeshas95 | 1:a0055b3280c8 | 332 | } |
shreeshas95 | 1:a0055b3280c8 | 333 | else if(input <= 124){ |
shreeshas95 | 1:a0055b3280c8 | 334 | // DE = 01 [1] |
shreeshas95 | 1:a0055b3280c8 | 335 | output = 0x1; |
shreeshas95 | 1:a0055b3280c8 | 336 | de_4 = 2; |
shreeshas95 | 1:a0055b3280c8 | 337 | } |
shreeshas95 | 1:a0055b3280c8 | 338 | |
shreeshas95 | 1:a0055b3280c8 | 339 | else if(input <= 496){ |
shreeshas95 | 1:a0055b3280c8 | 340 | // DE = 10 [2] |
shreeshas95 | 1:a0055b3280c8 | 341 | output = 0x2; |
shreeshas95 | 1:a0055b3280c8 | 342 | de_4 = 4; |
shreeshas95 | 1:a0055b3280c8 | 343 | } |
shreeshas95 | 1:a0055b3280c8 | 344 | |
shreeshas95 | 1:a0055b3280c8 | 345 | else if(input <= 1984){ |
shreeshas95 | 1:a0055b3280c8 | 346 | // DE = 11 [3] |
shreeshas95 | 1:a0055b3280c8 | 347 | output = 0x3; |
shreeshas95 | 1:a0055b3280c8 | 348 | de_4 = 6; |
shreeshas95 | 1:a0055b3280c8 | 349 | } |
shreeshas95 | 1:a0055b3280c8 | 350 | |
shreeshas95 | 1:a0055b3280c8 | 351 | unsigned short int temp = input >> de_4; |
shreeshas95 | 1:a0055b3280c8 | 352 | output += (temp ) << 2; |
shreeshas95 | 1:a0055b3280c8 | 353 | |
shreeshas95 | 1:a0055b3280c8 | 354 | return output; |
shreeshas95 | 1:a0055b3280c8 | 355 | |
shreeshas95 | 1:a0055b3280c8 | 356 | }; |
shreeshas95 | 1:a0055b3280c8 | 357 | |
shreeshas95 | 1:a0055b3280c8 | 358 | |
shreeshas95 | 1:a0055b3280c8 | 359 | unsigned char SFP_compress8_AT(unsigned int input){ |
shreeshas95 | 1:a0055b3280c8 | 360 | |
shreeshas95 | 1:a0055b3280c8 | 361 | int de_4 = 0;; |
shreeshas95 | 1:a0055b3280c8 | 362 | unsigned char output; |
shreeshas95 | 1:a0055b3280c8 | 363 | |
shreeshas95 | 1:a0055b3280c8 | 364 | if(input <= 63){ |
shreeshas95 | 1:a0055b3280c8 | 365 | // DE = 00 [0] |
shreeshas95 | 1:a0055b3280c8 | 366 | output = 0x0; |
shreeshas95 | 1:a0055b3280c8 | 367 | de_4 = 0; |
shreeshas95 | 1:a0055b3280c8 | 368 | } |
shreeshas95 | 1:a0055b3280c8 | 369 | else if(input <= 252){ |
shreeshas95 | 1:a0055b3280c8 | 370 | // DE = 01 [1] |
shreeshas95 | 1:a0055b3280c8 | 371 | output = 0x1; |
shreeshas95 | 1:a0055b3280c8 | 372 | de_4 = 2; |
shreeshas95 | 1:a0055b3280c8 | 373 | } |
shreeshas95 | 1:a0055b3280c8 | 374 | |
shreeshas95 | 1:a0055b3280c8 | 375 | else if(input <= 1008){ |
shreeshas95 | 1:a0055b3280c8 | 376 | // DE = 10 [2] |
shreeshas95 | 1:a0055b3280c8 | 377 | output = 0x2; |
shreeshas95 | 1:a0055b3280c8 | 378 | de_4 = 4; |
shreeshas95 | 1:a0055b3280c8 | 379 | } |
shreeshas95 | 1:a0055b3280c8 | 380 | |
shreeshas95 | 1:a0055b3280c8 | 381 | else { |
shreeshas95 | 1:a0055b3280c8 | 382 | // DE = 11 [3] |
shreeshas95 | 1:a0055b3280c8 | 383 | output = 0x3; |
shreeshas95 | 1:a0055b3280c8 | 384 | de_4 = 6; |
shreeshas95 | 1:a0055b3280c8 | 385 | } |
shreeshas95 | 1:a0055b3280c8 | 386 | |
shreeshas95 | 1:a0055b3280c8 | 387 | unsigned short int temp = input >> de_4; |
shreeshas95 | 1:a0055b3280c8 | 388 | output += (temp ) << 2; |
shreeshas95 | 1:a0055b3280c8 | 389 | |
shreeshas95 | 1:a0055b3280c8 | 390 | return output; |
shreeshas95 | 1:a0055b3280c8 | 391 | }; |
shreeshas95 | 1:a0055b3280c8 | 392 | |
shreeshas95 | 1:a0055b3280c8 | 393 | unsigned char SFP_compress5_AT(unsigned int input){ |
shreeshas95 | 1:a0055b3280c8 | 394 | int de_4 = 0;; |
shreeshas95 | 1:a0055b3280c8 | 395 | unsigned char output; |
shreeshas95 | 1:a0055b3280c8 | 396 | |
shreeshas95 | 1:a0055b3280c8 | 397 | if(input <= 3){ |
shreeshas95 | 1:a0055b3280c8 | 398 | // DE = 000 [0] |
shreeshas95 | 1:a0055b3280c8 | 399 | output = 0x0; |
shreeshas95 | 1:a0055b3280c8 | 400 | de_4 = 0; |
shreeshas95 | 1:a0055b3280c8 | 401 | } |
shreeshas95 | 1:a0055b3280c8 | 402 | else if(input <= 12){ |
shreeshas95 | 1:a0055b3280c8 | 403 | // DE = 001 [1] |
shreeshas95 | 1:a0055b3280c8 | 404 | output = 0x1; |
shreeshas95 | 1:a0055b3280c8 | 405 | de_4 = 2; |
shreeshas95 | 1:a0055b3280c8 | 406 | } |
shreeshas95 | 1:a0055b3280c8 | 407 | |
shreeshas95 | 1:a0055b3280c8 | 408 | else if(input <= 48){ |
shreeshas95 | 1:a0055b3280c8 | 409 | // DE = 010 [2] |
shreeshas95 | 1:a0055b3280c8 | 410 | output = 0x2; |
shreeshas95 | 1:a0055b3280c8 | 411 | de_4 = 4; |
shreeshas95 | 1:a0055b3280c8 | 412 | } |
shreeshas95 | 1:a0055b3280c8 | 413 | |
shreeshas95 | 1:a0055b3280c8 | 414 | else if(input <= 192) { |
shreeshas95 | 1:a0055b3280c8 | 415 | // DE = 011 [3] |
shreeshas95 | 1:a0055b3280c8 | 416 | output = 0x3; |
shreeshas95 | 1:a0055b3280c8 | 417 | de_4 = 6; |
shreeshas95 | 1:a0055b3280c8 | 418 | } |
shreeshas95 | 1:a0055b3280c8 | 419 | |
shreeshas95 | 1:a0055b3280c8 | 420 | else if(input <= 768) { |
shreeshas95 | 1:a0055b3280c8 | 421 | // DE = 100 [4] |
shreeshas95 | 1:a0055b3280c8 | 422 | output = 0x4; |
shreeshas95 | 1:a0055b3280c8 | 423 | de_4 = 8; |
shreeshas95 | 1:a0055b3280c8 | 424 | } |
shreeshas95 | 1:a0055b3280c8 | 425 | |
shreeshas95 | 1:a0055b3280c8 | 426 | else if(input <= 3072) { |
shreeshas95 | 1:a0055b3280c8 | 427 | // DE = 101 [5] |
shreeshas95 | 1:a0055b3280c8 | 428 | output = 0x5; |
shreeshas95 | 1:a0055b3280c8 | 429 | de_4 = 10; |
shreeshas95 | 1:a0055b3280c8 | 430 | } |
shreeshas95 | 1:a0055b3280c8 | 431 | |
shreeshas95 | 1:a0055b3280c8 | 432 | else if(input <= 12288) { |
shreeshas95 | 1:a0055b3280c8 | 433 | // DE = 110 [6] |
shreeshas95 | 1:a0055b3280c8 | 434 | output = 0x6; |
shreeshas95 | 1:a0055b3280c8 | 435 | de_4 = 12; |
shreeshas95 | 1:a0055b3280c8 | 436 | } |
shreeshas95 | 1:a0055b3280c8 | 437 | |
shreeshas95 | 1:a0055b3280c8 | 438 | else { |
shreeshas95 | 1:a0055b3280c8 | 439 | // DE = 111 [7] |
shreeshas95 | 1:a0055b3280c8 | 440 | output = 0x7; |
shreeshas95 | 1:a0055b3280c8 | 441 | de_4 = 14; |
shreeshas95 | 1:a0055b3280c8 | 442 | } |
shreeshas95 | 1:a0055b3280c8 | 443 | |
shreeshas95 | 1:a0055b3280c8 | 444 | unsigned short int temp = input >> de_4; |
shreeshas95 | 1:a0055b3280c8 | 445 | output += (temp ) << 3; |
shreeshas95 | 1:a0055b3280c8 | 446 | |
shreeshas95 | 1:a0055b3280c8 | 447 | return output; |
shreeshas95 | 1:a0055b3280c8 | 448 | } |
shreeshas95 | 1:a0055b3280c8 | 449 | |
shreeshas95 | 1:a0055b3280c8 | 450 | unsigned char SFP_compress7FC_AT(unsigned int input){ // for fast chain above threshold |
shreeshas95 | 1:a0055b3280c8 | 451 | int de_4 = 0;; |
shreeshas95 | 1:a0055b3280c8 | 452 | unsigned char output; |
shreeshas95 | 1:a0055b3280c8 | 453 | |
shreeshas95 | 1:a0055b3280c8 | 454 | if(input <= 15){ |
shreeshas95 | 1:a0055b3280c8 | 455 | // DE = 000 [0] |
shreeshas95 | 1:a0055b3280c8 | 456 | output = 0x0; |
shreeshas95 | 1:a0055b3280c8 | 457 | de_4 = 0; |
shreeshas95 | 1:a0055b3280c8 | 458 | } |
shreeshas95 | 1:a0055b3280c8 | 459 | else if(input <= 60){ |
shreeshas95 | 1:a0055b3280c8 | 460 | // DE = 001 [1] |
shreeshas95 | 1:a0055b3280c8 | 461 | output = 0x1; |
shreeshas95 | 1:a0055b3280c8 | 462 | de_4 = 2; |
shreeshas95 | 1:a0055b3280c8 | 463 | } |
shreeshas95 | 1:a0055b3280c8 | 464 | |
shreeshas95 | 1:a0055b3280c8 | 465 | else if(input <= 240){ |
shreeshas95 | 1:a0055b3280c8 | 466 | // DE = 010 [2] |
shreeshas95 | 1:a0055b3280c8 | 467 | output = 0x2; |
shreeshas95 | 1:a0055b3280c8 | 468 | de_4 = 4; |
shreeshas95 | 1:a0055b3280c8 | 469 | } |
shreeshas95 | 1:a0055b3280c8 | 470 | |
shreeshas95 | 1:a0055b3280c8 | 471 | else if(input <= 960) { |
shreeshas95 | 1:a0055b3280c8 | 472 | // DE = 011 [3] |
shreeshas95 | 1:a0055b3280c8 | 473 | output = 0x3; |
shreeshas95 | 1:a0055b3280c8 | 474 | de_4 = 6; |
shreeshas95 | 1:a0055b3280c8 | 475 | } |
shreeshas95 | 1:a0055b3280c8 | 476 | |
shreeshas95 | 1:a0055b3280c8 | 477 | else if(input <= 3840) { |
shreeshas95 | 1:a0055b3280c8 | 478 | // DE = 100 [4] |
shreeshas95 | 1:a0055b3280c8 | 479 | output = 0x4; |
shreeshas95 | 1:a0055b3280c8 | 480 | de_4 = 8; |
shreeshas95 | 1:a0055b3280c8 | 481 | } |
shreeshas95 | 1:a0055b3280c8 | 482 | |
shreeshas95 | 1:a0055b3280c8 | 483 | else if(input <= 15360) { |
shreeshas95 | 1:a0055b3280c8 | 484 | // DE = 101 [5] |
shreeshas95 | 1:a0055b3280c8 | 485 | output = 0x5; |
shreeshas95 | 1:a0055b3280c8 | 486 | de_4 = 10; |
shreeshas95 | 1:a0055b3280c8 | 487 | } |
shreeshas95 | 1:a0055b3280c8 | 488 | |
shreeshas95 | 1:a0055b3280c8 | 489 | else if(input <= 61440) { |
shreeshas95 | 1:a0055b3280c8 | 490 | // DE = 110 [6] |
shreeshas95 | 1:a0055b3280c8 | 491 | output = 0x6; |
shreeshas95 | 1:a0055b3280c8 | 492 | de_4 = 12; |
shreeshas95 | 1:a0055b3280c8 | 493 | } |
shreeshas95 | 1:a0055b3280c8 | 494 | |
shreeshas95 | 1:a0055b3280c8 | 495 | else { |
shreeshas95 | 1:a0055b3280c8 | 496 | // DE = 111 [7] |
shreeshas95 | 1:a0055b3280c8 | 497 | output = 0x7; |
shreeshas95 | 1:a0055b3280c8 | 498 | de_4 = 14; |
shreeshas95 | 1:a0055b3280c8 | 499 | } |
shreeshas95 | 1:a0055b3280c8 | 500 | |
shreeshas95 | 1:a0055b3280c8 | 501 | unsigned short int temp = input >> de_4; |
shreeshas95 | 1:a0055b3280c8 | 502 | output += (temp ) << 3; |
shreeshas95 | 1:a0055b3280c8 | 503 | |
shreeshas95 | 1:a0055b3280c8 | 504 | return output; |
shreeshas95 | 1:a0055b3280c8 | 505 | } |
shreeshas95 | 1:a0055b3280c8 | 506 | |
shreeshas95 | 1:a0055b3280c8 | 507 | |
shreeshas95 | 1:a0055b3280c8 | 508 | |
shreeshas95 | 1:a0055b3280c8 | 509 | //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
shreeshas95 | 1:a0055b3280c8 | 510 | unsigned char SCP_compress6(unsigned int input){ |
shreeshas95 | 1:a0055b3280c8 | 511 | int ef_4; |
shreeshas95 | 1:a0055b3280c8 | 512 | unsigned char output; |
shreeshas95 | 1:a0055b3280c8 | 513 | |
shreeshas95 | 1:a0055b3280c8 | 514 | if(input <= 15){ |
shreeshas95 | 1:a0055b3280c8 | 515 | // EF = 00 |
shreeshas95 | 1:a0055b3280c8 | 516 | output = 0x0; |
shreeshas95 | 1:a0055b3280c8 | 517 | ef_4 = 0; |
shreeshas95 | 1:a0055b3280c8 | 518 | } |
shreeshas95 | 1:a0055b3280c8 | 519 | |
shreeshas95 | 1:a0055b3280c8 | 520 | else if(input <= 60 ){ |
shreeshas95 | 1:a0055b3280c8 | 521 | // EF = 01 [1] |
shreeshas95 | 1:a0055b3280c8 | 522 | output = 0x01; |
shreeshas95 | 1:a0055b3280c8 | 523 | ef_4 = 2; |
shreeshas95 | 1:a0055b3280c8 | 524 | } |
shreeshas95 | 1:a0055b3280c8 | 525 | else if(input <= 240){ |
shreeshas95 | 1:a0055b3280c8 | 526 | // EF = 10 [2] |
shreeshas95 | 1:a0055b3280c8 | 527 | output = 0x02; |
shreeshas95 | 1:a0055b3280c8 | 528 | ef_4 = 4; |
shreeshas95 | 1:a0055b3280c8 | 529 | } |
shreeshas95 | 1:a0055b3280c8 | 530 | else{ |
shreeshas95 | 1:a0055b3280c8 | 531 | // EF = 11 [3] |
shreeshas95 | 1:a0055b3280c8 | 532 | output = 0x03; |
shreeshas95 | 1:a0055b3280c8 | 533 | ef_4 = 6; |
shreeshas95 | 1:a0055b3280c8 | 534 | } |
shreeshas95 | 1:a0055b3280c8 | 535 | |
shreeshas95 | 1:a0055b3280c8 | 536 | unsigned short int temp = input >> ef_4; |
shreeshas95 | 1:a0055b3280c8 | 537 | output += (temp & 0xf) << 2; |
shreeshas95 | 1:a0055b3280c8 | 538 | |
shreeshas95 | 1:a0055b3280c8 | 539 | return output; |
shreeshas95 | 1:a0055b3280c8 | 540 | } |
shreeshas95 | 1:a0055b3280c8 | 541 | |
shreeshas95 | 1:a0055b3280c8 | 542 | unsigned char SCP_compress5(unsigned int input){ |
shreeshas95 | 1:a0055b3280c8 | 543 | |
shreeshas95 | 1:a0055b3280c8 | 544 | int de_4 = 0;; |
shreeshas95 | 1:a0055b3280c8 | 545 | unsigned char output; |
shreeshas95 | 1:a0055b3280c8 | 546 | |
shreeshas95 | 1:a0055b3280c8 | 547 | if(input <= 7){ |
shreeshas95 | 1:a0055b3280c8 | 548 | // DE = 00 [0] |
shreeshas95 | 1:a0055b3280c8 | 549 | output = 0x0; |
shreeshas95 | 1:a0055b3280c8 | 550 | de_4 = 0; |
shreeshas95 | 1:a0055b3280c8 | 551 | } |
shreeshas95 | 1:a0055b3280c8 | 552 | |
shreeshas95 | 1:a0055b3280c8 | 553 | else if(input <= 28){ |
shreeshas95 | 1:a0055b3280c8 | 554 | // DE = 01 [1] |
shreeshas95 | 1:a0055b3280c8 | 555 | output = 0x01; |
shreeshas95 | 1:a0055b3280c8 | 556 | de_4 = 2; |
shreeshas95 | 1:a0055b3280c8 | 557 | } |
shreeshas95 | 1:a0055b3280c8 | 558 | else if(input <= 112){ |
shreeshas95 | 1:a0055b3280c8 | 559 | // DE = 10 [2] |
shreeshas95 | 1:a0055b3280c8 | 560 | output = 0x02; |
shreeshas95 | 1:a0055b3280c8 | 561 | de_4 = 4; |
shreeshas95 | 1:a0055b3280c8 | 562 | } |
shreeshas95 | 1:a0055b3280c8 | 563 | else{ |
shreeshas95 | 1:a0055b3280c8 | 564 | // DE = 11 [3] |
shreeshas95 | 1:a0055b3280c8 | 565 | output = 0x03; |
shreeshas95 | 1:a0055b3280c8 | 566 | de_4 = 6; |
shreeshas95 | 1:a0055b3280c8 | 567 | } |
shreeshas95 | 1:a0055b3280c8 | 568 | |
shreeshas95 | 1:a0055b3280c8 | 569 | unsigned short int temp = input >> de_4; |
shreeshas95 | 1:a0055b3280c8 | 570 | output += (temp & 0x7) << 2; |
shreeshas95 | 1:a0055b3280c8 | 571 | |
shreeshas95 | 1:a0055b3280c8 | 572 | return output; |
shreeshas95 | 1:a0055b3280c8 | 573 | } |
shreeshas95 | 1:a0055b3280c8 | 574 | |
shreeshas95 | 1:a0055b3280c8 | 575 | unsigned char SCP_compress6h(unsigned int input) { |
shreeshas95 | 1:a0055b3280c8 | 576 | |
shreeshas95 | 1:a0055b3280c8 | 577 | int ef_4; |
shreeshas95 | 1:a0055b3280c8 | 578 | unsigned char output; |
shreeshas95 | 1:a0055b3280c8 | 579 | |
shreeshas95 | 1:a0055b3280c8 | 580 | if(input <=7){ |
shreeshas95 | 1:a0055b3280c8 | 581 | // EF = 000 [0] |
shreeshas95 | 1:a0055b3280c8 | 582 | output = 0x00; |
shreeshas95 | 1:a0055b3280c8 | 583 | ef_4 = 0; |
shreeshas95 | 1:a0055b3280c8 | 584 | } |
shreeshas95 | 1:a0055b3280c8 | 585 | |
shreeshas95 | 1:a0055b3280c8 | 586 | else if(input <=28){ |
shreeshas95 | 1:a0055b3280c8 | 587 | // EF = 001 [1] |
shreeshas95 | 1:a0055b3280c8 | 588 | output = 0x01; |
shreeshas95 | 1:a0055b3280c8 | 589 | ef_4 = 2; |
shreeshas95 | 1:a0055b3280c8 | 590 | } |
shreeshas95 | 1:a0055b3280c8 | 591 | else if(input <= 112){ |
shreeshas95 | 1:a0055b3280c8 | 592 | |
shreeshas95 | 1:a0055b3280c8 | 593 | // EF = 010 [2] |
shreeshas95 | 1:a0055b3280c8 | 594 | output = 0x02; |
shreeshas95 | 1:a0055b3280c8 | 595 | ef_4 = 4; |
shreeshas95 | 1:a0055b3280c8 | 596 | } |
shreeshas95 | 1:a0055b3280c8 | 597 | else if(input <= 448){ |
shreeshas95 | 1:a0055b3280c8 | 598 | // EF = 011 [3] |
shreeshas95 | 1:a0055b3280c8 | 599 | output = 0x03; |
shreeshas95 | 1:a0055b3280c8 | 600 | ef_4 = 6; |
shreeshas95 | 1:a0055b3280c8 | 601 | } |
shreeshas95 | 1:a0055b3280c8 | 602 | else if(input <= 1792){ |
shreeshas95 | 1:a0055b3280c8 | 603 | // EF = 100 [4] |
shreeshas95 | 1:a0055b3280c8 | 604 | output = 0x04; |
shreeshas95 | 1:a0055b3280c8 | 605 | ef_4 = 8; |
shreeshas95 | 1:a0055b3280c8 | 606 | |
shreeshas95 | 1:a0055b3280c8 | 607 | } |
shreeshas95 | 1:a0055b3280c8 | 608 | else if(input <= 7168){ |
shreeshas95 | 1:a0055b3280c8 | 609 | // EF = 101 [5] |
shreeshas95 | 1:a0055b3280c8 | 610 | output = 0x05; |
shreeshas95 | 1:a0055b3280c8 | 611 | ef_4 = 10; |
shreeshas95 | 1:a0055b3280c8 | 612 | |
shreeshas95 | 1:a0055b3280c8 | 613 | } |
shreeshas95 | 1:a0055b3280c8 | 614 | else if(input <= 28672){ |
shreeshas95 | 1:a0055b3280c8 | 615 | // EF = 110 [6] |
shreeshas95 | 1:a0055b3280c8 | 616 | output = 0x06; |
shreeshas95 | 1:a0055b3280c8 | 617 | ef_4 = 12; |
shreeshas95 | 1:a0055b3280c8 | 618 | } |
shreeshas95 | 1:a0055b3280c8 | 619 | else{ |
shreeshas95 | 1:a0055b3280c8 | 620 | // EF = 111 [7] |
shreeshas95 | 1:a0055b3280c8 | 621 | output = 0x07; |
shreeshas95 | 1:a0055b3280c8 | 622 | ef_4 =14; |
shreeshas95 | 1:a0055b3280c8 | 623 | } |
shreeshas95 | 1:a0055b3280c8 | 624 | |
shreeshas95 | 1:a0055b3280c8 | 625 | unsigned short int temp = input >> ef_4; |
shreeshas95 | 1:a0055b3280c8 | 626 | output += (temp & 0x7) << 3; |
shreeshas95 | 1:a0055b3280c8 | 627 | |
shreeshas95 | 1:a0055b3280c8 | 628 | return output; |
shreeshas95 | 1:a0055b3280c8 | 629 | |
shreeshas95 | 1:a0055b3280c8 | 630 | } |
shreeshas95 | 1:a0055b3280c8 | 631 | |
shreeshas95 | 1:a0055b3280c8 | 632 | |
shreeshas95 | 1:a0055b3280c8 | 633 | unsigned char SCP_compress7h(unsigned int input) { |
shreeshas95 | 1:a0055b3280c8 | 634 | |
shreeshas95 | 1:a0055b3280c8 | 635 | int fg_4; |
shreeshas95 | 1:a0055b3280c8 | 636 | unsigned char output; |
shreeshas95 | 1:a0055b3280c8 | 637 | |
shreeshas95 | 1:a0055b3280c8 | 638 | if(input <= 15){ |
shreeshas95 | 1:a0055b3280c8 | 639 | // EF = 000 [0] |
shreeshas95 | 1:a0055b3280c8 | 640 | output = 0x0; |
shreeshas95 | 1:a0055b3280c8 | 641 | fg_4 = 0; |
shreeshas95 | 1:a0055b3280c8 | 642 | } |
shreeshas95 | 1:a0055b3280c8 | 643 | |
shreeshas95 | 1:a0055b3280c8 | 644 | else if(input <= 60){ |
shreeshas95 | 1:a0055b3280c8 | 645 | // EF = 001 [1] |
shreeshas95 | 1:a0055b3280c8 | 646 | output = 0x01; |
shreeshas95 | 1:a0055b3280c8 | 647 | fg_4 = 2; |
shreeshas95 | 1:a0055b3280c8 | 648 | } |
shreeshas95 | 1:a0055b3280c8 | 649 | else if(input <= 240){ |
shreeshas95 | 1:a0055b3280c8 | 650 | |
shreeshas95 | 1:a0055b3280c8 | 651 | // EF = 010 [2] |
shreeshas95 | 1:a0055b3280c8 | 652 | output = 0x02; |
shreeshas95 | 1:a0055b3280c8 | 653 | fg_4 = 4; |
shreeshas95 | 1:a0055b3280c8 | 654 | } |
shreeshas95 | 1:a0055b3280c8 | 655 | else if(input <= 960){ |
shreeshas95 | 1:a0055b3280c8 | 656 | // EF = 011 [3] |
shreeshas95 | 1:a0055b3280c8 | 657 | output = 0x03; |
shreeshas95 | 1:a0055b3280c8 | 658 | fg_4 = 6; |
shreeshas95 | 1:a0055b3280c8 | 659 | } |
shreeshas95 | 1:a0055b3280c8 | 660 | else if(input <= 3840){ |
shreeshas95 | 1:a0055b3280c8 | 661 | // EF = 100 [4] |
shreeshas95 | 1:a0055b3280c8 | 662 | output = 0x04; |
shreeshas95 | 1:a0055b3280c8 | 663 | fg_4 = 8; |
shreeshas95 | 1:a0055b3280c8 | 664 | |
shreeshas95 | 1:a0055b3280c8 | 665 | } |
shreeshas95 | 1:a0055b3280c8 | 666 | else if(input <= 15360){ |
shreeshas95 | 1:a0055b3280c8 | 667 | // EF = 101 [5] |
shreeshas95 | 1:a0055b3280c8 | 668 | output = 0x05; |
shreeshas95 | 1:a0055b3280c8 | 669 | fg_4 = 10; |
shreeshas95 | 1:a0055b3280c8 | 670 | |
shreeshas95 | 1:a0055b3280c8 | 671 | } |
shreeshas95 | 1:a0055b3280c8 | 672 | else if(input <= 61440){ |
shreeshas95 | 1:a0055b3280c8 | 673 | // EF = 110 [6] |
shreeshas95 | 1:a0055b3280c8 | 674 | output = 0x06; |
shreeshas95 | 1:a0055b3280c8 | 675 | fg_4 = 12; |
shreeshas95 | 1:a0055b3280c8 | 676 | } |
shreeshas95 | 1:a0055b3280c8 | 677 | else{ |
shreeshas95 | 1:a0055b3280c8 | 678 | // EF = 111 [7] |
shreeshas95 | 1:a0055b3280c8 | 679 | output = 0x07; |
shreeshas95 | 1:a0055b3280c8 | 680 | fg_4 =14; |
shreeshas95 | 1:a0055b3280c8 | 681 | } |
shreeshas95 | 1:a0055b3280c8 | 682 | |
shreeshas95 | 1:a0055b3280c8 | 683 | unsigned short int temp = input >> fg_4; |
shreeshas95 | 1:a0055b3280c8 | 684 | output += (temp & 0xf) << 3; |
shreeshas95 | 1:a0055b3280c8 | 685 | |
shreeshas95 | 1:a0055b3280c8 | 686 | return output; |
shreeshas95 | 1:a0055b3280c8 | 687 | |
shreeshas95 | 1:a0055b3280c8 | 688 | } |
shreeshas95 | 1:a0055b3280c8 | 689 | //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
shreeshas95 | 1:a0055b3280c8 | 690 | void SCP_compress_data(); |
shreeshas95 | 1:a0055b3280c8 | 691 | void SFP_compress_data(unsigned char* input){ |
shreeshas95 | 1:a0055b3280c8 | 692 | |
shreeshas95 | 1:a0055b3280c8 | 693 | bool LCR = true; |
shreeshas95 | 1:a0055b3280c8 | 694 | int i = 0; |
shreeshas95 | 1:a0055b3280c8 | 695 | static int packet_no = 0; //takes value from 0 to 29 |
shreeshas95 | 1:a0055b3280c8 | 696 | //TRAVERSE THE LIST TO DETERMINE LCR OR HCR and stroing the values in proton_bin and electron bin |
shreeshas95 | 1:a0055b3280c8 | 697 | SFP_bin[0] = *input; |
shreeshas95 | 1:a0055b3280c8 | 698 | for(i=1 ; i<= NUM_PROTON_BIN + NUM_ELECTRON_BIN + VETO ; ++i){ //storing the bin values into an array name bin |
shreeshas95 | 1:a0055b3280c8 | 699 | SFP_bin[i]=read_2byte(input+1+((i-1)<<1)); //proton bin and elecron bin are 2 byte, hence read_2byte and |
shreeshas95 | 1:a0055b3280c8 | 700 | SCP_bin[i]+=SFP_bin[i]; |
shreeshas95 | 1:a0055b3280c8 | 701 | if(SFP_bin[i] > SFP_thresholds[i]){ //fast cahin is 4 byte hence read_4byte |
shreeshas95 | 1:a0055b3280c8 | 702 | LCR = false; // if a single value is above threshold then lcr becomes false |
shreeshas95 | 1:a0055b3280c8 | 703 | i++; |
shreeshas95 | 1:a0055b3280c8 | 704 | break; |
shreeshas95 | 1:a0055b3280c8 | 705 | } |
shreeshas95 | 1:a0055b3280c8 | 706 | } |
shreeshas95 | 1:a0055b3280c8 | 707 | |
shreeshas95 | 1:a0055b3280c8 | 708 | for( ; i<= NUM_PROTON_BIN + NUM_ELECTRON_BIN + VETO ; ++i){ |
shreeshas95 | 1:a0055b3280c8 | 709 | SCP_bin[i]+=SFP_bin[i]; |
shreeshas95 | 1:a0055b3280c8 | 710 | SFP_bin[i] = read_2byte(input + 1 + ( (i-1)<<1) ); |
shreeshas95 | 1:a0055b3280c8 | 711 | } |
shreeshas95 | 1:a0055b3280c8 | 712 | |
shreeshas95 | 1:a0055b3280c8 | 713 | SFP_bin[i] = read_4byte(input+1+ ((i-1)<<1)) ; |
shreeshas95 | 1:a0055b3280c8 | 714 | SCP_bin[i]+=SFP_bin[i]; |
shreeshas95 | 1:a0055b3280c8 | 715 | |
shreeshas95 | 1:a0055b3280c8 | 716 | if(SFP_bin[i]>SFP_thresholds[i]) |
shreeshas95 | 1:a0055b3280c8 | 717 | LCR = false; //since veto starts from location (input + 65) and (input + 69) |
shreeshas95 | 1:a0055b3280c8 | 718 | |
shreeshas95 | 1:a0055b3280c8 | 719 | SFP_bin[i+1] = read_4byte(input+69); |
shreeshas95 | 1:a0055b3280c8 | 720 | SCP_bin[i]+=SFP_bin[i]; |
shreeshas95 | 1:a0055b3280c8 | 721 | |
shreeshas95 | 1:a0055b3280c8 | 722 | if(SFP_bin[i]>SFP_thresholds[i]) |
shreeshas95 | 1:a0055b3280c8 | 723 | LCR = false; |
shreeshas95 | 1:a0055b3280c8 | 724 | |
shreeshas95 | 1:a0055b3280c8 | 725 | |
shreeshas95 | 1:a0055b3280c8 | 726 | // printf("\n"); //for printing the sfp bin |
shreeshas95 | 1:a0055b3280c8 | 727 | // for (i=0;i<35;i++){ |
shreeshas95 | 1:a0055b3280c8 | 728 | // printf("sfp[%d] = %d",i,SFP_bin[i]); |
shreeshas95 | 1:a0055b3280c8 | 729 | // } |
shreeshas95 | 1:a0055b3280c8 | 730 | // printf("\n"); |
shreeshas95 | 1:a0055b3280c8 | 731 | |
shreeshas95 | 1:a0055b3280c8 | 732 | if(LCR){ |
shreeshas95 | 1:a0055b3280c8 | 733 | |
shreeshas95 | 1:a0055b3280c8 | 734 | SFP_outputBT[0] = (packet_no<<3) + ( SFP_compress5_BT(SFP_bin[1])>>2 ); |
shreeshas95 | 1:a0055b3280c8 | 735 | 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 | 1:a0055b3280c8 | 736 | SFP_outputBT[2] = ( SFP_compress5_BT(SFP_bin[3])<<4 ) + ( SFP_compress5_BT(SFP_bin[4])>>1 ); |
shreeshas95 | 1:a0055b3280c8 | 737 | 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 | 1:a0055b3280c8 | 738 | SFP_outputBT[4] = ( SFP_compress5_BT(SFP_bin[6])<<5 ) + ( SFP_compress5_BT(SFP_bin[7]) ); |
shreeshas95 | 1:a0055b3280c8 | 739 | SFP_outputBT[5] = ( SFP_compress5_BT(SFP_bin[8])<<3 ) + ( SFP_compress5_BT(SFP_bin[9])>>2 ); |
shreeshas95 | 1:a0055b3280c8 | 740 | 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 | 1:a0055b3280c8 | 741 | SFP_outputBT[7] = ( SFP_compress5_BT(SFP_bin[11])<<4 ) + ( SFP_compress5_BT(SFP_bin[12])>>1 ); |
shreeshas95 | 1:a0055b3280c8 | 742 | 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 | 1:a0055b3280c8 | 743 | SFP_outputBT[9] = ( SFP_compress5_BT(SFP_bin[14])<<5 ) + ( SFP_compress5_BT(SFP_bin[15]) ); |
shreeshas95 | 1:a0055b3280c8 | 744 | SFP_outputBT[10] = ( SFP_compress5_BT(SFP_bin[16])<<3 ) + ( SFP_compress5_BT(SFP_bin[17])>>2 ); |
shreeshas95 | 1:a0055b3280c8 | 745 | SFP_outputBT[11] = ( SFP_compress5_BT(SFP_bin[17])<<6 ) + ( SFP_compress6_BT(SFP_bin[18]) ); |
shreeshas95 | 1:a0055b3280c8 | 746 | SFP_outputBT[12] = ( SFP_compress6_BT(SFP_bin[19])<<2 ) + ( SFP_compress6_BT(SFP_bin[20])>>4 ); |
shreeshas95 | 1:a0055b3280c8 | 747 | SFP_outputBT[13] = ( SFP_compress6_BT(SFP_bin[20])<<4 ) + ( SFP_compress5_BT(SFP_bin[21])>>1 ); |
shreeshas95 | 1:a0055b3280c8 | 748 | 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 | 1:a0055b3280c8 | 749 | SFP_outputBT[15] = ( SFP_compress5_BT(SFP_bin[23])<<5 ) + ( SFP_compress5_BT(SFP_bin[24]) ); |
shreeshas95 | 1:a0055b3280c8 | 750 | SFP_outputBT[16] = ( SFP_compress5_BT(SFP_bin[25])<<3 ) + ( SFP_compress5_BT(SFP_bin[26])>>2 ); |
shreeshas95 | 1:a0055b3280c8 | 751 | 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 | 1:a0055b3280c8 | 752 | SFP_outputBT[18] = ( SFP_compress5_BT(SFP_bin[28])<<4 ) + ( SFP_compress5_BT(SFP_bin[29])>>1) ; |
shreeshas95 | 1:a0055b3280c8 | 753 | 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 | 1:a0055b3280c8 | 754 | SFP_outputBT[20] = ( SFP_compress5_BT(SFP_bin[31])<<5 ) + ( SFP_compress4_BT(SFP_bin[32])<<1) + ( SCP_compress5(SFP_bin[33])>>4 ) ; // |
shreeshas95 | 1:a0055b3280c8 | 755 | 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 | 1:a0055b3280c8 | 756 | SFP_outputBT[22] = ( SCP_compress5(SFP_bin[34])<<7 ); //7 bits are spare |
shreeshas95 | 1:a0055b3280c8 | 757 | |
shreeshas95 | 1:a0055b3280c8 | 758 | Science_TMframe::making_frame(3,'L',SFP_outputBT); |
shreeshas95 | 1:a0055b3280c8 | 759 | if(++packet_no == 30){ |
shreeshas95 | 1:a0055b3280c8 | 760 | packet_no=0; |
shreeshas95 | 1:a0055b3280c8 | 761 | SCP_compress_data(); |
shreeshas95 | 1:a0055b3280c8 | 762 | for(i=0;i<PACKET_SEQUENCE_COUNT + NUM_PROTON_BIN + NUM_ELECTRON_BIN + VETO + FASTCHAIN;i++){ |
shreeshas95 | 1:a0055b3280c8 | 763 | if(packet_no==0){ |
shreeshas95 | 1:a0055b3280c8 | 764 | SCP_bin[i]=0; |
shreeshas95 | 1:a0055b3280c8 | 765 | } |
shreeshas95 | 1:a0055b3280c8 | 766 | } |
shreeshas95 | 1:a0055b3280c8 | 767 | } |
shreeshas95 | 1:a0055b3280c8 | 768 | |
shreeshas95 | 1:a0055b3280c8 | 769 | |
shreeshas95 | 1:a0055b3280c8 | 770 | } |
shreeshas95 | 1:a0055b3280c8 | 771 | |
shreeshas95 | 1:a0055b3280c8 | 772 | else { |
shreeshas95 | 1:a0055b3280c8 | 773 | |
shreeshas95 | 1:a0055b3280c8 | 774 | |
shreeshas95 | 1:a0055b3280c8 | 775 | SFP_outputAT[0] = (RTC_TIME>>27)&(0xff); |
shreeshas95 | 1:a0055b3280c8 | 776 | SFP_outputAT[1] = (RTC_TIME>>19)&(0xff); |
shreeshas95 | 1:a0055b3280c8 | 777 | SFP_outputAT[2] = (RTC_TIME>>11)&(0xff); |
shreeshas95 | 1:a0055b3280c8 | 778 | SFP_outputAT[3] = (RTC_TIME>>3 )&(0xff); |
shreeshas95 | 1:a0055b3280c8 | 779 | SFP_outputAT[4] = (RTC_TIME<<5 )&(0xff) + (packet_no); |
shreeshas95 | 1:a0055b3280c8 | 780 | SFP_outputAT[5] = ( SFP_compress7_AT(SFP_bin[1])<<1 ) + ( SFP_compress7_AT(SFP_bin[2])>>6 ); |
shreeshas95 | 1:a0055b3280c8 | 781 | SFP_outputAT[6] = ( SFP_compress7_AT(SFP_bin[2])<<2 ) + ( SFP_compress7_AT(SFP_bin[3])>>5 ); |
shreeshas95 | 1:a0055b3280c8 | 782 | SFP_outputAT[7] = ( SFP_compress7_AT(SFP_bin[3])<<3 ) + ( SFP_compress7_AT(SFP_bin[4])>>4 ); |
shreeshas95 | 1:a0055b3280c8 | 783 | SFP_outputAT[8] = ( SFP_compress7_AT(SFP_bin[4])<<4 ) + ( SFP_compress7_AT(SFP_bin[5])>>3 ); |
shreeshas95 | 1:a0055b3280c8 | 784 | SFP_outputAT[9] = ( SFP_compress7_AT(SFP_bin[5])<<5 ) + ( SFP_compress7_AT(SFP_bin[6])>>2 ); |
shreeshas95 | 1:a0055b3280c8 | 785 | SFP_outputAT[10] = ( SFP_compress7_AT(SFP_bin[6])<<6 ) + ( SFP_compress7_AT(SFP_bin[7])>>1 ); |
shreeshas95 | 1:a0055b3280c8 | 786 | SFP_outputAT[11] = ( SFP_compress7_AT(SFP_bin[7])<<7 ) + ( SFP_compress7_AT(SFP_bin[8]) ); |
shreeshas95 | 1:a0055b3280c8 | 787 | SFP_outputAT[12] = ( SFP_compress7_AT(SFP_bin[9])<<1 ) + ( SFP_compress7_AT(SFP_bin[10])>>6); |
shreeshas95 | 1:a0055b3280c8 | 788 | SFP_outputAT[13] = ( SFP_compress7_AT(SFP_bin[10])<<2 ) + ( SFP_compress7_AT(SFP_bin[11])>>5); |
shreeshas95 | 1:a0055b3280c8 | 789 | SFP_outputAT[14] = ( SFP_compress7_AT(SFP_bin[11])<<3 ) + ( SFP_compress7_AT(SFP_bin[12])>>4); |
shreeshas95 | 1:a0055b3280c8 | 790 | SFP_outputAT[15] = ( SFP_compress7_AT(SFP_bin[12])<<4 ) + ( SFP_compress7_AT(SFP_bin[13])>>3); |
shreeshas95 | 1:a0055b3280c8 | 791 | SFP_outputAT[16] = ( SFP_compress7_AT(SFP_bin[13])<<5 ) + ( SFP_compress7_AT(SFP_bin[14])>>2); |
shreeshas95 | 1:a0055b3280c8 | 792 | SFP_outputAT[17] = ( SFP_compress7_AT(SFP_bin[14])<<6 ) + ( SFP_compress7_AT(SFP_bin[15])>>1); |
shreeshas95 | 1:a0055b3280c8 | 793 | SFP_outputAT[18] = ( SFP_compress7_AT(SFP_bin[15])<<7 ) + ( SFP_compress7_AT(SFP_bin[16])); |
shreeshas95 | 1:a0055b3280c8 | 794 | SFP_outputAT[19] = ( SFP_compress7_AT(SFP_bin[17])<<1 ) + ( SFP_compress8_AT(SFP_bin[18])>>7 ); |
shreeshas95 | 1:a0055b3280c8 | 795 | SFP_outputAT[20] = ( SFP_compress8_AT(SFP_bin[18])<<1 ) + ( SFP_compress8_AT(SFP_bin[19])>>7 ); |
shreeshas95 | 1:a0055b3280c8 | 796 | SFP_outputAT[21] = ( SFP_compress8_AT(SFP_bin[19])<<1 ) + ( SFP_compress8_AT(SFP_bin[20])>>7 ); |
shreeshas95 | 1:a0055b3280c8 | 797 | SFP_outputAT[22] = ( SFP_compress8_AT(SFP_bin[20])<<1 ) + ( SFP_compress7_AT(SFP_bin[21])>>6 ); |
shreeshas95 | 1:a0055b3280c8 | 798 | SFP_outputAT[23] = ( SFP_compress7_AT(SFP_bin[21])<<2 ) + ( SFP_compress7_AT(SFP_bin[22])>>5 ); |
shreeshas95 | 1:a0055b3280c8 | 799 | SFP_outputAT[24] = ( SFP_compress7_AT(SFP_bin[22])<<3 ) + ( SFP_compress7_AT(SFP_bin[23])>>4 ); |
shreeshas95 | 1:a0055b3280c8 | 800 | SFP_outputAT[25] = ( SFP_compress7_AT(SFP_bin[23])<<4 ) + ( SFP_compress7_AT(SFP_bin[24])>>3 ); |
shreeshas95 | 1:a0055b3280c8 | 801 | SFP_outputAT[26] = ( SFP_compress7_AT(SFP_bin[24])<<5 ) + ( SFP_compress7_AT(SFP_bin[25])>>2 ); |
shreeshas95 | 1:a0055b3280c8 | 802 | SFP_outputAT[27] = ( SFP_compress7_AT(SFP_bin[25])<<6 ) + ( SFP_compress7_AT(SFP_bin[26])>>1 ); |
shreeshas95 | 1:a0055b3280c8 | 803 | SFP_outputAT[28] = ( SFP_compress7_AT(SFP_bin[26])<<7 ) + ( SFP_compress7_AT(SFP_bin[27]) ); |
shreeshas95 | 1:a0055b3280c8 | 804 | SFP_outputAT[29] = ( SFP_compress7_AT(SFP_bin[28])<<1 ) + ( SFP_compress7_AT(SFP_bin[29])>>6); |
shreeshas95 | 1:a0055b3280c8 | 805 | SFP_outputAT[30] = ( SFP_compress7_AT(SFP_bin[29])<<2 ) + ( SFP_compress7_AT(SFP_bin[30])>>5); |
shreeshas95 | 1:a0055b3280c8 | 806 | SFP_outputAT[31] = ( SFP_compress7_AT(SFP_bin[30])<<3 ) +( SFP_compress7_AT(SFP_bin[31])>>4); |
shreeshas95 | 1:a0055b3280c8 | 807 | SFP_outputAT[32] = ( SFP_compress7_AT(SFP_bin[31])<<4 ) +( SFP_compress5_AT(SFP_bin[32])>>1); |
shreeshas95 | 1:a0055b3280c8 | 808 | SFP_outputAT[33] = ( SFP_compress5_AT(SFP_bin[32])<<7 ) +( SFP_compress7FC_AT(SFP_bin[33])); |
shreeshas95 | 1:a0055b3280c8 | 809 | SFP_outputAT[34] = ( SFP_compress7FC_AT(SFP_bin[34])<<1 ); // 1 bit is spare |
shreeshas95 | 1:a0055b3280c8 | 810 | |
shreeshas95 | 1:a0055b3280c8 | 811 | Science_TMframe::making_frame(2,'H',SFP_outputAT); |
shreeshas95 | 1:a0055b3280c8 | 812 | if(++packet_no == 30){ |
shreeshas95 | 1:a0055b3280c8 | 813 | packet_no=0; |
shreeshas95 | 1:a0055b3280c8 | 814 | SCP_compress_data(); |
shreeshas95 | 1:a0055b3280c8 | 815 | for(i=0;i<PACKET_SEQUENCE_COUNT + NUM_PROTON_BIN + NUM_ELECTRON_BIN + VETO + FASTCHAIN;i++){ |
shreeshas95 | 1:a0055b3280c8 | 816 | if(packet_no==0){ |
shreeshas95 | 1:a0055b3280c8 | 817 | SCP_bin[i]=0; |
shreeshas95 | 1:a0055b3280c8 | 818 | } |
shreeshas95 | 1:a0055b3280c8 | 819 | } |
shreeshas95 | 1:a0055b3280c8 | 820 | } |
shreeshas95 | 1:a0055b3280c8 | 821 | |
shreeshas95 | 1:a0055b3280c8 | 822 | } |
shreeshas95 | 1:a0055b3280c8 | 823 | |
shreeshas95 | 1:a0055b3280c8 | 824 | } |
shreeshas95 | 1:a0055b3280c8 | 825 | |
shreeshas95 | 1:a0055b3280c8 | 826 | |
shreeshas95 | 1:a0055b3280c8 | 827 | /* |
shreeshas95 | 1:a0055b3280c8 | 828 | brief: takes the pointer of the raw data string and return the address of the array which stores the address of 30 packets. |
shreeshas95 | 1:a0055b3280c8 | 829 | input: pointer to the raw data. |
shreeshas95 | 1:a0055b3280c8 | 830 | output : void |
shreeshas95 | 1:a0055b3280c8 | 831 | */ |
shreeshas95 | 1:a0055b3280c8 | 832 | |
shreeshas95 | 1:a0055b3280c8 | 833 | void complete_compression(unsigned char *SRP,uint64_t x){ |
shreeshas95 | 1:a0055b3280c8 | 834 | RTC_TIME = x; |
shreeshas95 | 1:a0055b3280c8 | 835 | int i; //30 times because 3 second data |
shreeshas95 | 1:a0055b3280c8 | 836 | |
shreeshas95 | 1:a0055b3280c8 | 837 | for(i=0;i<30;i++){ |
shreeshas95 | 1:a0055b3280c8 | 838 | SFP_compress_data(SRP + 73*i); |
shreeshas95 | 1:a0055b3280c8 | 839 | } |
shreeshas95 | 1:a0055b3280c8 | 840 | |
shreeshas95 | 1:a0055b3280c8 | 841 | } |
shreeshas95 | 1:a0055b3280c8 | 842 | |
shreeshas95 | 1:a0055b3280c8 | 843 | |
shreeshas95 | 1:a0055b3280c8 | 844 | |
shreeshas95 | 1:a0055b3280c8 | 845 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
shreeshas95 | 1:a0055b3280c8 | 846 | |
shreeshas95 | 1:a0055b3280c8 | 847 | |
shreeshas95 | 1:a0055b3280c8 | 848 | |
shreeshas95 | 1:a0055b3280c8 | 849 | /* |
shreeshas95 | 1:a0055b3280c8 | 850 | @brief: compresses the given input stream and return output packet |
shreeshas95 | 1:a0055b3280c8 | 851 | @param: pointer to input stream. Input stream always has the fixed size of RAW_PACKET_LENGTH |
shreeshas95 | 1:a0055b3280c8 | 852 | @return: pointer to output stream. Output stream has the size of 22 or 26 bytes |
shreeshas95 | 1:a0055b3280c8 | 853 | */ |
shreeshas95 | 1:a0055b3280c8 | 854 | void SCP_compress_data(){ |
shreeshas95 | 1:a0055b3280c8 | 855 | |
shreeshas95 | 1:a0055b3280c8 | 856 | bool LCR = true; |
shreeshas95 | 1:a0055b3280c8 | 857 | int i = 0; |
shreeshas95 | 1:a0055b3280c8 | 858 | |
shreeshas95 | 1:a0055b3280c8 | 859 | for(i=1;i<=PACKET_SEQUENCE_COUNT + NUM_PROTON_BIN + NUM_ELECTRON_BIN + VETO + FASTCHAIN ;i++){ |
shreeshas95 | 1:a0055b3280c8 | 860 | if(SCP_bin[i]>SCP_thresholds[i]){ |
shreeshas95 | 1:a0055b3280c8 | 861 | LCR = false; |
shreeshas95 | 1:a0055b3280c8 | 862 | break; |
shreeshas95 | 1:a0055b3280c8 | 863 | } |
shreeshas95 | 1:a0055b3280c8 | 864 | } |
shreeshas95 | 1:a0055b3280c8 | 865 | // printf("\n"); //for printing the scp bin |
shreeshas95 | 1:a0055b3280c8 | 866 | // for (i=0;i<35;i++){ |
shreeshas95 | 1:a0055b3280c8 | 867 | // printf(" scp[%d] = %d ",i,SCP_bin[i]); |
shreeshas95 | 1:a0055b3280c8 | 868 | // } |
shreeshas95 | 1:a0055b3280c8 | 869 | // printf("\n"); |
shreeshas95 | 1:a0055b3280c8 | 870 | // compressing the data |
shreeshas95 | 1:a0055b3280c8 | 871 | if(LCR){ |
shreeshas95 | 1:a0055b3280c8 | 872 | SCP_outputLCR[0] = (RTC_TIME>>5)&(0xff); //first 13 bits for time tagging |
shreeshas95 | 1:a0055b3280c8 | 873 | SCP_outputLCR[1] = (RTC_TIME<<3)&(0xff); //then 4 bits for attitude tag |
shreeshas95 | 1:a0055b3280c8 | 874 | SCP_outputLCR[2] = 0x00; //only attitude tag is left |
shreeshas95 | 1:a0055b3280c8 | 875 | SCP_outputLCR[2] += ( SCP_compress5(SCP_bin[0])<<1 ) + ( SCP_compress5(SCP_bin[1])>>4 ); |
shreeshas95 | 1:a0055b3280c8 | 876 | SCP_outputLCR[3] = ( SCP_compress5(SCP_bin[1])<<4 ) + ( SCP_compress5(SCP_bin[2])>>1 ); |
shreeshas95 | 1:a0055b3280c8 | 877 | SCP_outputLCR[4] = ( SCP_compress5(SCP_bin[2])<<7 ) + ( SCP_compress5(SCP_bin[3])<<2 ) + ( SCP_compress5(SCP_bin[4])>>3 ); |
shreeshas95 | 1:a0055b3280c8 | 878 | SCP_outputLCR[5] = ( SCP_compress5(SCP_bin[4])<<5 ) + ( SCP_compress5(SCP_bin[5]) ); |
shreeshas95 | 1:a0055b3280c8 | 879 | SCP_outputLCR[6] = ( SCP_compress5(SCP_bin[6])<<3 ) + ( SCP_compress5(SCP_bin[7])>>2 ); |
shreeshas95 | 1:a0055b3280c8 | 880 | SCP_outputLCR[7] = ( SCP_compress5(SCP_bin[7])<<6 ) + ( SCP_compress5(SCP_bin[8])<<1 ) + ( SCP_compress5(SCP_bin[9])>>4 ); |
shreeshas95 | 1:a0055b3280c8 | 881 | SCP_outputLCR[8] = ( SCP_compress5(SCP_bin[9])<<4 ) + ( SCP_compress5(SCP_bin[10])>>1 ); |
shreeshas95 | 1:a0055b3280c8 | 882 | SCP_outputLCR[9] = ( SCP_compress5(SCP_bin[10])<<7 ) + ( SCP_compress5(SCP_bin[11])<<2) + ( SCP_compress5(SCP_bin[12])>>3 ); |
shreeshas95 | 1:a0055b3280c8 | 883 | SCP_outputLCR[10] = ( SCP_compress5(SCP_bin[12])<<5 ) + ( SCP_compress5(SCP_bin[13]) ); |
shreeshas95 | 1:a0055b3280c8 | 884 | SCP_outputLCR[11] = ( SCP_compress5(SCP_bin[14])<<3 ) + ( SCP_compress5(SCP_bin[15])>>2 ); |
shreeshas95 | 1:a0055b3280c8 | 885 | SCP_outputLCR[12] = ( SCP_compress5(SCP_bin[15])<<6 ) + ( SCP_compress5(SCP_bin[16])<<1) + ( SCP_compress6(SCP_bin[17])>>5 ); |
shreeshas95 | 1:a0055b3280c8 | 886 | SCP_outputLCR[13] = ( SCP_compress6(SCP_bin[17])<<3 ) + ( SCP_compress6(SCP_bin[18])>>3 ); |
shreeshas95 | 1:a0055b3280c8 | 887 | SCP_outputLCR[14] = ( SCP_compress5(SCP_bin[18])<<5 ) + ( SCP_compress6(SCP_bin[19])>>1 ); |
shreeshas95 | 1:a0055b3280c8 | 888 | SCP_outputLCR[15] = ( SCP_compress6(SCP_bin[19])<<7 ) + ( SCP_compress5(SCP_bin[20])<<2 ) + ( SCP_compress5(SCP_bin[21])>>3 ); |
shreeshas95 | 1:a0055b3280c8 | 889 | SCP_outputLCR[16] = ( SCP_compress5(SCP_bin[21])<<5 ) + ( SCP_compress5(SCP_bin[22]) ); |
shreeshas95 | 1:a0055b3280c8 | 890 | SCP_outputLCR[17] = ( SCP_compress5(SCP_bin[23])<<3 ) + ( SCP_compress5(SCP_bin[24])>>2 ); |
shreeshas95 | 1:a0055b3280c8 | 891 | SCP_outputLCR[18] = ( SCP_compress5(SCP_bin[24])<<6 ) + ( SCP_compress5(SCP_bin[25])<<1) + ( SCP_compress5(SCP_bin[26])>>4 ); |
shreeshas95 | 1:a0055b3280c8 | 892 | SCP_outputLCR[19] = ( SCP_compress5(SCP_bin[26])<<4 ) + ( SCP_compress5(SCP_bin[27])>>1 ); |
shreeshas95 | 1:a0055b3280c8 | 893 | SCP_outputLCR[20] = ( SCP_compress5(SCP_bin[27])<<7 ) + ( SCP_compress5(SCP_bin[28])<<2 ) + ( SCP_compress5(SCP_bin[29])>>3 ); |
shreeshas95 | 1:a0055b3280c8 | 894 | SCP_outputLCR[21] = ( SCP_compress5(SCP_bin[29])<<5 ) + ( SCP_compress5(SCP_bin[30]) ); |
shreeshas95 | 1:a0055b3280c8 | 895 | |
shreeshas95 | 1:a0055b3280c8 | 896 | Science_TMframe::making_frame(1,'L',SCP_outputLCR); |
shreeshas95 | 1:a0055b3280c8 | 897 | } |
shreeshas95 | 1:a0055b3280c8 | 898 | else{ |
shreeshas95 | 1:a0055b3280c8 | 899 | |
shreeshas95 | 1:a0055b3280c8 | 900 | SCP_outputLCR[0] = (RTC_TIME>>5)&(0xff); //first 13 bits for time tagging |
shreeshas95 | 1:a0055b3280c8 | 901 | SCP_outputLCR[1] = (RTC_TIME<<3)&(0xff); |
shreeshas95 | 1:a0055b3280c8 | 902 | SCP_outputHCR[2] = 0x40; |
shreeshas95 | 1:a0055b3280c8 | 903 | SCP_outputHCR[2] += ( SCP_compress6h(SCP_bin[0])<<6 ) ; |
shreeshas95 | 1:a0055b3280c8 | 904 | SCP_outputHCR[3] = ( SCP_compress6h(SCP_bin[1])<<2 ) + ( SCP_compress6h(SCP_bin[2])>>4) ; |
shreeshas95 | 1:a0055b3280c8 | 905 | SCP_outputHCR[4] = ( SCP_compress6h(SCP_bin[2])<<4 ) + ( SCP_compress6h(SCP_bin[3])>>2) ; |
shreeshas95 | 1:a0055b3280c8 | 906 | SCP_outputHCR[5] = ( SCP_compress6h(SCP_bin[3])<<6 ) + ( SCP_compress6h(SCP_bin[4])) ; |
shreeshas95 | 1:a0055b3280c8 | 907 | SCP_outputHCR[6] = ( SCP_compress6h(SCP_bin[5])<<2 ) + ( SCP_compress6h(SCP_bin[6])>>4) ; |
shreeshas95 | 1:a0055b3280c8 | 908 | SCP_outputHCR[7] = ( SCP_compress6h(SCP_bin[6])<<4 ) + ( SCP_compress6h(SCP_bin[7])>>2) ; |
shreeshas95 | 1:a0055b3280c8 | 909 | SCP_outputHCR[8] = ( SCP_compress6h(SCP_bin[7])<<6 ) + ( SCP_compress6h(SCP_bin[8])) ; |
shreeshas95 | 1:a0055b3280c8 | 910 | SCP_outputHCR[9] = ( SCP_compress6h(SCP_bin[9])<<2 ) + ( SCP_compress6h(SCP_bin[10])>>4) ; |
shreeshas95 | 1:a0055b3280c8 | 911 | SCP_outputHCR[10] = ( SCP_compress6h(SCP_bin[10])<<4 ) + ( SCP_compress6h(SCP_bin[11])>>2); |
shreeshas95 | 1:a0055b3280c8 | 912 | SCP_outputHCR[11] = ( SCP_compress6h(SCP_bin[11])<<6 ) + ( SCP_compress6h(SCP_bin[12])) ; |
shreeshas95 | 1:a0055b3280c8 | 913 | SCP_outputHCR[12] = ( SCP_compress6h(SCP_bin[13])<<2 ) + ( SCP_compress6h(SCP_bin[14])>>4) ; |
shreeshas95 | 1:a0055b3280c8 | 914 | SCP_outputHCR[13] = ( SCP_compress6h(SCP_bin[14])<<4 ) + ( SCP_compress6h(SCP_bin[15])>>2) ; |
shreeshas95 | 1:a0055b3280c8 | 915 | SCP_outputHCR[14] = ( SCP_compress6h(SCP_bin[15])<<6 ) + ( SCP_compress6h(SCP_bin[16])) ; |
shreeshas95 | 1:a0055b3280c8 | 916 | SCP_outputHCR[15] = ( SCP_compress7h(SCP_bin[17])<<1 ) + ( SCP_compress7h(SCP_bin[18])>>6) ; |
shreeshas95 | 1:a0055b3280c8 | 917 | SCP_outputHCR[16] = ( SCP_compress7h(SCP_bin[18])<<2 ) + ( SCP_compress7h(SCP_bin[19])>>5) ; |
shreeshas95 | 1:a0055b3280c8 | 918 | SCP_outputHCR[17] = ( SCP_compress7h(SCP_bin[19])<<3 ) + ( SCP_compress6h(SCP_bin[20])>>3) ; |
shreeshas95 | 1:a0055b3280c8 | 919 | SCP_outputHCR[18] = ( SCP_compress6h(SCP_bin[20])<<5 ) + ( SCP_compress6h(SCP_bin[21])>>1) ; |
shreeshas95 | 1:a0055b3280c8 | 920 | SCP_outputHCR[19] = ( SCP_compress6h(SCP_bin[21])<<7 ) + ( SCP_compress6h(SCP_bin[22])<<1) + ( SCP_compress6h(SCP_bin[23])>>5) ; |
shreeshas95 | 1:a0055b3280c8 | 921 | SCP_outputHCR[20] = ( SCP_compress6h(SCP_bin[23])<<3 ) + ( SCP_compress6h(SCP_bin[24])>>3) ; |
shreeshas95 | 1:a0055b3280c8 | 922 | SCP_outputHCR[21] = ( SCP_compress6h(SCP_bin[24])<<5 ) + ( SCP_compress6h(SCP_bin[25])>>1) ; |
shreeshas95 | 1:a0055b3280c8 | 923 | SCP_outputHCR[22] = ( SCP_compress6h(SCP_bin[25])<<7 ) + ( SCP_compress6h(SCP_bin[26])<<1) + ( SCP_compress6h(SCP_bin[27])>>5) ; |
shreeshas95 | 1:a0055b3280c8 | 924 | SCP_outputHCR[23] = ( SCP_compress6h(SCP_bin[27])<<3 ) + ( SCP_compress6h(SCP_bin[28])>>3) ; |
shreeshas95 | 1:a0055b3280c8 | 925 | SCP_outputHCR[24] = ( SCP_compress6h(SCP_bin[28])<<5 ) + ( SCP_compress6h(SCP_bin[29])>>1) ; |
shreeshas95 | 1:a0055b3280c8 | 926 | SCP_outputHCR[25] = ( SCP_compress6h(SCP_bin[29])<<7 ) + ( SCP_compress6h(SCP_bin[30])<<1) ; //last bit is empty |
shreeshas95 | 1:a0055b3280c8 | 927 | |
shreeshas95 | 1:a0055b3280c8 | 928 | /* for (i=0;i<26;i++){ |
shreeshas95 | 1:a0055b3280c8 | 929 | printf("\nscp[%d] = %d",i,SCP_outputHCR[i]); |
shreeshas95 | 1:a0055b3280c8 | 930 | }*/ |
shreeshas95 | 1:a0055b3280c8 | 931 | Science_TMframe::making_frame(1,'H',SCP_outputHCR); |
shreeshas95 | 1:a0055b3280c8 | 932 | } |
shreeshas95 | 1:a0055b3280c8 | 933 | } |
shreeshas95 | 1:a0055b3280c8 | 934 | |
shreeshas95 | 1:a0055b3280c8 | 935 | } |
shreeshas95 | 1:a0055b3280c8 | 936 |