Repository for CDMS code

Dependencies:   SimpleDMA mbed-rtos mbed eeprom

Fork of COM_MNG_TMTC_SIMPLE by Shreesha S

Files at this revision

API Documentation at this revision

Comitter:
shreeshas95
Date:
Thu Dec 31 06:43:13 2015 +0000
Parent:
5:ab276a17ca07
Child:
7:fcd26c28411d
Child:
8:f0448a307351
Commit message:
After testing on 30 Dec 2015

Changed in this revision

COM_MNG_TMTC.h Show annotated file Show diff for this revision Revisions of this file
DefinitionsAndGlobals.h Show annotated file Show diff for this revision Revisions of this file
Structures.h Show annotated file Show diff for this revision Revisions of this file
ThreadsAndFunctions.h Show annotated file Show diff for this revision Revisions of this file
crc.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/COM_MNG_TMTC.h	Wed Dec 30 06:36:38 2015 +0000
+++ b/COM_MNG_TMTC.h	Thu Dec 31 06:43:13 2015 +0000
@@ -744,10 +744,15 @@
                                 gFLAGS = gFLAGS | COM_PA_HOT_FLAG;\
                             }\
                             /*read_TC(current_TC);*/\
-                            /*PENDING: ABORT ON NACK CHECK WITH SD CARD*/\
+                            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+PSC_START_VALUE-1) ){\
+                                gMASTER_STATE = TCL_STATE_COMPLETED;\
+                            }\
                         }\
                     }\
                     break;\
@@ -760,7 +765,10 @@
                 break;\
             }\
         }\
-        if( gMASTER_STATE == TCL_STATE_ABORTED ){\
+        if( gFLAGS & COM_SESSION_TIMEOUT_FLAG ){\
+            break;\
+        }\
+        else if( gMASTER_STATE == TCL_STATE_ABORTED ){\
             gPC.puts("ABORTING DUE TO ABORT ON NACK\r\n");\
             /*EXITED DUE TO ABORT ON NACK:*/\
             /*PENDING : POWER OFF COM TX*/\
@@ -778,7 +786,8 @@
         }\
         gPC.printf("successflly executed %u tc\r\n", execute_psc);\
     }\
