Repository for CDMS code

Dependencies:   SimpleDMA mbed-rtos mbed eeprom

Fork of COM_MNG_TMTC_SIMPLE by Shreesha S

Files at this revision

API Documentation at this revision

Comitter:
ee12b079
Date:
Fri Jul 01 17:41:48 2016 +0000
Parent:
202:8700a3e6324c
Child:
204:72f52e74e0e4
Child:
205:d2ac4580960d
Commit message:
obsrs algo checked for two blocks

Changed in this revision

COM_SND_TM.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
OBSRS.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
cdms_sd.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/COM_SND_TM.h	Fri Jul 01 08:56:27 2016 +0000
+++ b/COM_SND_TM.h	Fri Jul 01 17:41:48 2016 +0000
@@ -305,7 +305,8 @@
  
          int make_shor_tm(){
             make_DataStream;
-            return type1_no;
+            int y = ( type1_no % 10 == 0 )? (type1_no / 10) : ( (type1_no / 10) + 1);
+            return y;
         }
         void inline transmit_data(unsigned char * transmit , bool * last_buffer){
             if(transmit_data_f){
--- a/Compression.h	Fri Jul 01 08:56:27 2016 +0000
+++ b/Compression.h	Fri Jul 01 17:41:48 2016 +0000
@@ -56,7 +56,8 @@
 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;   
+int proton_scp_sum,electron_scp_sum,length, temp_crc,attitude = 0,debug_cntr = 0, size,space;
+uint32_t FSC_science;   
 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;
@@ -77,17 +78,8 @@
     
     //Call FCTN_SD_MNGR for latest fsc
     FCTN_SD_MNGR();
-    uint32_t FSC[6];
     uint8_t sd_stat;
     
-    for(int i =1; i<6;i++)
-    {
-        FSC[i] = FSC_CURRENT[i];
-    }
-    
-    
-    
-    
     for (int i = 0; i < 52 ; i++){
         scp_bin[i] = 0;
     }
@@ -299,8 +291,8 @@
                 if(id == 1){    //below thereshold
                     space = adjust(1,0,pointer,8);
                     space = adjust(4,3,pointer,space);
-                    FSC[3]++;
-                    gPC.printf("SID = 3, FSC = %02X\r\n", FSC[3]);
+                    FSC_science = FSC_CURRENT[3]+1;
+                    gPC.printf("SID = 3, FSC = %02X\r\n", FSC_CURRENT[3]+1);
                     frames[id][1] = (FSC_science>>24)&0xff;
                     frames[id][2] = (FSC_science>>16)&0xff;
                     frames[id][3] = (FSC_science>>8)&0xff;
@@ -313,9 +305,8 @@
                 }else if(id == 2){
                     space = adjust(1,0,pointer,8);
                     space = adjust(4,2,pointer,space);
-                    //FSC_science = FCTN_SD_MNGR(2);
-                    FSC[2]++;
-                    gPC.printf("SID = 2, FSC = %02X\r\n", FSC[2]);
+                    FSC_science = FSC_CURRENT[2]+1;
+                    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;
@@ -338,10 +329,10 @@
                 interleave(TM_convoluted_data+ 135,TM_interleave_data + 144);
                 
                 if(id == 1){
-                    sd_stat = SD_WRITE(TM_interleave_data,FSC[3],3);
+                    sd_stat = SD_WRITE(TM_interleave_data,FSC_CURRENT[3]+1,3);
                    }
                 else if (id == 2){
-                    sd_stat = SD_WRITE(TM_interleave_data,FSC[2],2);
+                    sd_stat = SD_WRITE(TM_interleave_data,FSC_CURRENT[2]+1,2);
                   }
                 if(sd_stat)
                 {
@@ -602,8 +593,8 @@
                 pointer = frames[id];
                 space = adjust(1,0,pointer,8);
                 space = adjust(4,1,pointer,space);
-                FSC[1]++;
-                gPC.printf("SID = 1, FSC = %02X\r\n", FSC[1]);
+                FSC_science = FSC_CURRENT[1]+1;
+                gPC.printf("SID = 1, 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;
@@ -622,7 +613,7 @@
                 convolution(frames[id]);
                 interleave(TM_convoluted_data,TM_interleave_data);
                 interleave(TM_convoluted_data+ 135,TM_interleave_data + 144);
-                sd_stat = SD_WRITE(TM_interleave_data,FSC[1],1);
+                sd_stat = SD_WRITE(TM_interleave_data,FSC_CURRENT[1]+1,1);
                 if(sd_stat)
                 {
                     gPC.puts("sd write failure");
--- a/OBSRS.h	Fri Jul 01 08:56:27 2016 +0000
+++ b/OBSRS.h	Fri Jul 01 17:41:48 2016 +0000
@@ -175,7 +175,6 @@
             buffer_112[counter_buffer_112] = SCH40[counter_SCH40++];\
             if (counter_SCH40 == 5)\
             {   \
-                /*gPC.printf("Asch40 sent\r\n");*/\
                 counter_SCH40 = 0;\
                 enable_SCH = false;\
                 enable_DS = true;\
@@ -215,7 +214,6 @@
             T_frames_sent = T_frames_sent +2;\
             if(repeat_last_2T_frames){\
                 enable_SCH = true;\
-                /*gPC.printf("repeated last 2 tframes\r\n");*/\
                 /*cout<<"T_frames_sent = "<<T_frames_sent<<ENDL;*/\
             }\
             else{\
@@ -224,10 +222,8 @@
                 T_frame_Ack_andcallsign_sent = T_frame_Ack_andcallsign_sent + 2;\
                 if(T_frame_Ack_andcallsign_sent == T_frame_in_Ackandcallsign ){\
                     repeat_last_2T_frames = true;\
-                }\
-                else if(T_frame_Ack_andcallsign_sent < T_frame_in_Ackandcallsign){\
-                    T_frame_in_Ackandcallsign = 2*snd_tm.make_shor_tm();\
-                    enable_SCH = true;\
+                    for(int i =0; i<144;i++)\
+                    {interleave_data[0][i] = 0;interleave_data[1][i] = 0; }\
                 }\
                 else{\
                     gPC.printf("error in send ack\r\n");\
@@ -235,15 +231,7 @@
             }\
             if(T_frames_sent == T_frames_in_segment){\
                 if(T_frame_Ack_andcallsign_sent < T_frame_in_Ackandcallsign){\
-                    if(segments_sent + 1>= max_segments){\
-                        adf_limit = true;\
-                        segments_sent = 0;\
-                        gPC.printf("adf limit reached");\
-                    }\
-                    else{\
-                        enable_new_segment = true;\
-                        gPC.printf("new segment");\
-                    }\
+                        gPC.printf("error in tframes sent = in seg");\
                 }\
                 else{\
                     send_EoS_and_stop = true; \
@@ -525,7 +513,7 @@
                 }
                 get_call_sign(ack_and_callsign->next_TM);
                 snd_tm.head_pointer_sdcard(ack_head);
-                T_frame_in_Ackandcallsign = 2*snd_tm.make_shor_tm();
+                T_frame_in_Ackandcallsign = (2*snd_tm.make_shor_tm());
 /*                gPC.printf(" T_frame_in_Ackandcallsign = %d\r\n",T_frame_in_Ackandcallsign);*/
                 Base_tm *ack_l234 = ack_and_callsign->next_TM;
                 
@@ -594,9 +582,8 @@
 //                        }
                    //int write_success = SD_WRITE(write_buffer,FSC + block_counter,SID);
 //                   wait_ms(8);
-                   //ack_code = SD_READ(buffer_512, FSC + block_counter,SID);
-/*                   gPC.printf("read block %d \n\r",read_success);*/
-                    ack_code = 0x02;
+                   ack_code = SD_READ(buffer_512, FSC + block_counter,SID);
+                    //ack_code = 0x02;
                }
                else{
                    ack_code = SD_READ(buffer_512, list_of_FSC[block_counter],SID);
@@ -621,7 +608,7 @@
                     enable_T_frame = false;
                 }
                 else if(ack_code == 0x86){
-                    gPC.printf("FSC outof bounds");
+                    /*gPC.printf("FSC outof bounds");*/
                     enable_T_frame = false;
                 }
                 else{
--- a/adf.h	Fri Jul 01 08:56:27 2016 +0000
+++ b/adf.h	Fri Jul 01 17:41:48 2016 +0000
@@ -214,22 +214,22 @@
         spi.write(0x18);\
         spi.write(0x20);\
         for(unsigned char i=0; i<112;i++){\
-            if(bypass_adf);\
-                /*gPC.putc(buffer_112[i]);*/\
+            if(bypass_adf)\
+                gPC.putc(buffer_112[i]);\
             else\
                 spi.write(buffer_112[i]);\
-            gPC.printf("%02X",buffer_112[i]);\
+            /*gPC.printf("%02X",buffer_112[i])*/;\
         }\
     }\
     else{\
         spi.write(0x18);\
         spi.write(0x90);\
         for(unsigned char i=0; i<112;i++){\
-            if(bypass_adf);\
-                /*gPC.putc(buffer_112[i]);*/\
+            if(bypass_adf)\
+                gPC.putc(buffer_112[i]);\
             else\
                 spi.write(buffer_112[i]);\
-            gPC.printf("%02X",buffer_112[i]);\
+            /*gPC.printf("%02X",buffer_112[i])*/;\
         }\
     }\
     gCS_ADF=1;\
--- a/cdms_sd.h	Fri Jul 01 08:56:27 2016 +0000
+++ b/cdms_sd.h	Fri Jul 01 17:41:48 2016 +0000
@@ -126,11 +126,13 @@
     uint32_t fsc;
     uint32_t start_fsc;
     uint8_t buffer[512];
+    int i;
     disk_read(buffer,SD_MNG_SECT);
     if(sid==0x01)
     {
         fsc=(uint32_t)(buffer[0]<<24)+(uint32_t)(buffer[1]<<16)+(uint32_t)(buffer[2]<<8)+(uint32_t)buffer[3];
         start_fsc=(uint32_t)(buffer[4]<<24)+(uint32_t)(buffer[5]<<16)+(uint32_t)(buffer[6]<<8)+(uint32_t)buffer[7];
+        fsc++;
         buffer[0]=(uint8_t) (fsc>>24 & 0xFF);
         buffer[1]=(uint8_t) (fsc>>16 & 0xFF);
         buffer[2]=(uint8_t) (fsc>>8 & 0xFF);
@@ -143,12 +145,15 @@
             buffer[6]=(uint8_t) (start_fsc>>8 & 0xFF);
             buffer[7]=(uint8_t) (start_fsc & 0xFF);
         }
-        return disk_write(buffer,SD_MNG_SECT);
+        i = disk_write(buffer,SD_MNG_SECT);
+        FCTN_SD_MNGR();
+        return i;
     }
     if(sid==0x02)
     {
         fsc=(uint32_t)(buffer[8]<<24)+(uint32_t)(buffer[9]<<16)+(uint32_t)(buffer[10]<<8)+(uint32_t)buffer[11];
         start_fsc=(uint32_t)(buffer[12]<<24)+(uint32_t)(buffer[13]<<16)+(uint32_t)(buffer[14]<<8)+(uint32_t)buffer[15];
+        fsc++;
         buffer[8]=(uint8_t) (fsc>>24 & 0xFF);
         buffer[9]=(uint8_t) (fsc>>16 & 0xFF);
         buffer[10]=(uint8_t) (fsc>>8 & 0xFF);
@@ -161,12 +166,15 @@
             buffer[14]=(uint8_t) (start_fsc>>8 & 0xFF);
             buffer[15]=(uint8_t) (start_fsc & 0xFF);
         }
-        return disk_write(buffer,SD_MNG_SECT);
+        i = disk_write(buffer,SD_MNG_SECT);
+        FCTN_SD_MNGR();
+        return i;
     }
     if(sid==0x03)
     {
         fsc=(uint32_t)(buffer[16]<<24)+(uint32_t)(buffer[17]<<16)+(uint32_t)(buffer[18]<<8)+(uint32_t)buffer[19];
         start_fsc=(uint32_t)(buffer[20]<<24)+(uint32_t)(buffer[21]<<16)+(uint32_t)(buffer[22]<<8)+(uint32_t)buffer[23];
+        fsc++;
         buffer[16]=(uint8_t) (fsc>>24 & 0xFF);
         buffer[17]=(uint8_t) (fsc>>16 & 0xFF);
         buffer[18]=(uint8_t) (fsc>>8 & 0xFF);
@@ -179,12 +187,15 @@
             buffer[22]=(uint8_t) (start_fsc>>8 & 0xFF);
             buffer[23]=(uint8_t) (start_fsc & 0xFF);
         }
-        return disk_write(buffer,SD_MNG_SECT);
+        i = disk_write(buffer,SD_MNG_SECT);
+        FCTN_SD_MNGR();
+        return i;
     }
      if(sid==0x04)
     {
         fsc=(uint32_t)(buffer[24]<<24)+(uint32_t)(buffer[25]<<16)+(uint32_t)(buffer[26]<<8)+(uint32_t)buffer[27];
         start_fsc=(uint32_t)(buffer[28]<<24)+(uint32_t)(buffer[29]<<16)+(uint32_t)(buffer[30]<<8)+(uint32_t)buffer[31];
+        fsc++;
         buffer[24]=(uint8_t) (fsc>>24 & 0xFF);
         buffer[25]=(uint8_t) (fsc>>16 & 0xFF);
         buffer[26]=(uint8_t) (fsc>>8 & 0xFF);
@@ -197,12 +208,15 @@
             buffer[30]=(uint8_t) (start_fsc>>8 & 0xFF);
             buffer[31]=(uint8_t) (start_fsc & 0xFF);
         }
-        return disk_write(buffer,SD_MNG_SECT);
+        i = disk_write(buffer,SD_MNG_SECT);
+        FCTN_SD_MNGR();
+        return i;
     }
      if(sid==0x05)
     {
         fsc=(uint32_t)(buffer[32]<<24)+(uint32_t)(buffer[33]<<16)+(uint32_t)(buffer[34]<<8)+(uint32_t)buffer[35];
         start_fsc=(uint32_t)(buffer[36]<<24)+(uint32_t)(buffer[37]<<16)+(uint32_t)(buffer[38]<<8)+(uint32_t)buffer[39];
+        fsc++;
         buffer[32]=(uint8_t) (fsc>>24 & 0xFF);
         buffer[33]=(uint8_t) (fsc>>16 & 0xFF);
         buffer[34]=(uint8_t) (fsc>>8 & 0xFF);
@@ -215,7 +229,9 @@
             buffer[38]=(uint8_t) (start_fsc>>8 & 0xFF);
             buffer[39]=(uint8_t) (start_fsc & 0xFF);
         }
-        return disk_write(buffer,SD_MNG_SECT);
+        i = disk_write(buffer,SD_MNG_SECT);
+        FCTN_SD_MNGR();
+        return i;
     }
     return -1;
 }
--- a/main.cpp	Fri Jul 01 08:56:27 2016 +0000
+++ b/main.cpp	Fri Jul 01 17:41:48 2016 +0000
@@ -102,7 +102,7 @@
     
     // DEBUG
     //gPC.puts("welcome to mng_tm_tc\r\n");
-    gPC.baud(9600);//changed for bypassing COM
+    gPC.baud(115200);//changed for bypassing COM
     
     // COMMON SPI
     spi.format(8,0);
@@ -114,11 +114,73 @@
     gCS_ADF = 1;
     
     FCTN_CDMS_INIT_RTC();/* rtc initialization*/
-    //FCTN_CDMS_SD_INIT();/* sd card initialization*/
+    FCTN_CDMS_SD_INIT();/* sd card initialization*/
     
     
     uint8_t test[512] = {0};
     disk_write(test,7000); //to be used only just before launch
+    uint8_t data[512];
+    for(int i=0;i<512;i++)
+        data[i] = i%100;
+    for(int i=0;i<512;i++)
+        test[i] = 1;
+    FCTN_SD_MNGR();//this should give the last fscs written : FSC_CURRENT 
+    gPC.printf("\r fsc_curr = %d\n",FSC_CURRENT[2]);
+    if(SD_WRITE(data,FSC_CURRENT[2]+1,2) == 0)//
+    {
+        gPC.printf("\r fsc_curr = %d\n",FSC_CURRENT[2]);
+        int j = SD_READ(test,FSC_CURRENT[2],2);
+        for(int i=0;i<15;i++)
+        {
+            gPC.printf("\r0x%02X 0x%02X %d %d\n",data[i],test[i],j,FSC_CURRENT[2]);
+        }
+    }
+    
+    if(SD_WRITE(data,FSC_CURRENT[2]+1,2) == 0)
+    {
+        int j = SD_READ(test,FSC_CURRENT[2],2);
+        for(int i=0;i<15;i++)
+        {
+            gPC.printf("\r0x%02X 0x%02X %d %d\n",data[i],test[i],j,FSC_CURRENT[2]);
+        }
+    }
+    gPC.printf("\r fsc_curr = %d\n",FSC_CURRENT[2]);
+    if(SD_WRITE(data,FSC_CURRENT[2]+1,2) == 0)
+    {
+        gPC.printf("\r fsc_curr = %d\n",FSC_CURRENT[2]);
+        int j = SD_READ(test,FSC_CURRENT[2],2);
+        gPC.printf("\r fsc_curr = %d\n",FSC_CURRENT[2]);
+        for(int i=0;i<15;i++)
+        {
+            gPC.printf("\r0x%02X 0x%02X %d %d\n",data[i],test[i],j,FSC_CURRENT[2]);
+        }
+    }
+    
+    
+    gPC.printf("\r fsc_curr = %d\n",FSC_CURRENT[1]);
+    if(SD_WRITE(data,FSC_CURRENT[1]+1,1) == 0)
+    {
+        gPC.printf("\r fsc_curr = %d\n",FSC_CURRENT[1]);
+        int j = SD_READ(test,FSC_CURRENT[1],1);
+        gPC.printf("\r fsc_curr = %d\n",FSC_CURRENT[1]);
+        for(int i=0;i<15;i++)
+        {
+            gPC.printf("\r0x%02X 0x%02X %d %d\n",data[i],test[i],j,FSC_CURRENT[1]);
+        }
+    }
+    
+    gPC.printf("\r fsc_curr = %d\n",FSC_CURRENT[2]);
+    if(SD_WRITE(data,FSC_CURRENT[2]+1,2) == 0)
+    {
+        gPC.printf("\r fsc_curr = %d\n",FSC_CURRENT[2]);
+        int j = SD_READ(test,FSC_CURRENT[2],2);
+        gPC.printf("\r fsc_curr = %d\n",FSC_CURRENT[2]);
+        for(int i=0;i<15;i++)
+        {
+            gPC.printf("\r0x%02X 0x%02X %d %d\n",data[i],test[i],j,FSC_CURRENT[2]);
+        }
+    }
+    
     
     
     #if DEBUG
@@ -144,6 +206,10 @@
     master.frequency(400000);
     PL_wo_dma = new RtosTimer(payload_isr_fun_dma, osTimerPeriodic,(void * )NULL);
     //PL_wo_dma->start(6000);//
+    //gSCIENCE_THREAD->signal_set(SCIENCE_SIGNAL);
+    
+    
+    
     
     gPC.printf("PL_TC sending\r\n");