pl ack in tmtc

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of COM_MNG_TMTC_SIMPLE_pl123 by shubham c

Revision:
37:c9a739750806
Parent:
23:c89376564196
Child:
44:b9b067d0559f
--- a/COM_MNG_TMTC.h	Wed Jan 06 13:24:24 2016 +0000
+++ b/COM_MNG_TMTC.h	Sat Jan 09 09:56:01 2016 +0000
@@ -168,8 +168,8 @@
     returnHere = tempReturn;\
     /*UPDATE gMASTER STATE*/\
     if( (returnHere == 0x00) ){\
-        if( (gMASTER_STATE == TCL_STATE_INCOMPLETE) || (gMASTER_STATE == TCL_STATE_COMPLETED) ){\
-            gMASTER_STATE = TCL_STATE_COMPLETED;\
+        if( (gMASTER_STATE == TCL_STATE_INCOMPLETE) || (gMASTER_STATE == TCL_STATE_COMPLETED) || (gMASTER_STATE == TCL_STATE_ABORTED) ){\
+            gMASTER_STATE = TCL_STATE_EXECUTING;\
         }\
     }\
     else{\
@@ -189,8 +189,8 @@
     returnHere = 0xFF;\
     while( (overflowCount < TCL_OVERFLOW_CONSTANT) && (testTC != NULL) ){\
         if( (GETpacket_seq_count(testTC) == PSC_CALLSIGN) && (GETapid(testTC) == APID_CALLSIGN) ){\
-            uint8_t temp8 = testTC->TC_string[1];\
-            if( temp8 & 0x04 ){\
+            /*uint8_t temp8 = testTC->TC_string[1];*/\
+            if( true ){\
                 for( int i = 2 ; i <= 8 ; ++i ){\
                     if( testTC->TC_string[i] != gGSCODE[i-2] ){\
                         returnHere = 0;\
@@ -539,21 +539,6 @@
 }
 
 #define EXECUTE_OBOSC_ONLY {\
-    Base_tm *obosc_tm_head = NULL;\
-    get_call_sign(obosc_tm_head);\
-    Base_tm *obosc_tm_current = obosc_tm_head;\
-    get_ack_l1(obosc_tm_current->next_TM);\
-    int overflowCountOBONLY = 0;\
-    while( obosc_tm_current->next_TM != NULL ){\
-        if( overflowCountOBONLY < TM_OVERFLOW_CONSTANT ){\
-            obosc_tm_current = obosc_tm_current->next_TM;\
-            ++overflowCountOBONLY;\
-        }\
-        else{\
-            /*PENDING: RESET CDMS*/\
-            break;\
-        }\
-    }\
     for(uint8_t execute_psc = PSC_START_VALUE ; execute_psc < gTOTAL_VALID_TC ; ++execute_psc){\
         Base_tc* current_TC = gHEAD_NODE_TCL;\
         int overCount = 0;\
@@ -571,19 +556,55 @@
                             /*gPC.printf("It is obosc: %u\r\n", execute_psc);*/\
                             /*EXECUTION OF OBOSC TC*/\
                             /*WARNING: LARGE MEMORY UTILIZATION FOR TC-LIST-REPORT */\
-                            execute_obosc_core(current_TC, obosc_tm_current->next_TM);\
-                            /*INCREMENT POINTER TO THE LAST NODE*/\
-                            int overflowCountOBinside = 0;\
+                            Base_tm *obosc_tm_head = NULL;\
+                            get_call_sign(obosc_tm_head);\
+                            Base_tm *obosc_tm_core = NULL;\
+                            execute_obosc_core(current_TC, obosc_tm_core);\
+                            Base_tm *obosc_tm_current = obosc_tm_head;\
+                            get_ack_l1(obosc_tm_current->next_TM);\
+                            int overflowCountOBONLY = 0;\
                             while( obosc_tm_current->next_TM != NULL ){\
-                                if( overflowCountOBinside < TM_OVERFLOW_CONSTANT ){\
+                                if( overflowCountOBONLY < TM_OVERFLOW_CONSTANT ){\
                                     obosc_tm_current = obosc_tm_current->next_TM;\
-                                    ++overflowCountOBinside;\
+                                    ++overflowCountOBONLY;\
                                 }\
                                 else{\
                                     /*PENDING: RESET CDMS*/\
                                     break;\
                                 }\
                             }\
+                            obosc_tm_current->next_TM = obosc_tm_core;\
+                            obosc_tm_current = obosc_tm_head;\
+                            while( obosc_tm_current != NULL ){\
+                                int length = TM_SHORT_SIZE;\
+                                if( GETshort_or_long_tm(obosc_tm_current->fields) == SHORT_TM_CODE ){\
+                                    length = TM_SHORT_SIZE;\
+                                }\
+                                else{\
+                                    length = TM_LONG_SIZE;\
+                                }\
+                                for(int i = 0 ; i < length ; ++i){\
+                                    gPC.putc(obosc_tm_current->TM_string[i]);\
+                                }\
+                                obosc_tm_current = obosc_tm_current->next_TM;\
+                            }\
+                            /*snd_tm.head_pointer(obosc_tm_head);*/\
+                            /*adf_not_SDcard();*/\
+                            /*DELETE THE TM AFTER USE*/\
+                            obosc_tm_current = obosc_tm_head;\
+                            int overCount = 0;\
+                            while( obosc_tm_current != NULL ){\
+                                if( (overCount < TM_OVERFLOW_CONSTANT) ){\
+                                    Base_tm *temp = obosc_tm_current->next_TM;\
+                                    delete obosc_tm_current;\
+                                    obosc_tm_current = temp;\
+                                    ++overCount;\
+                                }\
+                                else{\
+                                    /*PENDING: RESET CDMS: MEMORY LEAK FOUND*/\
+                                    break;\
+                                }\
+                            }\
                             uint16_t temp16 = TC_STATE_SUCCESSFULLY_EXECUTED;\
                             PUTexec_status(current_TC, temp16);\
                         }\
@@ -598,37 +619,6 @@
             }\
         }\
     }\
-    obosc_tm_current = obosc_tm_head;\
-    while( obosc_tm_current != NULL ){\
-        int length = TM_SHORT_SIZE;\
-        if( GETshort_or_long_tm(obosc_tm_current->fields) == SHORT_TM_CODE ){\
-            length = TM_SHORT_SIZE;\
-        }\
-        else{\
-            length = TM_LONG_SIZE;\
-        }\
-        for(int i = 0 ; i < length ; ++i){\
-            gPC.putc(obosc_tm_current->TM_string[i]);\
-        }\
-        obosc_tm_current = obosc_tm_current->next_TM;\
-    }\
-    /*snd_tm.head_pointer(obosc_tm_head);*/\
-    /*adf_not_SDcard();*/\
-    /*DELETE THE TM AFTER USE*/\
-    obosc_tm_current = obosc_tm_head;\
-    int overCount = 0;\
-    while( obosc_tm_current != NULL ){\
-        if( (overCount < TM_OVERFLOW_CONSTANT) ){\
-            Base_tm *temp = obosc_tm_current->next_TM;\
-            delete obosc_tm_current;\
-            obosc_tm_current = temp;\
-            ++overCount;\
-        }\
-        else{\
-            /*PENDING: RESET CDMS: MEMORY LEAK FOUND*/\
-            break;\
-        }\
-    }\
 }
 
 #define EXECUTE_TC {\
@@ -670,6 +660,7 @@
                                 /*gPC.printf("obosc tc inside normal tc at %u\r\n", execute_psc);*/\
                                 /*EXECUTION OF OBOSC TC*/\
                                 /*SKIP EXECUTION OF OBOSC HERE*/\
+                                break;\
                             }\
                             else{\
                                 /*gPC.printf("cdms relay tmtc at %u\r\n", execute_psc);*/\
@@ -697,6 +688,25 @@
                                 /*LAST TC IS EXECUTED*/\
                                 gMASTER_STATE = TCL_STATE_COMPLETED;\
                             }\
+                            else{\
+                                uint8_t check1 = 1;\
+                                for( uint8_t test_psc = execute_psc+1 ; test_psc < gTOTAL_VALID_TC ; ++test_psc ){\
+                                    Base_tc* test_TC = gHEAD_NODE_TCL;\
+                                    while(test_TC != NULL){\
+                                        if( GETpacket_seq_count(test_TC) == test_psc ){\
+                                            uint8_t checkval;\
+                                            isit_obosc(test_TC, checkval);\
+                                            if( checkval == 0 ){\
+                                                check1 = 0;\
+                                            }\
+                                        }\
+                                        test_TC = test_TC->next_TC;\
+                                    }\
+                                }\
+                                if( check1 == 0x01 ){\
+                                    gMASTER_STATE = TCL_STATE_COMPLETED;\
+                                }\
+                            }\
                             /*update last executed L1_ack*/\
                             if( put_tm_here != NULL ){\
                                 if( GETshort_or_long_tm(put_tm_here->fields) == SHORT_TM_CODE ){\
@@ -769,6 +779,25 @@
                         else{\
                             /*gPC.printf("sd card at %u\r\n", execute_psc);*/\
                             /*EXECUTION OF SD-CARD DATA SENDING (OBSRS)*/\
+                            Base_tm *tm_ptr_head = NULL;\
+                            get_call_sign(tm_ptr_head);\
+                            Base_tm *put_tm_here = NULL;\
+                            /*execute_obsrs(current_TC, put_tm_here)*/\
+                            /*PENDING: APPEND ACK L1*/\
+                            Base_tm *tm_ptr = tm_ptr_head;\
+                            get_ack_l1(tm_ptr->next_TM);\
+                            int overflowCountExecute = 0;\
+                            while( tm_ptr->next_TM != NULL ){\
+                                if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\
+                                    tm_ptr = tm_ptr->next_TM;\
+                                    ++overflowCountExecute;\
+                                }\
+                                else{\
+                                    /*PENDING: RESET CDMS*/\
+                                    break;\
+                                }\
+                            }\
+                            tm_ptr->next_TM = put_tm_here;\
                             /*CHECK FOR HOT PA*/\
                             uint8_t tempPAhot = 0x00;\
                             isPAhot(tempPAhot);\
@@ -785,6 +814,58 @@
                             else if( execute_psc == (gTOTAL_VALID_TC-1) ){\
                                 gMASTER_STATE = TCL_STATE_COMPLETED;\
                             }\
+                            else{\
+                                uint8_t check1 = 1;\
+                                for( uint8_t test_psc = execute_psc+1 ; test_psc < gTOTAL_VALID_TC ; ++test_psc ){\
+                                    Base_tc* test_TC = gHEAD_NODE_TCL;\
+                                    while(test_TC != NULL){\
+                                        if( GETpacket_seq_count(test_TC) == test_psc ){\
+                                            uint8_t checkval;\
+                                            isit_obosc(test_TC, checkval);\
+                                            if( checkval == 0 ){\
+                                                check1 = 0;\
+                                            }\
+                                        }\
+                                        test_TC = test_TC->next_TC;\
+                                    }\
+                                }\
+                                if( check1 == 0x01 ){\
+                                    gMASTER_STATE = TCL_STATE_COMPLETED;\
+                                }\
+                            }\
+                            tm_ptr = tm_ptr_head;\
+                            while( tm_ptr != NULL ){\
+                                int length = TM_SHORT_SIZE;\
+                                if( GETshort_or_long_tm(tm_ptr->fields) == SHORT_TM_CODE ){\
+                                    length = TM_SHORT_SIZE;\
+                                }\
+                                else{\
+                                    length = TM_LONG_SIZE;\
+                                }\
+                                /*gPC.puts("Printing Call Sign, ACK_L1, TM list");*/\
+                                for(int i = 0 ; i < length ; ++i){\
+                                    gPC.putc(tm_ptr->TM_string[i]);\
+                                }\
+                                tm_ptr = tm_ptr->next_TM;\
+                            }\
+                            /*SEND DATA TO GS*/\
+                            /*snd_tm.head_pointer(tm_ptr_head);*/\
+                            /*adf_SDcard();*/\
+                            /*DELETE THE TM AFTER USE*/\
+                            tm_ptr = tm_ptr_head;\
+                            overflowCountExecute = 0;\
+                            while(tm_ptr != NULL){\
+                                if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\
+                                    Base_tm *temp = tm_ptr->next_TM;\
+                                    delete tm_ptr;\
+                                    tm_ptr = temp;\
+                                    ++overflowCountExecute;\
+                                }\
+                                else{\
+                                    /*PENDING: RESET CDMS*/\
+                                    break;\
+                                }\
+                            }\
                         }\
                     }\
                     break;\