CDMS_CODE_samp_23SEP_DMA_flag

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE_samp_23SEP_DMA by iitm sat

Revision:
215:570251b23c7b
Parent:
213:867de6d350fa
Child:
216:93505a6f8db7
--- a/COM_MNG_TMTC.h	Sun Jul 03 09:26:42 2016 +0000
+++ b/COM_MNG_TMTC.h	Sun Jul 03 09:47:05 2016 +0000
@@ -45,7 +45,7 @@
 
 
 
-#define detect_ack(tm_ptr, temp_ack) {\
+#define detect_ack(tm_ptr, temp_ack, tc_psc) {\
     if( tm_ptr != NULL ){\
         int length = TM_SHORT_SIZE;\
         if( GETshort_or_long_tm(tm_ptr) == SHORT_TM_CODE ){\
@@ -62,20 +62,20 @@
             if( (temp8 == 0xC0) || (temp8 == 0xA0) )\
                 temp_ack = 0x01;\
             else{\
-                temp_ack = 0x02;\
+                temp_ack = 0x00;\
                 /*CHECK FOR NACK CODE: CRC FAIL NACK*/\
                 temp8 = tm_ptr->TM_string[TM_ACK_CODE_INDEX];\
                 temp8 = temp8 & 0x0F;\
                 if( temp8 == CRC_FAIL_NACK_CODE ){\
-                    temp_ack = 0x04;\
+                    tm_ptr->TM_string[2] = tc_psc;\
                 }\
             }\
         }\
         else\
-            temp_ack = 0x03;\
+            temp_ack = 0x00;\
     }\
     else{\
-        temp_ack = 0x02;\
+        temp_ack = 0x00;\
     }\
 }
 
@@ -942,7 +942,6 @@
     return;
 }
 // CDMS TEAM CODE END
-
 // EXECUTE OBOSC
 #define execute_obosc_core(tc_ptr, tm_ptr, reset_flag) {\
     if (DEBUG)\
@@ -975,7 +974,7 @@
                     ++modify_overflow;\
                 }\
                 else{\
-                    RESET_CDMS;\
+                    RESET_CDMS();\
                     break;\
                 }\
             }\
@@ -998,7 +997,7 @@
                     ++modify_overflow;\
                 }\
                 else{\
-                    RESET_CDMS;\
+                    RESET_CDMS();\
                     break;\
                 }\
             }\
@@ -1042,11 +1041,13 @@
         get_tc_list(ackl234new->next_TM, GETpacket_seq_count(tc_ptr));\
     }\
     else if( service_subtype == OBOSC_SUB_RESET ){\
+        /*reset_all;*/\
         reset_flag = 1;\
+        /*PENDING: VERIFY reset_all, RESET CDMS*/\
     }\
     else if( (service_subtype != OBOSC_SUB_DISABLE) && (service_subtype != OBOSC_SUB_RETRY) ){\
         /*CHANGE THE ACK CODE TO INVALID TC*/\
-        ackl234new->TM_string[2] = 0xAF;\
+        ackl234new->TM_string[2] = 0xA2;\
     }\
     if (DEBUG)\
         gPC.puts("completed obosc\r\n");\
@@ -1056,7 +1057,6 @@
 
 
 #define EXECUTE_OBOSC_ONLY {\
-    gMASTER_STATE = TCL_STATE_EXECUTING;\
     int reset_flag = 0;\
     if (DEBUG)\
         gPC.puts("iNSIDE EXECUTE_OBOSC_ONLY\r\n");\
@@ -1085,14 +1085,8 @@
                             while(obosc_tm_core != NULL){\
                                obosc_tm_core = obosc_tm_core->next_TM;\
                             }\
