Hi Shubham I am just using this to test PYLD code

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of COM_MNG_TMTC_SIMPLE by Shreesha S

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers COM_MNG_TMTC.h Source File

COM_MNG_TMTC.h

00001 // 8 Jul
00002 // did flowchart of states
00003 
00004 // handle sd card with cdms team
00005 
00006 // Jun 6
00007 // WHAT IS TC exec code in L1 ack ? 
00008 
00009 //Jan 7 
00010 //added RLY_TMTC function
00011 //added included related files
00012 
00013 //#include "Flash.h"
00014 #include "cdms_rtc.h"
00015 
00016 DigitalIn tm_status_4m_slv(PIN39); //I2C interrupt to CDMS from BAE
00017 //DigitalIn tm_status_4m_pl(PIN61); //I2C interrupt to CDMS from PL
00018 
00019 uint8_t received = 0;
00020 uint16_t mid1;
00021 uint16_t mid2;
00022 uint16_t Nbytes;
00023 uint32_t Data[2];
00024 uint16_t nbytes;
00025 uint8_t flash_counter = 0;
00026 uint16_t crc16;
00027 uint16_t mid;
00028 uint32_t block;
00029 
00030 #define delete_TC(tc_ptr) {\
00031     if(tc_ptr == gHEAD_NODE_TCL){\
00032         gHEAD_NODE_TCL = tc_ptr->next_TC;\
00033     }\
00034     delete tc_ptr;\
00035 }
00036 
00037 // typeof tm_ptr: Base_tm
00038 // typeof tc_ptr: Base_tc
00039 // typeof temp_xxxx: uint8_t
00040 
00041 
00042 
00043 
00044 #define detect_ack(tm_ptr, temp_ack, tc_psc) {\
00045     if( tm_ptr != NULL ){\
00046         int length = TM_SHORT_SIZE;\
00047         if( GETshort_or_long_tm(tm_ptr) == SHORT_TM_CODE ){\
00048             length = TM_SHORT_SIZE;\
00049         }\
00050         else{\
00051             length = TM_LONG_SIZE;\
00052         }\
00053         uint16_t crc = crc16_gen(tm_ptr->TM_string, length-2);\
00054         if( (((crc & 0xFF00) >> 8) == tm_ptr->TM_string[length-2]) && ( (crc & 0x00FF) == tm_ptr->TM_string[length-1] ) ){\
00055             uint8_t temp8;\
00056             temp8 = tm_ptr->TM_string[TM_ACK_CODE_INDEX];\
00057             temp8 = temp8 & 0xE0;\
00058             if( (temp8 == 0xC0) || (temp8 == 0xA0) )\
00059                 temp_ack = 0x01;\
00060             else{\
00061                 temp_ack = 0x00;\
00062                 /*CHECK FOR NACK CODE: CRC FAIL NACK*/\
00063                 temp8 = tm_ptr->TM_string[TM_ACK_CODE_INDEX];\
00064                 temp8 = temp8 & 0x0F;\
00065                 if( temp8 == CRC_FAIL_NACK_CODE ){\
00066                     tm_ptr->TM_string[2] = tc_psc;\
00067                 }\
00068             }\
00069         }\
00070         else\
00071             temp_ack = 0x00;\
00072     }\
00073     else{\
00074         temp_ack = 0x00;\
00075     }\
00076 }
00077 
00078 #define isit_obosc(tc_ptr, temp_obosc) {\
00079     temp_obosc = 0x00;\
00080     if( GETapid(tc_ptr) == APID_COM ){\
00081         if( ((tc_ptr->TC_string[2]) >> 4) == SERVICE_OBOSC ){\
00082             temp_obosc = 0x01;\
00083         }\
00084     }\
00085 }
00086 
00087 #define isit_sdcard(tc_ptr, temp_sdcard) {\
00088     temp_sdcard = 0x00;\
00089     if( GETapid(tc_ptr) == APID_COM ){\
00090         if( ( (tc_ptr->TC_string[2]) >> 4) == SERVICE_OBSRS ){\
00091             temp_sdcard = 0x01;\
00092         }\
00093     }\
00094 }
00095 
00096 
00097 
00098 void after_cooling_pa(){
00099     gCOM_MNG_TMTC_THREAD->signal_set(COM_MNG_TMTC_SIGNAL_UART_INT);
00100 }
00101 
00102 /*
00103 @brief:     check for missing tc, also check crc, i.e. 
00104             if true execution can be started else have to wait
00105             decide the next state
00106 @param:     none
00107 @return:    bool indicating whether there are missing tc
00108 */
00109 // PENDING: LAST FRAME BIT
00110 /*
00111 for loop: check for missing tc
00112 if: check for incorrect sized tc
00113 if: check for last frame bit
00114 */
00115 #define continueToExecute(returnHere) {\
00116     uint8_t tempReturn = 0x00;\
00117     /*search for missing psc*/\
00118     for(uint8_t p = 0x00 ; p < (gTOTAL_VALID_TC) ; ++p){\
00119         bool flag = false;\
00120         Base_tc *node_ptr = gHEAD_NODE_TCL;\
00121         while(node_ptr != NULL){\
00122             if( (GETpacket_seq_count(node_ptr) == p) && (GETcrc_pass(node_ptr) == 1) ){\
00123                 flag = true;\
00124                 break;\
00125             }\
00126             else{\
00127                 node_ptr = node_ptr->next_TC;\
00128             }\
00129         }\
00130         if(flag == false){\
00131             tempReturn = 0x02;\
00132             break;\
00133         }\
00134     }\
00135     /*search for last packet bit*/\
00136     tempReturn = tempReturn + 0x01;\
00137     Base_tc *tcp = gHEAD_NODE_TCL;\
00138     while(tcp != NULL){\
00139         if(GETpacket_seq_count(tcp) == (gTOTAL_VALID_TC - 1)){\
00140             if( ( (tcp->TC_string[1]) & 0x20 ) == 0x20 ){\
00141                 tempReturn = tempReturn - 0x01;\
00142             }\
00143             break;\
00144         }\
00145         tcp = tcp->next_TC;\
00146     }\
00147     returnHere = tempReturn;\
00148     /*UPDATE gMASTER STATE*/\
00149     if( (returnHere == 0x00) ){\
00150         if( (gMASTER_STATE == TCL_STATE_INCOMPLETE) || (gMASTER_STATE == TCL_STATE_COMPLETED) || (gMASTER_STATE == TCL_STATE_ABORTED) ){\
00151             gMASTER_STATE = TCL_STATE_EXECUTING;\
00152         }\
00153     }\
00154     else{\
00155         if( (gMASTER_STATE == TCL_STATE_INCOMPLETE) || (gMASTER_STATE == TCL_STATE_COMPLETED) ){\
00156             gMASTER_STATE = TCL_STATE_INCOMPLETE;\
00157         }\
00158     }\
00159 }
00160 
00161 /*
00162 return 1 if code match
00163 return 0 if code mismatch
00164 */
00165 #define GScodeVerification(returnHere){\
00166     Base_tc *testTC = gHEAD_NODE_TCL;\
00167     uint16_t overflowCount = 0;\
00168     returnHere = 0xFF;\
00169     while( (overflowCount < TCL_OVERFLOW_CONSTANT) && (testTC != NULL) ){\
00170         if( (GETpacket_seq_count(testTC) == PSC_CALLSIGN) && (GETapid(testTC) == APID_CALLSIGN) ){\
00171             /*uint8_t temp8 = testTC->TC_string[1];*/\
00172             if( true ){\
00173                 for( int i = 2 ; i <= 8 ; ++i ){\
00174                     if( testTC->TC_string[i] != gGSCODE[i-2] ){\
00175                         returnHere = 0;\
00176                         break;\
00177                     }\
00178                 }\
00179             }\
00180             break;\
00181         }\
00182         testTC = testTC->next_TC;\
00183         ++overflowCount;\
00184     }\
00185 }
00186 
00187 /*
00188 @brief:     DELETE THE CRC FAILED TC FROM THE LIST TO FREE-UP MEMORY AND UPDATE 
00189             THE TOTAL VALID TC AND GENERATE L1_ACK_TM
00190 @param:     none
00191 @return:    none
00192 */
00193 /*tm_ptr is the next_TM of a linked list, and should have the value NULL, i.e. tm_ptr should be the next_TM pointer of thte last node */
00194 
00195 /*tm_ptr is the next_TM of a linked list, and should have the value NULL, i.e. tm_ptr should be the next_TM pointer of thte last node */
00196 
00197 // CDMS TEAM CODE START
00198 inline Base_tm* FCTN_CDMS_RLY_TMTC(Base_tc *tc_ptr){
00199     uint8_t ACKCODE = 0x00;
00200     //printf("\rTC execution in progress\r\n");
00201     Base_tm *tm_pointer = new Long_tm;
00202     Base_tm *tm_ptr = tm_pointer;
00203     received = 0;
00204     switch(GETapid(tc_ptr))
00205     {
00206         case 1: //apid=01 implies it corresponds to bae
00207         {
00208             //printf("Telecommand is for BAE\r\n");
00209             //printf("Sending TC to BAE...\r\n"); //interrupt to be sent to the bae
00210             FCTN_I2C_WRITE((char*)tc_ptr->TC_string);
00211             while(1)
00212             {
00213                 wait(1); //TimeOut instead of wait
00214                 if(tm_status_4m_slv == 1)
00215                 {
00216                     //printf("receiving...\r\n");
00217                     FCTN_I2C_READ((char*)tm_pointer->TM_string,134);
00218                     //printf("%s", tm_pointer->TM_string);
00219                     received+=1;
00220                     tm_pointer = tm_pointer->next_TM;
00221                     break; //only for testing purpose
00222                 }
00223                 else
00224                 {
00225                     break;
00226                 }
00227             }
00228             if(received >= 1 )
00229             {
00230                 //printf("Telemetry is received from BAE\r\n");
00231                 Base_tm *tm_print = tm_ptr;
00232                 for(uint8_t i=0;i<received;i++)
00233                 {  
00234                     //printf("%s", tm_print->TM_string);
00235                     tm_print = tm_print->next_TM; //for check
00236                 }
00237                 received  = 0;
00238                 tm_pointer->next_TM = NULL;                 return tm_ptr;
00239             }
00240             else
00241             {
00242                 //printf("Telemetry is not received from BAE\r\n");
00243                 //tm_pointer = new Short_tm;
00244                 tm_pointer->TM_string[0] = 0xB0;
00245                 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);
00246                 tm_pointer->TM_string[2] = 0x01;
00247                 tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided
00248                 tm_pointer->TM_string[4] = 0x01;
00249                 for(uint8_t i=0;i<6;i++)
00250                 {
00251                     tm_pointer->TM_string[i+5] = 0;
00252                 }
00253                 crc16 = crc16_gen(tm_ptr->TM_string,11);
00254                 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00255                 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00256                 tm_pointer->next_TM = NULL;                 return tm_ptr;
00257             }
00258             break;
00259         }
00260         case 2:
00261         {
00262             //gPC.printf("Telecommand is for CDMS\r\n"); //apid = 10 corresponds to cdms
00263             switch(GETservice_type(tc_ptr))
00264             {
00265                 case 0x60:
00266                 {
00267                         //gPC.printf("service:MMS\r\n");
00268                         switch(GETservice_subtype(tc_ptr))
00269                         {
00270                             case 0x1:
00271                             {
00272                             //printf("sub_service:Read from RAM_Memory\r\n");
00273                             mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]);                                                       
00274                                                              
00275                                     //Data[0] = FCTN_CDMS_RD_FLASH(0);
00276                                     //Data[1] = FCTN_CDMS_RD_FLASH(1);
00277                                     //tm_pointer = new Long_tm;
00278                                     tm_pointer->TM_string[0] = 0x30;
00279                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);
00280                                     tm_pointer->TM_string[2] = (uint8_t)(flash_counter);
00281                                     for(uint8_t i=0;i<4;i++)
00282                                     {
00283                                         tm_pointer->TM_string[3+i] = (uint8_t)((Data[0]>>(8*i))&0x00FF);
00284                                     }
00285                                     for(uint8_t i=4;i<8;i++)
00286                                     {
00287                                         tm_pointer->TM_string[3+i] = (uint8_t)((Data[1]>>(8*i))&0x00FF);
00288                                     }
00289                                     crc16 = crc16_gen(tm_ptr->TM_string,9);
00290                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00291                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00292                                 tm_pointer->next_TM = NULL;                 return tm_ptr;
00293                             }                            
00294                             case 0x2:
00295                             {
00296                             //printf("sub_service:Read from Flash_Memory\r\n");
00297                             mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]);                           
00298                                                                                              
00299                                     //Data[0] = FCTN_CDMS_RD_FLASH(0);
00300                                     //Data[1] = FCTN_CDMS_RD_FLASH(1);                                                                                             
00301                                     //tm_pointer = new Long_tm;
00302                                     tm_pointer->TM_string[0] = 0x30;
00303                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);
00304                                     tm_pointer->TM_string[2] = (uint8_t)(flash_counter);
00305                                     for(uint8_t i=0;i<4;i++)
00306                                     {
00307                                         tm_pointer->TM_string[3+i] = (uint8_t)((Data[0]>>(8*i))&0x00FF);
00308                                     }
00309                                     for(uint8_t i=4;i<8;i++)
00310                                     {
00311                                         tm_pointer->TM_string[3+i] = (uint8_t)((Data[1]>>(8*i))&0x00FF);
00312                                     }
00313                                     crc16 = crc16_gen(tm_ptr->TM_string,9);
00314                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00315                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00316                                 tm_pointer->next_TM = NULL;                 return tm_ptr;
00317                             }                           
00318                             case 0x5:
00319                             {
00320                             //printf("WRITE ON FLASH_MEMORY\r\n");                          
00321                                     mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]);                                   
00322                                     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])));
00323                                     //FCTN_CDMS_WR_FLASH(mid,block);
00324                                     //tm_pointer = new Short_tm;
00325                                     tm_pointer->TM_string[0] = 0xB0;
00326                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);
00327                                     tm_pointer->TM_string[2] = 0x01;
00328                                     tm_pointer->TM_string[3] = ACKCODE;  //ackcode to be decided
00329                                     tm_pointer->TM_string[4] = 0x01;
00330                                     for(uint8_t i=0;i<6;i++)
00331                                     {
00332                                         tm_pointer->TM_string[i+5] = 0;
00333                                     }
00334                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00335                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00336                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00337                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00338                                     break;
00339                             }                                                    
00340                             default:
00341                             {
00342                                 //printf("INVALID TC\r\n"); //Send Invalid TC Telemetry
00343                                 //tm_pointer = new Short_tm;
00344                                 tm_pointer->TM_string[0] = 0xB0;
00345                                 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);
00346                                 tm_pointer->TM_string[2] = 0x01;
00347                                 tm_pointer->TM_string[3] = ACKCODE;  //ackcode to be decided
00348                                 tm_pointer->TM_string[4] = 0x01;
00349                                 for(uint8_t i=0;i<6;i++)
00350                                 {
00351                                     tm_pointer->TM_string[i+5] = 0;
00352                                 }
00353                                 crc16 = crc16_gen(tm_ptr->TM_string,11);
00354                                 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00355                                 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00356                                 tm_pointer->next_TM = NULL;                 return tm_ptr;                               
00357                             }
00358                             break;
00359                         }
00360                     }                                                                   
00361                     case 0x8:
00362                     {
00363                         //printf("service:FUNCTION MANAGEMENT SERVICE\r\n"); 
00364                         if(GETservice_subtype(tc_ptr)==0x1)
00365                             {                               
00366                               if(GETpid(tc_ptr)==0x01)
00367                                 {
00368                                     //printf("TC_PL_INIT\r\n"); // call PWR_SWCH_ON function
00369                                     //tm_pointer = new Short_tm; 
00370                                     tm_pointer->TM_string[0] = 0xB0; 
00371                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00372                                     tm_pointer->TM_string[2] = ACKCODE;                                   
00373                                     for(uint8_t i=3;i<11;i++)
00374                                     {
00375                                         tm_pointer->TM_string[i] = 0;
00376                                     }
00377                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00378                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00379                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00380                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00381                                     break;
00382                                 }                                
00383                                 else if(GETpid(tc_ptr)==0x02)
00384                                 {
00385                                     //printf("TC_PL_MAIN\r\n"); // call PWR_SWCH_ON function
00386                                     //tm_pointer = new Short_tm; 
00387                                     tm_pointer->TM_string[0] = 0xB0; 
00388                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00389                                     tm_pointer->TM_string[2] = ACKCODE;                                   
00390                                     for(uint8_t i=3;i<11;i++)
00391                                     {
00392                                         tm_pointer->TM_string[i] = 0;
00393                                     }
00394                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00395                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00396                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00397                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00398                                     break;
00399                                 }
00400                                else if(GETpid(tc_ptr)==0x03)
00401                                 {
00402                                     //printf("TC_COM_INIT\r\n"); // call PWR_SWCH_ON function
00403                                     //tm_pointer = new Short_tm; 
00404                                     tm_pointer->TM_string[0] = 0xB0; 
00405                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00406                                     tm_pointer->TM_string[2] = ACKCODE;                                   
00407                                     for(uint8_t i=3;i<11;i++)
00408                                     {
00409                                         tm_pointer->TM_string[i] = 0;
00410                                     }
00411                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00412                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00413                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00414                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00415                                     break;
00416                                 }
00417                                 else if(GETpid(tc_ptr)==0x04)
00418                                 {
00419                                     //printf("TC_CDMS_HK_MAIN\r\n"); // call PWR_SWCH_ON function
00420                                     //tm_pointer = new Short_tm; 
00421                                     tm_pointer->TM_string[0] = 0xB0; 
00422                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00423                                     tm_pointer->TM_string[2] = ACKCODE;                                    
00424                                     for(uint8_t i=3;i<11;i++)
00425                                     {
00426                                         tm_pointer->TM_string[i] = 0;
00427                                     }
00428                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00429                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00430                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00431                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00432                                     break;                                   
00433                                 }
00434                                 else if(GETpid(tc_ptr)==0x11)
00435                                 {
00436                                     //printf("TC_SW_ON_SD\r\n"); // call PWR_SWCH_ON function
00437                                     //tm_pointer = new Short_tm; 
00438                                     tm_pointer->TM_string[0] = 0xB0; 
00439                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00440                                     tm_pointer->TM_string[2] = ACKCODE;                                   
00441                                     for(uint8_t i=3;i<11;i++)
00442                                     {
00443                                         tm_pointer->TM_string[i] = 0;
00444                                     }
00445                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00446                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00447                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00448                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00449                                     break;
00450                                 }
00451                                 else if(GETpid(tc_ptr)==0x12)
00452                                 {
00453                                     //printf("TC_SW_ON_RTC\r\n"); // call PWR_SWCH_ON function
00454                                     //tm_pointer = new Short_tm; 
00455                                     tm_pointer->TM_string[0] = 0xB0; 
00456                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00457                                     tm_pointer->TM_string[2] = ACKCODE;                                    
00458                                     for(uint8_t i=3;i<11;i++)
00459                                     {
00460                                         tm_pointer->TM_string[i] = 0;
00461                                     }
00462                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00463                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00464                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00465                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00466                                     break;
00467                                 }
00468                                 else if(GETpid(tc_ptr)==0x13)
00469                                 {
00470                                     //printf("TC_SW_ON_BAE\r\n"); // call PWR_SWCH_ON function
00471                                     //tm_pointer = new Short_tm; 
00472                                     tm_pointer->TM_string[0] = 0xB0; 
00473                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00474                                     tm_pointer->TM_string[2] = ACKCODE;                                   
00475                                     for(uint8_t i=3;i<11;i++)
00476                                     {
00477                                         tm_pointer->TM_string[i] = 0;
00478                                     }
00479                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00480                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00481                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00482                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00483                                     break;
00484                                 }
00485                                 else if(GETpid(tc_ptr)==0x14)
00486                                 {
00487                                     //printf("TC_SW_ON_PL_DL\r\n"); // call PWR_SWCH_ON function
00488                                     //tm_pointer = new Short_tm; 
00489                                     tm_pointer->TM_string[0] = 0xB0; 
00490                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00491                                     tm_pointer->TM_string[2] = ACKCODE;                                    
00492                                     for(uint8_t i=3;i<11;i++)
00493                                     {
00494                                         tm_pointer->TM_string[i] = 0;
00495                                     }
00496                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00497                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00498                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00499                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00500                                     break;
00501                                 }
00502                                  else if(GETpid(tc_ptr)==0x15)
00503                                 {
00504                                     //printf("TC_SW_ON_PL_AG_HV\r\n"); // call PWR_SWCH_ON function
00505                                     //tm_pointer = new Short_tm; 
00506                                     tm_pointer->TM_string[0] = 0xB0; 
00507                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00508                                     tm_pointer->TM_string[2] = ACKCODE;                                   
00509                                     for(uint8_t i=3;i<11;i++)
00510                                     {
00511                                         tm_pointer->TM_string[i] = 0;
00512                                     }
00513                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00514                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00515                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00516                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00517                                     break;
00518                                 }
00519                                  else if(GETpid(tc_ptr)==0x16)
00520                                 {
00521                                     //printf("TC_SW_ON_V_A_EN\r\n"); // call PWR_SWCH_ON function
00522                                     //tm_pointer = new Short_tm; 
00523                                     tm_pointer->TM_string[0] = 0xB0; 
00524                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00525                                     tm_pointer->TM_string[2] = ACKCODE;                                   
00526                                     for(uint8_t i=3;i<11;i++)
00527                                     {
00528                                         tm_pointer->TM_string[i] = 0;
00529                                     }
00530                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00531                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00532                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00533                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00534                                     break;                                   
00535                                 }
00536                                 else if(GETpid(tc_ptr)==0x21)
00537                                 {
00538                                     //printf("TC_SW_OFF_SD\r\n"); // call PWR_SWCH_ON function
00539                                     //tm_pointer = new Short_tm; 
00540                                     tm_pointer->TM_string[0] = 0xB0; 
00541                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00542                                     tm_pointer->TM_string[2] = ACKCODE;                                   
00543                                     for(uint8_t i=3;i<11;i++)
00544                                     {
00545                                         tm_pointer->TM_string[i] = 0;
00546                                     }
00547                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00548                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00549                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00550                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00551                                     break;
00552                                 }
00553                                 else if(GETpid(tc_ptr)==0x22)
00554                                 {
00555                                     //printf("TC_SW_OFF_RTC\r\n"); // call PWR_SWCH_ON function
00556                                     //tm_pointer = new Short_tm; 
00557                                     tm_pointer->TM_string[0] = 0xB0; 
00558                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00559                                     tm_pointer->TM_string[2] = ACKCODE;                                    
00560                                     for(uint8_t i=3;i<11;i++)
00561                                     {
00562                                         tm_pointer->TM_string[i] = 0;
00563                                     }
00564                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00565                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00566                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00567                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00568                                     break;
00569                                 }
00570                                 else if(GETpid(tc_ptr)==0x23)
00571                                 {
00572                                     //printf("TC_SW_OFF_BAE\r\n"); // call PWR_SWCH_ON function
00573                                     //tm_pointer = new Short_tm; 
00574                                     tm_pointer->TM_string[0] = 0xB0; 
00575                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00576                                     tm_pointer->TM_string[2] = ACKCODE;                                   
00577                                     for(uint8_t i=3;i<11;i++)
00578                                     {
00579                                         tm_pointer->TM_string[i] = 0;
00580                                     }
00581                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00582                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00583                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00584                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00585                                     break;
00586                                 }
00587                                 else if(GETpid(tc_ptr)==0x24)
00588                                 {
00589                                     //printf("TC_SW_OFF_PL_DL\r\n"); // call PWR_SWCH_ON function
00590                                     //tm_pointer = new Short_tm; 
00591                                     tm_pointer->TM_string[0] = 0xB0; 
00592                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00593                                     tm_pointer->TM_string[2] = ACKCODE;                                   
00594                                     for(uint8_t i=3;i<11;i++)
00595                                     {
00596                                         tm_pointer->TM_string[i] = 0;
00597                                     }
00598                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00599                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00600                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00601                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00602                                     break;
00603                                 }
00604                                  else if(GETpid(tc_ptr)==0x25)
00605                                 {
00606                                     //printf("TC_SW_OFF_PL_AG_HV\r\n"); // call PWR_SWCH_ON function
00607                                     //tm_pointer = new Short_tm; 
00608                                     tm_pointer->TM_string[0] = 0xB0; 
00609                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00610                                     tm_pointer->TM_string[2] = ACKCODE;                                   
00611                                     for(uint8_t i=3;i<11;i++)
00612                                     {
00613                                         tm_pointer->TM_string[i] = 0;
00614                                     }
00615                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00616                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00617                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00618                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00619                                     break;
00620                                 }
00621                                  else if(GETpid(tc_ptr)==0x26)
00622                                 {
00623                                     //printf("TC_SW_OFF_V_A_EN\r\n"); // call PWR_SWCH_ON function
00624                                     //tm_pointer = new Short_tm; 
00625                                     tm_pointer->TM_string[0] = 0xB0; 
00626                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00627                                     tm_pointer->TM_string[2] = ACKCODE;                                    
00628                                     for(uint8_t i=3;i<11;i++)
00629                                     {
00630                                         tm_pointer->TM_string[i] = 0;
00631                                     }
00632                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00633                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00634                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00635                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00636                                     break;
00637                                 }
00638                                 else if(GETpid(tc_ptr)==0x31)
00639                                 {
00640                                     //printf("TC_RST_SD\r\n"); // call PWR_SWCH_ON function
00641                                     //tm_pointer = new Short_tm; 
00642                                     tm_pointer->TM_string[0] = 0xB0; 
00643                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00644                                     tm_pointer->TM_string[2] = ACKCODE;                                   
00645                                     for(uint8_t i=3;i<11;i++)
00646                                     {
00647                                         tm_pointer->TM_string[i] = 0;
00648                                     }
00649                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00650                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00651                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00652                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00653                                     break;
00654                                 }
00655                                 else if(GETpid(tc_ptr)==0x32)
00656                                 {
00657                                     //printf("TC_RST_RTC\r\n"); // call PWR_SWCH_ON function
00658                                     //tm_pointer = new Short_tm; 
00659                                     tm_pointer->TM_string[0] = 0xB0; 
00660                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00661                                     tm_pointer->TM_string[2] = ACKCODE;                                   
00662                                     for(uint8_t i=3;i<11;i++)
00663                                     {
00664                                         tm_pointer->TM_string[i] = 0;
00665                                     }
00666                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00667                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00668                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00669                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00670                                     break;
00671                                 }
00672                                 else if(GETpid(tc_ptr)==0x33)
00673                                 {
00674                                     //printf("TC_RST_BAE\r\n"); // call PWR_SWCH_ON function
00675                                     //tm_pointer = new Short_tm; 
00676                                     tm_pointer->TM_string[0] = 0xB0; 
00677                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00678                                     tm_pointer->TM_string[2] = ACKCODE;                                   
00679                                     for(uint8_t i=3;i<11;i++)
00680                                     {
00681                                         tm_pointer->TM_string[i] = 0;
00682                                     }
00683                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00684                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00685                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00686                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00687                                     break;
00688                                 }
00689                                 else if(GETpid(tc_ptr)==0x34)
00690                                 {
00691                                     //printf("TC_RST_PL_DL\r\n"); // call PWR_SWCH_ON function
00692                                     //tm_pointer = new Short_tm; 
00693                                     tm_pointer->TM_string[0] = 0xB0; 
00694                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00695                                     tm_pointer->TM_string[2] = ACKCODE;                                   
00696                                     for(uint8_t i=3;i<11;i++)
00697                                     {
00698                                         tm_pointer->TM_string[i] = 0;
00699                                     }
00700                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00701                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00702                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00703                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00704                                     break;
00705                                     break;
00706                                 }
00707                                 else if(GETpid(tc_ptr)==0xC1)
00708                                 {
00709                                     //printf("RESET_HK_COUNTER\r\n"); // call PWR_SWCH_ON function
00710                                     //tm_pointer = new Short_tm; 
00711                                     tm_pointer->TM_string[0] = 0xB0; 
00712                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00713                                     tm_pointer->TM_string[2] = ACKCODE;                                   
00714                                     for(uint8_t i=3;i<11;i++)
00715                                     {
00716                                         tm_pointer->TM_string[i] = 0;
00717                                     }
00718                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00719                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00720                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00721                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00722                                     break;
00723                                 }
00724                                 else if(GETpid(tc_ptr)==0xF1)
00725                                 {
00726                                     //printf("RD_RTC\r\n"); //call RD_RTC
00727                                     //tm_pointer = new Short_tm;
00728                                     tm_pointer->TM_string[0] = 0xD0;
00729                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);
00730                                     tm_pointer->TM_string[2] = 0x01;
00731                                     uint64_t time = FCTN_CDMS_RD_RTC();
00732                                     tm_pointer->TM_string[3] = (uint8_t)((time&0xFF00000000000000)>>56);
00733                                     tm_pointer->TM_string[4] = (uint8_t)((time&0x00FF000000000000)>>48);
00734                                     tm_pointer->TM_string[5] = (uint8_t)((time&0x0000FF0000000000)>>40);
00735                                     tm_pointer->TM_string[6] = (uint8_t)((time&0x000000FF00000000)>>32);
00736                                     tm_pointer->TM_string[7] = (uint8_t)((time&0x00000000FF000000)>>24);
00737                                     tm_pointer->TM_string[8] = (uint8_t)((time&0x0000000000FF0000)>>16);
00738                                     tm_pointer->TM_string[9] = (uint8_t)((time&0x000000000000FF00)>>8);
00739                                     tm_pointer->TM_string[10] = (uint8_t)(time&0x00000000000000FF);
00740                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00741                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00742                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00743                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00744                                 }                               
00745                                 else 
00746                                 {
00747                                     //printf("INVALID TC\r\n");
00748                                     //tm_pointer = new Short_tm; 
00749                                     tm_pointer->TM_string[0] = 0xB0; 
00750                                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00751                                     tm_pointer->TM_string[2] = 0x01;
00752                                     tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided
00753                                     tm_pointer->TM_string[4] = 0x01;
00754                                     for(uint8_t i=0;i<6;i++)
00755                                     {
00756                                         tm_pointer->TM_string[i+5] = 0;
00757                                     }
00758                                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00759                                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00760                                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00761                                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00762                                 }
00763                             }                          
00764                                               
00765                                      
00766                 }
00767                 default:
00768                 {
00769                     //printf("INVALID TC"); //send invalid TC TM
00770                     //tm_pointer = new Short_tm; 
00771                     tm_pointer->TM_string[0] = 0xB0; 
00772                     tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00773                     tm_pointer->TM_string[2] = 0x01;
00774                     tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided
00775                     tm_pointer->TM_string[4] = 0x01;
00776                     for(uint8_t i=0;i<6;i++)
00777                     {
00778                         tm_pointer->TM_string[i+5] = 0;
00779                     }
00780                     crc16 = crc16_gen(tm_ptr->TM_string,11);
00781                     tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00782                     tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00783                     tm_pointer->next_TM = NULL;                 return tm_ptr;
00784                     break;
00785                 }
00786             }
00787         }
00788         case 3:
00789         {
00790             //printf("Telecommand is for PL\r\n");
00791             // printf("Informing PL about TC using I2C\r\n"); //interrupt to be sent to the bae
00792             // FCTN_I2C_WRITE((char*)tc_ptr->TC_string);
00793             // printf("sent the Telecommand to BAE\r\n"); //packet along with crc will be sent when bae is ready
00794             // wait(1); //wait time is to be optimised
00795             // if(tm_status_4m_slv == 1)
00796             // {
00797             //     FCTN_I2C_READ((char*)tm_ptr->TM_string);
00798             //     received = 1;
00799             // }
00800             // if(received == 1 )
00801             // {
00802             //     printf("Telemetry is received from BAE\r\n");
00803             //     printf("%s", tm_ptr->TM_string);
00804             //     received  = 0;
00805             // } // similar to BAE functions
00806             break;
00807         }
00808         default: //invalid TC
00809         {
00810             //printf("INVALID TC\r\n");
00811             //tm_pointer = new Short_tm; 
00812             tm_pointer->TM_string[0] = 0xB0; 
00813             tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr);                                    
00814             tm_pointer->TM_string[2] = 0x01;
00815             tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided
00816             tm_pointer->TM_string[4] = 0x01;
00817             for(uint8_t i=0;i<6;i++)
00818             {
00819                 tm_pointer->TM_string[i+5] = 0;
00820             }
00821             crc16 = crc16_gen(tm_ptr->TM_string,11);
00822             tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8);
00823             tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF);
00824             tm_pointer->next_TM = NULL;                 return tm_ptr;
00825             break;
00826         }
00827      }
00828 }
00829 // CDMS TEAM CODE END
00830 // EXECUTE OBOSC
00831 #define execute_obosc_core(tc_ptr, tm_ptr, reset_flag) {\
00832     if (DEBUG)\
00833         gPC.puts("Inside execute_obosc_core\r\n");\
00834     uint8_t service_subtype = (tc_ptr->TC_string[2]) & 0x0F;\
00835     uint8_t temp8 = 0x00;\
00836     Base_tc *modify_this = gHEAD_NODE_TCL;\
00837     int modify_overflow = 0x00;\
00838     switch( service_subtype ){\
00839         case OBOSC_SUB_DISABLE:\
00840             /*gPC.puts("target psc are ");*/\
00841             for(int i = 3 ; i < 9 ; ++i){\
00842                 /*gPC.printf("%u ", tc_ptr->TC_string[i]);*/\
00843             }\
00844             /*gPC.puts("\r\n");*/\
00845             /*gPC.puts("disable type obosc\r\n");*/\
00846             while( modify_this != NULL ){\
00847                 if( modify_overflow < TCL_OVERFLOW_CONSTANT ){\
00848                     uint8_t modify_psc = GETpacket_seq_count(modify_this);\
00849                     /*gPC.printf("mosify_psc = %u\r\n", modify_psc);*/\
00850                     for( int i = 3 ; i < 9 ; ++i ){\
00851                         uint8_t target_psc = tc_ptr->TC_string[i];\
00852                         if( (target_psc == modify_psc) && (target_psc != 0) ){\
00853                             uint16_t tempExec = TC_STATE_DISABLED;\
00854                             PUTexec_status( modify_this, tempExec );\
00855                             break;\
00856                         }\
00857                     }\
00858                     modify_this = modify_this->next_TC;\
00859                     ++modify_overflow;\
00860                 }\
00861                 else{\
00862                     /*PENDING: RESET CDMS*/\
00863                     break;\
00864                 }\
00865             }\
00866             break;\
00867         case OBOSC_SUB_RETRY:\
00868             /*gPC.puts("retry type obosc\r\n");*/\
00869             while( modify_this != NULL ){\
00870                 if( modify_overflow < TCL_OVERFLOW_CONSTANT ){\
00871                     uint8_t modify_psc = GETpacket_seq_count(modify_this);\
00872                     for( int i = 3 ; i < 9 ; ++i ){\
00873                         uint8_t target_psc = tc_ptr->TC_string[i];\
00874                         if( (target_psc == modify_psc) && (target_psc != 0) ){\
00875                             uint16_t tempExec = TC_STATE_MARKED_RETRY;\
00876                             PUTexec_status( modify_this, tempExec );\
00877                             /*gPC.puts("reqquired tc found: disable\r\n");*/\
00878                             break;\
00879                         }\
00880                     }\
00881                     modify_this = modify_this->next_TC;\
00882                     ++modify_overflow;\
00883                 }\
00884                 else{\
00885                     /*PENDING: RESET CDMS*/\
00886                     break;\
00887                 }\
00888             }\
00889             break;\
00890     }\
00891     Base_tm *ackl234new = new Short_tm;\
00892     ackl234new->next_TM = NULL;\
00893     /*return telemetry pointer here*/\
00894     tm_ptr = ackl234new;\
00895     ackl234new->TM_string[0] = TMID_ACK_L234 << 4;\
00896     ackl234new->TM_string[1] = GETpacket_seq_count(tc_ptr);\
00897     ackl234new->TM_string[2] = 0xA0;\
00898     for(int i = 3; i < 11; ++i){\
00899         ackl234new->TM_string[i] = 0x00;\
00900     }\
00901     uint16_t crc = crc16_gen(ackl234new->TM_string, TM_SHORT_SIZE-2);\
00902     ackl234new->TM_string[11] = (crc & 0xFF00) >> 8;\
00903     ackl234new->TM_string[12] = crc & 0x00FF;\
00904     /*ack l234 old*/\
00905     if( service_subtype == OBOSC_SUB_REP_LE ){\
00906         if( gLAST_TM_SHORT_OR_LONG == SHORT_TM_CODE ){\
00907             Base_tm *ackl234old = new Short_tm;\
00908             ackl234old->next_TM = NULL;\
00909             /*APPEND TO ACK L234 NEW HERE*/\
00910             ackl234new->next_TM = ackl234old;\
00911             for( int i = 0 ; i < TM_SHORT_SIZE ; ++i ){\
00912                 ackl234old->TM_string[i] = gLAST_TM[i];\
00913             }\
00914         }\
00915         else{\
00916             Base_tm *tempLongTM = new Long_tm;\
00917             tempLongTM->next_TM = NULL;\
00918             /*APPEND TO ACK L234 NEW HERE*/\
00919             ackl234new->next_TM = tempLongTM;\
00920             for( int i = 0 ; i < TM_LONG_SIZE ; ++i ){\
00921                 tempLongTM->TM_string[i] = gLAST_TM[i];\
00922             }\
00923         }\
00924     }\
00925     else if( service_subtype == OBOSC_SUB_REP_TCLD ){\
00926         get_tc_list(ackl234new->next_TM, GETpacket_seq_count(tc_ptr));\
00927     }\
00928     else if( service_subtype == OBOSC_SUB_RESET ){\
00929         /*reset_all;*/\
00930         reset_flag = 1;\
00931         /*PENDING: VERIFY reset_all, RESET CDMS*/\
00932     }\
00933     else if( (service_subtype != OBOSC_SUB_DISABLE) && (service_subtype != OBOSC_SUB_RETRY) ){\
00934         /*CHANGE THE ACK CODE TO INVALID TC*/\
00935         ackl234new->TM_string[2] = 0xA2;\
00936     }\
00937     if (DEBUG)\
00938         gPC.puts("completed obosc\r\n");\
00939 }
00940 
00941 /*tm_ptr is the next_TM of a linked list, and should have the value NULL, i.e. tm_ptr should be the next_TM pointer of thte last node */
00942 
00943 
00944 #define EXECUTE_OBOSC_ONLY {\
00945     int reset_flag = 0;\
00946     if (DEBUG)\
00947         gPC.puts("iNSIDE EXECUTE_OBOSC_ONLY\r\n");\
00948     for(uint8_t execute_psc = PSC_START_VALUE ; execute_psc < gTOTAL_VALID_TC ; ++execute_psc){\
00949         Base_tc* current_TC = gHEAD_NODE_TCL;\
00950         int overCount = 0;\
00951         while( current_TC != NULL ){\
00952             if( overCount < TCL_OVERFLOW_CONSTANT ){\
00953                 if( (GETcrc_pass(current_TC) == 1) && (GETpacket_seq_count(current_TC) == execute_psc) ){\
00954                     /*CHECK FOR OBOSC*/\
00955                     uint8_t temp82 = 0x00;\
00956                     isit_obosc(current_TC, temp82);\
00957                     if(temp82 == 0x01){\
00958                         uint16_t current_exec_status = GETexec_status(current_TC);\
00959                         if( (current_exec_status == TC_STATE_SUCCESSFULLY_EXECUTED) || (current_exec_status == TC_STATE_DISABLED) )\
00960                             break;\
00961                         else if( (current_exec_status == TC_STATE_UNEXECUTED) || (current_exec_status == TC_STATE_MARKED_RETRY) ){\
00962                             if (DEBUG)\
00963                                 gPC.printf("It is obosc: %u\r\n", execute_psc);\
00964                             /*EXECUTION OF OBOSC TC*/\
00965                             /*WARNING: LARGE MEMORY UTILIZATION FOR TC-LIST-REPORT */\
00966                             Base_tm *obosc_tm_head = NULL;\
00967                             get_call_sign(obosc_tm_head);\
00968                             Base_tm *obosc_tm_core = NULL;\
00969                             execute_obosc_core(current_TC, obosc_tm_core, reset_flag);\
00970                             uint16_t temp16 = TC_STATE_SUCCESSFULLY_EXECUTED;\
00971                             PUTexec_status(current_TC, temp16);\
00972                             Base_tm *obosc_tm_current = obosc_tm_head;\
00973                             get_ack_l1(obosc_tm_current->next_TM);\
00974                             int overflowCountOBONLY = 0;\
00975                             while( obosc_tm_current->next_TM != NULL ){\
00976                                 if( overflowCountOBONLY < TM_OVERFLOW_CONSTANT ){\
00977                                     obosc_tm_current = obosc_tm_current->next_TM;\
00978                                     ++overflowCountOBONLY;\
00979                                 }\
00980                                 else{\
00981                                     /*PENDING: RESET CDMS*/\
00982                                     break;\
00983                                 }\
00984                             }\
00985                             obosc_tm_current->next_TM = obosc_tm_core;\
00986                             obosc_tm_current = obosc_tm_head;\
00987                             while( obosc_tm_current != NULL ){\
00988                                 int length = TM_SHORT_SIZE;\
00989                                 if( GETshort_or_long_tm(obosc_tm_current) == SHORT_TM_CODE ){\
00990                                     length = TM_SHORT_SIZE;\
00991                                 }\
00992                                 else{\
00993                                     length = TM_LONG_SIZE;\
00994                                 }\
00995                                 for(int i = 0 ; i < length ; ++i){\
00996                                     /*gPC.putc(obosc_tm_current->TM_string[i]);*/\
00997                                 }\
00998                                 obosc_tm_current = obosc_tm_current->next_TM;\
00999                             }\
01000                             /*Sending OBOSC TM to GS*/\
01001                             /*snd_tm.head_pointer(obosc_tm_head);*/\
01002                             /*transmit_adf;*/\
01003                             /*DELETE THE TM AFTER USE*/\
01004                             obosc_tm_current = obosc_tm_head;\
01005                             int overCount = 0;\
01006                             while( obosc_tm_current != NULL ){\
01007                                 if( (overCount < TM_OVERFLOW_CONSTANT) ){\
01008                                     Base_tm *temp = obosc_tm_current->next_TM;\
01009                                     delete obosc_tm_current;\
01010                                     obosc_tm_current = temp;\
01011                                     ++overCount;\
01012                                 }\
01013                                 else{\
01014                                     /*PENDING: RESET CDMS: MEMORY LEAK FOUND*/\
01015                                     break;\
01016                                 }\
01017                             }\
01018                             if ( reset_flag ==1 ){\
01019                                 reset_all;\
01020                             }\
01021                         }\
01022                     }\
01023                 }\
01024                 current_TC = current_TC->next_TC;\
01025                 ++overCount;\
01026             }\
01027             else{\
01028                 /*PENDING: REST CDMS: MEMORY LEAK FOUND*/\
01029                 break;\
01030             }\
01031         }\
01032     }\
01033 }
01034 
01035 #define EXECUTE_TC {\
01036     gMASTER_STATE = TCL_STATE_EXECUTING;\
01037     if (DEBUG)\
01038         gPC.puts("iNSIDE EXECUTE_TC\r\n");\
01039     /*gPC.printf("%u\r\n", gTOTAL_VALID_TC);*/\
01040     for(uint8_t execute_psc = PSC_START_VALUE ; execute_psc < gTOTAL_VALID_TC ; ++execute_psc ){\
01041         if (DEBUG)\
01042             gPC.printf("executing normal %u\r\n", execute_psc);\
01043         /*gLEDG = !gLEDG;*/\
01044         /*gLEDR = !gLEDR;*/\
01045         Base_tc* current_TC = gHEAD_NODE_TCL;\
01046         int overflowCount = 0;\
01047         while(current_TC != NULL){\
01048             if( overflowCount < TCL_OVERFLOW_CONSTANT ){\
01049                 if( (GETcrc_pass(current_TC) == 1) && (GETpacket_seq_count(current_TC) == execute_psc) ){\
01050                     uint8_t current_exec_status = GETexec_status(current_TC);\
01051                     if( (current_exec_status == TC_STATE_SUCCESSFULLY_EXECUTED) || (current_exec_status == TC_STATE_DISABLED) ){\
01052                         /*gPC.printf("disabled or completed at %u\n", execute_psc);*/\
01053                         break;\
01054                     }\
01055                     else if( (current_exec_status == TC_STATE_EXECUTION_FAILED) && (GETabort_on_nack(current_TC) == 1) ){\
01056                         /*gPC.printf("abort on nack at %u psc\r\n", execute_psc);*/\
01057                         gMASTER_STATE = TCL_STATE_ABORTED;\
01058                         Base_tm *tm_ptr_head = NULL;\
01059                         get_call_sign(tm_ptr_head);\
01060                         Base_tm *tm_ptr = tm_ptr_head;\
01061                         get_ack_l1(tm_ptr->next_TM);\
01062                         tm_ptr = tm_ptr_head;\
01063                         while( tm_ptr != NULL ){\
01064                             int length = TM_SHORT_SIZE;\
01065                             if( GETshort_or_long_tm(tm_ptr) == SHORT_TM_CODE ){\
01066                                 length = TM_SHORT_SIZE;\
01067                             }\
01068                             else{\
01069                                 length = TM_LONG_SIZE;\
01070                             }\
01071                             /*gPC.puts("Printing Call Sign, ACK_L1, TM list");*/\
01072                             for(int i = 0 ; i < length ; ++i){\
01073                                 /*gPC.putc(tm_ptr->TM_string[i]);*/\
01074                             }\
01075                             tm_ptr = tm_ptr->next_TM;\
01076                         }\ 
01077                         /*Send only call sign, ACK_L1 to GS*/\
01078                         /*snd_tm.head_pointer(tm_ptr_head);*/\
01079                         /*transmit_adf;*/\
01080                         /*DELETE THE TM AFTER USE*/\
01081                         tm_ptr = tm_ptr_head;\
01082                         int overflowCountExecute = 0;\
01083                         while(tm_ptr != NULL){\
01084                             if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\
01085                                 Base_tm *temp = tm_ptr->next_TM;\
01086                                 delete tm_ptr;\
01087                                 tm_ptr = temp;\
01088                                 ++overflowCountExecute;\
01089                             }\
01090                             else{\
01091                                 /*PENDING: RESET CDMS*/\
01092                                 break;\
01093                             }\
01094                         }\
01095                         break;\
01096                     }\
01097                     else if( (current_exec_status == TC_STATE_UNEXECUTED) || (current_exec_status == TC_STATE_MARKED_RETRY) ){\
01098                         /*EXECUTION OF TC START*/\
01099                         uint8_t temp81 = 0x00;\
01100                         isit_sdcard(current_TC, temp81);\
01101                         if( temp81 == 0x00 ){\
01102                             if (DEBUG)\
01103                                 gPC.printf("non sd card at %u\r\n", execute_psc);\
01104                             /*EXECUTION OF NON SD-CARD (BOTH OBOSC and CDMS functions)*/\
01105                             Base_tm *tm_ptr_head = NULL;\
01106                             get_call_sign(tm_ptr_head);\
01107                             Base_tm *put_tm_here = NULL;\
01108                             uint8_t temp82 = 0x00;\
01109                             uint8_t tempPAhot = 0x00;\
01110                             isit_obosc(current_TC, temp82);\
01111                             if(temp82 == 0x01){\
01112                                 /*gPC.printf("obosc tc inside normal tc at %u\r\n", execute_psc);*/\
01113                                 /*EXECUTION OF OBOSC TC*/\
01114                                 /*SKIP EXECUTION OF OBOSC HERE*/\
01115                                 break;\
01116                             }\
01117                             else{\
01118                                 /*gPC.printf("cdms relay tmtc at %u\r\n", execute_psc);*/\
01119                                 /*call CDMS_RLY_TMTC*/\
01120                                 /*CDMS_RLY_TMTC(current_TC, put_tm_here);*/\
01121                                 put_tm_here =  FCTN_CDMS_RLY_TMTC(current_TC);\
01122                             }\
01123                             /*DETECT ACK OR NACK*/\
01124                             uint8_t temp83 = 0x00;\
01125                             uint8_t temp84 = GETpacket_seq_count(current_TC);\
01126                             detect_ack(put_tm_here, temp83, temp84);\
01127                             if( temp83 == 0x01){\
01128                                 uint16_t temp16 = TC_STATE_SUCCESSFULLY_EXECUTED;\
01129                                 PUTexec_status(current_TC, temp16);\
01130                             }\
01131                             else{\
01132                                 /*gPC.puts("TC_STATE_EXECUTION_FAILED");*/\
01133                                 uint16_t temp16 = TC_STATE_EXECUTION_FAILED;\
01134                                 PUTexec_status(current_TC, temp16);\
01135                             }\
01136                             /*ABORT ON NACK AND TC LIST COMPLETED: UPDATE IN gMASTERSTATE*/\
01137                             if( (GETexec_status(current_TC) == TC_STATE_EXECUTION_FAILED) && (GETabort_on_nack(current_TC) == 1) ){\
01138                                 gMASTER_STATE = TCL_STATE_ABORTED;\
01139                             }\
01140                             else if( execute_psc == (gTOTAL_VALID_TC-1) ){\
01141                                 /*LAST TC IS EXECUTED*/\
01142                                 gMASTER_STATE = TCL_STATE_COMPLETED;\
01143                             }\
01144                             else{\
01145                                 uint8_t check1 = 1;\
01146                                 for( uint8_t test_psc = execute_psc+1 ; test_psc < gTOTAL_VALID_TC ; ++test_psc ){\
01147                                     Base_tc* test_TC = gHEAD_NODE_TCL;\
01148                                     while(test_TC != NULL){\
01149                                         if( GETpacket_seq_count(test_TC) == test_psc ){\
01150                                             uint8_t checkval;\
01151                                             isit_obosc(test_TC, checkval);\
01152                                             if( checkval == 0 ){\
01153                                                 check1 = 0;\
01154                                             }\
01155                                         }\
01156                                         test_TC = test_TC->next_TC;\
01157                                     }\
01158                                 }\
01159                                 if( check1 == 0x01 ){\
01160                                     gMASTER_STATE = TCL_STATE_COMPLETED;\
01161                                 }\
01162                             }\
01163                             /*update last executed L1_ack*/\
01164                             if( put_tm_here != NULL ){\
01165                                 if( GETshort_or_long_tm(put_tm_here) == SHORT_TM_CODE ){\
01166                                     for(int i = 0 ; i < TM_SHORT_SIZE ; ++i){\
01167                                         gLAST_TM[i] = put_tm_here->TM_string[i];\
01168                                         gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;\
01169                                     }\
01170                                 }\
01171                                 else{\
01172                                     for( int i = 0 ; i < TM_LONG_SIZE ; ++i ){\
01173                                         gLAST_TM[i] = put_tm_here->TM_string[i];\
01174                                         gLAST_TM_SHORT_OR_LONG = LONG_TM_CODE;\
01175                                     }\
01176                                 }\
01177                             }\
01178                             /*PENDING: APPEND ACK L1*/\
01179                             Base_tm *tm_ptr = tm_ptr_head;\
01180                             get_ack_l1(tm_ptr->next_TM);\
01181                             int overflowCountExecute = 0;\
01182                             while( tm_ptr->next_TM != NULL ){\
01183                                 if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\
01184                                     tm_ptr = tm_ptr->next_TM;\
01185                                     ++overflowCountExecute;\
01186                                 }\
01187                                 else{\
01188                                     /*PENDING: RESET CDMS*/\
01189                                     break;\
01190                                 }\
01191                             }\
01192                             tm_ptr->next_TM = put_tm_here;\
01193                             /*CHECK FOR HOT PA*/\
01194                             isPAhot(tempPAhot);\
01195                             if( tempPAhot == 0x00 ){\
01196                                 gFLAGS = gFLAGS | COM_PA_HOT_FLAG;\
01197                             }\
01198                             tm_ptr = tm_ptr_head;\
01199                             while( tm_ptr != NULL ){\
01200                                 int length = TM_SHORT_SIZE;\
01201                                 if( GETshort_or_long_tm(tm_ptr) == SHORT_TM_CODE ){\
01202                                     length = TM_SHORT_SIZE;\
01203                                 }\
01204                                 else{\
01205                                     length = TM_LONG_SIZE;\
01206                                 }\
01207                                 /*gPC.puts("Printing Call Sign, ACK_L1, TM list");*/\
01208                                 for(int i = 0 ; i < length ; ++i){\
01209                                     /*gPC.putc(tm_ptr->TM_string[i]);*/\
01210                                 }\
01211                                 tm_ptr = tm_ptr->next_TM;\
01212                             }\
01213                             /*SEND call sign, ACK_L1, NON OBSRS TM TO GS*/\
01214                             snd_tm.head_pointer(tm_ptr_head);\
01215                             gPC.puts("enter_adf\r\n");\
01216                             transmit_adf;\
01217                             gPC.puts("exit_adf\r\n");\ 
01218                             /*DELETE THE TM AFTER USE*/\
01219                             tm_ptr = tm_ptr_head;\
01220                             overflowCountExecute = 0;\
01221                             while(tm_ptr != NULL){\
01222                                 if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\
01223                                     Base_tm *temp = tm_ptr->next_TM;\
01224                                     delete tm_ptr;\
01225                                     tm_ptr = temp;\
01226                                     ++overflowCountExecute;\
01227                                 }\
01228                                 else{\
01229                                     /*PENDING: RESET CDMS*/\
01230                                     break;\
01231                                 }\ 
01232                             }\
01233                         }\
01234                         else{\
01235                             if (DEBUG)\
01236                                 gPC.printf("sd card at %u\r\n", execute_psc);\
01237                             /*EXECUTION OF SD-CARD DATA SENDING (OBSRS)*/\
01238                             Base_tm *tm_ptr_head = NULL;\
01239                             get_call_sign(tm_ptr_head);\
01240                             Base_tm *put_tm_here = NULL;\
01241                             /*execute_obsrs(current_TC, put_tm_here)*/\
01242                             /*read_TC(current_TC);*/\
01243                             execute_OBSRS_TC(current_TC);\
01244                             gPC.puts("en_adf");\
01245                             transmit_adf;\
01246                             gPC.puts("ex_adf");\
01247                             uint8_t tempExec = TC_STATE_SUCCESSFULLY_EXECUTED;\
01248                             PUTexec_status(current_TC, tempExec);\
01249                             /*PENDING: ABORT ON NACK CHECK, gMASTER_STATE VERIFICATION WITH SD CARD, session timeout, last executed ack l234*/\
01250                             if( (GETexec_status(current_TC) == TC_STATE_EXECUTION_FAILED) && (GETabort_on_nack(current_TC) == 1) ){\
01251                                 gMASTER_STATE = TCL_STATE_ABORTED;\
01252                             }\
01253                             else if( execute_psc == (gTOTAL_VALID_TC-1) ){\
01254                                 gMASTER_STATE = TCL_STATE_COMPLETED;\
01255                             }\
01256                             else{\
01257                                 uint8_t check1 = 1;\
01258                                 for( uint8_t test_psc = execute_psc+1 ; test_psc < gTOTAL_VALID_TC ; ++test_psc ){\
01259                                     Base_tc* test_TC = gHEAD_NODE_TCL;\
01260                                     while(test_TC != NULL){\
01261                                         if( GETpacket_seq_count(test_TC) == test_psc ){\
01262                                             uint8_t checkval;\
01263                                             isit_obosc(test_TC, checkval);\
01264                                             if( checkval == 0 ){\
01265                                                 check1 = 0;\
01266                                             }\
01267                                         }\
01268                                         test_TC = test_TC->next_TC;\
01269                                     }\
01270                                 }\
01271                                 if( check1 == 0x01 ){\
01272                                     gMASTER_STATE = TCL_STATE_COMPLETED;\
01273                                 }\
01274                             }\
01275                             /*update last executed L1_ack*/\
01276                             if( put_tm_here != NULL ){\
01277                                 if( GETshort_or_long_tm(put_tm_here) == SHORT_TM_CODE ){\
01278                                     for(int i = 0 ; i < TM_SHORT_SIZE ; ++i){\
01279                                         gLAST_TM[i] = put_tm_here->TM_string[i];\
01280                                         gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;\
01281                                     }\
01282                                 }\
01283                                 else{\
01284                                     for( int i = 0 ; i < TM_LONG_SIZE ; ++i ){\
01285                                         gLAST_TM[i] = put_tm_here->TM_string[i];\
01286                                         gLAST_TM_SHORT_OR_LONG = LONG_TM_CODE;\
01287                                     }\
01288                                 }\
01289                             }\
01290                             /*PENDING: APPEND ACK L1*/\
01291                             Base_tm *tm_ptr = tm_ptr_head;\
01292                             get_ack_l1(tm_ptr->next_TM);\
01293                             int overflowCountExecute = 0;\
01294                             while( tm_ptr->next_TM != NULL ){\
01295                                 if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\
01296                                     tm_ptr = tm_ptr->next_TM;\
01297                                     ++overflowCountExecute;\
01298                                 }\
01299                                 else{\
01300                                     /*PENDING: RESET CDMS*/\
01301                                     break;\
01302                                 }\
01303                             }\
01304                             tm_ptr->next_TM = put_tm_here;\
01305                             /*CHECK FOR HOT PA*/\
01306                             uint8_t tempPAhot = 0x00;\
01307                             isPAhot(tempPAhot);\
01308                             if( tempPAhot == 0x00 ){\
01309                                 gFLAGS = gFLAGS | COM_PA_HOT_FLAG;\
01310                             }\
01311                             tm_ptr = tm_ptr_head;\
01312                             while( tm_ptr != NULL ){\
01313                                 int length = TM_SHORT_SIZE;\
01314                                 if( GETshort_or_long_tm(tm_ptr) == SHORT_TM_CODE ){\
01315                                     length = TM_SHORT_SIZE;\
01316                                 }\
01317                                 else{\
01318                                     length = TM_LONG_SIZE;\
01319                                 }\
01320                                 /*gPC.puts("Printing Call Sign, ACK_L1, TM list");*/\
01321                                 for(int i = 0 ; i < length ; ++i){\
01322                                     /*gPC.putc(tm_ptr->TM_string[i]);*/\
01323                                 }\
01324                                 tm_ptr = tm_ptr->next_TM;\
01325                             }\
01326                             /*SEND call sign, ACK_L1, OBSRS TO GS*/\
01327                             /*snd_tm.head_pointer(tm_ptr_head);*/\
01328                             /*adf_SDcard();*/\
01329                             /*DELETE THE TM AFTER USE*/\
01330                             tm_ptr = tm_ptr_head;\
01331                             overflowCountExecute = 0;\
01332                             while(tm_ptr != NULL){\
01333                                 if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\
01334                                     Base_tm *temp = tm_ptr->next_TM;\
01335                                     delete tm_ptr;\
01336                                     tm_ptr = temp;\
01337                                     ++overflowCountExecute;\
01338                                 }\
01339                                 else{\
01340                                     /*PENDING: RESET CDMS*/\
01341                                     break;\
01342                                 }\
01343                             }\
01344                         }\
01345                     }\
01346                     break;\
01347                 }\
01348                 current_TC = current_TC->next_TC;\
01349                 ++overflowCount;\
01350             }\
01351             else{\
01352                 /*PENDING: RESET CDMS*/\
01353                 break;\
01354             }\
01355         }\
01356         if( gFLAGS & COM_SESSION_TIMEOUT_FLAG ){\
01357             break;\
01358         }\
01359         else if( gMASTER_STATE == TCL_STATE_ABORTED ){\
01360             if (DEBUG)\
01361                 gPC.puts("ABORTING DUE TO ABORT ON NACK\r\n");\
01362             /*EXITED DUE TO ABORT ON NACK:*/\
01363             /*PENDING : POWER OFF COM TX*/\
01364             RX1M.attach(&rx_read, Serial::RxIrq);\
01365             gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\
01366             break;\
01367         }\
01368         else if( gFLAGS & COM_PA_HOT_FLAG ){\
01369             /*PA HOT: WAIT FOR TIMEOUT*/\
01370             gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT);\
01371             /*PENDING : POWER OFF COMM TX*/\
01372             RX1M.attach(&rx_read, Serial::RxIrq);\
01373             gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\
01374             break;\
01375         }\
01376         if (DEBUG)\
01377             gPC.printf("successflly executed %u tc\r\n", execute_psc);\
01378     }\
01379     if( (gMASTER_STATE == TCL_STATE_COMPLETED) || (gFLAGS & COM_SESSION_TIMEOUT_FLAG) ){\
01380         if (DEBUG)\
01381             gPC.printf("completed or session timed out: %x\r\n", gMASTER_STATE);\
01382         /*COMPLETED EXECUTION OF TC*/\
01383         gMASTER_STATE = TCL_STATE_COMPLETED;\
01384         COM_POWER_OFF_TX;\
01385         reset_all;\
01386         /*PENDING : ENABLE THREADS*/\
01387         gPAY_SPI.bulkRead_start();\
01388         gSESSION_TIMEOUT.detach();\
01389         gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\
01390         gFLAGS = gFLAGS & (~COM_SESSION_FLAG);\
01391     }\
01392 }