Simple version of COM_MNG_TMTC_CODE for IITMSAT.

Dependencies:   mbed-rtos mbed FreescaleIAP SimpleDMA

Revision:
171:31bdf83591a1
Parent:
114:9fb55057b13f
Child:
174:44a6d7c7674c
--- a/Compression.h	Tue Apr 19 23:00:31 2016 +0000
+++ b/Compression.h	Wed Apr 20 12:58:58 2016 +0000
@@ -1,10 +1,10 @@
-unsigned int read_2byte(unsigned char* ptr){
+unsigned int read_2byte(uint8_t* ptr){
     unsigned int output = (unsigned int) *(ptr+1);
     output += ( (unsigned int)(*ptr) ) << 8;
     return output;
 }
     
-unsigned int read_4byte(unsigned char* ptr){
+unsigned int read_4byte(uint8_t* ptr){
     unsigned int output = (unsigned int) *(ptr+3);
     output += (unsigned int)*(ptr+2)<<8;
     output += (unsigned int)*(ptr+1)<<16;
@@ -12,8 +12,9 @@
     return output;
 }
 
-int adjust(int size, unsigned int data, unsigned char* ptr , int space){
+int adjust(int size, unsigned int data, uint8_t* ptr , int space){
     space = space&0x0f;
+    if(space == 8)  *ptr = 0;
     data = data&((1<<size)-1);
     if(space >= size){
         *ptr += data<<(space-size);
@@ -45,29 +46,29 @@
 
 
 //variable declerations
-unsigned char srp_mode , at , pzf , ezf ,sfp[65] ,scp[55];; //tells which mode is calibrated or plot 0 for calibrated and 1 for scatterered, below threshold , proton zero flux, electron zero flux.
+uint8_t srp_mode , at , pzf , ezf ,sfp[65] ,scp[55];; //tells which mode is calibrated or plot 0 for calibrated and 1 for scatterered, below threshold , proton zero flux, electron zero flux.
 unsigned int sfp_bin[52] , scp_bin[52];         //storing the bin values.
 unsigned int sfp_threshold_m0[52] = {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,4032,4032,124,124,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,252,252,252,252,252}; 
 const unsigned int scp_threshold_m0[52] = {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,114688,114688,4032,4032,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,1984,8128,4032,4032,4032,4032};
 unsigned int scp_threshold_m0_1[9]={114688,245760,245760,245760,245760,114688,114688,65472,65472} ; //for mode 0..ie callibrated mode
 const unsigned int sfp_threshold_m1[2] ={252,8128},scp_threshold_m1[2]={7680,245760};
-unsigned char frames[3][134] = {0};
-unsigned char position_tm_frame[3] = {8,11,5} , position_tm_starting[3] = {8,11,5}; //{sc,sf-bt,sf-at}
-unsigned char id;   //sf = 0,sc-at = 1,sc-bt = 2;
-unsigned char TM_interleave_data[512] , TM_convoluted_data[270] = {0};
+uint8_t frames[3][134] = {0};
+uint8_t position_tm_frame[3] = {8,11,5} , position_tm_starting[3] = {8,11,5}; //{sc,sf-bt,sf-at}
+uint8_t id;   //sf = 0,sc-at = 1,sc-bt = 2;
+uint8_t TM_interleave_data[512] , TM_convoluted_data[270] = {0};
 int proton_scp_sum,electron_scp_sum,length, temp_crc,attitude = 0,FSC_science = 1,debug_cntr = 0, size,space;   
-unsigned char *ptr ,* pointer;
+uint8_t *ptr ,* pointer;
 long long int sci_time = 0x221000000;       //call some function and get the time or get in the starting, what ever akshay says
 int test_cntr = 0;
 
     Convolution ConvObj;
-    void convolution (unsigned char * ptr){
+    void convolution (uint8_t * ptr){
         ConvObj.convolutionEncode(ptr, TM_convoluted_data);
         ConvObj.convolutionEncode(ptr + 67, TM_convoluted_data + 135);
     }
 
 //give the pointer of 6 second data to this function
-void srp(unsigned char * head){
+void srp(uint8_t * head){
     //sci_time = FCTN_CDMS_RD_RTC();
     sci_time = 0;
     gPC.puts("enter srp");
@@ -79,6 +80,9 @@
     srp_mode = head[2]&0x1;
     at = 0;     //above threshold is false
     for(int counter = 0 ; counter < 60 ; counter++){
+        gPC.puts("Y");
+//        gPC.printf("counter = %d\n",counter);
+//        cout<<"counter = "<<counter<<endl;
         pzf = 1;    ezf = 1;
         if(srp_mode == 0){      //calibrated mode
             for(int i=0; i<48 ; i++){
@@ -294,9 +298,9 @@
                 }else if(id == 2){
                     space = adjust(1,0,pointer,8);
                     space = adjust(4,2,pointer,space);
-//                    FSC_science = FCTN_SD_MNGR(2);
+                    FSC_science = FCTN_SD_MNGR(2);
                     
-                    //gPC.printf("SID = 2, FSC = %02X\r\n", FSC_science);
+                    gPC.printf("SID = 2, FSC = %02X\r\n", FSC_science);
                     frames[id][1] = (FSC_science>>16)&0xff;
                     frames[id][2] = (FSC_science>>8)&0xff;
                     frames[id][3] = FSC_science&0xff;
@@ -304,24 +308,30 @@
                 temp_crc = crc16_gen(frames[id],132);
                 frames[id][132] = temp_crc>>8;
                 frames[id][133] = temp_crc & 0xff;
-                if(test_cntr++ == 0){
-                    gPC.puts("frame start\r\n");
-                    for(int i = 0; i<134; i++){
-                        gPC.printf("%02X",frames[id][i]);
-                    }    
-                    gPC.puts("frame ends\r\n");
-                }
+              //  if(test_cntr++ == 0){
+//                    gPC.puts("frame start\r\n");
+//                    for(int i = 0; i<134; i++){
+//                        gPC.printf("%02X",frames[id][i]);
+//                    }    
+//                    gPC.puts("frame ends\r\n");
+//                }
+                   
+                
                 exor(frames[id]);
                 convolution(frames[id]);
                 interleave(TM_convoluted_data,TM_interleave_data);
                 interleave(TM_convoluted_data+ 135,TM_interleave_data + 144);
-                if(id == 1)
+                
+                if(id == 1){
                     SD_WRITE(TM_interleave_data,FSC_science,3);
-                else if (id == 2)
+                   }
+                else if (id == 2){
                     SD_WRITE(TM_interleave_data,FSC_science,2);
+                  }
                 FSC_science++;      //remove this after testing
                 position_tm_frame[id] = position_tm_starting[id];
                 frames[id][6-id] = (length-1) - j;      // first head pointer.
+                
             }
         }
         
@@ -330,7 +340,7 @@
     //---------------below is scp --------------**************************************************************************************************
     at = 0;     pzf = 1;    ezf = 1;
     srp_mode = head[2]&0x1;
-    unsigned char compression_option = (head[2]>>1)&0x3;    //--------------------------------------------------------------------------------------
+    uint8_t compression_option = (head[2]>>1)&0x3;    //--------------------------------------------------------------------------------------
     if(srp_mode ==0){
         if(compression_option == 0){
             for(int i=0; i<52 ;i++){
@@ -388,7 +398,7 @@
     gPC.puts("scp\r\n");
     
     pointer = scp;      debug_cntr = 0;     space = 8;
-    unsigned char packet_pp = 1;    //where to get this packet present bit----------------------------------------------------------------------------------
+    uint8_t packet_pp = 1;    //where to get this packet present bit----------------------------------------------------------------------------------
     int sfp_at_counter; //----------------------------------------------------------------------------------------------------------------------------------
     space = adjust(1, packet_pp,pointer,space);     pointer += space>>4;    debug_cntr += space>>4;
     space = adjust(5, (sci_time>>8)&0x1f,pointer,space);        pointer += space>>4;    debug_cntr += space>>4;