-                            if(obosc_tm_current->TM_string[2] == 0xA0){\
-                                uint16_t temp16 = TC_STATE_SUCCESSFULLY_EXECUTED;\
-                                PUTexec_status(current_TC, temp16);\
-                            }\
-                            else{\
-                                uint16_t temp16 = TC_STATE_EXECUTION_FAILED;\
-                                PUTexec_status(current_TC, temp16);\
-                            }\
+                            uint16_t temp16 = TC_STATE_SUCCESSFULLY_EXECUTED;\
+                            PUTexec_status(current_TC, temp16);\
                             while( obosc_tm_current != NULL ){\
                                 int length = TM_SHORT_SIZE;\
                                 if( GETshort_or_long_tm(obosc_tm_current) == SHORT_TM_CODE ){\
@@ -1106,6 +1100,9 @@
                                 }\
                                 obosc_tm_current = obosc_tm_current->next_TM;\
                             }\
+                            if ( reset_flag ==1 ){\
+                                reset_all;\
+                            }\
                         }\
                     }\
                 }\
@@ -1113,7 +1110,7 @@
                 ++overCount;\
             }\
             else{\
-                RESET_CDMS;\
+                /*PENDING: REST CDMS: MEMORY LEAK FOUND*/\
                 break;\
             }\
         }\
@@ -1130,7 +1127,7 @@
                 ++overflowCountOBONLY;\
             }\
             else{\
-                RESET_CDMS;\
+                RESET_CDMS();\
                 break;\
             }\
         }\
@@ -1149,17 +1146,11 @@
                 ++overCount;\
             }\
             else{\
-                RESET_CDMS;\
+                RESET_CDMS();\
                 break;\
             }\
         }\
-    }\
-    if ( reset_flag == 1 ){\
-        reset_all;\
-        /*PENDING: Enable threads*/\
-        /*gCDMS_HK_TIMER.start(5000);*/\
-        gSESSION_TIMEOUT.detach();\
-    }\
+    }\    
 }
 
 #define EXECUTE_TC {\
@@ -1222,7 +1213,7 @@
                                 ++overflowCountExecute;\
                             }\
                             else{\
-                                RESET_CDMS;\
+                                RESET_CDMS();\
                                 break;\
                             }\
                         }\
@@ -1250,37 +1241,25 @@
                             }\
                             else{\
                                 /*gPC.printf("cdms relay tmtc at %u\r\n", execute_psc);*/\
+                                /*call CDMS_RLY_TMTC*/\
+                                /*CDMS_RLY_TMTC(current_TC, put_tm_here);*/\
                                 put_tm_here =  FCTN_CDMS_RLY_TMTC(current_TC);\
                             }\
                             /*DETECT ACK OR NACK*/\
                             uint8_t temp83 = 0x00;\
-                            detect_ack(put_tm_here, temp83);\
+                            uint8_t temp84 = GETpacket_seq_count(current_TC);\
+                            detect_ack(put_tm_here, temp83, temp84);\
                             if( temp83 == 0x01){\
                                 uint16_t temp16 = TC_STATE_SUCCESSFULLY_EXECUTED;\
                                 PUTexec_status(current_TC, temp16);\
                             }\
-                            else if( temp83 == 0x03){\
-                                /*gPC.puts("TC_STATE_EXECUTION_UNKNOWN");*/\
-                                uint16_t temp16 = TC_STATE_EXECUTION_UNKNOWN;\
-                                PUTexec_status(current_TC, temp16);\
-                            }\
-                            else if( temp83 == 0x04){\
-                                /*gPC.puts("TC_STATE_EXECUTION_UNKNOWN");*/\
-                                uint16_t temp16 = TC_STATE_EXECUTION_FAILED;\
-                                PUTexec_status(current_TC, temp16);\
-                                uint8_t temp84 = GETpacket_seq_count(current_TC);\
-                                put_tm_here->TM_string[2] = temp84;\
-                                uint16_t crc16 = crc16_gen(put_tm_here->TM_string, 11);\
-                                put_tm_here->TM_string[11]  = (crc16 & 0xFF00)>>8;\
-                                put_tm_here->TM_string[12] = (crc16 & 0x00FF);\
-                            }\
                             else{\
                                 /*gPC.puts("TC_STATE_EXECUTION_FAILED");*/\
                                 uint16_t temp16 = TC_STATE_EXECUTION_FAILED;\
                                 PUTexec_status(current_TC, temp16);\
                             }\
                             /*ABORT ON NACK AND TC LIST COMPLETED: UPDATE IN gMASTERSTATE*/\
