sd 32 update

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of COM_MNG_TMTC_SIMPLE by Shreesha S

Revision:
35:3beac900a034
Parent:
34:f0b518523381
Child:
36:d1424f871de1
Child:
39:a41468817921
Child:
41:7e06018f6a1c
Child:
47:5660bd20b146
--- a/COM_MNG_TMTC.h	Wed Jan 06 21:23:42 2016 +0000
+++ b/COM_MNG_TMTC.h	Thu Jan 07 10:35:40 2016 +0000
@@ -6,6 +6,30 @@
 // Jun 6
 // WHAT IS TC exec code in L1 ack ? 
 
+//Jan 7 
+//added RLY_TMTC function
+//added included related files
+
+#include "pinconfig.h"
+#include "i2c.h"
+#include "Flash.h"
+#include "cdms_rtc.h"
+
+DigitalIn tm_status_4m_slv(PIN39); //I2C interrupt to CDMS from BAE
+//DigitalIn tm_status_4m_pl(PIN61); //I2C interrupt to CDMS from PL
+
+uint8_t received = 0;
+uint16_t mid1;
+uint16_t mid2;
+uint16_t Nbytes;
+uint32_t Data[2];
+uint16_t nbytes;
+uint8_t flash_counter = 0;
+uint16_t crc16;
+uint16_t mid;
+uint32_t block;
+
+
 #define delete_TC(tc_ptr) {\
     if(tc_ptr == gHEAD_NODE_TCL){\
         gHEAD_NODE_TCL = tc_ptr->next_TC;\
@@ -398,9 +422,637 @@
 }
 
 // CDMS TEAM CODE START