-    if( gMASTER_STATE != TCL_STATE_ABORTED ){\
+    if( (gMASTER_STATE == TCL_STATE_COMPLETED) || (gFLAGS & COM_SESSION_TIMEOUT_FLAG) ){\
+        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;\
--- a/DefinitionsAndGlobals.h	Wed Dec 30 06:36:38 2015 +0000
+++ b/DefinitionsAndGlobals.h	Thu Dec 31 06:43:13 2015 +0000
@@ -35,9 +35,10 @@
     #define ALL_CRC_PASS_FLAG 0x0040
     #define COM_PA_HOT_FLAG 0x0080
     #define COM_TX_FLAG 0x0100
+    #define COM_SESSION_TIMEOUT_FLAG 0x0200
 
 // COM_MNG_TMTC THREAD
-    #define SESSION_TIME_LIMIT 1200
+    #define SESSION_TIME_LIMIT 1500
     #define COM_MNG_TMTC_SIGNAL_UART_INT 0x01
     #define COM_MNG_TMTC_SIGNAL_ADF_NSD 0x02
     #define COM_MNG_TMTC_SIGNAL_ADF_SD 0x03
--- a/Structures.h	Wed Dec 30 06:36:38 2015 +0000
+++ b/Structures.h	Thu Dec 31 06:43:13 2015 +0000
@@ -51,7 +51,7 @@
 #define GETpacket_seq_count(x) (x->TC_string[0])
 
 //x should be a Base_tc pointer
-//y should be a 16-bit number with relevant data in LSB
+//y should be a 8-bit number with relevant data in LSB
 //use in a seperate line with ; at the end: similar to a function
 #define PUTshort_or_long(x,y) x->flags = ( (x->flags) & ~(SHORT_LONG_TC_MASK)) | ( (y << 4) & SHORT_LONG_TC_MASK )
 #define PUTcrc_pass(x,y) x->flags = ( (x->flags) & ~(CRC_MASK)) | ( (y << 3) & CRC_MASK)
--- a/ThreadsAndFunctions.h	Wed Dec 30 06:36:38 2015 +0000
+++ b/ThreadsAndFunctions.h	Thu Dec 31 06:43:13 2015 +0000
@@ -15,8 +15,10 @@
 // SESSION_TIMOUT ISR
 void after_session(){
     gSESSION_TIMEOUT.detach();
-    gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
-    gCOM_MNG_TMTC_THREAD->signal_set(COM_MNG_TMTC_SIGNAL_UART_INT);
+    gFLAGS = gFLAGS | COM_SESSION_TIMEOUT_FLAG;
+    if( gMASTER_STATE != TCL_STATE_EXECUTING ){
+        gCOM_MNG_TMTC_THREAD->signal_set(COM_MNG_TMTC_SIGNAL_UART_INT);
+    }
 }
 
 #define reset_all {\
@@ -102,7 +104,6 @@
         else if( gFLAGS & NEW_TC_RECEIVED ){
             gPC.puts("NEW TC RECEIVED\r\n");
             gFLAGS = gFLAGS & (~NEW_TC_RECEIVED);
-            gFLAGS = gFLAGS & (~COM_RX_FLAG);
             gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG;
 
             // DISABLE THE RX1M INTERRUPT
@@ -115,6 +116,7 @@
             }
             gRX_COUNT = 0;
             raw_data_to_tc();
+            gFLAGS = gFLAGS & (~COM_RX_FLAG);
 
             if( gTOTAL_VALID_TC > 0 ){
                 gPC.printf("valid TC rx: %u\r\n", gTOTAL_VALID_TC);
@@ -137,6 +139,8 @@
                             uint8_t tempPAHot = 0x00;
                             isPAhot(tempPAHot);
                             if( tempPAHot == 0xFF ){
+                                gFLAGS = gFLAGS & ~(COM_PA_HOT_FLAG);
+                                gCOM_PA_COOLING_TIMEOUT.detach();
                                 gPC.puts("EXECUTING TELECOMMANDS\r\n");
                                 EXECUTE_OBOSC_ONLY;
                                 EXECUTE_TC;
@@ -144,13 +148,15 @@
                             }
                             else{
                                 gFLAGS = gFLAGS | COM_PA_HOT_FLAG;
-                                COM_POWER_OFF_TX;
+                                // PENDING: power off transmitter only
+                                gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT);
+                                gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
                                 RX1M.attach(&rx_read, Serial::RxIrq);
-                                gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
                             }
                         }
                         else{
                             gPC.puts("GS code mismatch !!\r\n");
+                            RX1M.attach(&rx_read, Serial::RxIrq);
                             reset_all;
                             gFLAGS = gFLAGS & (~COM_SESSION_VALIDITY);
                             // PENDING : ENABLE THREADS
@@ -194,41 +200,64 @@
                 }
                 else{
                     COM_POWER_ON_TX;
-                    // POWER OFF TX
+                    // POWER OFF TX transmitter only
                     // WARNING: reset_all ? clear com_session ?
                     RX1M.attach(&rx_read, Serial::RxIrq);
                     gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
                 }
             }
             else{
-                gPC.puts("No valid TC recweived\r\n");
+                gPC.puts("No valid TC received\r\n");
                 RX1M.attach(&rx_read, Serial::RxIrq);
                 gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
-
-                if( !(gFLAGS & COM_TX_FLAG) ){
-                    reset_all;
-                    // PENDING : ENABLE THREADS
-                    gSESSION_TIMEOUT.detach();
-                    gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
-                }
-                // else wait
+                reset_all;
+                // PENDING : ENABLE THREADS
+                gSESSION_TIMEOUT.detach();
+                gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
             }
         }
         else if( gFLAGS & COM_PA_HOT_FLAG ){
-            uint8_t tempPA = 0xFF;
-            isPAhot(tempPA);
-            if( tempPA == 0x00 ){
-                gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT);
+            gPC.puts("checking for PA hot in main\r\n");
+            if( gFLAGS & COM_RX_FLAG ){
+                uint8_t tempPA = 0xFF;
+                isPAhot(tempPA);
+                if( tempPA == 0x00 ){
+                    gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT);
+                }
+                else{
+                    gFLAGS = gFLAGS & ~(COM_PA_HOT_FLAG);
+                    gCOM_PA_COOLING_TIMEOUT.detach();
+                }
             }
             else{
-                gFLAGS = gFLAGS & (~COM_PA_HOT_FLAG);
-                gCOM_PA_COOLING_TIMEOUT.detach();
-                COM_POWER_ON_TX;
-                EXECUTE_OBOSC_ONLY;
-                EXECUTE_TC;
+                uint8_t tempPA = 0xFF;
+                isPAhot(tempPA);
+                if( tempPA == 0x00 ){
+                    gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT);
+                }
+                else{
+                    gPC.puts("PA IS COOLED DOWN\r\n");
+                    gFLAGS = gFLAGS & (~COM_PA_HOT_FLAG);
+                    gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG;
+                    RX1M.attach(NULL);
+                    gCOM_PA_COOLING_TIMEOUT.detach();
+                    COM_POWER_ON_TX;
+                    EXECUTE_OBOSC_ONLY;
+                    EXECUTE_TC;
+                }
             }
         }
+        else if( gFLAGS & COM_SESSION_TIMEOUT_FLAG ){
+            gPC.puts("session timeout: resetting in main\r\n");
+            COM_POWER_OFF_TX;
+            /*PENDING : ENABLE THREADS*/
+            gSESSION_TIMEOUT.detach();
+            gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);
+            gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
+            reset_all;
+        }
         else{
+            gPC.puts("INVALID SIGNAL RECEIVED IN MAIN\r\n");
             // SOME INVALID SIGNAL RECEIVED
             COM_POWER_OFF_TX;
             reset_all;
--- a/crc.h	Wed Dec 30 06:36:38 2015 +0000
+++ b/crc.h	Thu Dec 31 06:43:13 2015 +0000
@@ -5,7 +5,7 @@
 #define TOPBIT16 (1 << 15)
 #define TOPBIT8 (1 << 7)
 #define POLYNOMIAL16 0x1021
-#define POLYNOMIAL8 0xEA
+#define POLYNOMIAL8 0x07
 
 typedef uint16_t crctype16; 
 crctype16 crc16_gen(const unsigned char message[], unsigned int nBytes){
--- a/main.cpp	Wed Dec 30 06:36:38 2015 +0000
+++ b/main.cpp	Thu Dec 31 06:43:13 2015 +0000
@@ -55,12 +55,6 @@
     
     int theAcount = 0;
     while(true){
-        if(theAcount >= 700000){
-            theAcount = 0;
-            //gLEDR = !gLEDR;
-        }
-        else{
-            theAcount++;
-        }
+        Thread::wait(osWaitForever);
     }
 }
\ No newline at end of file