-                            if( ((GETexec_status(current_TC) == TC_STATE_EXECUTION_FAILED) || (GETexec_status(current_TC) == TC_STATE_EXECUTION_UNKNOWN)) && (GETabort_on_nack(current_TC) == 1) ){\
+                            if( (GETexec_status(current_TC) == TC_STATE_EXECUTION_FAILED) && (GETabort_on_nack(current_TC) == 1) ){\
                                 gMASTER_STATE = TCL_STATE_ABORTED;\
                             }\
                             else if( execute_psc == (gTOTAL_VALID_TC-1) ){\
@@ -1289,23 +1268,20 @@
                             }\
                             /*update last executed L1_ack*/\
                             if( put_tm_here != NULL ){\
-                                Base_tm *ptr_tm = put_tm_here;\
-                                while(ptr_tm->next_TM != NULL)\
-                                    ptr_tm = ptr_tm->next_TM;\
-                                if( GETshort_or_long_tm(ptr_tm) == SHORT_TM_CODE ){\
+                                if( GETshort_or_long_tm(put_tm_here) == SHORT_TM_CODE ){\
                                     for(int i = 0 ; i < TM_SHORT_SIZE ; ++i){\
-                                        gLAST_TM[i] = ptr_tm->TM_string[i];\
+                                        gLAST_TM[i] = put_tm_here->TM_string[i];\
                                         gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;\
                                     }\
                                 }\
                                 else{\
                                     for( int i = 0 ; i < TM_LONG_SIZE ; ++i ){\
-                                        gLAST_TM[i] = ptr_tm->TM_string[i];\
+                                        gLAST_TM[i] = put_tm_here->TM_string[i];\
                                         gLAST_TM_SHORT_OR_LONG = LONG_TM_CODE;\
                                     }\
                                 }\
                             }\
-                            P_COM_HK;\
+                            /*PENDING: APPEND ACK L1*/\
                             Base_tm *tm_ptr = tm_ptr_head;\
                             get_ack_l1(tm_ptr->next_TM);\
                             int overflowCountExecute = 0;\
@@ -1315,11 +1291,16 @@
                                     ++overflowCountExecute;\
                                 }\
                                 else{\
-                                    RESET_CDMS;\
+                                    RESET_CDMS();\
                                     break;\
                                 }\
                             }\
                             tm_ptr->next_TM = put_tm_here;\
+                            /*CHECK FOR HOT PA*/\
+                            isPAhot(tempPAhot);\
+                            if( tempPAhot == 0x00 ){\
+                                gFLAGS = gFLAGS | COM_PA_HOT_FLAG;\
+                            }\
                             tm_ptr = tm_ptr_head;\
                             while( tm_ptr != NULL ){\
                                 int length = TM_SHORT_SIZE;\
@@ -1351,7 +1332,7 @@
                                     ++overflowCountExecute;\
                                 }\
                                 else{\
-                                    RESET_CDMS;\
+                                    RESET_CDMS();\
                                     break;\
                                 }\ 
                             }\
@@ -1360,7 +1341,112 @@
                             if (DEBUG)\
                                 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)*/\
+                            /*read_TC(current_TC);*/\
                             execute_OBSRS_TC(current_TC);\
