
Compression code changed and RLY_TMTC pointers managed
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE by
Compression.h@265:ae588e75cfa4, 2016-07-15 (annotated)
- Committer:
- prasanthbj05
- Date:
- Fri Jul 15 14:59:27 2016 +0000
- Revision:
- 265:ae588e75cfa4
- Parent:
- 261:1e54415b34d3
- Child:
- 266:783c248a6207
Compression code modified and RLY_TMTC pointers managed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
prasanthbj05 | 265:ae588e75cfa4 | 1 | /*-----------------------------------------to_do_compression.h-------------------------------------------------- |
prasanthbj05 | 265:ae588e75cfa4 | 2 | |
prasanthbj05 | 265:ae588e75cfa4 | 3 | -> SD_Write error to be checked |
prasanthbj05 | 265:ae588e75cfa4 | 4 | -> fsc_counter is 32 bit but in the code 24 bit. Talk to chaitu |
prasanthbj05 | 265:ae588e75cfa4 | 5 | ---------------------------------------------------------------------------------------------------------------*/ |
prasanthbj05 | 265:ae588e75cfa4 | 6 | |
prasanthbj05 | 265:ae588e75cfa4 | 7 | //updated compression algorithm |
prasanthbj05 | 265:ae588e75cfa4 | 8 | /*#include <iostream> |
prasanthbj05 | 265:ae588e75cfa4 | 9 | #include "stdio.h" |
prasanthbj05 | 265:ae588e75cfa4 | 10 | #include "crc.h" |
prasanthbj05 | 265:ae588e75cfa4 | 11 | #include "interleave.h" |
prasanthbj05 | 265:ae588e75cfa4 | 12 | #include "Convolution.h" |
prasanthbj05 | 265:ae588e75cfa4 | 13 | #include "bitset"*/ |
prasanthbj05 | 265:ae588e75cfa4 | 14 | //using namespace std; |
prasanthbj05 | 265:ae588e75cfa4 | 15 | |
prasanthbj05 | 265:ae588e75cfa4 | 16 | //reading functions 2byte, 4byte |
prasanthbj05 | 265:ae588e75cfa4 | 17 | |
prasanthbj05 | 265:ae588e75cfa4 | 18 | uint16_t read_2byte(uint8_t* ptr) |
prasanthbj05 | 265:ae588e75cfa4 | 19 | { |
prasanthbj05 | 265:ae588e75cfa4 | 20 | uint16_t output = (uint8_t ) *(ptr+1); |
prasanthbj05 | 265:ae588e75cfa4 | 21 | output += ( (uint8_t )(*ptr) ) << 8; |
ee12b079 | 93:4d76de54a699 | 22 | return output; |
ee12b079 | 93:4d76de54a699 | 23 | } |
ee12b079 | 93:4d76de54a699 | 24 | |
prasanthbj05 | 265:ae588e75cfa4 | 25 | uint32_t read_4byte(uint8_t* ptr) |
prasanthbj05 | 265:ae588e75cfa4 | 26 | { |
prasanthbj05 | 265:ae588e75cfa4 | 27 | uint32_t output = (uint32_t) (*(ptr+3)); |
prasanthbj05 | 265:ae588e75cfa4 | 28 | output += (uint32_t)(*(ptr+2)<<8); |
prasanthbj05 | 265:ae588e75cfa4 | 29 | output += (uint32_t)(*(ptr+1)<<16); |
prasanthbj05 | 265:ae588e75cfa4 | 30 | output += (uint32_t)(*(ptr)<<24); |
prasanthbj05 | 265:ae588e75cfa4 | 31 | return output; |
prasanthbj05 | 265:ae588e75cfa4 | 32 | } |
prasanthbj05 | 265:ae588e75cfa4 | 33 | |
prasanthbj05 | 265:ae588e75cfa4 | 34 | uint8_t adjust(uint8_t size, uint8_t data, uint8_t* ptr , uint8_t space) |
prasanthbj05 | 265:ae588e75cfa4 | 35 | { |
ee12b079 | 93:4d76de54a699 | 36 | space = space&0x0f; |
ee12b079 | 171:31bdf83591a1 | 37 | if(space == 8) *ptr = 0; |
ee12b079 | 93:4d76de54a699 | 38 | data = data&((1<<size)-1); |
ee12b079 | 93:4d76de54a699 | 39 | if(space >= size){ |
ee12b079 | 93:4d76de54a699 | 40 | *ptr += data<<(space-size); |
ee12b079 | 93:4d76de54a699 | 41 | if(space - size == 0){ |
ee12b079 | 93:4d76de54a699 | 42 | return 0x18; |
ee12b079 | 93:4d76de54a699 | 43 | }else{ |
ee12b079 | 93:4d76de54a699 | 44 | return space-size; |
shreeshas95 | 1:a0055b3280c8 | 45 | } |
ee12b079 | 93:4d76de54a699 | 46 | }else{ |
ee12b079 | 93:4d76de54a699 | 47 | ptr[0] += data>>(size-space); |
ee12b079 | 93:4d76de54a699 | 48 | ptr[1] = (data<<(8-(size-space)))&0xff ; |
ee12b079 | 93:4d76de54a699 | 49 | return 0x10 + 8-(size - space); |
ee12b079 | 93:4d76de54a699 | 50 | } |
ee12b079 | 93:4d76de54a699 | 51 | } |
prasanthbj05 | 265:ae588e75cfa4 | 52 | int compress (int data, int x, int y) //to be compressed with scheme (msb x)*4^y ; |
prasanthbj05 | 265:ae588e75cfa4 | 53 | { |
prasanthbj05 | 265:ae588e75cfa4 | 54 | for(int i = 0 ; i < (1<<y) ; i++) |
prasanthbj05 | 265:ae588e75cfa4 | 55 | { |
prasanthbj05 | 265:ae588e75cfa4 | 56 | if(data <= ( (1<<x)-1) * (1<<(2*i)) ) |
prasanthbj05 | 265:ae588e75cfa4 | 57 | { |
ee12b079 | 93:4d76de54a699 | 58 | return ( ((data>>i*2)<<y) + i); |
shreeshas95 | 1:a0055b3280c8 | 59 | } |
ee12b079 | 93:4d76de54a699 | 60 | } |
prasanthbj05 | 265:ae588e75cfa4 | 61 | if ( data > (( (1<<x)-1) * (1<<(2*((1<<y)-1)))) ) |
prasanthbj05 | 265:ae588e75cfa4 | 62 | { |
prasanthbj05 | 265:ae588e75cfa4 | 63 | //cout <<"compression exception"<<endl; |
prasanthbj05 | 265:ae588e75cfa4 | 64 | return (((1<<x)-1) * (1<<(2*((1<<y)-1)))); |
ee12b079 | 93:4d76de54a699 | 65 | } |
ee12b079 | 93:4d76de54a699 | 66 | } |
ee12b079 | 93:4d76de54a699 | 67 | |
prasanthbj05 | 265:ae588e75cfa4 | 68 | //--------------------------------------------------------beacon |
prasanthbj05 | 265:ae588e75cfa4 | 69 | uint8_t beacon_array[134]; |
prasanthbj05 | 265:ae588e75cfa4 | 70 | uint8_t beacon_cntr = 1; |
prasanthbj05 | 265:ae588e75cfa4 | 71 | uint8_t *beacon_ptr; |
prasanthbj05 | 265:ae588e75cfa4 | 72 | //--------------------------------------------------------beacon |
ee12b079 | 93:4d76de54a699 | 73 | |
prasanthbj05 | 265:ae588e75cfa4 | 74 | //variable declarations |
prasanthbj05 | 265:ae588e75cfa4 | 75 | uint8_t srp_mode , at , pzf , ezf ,sfp[71] ,scp[56],beacon_at; //tells which mode is calibrated or plot 0 for calibrated and 1 for scatterered, below threshold , proton zero flux, electron zero flux. |
prasanthbj05 | 265:ae588e75cfa4 | 76 | uint32_t sfp_bin[52] , scp_bin[52]; //storing the bin values. |
prasanthbj05 | 265:ae588e75cfa4 | 77 | uint32_t sfp_threshold_m0[52] = {124,124,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,4032,252,252,252,252,252,4032,8128,8128,8128,8128,8128,8128,8128,8128,960,960,960,960,960,960,960,960,960,960,960,960,4032,4032,4032,4032,8128,8128,8128,8128}; |
prasanthbj05 | 265:ae588e75cfa4 | 78 | uint32_t scp_threshold_m0[52] = {4032,4032,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,114688,8128,4032,4032,4032,4032,114688,245760,245760,245760,245760,245760,245760,245760,245760,49152,49152,49152,49152,49152,49152,49152,49152,49152,49152,49152,49152,114688,114688,114688,114688,245760,245760,245760,245760}; |
prasanthbj05 | 265:ae588e75cfa4 | 79 | uint32_t scp_threshold_m0_1[9] = {114688,245760,245760,245760,245760,114688,114688,65472,65472} ; //for callibrated mode with data conservation |
prasanthbj05 | 265:ae588e75cfa4 | 80 | uint32_t scp_sfp_threshold_m0_2[3] = {245760,65472,65472}; |
prasanthbj05 | 265:ae588e75cfa4 | 81 | uint32_t sfp_threshold_m1[52] = {1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,8128,8128,8128,8128}; |
prasanthbj05 | 265:ae588e75cfa4 | 82 | uint32_t scp_threshold_m1[52] = {114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,114688,245760,245760,245760,245760}; |
ee12b079 | 171:31bdf83591a1 | 83 | uint8_t frames[3][134] = {0}; |
ee12b079 | 171:31bdf83591a1 | 84 | uint8_t position_tm_frame[3] = {8,11,5} , position_tm_starting[3] = {8,11,5}; //{sc,sf-bt,sf-at} |
ee12b079 | 171:31bdf83591a1 | 85 | uint8_t id; //sf = 0,sc-at = 1,sc-bt = 2; |
ee12b079 | 171:31bdf83591a1 | 86 | uint8_t TM_interleave_data[512] , TM_convoluted_data[270] = {0}; |
prasanthbj05 | 265:ae588e75cfa4 | 87 | uint64_t proton_scp_sum,electron_scp_sum,FSC_science; |
prasanthbj05 | 265:ae588e75cfa4 | 88 | uint16_t temp_crc; |
prasanthbj05 | 265:ae588e75cfa4 | 89 | uint32_t debug_cntr, size,space,length; |
ee12b079 | 171:31bdf83591a1 | 90 | uint8_t *ptr ,* pointer; |
prasanthbj05 | 265:ae588e75cfa4 | 91 | uint64_t sci_time = 0, time_prev_scp = 0; |
prasanthbj05 | 265:ae588e75cfa4 | 92 | uint32_t attitude = 0; |
prasanthbj05 | 265:ae588e75cfa4 | 93 | uint32_t beacon_threshold[9] = {114688,245760,245760,245760,245760,114688,114688,65472,65472}; |
ee12b079 | 93:4d76de54a699 | 94 | |
prasanthbj05 | 265:ae588e75cfa4 | 95 | Convolution ConvObj; |
prasanthbj05 | 265:ae588e75cfa4 | 96 | void convolution (uint8_t * ptr){ |
prasanthbj05 | 265:ae588e75cfa4 | 97 | ConvObj.convolutionEncode(ptr, TM_convoluted_data); |
prasanthbj05 | 265:ae588e75cfa4 | 98 | ConvObj.convolutionEncode(ptr + 67, TM_convoluted_data + 135); |
prasanthbj05 | 265:ae588e75cfa4 | 99 | } |
ee12b079 | 93:4d76de54a699 | 100 | |
ee12b079 | 93:4d76de54a699 | 101 | //give the pointer of 6 second data to this function |
prasanthbj05 | 265:ae588e75cfa4 | 102 | void srp(uint8_t * head) |
prasanthbj05 | 265:ae588e75cfa4 | 103 | { |
prasanthbj05 | 265:ae588e75cfa4 | 104 | gPC.printf("\n\rEntered srp"); |
prasanthbj05 | 265:ae588e75cfa4 | 105 | debug_cntr = 0; |
prasanthbj05 | 265:ae588e75cfa4 | 106 | sci_time = FCTN_CDMS_RD_RTC(); |
prasanthbj05 | 265:ae588e75cfa4 | 107 | if(time_prev_scp==0){ |
prasanthbj05 | 265:ae588e75cfa4 | 108 | time_prev_scp = sci_time; |
prasanthbj05 | 265:ae588e75cfa4 | 109 | } |
prasanthbj05 | 265:ae588e75cfa4 | 110 | FCTN_SD_MNGR(); ///changed recently |
prasanthbj05 | 265:ae588e75cfa4 | 111 | for (int i = 0; i < 56 ; i++) |
prasanthbj05 | 265:ae588e75cfa4 | 112 | { |
ee12b079 | 93:4d76de54a699 | 113 | scp_bin[i] = 0; |
shreeshas95 | 1:a0055b3280c8 | 114 | } |
prasanthbj05 | 265:ae588e75cfa4 | 115 | ptr = head + 3; //ptr points to proton energy bin of srp |
ee12b079 | 93:4d76de54a699 | 116 | srp_mode = head[2]&0x1; |
prasanthbj05 | 265:ae588e75cfa4 | 117 | for(uint8_t counter = 0 ; counter < 60 ; counter++) |
prasanthbj05 | 265:ae588e75cfa4 | 118 | { |
prasanthbj05 | 265:ae588e75cfa4 | 119 | /*-------------------- ------------populating sfp_bin and scp_bin[] starts here(also tag AT or BT)-----------------------*/ |
prasanthbj05 | 265:ae588e75cfa4 | 120 | at = 0; pzf = 1; ezf = 1; |
prasanthbj05 | 265:ae588e75cfa4 | 121 | if(srp_mode == 0) //calibrated mode |
prasanthbj05 | 265:ae588e75cfa4 | 122 | { |
prasanthbj05 | 265:ae588e75cfa4 | 123 | for(int i=0; i<48 ; i++) //first 48 bins or SRP are of 16 bits size |
prasanthbj05 | 265:ae588e75cfa4 | 124 | { |
ee12b079 | 93:4d76de54a699 | 125 | sfp_bin[i] = read_2byte(ptr + i*2); |
ee12b079 | 93:4d76de54a699 | 126 | scp_bin[i] += sfp_bin[i]; |
prasanthbj05 | 265:ae588e75cfa4 | 127 | if(sfp_bin[i]>sfp_threshold_m0[i]) |
prasanthbj05 | 265:ae588e75cfa4 | 128 | { |
ee12b079 | 93:4d76de54a699 | 129 | at = 1; |
ee12b079 | 93:4d76de54a699 | 130 | } |
prasanthbj05 | 265:ae588e75cfa4 | 131 | if(i<17) |
prasanthbj05 | 265:ae588e75cfa4 | 132 | { |
ee12b079 | 93:4d76de54a699 | 133 | if(sfp_bin[i] > 0) |
ee12b079 | 93:4d76de54a699 | 134 | pzf = 0; |
ee12b079 | 93:4d76de54a699 | 135 | } |
prasanthbj05 | 265:ae588e75cfa4 | 136 | else if (i>17 && i < 23) |
prasanthbj05 | 265:ae588e75cfa4 | 137 | { |
ee12b079 | 93:4d76de54a699 | 138 | if(sfp_bin[i]>0) |
ee12b079 | 93:4d76de54a699 | 139 | ezf = 0; |
ee12b079 | 93:4d76de54a699 | 140 | } |
ee12b079 | 93:4d76de54a699 | 141 | } |
prasanthbj05 | 265:ae588e75cfa4 | 142 | for(int i=0; i<4; i++) //last 4 bins(excluding the spare bin) are 32 bit each |
prasanthbj05 | 265:ae588e75cfa4 | 143 | { |
ee12b079 | 93:4d76de54a699 | 144 | sfp_bin[i+48] = read_4byte( (ptr+96) + 4*i ); |
ee12b079 | 93:4d76de54a699 | 145 | scp_bin[i+48] += sfp_bin[i+48]; |
ee12b079 | 93:4d76de54a699 | 146 | if(sfp_bin[i+48]>sfp_threshold_m0[i+48]) |
ee12b079 | 93:4d76de54a699 | 147 | at = 1; |
ee12b079 | 93:4d76de54a699 | 148 | } |
ee12b079 | 93:4d76de54a699 | 149 | } |
prasanthbj05 | 265:ae588e75cfa4 | 150 | else if(srp_mode == 1) //scattered mode |
prasanthbj05 | 265:ae588e75cfa4 | 151 | { |
prasanthbj05 | 265:ae588e75cfa4 | 152 | for(int i = 0; i <48; i++) //first 48 bins of SRP are of 16 bit size |
prasanthbj05 | 265:ae588e75cfa4 | 153 | { |
prasanthbj05 | 265:ae588e75cfa4 | 154 | sfp_bin[i] = read_2byte(ptr+2*i); |
ee12b079 | 93:4d76de54a699 | 155 | scp_bin[i] += sfp_bin[i]; |
prasanthbj05 | 265:ae588e75cfa4 | 156 | if(sfp_bin[i] > sfp_threshold_m1[i]) |
ee12b079 | 93:4d76de54a699 | 157 | at = 1; |
ee12b079 | 93:4d76de54a699 | 158 | } |
prasanthbj05 | 265:ae588e75cfa4 | 159 | for(int i = 0; i < 4 ; i++) //next 4 bins are of 32 bit size |
prasanthbj05 | 265:ae588e75cfa4 | 160 | { |
prasanthbj05 | 265:ae588e75cfa4 | 161 | ///sfp_bin[i+48] = read_4byte( (ptr+64) + 4*i ); |
prasanthbj05 | 265:ae588e75cfa4 | 162 | sfp_bin[i+48] = read_4byte( (ptr+96) + 4*i ); |
prasanthbj05 | 265:ae588e75cfa4 | 163 | scp_bin[i+48] += sfp_bin[i+48]; |
prasanthbj05 | 265:ae588e75cfa4 | 164 | if(sfp_bin[i+48] > sfp_threshold_m1[i+48]) |
ee12b079 | 93:4d76de54a699 | 165 | at = 1; |
ee12b079 | 93:4d76de54a699 | 166 | } |
shreeshas95 | 1:a0055b3280c8 | 167 | } |
prasanthbj05 | 265:ae588e75cfa4 | 168 | /*---------------------------populating sfp_bin[] and scp_bin[] from srp ends here(also tagging AT or BT)------------------*/ |
prasanthbj05 | 265:ae588e75cfa4 | 169 | |
prasanthbj05 | 265:ae588e75cfa4 | 170 | ptr = ptr + 112; //moving the pointer to next srp packet in the DMA buffer |
prasanthbj05 | 265:ae588e75cfa4 | 171 | |
prasanthbj05 | 265:ae588e75cfa4 | 172 | /*------------------------------------------forming a science fine packet starts here---------------------------------------- |
prasanthbj05 | 265:ae588e75cfa4 | 173 | First we fill packet header, then fill packet data and finally assign its length |
prasanthbj05 | 265:ae588e75cfa4 | 174 | ----------------------------------------------------------------------------------------------------------------------------*/ |
prasanthbj05 | 265:ae588e75cfa4 | 175 | for(int i = 0; i<71; i++) |
ee12b079 | 93:4d76de54a699 | 176 | sfp[i] = 0; |
prasanthbj05 | 265:ae588e75cfa4 | 177 | if(srp_mode == 0) //calibrated mode |
prasanthbj05 | 265:ae588e75cfa4 | 178 | { |
prasanthbj05 | 265:ae588e75cfa4 | 179 | if(at == 0) |
prasanthbj05 | 265:ae588e75cfa4 | 180 | { |
ee12b079 | 93:4d76de54a699 | 181 | pointer = sfp; debug_cntr = 0; |
prasanthbj05 | 265:ae588e75cfa4 | 182 | space = adjust(4, attitude,pointer,8); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 183 | space = adjust(6, counter,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 184 | space = adjust(1, srp_mode,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 185 | space = adjust(1, pzf,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 186 | space = adjust(1, ezf,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 187 | for(uint8_t i = 0 ; i < 8 ; i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 188 | space = adjust(1, ((compress(sfp_bin[24+i],7,2))&0x100)>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 189 | space = adjust(8, ((compress(sfp_bin[24+i],7,2))&0xff) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 190 | } |
prasanthbj05 | 265:ae588e75cfa4 | 191 | for(uint8_t i = 0 ; i <12 ; i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 192 | space = adjust(6, (compress(sfp_bin[32+i],4,2)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 193 | } |
prasanthbj05 | 265:ae588e75cfa4 | 194 | for(uint8_t i = 0; i < 4; i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 195 | space = adjust(8, (compress(sfp_bin[44+i],6,2)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 196 | } |
prasanthbj05 | 265:ae588e75cfa4 | 197 | for(uint8_t i = 0 ; i < 4 ; i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 198 | space = adjust(1, (compress(sfp_bin[48+i],7,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 199 | space = adjust(8, compress(sfp_bin[48+i],7,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 200 | } |
prasanthbj05 | 265:ae588e75cfa4 | 201 | space = adjust(8, ((compress(sfp_bin[17],6,2))&0xff) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 202 | space = adjust(8, ((compress(sfp_bin[23],6,2))&0xff) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 203 | if(pzf == 0){ |
prasanthbj05 | 265:ae588e75cfa4 | 204 | for(uint8_t i = 0; i<2 ; i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 205 | space = adjust(6, ((compress(sfp_bin[i],5,1))&0xff) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 206 | } |
prasanthbj05 | 265:ae588e75cfa4 | 207 | for(uint8_t i = 0; i<15 ; i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 208 | space = adjust(5, ((compress(sfp_bin[i+2],4,1))&0xff) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 209 | } |
ee12b079 | 93:4d76de54a699 | 210 | } |
ee12b079 | 93:4d76de54a699 | 211 | if(ezf == 0){ |
prasanthbj05 | 265:ae588e75cfa4 | 212 | for(uint8_t i = 0; i <5 ;i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 213 | space = adjust(7, ((compress(sfp_bin[18+i],6,1))&0xff) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 214 | } |
ee12b079 | 93:4d76de54a699 | 215 | } |
prasanthbj05 | 265:ae588e75cfa4 | 216 | } //below thershold ends here. |
ee12b079 | 93:4d76de54a699 | 217 | if(at == 1){ |
ee12b079 | 93:4d76de54a699 | 218 | pointer = sfp + 6; debug_cntr = 6;space = 8; |
ee12b079 | 93:4d76de54a699 | 219 | sfp[0] = (sci_time>>27)&0xff; sfp[1] = (sci_time>>19)&0xff; sfp[2] = (sci_time>>11)&0xff; sfp[3] = (sci_time>>3)&0xff; |
prasanthbj05 | 265:ae588e75cfa4 | 220 | sfp[4] = ((sci_time&0x07)<<5) + ((attitude&0x0f)<<1) + (counter>>5); |
prasanthbj05 | 265:ae588e75cfa4 | 221 | sfp[5] = ((counter&0x1f)<<3) + (srp_mode<<2); |
ee12b079 | 93:4d76de54a699 | 222 | sfp[5] += (pzf<<1) + ezf ; |
prasanthbj05 | 265:ae588e75cfa4 | 223 | for(uint8_t i = 0 ; i < 8 ; i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 224 | space = adjust(1, (compress(sfp_bin[24+i],7,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 225 | space = adjust(8, ((compress(sfp_bin[24+i],7,2))&0xff) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
shreeshas95 | 1:a0055b3280c8 | 226 | } |
prasanthbj05 | 265:ae588e75cfa4 | 227 | for(uint8_t i = 0 ; i <12 ; i++){ |
ee12b079 | 93:4d76de54a699 | 228 | space = adjust(6, ((compress(sfp_bin[32+i],3,3))&0xff) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
shreeshas95 | 1:a0055b3280c8 | 229 | } |
prasanthbj05 | 265:ae588e75cfa4 | 230 | for(uint8_t i = 0 ; i < 4 ; i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 231 | space = adjust(2, (compress(sfp_bin[44+i],8,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 232 | space = adjust(8, compress(sfp_bin[44+i],8,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
shreeshas95 | 1:a0055b3280c8 | 233 | } |
prasanthbj05 | 265:ae588e75cfa4 | 234 | for(uint8_t i = 0 ; i < 4 ; i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 235 | space = adjust(1, (compress(sfp_bin[48+i],6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 236 | space = adjust(8, compress(sfp_bin[48+i],6,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 237 | } |
prasanthbj05 | 265:ae588e75cfa4 | 238 | space = adjust(2, (compress(sfp_bin[17],8,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 239 | space = adjust(8, compress(sfp_bin[17],8,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 240 | space = adjust(2, (compress(sfp_bin[23],8,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 241 | space = adjust(8, compress(sfp_bin[23],8,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 242 | |
ee12b079 | 93:4d76de54a699 | 243 | if(pzf == 0){ |
prasanthbj05 | 265:ae588e75cfa4 | 244 | //cout<<"proton bins "; |
prasanthbj05 | 265:ae588e75cfa4 | 245 | for(uint8_t i = 0; i<17 ; i++){ |
ee12b079 | 93:4d76de54a699 | 246 | space = adjust(2, ((compress(sfp_bin[i],8,2))>>8) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 247 | space = adjust(8, compress(sfp_bin[i],8,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 248 | //printf("%02X ",compress(sfp_bin[i],8,2)); |
ee12b079 | 93:4d76de54a699 | 249 | } |
ee12b079 | 93:4d76de54a699 | 250 | } |
ee12b079 | 93:4d76de54a699 | 251 | if(ezf == 0){ |
prasanthbj05 | 265:ae588e75cfa4 | 252 | //cout<<"electron bins "; |
ee12b079 | 93:4d76de54a699 | 253 | for(int i = 0; i<5 ; i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 254 | space = adjust(2,((compress(sfp_bin[18+i],8,2))>>8),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 255 | space = adjust(8, compress(sfp_bin[18+i],8,2),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 256 | //printf("%02X ",compress(sfp_bin[i],8,2)); |
ee12b079 | 93:4d76de54a699 | 257 | } |
ee12b079 | 93:4d76de54a699 | 258 | } |
prasanthbj05 | 265:ae588e75cfa4 | 259 | } //above threshold ends here. |
prasanthbj05 | 265:ae588e75cfa4 | 260 | if(at == 0) |
prasanthbj05 | 265:ae588e75cfa4 | 261 | { |
prasanthbj05 | 265:ae588e75cfa4 | 262 | id = 1; length = 241+5; //5 spare bits |
ee12b079 | 93:4d76de54a699 | 263 | if(pzf == 0) |
ee12b079 | 93:4d76de54a699 | 264 | length += 87; |
ee12b079 | 93:4d76de54a699 | 265 | if(ezf == 0) |
ee12b079 | 93:4d76de54a699 | 266 | length += 35; |
prasanthbj05 | 265:ae588e75cfa4 | 267 | } |
prasanthbj05 | 265:ae588e75cfa4 | 268 | else |
prasanthbj05 | 265:ae588e75cfa4 | 269 | { |
prasanthbj05 | 265:ae588e75cfa4 | 270 | id = 2; length = 288; //0 spare bits |
ee12b079 | 93:4d76de54a699 | 271 | if(pzf == 0) |
ee12b079 | 93:4d76de54a699 | 272 | length += 170; |
ee12b079 | 93:4d76de54a699 | 273 | if(ezf == 0) |
ee12b079 | 93:4d76de54a699 | 274 | length += 50; |
ee12b079 | 93:4d76de54a699 | 275 | } |
shreeshas95 | 1:a0055b3280c8 | 276 | } |
prasanthbj05 | 265:ae588e75cfa4 | 277 | else if(srp_mode == 1) //scattered mode |
prasanthbj05 | 265:ae588e75cfa4 | 278 | { |
prasanthbj05 | 265:ae588e75cfa4 | 279 | if(at == 0) |
prasanthbj05 | 265:ae588e75cfa4 | 280 | { |
prasanthbj05 | 265:ae588e75cfa4 | 281 | pointer = sfp; debug_cntr = 0; space = 8; |
prasanthbj05 | 265:ae588e75cfa4 | 282 | space = adjust(4, attitude,pointer,8); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 283 | space = adjust(6, counter,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 284 | space = adjust(1, srp_mode,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 285 | for(uint8_t i=0; i<48; i++) |
prasanthbj05 | 265:ae588e75cfa4 | 286 | { |
prasanthbj05 | 265:ae588e75cfa4 | 287 | space = adjust(7, compress(sfp_bin[i],5,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 288 | } |
prasanthbj05 | 265:ae588e75cfa4 | 289 | for(uint8_t i = 0 ; i < 4 ; i++) |
prasanthbj05 | 265:ae588e75cfa4 | 290 | { |
prasanthbj05 | 265:ae588e75cfa4 | 291 | space = adjust(1, (compress(sfp_bin[48+i],7,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 292 | space = adjust(8, compress(sfp_bin[48+i],7,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 293 | } |
prasanthbj05 | 265:ae588e75cfa4 | 294 | } |
prasanthbj05 | 265:ae588e75cfa4 | 295 | if(at == 1) |
prasanthbj05 | 265:ae588e75cfa4 | 296 | { |
prasanthbj05 | 265:ae588e75cfa4 | 297 | pointer = sfp; debug_cntr = 0; space = 8; |
prasanthbj05 | 265:ae588e75cfa4 | 298 | space = adjust(3, sci_time>>32 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 299 | space = adjust(8, sci_time>>24 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 300 | space = adjust(8, sci_time>>16 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 301 | space = adjust(8, sci_time>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 302 | space = adjust(8, sci_time ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 303 | space = adjust(4, attitude,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 304 | space = adjust(6, counter,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 305 | space = adjust(1, srp_mode,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 306 | for(uint8_t i=0; i<48; i++) |
prasanthbj05 | 265:ae588e75cfa4 | 307 | { |
prasanthbj05 | 265:ae588e75cfa4 | 308 | space = adjust(2, (compress(sfp_bin[i],8,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 309 | space = adjust(8, compress(sfp_bin[i],8,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 310 | } |
prasanthbj05 | 265:ae588e75cfa4 | 311 | for(uint8_t i = 0 ; i < 4 ; i++) |
prasanthbj05 | 265:ae588e75cfa4 | 312 | { |
prasanthbj05 | 265:ae588e75cfa4 | 313 | space = adjust(1, (compress(sfp_bin[48+i],6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 314 | space = adjust(8, compress(sfp_bin[48+i],6,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 315 | } |
prasanthbj05 | 265:ae588e75cfa4 | 316 | } |
prasanthbj05 | 265:ae588e75cfa4 | 317 | if(at == 0) |
prasanthbj05 | 265:ae588e75cfa4 | 318 | { |
prasanthbj05 | 265:ae588e75cfa4 | 319 | id = 1; length = 384; //0 spare bits |
prasanthbj05 | 265:ae588e75cfa4 | 320 | } |
prasanthbj05 | 265:ae588e75cfa4 | 321 | else |
prasanthbj05 | 265:ae588e75cfa4 | 322 | { |
prasanthbj05 | 265:ae588e75cfa4 | 323 | id = 2; length = 568; //0 spare bits |
ee12b079 | 93:4d76de54a699 | 324 | } |
shreeshas95 | 1:a0055b3280c8 | 325 | } |
prasanthbj05 | 265:ae588e75cfa4 | 326 | length = (length%8==0)?(length/8):(length/8)+1; //converting length to mulitple of 8 |
prasanthbj05 | 265:ae588e75cfa4 | 327 | /*----------------------------------------forming a science packet ends here-----------------------------------------------*/ |
prasanthbj05 | 265:ae588e75cfa4 | 328 | |
prasanthbj05 | 265:ae588e75cfa4 | 329 | /*-----------------------------Inserting the above packet(sfp) into the TM frame(s) starts here----------------------------*/ |
prasanthbj05 | 265:ae588e75cfa4 | 330 | if(id==1){ |
prasanthbj05 | 265:ae588e75cfa4 | 331 | if(position_tm_frame[id]>130){ |
prasanthbj05 | 265:ae588e75cfa4 | 332 | while(position_tm_frame[id]<132){ |
prasanthbj05 | 265:ae588e75cfa4 | 333 | frames[id][position_tm_frame[id]] = 0; |
prasanthbj05 | 265:ae588e75cfa4 | 334 | position_tm_frame[id]++; |
prasanthbj05 | 265:ae588e75cfa4 | 335 | } |
prasanthbj05 | 265:ae588e75cfa4 | 336 | } |
prasanthbj05 | 265:ae588e75cfa4 | 337 | } |
prasanthbj05 | 265:ae588e75cfa4 | 338 | else if(id==2){ |
prasanthbj05 | 265:ae588e75cfa4 | 339 | if(position_tm_frame[id]>126){ |
prasanthbj05 | 265:ae588e75cfa4 | 340 | while(position_tm_frame[id]<132){ |
prasanthbj05 | 265:ae588e75cfa4 | 341 | frames[id][position_tm_frame[id]] = 0; |
prasanthbj05 | 265:ae588e75cfa4 | 342 | position_tm_frame[id]++; |
prasanthbj05 | 265:ae588e75cfa4 | 343 | } |
prasanthbj05 | 265:ae588e75cfa4 | 344 | } |
prasanthbj05 | 265:ae588e75cfa4 | 345 | } |
prasanthbj05 | 265:ae588e75cfa4 | 346 | if(position_tm_frame[id]==position_tm_starting[id]){ |
prasanthbj05 | 265:ae588e75cfa4 | 347 | frames[id][6-id] = position_tm_starting[id]; |
prasanthbj05 | 265:ae588e75cfa4 | 348 | } |
prasanthbj05 | 265:ae588e75cfa4 | 349 | for(uint16_t j=0 ; j<length ;) |
prasanthbj05 | 265:ae588e75cfa4 | 350 | { |
prasanthbj05 | 265:ae588e75cfa4 | 351 | if(position_tm_frame[id]==frames[id][6-id]){ |
prasanthbj05 | 265:ae588e75cfa4 | 352 | if(id==1){ |
prasanthbj05 | 265:ae588e75cfa4 | 353 | frames[id][6] = (uint8_t)((sci_time>>32)&0x07); |
prasanthbj05 | 265:ae588e75cfa4 | 354 | frames[id][7] = (uint8_t)((sci_time>>24)&0xff); |
prasanthbj05 | 265:ae588e75cfa4 | 355 | frames[id][8] = (uint8_t)((sci_time>>16)&0xff); |
prasanthbj05 | 265:ae588e75cfa4 | 356 | frames[id][9] = (uint8_t)((sci_time>>8)&0xff); |
prasanthbj05 | 265:ae588e75cfa4 | 357 | frames[id][10] = (uint8_t)((sci_time)&0xff); |
prasanthbj05 | 265:ae588e75cfa4 | 358 | } |
prasanthbj05 | 265:ae588e75cfa4 | 359 | } |
prasanthbj05 | 265:ae588e75cfa4 | 360 | if(position_tm_frame[id]<132){ |
prasanthbj05 | 265:ae588e75cfa4 | 361 | frames[id][position_tm_frame[id]] = sfp[j]; |
prasanthbj05 | 265:ae588e75cfa4 | 362 | j++; |
prasanthbj05 | 265:ae588e75cfa4 | 363 | position_tm_frame[id]++; //incrementing position of write pointer in TM frame |
prasanthbj05 | 265:ae588e75cfa4 | 364 | } |
prasanthbj05 | 265:ae588e75cfa4 | 365 | if(position_tm_frame[id] == 132) |
prasanthbj05 | 265:ae588e75cfa4 | 366 | { |
prasanthbj05 | 265:ae588e75cfa4 | 367 | /*-----------the current frame is completely filled and we fill frame header to write into SD card---------*/ |
ee12b079 | 93:4d76de54a699 | 368 | pointer = frames[id]; |
prasanthbj05 | 265:ae588e75cfa4 | 369 | if(id == 1){ //below threshold |
ee12b079 | 93:4d76de54a699 | 370 | space = adjust(1,0,pointer,8); |
ee12b079 | 93:4d76de54a699 | 371 | space = adjust(4,3,pointer,space); |
prasanthbj05 | 265:ae588e75cfa4 | 372 | FSC_science = FSC_CURRENT[3]; ///to be used as this, but FSC_CURRENT[] is 32 bit |
ee12b079 | 93:4d76de54a699 | 373 | frames[id][1] = (FSC_science>>24)&0xff; |
ee12b079 | 93:4d76de54a699 | 374 | frames[id][2] = (FSC_science>>16)&0xff; |
ee12b079 | 93:4d76de54a699 | 375 | frames[id][3] = (FSC_science>>8)&0xff; |
prasanthbj05 | 265:ae588e75cfa4 | 376 | frames[id][4] = FSC_science&0xff; |
prasanthbj05 | 265:ae588e75cfa4 | 377 | } |
prasanthbj05 | 265:ae588e75cfa4 | 378 | else if(id == 2) //above threshold |
prasanthbj05 | 265:ae588e75cfa4 | 379 | { |
ee12b079 | 93:4d76de54a699 | 380 | space = adjust(1,0,pointer,8); |
prasanthbj05 | 265:ae588e75cfa4 | 381 | space = adjust(4,2,pointer,space); |
prasanthbj05 | 265:ae588e75cfa4 | 382 | FSC_science = FSC_CURRENT[2]; ///to be used as this |
ee12b079 | 93:4d76de54a699 | 383 | frames[id][1] = (FSC_science>>16)&0xff; |
ee12b079 | 93:4d76de54a699 | 384 | frames[id][2] = (FSC_science>>8)&0xff; |
ee12b079 | 93:4d76de54a699 | 385 | frames[id][3] = FSC_science&0xff; |
ee12b079 | 93:4d76de54a699 | 386 | } |
ee12b079 | 93:4d76de54a699 | 387 | temp_crc = crc16_gen(frames[id],132); |
ee12b079 | 93:4d76de54a699 | 388 | frames[id][132] = temp_crc>>8; |
ee12b079 | 93:4d76de54a699 | 389 | frames[id][133] = temp_crc & 0xff; |
prasanthbj05 | 265:ae588e75cfa4 | 390 | |
prasanthbj05 | 265:ae588e75cfa4 | 391 | /*------------------current TM frame completely filled-----------------------*/ |
ee12b079 | 171:31bdf83591a1 | 392 | |
ee12b079 | 114:9fb55057b13f | 393 | exor(frames[id]); |
ee12b079 | 93:4d76de54a699 | 394 | convolution(frames[id]); |
ee12b079 | 93:4d76de54a699 | 395 | interleave(TM_convoluted_data,TM_interleave_data); |
ee12b079 | 93:4d76de54a699 | 396 | interleave(TM_convoluted_data+ 135,TM_interleave_data + 144); |
prasanthbj05 | 265:ae588e75cfa4 | 397 | if(id == 1) |
ee12b079 | 195:6a549c0e9287 | 398 | { |
prasanthbj05 | 265:ae588e75cfa4 | 399 | SD_WRITE(TM_interleave_data,FSC_science+1,3); //sd_write will return ack later, for now not included |
prasanthbj05 | 265:ae588e75cfa4 | 400 | } |
prasanthbj05 | 265:ae588e75cfa4 | 401 | else if (id == 2) |
prasanthbj05 | 265:ae588e75cfa4 | 402 | { |
prasanthbj05 | 265:ae588e75cfa4 | 403 | SD_WRITE(TM_interleave_data,FSC_science+1,2); //sd_write will return ack later, for now not included |
prasanthbj05 | 265:ae588e75cfa4 | 404 | } |
ee12b079 | 93:4d76de54a699 | 405 | position_tm_frame[id] = position_tm_starting[id]; |
prasanthbj05 | 265:ae588e75cfa4 | 406 | frames[id][6-id] = ((length-1) - j)+position_tm_starting[id]; |
ee12b079 | 93:4d76de54a699 | 407 | } |
shreeshas95 | 1:a0055b3280c8 | 408 | } |
prasanthbj05 | 265:ae588e75cfa4 | 409 | /*------------------------------finished inserting the sfp packet into the TM frame(s)-------------------------------------*/ |
prasanthbj05 | 265:ae588e75cfa4 | 410 | } // for loop bracket which runs 60 times |
ee12b079 | 93:4d76de54a699 | 411 | at = 0; pzf = 1; ezf = 1; |
ee12b079 | 93:4d76de54a699 | 412 | srp_mode = head[2]&0x1; |
prasanthbj05 | 265:ae588e75cfa4 | 413 | uint8_t compression_option = (head[2]>>1)&0x3; |
prasanthbj05 | 265:ae588e75cfa4 | 414 | /*-------------------------------Tagging the scp packet formed from these 60 sfp's as AT or BT starts here------------------------- |
prasanthbj05 | 265:ae588e75cfa4 | 415 | ------------------(in case compression option = 0 , then tagging beacon packet(not yet formed) as AT or BT is also done)----------*/ |
prasanthbj05 | 265:ae588e75cfa4 | 416 | if(srp_mode ==0) |
prasanthbj05 | 265:ae588e75cfa4 | 417 | { |
prasanthbj05 | 265:ae588e75cfa4 | 418 | if(compression_option == 0) |
prasanthbj05 | 265:ae588e75cfa4 | 419 | { |
prasanthbj05 | 265:ae588e75cfa4 | 420 | for(int i=0; i<52 ;i++) |
prasanthbj05 | 265:ae588e75cfa4 | 421 | { |
prasanthbj05 | 265:ae588e75cfa4 | 422 | if(scp_bin[i] > scp_threshold_m0[i]) |
prasanthbj05 | 265:ae588e75cfa4 | 423 | { |
ee12b079 | 93:4d76de54a699 | 424 | at = 1; |
shreeshas95 | 1:a0055b3280c8 | 425 | break; |
shreeshas95 | 1:a0055b3280c8 | 426 | } |
shreeshas95 | 1:a0055b3280c8 | 427 | } |
ee12b079 | 93:4d76de54a699 | 428 | } |
prasanthbj05 | 265:ae588e75cfa4 | 429 | else if(compression_option == 1) |
prasanthbj05 | 265:ae588e75cfa4 | 430 | { |
ee12b079 | 93:4d76de54a699 | 431 | if(scp_bin[44] > scp_threshold_m0_1[0]) at=1; |
prasanthbj05 | 265:ae588e75cfa4 | 432 | for(int i=0; i<4 ;i++) |
prasanthbj05 | 265:ae588e75cfa4 | 433 | { |
prasanthbj05 | 265:ae588e75cfa4 | 434 | if(scp_bin[48+i] > scp_threshold_m0_1[i+1]) |
prasanthbj05 | 265:ae588e75cfa4 | 435 | { |
ee12b079 | 93:4d76de54a699 | 436 | at = 1; |
ee12b079 | 93:4d76de54a699 | 437 | break; |
ee12b079 | 93:4d76de54a699 | 438 | } |
shreeshas95 | 1:a0055b3280c8 | 439 | } |
ee12b079 | 93:4d76de54a699 | 440 | if(scp_bin[17] > scp_threshold_m0_1[5]) at=1; |
ee12b079 | 93:4d76de54a699 | 441 | if(scp_bin[23] > scp_threshold_m0_1[6]) at=1; |
prasanthbj05 | 265:ae588e75cfa4 | 442 | |
ee12b079 | 93:4d76de54a699 | 443 | proton_scp_sum = 0; electron_scp_sum = 0; |
prasanthbj05 | 265:ae588e75cfa4 | 444 | for(int i=0;i<17;i++) |
prasanthbj05 | 265:ae588e75cfa4 | 445 | { |
ee12b079 | 93:4d76de54a699 | 446 | proton_scp_sum += scp_bin[i]; |
shreeshas95 | 1:a0055b3280c8 | 447 | } |
prasanthbj05 | 265:ae588e75cfa4 | 448 | for(int i=0; i<5; i++) |
prasanthbj05 | 265:ae588e75cfa4 | 449 | { |
ee12b079 | 93:4d76de54a699 | 450 | electron_scp_sum += scp_bin[18+i]; |
ee12b079 | 93:4d76de54a699 | 451 | } |
ee12b079 | 93:4d76de54a699 | 452 | if(proton_scp_sum > scp_threshold_m0_1[7]) at=1; |
ee12b079 | 93:4d76de54a699 | 453 | if(electron_scp_sum > scp_threshold_m0_1[8]) at=1; |
shreeshas95 | 1:a0055b3280c8 | 454 | } |
prasanthbj05 | 265:ae588e75cfa4 | 455 | else if(compression_option == 2) |
prasanthbj05 | 265:ae588e75cfa4 | 456 | { |
prasanthbj05 | 265:ae588e75cfa4 | 457 | if(scp_bin[50] > scp_sfp_threshold_m0_2[0]) at=1; |
prasanthbj05 | 265:ae588e75cfa4 | 458 | proton_scp_sum = 0; electron_scp_sum = 0; |
prasanthbj05 | 265:ae588e75cfa4 | 459 | for(int i=0;i<17;i++) |
prasanthbj05 | 265:ae588e75cfa4 | 460 | { |
prasanthbj05 | 265:ae588e75cfa4 | 461 | proton_scp_sum += scp_bin[i]; |
prasanthbj05 | 265:ae588e75cfa4 | 462 | } |
prasanthbj05 | 265:ae588e75cfa4 | 463 | for(int i=0; i<5; i++) |
prasanthbj05 | 265:ae588e75cfa4 | 464 | { |
prasanthbj05 | 265:ae588e75cfa4 | 465 | electron_scp_sum += scp_bin[18+i]; |
prasanthbj05 | 265:ae588e75cfa4 | 466 | } |
prasanthbj05 | 265:ae588e75cfa4 | 467 | if(proton_scp_sum > scp_sfp_threshold_m0_2[1]) at=1; |
prasanthbj05 | 265:ae588e75cfa4 | 468 | if(electron_scp_sum > scp_sfp_threshold_m0_2[2]) at=1; |
prasanthbj05 | 265:ae588e75cfa4 | 469 | } |
prasanthbj05 | 265:ae588e75cfa4 | 470 | } |
prasanthbj05 | 265:ae588e75cfa4 | 471 | else if(srp_mode ==1) |
prasanthbj05 | 265:ae588e75cfa4 | 472 | { |
prasanthbj05 | 265:ae588e75cfa4 | 473 | if(compression_option==0){ |
prasanthbj05 | 265:ae588e75cfa4 | 474 | for(int i=0; i<48; i++) |
prasanthbj05 | 265:ae588e75cfa4 | 475 | { |
prasanthbj05 | 265:ae588e75cfa4 | 476 | if(scp_bin[i] > scp_threshold_m1[i]){ |
prasanthbj05 | 265:ae588e75cfa4 | 477 | at = 1; |
prasanthbj05 | 265:ae588e75cfa4 | 478 | break; |
prasanthbj05 | 265:ae588e75cfa4 | 479 | } |
prasanthbj05 | 265:ae588e75cfa4 | 480 | } |
prasanthbj05 | 265:ae588e75cfa4 | 481 | for(int i=48; i<52; i++) |
prasanthbj05 | 265:ae588e75cfa4 | 482 | { |
prasanthbj05 | 265:ae588e75cfa4 | 483 | if(scp_bin[i] > scp_threshold_m1[i]){ |
prasanthbj05 | 265:ae588e75cfa4 | 484 | at = 1; |
prasanthbj05 | 265:ae588e75cfa4 | 485 | break; |
prasanthbj05 | 265:ae588e75cfa4 | 486 | } |
shreeshas95 | 1:a0055b3280c8 | 487 | } |
shreeshas95 | 1:a0055b3280c8 | 488 | } |
prasanthbj05 | 265:ae588e75cfa4 | 489 | else if(compression_option==2){ |
prasanthbj05 | 265:ae588e75cfa4 | 490 | if(scp_bin[50]>scp_sfp_threshold_m0_2[0]) at=1; |
prasanthbj05 | 265:ae588e75cfa4 | 491 | } |
prasanthbj05 | 265:ae588e75cfa4 | 492 | } |
prasanthbj05 | 265:ae588e75cfa4 | 493 | /*----------------------------Tagging the scp packet formed from these 60 sfp's as AT or BT ends here--------------------------*/ |
prasanthbj05 | 265:ae588e75cfa4 | 494 | |
prasanthbj05 | 265:ae588e75cfa4 | 495 | if(srp_mode == 0) |
prasanthbj05 | 265:ae588e75cfa4 | 496 | { |
prasanthbj05 | 265:ae588e75cfa4 | 497 | //determining if non zero values of proton and electron bins exist for calibrated mode (srp) |
prasanthbj05 | 265:ae588e75cfa4 | 498 | for(int i=0; i<17 ;i++) |
prasanthbj05 | 265:ae588e75cfa4 | 499 | { |
prasanthbj05 | 265:ae588e75cfa4 | 500 | if(scp_bin[i]>0) |
prasanthbj05 | 265:ae588e75cfa4 | 501 | pzf = 0; |
prasanthbj05 | 265:ae588e75cfa4 | 502 | } |
prasanthbj05 | 265:ae588e75cfa4 | 503 | for(int i=18; i<23 ;i++) |
prasanthbj05 | 265:ae588e75cfa4 | 504 | { |
prasanthbj05 | 265:ae588e75cfa4 | 505 | if(scp_bin[i]>0) |
prasanthbj05 | 265:ae588e75cfa4 | 506 | ezf = 0; |
prasanthbj05 | 265:ae588e75cfa4 | 507 | } |
prasanthbj05 | 265:ae588e75cfa4 | 508 | } |
prasanthbj05 | 265:ae588e75cfa4 | 509 | /*-----------------------------------------Tagging beacon packet as AT or BT starts here-------------------------------------*/ |
prasanthbj05 | 265:ae588e75cfa4 | 510 | beacon_at = 0; |
prasanthbj05 | 265:ae588e75cfa4 | 511 | if(srp_mode==0) //those bins which can be meaningfully compared only in srp_mode==0 |
prasanthbj05 | 265:ae588e75cfa4 | 512 | { |
prasanthbj05 | 265:ae588e75cfa4 | 513 | if(scp_bin[44]>beacon_threshold[0]) beacon_at = 1; |
prasanthbj05 | 265:ae588e75cfa4 | 514 | if(scp_bin[17]>beacon_threshold[5]) beacon_at = 1; |
prasanthbj05 | 265:ae588e75cfa4 | 515 | if(scp_bin[23]>beacon_threshold[6]) beacon_at = 1; |
prasanthbj05 | 265:ae588e75cfa4 | 516 | proton_scp_sum = 0; electron_scp_sum = 0; |
prasanthbj05 | 265:ae588e75cfa4 | 517 | for(int i=0;i<17;i++) |
prasanthbj05 | 265:ae588e75cfa4 | 518 | { |
prasanthbj05 | 265:ae588e75cfa4 | 519 | proton_scp_sum += scp_bin[i]; |
prasanthbj05 | 265:ae588e75cfa4 | 520 | } |
prasanthbj05 | 265:ae588e75cfa4 | 521 | for(int i=0; i<5; i++) |
prasanthbj05 | 265:ae588e75cfa4 | 522 | { |
prasanthbj05 | 265:ae588e75cfa4 | 523 | electron_scp_sum += scp_bin[18+i]; |
prasanthbj05 | 265:ae588e75cfa4 | 524 | } |
prasanthbj05 | 265:ae588e75cfa4 | 525 | if(proton_scp_sum > beacon_threshold[7]) beacon_at =1; |
prasanthbj05 | 265:ae588e75cfa4 | 526 | if(electron_scp_sum > beacon_threshold[8]) beacon_at =1; |
prasanthbj05 | 265:ae588e75cfa4 | 527 | } |
prasanthbj05 | 265:ae588e75cfa4 | 528 | if(scp_bin[48]>beacon_threshold[1]) beacon_at = 1; |
prasanthbj05 | 265:ae588e75cfa4 | 529 | if(scp_bin[49]>beacon_threshold[2]) beacon_at = 1; |
prasanthbj05 | 265:ae588e75cfa4 | 530 | if(scp_bin[50]>beacon_threshold[3]) beacon_at = 1; |
prasanthbj05 | 265:ae588e75cfa4 | 531 | if(scp_bin[51]>beacon_threshold[4]) beacon_at = 1; |
prasanthbj05 | 265:ae588e75cfa4 | 532 | /*----------------------------------------Tagging beacon packet as AT or BT ends here------------------------------------------*/ |
prasanthbj05 | 265:ae588e75cfa4 | 533 | |
prasanthbj05 | 265:ae588e75cfa4 | 534 | /*-----------------------------------------------Forming the beacon packet starts here-----------------------------------------*/ |
prasanthbj05 | 265:ae588e75cfa4 | 535 | //Last 512 bits of beacon_array excluding CRC bits is used for storing the 5 most recent beacon packets |
prasanthbj05 | 265:ae588e75cfa4 | 536 | |
prasanthbj05 | 265:ae588e75cfa4 | 537 | if(beacon_cntr == 1) |
prasanthbj05 | 265:ae588e75cfa4 | 538 | { |
prasanthbj05 | 265:ae588e75cfa4 | 539 | beacon_ptr = &(beacon_array[62]); // starting block address, stores the oldest(among the 5 most recent) beacon packet |
prasanthbj05 | 265:ae588e75cfa4 | 540 | } |
prasanthbj05 | 265:ae588e75cfa4 | 541 | else if(beacon_cntr>1 && beacon_cntr<6) |
prasanthbj05 | 265:ae588e75cfa4 | 542 | { |
prasanthbj05 | 265:ae588e75cfa4 | 543 | beacon_ptr +=14; // increase the block number(totally 5 blocks for 5 beacon packets) |
prasanthbj05 | 265:ae588e75cfa4 | 544 | } |
prasanthbj05 | 265:ae588e75cfa4 | 545 | else if(beacon_cntr == 6) |
prasanthbj05 | 265:ae588e75cfa4 | 546 | { |
prasanthbj05 | 265:ae588e75cfa4 | 547 | for(uint16_t i=0;i<14;i++) // when all 5 blocks have been used shift the last 4 blocks up along the array and |
prasanthbj05 | 265:ae588e75cfa4 | 548 | { // overwrite the new beacon packet in the 5th block |
prasanthbj05 | 265:ae588e75cfa4 | 549 | beacon_array[62+i] = beacon_array[76+i]; |
prasanthbj05 | 265:ae588e75cfa4 | 550 | beacon_array[76+i] = beacon_array[90+i]; |
prasanthbj05 | 265:ae588e75cfa4 | 551 | beacon_array[90+i] = beacon_array[104+i]; |
prasanthbj05 | 265:ae588e75cfa4 | 552 | beacon_array[104+i] = beacon_array[118+i]; |
prasanthbj05 | 265:ae588e75cfa4 | 553 | } |
prasanthbj05 | 265:ae588e75cfa4 | 554 | beacon_ptr = &(beacon_array[118]); //address of the 5th block |
prasanthbj05 | 265:ae588e75cfa4 | 555 | beacon_cntr = 5; |
prasanthbj05 | 265:ae588e75cfa4 | 556 | } |
prasanthbj05 | 265:ae588e75cfa4 | 557 | pointer = beacon_ptr; debug_cntr = 0; space = 8; |
prasanthbj05 | 265:ae588e75cfa4 | 558 | space = adjust(1, 1,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 559 | space = adjust(5,(sci_time>>8)&0x1f,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 560 | space = adjust(8, sci_time,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 561 | space = adjust(4, (attitude)&0xf,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 562 | |
prasanthbj05 | 265:ae588e75cfa4 | 563 | if(srp_mode==0){ |
prasanthbj05 | 265:ae588e75cfa4 | 564 | if(beacon_at == 0){ |
prasanthbj05 | 265:ae588e75cfa4 | 565 | space = adjust(1, 0,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 566 | space = adjust(6, compress(scp_bin[44],3,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 567 | space = adjust(7, compress(scp_bin[48],4,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 568 | space = adjust(7, compress(scp_bin[49],4,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 569 | space = adjust(7, compress(scp_bin[50],4,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 570 | space = adjust(7, compress(scp_bin[51],4,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 571 | space = adjust(6, compress(scp_bin[17],3,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 572 | space = adjust(6, compress(scp_bin[23],3,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 573 | space = adjust(4, compress(proton_scp_sum ,10,2)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 574 | space = adjust(8, compress(proton_scp_sum ,10,2),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 575 | space = adjust(4, compress(electron_scp_sum ,10,2)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 576 | space = adjust(8, compress(electron_scp_sum ,10,2),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 577 | pointer = pointer + 1; |
prasanthbj05 | 265:ae588e75cfa4 | 578 | for(int temp_i = 12; temp_i<14; temp_i++) |
prasanthbj05 | 265:ae588e75cfa4 | 579 | { |
prasanthbj05 | 265:ae588e75cfa4 | 580 | *pointer = 0; |
prasanthbj05 | 265:ae588e75cfa4 | 581 | pointer = pointer + 1; |
prasanthbj05 | 265:ae588e75cfa4 | 582 | } |
prasanthbj05 | 265:ae588e75cfa4 | 583 | } |
prasanthbj05 | 265:ae588e75cfa4 | 584 | else if(beacon_at==1){ |
prasanthbj05 | 265:ae588e75cfa4 | 585 | space = adjust(1, 1,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 586 | space = adjust(1, compress(sfp_bin[44],6,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 587 | space = adjust(8, compress(sfp_bin[44],6,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 588 | space = adjust(4, compress(sfp_bin[48],9,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 589 | space = adjust(8, compress(sfp_bin[48],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 590 | space = adjust(4, compress(sfp_bin[49],9,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 591 | space = adjust(8, compress(sfp_bin[49],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 592 | space = adjust(4, compress(sfp_bin[50],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 593 | space = adjust(8, compress(sfp_bin[50],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 594 | space = adjust(4, compress(sfp_bin[51],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 595 | space = adjust(8, compress(sfp_bin[51],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 596 | space = adjust(1, compress(sfp_bin[17],6,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 597 | space = adjust(8, compress(sfp_bin[17],6,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 598 | space = adjust(1, compress(sfp_bin[23],6,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 599 | space = adjust(8, compress(sfp_bin[23],6,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 600 | space = adjust(1, compress(proton_scp_sum ,6,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 601 | space = adjust(8, compress(proton_scp_sum ,6,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 602 | space = adjust(1, compress(electron_scp_sum,6,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 603 | space = adjust(8, compress(electron_scp_sum ,6,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 604 | //cout<<"for beacon space = "<<(space&0x0f)<<" counter = "<<debug_cntr; |
prasanthbj05 | 265:ae588e75cfa4 | 605 | } |
prasanthbj05 | 265:ae588e75cfa4 | 606 | }else if(srp_mode==1){ |
prasanthbj05 | 265:ae588e75cfa4 | 607 | if(beacon_at==0){ |
prasanthbj05 | 265:ae588e75cfa4 | 608 | space = adjust(1, 0,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 609 | space = adjust(6, compress(0,3,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 610 | space = adjust(7, compress(sfp_bin[48],4,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 611 | space = adjust(7, compress(sfp_bin[49],4,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 612 | space = adjust(7, compress(sfp_bin[50],4,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 613 | space = adjust(7, compress(sfp_bin[51],4,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 614 | pointer = pointer + 1; |
prasanthbj05 | 265:ae588e75cfa4 | 615 | for(uint8_t temp_i = 7; temp_i<14; temp_i++) |
prasanthbj05 | 265:ae588e75cfa4 | 616 | { |
prasanthbj05 | 265:ae588e75cfa4 | 617 | *pointer = 0; |
prasanthbj05 | 265:ae588e75cfa4 | 618 | pointer = pointer + 1; |
prasanthbj05 | 265:ae588e75cfa4 | 619 | } |
prasanthbj05 | 265:ae588e75cfa4 | 620 | } |
prasanthbj05 | 265:ae588e75cfa4 | 621 | else if(beacon_at==1){ |
prasanthbj05 | 265:ae588e75cfa4 | 622 | space = adjust(1, 1,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 623 | space = adjust(1, compress(0,6,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 624 | space = adjust(8, compress(0,6,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 625 | space = adjust(4, compress(sfp_bin[48],9,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 626 | space = adjust(8, compress(sfp_bin[48],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 627 | space = adjust(4, compress(sfp_bin[49],9,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 628 | space = adjust(8, compress(sfp_bin[49],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 629 | space = adjust(4, compress(sfp_bin[50],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 630 | space = adjust(8, compress(sfp_bin[50],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 631 | space = adjust(4, compress(sfp_bin[51],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 632 | space = adjust(8, compress(sfp_bin[51],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 633 | pointer = pointer + 1; |
prasanthbj05 | 265:ae588e75cfa4 | 634 | for(uint8_t temp_i = 10; temp_i<14; temp_i++) |
prasanthbj05 | 265:ae588e75cfa4 | 635 | { |
prasanthbj05 | 265:ae588e75cfa4 | 636 | *pointer = 0; |
prasanthbj05 | 265:ae588e75cfa4 | 637 | pointer = pointer + 1; |
ee12b079 | 93:4d76de54a699 | 638 | } |
shreeshas95 | 1:a0055b3280c8 | 639 | } |
shreeshas95 | 1:a0055b3280c8 | 640 | } |
prasanthbj05 | 265:ae588e75cfa4 | 641 | beacon_cntr++; |
prasanthbj05 | 265:ae588e75cfa4 | 642 | /*--------------------------------------------------beacon packet ends here--------------------------------------------------------*/ |
prasanthbj05 | 265:ae588e75cfa4 | 643 | |
prasanthbj05 | 265:ae588e75cfa4 | 644 | gPC.printf("scp\r\n"); |
prasanthbj05 | 265:ae588e75cfa4 | 645 | uint8_t packet_pp,time_diff; |
prasanthbj05 | 265:ae588e75cfa4 | 646 | /*------------------------------------------Forming a science packet(scp) starts here----------------------------------------------*/ |
prasanthbj05 | 265:ae588e75cfa4 | 647 | |
ee12b079 | 93:4d76de54a699 | 648 | pointer = scp; debug_cntr = 0; space = 8; |
prasanthbj05 | 265:ae588e75cfa4 | 649 | time_diff = 0; |
prasanthbj05 | 265:ae588e75cfa4 | 650 | |
prasanthbj05 | 265:ae588e75cfa4 | 651 | packet_pp = 1; |
prasanthbj05 | 265:ae588e75cfa4 | 652 | if((((uint8_t)(sci_time>>7))&0x3f)<(((uint8_t)(time_prev_scp>>7))&0x3f)) |
prasanthbj05 | 265:ae588e75cfa4 | 653 | { |
prasanthbj05 | 265:ae588e75cfa4 | 654 | time_diff = time_diff+60; |
prasanthbj05 | 265:ae588e75cfa4 | 655 | } |
prasanthbj05 | 265:ae588e75cfa4 | 656 | time_diff += (((uint8_t)(sci_time>>7))&0x3f); |
prasanthbj05 | 265:ae588e75cfa4 | 657 | time_diff -= (((uint8_t)(time_prev_scp>>7))&0x3f); |
prasanthbj05 | 265:ae588e75cfa4 | 658 | if(time_diff>10){ |
prasanthbj05 | 265:ae588e75cfa4 | 659 | packet_pp = 0; |
prasanthbj05 | 265:ae588e75cfa4 | 660 | } |
prasanthbj05 | 265:ae588e75cfa4 | 661 | time_prev_scp = sci_time; |
prasanthbj05 | 265:ae588e75cfa4 | 662 | uint32_t sfp_at_counter; |
prasanthbj05 | 265:ae588e75cfa4 | 663 | sfp_at_counter = FSC_CURRENT[2]; |
prasanthbj05 | 265:ae588e75cfa4 | 664 | space = adjust(1, packet_pp,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 665 | space = adjust(5, (sci_time>>8)&0x1f,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 666 | space = adjust(8, (sci_time)&0xff,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 667 | space = adjust(4, (attitude)&0xf,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 668 | space = adjust(2, compression_option,pointer,space); pointer += space>>4; debug_cntr += space>>4; //first two bits of compression option |
prasanthbj05 | 265:ae588e75cfa4 | 669 | space = adjust(1, at,pointer,space); pointer += space>>4; debug_cntr += space>>4; //last bit of compression option |
prasanthbj05 | 265:ae588e75cfa4 | 670 | space = adjust(1, srp_mode,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 671 | if(!(srp_mode==0 && compression_option==2)) |
prasanthbj05 | 265:ae588e75cfa4 | 672 | { |
prasanthbj05 | 265:ae588e75cfa4 | 673 | space = adjust(8, sfp_at_counter>>16,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 674 | space = adjust(8, sfp_at_counter>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 675 | space = adjust(8, sfp_at_counter,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 676 | } |
ee12b079 | 93:4d76de54a699 | 677 | if(srp_mode == 0 && compression_option == 0){ //normal callibrated mode |
prasanthbj05 | 265:ae588e75cfa4 | 678 | space = adjust(1, pzf,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 679 | space = adjust(1, ezf,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 680 | if(at == 0 ){ |
ee12b079 | 93:4d76de54a699 | 681 | for(int i = 0; i<8 ;i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 682 | space = adjust(7,compress(scp_bin[24+i],4,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 683 | } |
ee12b079 | 93:4d76de54a699 | 684 | for(int i = 0; i<12 ;i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 685 | space = adjust(5,compress(scp_bin[32+i],2,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 686 | } |
ee12b079 | 93:4d76de54a699 | 687 | for(int i = 0; i<4 ;i++){ |
ee12b079 | 93:4d76de54a699 | 688 | space = adjust(6,compress(scp_bin[44+i],3,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 689 | } |
ee12b079 | 93:4d76de54a699 | 690 | for(int i = 0; i<4 ;i++){ |
ee12b079 | 93:4d76de54a699 | 691 | space = adjust(7,compress(scp_bin[48+i],4,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 692 | } |
prasanthbj05 | 265:ae588e75cfa4 | 693 | space = adjust(6,compress(scp_bin[17],3,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 694 | space = adjust(6,compress(scp_bin[23],3,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 695 | if(pzf == 0){ |
ee12b079 | 93:4d76de54a699 | 696 | for(int i = 0; i<2 ;i++){ |
ee12b079 | 93:4d76de54a699 | 697 | space = adjust(8,compress(scp_bin[i],6,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 698 | } |
ee12b079 | 93:4d76de54a699 | 699 | for(int i = 0; i<15 ;i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 700 | space = adjust(7,compress(scp_bin[i+2],5,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 701 | } |
ee12b079 | 93:4d76de54a699 | 702 | } |
ee12b079 | 93:4d76de54a699 | 703 | if(ezf == 0){ |
ee12b079 | 93:4d76de54a699 | 704 | space = adjust(1,compress(scp_bin[18],7,2)>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 705 | space = adjust(8,compress(scp_bin[18],7,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 706 | for(int i=0; i<4; i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 707 | space = adjust(8,compress(scp_bin[19+i],6,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 708 | } |
ee12b079 | 93:4d76de54a699 | 709 | } |
ee12b079 | 93:4d76de54a699 | 710 | }// below threshold ends here |
ee12b079 | 93:4d76de54a699 | 711 | if(at == 1){ |
ee12b079 | 93:4d76de54a699 | 712 | for(int i = 0; i<8 ;i++){ |
ee12b079 | 93:4d76de54a699 | 713 | space = adjust(7,compress(scp_bin[24+i],4,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 714 | } |
ee12b079 | 93:4d76de54a699 | 715 | for(int i = 0; i<12 ;i++){ |
ee12b079 | 93:4d76de54a699 | 716 | space = adjust(5,compress(scp_bin[32+i],2,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 717 | } |
ee12b079 | 93:4d76de54a699 | 718 | for(int i = 0; i<4 ;i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 719 | space = adjust(1,compress(scp_bin[44+i],6,3)>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 720 | space = adjust(8,compress(scp_bin[44+i],6,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 721 | } |
ee12b079 | 93:4d76de54a699 | 722 | for(int i=0; i<4 ;i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 723 | space = adjust(4,compress(scp_bin[48+i],9,3)>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 724 | space = adjust(8,compress(scp_bin[48+i],9,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 725 | } |
prasanthbj05 | 265:ae588e75cfa4 | 726 | space = adjust(1,compress(scp_bin[17],6,3)>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 727 | space = adjust(8,compress(scp_bin[17],6,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 728 | space = adjust(1,compress(scp_bin[23],6,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 729 | space = adjust(8,compress(scp_bin[23],6,3),pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 730 | |
ee12b079 | 93:4d76de54a699 | 731 | if(pzf == 0){ |
ee12b079 | 93:4d76de54a699 | 732 | for(int i = 0; i<17 ; i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 733 | space = adjust(8, (compress(scp_bin[i],5,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 734 | } |
ee12b079 | 93:4d76de54a699 | 735 | } |
ee12b079 | 93:4d76de54a699 | 736 | if(ezf == 0){ |
ee12b079 | 93:4d76de54a699 | 737 | for(int i = 0; i<5 ; i++){ |
ee12b079 | 93:4d76de54a699 | 738 | space = adjust(8, (compress(scp_bin[18+i],5,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 739 | } |
ee12b079 | 93:4d76de54a699 | 740 | } |
ee12b079 | 93:4d76de54a699 | 741 | } //above thresholds ends |
ee12b079 | 93:4d76de54a699 | 742 | } //srp_mode == 0 ends |
ee12b079 | 93:4d76de54a699 | 743 | if(srp_mode == 1){ |
ee12b079 | 93:4d76de54a699 | 744 | if(at == 0){ |
prasanthbj05 | 265:ae588e75cfa4 | 745 | for(int i=0; i<48; i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 746 | space = adjust(6, ((compress(scp_bin[i],3,3))&0xff) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 747 | } |
ee12b079 | 93:4d76de54a699 | 748 | for(int i = 0 ; i < 4 ; i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 749 | space = adjust(7, (compress(scp_bin[48+i],4,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 750 | } |
ee12b079 | 93:4d76de54a699 | 751 | } |
ee12b079 | 93:4d76de54a699 | 752 | if(at == 1){ |
prasanthbj05 | 265:ae588e75cfa4 | 753 | for(int i=0; i<48; i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 754 | space = adjust(7, (compress((scp_bin[i]/2),4,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 755 | } |
ee12b079 | 93:4d76de54a699 | 756 | for(int i = 0 ; i < 4 ; i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 757 | space = adjust(4, (compress(scp_bin[48+i],9,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 758 | space = adjust(8, (compress(scp_bin[48+i],9,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 759 | } |
ee12b079 | 93:4d76de54a699 | 760 | } |
ee12b079 | 93:4d76de54a699 | 761 | }// scp mode 1 end |
ee12b079 | 93:4d76de54a699 | 762 | if( srp_mode == 0 && compression_option == 1 ){ //scp data conservation mode |
ee12b079 | 93:4d76de54a699 | 763 | space = adjust(1, pzf,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 764 | space = adjust(1, ezf,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 765 | if(at == 0){ |
prasanthbj05 | 265:ae588e75cfa4 | 766 | space = adjust(6, (compress(scp_bin[44],3,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 767 | for(int i=0; i<4; i++){ |
prasanthbj05 | 265:ae588e75cfa4 | 768 | space = adjust(7, (compress(scp_bin[48+i],4,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 769 | } |
prasanthbj05 | 265:ae588e75cfa4 | 770 | space = adjust(6, (compress(scp_bin[17],3,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 771 | space = adjust(6, (compress(scp_bin[23],3,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 772 | if(pzf==0){ |
prasanthbj05 | 265:ae588e75cfa4 | 773 | space = adjust(4, (compress(proton_scp_sum,10,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 774 | space = adjust(8, ( compress(proton_scp_sum,10,2)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 775 | } |
prasanthbj05 | 265:ae588e75cfa4 | 776 | if(ezf==0){ |
prasanthbj05 | 265:ae588e75cfa4 | 777 | space = adjust(4, (compress(electron_scp_sum,10,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 778 | space = adjust(8, (compress(electron_scp_sum,10,2)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 779 | } |
ee12b079 | 93:4d76de54a699 | 780 | }else if(at == 1){ |
prasanthbj05 | 265:ae588e75cfa4 | 781 | space = adjust(1, (compress(scp_bin[44],6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 782 | space = adjust(8, (compress(scp_bin[44],6,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 783 | for(int i=0; i<4; i++){ |
ee12b079 | 93:4d76de54a699 | 784 | space = adjust(4, (compress(scp_bin[48+i],9,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 785 | space = adjust(8, (compress(scp_bin[48+i],9,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 786 | } |
prasanthbj05 | 265:ae588e75cfa4 | 787 | space = adjust(1, (compress(scp_bin[17],6,3)>>8) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 788 | space = adjust(8, (compress(scp_bin[17],6,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 789 | space = adjust(1, (compress(scp_bin[23],6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 790 | space = adjust(8, (compress(scp_bin[23],6,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 791 | if(pzf==0){ |
prasanthbj05 | 265:ae588e75cfa4 | 792 | space = adjust(1, (compress(proton_scp_sum,6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 793 | space = adjust(8, (compress(proton_scp_sum,6,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 794 | } |
ee12b079 | 93:4d76de54a699 | 795 | if(ezf==0){ |
prasanthbj05 | 265:ae588e75cfa4 | 796 | space = adjust(1, (compress(electron_scp_sum,6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 797 | space = adjust(8, (compress(electron_scp_sum,6,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
ee12b079 | 93:4d76de54a699 | 798 | } |
ee12b079 | 93:4d76de54a699 | 799 | } |
prasanthbj05 | 265:ae588e75cfa4 | 800 | } |
prasanthbj05 | 265:ae588e75cfa4 | 801 | if(compression_option == 2 ) //scp extreme data conservation mode |
prasanthbj05 | 265:ae588e75cfa4 | 802 | { |
prasanthbj05 | 265:ae588e75cfa4 | 803 | if(srp_mode==0) |
prasanthbj05 | 265:ae588e75cfa4 | 804 | { |
prasanthbj05 | 265:ae588e75cfa4 | 805 | space = adjust(1, pzf,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 806 | space = adjust(1, ezf,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 807 | if(at==0){ |
prasanthbj05 | 265:ae588e75cfa4 | 808 | space = adjust(7, (compress(scp_bin[50],4,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 809 | if(pzf==0){ |
prasanthbj05 | 265:ae588e75cfa4 | 810 | space = adjust(4, (compress(proton_scp_sum,10,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 811 | space = adjust(8, ( compress(proton_scp_sum,10,2)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 812 | } |
prasanthbj05 | 265:ae588e75cfa4 | 813 | if(ezf==0){ |
prasanthbj05 | 265:ae588e75cfa4 | 814 | space = adjust(4, (compress(electron_scp_sum,10,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 815 | space = adjust(8, (compress(electron_scp_sum,10,2)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 816 | } |
prasanthbj05 | 265:ae588e75cfa4 | 817 | }else if(at==1){ |
prasanthbj05 | 265:ae588e75cfa4 | 818 | space = adjust(4, (compress(scp_bin[50],9,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 819 | space = adjust(8, (compress(scp_bin[50],9,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 820 | if(pzf==0){ |
prasanthbj05 | 265:ae588e75cfa4 | 821 | space = adjust(1, (compress(proton_scp_sum,6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 822 | space = adjust(8, (compress(proton_scp_sum,6,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 823 | } |
prasanthbj05 | 265:ae588e75cfa4 | 824 | if(ezf==0){ |
prasanthbj05 | 265:ae588e75cfa4 | 825 | space = adjust(1, (compress(electron_scp_sum,6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 826 | space = adjust(8, (compress(electron_scp_sum,6,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 827 | } |
prasanthbj05 | 265:ae588e75cfa4 | 828 | } |
prasanthbj05 | 265:ae588e75cfa4 | 829 | } |
prasanthbj05 | 265:ae588e75cfa4 | 830 | else if(srp_mode==1) |
prasanthbj05 | 265:ae588e75cfa4 | 831 | { |
prasanthbj05 | 265:ae588e75cfa4 | 832 | pzf = 0; ezf = 0; //because proton energy bins are not available in scatter plot mode and hence in the packet we send dummy data(which is nothng but the maximum value which fits into that particular compression scheme) |
prasanthbj05 | 265:ae588e75cfa4 | 833 | space = adjust(1, pzf,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 834 | space = adjust(1, ezf,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 835 | if(at==0){ |
prasanthbj05 | 265:ae588e75cfa4 | 836 | space = adjust(7, (compress(scp_bin[50],4,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 837 | // below 4 lines - filling the proton ane electron energy bins with zeros(junk value) since they're not available in srp |
prasanthbj05 | 265:ae588e75cfa4 | 838 | space = adjust(4, (compress(0,10,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 839 | space = adjust(8, (compress(0,10,2)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 840 | space = adjust(4, (compress(0,10,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 841 | space = adjust(8, (compress(0,10,2)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 842 | } |
prasanthbj05 | 265:ae588e75cfa4 | 843 | else if(at==1){ |
prasanthbj05 | 265:ae588e75cfa4 | 844 | space = adjust(4, (compress(scp_bin[50],9,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 845 | space = adjust(8, (compress(scp_bin[50],9,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 846 | space = adjust(1, (compress(0,6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 847 | space = adjust(8, (compress(0,6,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 848 | space = adjust(1, (compress(0,6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 849 | space = adjust(8, (compress(0,6,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4; |
prasanthbj05 | 265:ae588e75cfa4 | 850 | } |
prasanthbj05 | 265:ae588e75cfa4 | 851 | } |
prasanthbj05 | 265:ae588e75cfa4 | 852 | } |
prasanthbj05 | 265:ae588e75cfa4 | 853 | /*---------------------------------------------forming a science packet ends here----------------------------------------------*/ |
prasanthbj05 | 265:ae588e75cfa4 | 854 | |
ee12b079 | 93:4d76de54a699 | 855 | id = 0; |
ee12b079 | 93:4d76de54a699 | 856 | if(srp_mode == 0 && compression_option == 0){ |
ee12b079 | 93:4d76de54a699 | 857 | if(at == 0){ |
prasanthbj05 | 265:ae588e75cfa4 | 858 | length = 228+2; //2 spare bits |
ee12b079 | 93:4d76de54a699 | 859 | if(pzf == 0) |
ee12b079 | 93:4d76de54a699 | 860 | length += 121; |
ee12b079 | 93:4d76de54a699 | 861 | if(ezf == 0) |
ee12b079 | 93:4d76de54a699 | 862 | length +=41; |
ee12b079 | 93:4d76de54a699 | 863 | }else if(at == 1){ |
prasanthbj05 | 265:ae588e75cfa4 | 864 | length = 266+6; //6 spare bits |
ee12b079 | 93:4d76de54a699 | 865 | if(pzf == 0) |
ee12b079 | 93:4d76de54a699 | 866 | length += 136; |
ee12b079 | 93:4d76de54a699 | 867 | if(ezf == 0) |
ee12b079 | 93:4d76de54a699 | 868 | length += 40; |
ee12b079 | 93:4d76de54a699 | 869 | } |
prasanthbj05 | 265:ae588e75cfa4 | 870 | }else if(srp_mode == 0 && compression_option == 1){ //data conservation mode |
ee12b079 | 93:4d76de54a699 | 871 | if(at == 0){ |
prasanthbj05 | 265:ae588e75cfa4 | 872 | length = 94+2; //2 spare bits |
ee12b079 | 93:4d76de54a699 | 873 | if(pzf == 0) |
ee12b079 | 93:4d76de54a699 | 874 | length += 12; |
ee12b079 | 93:4d76de54a699 | 875 | if(ezf == 0) |
ee12b079 | 93:4d76de54a699 | 876 | length += 12; |
ee12b079 | 93:4d76de54a699 | 877 | }else if(at == 1){ |
prasanthbj05 | 265:ae588e75cfa4 | 878 | length = 123+3; //3 spare bits |
prasanthbj05 | 265:ae588e75cfa4 | 879 | if(pzf == 0) |
prasanthbj05 | 265:ae588e75cfa4 | 880 | length += 9; |
prasanthbj05 | 265:ae588e75cfa4 | 881 | if(ezf == 0) |
prasanthbj05 | 265:ae588e75cfa4 | 882 | length += 9; |
prasanthbj05 | 265:ae588e75cfa4 | 883 | } |
prasanthbj05 | 265:ae588e75cfa4 | 884 | } |
prasanthbj05 | 265:ae588e75cfa4 | 885 | else if( srp_mode == 1){ |
prasanthbj05 | 265:ae588e75cfa4 | 886 | if(at == 0) |
prasanthbj05 | 265:ae588e75cfa4 | 887 | length = 368; |
prasanthbj05 | 265:ae588e75cfa4 | 888 | else if(at == 1) |
prasanthbj05 | 265:ae588e75cfa4 | 889 | length = 432; |
prasanthbj05 | 265:ae588e75cfa4 | 890 | } |
prasanthbj05 | 265:ae588e75cfa4 | 891 | else if(compression_option == 2) //in extreme data conservation mode, length is same for both srp_modes |
prasanthbj05 | 265:ae588e75cfa4 | 892 | { |
prasanthbj05 | 265:ae588e75cfa4 | 893 | if(at == 0){ |
prasanthbj05 | 265:ae588e75cfa4 | 894 | length = 31+1; //1 spare bits |
prasanthbj05 | 265:ae588e75cfa4 | 895 | if(pzf == 0) |
prasanthbj05 | 265:ae588e75cfa4 | 896 | length += 12; |
prasanthbj05 | 265:ae588e75cfa4 | 897 | if(ezf == 0) |
prasanthbj05 | 265:ae588e75cfa4 | 898 | length += 12; |
prasanthbj05 | 265:ae588e75cfa4 | 899 | }else if(at == 1){ |
prasanthbj05 | 265:ae588e75cfa4 | 900 | length = 36+2; //2 spare bits |
ee12b079 | 93:4d76de54a699 | 901 | if(pzf == 0) |
ee12b079 | 93:4d76de54a699 | 902 | length += 9; |
ee12b079 | 93:4d76de54a699 | 903 | if(ezf == 0) |
ee12b079 | 93:4d76de54a699 | 904 | length += 9; |
ee12b079 | 93:4d76de54a699 | 905 | } |
ee12b079 | 93:4d76de54a699 | 906 | } |
ee12b079 | 93:4d76de54a699 | 907 | length = (length%8==0)?(length/8):(length/8)+1; |
prasanthbj05 | 265:ae588e75cfa4 | 908 | if(position_tm_frame[id]>129){ |
prasanthbj05 | 265:ae588e75cfa4 | 909 | while(position_tm_frame[id]<132){ |
prasanthbj05 | 265:ae588e75cfa4 | 910 | frames[id][position_tm_frame[id]] = 0; |
prasanthbj05 | 265:ae588e75cfa4 | 911 | position_tm_frame[id]++; |
prasanthbj05 | 265:ae588e75cfa4 | 912 | } |
prasanthbj05 | 265:ae588e75cfa4 | 913 | } |
prasanthbj05 | 265:ae588e75cfa4 | 914 | if(position_tm_frame[id]==position_tm_starting[id]){ |
prasanthbj05 | 265:ae588e75cfa4 | 915 | frames[id][4] = position_tm_starting[id]; |
prasanthbj05 | 265:ae588e75cfa4 | 916 | } |
prasanthbj05 | 265:ae588e75cfa4 | 917 | for(int j= 0; j < length ;) |
prasanthbj05 | 265:ae588e75cfa4 | 918 | { |
prasanthbj05 | 265:ae588e75cfa4 | 919 | if(position_tm_frame[id]==frames[id][4]){ |
prasanthbj05 | 265:ae588e75cfa4 | 920 | frames[id][5] = (uint8_t)((sci_time>>29)&0x3f); |
prasanthbj05 | 265:ae588e75cfa4 | 921 | frames[id][6] = (uint8_t)((sci_time>>21)&0xff); |
prasanthbj05 | 265:ae588e75cfa4 | 922 | frames[id][7] = (uint8_t)((sci_time>>13)&0x3f); |
prasanthbj05 | 265:ae588e75cfa4 | 923 | } |
prasanthbj05 | 265:ae588e75cfa4 | 924 | if(position_tm_frame[id]<132){ |
prasanthbj05 | 265:ae588e75cfa4 | 925 | frames[id][position_tm_frame[id]] = scp[j]; |
prasanthbj05 | 265:ae588e75cfa4 | 926 | j++; |
ee12b079 | 93:4d76de54a699 | 927 | position_tm_frame[id]++; |
prasanthbj05 | 265:ae588e75cfa4 | 928 | } |
prasanthbj05 | 265:ae588e75cfa4 | 929 | if(position_tm_frame[id] == 132) //space full in the frame bro |
prasanthbj05 | 265:ae588e75cfa4 | 930 | { |
prasanthbj05 | 265:ae588e75cfa4 | 931 | pointer = frames[id]; |
prasanthbj05 | 265:ae588e75cfa4 | 932 | space = adjust(1,0,pointer,8); |
prasanthbj05 | 265:ae588e75cfa4 | 933 | space = adjust(4,1,pointer,space); |
prasanthbj05 | 265:ae588e75cfa4 | 934 | FSC_science = FSC_CURRENT[1]; |
prasanthbj05 | 265:ae588e75cfa4 | 935 | frames[id][1] = (FSC_science>>16)&0xff; |
prasanthbj05 | 265:ae588e75cfa4 | 936 | frames[id][2] = (FSC_science>>8)&0xff; |
prasanthbj05 | 265:ae588e75cfa4 | 937 | frames[id][3] = (FSC_science)&0xff; |
prasanthbj05 | 265:ae588e75cfa4 | 938 | temp_crc = crc16_gen(frames[id],132); |
prasanthbj05 | 265:ae588e75cfa4 | 939 | frames[id][132] = temp_crc>>8; |
prasanthbj05 | 265:ae588e75cfa4 | 940 | frames[id][133] = temp_crc & 0xff; |
prasanthbj05 | 265:ae588e75cfa4 | 941 | exor(frames[id]); |
prasanthbj05 | 265:ae588e75cfa4 | 942 | convolution(frames[id]); |
prasanthbj05 | 265:ae588e75cfa4 | 943 | interleave(TM_convoluted_data,TM_interleave_data); |
prasanthbj05 | 265:ae588e75cfa4 | 944 | interleave(TM_convoluted_data+ 135,TM_interleave_data + 144); |
prasanthbj05 | 265:ae588e75cfa4 | 945 | |
prasanthbj05 | 265:ae588e75cfa4 | 946 | SD_WRITE(TM_interleave_data,FSC_science+1,1); //sd_write returns ack, for now not included |
prasanthbj05 | 265:ae588e75cfa4 | 947 | |
prasanthbj05 | 265:ae588e75cfa4 | 948 | position_tm_frame[id] = position_tm_starting[id]; |
prasanthbj05 | 265:ae588e75cfa4 | 949 | frames[id][4] = ((length-1) - j)+position_tm_starting[id]; |
prasanthbj05 | 265:ae588e75cfa4 | 950 | } |
ee12b079 | 93:4d76de54a699 | 951 | } |
prasanthbj05 | 265:ae588e75cfa4 | 952 | } |