June 30

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE by shubham c

Files at this revision

API Documentation at this revision

Comitter:
ee12b079
Date:
Wed Apr 20 12:58:58 2016 +0000
Parent:
170:286ef9dad36a
Child:
172:c508bbf7e89a
Commit message:
Testing OBSRS TC

Changed in this revision

COM_MNG_TMTC.h Show annotated file Show diff for this revision Revisions of this file
Compression.h Show annotated file Show diff for this revision Revisions of this file
DefinitionsAndGlobals.h Show annotated file Show diff for this revision Revisions of this file
adf.h Show annotated file Show diff for this revision Revisions of this file
i2c.h Show annotated file Show diff for this revision Revisions of this file
--- a/COM_MNG_TMTC.h	Tue Apr 19 23:00:31 2016 +0000
+++ b/COM_MNG_TMTC.h	Wed Apr 20 12:58:58 2016 +0000
@@ -783,7 +783,7 @@
             #if DEBUG
             printf("Telecommand is for PL\r\n");
             #endif
-
+            received = 0;
 
             if(GETservice_subtype(tc_ptr) == 0xD0 || GETservice_subtype(tc_ptr) == 0xD2 || GETservice_subtype(tc_ptr) == 0xD3)
             {
@@ -803,14 +803,38 @@
             
             while(1)
             {
+                wait(1);
                 if(rcv_isr == 1)
                 {
                     //gPC.printf("i2c_t = %d",t_pl.read_ms());  
                         for(int i = 0;i< PL_TM_SIZE;i++)
                         tm_pointer->TM_string[i] = PL_I2C_DATA[i];
+                        received++;
                         rcv_isr = 0; 
                         break;
                 }
+                else
+                {
+                    gPC.printf("\n\rData received from PL \n");
+                    break;
+                    }
+            }
+            if(received < 1 )
+            {
+                //printf("Telemetry is not received from BAE\r\n");
+                //tm_pointer = new Short_tm;
+                tm_pointer->TM_string[0] = 0xB0;
+                tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);
+                tm_pointer->TM_string[2] = 0x00;
+                tm_pointer->TM_string[3] = 0x00; //ackcode to be decided
+                tm_pointer->TM_string[4] = 0x00;
+                for(uint8_t i=0;i<6;i++)
+                {
+                    tm_pointer->TM_string[i+5] = 0;
+                }
+                crc16 = crc16_gen(tm_ptr->TM_string,11);
+                tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
+                tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
             }
             tm_pointer->next_TM = NULL;                 return tm_ptr;          
             break;
@@ -1213,7 +1237,7 @@
                             /*SEND call sign, ACK_L1, NON OBSRS TM TO GS*/\
                             snd_tm.head_pointer(tm_ptr_head);\
                             gPC.puts("enter_adf\r\n");\
-                            transmit_adf;\
+                            /*transmit_adf;*/\
                             gPC.puts("exit_adf\r\n");\ 
                             /*DELETE THE TM AFTER USE*/\
                             tm_ptr = tm_ptr_head;\
@@ -1240,7 +1264,9 @@
                             /*execute_obsrs(current_TC, put_tm_here)*/\
                             /*read_TC(current_TC);*/\
                             execute_OBSRS_TC(current_TC);\
-                            transmit_adf;\
+                            gPC.puts("enter_adf\r\n");\
+                            /*transmit_adf;*/\
+                            gPC.puts("exit_adf\r\n");\
                             uint8_t tempExec = TC_STATE_SUCCESSFULLY_EXECUTED;\
                             PUTexec_status(current_TC, tempExec);\
                             /*PENDING: ABORT ON NACK CHECK, gMASTER_STATE VERIFICATION WITH SD CARD, session timeout, last executed ack l234*/\
--- 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;
--- a/DefinitionsAndGlobals.h	Tue Apr 19 23:00:31 2016 +0000
+++ b/DefinitionsAndGlobals.h	Wed Apr 20 12:58:58 2016 +0000
@@ -28,7 +28,7 @@
     
 //I2C - Payload to CDMS (need to change while using CDMS hardware);
 I2C master(PIN32,PIN31);
-InterruptIn PYLD_I2C_Int(PTA13);
+InterruptIn PYLD_I2C_Int(PTC13);
 
 //I2C - CDMS to BAE
 DigitalIn BAE_I2C_GPIO(PIN39);
--- a/adf.h	Tue Apr 19 23:00:31 2016 +0000
+++ b/adf.h	Wed Apr 20 12:58:58 2016 +0000
@@ -1,5 +1,5 @@
 //without reset feature , with state checks.
-InterruptIn IRQ(ADF_IRQ);
+DigitalIn IRQ(ADF_IRQ);
 //Ticker ticker;
  
 bool loop_on;
@@ -108,11 +108,11 @@
         else{\
             hardware_reset(0);\
             hw_reset_err_cnt++;\
-            /*gPC.puts("Resetting hardware\r\n");*/\
+            gPC.puts("Resetting hardware\r\n");\
         }\
     }\
     if( flag == false ){\
-        /*gPC.puts("Seems to be SPI problem\r\n");*/\
+        gPC.puts("Seems to be SPI problem\r\n");\
     }\
     assrt_phy_off(tempReturn);\
     if(!bbram_flag){\
@@ -295,9 +295,9 @@
     loop_on = true;\
     ADF_off = false;\
     initial_adf_check;\
-    /*gPC.puts("initial adf check\r\n");*/\
+    gPC.puts("initial adf check\r\n");\
     initiate;\
-    /*gPC.puts("adf configured\r\n");*/\
+    gPC.puts("adf configured\r\n");\
     /*gLEDR = !gLEDR;*/\
 }
  
--- a/i2c.h	Tue Apr 19 23:00:31 2016 +0000
+++ b/i2c.h	Wed Apr 20 12:58:58 2016 +0000
@@ -17,6 +17,8 @@
 void FCTN_I2C_WRITE_PL(char *data2,uint8_t tc_len2)
 {
     write_ack = master.write(addr_pl|0x00,data2,tc_len2);//address to be defined in payload
+    if(write_ack == 0)
+        {gPC.printf("\n\rData sent to PL \n");}
     if(write_ack == 1)
     {
         gPC.printf("\n\rdata not sent\n");