-#define CDMS_RLY_TMTC(tc_ptr, tm_ptr){\
-    tm_ptr = NULL;\
-}\
+inline Base_tm* FCTN_CDMS_RLY_TMTC(Base_tc *tc_ptr){
+    uint8_t ACKCODE = 0x00;
+    printf("\rTC execution in progress\r\n");
+    Base_tm *tm_ptr = new Long_tm;
+    Base_tm *tm_pointer = tm_ptr;
+    received = 0;
+    switch(GETapid(tc_ptr))
+    {
+        case 1: //apid=01 implies it corresponds to bae
+        {
+            printf("Telecommand is for BAE\r\n");
+            printf("Sending TC to BAE...\r\n"); //interrupt to be sent to the bae
+            FCTN_I2C_WRITE((char*)tc_ptr->TC_string);
+            while(1)
+            {
+                wait(1); //TimeOut instead of wait
+                if(tm_status_4m_slv == 1)
+                {
+                    printf("receiving...\r\n");
+                    FCTN_I2C_READ((char*)tm_pointer->TM_string);
+                    //printf("%s", tm_pointer->TM_string);
+                    received+=1;
+                    tm_pointer = tm_pointer->next_TM;
+                    break; //only for testing purpose
+                }
+                else
+                {
+                    break;
+                }
+            }
+            if(received >= 1 )
+            {
+                printf("Telemetry is received from BAE\r\n");
+                Base_tm *tm_print = tm_ptr;
+                for(uint8_t i=0;i<received;i++)
+                {  
+                    printf("%s", tm_print->TM_string);
+                    tm_print = tm_print->next_TM; //for check
+                }
+                received  = 0;
+                return tm_ptr;
+            }
+            else
+            {
+                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] = 0x01;
+                tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided
+                tm_pointer->TM_string[4] = 0x01;
+                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);
+                return tm_ptr;
+            }
+            break;
+        }
+        case 2:
+        {
+            printf("Telecommand is for CDMS\r\n"); //apid = 10 corresponds to cdms
+            switch(GETservice_type(tc_ptr))
+            {
+                case 0x60:
+                {
+                        printf("service:MMS\r\n");
+                        switch(GETservice_subtype(tc_ptr))
+                        {
+                            case 0x1:
+                            {
+                            printf("sub_service:Read from RAM_Memory\r\n");
+                            mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]);                                                       
+                            {                                 
+                                    Data[0] = FCTN_CDMS_RD_FLASH(0);
+                                    Data[1] = FCTN_CDMS_RD_FLASH(1);
+                                    tm_pointer = new Long_tm;
+                                    tm_pointer->TM_string[0] = 0x30;
+                                    tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);
+                                    tm_pointer->TM_string[2] = (uint8_t)(flash_counter);
+                                    for(uint8_t i=0;i<4;i++)
+                                    {
+                                        tm_pointer->TM_string[3+i] = (uint8_t)((Data[0]>>(8*i))&0x00FF);
+                                    }
+                                    for(uint8_t i=4;i<8;i++)
+                                    {
+                                        tm_pointer->TM_string[3+i] = (uint8_t)((Data[1]>>(8*i))&0x00FF);
+                                    }
+                                    crc16 = crc16_gen(tm_ptr->TM_string,9);
+                                    tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
+                                    tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
+                                return tm_ptr;
+                            }                            
+                            case 0x2:
+                            {
+                            printf("sub_service:Read from Flash_Memory\r\n");
+                            mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]);                           
+                            {                                                                 
+                                    Data[0] = FCTN_CDMS_RD_FLASH(0);
+                                    Data[1] = FCTN_CDMS_RD_FLASH(1);                                                                                             
+                                    tm_pointer = new Long_tm;
+                                    tm_pointer->TM_string[0] = 0x30;
+                                    tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);
+                                    tm_pointer->TM_string[2] = (uint8_t)(flash_counter);
+                                    for(uint8_t i=0;i<4;i++)
+                                    {
+                                        tm_pointer->TM_string[3+i] = (uint8_t)((Data[0]>>(8*i))&0x00FF);
+                                    }
+                                    for(uint8_t i=4;i<8;i++)
+                                    {
+                                        tm_pointer->TM_string[3+i] = (uint8_t)((Data[1]>>(8*i))&0x00FF);
+                                    }
+                                    crc16 = crc16_gen(tm_ptr->TM_string,9);
+                                    tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
+                                    tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
+                                return tm_ptr;
+                            }                           
+                            case 0x5:
+                            {
+                            printf("WRITE ON FLASH_MEMORY\r\n");                          
+                                    mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]);                                   
+                                    block = (((uint32_t)(tc_ptr->TC_string[5])<<24)|((uint32_t)(tc_ptr->TC_string[5])<<16)|((uint32_t)(tc_ptr->TC_string[5])<<8)|((uint32_t)(tc_ptr->TC_string[5])));
+                                    FCTN_CDMS_WR_FLASH(mid,block);
+                                    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] = 0x01;
+                                    tm_pointer->TM_string[3] = ACKCODE;  //ackcode to be decided
+                                    tm_pointer->TM_string[4] = 0x01;
+                                    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);
+                                    return tm_ptr;
+                                    break;
+                            }                                                    
+                            default:
+                            {
+                                printf("INVALID TC\r\n"); //Send Invalid TC Telemetry
+                                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] = 0x01;
+                                tm_pointer->TM_string[3] = ACKCODE;  //ackcode to be decided
+                                tm_pointer->TM_string[4] = 0x01;
+                                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);
+                                return tm_ptr;                               
+                            }
+                            break;
+                        }
+                    }                                                                   
+                    case 0x8:
+                    {
+                        printf("service:FUNCTION MANAGEMENT SERVICE\r\n"); 
+                        if(GETservice_subtype(tc_ptr)==0x1)
+                            {                               
+                              if(GETpid(tc_ptr)==0x01)
+                                {
+                                    printf("TC_PL_INIT\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                   
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;
+                                }                                
+                                else if(GETpid(tc_ptr)==0x02)
+                                {
+                                    printf("TC_PL_MAIN\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                   
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;
+                                }
+                               else if(GETpid(tc_ptr)==0x03)
+                                {
+                                    printf("TC_COM_INIT\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                   
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;
+                                }
+                                else if(GETpid(tc_ptr)==0x04)
+                                {
+                                    printf("TC_CDMS_HK_MAIN\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                    
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;                                   
+                                }
+                                else if(GETpid(tc_ptr)==0x11)
+                                {
+                                    printf("TC_SW_ON_SD\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                   
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;
+                                }
+                                else if(GETpid(tc_ptr)==0x12)
+                                {
+                                    printf("TC_SW_ON_RTC\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                    
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;
+                                }
+                                else if(GETpid(tc_ptr)==0x13)
+                                {
+                                    printf("TC_SW_ON_BAE\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                   
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;
+                                }
+                                else if(GETpid(tc_ptr)==0x14)
+                                {
+                                    printf("TC_SW_ON_PL_DL\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                    
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;
+                                }
+                                 else if(GETpid(tc_ptr)==0x15)
+                                {
+                                    printf("TC_SW_ON_PL_AG_HV\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                   
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;
+                                }
+                                 else if(GETpid(tc_ptr)==0x16)
+                                {
+                                    printf("TC_SW_ON_V_A_EN\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                   
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;                                   
+                                }
+                                else if(GETpid(tc_ptr)==0x21)
+                                {
+                                    printf("TC_SW_OFF_SD\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                   
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;
+                                }
+                                else if(GETpid(tc_ptr)==0x22)
+                                {
+                                    printf("TC_SW_OFF_RTC\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                    
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;
+                                }
+                                else if(GETpid(tc_ptr)==0x23)
+                                {
+                                    printf("TC_SW_OFF_BAE\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                   
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;
+                                }
+                                else if(GETpid(tc_ptr)==0x24)
+                                {
+                                    printf("TC_SW_OFF_PL_DL\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                   
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;
+                                }
+                                 else if(GETpid(tc_ptr)==0x25)
+                                {
+                                    printf("TC_SW_OFF_PL_AG_HV\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                   
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;
+                                }
+                                 else if(GETpid(tc_ptr)==0x26)
+                                {
+                                    printf("TC_SW_OFF_V_A_EN\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                    
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;
+                                }
+                                else if(GETpid(tc_ptr)==0x31)
+                                {
+                                    printf("TC_RST_SD\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                   
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;
+                                }
+                                else if(GETpid(tc_ptr)==0x32)
+                                {
+                                    printf("TC_RST_RTC\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                   
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;
+                                }
+                                else if(GETpid(tc_ptr)==0x33)
+                                {
+                                    printf("TC_RST_BAE\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                   
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;
+                                }
+                                else if(GETpid(tc_ptr)==0x34)
+                                {
+                                    printf("TC_RST_PL_DL\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                   
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;
+                                    break;
+                                }
+                                else if(GETpid(tc_ptr)==0xC1)
+                                {
+                                    printf("RESET_HK_COUNTER\r\n"); // call PWR_SWCH_ON function
+                                    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] = ACKCODE;                                   
+                                    for(uint8_t i=3;i<11;i++)
+                                    {
+                                        tm_pointer->TM_string[i] = 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);
+                                    return tm_ptr;
+                                    break;
+                                }
+                                else if(GETpid(tc_ptr)==0xF1)
+                                {
+                                    printf("RD_RTC\r\n"); //call RD_RTC
+                                    tm_pointer = new Short_tm;
+                                    tm_pointer->TM_string[0] = 0xD0;
+                                    tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);
+                                    tm_pointer->TM_string[2] = 0x01;
+                                    uint64_t time = FCTN_CDMS_RD_RTC();
+                                    tm_pointer->TM_string[3] = (uint8_t)((time&0xFF00000000000000)>>56);
+                                    tm_pointer->TM_string[4] = (uint8_t)((time&0x00FF000000000000)>>48);
+                                    tm_pointer->TM_string[5] = (uint8_t)((time&0x0000FF0000000000)>>40);
+                                    tm_pointer->TM_string[6] = (uint8_t)((time&0x000000FF00000000)>>32);
+                                    tm_pointer->TM_string[7] = (uint8_t)((time&0x00000000FF000000)>>24);
+                                    tm_pointer->TM_string[8] = (uint8_t)((time&0x0000000000FF0000)>>16);
+                                    tm_pointer->TM_string[9] = (uint8_t)((time&0x000000000000FF00)>>8);
+                                    tm_pointer->TM_string[10] = (uint8_t)(time&0x00000000000000FF);
+                                    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);
+                                    return tm_ptr;
+                                }                               
+                                else 
+                                {
+                                    printf("INVALID TC\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] = 0x01;
+                                    tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided
+                                    tm_pointer->TM_string[4] = 0x01;
+                                    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);
+                                    return tm_ptr;
+                                }
+                            }                          
+                        }                      
+                    }                 
+                }
+                default:
+                {
+                    printf("INVALID TC"); //send invalid TC TM
+                    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] = 0x01;
+                    tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided
+                    tm_pointer->TM_string[4] = 0x01;
+                    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);
+                    return tm_ptr;
+                    break;
+                }
+            }
+        }
+        case 3:
+        {
+            printf("Telecommand is for PL\r\n");
+            // printf("Informing PL about TC using I2C\r\n"); //interrupt to be sent to the bae
+            // FCTN_I2C_WRITE((char*)tc_ptr->TC_string);
+            // printf("sent the Telecommand to BAE\r\n"); //packet along with crc will be sent when bae is ready
+            // wait(1); //wait time is to be optimised
+            // if(tm_status_4m_slv == 1)
+            // {
+            //     FCTN_I2C_READ((char*)tm_ptr->TM_string);
+            //     received = 1;
+            // }
+            // if(received == 1 )
+            // {
+            //     printf("Telemetry is received from BAE\r\n");
+            //     printf("%s", tm_ptr->TM_string);
+            //     received  = 0;
+            // } // similar to BAE functions
+            break;
+        }
+        default: //invalid TC
+        {
+            printf("INVALID TC\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] = 0x01;
+            tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided
+            tm_pointer->TM_string[4] = 0x01;
+            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);
+            return tm_ptr;
+            break;
+        }
+     }
+}
 // CDMS TEAM CODE END
 
 // EXECUTE OBOSC
@@ -672,9 +1324,8 @@
                                 /*SKIP EXECUTION OF OBOSC HERE*/\
                             }\
                             else{\
-                                /*gPC.printf("cdms relay tmtc at %u\r\n", execute_psc);*/\
-                                /*call CDMS_RLY_TMTC*/\
-                                /*CDMS_RLY_TMTC(current_TC, put_tm_here);*/\
+                                gPC.printf("cdms relay tmtc at %u\r\n", execute_psc);\
+                                put_tm_here =  FCTN_CDMS_RLY_TMTC(current_TC);\
                             }\
                             /*DETECT ACK OR NACK*/\
                             uint8_t temp83 = 0x00;\