+                            gPC.puts("en_adf");\
+                            transmit_adf;\
+                            gPC.puts("ex_adf");\
+                            uint8_t tempExec = TC_STATE_SUCCESSFULLY_EXECUTED;\
+                            PUTexec_status(current_TC, tempExec);\
+                            /*PENDING: ABORT ON NACK CHECK, gMASTER_STATE VERIFICATION WITH SD CARD, session timeout, last executed ack l234*/\
+                            if( (GETexec_status(current_TC) == TC_STATE_EXECUTION_FAILED) && (GETabort_on_nack(current_TC) == 1) ){\
+                                gMASTER_STATE = TCL_STATE_ABORTED;\
+                            }\
+                            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;\
+                                }\
+                            }\
+                            /*update last executed L1_ack*/\
+                            if( put_tm_here != NULL ){\
+                                if( GETshort_or_long_tm(put_tm_here) == SHORT_TM_CODE ){\
+                                    for(int i = 0 ; i < TM_SHORT_SIZE ; ++i){\
+                                        gLAST_TM[i] = put_tm_here->TM_string[i];\
+                                        gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;\
+                                    }\
+                                }\
+                                else{\
+                                    for( int i = 0 ; i < TM_LONG_SIZE ; ++i ){\
+                                        gLAST_TM[i] = put_tm_here->TM_string[i];\
+                                        gLAST_TM_SHORT_OR_LONG = LONG_TM_CODE;\
+                                    }\
+                                }\
+                            }\
+                            /*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{\
+                                    RESET_CDMS();\
+                                    break;\
+                                }\
+                            }\
+                            tm_ptr->next_TM = put_tm_here;\
+                            /*CHECK FOR HOT PA*/\
+                            uint8_t tempPAhot = 0x00;\
+                            isPAhot(tempPAhot);\
+                            if( tempPAhot == 0x00 ){\
+                                gFLAGS = gFLAGS | COM_PA_HOT_FLAG;\
+                            }\
+                            tm_ptr = tm_ptr_head;\
+                            while( tm_ptr != NULL ){\
+                                int length = TM_SHORT_SIZE;\
+                                if( GETshort_or_long_tm(tm_ptr) == 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 call sign, ACK_L1, OBSRS TO GS*/\
+                            /*snd_tm.head_pointer(tm_ptr_head);*/\
+                            /*transmit_adf;*/\
+                            /*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{\
+                                    RESET_CDMS();\
+                                    break;\
+                                }\
+                            }\
                         }\
                     }\
                     break;\
@@ -1369,7 +1455,7 @@
                 ++overflowCount;\
             }\
             else{\
-                RESET_CDMS;\
+                RESET_CDMS();\
                 break;\
             }\
         }\
@@ -1380,15 +1466,15 @@
             if (DEBUG)\
                 gPC.puts("ABORTING DUE TO ABORT ON NACK\r\n");\
             /*EXITED DUE TO ABORT ON NACK:*/\
-            COM_TX_CNTRL = 0;\
+            /*COM_TX_CNTRL = 0;*/\
             RX1M.attach(&rx_read, Serial::RxIrq);\
             gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\
             break;\
         }\
-        else if( (gFLAGS & COM_PA_HOT_FLAG) || (gFLAGS & COM_PA_OC_FLAG) ){\
+        else if( gFLAGS & COM_PA_HOT_FLAG ){\
             /*PA HOT: WAIT FOR TIMEOUT*/\
             gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT);\
-            COM_TX_CNTRL = 0;\
+            /*COM_TX_CNTRL = 0;*/\
             RX1M.attach(&rx_read, Serial::RxIrq);\
             gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\
             break;\
@@ -1401,10 +1487,9 @@
             gPC.printf("completed or session timed out: %x\r\n", gMASTER_STATE);\
         /*COMPLETED EXECUTION OF TC*/\
         gMASTER_STATE = TCL_STATE_COMPLETED;\
-        COM_POWER_OFF_TX;\
+        /*COM_POWER_OFF_TX;*/\
         reset_all;\
         /*PENDING : ENABLE THREADS*/\
-        /*gCDMS_HK_TIMER.start(5000);*/\
         gPAY_SPI.bulkRead_start();\
         gSESSION_TIMEOUT.detach();\
         gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\