CDMS_CODE_samp_23SEP_DMA_flag

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE_samp_23SEP_DMA by iitm sat

Committer:
chaithanyarss
Date:
Sun Aug 07 10:36:59 2016 +0000
Revision:
290:3159ff1081a2
Parent:
278:1d837d6dfb6e
Child:
295:699801854b71
testing in indo mim. DMA not working;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
prasanthbj05 266:ae588e75cfa4 1 /*-----------------------------------------to_do_compression.h--------------------------------------------------
prasanthbj05 266:ae588e75cfa4 2
prasanthbj05 266:ae588e75cfa4 3 -> SD_Write error to be checked
prasanthbj05 266:ae588e75cfa4 4 -> fsc_counter is 32 bit but in the code 24 bit. Talk to chaitu
prasanthbj05 266:ae588e75cfa4 5 ---------------------------------------------------------------------------------------------------------------*/
prasanthbj05 266:ae588e75cfa4 6
prasanthbj05 266:ae588e75cfa4 7 //updated compression algorithm
prasanthbj05 266:ae588e75cfa4 8 /*#include <iostream>
prasanthbj05 266:ae588e75cfa4 9 #include "stdio.h"
prasanthbj05 266:ae588e75cfa4 10 #include "crc.h"
prasanthbj05 266:ae588e75cfa4 11 #include "interleave.h"
prasanthbj05 266:ae588e75cfa4 12 #include "Convolution.h"
prasanthbj05 266:ae588e75cfa4 13 #include "bitset"*/
prasanthbj05 266:ae588e75cfa4 14 //using namespace std;
prasanthbj05 266:ae588e75cfa4 15
prasanthbj05 266:ae588e75cfa4 16 //reading functions 2byte, 4byte
ee12b079 278:1d837d6dfb6e 17 #define srpz 0
ee12b079 278:1d837d6dfb6e 18 #define scpz 0
chaithanyarss 290:3159ff1081a2 19 #define scpz_last 0
chaithanyarss 290:3159ff1081a2 20 #define srpz_last 0
chaithanyarss 290:3159ff1081a2 21 #define debug_fsc 0
chaithanyarss 290:3159ff1081a2 22 #define debug_time 0
chaithanyarss 290:3159ff1081a2 23 #define debug_dma 0
prasanthbj05 266:ae588e75cfa4 24
chaithanyarss 290:3159ff1081a2 25 #if debug_dma
chaithanyarss 290:3159ff1081a2 26 uint16_t read_2byte(uint8_t* ptr)
chaithanyarss 290:3159ff1081a2 27 {
chaithanyarss 290:3159ff1081a2 28 uint16_t output = (((uint16_t )(*(ptr+1)))<<8);
chaithanyarss 290:3159ff1081a2 29 output += (((uint16_t)(*ptr)));
chaithanyarss 290:3159ff1081a2 30 return output;
chaithanyarss 290:3159ff1081a2 31 }
chaithanyarss 290:3159ff1081a2 32
chaithanyarss 290:3159ff1081a2 33 uint32_t read_4byte(uint8_t* ptr)
chaithanyarss 290:3159ff1081a2 34 {
chaithanyarss 290:3159ff1081a2 35 uint32_t output = (uint32_t)(*(ptr+3))<<24;
chaithanyarss 290:3159ff1081a2 36 output += (uint32_t)(*(ptr+2)<<16);
chaithanyarss 290:3159ff1081a2 37 output += (uint32_t)(*(ptr+1)<<8);
chaithanyarss 290:3159ff1081a2 38 output += (uint32_t)(*(ptr));
chaithanyarss 290:3159ff1081a2 39 return output;
chaithanyarss 290:3159ff1081a2 40 }
chaithanyarss 290:3159ff1081a2 41 #endif
chaithanyarss 290:3159ff1081a2 42 #if !debug_dma
prasanthbj05 266:ae588e75cfa4 43 uint16_t read_2byte(uint8_t* ptr)
prasanthbj05 266:ae588e75cfa4 44 {
prasanthbj05 266:ae588e75cfa4 45 uint16_t output = (uint8_t ) *(ptr+1);
prasanthbj05 266:ae588e75cfa4 46 output += ( (uint8_t )(*ptr) ) << 8;
ee12b079 93:4d76de54a699 47 return output;
ee12b079 93:4d76de54a699 48 }
ee12b079 93:4d76de54a699 49
prasanthbj05 266:ae588e75cfa4 50 uint32_t read_4byte(uint8_t* ptr)
prasanthbj05 266:ae588e75cfa4 51 {
prasanthbj05 266:ae588e75cfa4 52 uint32_t output = (uint32_t) (*(ptr+3));
prasanthbj05 266:ae588e75cfa4 53 output += (uint32_t)(*(ptr+2)<<8);
prasanthbj05 266:ae588e75cfa4 54 output += (uint32_t)(*(ptr+1)<<16);
prasanthbj05 266:ae588e75cfa4 55 output += (uint32_t)(*(ptr)<<24);
prasanthbj05 266:ae588e75cfa4 56 return output;
prasanthbj05 266:ae588e75cfa4 57 }
chaithanyarss 290:3159ff1081a2 58 #endif
prasanthbj05 266:ae588e75cfa4 59 uint8_t adjust(uint8_t size, uint8_t data, uint8_t* ptr , uint8_t space)
prasanthbj05 266:ae588e75cfa4 60 {
ee12b079 93:4d76de54a699 61 space = space&0x0f;
ee12b079 171:31bdf83591a1 62 if(space == 8) *ptr = 0;
ee12b079 93:4d76de54a699 63 data = data&((1<<size)-1);
ee12b079 93:4d76de54a699 64 if(space >= size){
ee12b079 93:4d76de54a699 65 *ptr += data<<(space-size);
ee12b079 93:4d76de54a699 66 if(space - size == 0){
ee12b079 93:4d76de54a699 67 return 0x18;
ee12b079 93:4d76de54a699 68 }else{
ee12b079 93:4d76de54a699 69 return space-size;
shreeshas95 1:a0055b3280c8 70 }
ee12b079 93:4d76de54a699 71 }else{
ee12b079 93:4d76de54a699 72 ptr[0] += data>>(size-space);
ee12b079 93:4d76de54a699 73 ptr[1] = (data<<(8-(size-space)))&0xff ;
ee12b079 93:4d76de54a699 74 return 0x10 + 8-(size - space);
ee12b079 93:4d76de54a699 75 }
ee12b079 93:4d76de54a699 76 }
prasanthbj05 266:ae588e75cfa4 77 int compress (int data, int x, int y) //to be compressed with scheme (msb x)*4^y ;
prasanthbj05 266:ae588e75cfa4 78 {
prasanthbj05 266:ae588e75cfa4 79 for(int i = 0 ; i < (1<<y) ; i++)
prasanthbj05 266:ae588e75cfa4 80 {
prasanthbj05 266:ae588e75cfa4 81 if(data <= ( (1<<x)-1) * (1<<(2*i)) )
prasanthbj05 266:ae588e75cfa4 82 {
ee12b079 93:4d76de54a699 83 return ( ((data>>i*2)<<y) + i);
shreeshas95 1:a0055b3280c8 84 }
ee12b079 93:4d76de54a699 85 }
prasanthbj05 266:ae588e75cfa4 86 if ( data > (( (1<<x)-1) * (1<<(2*((1<<y)-1)))) )
prasanthbj05 266:ae588e75cfa4 87 {
prasanthbj05 266:ae588e75cfa4 88 //cout <<"compression exception"<<endl;
prasanthbj05 266:ae588e75cfa4 89 return (((1<<x)-1) * (1<<(2*((1<<y)-1))));
ee12b079 93:4d76de54a699 90 }
ee12b079 93:4d76de54a699 91 }
ee12b079 93:4d76de54a699 92
prasanthbj05 266:ae588e75cfa4 93 //--------------------------------------------------------beacon
prasanthbj05 266:ae588e75cfa4 94 uint8_t beacon_array[134];
prasanthbj05 266:ae588e75cfa4 95 uint8_t beacon_cntr = 1;
prasanthbj05 266:ae588e75cfa4 96 uint8_t *beacon_ptr;
prasanthbj05 266:ae588e75cfa4 97 //--------------------------------------------------------beacon
ee12b079 93:4d76de54a699 98
prasanthbj05 266:ae588e75cfa4 99 //variable declarations
prasanthbj05 266:ae588e75cfa4 100 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 266:ae588e75cfa4 101 uint32_t sfp_bin[52] , scp_bin[52]; //storing the bin values.
prasanthbj05 266:ae588e75cfa4 102 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 266:ae588e75cfa4 103 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 266:ae588e75cfa4 104 uint32_t scp_threshold_m0_1[9] = {114688,245760,245760,245760,245760,114688,114688,65472,65472} ; //for callibrated mode with data conservation
prasanthbj05 266:ae588e75cfa4 105 uint32_t scp_sfp_threshold_m0_2[3] = {245760,65472,65472};
prasanthbj05 266:ae588e75cfa4 106 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 266:ae588e75cfa4 107 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 108 uint8_t frames[3][134] = {0};
ee12b079 171:31bdf83591a1 109 uint8_t position_tm_frame[3] = {8,11,5} , position_tm_starting[3] = {8,11,5}; //{sc,sf-bt,sf-at}
ee12b079 171:31bdf83591a1 110 uint8_t id; //sf = 0,sc-at = 1,sc-bt = 2;
ee12b079 171:31bdf83591a1 111 uint8_t TM_interleave_data[512] , TM_convoluted_data[270] = {0};
prasanthbj05 266:ae588e75cfa4 112 uint64_t proton_scp_sum,electron_scp_sum,FSC_science;
prasanthbj05 266:ae588e75cfa4 113 uint16_t temp_crc;
prasanthbj05 266:ae588e75cfa4 114 uint32_t debug_cntr, size,space,length;
ee12b079 171:31bdf83591a1 115 uint8_t *ptr ,* pointer;
prasanthbj05 266:ae588e75cfa4 116 uint64_t sci_time = 0, time_prev_scp = 0;
prasanthbj05 266:ae588e75cfa4 117 uint32_t attitude = 0;
prasanthbj05 266:ae588e75cfa4 118 uint32_t beacon_threshold[9] = {114688,245760,245760,245760,245760,114688,114688,65472,65472};
ee12b079 93:4d76de54a699 119
chaithanyarss 290:3159ff1081a2 120 /*----------------------------temporary counters used for testing purposes---------------------------*/
chaithanyarss 290:3159ff1081a2 121 uint32_t test_fsc[4]={1,1,1,1};
chaithanyarss 290:3159ff1081a2 122 /*---------------------------------------------------------------------------------------------------*/
chaithanyarss 290:3159ff1081a2 123
chaithanyarss 290:3159ff1081a2 124
prasanthbj05 266:ae588e75cfa4 125 Convolution ConvObj;
prasanthbj05 266:ae588e75cfa4 126 void convolution (uint8_t * ptr){
prasanthbj05 266:ae588e75cfa4 127 ConvObj.convolutionEncode(ptr, TM_convoluted_data);
prasanthbj05 266:ae588e75cfa4 128 ConvObj.convolutionEncode(ptr + 67, TM_convoluted_data + 135);
prasanthbj05 266:ae588e75cfa4 129 }
ee12b079 93:4d76de54a699 130
ee12b079 93:4d76de54a699 131 //give the pointer of 6 second data to this function
prasanthbj05 266:ae588e75cfa4 132 void srp(uint8_t * head)
prasanthbj05 266:ae588e75cfa4 133 {
ee12b079 268:ded5306a1fd1 134 uint8_t sd_stat = 0;
chaithanyarss 290:3159ff1081a2 135 gPC.printf("\n\rEntered SRP function");
prasanthbj05 266:ae588e75cfa4 136 debug_cntr = 0;
prasanthbj05 266:ae588e75cfa4 137 sci_time = FCTN_CDMS_RD_RTC();
chaithanyarss 290:3159ff1081a2 138 #if debug_time
chaithanyarss 290:3159ff1081a2 139 sci_time = 0x0000000021000000;
chaithanyarss 290:3159ff1081a2 140 #endif
prasanthbj05 266:ae588e75cfa4 141 if(time_prev_scp==0){
prasanthbj05 266:ae588e75cfa4 142 time_prev_scp = sci_time;
prasanthbj05 266:ae588e75cfa4 143 }
prasanthbj05 266:ae588e75cfa4 144 FCTN_SD_MNGR(); ///changed recently
ee12b079 268:ded5306a1fd1 145 for (int i = 0; i < 52 ; i++)
prasanthbj05 266:ae588e75cfa4 146 {
ee12b079 93:4d76de54a699 147 scp_bin[i] = 0;
shreeshas95 1:a0055b3280c8 148 }
prasanthbj05 266:ae588e75cfa4 149 ptr = head + 3; //ptr points to proton energy bin of srp
ee12b079 93:4d76de54a699 150 srp_mode = head[2]&0x1;
prasanthbj05 266:ae588e75cfa4 151 for(uint8_t counter = 0 ; counter < 60 ; counter++)
prasanthbj05 266:ae588e75cfa4 152 {
ee12b079 268:ded5306a1fd1 153 #if srpz
chaithanyarss 290:3159ff1081a2 154 gPC.printf("\n\n\rSRP count:%d",counter+1);
ee12b079 268:ded5306a1fd1 155 #endif
prasanthbj05 266:ae588e75cfa4 156 /*-------------------- ------------populating sfp_bin and scp_bin[] starts here(also tag AT or BT)-----------------------*/
prasanthbj05 266:ae588e75cfa4 157 at = 0; pzf = 1; ezf = 1;
prasanthbj05 266:ae588e75cfa4 158 if(srp_mode == 0) //calibrated mode
prasanthbj05 266:ae588e75cfa4 159 {
ee12b079 268:ded5306a1fd1 160 #if srpz
chaithanyarss 290:3159ff1081a2 161 gPC.printf("\n\rSRP - Calibrated Mode");
ee12b079 268:ded5306a1fd1 162 #endif
prasanthbj05 266:ae588e75cfa4 163 for(int i=0; i<48 ; i++) //first 48 bins or SRP are of 16 bits size
prasanthbj05 266:ae588e75cfa4 164 {
ee12b079 93:4d76de54a699 165 sfp_bin[i] = read_2byte(ptr + i*2);
ee12b079 93:4d76de54a699 166 scp_bin[i] += sfp_bin[i];
prasanthbj05 266:ae588e75cfa4 167 if(sfp_bin[i]>sfp_threshold_m0[i])
prasanthbj05 266:ae588e75cfa4 168 {
ee12b079 268:ded5306a1fd1 169 //gPC.printf("\n\rSFP above threshold index:%d",i);
ee12b079 93:4d76de54a699 170 at = 1;
ee12b079 93:4d76de54a699 171 }
prasanthbj05 266:ae588e75cfa4 172 if(i<17)
prasanthbj05 266:ae588e75cfa4 173 {
ee12b079 93:4d76de54a699 174 if(sfp_bin[i] > 0)
ee12b079 93:4d76de54a699 175 pzf = 0;
ee12b079 93:4d76de54a699 176 }
prasanthbj05 266:ae588e75cfa4 177 else if (i>17 && i < 23)
prasanthbj05 266:ae588e75cfa4 178 {
ee12b079 93:4d76de54a699 179 if(sfp_bin[i]>0)
ee12b079 93:4d76de54a699 180 ezf = 0;
ee12b079 93:4d76de54a699 181 }
ee12b079 93:4d76de54a699 182 }
prasanthbj05 266:ae588e75cfa4 183 for(int i=0; i<4; i++) //last 4 bins(excluding the spare bin) are 32 bit each
prasanthbj05 266:ae588e75cfa4 184 {
ee12b079 93:4d76de54a699 185 sfp_bin[i+48] = read_4byte( (ptr+96) + 4*i );
ee12b079 93:4d76de54a699 186 scp_bin[i+48] += sfp_bin[i+48];
ee12b079 268:ded5306a1fd1 187 if(sfp_bin[i+48]>sfp_threshold_m0[i+48]){
ee12b079 268:ded5306a1fd1 188 //gPC.printf("\n\rSP above threshold index: %d",i+48);
ee12b079 93:4d76de54a699 189 at = 1;
ee12b079 268:ded5306a1fd1 190 }
ee12b079 93:4d76de54a699 191 }
ee12b079 93:4d76de54a699 192 }
prasanthbj05 266:ae588e75cfa4 193 else if(srp_mode == 1) //scattered mode
prasanthbj05 266:ae588e75cfa4 194 {
ee12b079 268:ded5306a1fd1 195 #if srpz
chaithanyarss 290:3159ff1081a2 196 gPC.printf("\n\rSRP - Scatter Plot Mode");
ee12b079 268:ded5306a1fd1 197 #endif
prasanthbj05 266:ae588e75cfa4 198 for(int i = 0; i <48; i++) //first 48 bins of SRP are of 16 bit size
prasanthbj05 266:ae588e75cfa4 199 {
prasanthbj05 266:ae588e75cfa4 200 sfp_bin[i] = read_2byte(ptr+2*i);
ee12b079 93:4d76de54a699 201 scp_bin[i] += sfp_bin[i];
ee12b079 268:ded5306a1fd1 202 //gPC.printf("\n\rsfp_bin[%d]= %u\t\tscp_bin[%d]= %u",i,sfp_bin[i],i,scp_bin[i]);
ee12b079 268:ded5306a1fd1 203 if(sfp_bin[i] > sfp_threshold_m1[i]){
ee12b079 268:ded5306a1fd1 204 //gPC.printf("\n\rSP above threshold index: %d",i);
ee12b079 93:4d76de54a699 205 at = 1;
ee12b079 268:ded5306a1fd1 206 }
ee12b079 93:4d76de54a699 207 }
prasanthbj05 266:ae588e75cfa4 208 for(int i = 0; i < 4 ; i++) //next 4 bins are of 32 bit size
prasanthbj05 266:ae588e75cfa4 209 {
prasanthbj05 266:ae588e75cfa4 210 sfp_bin[i+48] = read_4byte( (ptr+96) + 4*i );
prasanthbj05 266:ae588e75cfa4 211 scp_bin[i+48] += sfp_bin[i+48];
ee12b079 268:ded5306a1fd1 212 if(sfp_bin[i+48] > sfp_threshold_m1[i+48]){
ee12b079 268:ded5306a1fd1 213 //gPC.printf("\n\rSP above threshold index: %d",i+48);
ee12b079 93:4d76de54a699 214 at = 1;
ee12b079 268:ded5306a1fd1 215 }
ee12b079 93:4d76de54a699 216 }
shreeshas95 1:a0055b3280c8 217 }
prasanthbj05 266:ae588e75cfa4 218 /*---------------------------populating sfp_bin[] and scp_bin[] from srp ends here(also tagging AT or BT)------------------*/
prasanthbj05 266:ae588e75cfa4 219
ee12b079 268:ded5306a1fd1 220 //ptr = ptr + 112; //moving the pointer to next srp packet in the DMA buffer
prasanthbj05 266:ae588e75cfa4 221
prasanthbj05 266:ae588e75cfa4 222 /*------------------------------------------forming a science fine packet starts here----------------------------------------
prasanthbj05 266:ae588e75cfa4 223 First we fill packet header, then fill packet data and finally assign its length
prasanthbj05 266:ae588e75cfa4 224 ----------------------------------------------------------------------------------------------------------------------------*/
prasanthbj05 266:ae588e75cfa4 225 for(int i = 0; i<71; i++)
ee12b079 93:4d76de54a699 226 sfp[i] = 0;
prasanthbj05 266:ae588e75cfa4 227 if(srp_mode == 0) //calibrated mode
prasanthbj05 266:ae588e75cfa4 228 {
prasanthbj05 266:ae588e75cfa4 229 if(at == 0)
prasanthbj05 266:ae588e75cfa4 230 {
ee12b079 268:ded5306a1fd1 231 #if srpz
chaithanyarss 290:3159ff1081a2 232 gPC.printf("\n\rSFP Below Threshold");
ee12b079 268:ded5306a1fd1 233 #endif
ee12b079 93:4d76de54a699 234 pointer = sfp; debug_cntr = 0;
prasanthbj05 266:ae588e75cfa4 235 space = adjust(4, attitude,pointer,8); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 236 space = adjust(6, counter,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 237 space = adjust(1, srp_mode,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 238 space = adjust(1, pzf,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 239 space = adjust(1, ezf,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 240 for(uint8_t i = 0 ; i < 8 ; i++){
prasanthbj05 266:ae588e75cfa4 241 space = adjust(1, ((compress(sfp_bin[24+i],7,2))&0x100)>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 242 space = adjust(8, ((compress(sfp_bin[24+i],7,2))&0xff) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 243 }
prasanthbj05 266:ae588e75cfa4 244 for(uint8_t i = 0 ; i <12 ; i++){
prasanthbj05 266:ae588e75cfa4 245 space = adjust(6, (compress(sfp_bin[32+i],4,2)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 246 }
prasanthbj05 266:ae588e75cfa4 247 for(uint8_t i = 0; i < 4; i++){
prasanthbj05 266:ae588e75cfa4 248 space = adjust(8, (compress(sfp_bin[44+i],6,2)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 249 }
prasanthbj05 266:ae588e75cfa4 250 for(uint8_t i = 0 ; i < 4 ; i++){
prasanthbj05 266:ae588e75cfa4 251 space = adjust(1, (compress(sfp_bin[48+i],7,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 252 space = adjust(8, compress(sfp_bin[48+i],7,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 253 }
prasanthbj05 266:ae588e75cfa4 254 space = adjust(8, ((compress(sfp_bin[17],6,2))&0xff) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 255 space = adjust(8, ((compress(sfp_bin[23],6,2))&0xff) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 256 if(pzf == 0){
prasanthbj05 266:ae588e75cfa4 257 for(uint8_t i = 0; i<2 ; i++){
prasanthbj05 266:ae588e75cfa4 258 space = adjust(6, ((compress(sfp_bin[i],5,1))&0xff) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 259 }
prasanthbj05 266:ae588e75cfa4 260 for(uint8_t i = 0; i<15 ; i++){
prasanthbj05 266:ae588e75cfa4 261 space = adjust(5, ((compress(sfp_bin[i+2],4,1))&0xff) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 262 }
ee12b079 93:4d76de54a699 263 }
ee12b079 93:4d76de54a699 264 if(ezf == 0){
prasanthbj05 266:ae588e75cfa4 265 for(uint8_t i = 0; i <5 ;i++){
prasanthbj05 266:ae588e75cfa4 266 space = adjust(7, ((compress(sfp_bin[18+i],6,1))&0xff) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 267 }
ee12b079 93:4d76de54a699 268 }
prasanthbj05 266:ae588e75cfa4 269 } //below thershold ends here.
ee12b079 93:4d76de54a699 270 if(at == 1){
ee12b079 268:ded5306a1fd1 271 #if srpz
chaithanyarss 290:3159ff1081a2 272 gPC.printf("\n\rSFP Above Threshold");
ee12b079 268:ded5306a1fd1 273 #endif
ee12b079 93:4d76de54a699 274 pointer = sfp + 6; debug_cntr = 6;space = 8;
ee12b079 93:4d76de54a699 275 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 266:ae588e75cfa4 276 sfp[4] = ((sci_time&0x07)<<5) + ((attitude&0x0f)<<1) + (counter>>5);
prasanthbj05 266:ae588e75cfa4 277 sfp[5] = ((counter&0x1f)<<3) + (srp_mode<<2);
ee12b079 93:4d76de54a699 278 sfp[5] += (pzf<<1) + ezf ;
prasanthbj05 266:ae588e75cfa4 279 for(uint8_t i = 0 ; i < 8 ; i++){
prasanthbj05 266:ae588e75cfa4 280 space = adjust(1, (compress(sfp_bin[24+i],7,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 281 space = adjust(8, ((compress(sfp_bin[24+i],7,2))&0xff) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
shreeshas95 1:a0055b3280c8 282 }
prasanthbj05 266:ae588e75cfa4 283 for(uint8_t i = 0 ; i <12 ; i++){
ee12b079 93:4d76de54a699 284 space = adjust(6, ((compress(sfp_bin[32+i],3,3))&0xff) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
shreeshas95 1:a0055b3280c8 285 }
prasanthbj05 266:ae588e75cfa4 286 for(uint8_t i = 0 ; i < 4 ; i++){
prasanthbj05 266:ae588e75cfa4 287 space = adjust(2, (compress(sfp_bin[44+i],8,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 288 space = adjust(8, compress(sfp_bin[44+i],8,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
shreeshas95 1:a0055b3280c8 289 }
prasanthbj05 266:ae588e75cfa4 290 for(uint8_t i = 0 ; i < 4 ; i++){
prasanthbj05 266:ae588e75cfa4 291 space = adjust(1, (compress(sfp_bin[48+i],6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 292 space = adjust(8, compress(sfp_bin[48+i],6,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 293 }
prasanthbj05 266:ae588e75cfa4 294 space = adjust(2, (compress(sfp_bin[17],8,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 295 space = adjust(8, compress(sfp_bin[17],8,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 296 space = adjust(2, (compress(sfp_bin[23],8,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 297 space = adjust(8, compress(sfp_bin[23],8,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 298
ee12b079 93:4d76de54a699 299 if(pzf == 0){
prasanthbj05 266:ae588e75cfa4 300 //cout<<"proton bins ";
ee12b079 268:ded5306a1fd1 301 #if srpz
chaithanyarss 290:3159ff1081a2 302 gPC.printf("\n\rProton bins present in SRP");
ee12b079 268:ded5306a1fd1 303 #endif
prasanthbj05 266:ae588e75cfa4 304 for(uint8_t i = 0; i<17 ; i++){
ee12b079 93:4d76de54a699 305 space = adjust(2, ((compress(sfp_bin[i],8,2))>>8) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 306 space = adjust(8, compress(sfp_bin[i],8,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 307 //printf("%02X ",compress(sfp_bin[i],8,2));
ee12b079 93:4d76de54a699 308 }
ee12b079 93:4d76de54a699 309 }
ee12b079 93:4d76de54a699 310 if(ezf == 0){
prasanthbj05 266:ae588e75cfa4 311 //cout<<"electron bins ";
ee12b079 268:ded5306a1fd1 312 #if srpz
chaithanyarss 290:3159ff1081a2 313 gPC.printf("\n\rElectron bins present in SRP");
ee12b079 268:ded5306a1fd1 314 #endif
ee12b079 93:4d76de54a699 315 for(int i = 0; i<5 ; i++){
prasanthbj05 266:ae588e75cfa4 316 space = adjust(2,((compress(sfp_bin[18+i],8,2))>>8),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 317 space = adjust(8, compress(sfp_bin[18+i],8,2),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 318 //printf("%02X ",compress(sfp_bin[i],8,2));
ee12b079 93:4d76de54a699 319 }
ee12b079 93:4d76de54a699 320 }
prasanthbj05 266:ae588e75cfa4 321 } //above threshold ends here.
prasanthbj05 266:ae588e75cfa4 322 if(at == 0)
prasanthbj05 266:ae588e75cfa4 323 {
prasanthbj05 266:ae588e75cfa4 324 id = 1; length = 241+5; //5 spare bits
ee12b079 93:4d76de54a699 325 if(pzf == 0)
ee12b079 93:4d76de54a699 326 length += 87;
ee12b079 93:4d76de54a699 327 if(ezf == 0)
ee12b079 93:4d76de54a699 328 length += 35;
prasanthbj05 266:ae588e75cfa4 329 }
prasanthbj05 266:ae588e75cfa4 330 else
prasanthbj05 266:ae588e75cfa4 331 {
prasanthbj05 266:ae588e75cfa4 332 id = 2; length = 288; //0 spare bits
ee12b079 93:4d76de54a699 333 if(pzf == 0)
ee12b079 93:4d76de54a699 334 length += 170;
ee12b079 93:4d76de54a699 335 if(ezf == 0)
ee12b079 93:4d76de54a699 336 length += 50;
ee12b079 93:4d76de54a699 337 }
shreeshas95 1:a0055b3280c8 338 }
prasanthbj05 266:ae588e75cfa4 339 else if(srp_mode == 1) //scattered mode
prasanthbj05 266:ae588e75cfa4 340 {
prasanthbj05 266:ae588e75cfa4 341 if(at == 0)
prasanthbj05 266:ae588e75cfa4 342 {
ee12b079 268:ded5306a1fd1 343 #if srpz
chaithanyarss 290:3159ff1081a2 344 gPC.printf("\n\rSFP below threshold");
ee12b079 268:ded5306a1fd1 345 #endif
prasanthbj05 266:ae588e75cfa4 346 pointer = sfp; debug_cntr = 0; space = 8;
prasanthbj05 266:ae588e75cfa4 347 space = adjust(4, attitude,pointer,8); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 348 space = adjust(6, counter,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 349 space = adjust(1, srp_mode,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 350 for(uint8_t i=0; i<48; i++)
prasanthbj05 266:ae588e75cfa4 351 {
prasanthbj05 266:ae588e75cfa4 352 space = adjust(7, compress(sfp_bin[i],5,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 353 }
prasanthbj05 266:ae588e75cfa4 354 for(uint8_t i = 0 ; i < 4 ; i++)
prasanthbj05 266:ae588e75cfa4 355 {
prasanthbj05 266:ae588e75cfa4 356 space = adjust(1, (compress(sfp_bin[48+i],7,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 357 space = adjust(8, compress(sfp_bin[48+i],7,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 358 }
prasanthbj05 266:ae588e75cfa4 359 }
prasanthbj05 266:ae588e75cfa4 360 if(at == 1)
prasanthbj05 266:ae588e75cfa4 361 {
ee12b079 268:ded5306a1fd1 362
ee12b079 268:ded5306a1fd1 363 #if srpz
chaithanyarss 290:3159ff1081a2 364 gPC.printf("\n\rSFP below threshold");
ee12b079 268:ded5306a1fd1 365 #endif
prasanthbj05 266:ae588e75cfa4 366 pointer = sfp; debug_cntr = 0; space = 8;
prasanthbj05 266:ae588e75cfa4 367 space = adjust(3, sci_time>>32 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 368 space = adjust(8, sci_time>>24 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 369 space = adjust(8, sci_time>>16 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 370 space = adjust(8, sci_time>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 371 space = adjust(8, sci_time ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 372 space = adjust(4, attitude,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 373 space = adjust(6, counter,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 374 space = adjust(1, srp_mode,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 375 for(uint8_t i=0; i<48; i++)
prasanthbj05 266:ae588e75cfa4 376 {
prasanthbj05 266:ae588e75cfa4 377 space = adjust(2, (compress(sfp_bin[i],8,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 378 space = adjust(8, compress(sfp_bin[i],8,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 379 }
prasanthbj05 266:ae588e75cfa4 380 for(uint8_t i = 0 ; i < 4 ; i++)
prasanthbj05 266:ae588e75cfa4 381 {
prasanthbj05 266:ae588e75cfa4 382 space = adjust(1, (compress(sfp_bin[48+i],6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 383 space = adjust(8, compress(sfp_bin[48+i],6,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 384 }
prasanthbj05 266:ae588e75cfa4 385 }
prasanthbj05 266:ae588e75cfa4 386 if(at == 0)
prasanthbj05 266:ae588e75cfa4 387 {
prasanthbj05 266:ae588e75cfa4 388 id = 1; length = 384; //0 spare bits
prasanthbj05 266:ae588e75cfa4 389 }
prasanthbj05 266:ae588e75cfa4 390 else
prasanthbj05 266:ae588e75cfa4 391 {
prasanthbj05 266:ae588e75cfa4 392 id = 2; length = 568; //0 spare bits
ee12b079 93:4d76de54a699 393 }
shreeshas95 1:a0055b3280c8 394 }
prasanthbj05 266:ae588e75cfa4 395 length = (length%8==0)?(length/8):(length/8)+1; //converting length to mulitple of 8
ee12b079 268:ded5306a1fd1 396 #if srpz
chaithanyarss 290:3159ff1081a2 397 gPC.printf("\n\rLength of SFP packet in bytes = %d",length);
ee12b079 268:ded5306a1fd1 398 #endif
prasanthbj05 266:ae588e75cfa4 399 /*----------------------------------------forming a science packet ends here-----------------------------------------------*/
prasanthbj05 266:ae588e75cfa4 400
prasanthbj05 266:ae588e75cfa4 401 /*-----------------------------Inserting the above packet(sfp) into the TM frame(s) starts here----------------------------*/
prasanthbj05 266:ae588e75cfa4 402 if(id==1){
prasanthbj05 266:ae588e75cfa4 403 if(position_tm_frame[id]>130){
ee12b079 268:ded5306a1fd1 404 #if srpz
chaithanyarss 290:3159ff1081a2 405 gPC.printf("\n\rSkipping the current frame.Inserting sfp packet into the next frame.");
ee12b079 268:ded5306a1fd1 406 #endif
prasanthbj05 266:ae588e75cfa4 407 while(position_tm_frame[id]<132){
prasanthbj05 266:ae588e75cfa4 408 frames[id][position_tm_frame[id]] = 0;
prasanthbj05 266:ae588e75cfa4 409 position_tm_frame[id]++;
prasanthbj05 266:ae588e75cfa4 410 }
prasanthbj05 266:ae588e75cfa4 411 }
prasanthbj05 266:ae588e75cfa4 412 }
prasanthbj05 266:ae588e75cfa4 413 else if(id==2){
prasanthbj05 266:ae588e75cfa4 414 if(position_tm_frame[id]>126){
ee12b079 268:ded5306a1fd1 415 #if srpz
chaithanyarss 290:3159ff1081a2 416 gPC.printf("\n\rSkipping the current frame.Inserting sfp packet into the next frame.");
ee12b079 268:ded5306a1fd1 417 #endif
prasanthbj05 266:ae588e75cfa4 418 while(position_tm_frame[id]<132){
prasanthbj05 266:ae588e75cfa4 419 frames[id][position_tm_frame[id]] = 0;
prasanthbj05 266:ae588e75cfa4 420 position_tm_frame[id]++;
prasanthbj05 266:ae588e75cfa4 421 }
prasanthbj05 266:ae588e75cfa4 422 }
prasanthbj05 266:ae588e75cfa4 423 }
prasanthbj05 266:ae588e75cfa4 424 if(position_tm_frame[id]==position_tm_starting[id]){
prasanthbj05 266:ae588e75cfa4 425 frames[id][6-id] = position_tm_starting[id];
prasanthbj05 266:ae588e75cfa4 426 }
prasanthbj05 266:ae588e75cfa4 427 for(uint16_t j=0 ; j<length ;)
prasanthbj05 266:ae588e75cfa4 428 {
prasanthbj05 266:ae588e75cfa4 429 if(position_tm_frame[id]==frames[id][6-id]){
prasanthbj05 266:ae588e75cfa4 430 if(id==1){
ee12b079 268:ded5306a1fd1 431 #if srpz
chaithanyarss 290:3159ff1081a2 432 gPC.printf("\n\rAdding Time to TM frame");
ee12b079 268:ded5306a1fd1 433 #endif
prasanthbj05 266:ae588e75cfa4 434 frames[id][6] = (uint8_t)((sci_time>>32)&0x07);
prasanthbj05 266:ae588e75cfa4 435 frames[id][7] = (uint8_t)((sci_time>>24)&0xff);
prasanthbj05 266:ae588e75cfa4 436 frames[id][8] = (uint8_t)((sci_time>>16)&0xff);
prasanthbj05 266:ae588e75cfa4 437 frames[id][9] = (uint8_t)((sci_time>>8)&0xff);
prasanthbj05 266:ae588e75cfa4 438 frames[id][10] = (uint8_t)((sci_time)&0xff);
prasanthbj05 266:ae588e75cfa4 439 }
prasanthbj05 266:ae588e75cfa4 440 }
prasanthbj05 266:ae588e75cfa4 441 if(position_tm_frame[id]<132){
prasanthbj05 266:ae588e75cfa4 442 frames[id][position_tm_frame[id]] = sfp[j];
prasanthbj05 266:ae588e75cfa4 443 j++;
prasanthbj05 266:ae588e75cfa4 444 position_tm_frame[id]++; //incrementing position of write pointer in TM frame
prasanthbj05 266:ae588e75cfa4 445 }
prasanthbj05 266:ae588e75cfa4 446 if(position_tm_frame[id] == 132)
prasanthbj05 266:ae588e75cfa4 447 {
prasanthbj05 266:ae588e75cfa4 448 /*-----------the current frame is completely filled and we fill frame header to write into SD card---------*/
ee12b079 268:ded5306a1fd1 449 #if srpz
chaithanyarss 290:3159ff1081a2 450 gPC.printf("\n\rSFP_TM frame full. Length of current packet = %d",j);
chaithanyarss 290:3159ff1081a2 451 gPC.printf("\n\rFirst Header pointer: %d",frames[id][6-id]);
chaithanyarss 290:3159ff1081a2 452 gPC.printf("\n\rFirst head pointer contents: 0x%02X",frames[id][frames[id][6-id]]);
ee12b079 268:ded5306a1fd1 453 #endif
ee12b079 93:4d76de54a699 454 pointer = frames[id];
prasanthbj05 266:ae588e75cfa4 455 if(id == 1){ //below threshold
ee12b079 93:4d76de54a699 456 space = adjust(1,0,pointer,8);
ee12b079 93:4d76de54a699 457 space = adjust(4,3,pointer,space);
ee12b079 271:72529b247333 458 FSC_science = FSC_CURRENT[3]; ///to be used as this, but FSC_CURRENT[] is 32 bit
chaithanyarss 290:3159ff1081a2 459
chaithanyarss 290:3159ff1081a2 460 //gPC.printf("3 = 0x%X",FSC_science);
chaithanyarss 290:3159ff1081a2 461 #if debug_fsc
chaithanyarss 290:3159ff1081a2 462 frames[id][1] = (test_fsc[3]>>24)&0xff;
chaithanyarss 290:3159ff1081a2 463 frames[id][2] = (test_fsc[3]>>16)&0xff;
chaithanyarss 290:3159ff1081a2 464 frames[id][3] = (test_fsc[3]>>8)&0xff;
chaithanyarss 290:3159ff1081a2 465 frames[id][4] = test_fsc[3]&0xff;
chaithanyarss 290:3159ff1081a2 466 test_fsc[3]++;
chaithanyarss 290:3159ff1081a2 467 #endif
chaithanyarss 290:3159ff1081a2 468 #if !debug_fsc
ee12b079 93:4d76de54a699 469 frames[id][1] = (FSC_science>>24)&0xff;
ee12b079 93:4d76de54a699 470 frames[id][2] = (FSC_science>>16)&0xff;
ee12b079 93:4d76de54a699 471 frames[id][3] = (FSC_science>>8)&0xff;
prasanthbj05 266:ae588e75cfa4 472 frames[id][4] = FSC_science&0xff;
chaithanyarss 290:3159ff1081a2 473 #endif
prasanthbj05 266:ae588e75cfa4 474 }
prasanthbj05 266:ae588e75cfa4 475 else if(id == 2) //above threshold
prasanthbj05 266:ae588e75cfa4 476 {
ee12b079 93:4d76de54a699 477 space = adjust(1,0,pointer,8);
prasanthbj05 266:ae588e75cfa4 478 space = adjust(4,2,pointer,space);
prasanthbj05 266:ae588e75cfa4 479 FSC_science = FSC_CURRENT[2]; ///to be used as this
chaithanyarss 290:3159ff1081a2 480 //gPC.printf("2 = 0x%X",FSC_science);
chaithanyarss 290:3159ff1081a2 481 #if debug_fsc
chaithanyarss 290:3159ff1081a2 482 frames[id][1] = (test_fsc[2]>>16)&0xff;
chaithanyarss 290:3159ff1081a2 483 frames[id][2] = (test_fsc[2]>>8)&0xff;
chaithanyarss 290:3159ff1081a2 484 frames[id][3] = test_fsc[2]&0xff;
chaithanyarss 290:3159ff1081a2 485 test_fsc[2]++;
chaithanyarss 290:3159ff1081a2 486 #endif
chaithanyarss 290:3159ff1081a2 487 #if !debug_fsc
ee12b079 93:4d76de54a699 488 frames[id][1] = (FSC_science>>16)&0xff;
ee12b079 93:4d76de54a699 489 frames[id][2] = (FSC_science>>8)&0xff;
ee12b079 93:4d76de54a699 490 frames[id][3] = FSC_science&0xff;
chaithanyarss 290:3159ff1081a2 491 #endif
ee12b079 93:4d76de54a699 492 }
ee12b079 93:4d76de54a699 493 temp_crc = crc16_gen(frames[id],132);
ee12b079 93:4d76de54a699 494 frames[id][132] = temp_crc>>8;
ee12b079 93:4d76de54a699 495 frames[id][133] = temp_crc & 0xff;
ee12b079 268:ded5306a1fd1 496
ee12b079 268:ded5306a1fd1 497 #if srpz
ee12b079 268:ded5306a1fd1 498 gPC.printf("\n\rPrinting SFP_TM\n\r{");
chaithanyarss 290:3159ff1081a2 499 //gPC.printf("\n\r{");
ee12b079 268:ded5306a1fd1 500 for(uint8_t z=0;z<134;z++){
chaithanyarss 290:3159ff1081a2 501 gPC.printf("%02X",frames[id][z]);
ee12b079 268:ded5306a1fd1 502 }
ee12b079 268:ded5306a1fd1 503 gPC.printf("}\n\r");
ee12b079 268:ded5306a1fd1 504 #endif
prasanthbj05 266:ae588e75cfa4 505 /*------------------current TM frame completely filled-----------------------*/
ee12b079 171:31bdf83591a1 506
ee12b079 114:9fb55057b13f 507 exor(frames[id]);
ee12b079 93:4d76de54a699 508 convolution(frames[id]);
ee12b079 93:4d76de54a699 509 interleave(TM_convoluted_data,TM_interleave_data);
ee12b079 93:4d76de54a699 510 interleave(TM_convoluted_data+ 135,TM_interleave_data + 144);
prasanthbj05 266:ae588e75cfa4 511 if(id == 1)
ee12b079 195:6a549c0e9287 512 {
ee12b079 268:ded5306a1fd1 513 sd_stat = SD_WRITE(TM_interleave_data,FSC_science+1,3); //sd_write will return ack later, for now not included
prasanthbj05 266:ae588e75cfa4 514 }
prasanthbj05 266:ae588e75cfa4 515 else if (id == 2)
prasanthbj05 266:ae588e75cfa4 516 {
ee12b079 268:ded5306a1fd1 517 sd_stat = SD_WRITE(TM_interleave_data,FSC_science+1,2); //sd_write will return ack later, for now not included
prasanthbj05 266:ae588e75cfa4 518 }
ee12b079 268:ded5306a1fd1 519 if(sd_stat)
ee12b079 268:ded5306a1fd1 520 {
ee12b079 268:ded5306a1fd1 521 gPC.puts("sd write fail");
chaithanyarss 290:3159ff1081a2 522 }
ee12b079 93:4d76de54a699 523 position_tm_frame[id] = position_tm_starting[id];
ee12b079 268:ded5306a1fd1 524 frames[id][6-id] = (length - j)+position_tm_starting[id];
ee12b079 93:4d76de54a699 525 }
shreeshas95 1:a0055b3280c8 526 }
prasanthbj05 266:ae588e75cfa4 527 /*------------------------------finished inserting the sfp packet into the TM frame(s)-------------------------------------*/
ee12b079 268:ded5306a1fd1 528 } // for loop bracket which runs 60 times
ee12b079 268:ded5306a1fd1 529 #if srpz_last
ee12b079 268:ded5306a1fd1 530 //gPC.printf("\n\rPrinting the last SFP_TM frame");
ee12b079 268:ded5306a1fd1 531 //gPC.printf("\n\n\rPosition of tm_pointer: %d",position_tm_frame[id]);
ee12b079 268:ded5306a1fd1 532 while(position_tm_frame[id]<132){
ee12b079 268:ded5306a1fd1 533 frames[id][position_tm_frame[id]] = 0;
ee12b079 268:ded5306a1fd1 534 position_tm_frame[id]++;
ee12b079 268:ded5306a1fd1 535 }
ee12b079 268:ded5306a1fd1 536 if(position_tm_frame[id]==132){
ee12b079 268:ded5306a1fd1 537 //gPC.printf("\n\rFirst head pointer contents: 0x%02X",frames[id][frames[id][6-id]]);
ee12b079 268:ded5306a1fd1 538 pointer = frames[id];
ee12b079 268:ded5306a1fd1 539 if(id == 1){ //below threshold
ee12b079 268:ded5306a1fd1 540 space = adjust(1,0,pointer,8);
ee12b079 268:ded5306a1fd1 541 space = adjust(4,3,pointer,space);
ee12b079 268:ded5306a1fd1 542 FSC_science = FSC_CURRENT[3]; ///to be used as this, but FSC_CURRENT[] is 32 bit
chaithanyarss 290:3159ff1081a2 543 #if debug_fsc
chaithanyarss 290:3159ff1081a2 544 frames[id][1] = (FSC_science>>24)&0xff;
chaithanyarss 290:3159ff1081a2 545 frames[id][2] = (FSC_science>>16)&0xff;
chaithanyarss 290:3159ff1081a2 546 frames[id][3] = (FSC_science>>8)&0xff;
chaithanyarss 290:3159ff1081a2 547 frames[id][4] = FSC_science&0xff;
chaithanyarss 290:3159ff1081a2 548 test_fsc[3]++;
chaithanyarss 290:3159ff1081a2 549 #endif
chaithanyarss 290:3159ff1081a2 550 #if !debug_fsc
ee12b079 268:ded5306a1fd1 551 frames[id][1] = (FSC_science>>24)&0xff;
ee12b079 268:ded5306a1fd1 552 frames[id][2] = (FSC_science>>16)&0xff;
ee12b079 268:ded5306a1fd1 553 frames[id][3] = (FSC_science>>8)&0xff;
ee12b079 268:ded5306a1fd1 554 frames[id][4] = FSC_science&0xff;
chaithanyarss 290:3159ff1081a2 555 #endif
ee12b079 268:ded5306a1fd1 556 }
ee12b079 268:ded5306a1fd1 557 else if(id == 2) //above threshold
ee12b079 268:ded5306a1fd1 558 {
ee12b079 268:ded5306a1fd1 559 space = adjust(1,0,pointer,8);
ee12b079 268:ded5306a1fd1 560 space = adjust(4,2,pointer,space);
ee12b079 268:ded5306a1fd1 561 FSC_science = FSC_CURRENT[2]; ///to be used as this
chaithanyarss 290:3159ff1081a2 562 #if debug_fsc
chaithanyarss 290:3159ff1081a2 563 frames[id][1] = (test_fsc[2]>>16)&0xff;
chaithanyarss 290:3159ff1081a2 564 frames[id][2] = (test_fsc[2]>>8)&0xff;
chaithanyarss 290:3159ff1081a2 565 frames[id][3] = test_fsc[2]&0xff;
chaithanyarss 290:3159ff1081a2 566 test_fsc[2]++;
chaithanyarss 290:3159ff1081a2 567 #endif
chaithanyarss 290:3159ff1081a2 568 #if !debug_fsc
ee12b079 268:ded5306a1fd1 569 frames[id][1] = (FSC_science>>16)&0xff;
ee12b079 268:ded5306a1fd1 570 frames[id][2] = (FSC_science>>8)&0xff;
ee12b079 268:ded5306a1fd1 571 frames[id][3] = FSC_science&0xff;
chaithanyarss 290:3159ff1081a2 572 #endif
ee12b079 268:ded5306a1fd1 573 }
ee12b079 268:ded5306a1fd1 574 temp_crc = crc16_gen(frames[id],132);
ee12b079 268:ded5306a1fd1 575 frames[id][132] = temp_crc>>8;
ee12b079 268:ded5306a1fd1 576 frames[id][133] = temp_crc & 0xff;
ee12b079 268:ded5306a1fd1 577
chaithanyarss 290:3159ff1081a2 578 //gPC.printf("\n\rPrinting SFP_TM\n\r{");
chaithanyarss 290:3159ff1081a2 579 gPC.printf("\n\r{");
ee12b079 268:ded5306a1fd1 580 for(uint8_t z=0;z<134;z++){
chaithanyarss 290:3159ff1081a2 581 gPC.printf("%02X",frames[id][z]);
ee12b079 268:ded5306a1fd1 582 }
ee12b079 268:ded5306a1fd1 583 gPC.printf("}\n\r");
chaithanyarss 290:3159ff1081a2 584 position_tm_frame[id] = position_tm_starting[id];
ee12b079 268:ded5306a1fd1 585 }
ee12b079 268:ded5306a1fd1 586 #endif
ee12b079 93:4d76de54a699 587 at = 0; pzf = 1; ezf = 1;
ee12b079 93:4d76de54a699 588 srp_mode = head[2]&0x1;
prasanthbj05 266:ae588e75cfa4 589 uint8_t compression_option = (head[2]>>1)&0x3;
prasanthbj05 266:ae588e75cfa4 590 /*-------------------------------Tagging the scp packet formed from these 60 sfp's as AT or BT starts here-------------------------
prasanthbj05 266:ae588e75cfa4 591 ------------------(in case compression option = 0 , then tagging beacon packet(not yet formed) as AT or BT is also done)----------*/
prasanthbj05 266:ae588e75cfa4 592 if(srp_mode ==0)
prasanthbj05 266:ae588e75cfa4 593 {
prasanthbj05 266:ae588e75cfa4 594 if(compression_option == 0)
prasanthbj05 266:ae588e75cfa4 595 {
prasanthbj05 266:ae588e75cfa4 596 for(int i=0; i<52 ;i++)
prasanthbj05 266:ae588e75cfa4 597 {
prasanthbj05 266:ae588e75cfa4 598 if(scp_bin[i] > scp_threshold_m0[i])
prasanthbj05 266:ae588e75cfa4 599 {
ee12b079 268:ded5306a1fd1 600 //gPC.printf("\n\rSCP above threshold index: %d",i);
ee12b079 93:4d76de54a699 601 at = 1;
shreeshas95 1:a0055b3280c8 602 break;
shreeshas95 1:a0055b3280c8 603 }
shreeshas95 1:a0055b3280c8 604 }
ee12b079 93:4d76de54a699 605 }
prasanthbj05 266:ae588e75cfa4 606 else if(compression_option == 1)
prasanthbj05 266:ae588e75cfa4 607 {
ee12b079 268:ded5306a1fd1 608 if(scp_bin[44] > scp_threshold_m0_1[0]){//gPC.printf("\n\rSCP above threshold index: 44");
ee12b079 268:ded5306a1fd1 609 at=1;}
prasanthbj05 266:ae588e75cfa4 610 for(int i=0; i<4 ;i++)
prasanthbj05 266:ae588e75cfa4 611 {
prasanthbj05 266:ae588e75cfa4 612 if(scp_bin[48+i] > scp_threshold_m0_1[i+1])
prasanthbj05 266:ae588e75cfa4 613 {
ee12b079 268:ded5306a1fd1 614 //gPC.printf("\n\rSCP above threshold index: %d",i+48);
ee12b079 93:4d76de54a699 615 at = 1;
ee12b079 93:4d76de54a699 616 break;
ee12b079 93:4d76de54a699 617 }
shreeshas95 1:a0055b3280c8 618 }
ee12b079 268:ded5306a1fd1 619 if(scp_bin[17] > scp_threshold_m0_1[5]){
ee12b079 268:ded5306a1fd1 620 //gPC.printf("\n\rSP above threshold index: 17");
ee12b079 268:ded5306a1fd1 621 at=1;
ee12b079 268:ded5306a1fd1 622 }
ee12b079 268:ded5306a1fd1 623 if(scp_bin[23] > scp_threshold_m0_1[6]){
ee12b079 268:ded5306a1fd1 624 //gPC.printf("\n\rSP above threshold index: 23");
ee12b079 268:ded5306a1fd1 625 at=1;
ee12b079 268:ded5306a1fd1 626 }
prasanthbj05 266:ae588e75cfa4 627
ee12b079 93:4d76de54a699 628 proton_scp_sum = 0; electron_scp_sum = 0;
prasanthbj05 266:ae588e75cfa4 629 for(int i=0;i<17;i++)
prasanthbj05 266:ae588e75cfa4 630 {
ee12b079 93:4d76de54a699 631 proton_scp_sum += scp_bin[i];
shreeshas95 1:a0055b3280c8 632 }
prasanthbj05 266:ae588e75cfa4 633 for(int i=0; i<5; i++)
prasanthbj05 266:ae588e75cfa4 634 {
ee12b079 93:4d76de54a699 635 electron_scp_sum += scp_bin[18+i];
ee12b079 93:4d76de54a699 636 }
ee12b079 268:ded5306a1fd1 637 if(proton_scp_sum > scp_threshold_m0_1[7]){ //gPC.printf("\n\rProton_scp_sum above threshold");
ee12b079 268:ded5306a1fd1 638 at=1;}
ee12b079 268:ded5306a1fd1 639 if(electron_scp_sum > scp_threshold_m0_1[8]){//gPC.printf("\n\rElectron_scp_sum above threshold");
ee12b079 268:ded5306a1fd1 640 at=1;}
shreeshas95 1:a0055b3280c8 641 }
prasanthbj05 266:ae588e75cfa4 642 else if(compression_option == 2)
prasanthbj05 266:ae588e75cfa4 643 {
ee12b079 268:ded5306a1fd1 644 if(scp_bin[50] > scp_sfp_threshold_m0_2[0]){//gPC.printf("\n\rSCP above threshold index:50");
ee12b079 268:ded5306a1fd1 645 at=1;}
prasanthbj05 266:ae588e75cfa4 646 proton_scp_sum = 0; electron_scp_sum = 0;
prasanthbj05 266:ae588e75cfa4 647 for(int i=0;i<17;i++)
prasanthbj05 266:ae588e75cfa4 648 {
prasanthbj05 266:ae588e75cfa4 649 proton_scp_sum += scp_bin[i];
prasanthbj05 266:ae588e75cfa4 650 }
prasanthbj05 266:ae588e75cfa4 651 for(int i=0; i<5; i++)
prasanthbj05 266:ae588e75cfa4 652 {
prasanthbj05 266:ae588e75cfa4 653 electron_scp_sum += scp_bin[18+i];
prasanthbj05 266:ae588e75cfa4 654 }
ee12b079 268:ded5306a1fd1 655 if(proton_scp_sum > scp_sfp_threshold_m0_2[1]){//gPC.printf("\n\rProton_SCP_sum above threshold");
ee12b079 268:ded5306a1fd1 656 at=1;}
ee12b079 268:ded5306a1fd1 657 if(electron_scp_sum > scp_sfp_threshold_m0_2[2]){//gPC.printf("\n\rElectron above threshold");
ee12b079 268:ded5306a1fd1 658 at=1;}
prasanthbj05 266:ae588e75cfa4 659 }
prasanthbj05 266:ae588e75cfa4 660 }
prasanthbj05 266:ae588e75cfa4 661 else if(srp_mode ==1)
prasanthbj05 266:ae588e75cfa4 662 {
ee12b079 268:ded5306a1fd1 663 if(compression_option==0){
prasanthbj05 266:ae588e75cfa4 664 for(int i=0; i<48; i++)
prasanthbj05 266:ae588e75cfa4 665 {
prasanthbj05 266:ae588e75cfa4 666 if(scp_bin[i] > scp_threshold_m1[i]){
ee12b079 268:ded5306a1fd1 667 //gPC.printf("\nSCP above threshold index:%d, Value:%d",i,scp_bin[i]);
prasanthbj05 266:ae588e75cfa4 668 at = 1;
prasanthbj05 266:ae588e75cfa4 669 break;
prasanthbj05 266:ae588e75cfa4 670 }
prasanthbj05 266:ae588e75cfa4 671 }
prasanthbj05 266:ae588e75cfa4 672 for(int i=48; i<52; i++)
prasanthbj05 266:ae588e75cfa4 673 {
prasanthbj05 266:ae588e75cfa4 674 if(scp_bin[i] > scp_threshold_m1[i]){
ee12b079 268:ded5306a1fd1 675 //gPC.printf("\nSCP above threshold index:%d, Value:%d",i,scp_bin[i]);
prasanthbj05 266:ae588e75cfa4 676 at = 1;
prasanthbj05 266:ae588e75cfa4 677 break;
prasanthbj05 266:ae588e75cfa4 678 }
shreeshas95 1:a0055b3280c8 679 }
shreeshas95 1:a0055b3280c8 680 }
ee12b079 268:ded5306a1fd1 681 else if(compression_option==2){
ee12b079 268:ded5306a1fd1 682 if(scp_bin[50]>scp_sfp_threshold_m0_2[0]){
ee12b079 268:ded5306a1fd1 683 //gPC.printf("\nSCP above threshold index:50, Value:%",scp_bin[50]);
ee12b079 268:ded5306a1fd1 684 at=1;
ee12b079 268:ded5306a1fd1 685 }
prasanthbj05 266:ae588e75cfa4 686 }
prasanthbj05 266:ae588e75cfa4 687 }
prasanthbj05 266:ae588e75cfa4 688 /*----------------------------Tagging the scp packet formed from these 60 sfp's as AT or BT ends here--------------------------*/
prasanthbj05 266:ae588e75cfa4 689
prasanthbj05 266:ae588e75cfa4 690 if(srp_mode == 0)
prasanthbj05 266:ae588e75cfa4 691 {
prasanthbj05 266:ae588e75cfa4 692 //determining if non zero values of proton and electron bins exist for calibrated mode (srp)
prasanthbj05 266:ae588e75cfa4 693 for(int i=0; i<17 ;i++)
prasanthbj05 266:ae588e75cfa4 694 {
prasanthbj05 266:ae588e75cfa4 695 if(scp_bin[i]>0)
prasanthbj05 266:ae588e75cfa4 696 pzf = 0;
prasanthbj05 266:ae588e75cfa4 697 }
prasanthbj05 266:ae588e75cfa4 698 for(int i=18; i<23 ;i++)
prasanthbj05 266:ae588e75cfa4 699 {
prasanthbj05 266:ae588e75cfa4 700 if(scp_bin[i]>0)
prasanthbj05 266:ae588e75cfa4 701 ezf = 0;
prasanthbj05 266:ae588e75cfa4 702 }
prasanthbj05 266:ae588e75cfa4 703 }
prasanthbj05 266:ae588e75cfa4 704 /*-----------------------------------------Tagging beacon packet as AT or BT starts here-------------------------------------*/
prasanthbj05 266:ae588e75cfa4 705 beacon_at = 0;
prasanthbj05 266:ae588e75cfa4 706 if(srp_mode==0) //those bins which can be meaningfully compared only in srp_mode==0
prasanthbj05 266:ae588e75cfa4 707 {
prasanthbj05 266:ae588e75cfa4 708 if(scp_bin[44]>beacon_threshold[0]) beacon_at = 1;
prasanthbj05 266:ae588e75cfa4 709 if(scp_bin[17]>beacon_threshold[5]) beacon_at = 1;
prasanthbj05 266:ae588e75cfa4 710 if(scp_bin[23]>beacon_threshold[6]) beacon_at = 1;
prasanthbj05 266:ae588e75cfa4 711 proton_scp_sum = 0; electron_scp_sum = 0;
prasanthbj05 266:ae588e75cfa4 712 for(int i=0;i<17;i++)
prasanthbj05 266:ae588e75cfa4 713 {
prasanthbj05 266:ae588e75cfa4 714 proton_scp_sum += scp_bin[i];
prasanthbj05 266:ae588e75cfa4 715 }
prasanthbj05 266:ae588e75cfa4 716 for(int i=0; i<5; i++)
prasanthbj05 266:ae588e75cfa4 717 {
prasanthbj05 266:ae588e75cfa4 718 electron_scp_sum += scp_bin[18+i];
prasanthbj05 266:ae588e75cfa4 719 }
prasanthbj05 266:ae588e75cfa4 720 if(proton_scp_sum > beacon_threshold[7]) beacon_at =1;
prasanthbj05 266:ae588e75cfa4 721 if(electron_scp_sum > beacon_threshold[8]) beacon_at =1;
prasanthbj05 266:ae588e75cfa4 722 }
prasanthbj05 266:ae588e75cfa4 723 if(scp_bin[48]>beacon_threshold[1]) beacon_at = 1;
prasanthbj05 266:ae588e75cfa4 724 if(scp_bin[49]>beacon_threshold[2]) beacon_at = 1;
prasanthbj05 266:ae588e75cfa4 725 if(scp_bin[50]>beacon_threshold[3]) beacon_at = 1;
prasanthbj05 266:ae588e75cfa4 726 if(scp_bin[51]>beacon_threshold[4]) beacon_at = 1;
prasanthbj05 266:ae588e75cfa4 727 /*----------------------------------------Tagging beacon packet as AT or BT ends here------------------------------------------*/
prasanthbj05 266:ae588e75cfa4 728
prasanthbj05 266:ae588e75cfa4 729 /*-----------------------------------------------Forming the beacon packet starts here-----------------------------------------*/
prasanthbj05 266:ae588e75cfa4 730 //Last 512 bits of beacon_array excluding CRC bits is used for storing the 5 most recent beacon packets
prasanthbj05 266:ae588e75cfa4 731
prasanthbj05 266:ae588e75cfa4 732 if(beacon_cntr == 1)
prasanthbj05 266:ae588e75cfa4 733 {
prasanthbj05 267:783c248a6207 734 beacon_ptr = &(beacon_array[47]); // starting block address, stores the oldest(among the 5 most recent) beacon packet
prasanthbj05 266:ae588e75cfa4 735 }
prasanthbj05 266:ae588e75cfa4 736 else if(beacon_cntr>1 && beacon_cntr<6)
prasanthbj05 266:ae588e75cfa4 737 {
prasanthbj05 267:783c248a6207 738 beacon_ptr +=17; // increase the block number(totally 5 blocks for 5 beacon packets)
prasanthbj05 266:ae588e75cfa4 739 }
prasanthbj05 266:ae588e75cfa4 740 else if(beacon_cntr == 6)
prasanthbj05 266:ae588e75cfa4 741 {
prasanthbj05 267:783c248a6207 742 for(uint16_t i=0;i<17;i++) // when all 5 blocks have been used shift the last 4 blocks up along the array and
prasanthbj05 266:ae588e75cfa4 743 { // overwrite the new beacon packet in the 5th block
prasanthbj05 267:783c248a6207 744 beacon_array[47+i] = beacon_array[64+i];
prasanthbj05 267:783c248a6207 745 beacon_array[64+i] = beacon_array[81+i];
prasanthbj05 267:783c248a6207 746 beacon_array[81+i] = beacon_array[98+i];
prasanthbj05 267:783c248a6207 747 beacon_array[98+i] = beacon_array[115+i];
prasanthbj05 266:ae588e75cfa4 748 }
prasanthbj05 267:783c248a6207 749 beacon_ptr = &(beacon_array[115]); //address of the 5th block
prasanthbj05 266:ae588e75cfa4 750 beacon_cntr = 5;
prasanthbj05 266:ae588e75cfa4 751 }
prasanthbj05 266:ae588e75cfa4 752 pointer = beacon_ptr; debug_cntr = 0; space = 8;
prasanthbj05 267:783c248a6207 753 space = adjust(2, compression_option,pointer,space); pointer += space>>4; debug_cntr += space>>4; //first two bits of compression option
prasanthbj05 267:783c248a6207 754 space = adjust(1, srp_mode,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 267:783c248a6207 755 space = adjust(3,(sci_time>>32)&0x07,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 267:783c248a6207 756 space = adjust(8,(sci_time>>24)&0xff,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 267:783c248a6207 757 space = adjust(8,(sci_time>>16)&0xff,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 267:783c248a6207 758 space = adjust(8,(sci_time>>8)&0xff,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 267:783c248a6207 759 space = adjust(8,(sci_time)&0xff,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 267:783c248a6207 760 space = adjust(4, (attitude)&0x0f,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 761
prasanthbj05 266:ae588e75cfa4 762 if(srp_mode==0){
prasanthbj05 266:ae588e75cfa4 763 if(beacon_at == 0){
prasanthbj05 267:783c248a6207 764 space = adjust(1, 0,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 267:783c248a6207 765 space = adjust(6, compress(scp_bin[44],3,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 267:783c248a6207 766 space = adjust(7, compress(scp_bin[48],4,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 267:783c248a6207 767 space = adjust(7, compress(scp_bin[49],4,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 267:783c248a6207 768 space = adjust(7, compress(scp_bin[50],4,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 267:783c248a6207 769 space = adjust(7, compress(scp_bin[51],4,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 267:783c248a6207 770 space = adjust(6, compress(scp_bin[17],3,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 267:783c248a6207 771 space = adjust(6, compress(scp_bin[23],3,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 772 space = adjust(4, compress(proton_scp_sum ,10,2)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 773 space = adjust(8, compress(proton_scp_sum ,10,2),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 267:783c248a6207 774 space = adjust(4, compress(electron_scp_sum ,10,2)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 775 space = adjust(8, compress(electron_scp_sum ,10,2),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 776 pointer = pointer + 1;
prasanthbj05 266:ae588e75cfa4 777 for(int temp_i = 12; temp_i<14; temp_i++)
prasanthbj05 266:ae588e75cfa4 778 {
prasanthbj05 266:ae588e75cfa4 779 *pointer = 0;
prasanthbj05 266:ae588e75cfa4 780 pointer = pointer + 1;
prasanthbj05 266:ae588e75cfa4 781 }
prasanthbj05 266:ae588e75cfa4 782 }
prasanthbj05 266:ae588e75cfa4 783 else if(beacon_at==1){
prasanthbj05 266:ae588e75cfa4 784 space = adjust(1, 1,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 785 space = adjust(1, compress(sfp_bin[44],6,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 786 space = adjust(8, compress(sfp_bin[44],6,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 787 space = adjust(4, compress(sfp_bin[48],9,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 788 space = adjust(8, compress(sfp_bin[48],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 789 space = adjust(4, compress(sfp_bin[49],9,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 790 space = adjust(8, compress(sfp_bin[49],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 791 space = adjust(4, compress(sfp_bin[50],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 792 space = adjust(8, compress(sfp_bin[50],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 793 space = adjust(4, compress(sfp_bin[51],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 794 space = adjust(8, compress(sfp_bin[51],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 795 space = adjust(1, compress(sfp_bin[17],6,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 796 space = adjust(8, compress(sfp_bin[17],6,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 797 space = adjust(1, compress(sfp_bin[23],6,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 798 space = adjust(8, compress(sfp_bin[23],6,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 799 space = adjust(1, compress(proton_scp_sum ,6,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 800 space = adjust(8, compress(proton_scp_sum ,6,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 801 space = adjust(1, compress(electron_scp_sum,6,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 802 space = adjust(8, compress(electron_scp_sum ,6,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 803 //cout<<"for beacon space = "<<(space&0x0f)<<" counter = "<<debug_cntr;
prasanthbj05 266:ae588e75cfa4 804 }
prasanthbj05 266:ae588e75cfa4 805 }else if(srp_mode==1){
prasanthbj05 266:ae588e75cfa4 806 if(beacon_at==0){
prasanthbj05 267:783c248a6207 807 space = adjust(1, 0,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 267:783c248a6207 808 space = adjust(6, compress(0,3,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 809 space = adjust(7, compress(sfp_bin[48],4,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 810 space = adjust(7, compress(sfp_bin[49],4,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 811 space = adjust(7, compress(sfp_bin[50],4,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 812 space = adjust(7, compress(sfp_bin[51],4,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 813 pointer = pointer + 1;
prasanthbj05 266:ae588e75cfa4 814 for(uint8_t temp_i = 7; temp_i<14; temp_i++)
prasanthbj05 266:ae588e75cfa4 815 {
prasanthbj05 266:ae588e75cfa4 816 *pointer = 0;
prasanthbj05 266:ae588e75cfa4 817 pointer = pointer + 1;
prasanthbj05 266:ae588e75cfa4 818 }
prasanthbj05 266:ae588e75cfa4 819 }
prasanthbj05 266:ae588e75cfa4 820 else if(beacon_at==1){
prasanthbj05 267:783c248a6207 821 space = adjust(1, 1,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 267:783c248a6207 822 space = adjust(1, compress(0,6,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 267:783c248a6207 823 space = adjust(8, compress(0,6,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 824 space = adjust(4, compress(sfp_bin[48],9,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 825 space = adjust(8, compress(sfp_bin[48],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 826 space = adjust(4, compress(sfp_bin[49],9,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 827 space = adjust(8, compress(sfp_bin[49],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 828 space = adjust(4, compress(sfp_bin[50],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 829 space = adjust(8, compress(sfp_bin[50],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 830 space = adjust(4, compress(sfp_bin[51],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 831 space = adjust(8, compress(sfp_bin[51],9,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 832 pointer = pointer + 1;
prasanthbj05 266:ae588e75cfa4 833 for(uint8_t temp_i = 10; temp_i<14; temp_i++)
prasanthbj05 266:ae588e75cfa4 834 {
prasanthbj05 266:ae588e75cfa4 835 *pointer = 0;
prasanthbj05 266:ae588e75cfa4 836 pointer = pointer + 1;
ee12b079 93:4d76de54a699 837 }
shreeshas95 1:a0055b3280c8 838 }
shreeshas95 1:a0055b3280c8 839 }
prasanthbj05 266:ae588e75cfa4 840 beacon_cntr++;
prasanthbj05 266:ae588e75cfa4 841 /*--------------------------------------------------beacon packet ends here--------------------------------------------------------*/
prasanthbj05 266:ae588e75cfa4 842
chaithanyarss 290:3159ff1081a2 843 //gPC.printf("\n\n\rSCP");
prasanthbj05 266:ae588e75cfa4 844 uint8_t packet_pp,time_diff;
prasanthbj05 266:ae588e75cfa4 845 /*------------------------------------------Forming a science packet(scp) starts here----------------------------------------------*/
prasanthbj05 266:ae588e75cfa4 846
ee12b079 93:4d76de54a699 847 pointer = scp; debug_cntr = 0; space = 8;
prasanthbj05 266:ae588e75cfa4 848 time_diff = 0;
prasanthbj05 266:ae588e75cfa4 849
prasanthbj05 266:ae588e75cfa4 850 packet_pp = 1;
prasanthbj05 266:ae588e75cfa4 851 if((((uint8_t)(sci_time>>7))&0x3f)<(((uint8_t)(time_prev_scp>>7))&0x3f))
prasanthbj05 266:ae588e75cfa4 852 {
prasanthbj05 266:ae588e75cfa4 853 time_diff = time_diff+60;
prasanthbj05 266:ae588e75cfa4 854 }
prasanthbj05 266:ae588e75cfa4 855 time_diff += (((uint8_t)(sci_time>>7))&0x3f);
prasanthbj05 266:ae588e75cfa4 856 time_diff -= (((uint8_t)(time_prev_scp>>7))&0x3f);
prasanthbj05 266:ae588e75cfa4 857 if(time_diff>10){
prasanthbj05 266:ae588e75cfa4 858 packet_pp = 0;
prasanthbj05 266:ae588e75cfa4 859 }
prasanthbj05 266:ae588e75cfa4 860 time_prev_scp = sci_time;
prasanthbj05 266:ae588e75cfa4 861 uint32_t sfp_at_counter;
prasanthbj05 266:ae588e75cfa4 862 sfp_at_counter = FSC_CURRENT[2];
prasanthbj05 266:ae588e75cfa4 863 space = adjust(1, packet_pp,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 864 space = adjust(5, (sci_time>>8)&0x1f,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 865 space = adjust(8, (sci_time)&0xff,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 866 space = adjust(4, (attitude)&0xf,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 867 space = adjust(2, compression_option,pointer,space); pointer += space>>4; debug_cntr += space>>4; //first two bits of compression option
prasanthbj05 266:ae588e75cfa4 868 space = adjust(1, at,pointer,space); pointer += space>>4; debug_cntr += space>>4; //last bit of compression option
prasanthbj05 266:ae588e75cfa4 869 space = adjust(1, srp_mode,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 870 if(!(srp_mode==0 && compression_option==2))
prasanthbj05 266:ae588e75cfa4 871 {
prasanthbj05 266:ae588e75cfa4 872 space = adjust(8, sfp_at_counter>>16,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 873 space = adjust(8, sfp_at_counter>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 874 space = adjust(8, sfp_at_counter,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 875 }
ee12b079 93:4d76de54a699 876 if(srp_mode == 0 && compression_option == 0){ //normal callibrated mode
ee12b079 268:ded5306a1fd1 877 #if scpz
chaithanyarss 290:3159ff1081a2 878 gPC.printf("\n\rSCP - Normal calibrated mode");
ee12b079 268:ded5306a1fd1 879 #endif
prasanthbj05 266:ae588e75cfa4 880 space = adjust(1, pzf,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 881 space = adjust(1, ezf,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 882 if(at == 0 ){
ee12b079 268:ded5306a1fd1 883 #if scpz
chaithanyarss 290:3159ff1081a2 884 gPC.printf("\n\rBelow threshold");
ee12b079 268:ded5306a1fd1 885 #endif
ee12b079 93:4d76de54a699 886 for(int i = 0; i<8 ;i++){
prasanthbj05 266:ae588e75cfa4 887 space = adjust(7,compress(scp_bin[24+i],4,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 888 }
ee12b079 93:4d76de54a699 889 for(int i = 0; i<12 ;i++){
prasanthbj05 266:ae588e75cfa4 890 space = adjust(5,compress(scp_bin[32+i],2,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 891 }
ee12b079 93:4d76de54a699 892 for(int i = 0; i<4 ;i++){
ee12b079 93:4d76de54a699 893 space = adjust(6,compress(scp_bin[44+i],3,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 894 }
ee12b079 93:4d76de54a699 895 for(int i = 0; i<4 ;i++){
ee12b079 93:4d76de54a699 896 space = adjust(7,compress(scp_bin[48+i],4,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 897 }
prasanthbj05 266:ae588e75cfa4 898 space = adjust(6,compress(scp_bin[17],3,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 899 space = adjust(6,compress(scp_bin[23],3,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 900 if(pzf == 0){
ee12b079 93:4d76de54a699 901 for(int i = 0; i<2 ;i++){
ee12b079 93:4d76de54a699 902 space = adjust(8,compress(scp_bin[i],6,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 903 }
ee12b079 93:4d76de54a699 904 for(int i = 0; i<15 ;i++){
prasanthbj05 266:ae588e75cfa4 905 space = adjust(7,compress(scp_bin[i+2],5,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 906 }
ee12b079 93:4d76de54a699 907 }
ee12b079 93:4d76de54a699 908 if(ezf == 0){
ee12b079 93:4d76de54a699 909 space = adjust(1,compress(scp_bin[18],7,2)>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 910 space = adjust(8,compress(scp_bin[18],7,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 911 for(int i=0; i<4; i++){
prasanthbj05 266:ae588e75cfa4 912 space = adjust(8,compress(scp_bin[19+i],6,2) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 913 }
ee12b079 93:4d76de54a699 914 }
ee12b079 93:4d76de54a699 915 }// below threshold ends here
ee12b079 93:4d76de54a699 916 if(at == 1){
ee12b079 268:ded5306a1fd1 917 #if scpz
chaithanyarss 290:3159ff1081a2 918 gPC.printf("\n\rAbove threshold");
ee12b079 268:ded5306a1fd1 919 #endif
ee12b079 93:4d76de54a699 920 for(int i = 0; i<8 ;i++){
ee12b079 93:4d76de54a699 921 space = adjust(7,compress(scp_bin[24+i],4,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 922 }
ee12b079 93:4d76de54a699 923 for(int i = 0; i<12 ;i++){
ee12b079 93:4d76de54a699 924 space = adjust(5,compress(scp_bin[32+i],2,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 925 }
ee12b079 93:4d76de54a699 926 for(int i = 0; i<4 ;i++){
prasanthbj05 266:ae588e75cfa4 927 space = adjust(1,compress(scp_bin[44+i],6,3)>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 928 space = adjust(8,compress(scp_bin[44+i],6,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 929 }
ee12b079 93:4d76de54a699 930 for(int i=0; i<4 ;i++){
prasanthbj05 266:ae588e75cfa4 931 space = adjust(4,compress(scp_bin[48+i],9,3)>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 932 space = adjust(8,compress(scp_bin[48+i],9,3) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 933 }
prasanthbj05 266:ae588e75cfa4 934 space = adjust(1,compress(scp_bin[17],6,3)>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 935 space = adjust(8,compress(scp_bin[17],6,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 936 space = adjust(1,compress(scp_bin[23],6,3)>>8,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 937 space = adjust(8,compress(scp_bin[23],6,3),pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 938
ee12b079 93:4d76de54a699 939 if(pzf == 0){
ee12b079 93:4d76de54a699 940 for(int i = 0; i<17 ; i++){
prasanthbj05 266:ae588e75cfa4 941 space = adjust(8, (compress(scp_bin[i],5,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 942 }
ee12b079 93:4d76de54a699 943 }
ee12b079 93:4d76de54a699 944 if(ezf == 0){
ee12b079 93:4d76de54a699 945 for(int i = 0; i<5 ; i++){
ee12b079 93:4d76de54a699 946 space = adjust(8, (compress(scp_bin[18+i],5,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 947 }
ee12b079 93:4d76de54a699 948 }
ee12b079 93:4d76de54a699 949 } //above thresholds ends
ee12b079 93:4d76de54a699 950 } //srp_mode == 0 ends
ee12b079 93:4d76de54a699 951 if(srp_mode == 1){
ee12b079 268:ded5306a1fd1 952 #if scpz
chaithanyarss 290:3159ff1081a2 953 gPC.printf("\n\rSCP - Scatter plot mode");
ee12b079 268:ded5306a1fd1 954 #endif
ee12b079 93:4d76de54a699 955 if(at == 0){
ee12b079 268:ded5306a1fd1 956 #if scpz
chaithanyarss 290:3159ff1081a2 957 gPC.printf("\n\rBelow Threshold");
ee12b079 268:ded5306a1fd1 958 #endif
prasanthbj05 266:ae588e75cfa4 959 for(int i=0; i<48; i++){
prasanthbj05 266:ae588e75cfa4 960 space = adjust(6, ((compress(scp_bin[i],3,3))&0xff) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 961 }
ee12b079 93:4d76de54a699 962 for(int i = 0 ; i < 4 ; i++){
prasanthbj05 266:ae588e75cfa4 963 space = adjust(7, (compress(scp_bin[48+i],4,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 964 }
ee12b079 93:4d76de54a699 965 }
ee12b079 93:4d76de54a699 966 if(at == 1){
ee12b079 268:ded5306a1fd1 967 #if scpz
chaithanyarss 290:3159ff1081a2 968 gPC.printf("\n\rAbove threshold");
ee12b079 268:ded5306a1fd1 969 #endif
prasanthbj05 266:ae588e75cfa4 970 for(int i=0; i<48; i++){
prasanthbj05 266:ae588e75cfa4 971 space = adjust(7, (compress((scp_bin[i]/2),4,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 972 }
ee12b079 93:4d76de54a699 973 for(int i = 0 ; i < 4 ; i++){
prasanthbj05 266:ae588e75cfa4 974 space = adjust(4, (compress(scp_bin[48+i],9,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 975 space = adjust(8, (compress(scp_bin[48+i],9,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 976 }
ee12b079 93:4d76de54a699 977 }
ee12b079 93:4d76de54a699 978 }// scp mode 1 end
ee12b079 93:4d76de54a699 979 if( srp_mode == 0 && compression_option == 1 ){ //scp data conservation mode
ee12b079 268:ded5306a1fd1 980 #if scpz
chaithanyarss 290:3159ff1081a2 981 gPC.printf("\n\rSCP - Calibrated data conservation mode");
ee12b079 268:ded5306a1fd1 982 #endif
ee12b079 93:4d76de54a699 983 space = adjust(1, pzf,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 984 space = adjust(1, ezf,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 985 if(at == 0){
ee12b079 268:ded5306a1fd1 986 #if scpz
chaithanyarss 290:3159ff1081a2 987 gPC.printf("\n\rBelow threshold");
ee12b079 268:ded5306a1fd1 988 #endif
prasanthbj05 266:ae588e75cfa4 989 space = adjust(6, (compress(scp_bin[44],3,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 990 for(int i=0; i<4; i++){
prasanthbj05 266:ae588e75cfa4 991 space = adjust(7, (compress(scp_bin[48+i],4,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 992 }
prasanthbj05 266:ae588e75cfa4 993 space = adjust(6, (compress(scp_bin[17],3,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 994 space = adjust(6, (compress(scp_bin[23],3,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 995 if(pzf==0){
prasanthbj05 266:ae588e75cfa4 996 space = adjust(4, (compress(proton_scp_sum,10,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 997 space = adjust(8, ( compress(proton_scp_sum,10,2)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 998 }
prasanthbj05 266:ae588e75cfa4 999 if(ezf==0){
prasanthbj05 266:ae588e75cfa4 1000 space = adjust(4, (compress(electron_scp_sum,10,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1001 space = adjust(8, (compress(electron_scp_sum,10,2)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1002 }
ee12b079 93:4d76de54a699 1003 }else if(at == 1){
ee12b079 268:ded5306a1fd1 1004 #if scpz
chaithanyarss 290:3159ff1081a2 1005 gPC.printf("\n\rAbove threshold");
ee12b079 268:ded5306a1fd1 1006 #endif
prasanthbj05 266:ae588e75cfa4 1007 space = adjust(1, (compress(scp_bin[44],6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1008 space = adjust(8, (compress(scp_bin[44],6,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 1009 for(int i=0; i<4; i++){
ee12b079 93:4d76de54a699 1010 space = adjust(4, (compress(scp_bin[48+i],9,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 1011 space = adjust(8, (compress(scp_bin[48+i],9,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 1012 }
prasanthbj05 266:ae588e75cfa4 1013 space = adjust(1, (compress(scp_bin[17],6,3)>>8) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1014 space = adjust(8, (compress(scp_bin[17],6,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1015 space = adjust(1, (compress(scp_bin[23],6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1016 space = adjust(8, (compress(scp_bin[23],6,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 1017 if(pzf==0){
prasanthbj05 266:ae588e75cfa4 1018 space = adjust(1, (compress(proton_scp_sum,6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 1019 space = adjust(8, (compress(proton_scp_sum,6,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 1020 }
ee12b079 93:4d76de54a699 1021 if(ezf==0){
prasanthbj05 266:ae588e75cfa4 1022 space = adjust(1, (compress(electron_scp_sum,6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 1023 space = adjust(8, (compress(electron_scp_sum,6,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
ee12b079 93:4d76de54a699 1024 }
ee12b079 93:4d76de54a699 1025 }
prasanthbj05 266:ae588e75cfa4 1026 }
prasanthbj05 266:ae588e75cfa4 1027 if(compression_option == 2 ) //scp extreme data conservation mode
prasanthbj05 266:ae588e75cfa4 1028 {
prasanthbj05 266:ae588e75cfa4 1029 if(srp_mode==0)
prasanthbj05 266:ae588e75cfa4 1030 {
ee12b079 268:ded5306a1fd1 1031 #if scpz
chaithanyarss 290:3159ff1081a2 1032 gPC.printf("\n\rSCP - calibrated extreme data conservation mode");
ee12b079 268:ded5306a1fd1 1033 #endif
prasanthbj05 266:ae588e75cfa4 1034 space = adjust(1, pzf,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1035 space = adjust(1, ezf,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1036 if(at==0){
ee12b079 268:ded5306a1fd1 1037 #if scpz
chaithanyarss 290:3159ff1081a2 1038 gPC.printf("\n\rBelow threshold");
ee12b079 268:ded5306a1fd1 1039 #endif
prasanthbj05 266:ae588e75cfa4 1040 space = adjust(7, (compress(scp_bin[50],4,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1041 if(pzf==0){
prasanthbj05 266:ae588e75cfa4 1042 space = adjust(4, (compress(proton_scp_sum,10,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1043 space = adjust(8, ( compress(proton_scp_sum,10,2)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1044 }
prasanthbj05 266:ae588e75cfa4 1045 if(ezf==0){
prasanthbj05 266:ae588e75cfa4 1046 space = adjust(4, (compress(electron_scp_sum,10,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1047 space = adjust(8, (compress(electron_scp_sum,10,2)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1048 }
prasanthbj05 266:ae588e75cfa4 1049 }else if(at==1){
ee12b079 268:ded5306a1fd1 1050 #if scpz
chaithanyarss 290:3159ff1081a2 1051 gPC.printf("\n\rAbove threshold");
ee12b079 268:ded5306a1fd1 1052 #endif
prasanthbj05 266:ae588e75cfa4 1053 space = adjust(4, (compress(scp_bin[50],9,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1054 space = adjust(8, (compress(scp_bin[50],9,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1055 if(pzf==0){
prasanthbj05 266:ae588e75cfa4 1056 space = adjust(1, (compress(proton_scp_sum,6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1057 space = adjust(8, (compress(proton_scp_sum,6,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1058 }
prasanthbj05 266:ae588e75cfa4 1059 if(ezf==0){
prasanthbj05 266:ae588e75cfa4 1060 space = adjust(1, (compress(electron_scp_sum,6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1061 space = adjust(8, (compress(electron_scp_sum,6,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1062 }
prasanthbj05 266:ae588e75cfa4 1063 }
prasanthbj05 266:ae588e75cfa4 1064 }
prasanthbj05 266:ae588e75cfa4 1065 else if(srp_mode==1)
prasanthbj05 266:ae588e75cfa4 1066 {
ee12b079 268:ded5306a1fd1 1067 #if scpz
chaithanyarss 290:3159ff1081a2 1068 gPC.printf("\n\rSCP - Scatter plot, extreme data conservation mode");
ee12b079 268:ded5306a1fd1 1069 #endif
prasanthbj05 266:ae588e75cfa4 1070 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 266:ae588e75cfa4 1071 space = adjust(1, pzf,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1072 space = adjust(1, ezf,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1073 if(at==0){
ee12b079 268:ded5306a1fd1 1074 #if scpz
chaithanyarss 290:3159ff1081a2 1075 gPC.printf("\n\rBelow threshold");
ee12b079 268:ded5306a1fd1 1076 #endif
prasanthbj05 266:ae588e75cfa4 1077 space = adjust(7, (compress(scp_bin[50],4,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1078 // below 4 lines - filling the proton ane electron energy bins with zeros(junk value) since they're not available in srp
prasanthbj05 266:ae588e75cfa4 1079 space = adjust(4, (compress(0,10,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1080 space = adjust(8, (compress(0,10,2)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1081 space = adjust(4, (compress(0,10,2))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1082 space = adjust(8, (compress(0,10,2)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1083 }
prasanthbj05 266:ae588e75cfa4 1084 else if(at==1){
ee12b079 268:ded5306a1fd1 1085 #if scpz
chaithanyarss 290:3159ff1081a2 1086 gPC.printf("\n\rAbove threshold");
ee12b079 268:ded5306a1fd1 1087 #endif
prasanthbj05 266:ae588e75cfa4 1088 space = adjust(4, (compress(scp_bin[50],9,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1089 space = adjust(8, (compress(scp_bin[50],9,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1090 space = adjust(1, (compress(0,6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1091 space = adjust(8, (compress(0,6,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1092 space = adjust(1, (compress(0,6,3))>>8 ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1093 space = adjust(8, (compress(0,6,3)) ,pointer,space); pointer += space>>4; debug_cntr += space>>4;
prasanthbj05 266:ae588e75cfa4 1094 }
prasanthbj05 266:ae588e75cfa4 1095 }
prasanthbj05 266:ae588e75cfa4 1096 }
prasanthbj05 266:ae588e75cfa4 1097 /*---------------------------------------------forming a science packet ends here----------------------------------------------*/
prasanthbj05 266:ae588e75cfa4 1098
ee12b079 93:4d76de54a699 1099 id = 0;
ee12b079 93:4d76de54a699 1100 if(srp_mode == 0 && compression_option == 0){
ee12b079 93:4d76de54a699 1101 if(at == 0){
prasanthbj05 266:ae588e75cfa4 1102 length = 228+2; //2 spare bits
ee12b079 93:4d76de54a699 1103 if(pzf == 0)
ee12b079 93:4d76de54a699 1104 length += 121;
ee12b079 93:4d76de54a699 1105 if(ezf == 0)
ee12b079 93:4d76de54a699 1106 length +=41;
ee12b079 93:4d76de54a699 1107 }else if(at == 1){
prasanthbj05 266:ae588e75cfa4 1108 length = 266+6; //6 spare bits
ee12b079 93:4d76de54a699 1109 if(pzf == 0)
ee12b079 93:4d76de54a699 1110 length += 136;
ee12b079 93:4d76de54a699 1111 if(ezf == 0)
ee12b079 93:4d76de54a699 1112 length += 40;
ee12b079 93:4d76de54a699 1113 }
prasanthbj05 266:ae588e75cfa4 1114 }else if(srp_mode == 0 && compression_option == 1){ //data conservation mode
ee12b079 93:4d76de54a699 1115 if(at == 0){
prasanthbj05 266:ae588e75cfa4 1116 length = 94+2; //2 spare bits
ee12b079 93:4d76de54a699 1117 if(pzf == 0)
ee12b079 93:4d76de54a699 1118 length += 12;
ee12b079 93:4d76de54a699 1119 if(ezf == 0)
ee12b079 93:4d76de54a699 1120 length += 12;
ee12b079 93:4d76de54a699 1121 }else if(at == 1){
prasanthbj05 266:ae588e75cfa4 1122 length = 123+3; //3 spare bits
prasanthbj05 266:ae588e75cfa4 1123 if(pzf == 0)
prasanthbj05 266:ae588e75cfa4 1124 length += 9;
prasanthbj05 266:ae588e75cfa4 1125 if(ezf == 0)
prasanthbj05 266:ae588e75cfa4 1126 length += 9;
prasanthbj05 266:ae588e75cfa4 1127 }
prasanthbj05 266:ae588e75cfa4 1128 }
prasanthbj05 266:ae588e75cfa4 1129 else if( srp_mode == 1){
prasanthbj05 266:ae588e75cfa4 1130 if(at == 0)
prasanthbj05 266:ae588e75cfa4 1131 length = 368;
prasanthbj05 266:ae588e75cfa4 1132 else if(at == 1)
prasanthbj05 266:ae588e75cfa4 1133 length = 432;
prasanthbj05 266:ae588e75cfa4 1134 }
prasanthbj05 266:ae588e75cfa4 1135 else if(compression_option == 2) //in extreme data conservation mode, length is same for both srp_modes
prasanthbj05 266:ae588e75cfa4 1136 {
prasanthbj05 266:ae588e75cfa4 1137 if(at == 0){
prasanthbj05 266:ae588e75cfa4 1138 length = 31+1; //1 spare bits
prasanthbj05 266:ae588e75cfa4 1139 if(pzf == 0)
prasanthbj05 266:ae588e75cfa4 1140 length += 12;
prasanthbj05 266:ae588e75cfa4 1141 if(ezf == 0)
prasanthbj05 266:ae588e75cfa4 1142 length += 12;
prasanthbj05 266:ae588e75cfa4 1143 }else if(at == 1){
prasanthbj05 266:ae588e75cfa4 1144 length = 36+2; //2 spare bits
ee12b079 93:4d76de54a699 1145 if(pzf == 0)
ee12b079 93:4d76de54a699 1146 length += 9;
ee12b079 93:4d76de54a699 1147 if(ezf == 0)
ee12b079 93:4d76de54a699 1148 length += 9;
ee12b079 93:4d76de54a699 1149 }
ee12b079 93:4d76de54a699 1150 }
ee12b079 93:4d76de54a699 1151 length = (length%8==0)?(length/8):(length/8)+1;
ee12b079 268:ded5306a1fd1 1152 #if scpz
chaithanyarss 290:3159ff1081a2 1153 gPC.printf("\n\rSCP packet length = %d",length);
ee12b079 268:ded5306a1fd1 1154 #endif
ee12b079 268:ded5306a1fd1 1155 if(position_tm_frame[id]>129){
ee12b079 268:ded5306a1fd1 1156 #if scpz
chaithanyarss 290:3159ff1081a2 1157 gPC.printf("\n\rSkipping the current TM frame. Inserting SCP into the next frame");
chaithanyarss 290:3159ff1081a2 1158 gPC.printf("\n\rposition_tm_frame = %d",position_tm_frame[id]);
ee12b079 268:ded5306a1fd1 1159 #endif
prasanthbj05 266:ae588e75cfa4 1160 while(position_tm_frame[id]<132){
prasanthbj05 266:ae588e75cfa4 1161 frames[id][position_tm_frame[id]] = 0;
prasanthbj05 266:ae588e75cfa4 1162 position_tm_frame[id]++;
prasanthbj05 266:ae588e75cfa4 1163 }
prasanthbj05 266:ae588e75cfa4 1164 }
prasanthbj05 266:ae588e75cfa4 1165 if(position_tm_frame[id]==position_tm_starting[id]){
prasanthbj05 266:ae588e75cfa4 1166 frames[id][4] = position_tm_starting[id];
prasanthbj05 266:ae588e75cfa4 1167 }
prasanthbj05 266:ae588e75cfa4 1168 for(int j= 0; j < length ;)
prasanthbj05 266:ae588e75cfa4 1169 {
prasanthbj05 266:ae588e75cfa4 1170 if(position_tm_frame[id]==frames[id][4]){
ee12b079 268:ded5306a1fd1 1171 #if scpz
chaithanyarss 290:3159ff1081a2 1172 gPC.printf("\n\rInserting Time into SCP_TM");
ee12b079 268:ded5306a1fd1 1173 #endif
prasanthbj05 266:ae588e75cfa4 1174 frames[id][5] = (uint8_t)((sci_time>>29)&0x3f);
prasanthbj05 266:ae588e75cfa4 1175 frames[id][6] = (uint8_t)((sci_time>>21)&0xff);
prasanthbj05 266:ae588e75cfa4 1176 frames[id][7] = (uint8_t)((sci_time>>13)&0x3f);
prasanthbj05 266:ae588e75cfa4 1177 }
prasanthbj05 266:ae588e75cfa4 1178 if(position_tm_frame[id]<132){
prasanthbj05 266:ae588e75cfa4 1179 frames[id][position_tm_frame[id]] = scp[j];
prasanthbj05 266:ae588e75cfa4 1180 j++;
ee12b079 93:4d76de54a699 1181 position_tm_frame[id]++;
prasanthbj05 266:ae588e75cfa4 1182 }
prasanthbj05 266:ae588e75cfa4 1183 if(position_tm_frame[id] == 132) //space full in the frame bro
prasanthbj05 266:ae588e75cfa4 1184 {
ee12b079 268:ded5306a1fd1 1185 #if scpz
chaithanyarss 290:3159ff1081a2 1186 gPC.printf("\n\rSCP_TM frame full. Length of current SCP packet = %d",j);
ee12b079 268:ded5306a1fd1 1187 #endif
prasanthbj05 266:ae588e75cfa4 1188 pointer = frames[id];
prasanthbj05 266:ae588e75cfa4 1189 space = adjust(1,0,pointer,8);
prasanthbj05 266:ae588e75cfa4 1190 space = adjust(4,1,pointer,space);
prasanthbj05 266:ae588e75cfa4 1191 FSC_science = FSC_CURRENT[1];
chaithanyarss 290:3159ff1081a2 1192 //gPC.printf("1 = 0x%X",FSC_science);
chaithanyarss 290:3159ff1081a2 1193
chaithanyarss 290:3159ff1081a2 1194 #if debug_fsc
prasanthbj05 266:ae588e75cfa4 1195 frames[id][1] = (FSC_science>>16)&0xff;
prasanthbj05 266:ae588e75cfa4 1196 frames[id][2] = (FSC_science>>8)&0xff;
prasanthbj05 266:ae588e75cfa4 1197 frames[id][3] = (FSC_science)&0xff;
chaithanyarss 290:3159ff1081a2 1198 test_fsc[1]++;
chaithanyarss 290:3159ff1081a2 1199 #endif
chaithanyarss 290:3159ff1081a2 1200 #if !debug_fsc
chaithanyarss 290:3159ff1081a2 1201 frames[id][1] = (FSC_science>>16)&0xff;
chaithanyarss 290:3159ff1081a2 1202 frames[id][2] = (FSC_science>>8)&0xff;
chaithanyarss 290:3159ff1081a2 1203 frames[id][3] = (FSC_science)&0xff;
chaithanyarss 290:3159ff1081a2 1204 #endif
chaithanyarss 290:3159ff1081a2 1205
prasanthbj05 266:ae588e75cfa4 1206 temp_crc = crc16_gen(frames[id],132);
prasanthbj05 266:ae588e75cfa4 1207 frames[id][132] = temp_crc>>8;
prasanthbj05 266:ae588e75cfa4 1208 frames[id][133] = temp_crc & 0xff;
ee12b079 268:ded5306a1fd1 1209 #if scpz
ee12b079 268:ded5306a1fd1 1210 //gPC.printf("\n\rFirst head pointer contents: 0x%02X",frames[id][frames[id][4]]);
chaithanyarss 290:3159ff1081a2 1211 //gPC.printf("\n\rPrinting SCP_TM\n\r{");
chaithanyarss 290:3159ff1081a2 1212 gPC.printf("\n\r{");
ee12b079 268:ded5306a1fd1 1213 for(uint8_t z=0;z<134;z++){
chaithanyarss 290:3159ff1081a2 1214 gPC.printf("%02X",frames[id][z]);
ee12b079 268:ded5306a1fd1 1215 }
ee12b079 268:ded5306a1fd1 1216 gPC.printf("}\n\r");
ee12b079 268:ded5306a1fd1 1217 #endif
prasanthbj05 266:ae588e75cfa4 1218 exor(frames[id]);
prasanthbj05 266:ae588e75cfa4 1219 convolution(frames[id]);
prasanthbj05 266:ae588e75cfa4 1220 interleave(TM_convoluted_data,TM_interleave_data);
prasanthbj05 266:ae588e75cfa4 1221 interleave(TM_convoluted_data+ 135,TM_interleave_data + 144);
prasanthbj05 266:ae588e75cfa4 1222
ee12b079 268:ded5306a1fd1 1223 sd_stat = SD_WRITE(TM_interleave_data,FSC_science+1,1); //sd_write returns ack, for now not included
ee12b079 268:ded5306a1fd1 1224 if(sd_stat)
chaithanyarss 290:3159ff1081a2 1225 {
chaithanyarss 290:3159ff1081a2 1226 gPC.puts("sd write fail");
chaithanyarss 290:3159ff1081a2 1227 }
prasanthbj05 266:ae588e75cfa4 1228 position_tm_frame[id] = position_tm_starting[id];
ee12b079 268:ded5306a1fd1 1229 frames[id][4] = (length - j)+position_tm_starting[id];
prasanthbj05 266:ae588e75cfa4 1230 }
ee12b079 93:4d76de54a699 1231 }
ee12b079 268:ded5306a1fd1 1232 #if scpz_last
chaithanyarss 290:3159ff1081a2 1233 //gPC.printf("\n\rPrinting the last SCP_TM frame");
ee12b079 268:ded5306a1fd1 1234 //gPC.printf("\n\n\rPosition of tm_pointer: %d",position_tm_frame[id]);
ee12b079 268:ded5306a1fd1 1235 while(position_tm_frame[id]<132){
ee12b079 268:ded5306a1fd1 1236 frames[id][position_tm_frame[id]] = 0;
ee12b079 268:ded5306a1fd1 1237 position_tm_frame[id]++;
ee12b079 268:ded5306a1fd1 1238 }
chaithanyarss 290:3159ff1081a2 1239 if(position_tm_frame[id] == 132) //space full in the frame bro
chaithanyarss 290:3159ff1081a2 1240 {
chaithanyarss 290:3159ff1081a2 1241 //gPC.printf("\n\rSCP_TM frame full. Length of current SCP packet = %d",j);
ee12b079 268:ded5306a1fd1 1242 pointer = frames[id];
chaithanyarss 290:3159ff1081a2 1243 space = adjust(1,0,pointer,8);
chaithanyarss 290:3159ff1081a2 1244 space = adjust(4,1,pointer,space);
chaithanyarss 290:3159ff1081a2 1245 FSC_science = FSC_CURRENT[1];
chaithanyarss 290:3159ff1081a2 1246 //gPC.printf("1 = 0x%X",FSC_science);
chaithanyarss 290:3159ff1081a2 1247
chaithanyarss 290:3159ff1081a2 1248 #if debug_fsc
chaithanyarss 290:3159ff1081a2 1249 frames[id][1] = (FSC_science>>16)&0xff;
chaithanyarss 290:3159ff1081a2 1250 frames[id][2] = (FSC_science>>8)&0xff;
chaithanyarss 290:3159ff1081a2 1251 frames[id][3] = (FSC_science)&0xff;
chaithanyarss 290:3159ff1081a2 1252 test_fsc[1]++;
chaithanyarss 290:3159ff1081a2 1253 #endif
chaithanyarss 290:3159ff1081a2 1254 #if !debug_fsc
chaithanyarss 290:3159ff1081a2 1255 frames[id][1] = (FSC_science>>16)&0xff;
chaithanyarss 290:3159ff1081a2 1256 frames[id][2] = (FSC_science>>8)&0xff;
chaithanyarss 290:3159ff1081a2 1257 frames[id][3] = (FSC_science)&0xff;
chaithanyarss 290:3159ff1081a2 1258 #endif
chaithanyarss 290:3159ff1081a2 1259
ee12b079 268:ded5306a1fd1 1260 temp_crc = crc16_gen(frames[id],132);
ee12b079 268:ded5306a1fd1 1261 frames[id][132] = temp_crc>>8;
ee12b079 268:ded5306a1fd1 1262 frames[id][133] = temp_crc & 0xff;
chaithanyarss 290:3159ff1081a2 1263 //gPC.printf("\n\rFirst head pointer contents: 0x%02X",frames[id][frames[id][4]]);
chaithanyarss 290:3159ff1081a2 1264 //gPC.printf("\n\rPrinting SCP_TM\n\r{");
chaithanyarss 290:3159ff1081a2 1265 gPC.printf("\n\r{");
ee12b079 268:ded5306a1fd1 1266 for(uint8_t z=0;z<134;z++){
chaithanyarss 290:3159ff1081a2 1267 gPC.printf("%02X",frames[id][z]);
ee12b079 268:ded5306a1fd1 1268 }
ee12b079 268:ded5306a1fd1 1269 gPC.printf("}\n\r");
chaithanyarss 290:3159ff1081a2 1270 position_tm_frame[id] = position_tm_starting[id];
ee12b079 268:ded5306a1fd1 1271 }
chaithanyarss 290:3159ff1081a2 1272 #endif
chaithanyarss 290:3159ff1081a2 1273 gPC.printf("\n\rExiting SRP");
prasanthbj05 266:ae588e75cfa4 1274 }