
Compression code changed and RLY_TMTC pointers managed
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE by
ThreadsAndFunctions.h@186:eb19a02f83d6, 2016-06-17 (annotated)
- Committer:
- ee12b079
- Date:
- Fri Jun 17 13:41:43 2016 +0000
- Revision:
- 186:eb19a02f83d6
- Parent:
- 182:8b73c010286b
Testing spi ..
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ee12b079 | 173:f81ded27423d | 1 | //Science Thread |
ee12b079 | 173:f81ded27423d | 2 | //SPI ISR |
ee12b079 | 173:f81ded27423d | 3 | void payload_isr_fun(){ |
ee12b079 | 173:f81ded27423d | 4 | gSCIENCE_THREAD->signal_set(SCIENCE_SIGNAL); |
ee12b079 | 173:f81ded27423d | 5 | } |
ee12b079 | 173:f81ded27423d | 6 | |
ee12b079 | 173:f81ded27423d | 7 | void SCIENCE_FUN(void const *args){ |
ee12b079 | 173:f81ded27423d | 8 | |
ee12b079 | 173:f81ded27423d | 9 | // initialisation of payload spi |
ee12b079 | 173:f81ded27423d | 10 | gPAY_SPI.frequency(1000000); |
ee12b079 | 173:f81ded27423d | 11 | gPAY_SPI.format(8,0); |
ee12b079 | 173:f81ded27423d | 12 | gPAY_SPI.bulkRead_init(gPAYLOAD_BUFFER, PAYLOAD_BUFFER_LENGTH, &payload_isr_fun); |
ee12b079 | 173:f81ded27423d | 13 | gPAY_SPI.bulkRead_start(); |
ee12b079 | 177:2fa8582896e0 | 14 | |
ee12b079 | 173:f81ded27423d | 15 | while(true){ |
ee12b079 | 173:f81ded27423d | 16 | gPC.puts("entering sci\r\n"); |
ee12b079 | 173:f81ded27423d | 17 | gSCIENCE_THREAD->signal_wait(SCIENCE_SIGNAL); |
ee12b079 | 173:f81ded27423d | 18 | gPC.puts("sig_set\r\n"); |
ee12b079 | 173:f81ded27423d | 19 | srp(gPAYLOAD_BUFFER); |
ee12b079 | 173:f81ded27423d | 20 | gPC.puts("exit_srp\r\n"); |
ee12b079 | 173:f81ded27423d | 21 | gPAY_SPI.bulkRead_start(); |
ee12b079 | 175:e869e7837978 | 22 | |
ee12b079 | 173:f81ded27423d | 23 | } |
ee12b079 | 173:f81ded27423d | 24 | } |
ee12b079 | 173:f81ded27423d | 25 | |
ee12b079 | 173:f81ded27423d | 26 | //COM THREAD |
ee12b079 | 186:eb19a02f83d6 | 27 | |
ee12b079 | 186:eb19a02f83d6 | 28 | #define STANDBY_SCIENCE_PL(tm_ptr) {\ |
ee12b079 | 186:eb19a02f83d6 | 29 | Base_tc *linktest_tc = new Short_tc;\ |
ee12b079 | 186:eb19a02f83d6 | 30 | linktest_tc->next_TC = NULL;\ |
ee12b079 | 186:eb19a02f83d6 | 31 | PUTshort_or_long(linktest_tc,SHORT_TC_CODE);\ |
ee12b079 | 186:eb19a02f83d6 | 32 | PUTcrc_pass(linktest_tc,0x1);\ |
ee12b079 | 186:eb19a02f83d6 | 33 | PUTexec_status(linktest_tc,0);\ |
ee12b079 | 186:eb19a02f83d6 | 34 | linktest_tc->TC_string[0] = 0x01;\ |
ee12b079 | 186:eb19a02f83d6 | 35 | linktest_tc->TC_string[1] = 0xC0;\ |
ee12b079 | 186:eb19a02f83d6 | 36 | linktest_tc->TC_string[2] = 0x81;\ |
ee12b079 | 186:eb19a02f83d6 | 37 | linktest_tc->TC_string[3] = 0x2;\ |
ee12b079 | 186:eb19a02f83d6 | 38 | linktest_tc->TC_string[4] = 0;\ |
ee12b079 | 186:eb19a02f83d6 | 39 | linktest_tc->TC_string[5] = 0;\ |
ee12b079 | 186:eb19a02f83d6 | 40 | linktest_tc->TC_string[6] = 0;\ |
ee12b079 | 186:eb19a02f83d6 | 41 | linktest_tc->TC_string[7] = 0;\ |
ee12b079 | 186:eb19a02f83d6 | 42 | linktest_tc->TC_string[8] = 0;\ |
ee12b079 | 186:eb19a02f83d6 | 43 | uint16_t crc16 = crc16_gen(linktest_tc->TC_string, 9);\ |
ee12b079 | 186:eb19a02f83d6 | 44 | linktest_tc->TC_string[9] = (crc16 & 0xFF00)>>8;\ |
ee12b079 | 186:eb19a02f83d6 | 45 | linktest_tc->TC_string[10] = (crc16 & 0x00FF);\ |
ee12b079 | 186:eb19a02f83d6 | 46 | tm_ptr = FCTN_CDMS_RLY_TMTC(linktest_tc);\ |
ee12b079 | 186:eb19a02f83d6 | 47 | } |
ee12b079 | 186:eb19a02f83d6 | 48 | |
ee12b079 | 186:eb19a02f83d6 | 49 | #define INIT_SCIENCE_PL(tm_ptr) {\ |
ee12b079 | 186:eb19a02f83d6 | 50 | Base_tc *linktest_tc = new Short_tc;\ |
ee12b079 | 186:eb19a02f83d6 | 51 | linktest_tc->next_TC = NULL;\ |
ee12b079 | 186:eb19a02f83d6 | 52 | PUTshort_or_long(linktest_tc,SHORT_TC_CODE);\ |
ee12b079 | 186:eb19a02f83d6 | 53 | PUTcrc_pass(linktest_tc,0x1);\ |
ee12b079 | 186:eb19a02f83d6 | 54 | PUTexec_status(linktest_tc,0);\ |
ee12b079 | 186:eb19a02f83d6 | 55 | linktest_tc->TC_string[0] = 0x02;\ |
ee12b079 | 186:eb19a02f83d6 | 56 | linktest_tc->TC_string[1] = 0xC0;\ |
ee12b079 | 186:eb19a02f83d6 | 57 | linktest_tc->TC_string[2] = 0x81;\ |
ee12b079 | 186:eb19a02f83d6 | 58 | linktest_tc->TC_string[3] = 0x4;\ |
ee12b079 | 186:eb19a02f83d6 | 59 | linktest_tc->TC_string[4] = 0;\ |
ee12b079 | 186:eb19a02f83d6 | 60 | linktest_tc->TC_string[5] = 0;\ |
ee12b079 | 186:eb19a02f83d6 | 61 | linktest_tc->TC_string[6] = 0;\ |
ee12b079 | 186:eb19a02f83d6 | 62 | linktest_tc->TC_string[7] = 0;\ |
ee12b079 | 186:eb19a02f83d6 | 63 | linktest_tc->TC_string[8] = 0;\ |
ee12b079 | 186:eb19a02f83d6 | 64 | uint16_t crc16 = crc16_gen(linktest_tc->TC_string, 9);\ |
ee12b079 | 186:eb19a02f83d6 | 65 | linktest_tc->TC_string[9] = (crc16 & 0xFF00)>>8;\ |
ee12b079 | 186:eb19a02f83d6 | 66 | linktest_tc->TC_string[10] = (crc16 & 0x00FF);\ |
ee12b079 | 186:eb19a02f83d6 | 67 | tm_ptr = FCTN_CDMS_RLY_TMTC(linktest_tc);\ |
ee12b079 | 186:eb19a02f83d6 | 68 | } |
ee12b079 | 186:eb19a02f83d6 | 69 | |
ee12b079 | 186:eb19a02f83d6 | 70 | |
ee12b079 | 186:eb19a02f83d6 | 71 | |
shreeshas95 | 0:f016e9e8d48b | 72 | // UART ISR |
shreeshas95 | 0:f016e9e8d48b | 73 | void rx_read(){ |
shreeshas95 | 2:2caf2a9a13aa | 74 | gRX_CURRENT_DATA_NODE->values[gRX_COUNT] = RX1M.getc(); |
shreeshas95 | 2:2caf2a9a13aa | 75 | gFLAGS = gFLAGS | UART_INT_FLAG; |
shreeshas95 | 0:f016e9e8d48b | 76 | gCOM_MNG_TMTC_THREAD->signal_set(COM_MNG_TMTC_SIGNAL_UART_INT); |
shreeshas95 | 0:f016e9e8d48b | 77 | } |
shreeshas95 | 0:f016e9e8d48b | 78 | |
shreeshas95 | 0:f016e9e8d48b | 79 | // RX_TIMEOUT ISR |
shreeshas95 | 0:f016e9e8d48b | 80 | void after_receive(){ |
shreeshas95 | 0:f016e9e8d48b | 81 | gRX_TIMEOUT.detach(); |
shreeshas95 | 2:2caf2a9a13aa | 82 | gFLAGS = gFLAGS | NEW_TC_RECEIVED; |
shreeshas95 | 0:f016e9e8d48b | 83 | gCOM_MNG_TMTC_THREAD->signal_set(COM_MNG_TMTC_SIGNAL_UART_INT); |
shreeshas95 | 0:f016e9e8d48b | 84 | } |
shreeshas95 | 0:f016e9e8d48b | 85 | |
shreeshas95 | 0:f016e9e8d48b | 86 | // SESSION_TIMOUT ISR |
shreeshas95 | 0:f016e9e8d48b | 87 | void after_session(){ |
shreeshas95 | 0:f016e9e8d48b | 88 | gSESSION_TIMEOUT.detach(); |
shreeshas95 | 6:79d422d1ed42 | 89 | gFLAGS = gFLAGS | COM_SESSION_TIMEOUT_FLAG; |
shreeshas95 | 6:79d422d1ed42 | 90 | if( gMASTER_STATE != TCL_STATE_EXECUTING ){ |
shreeshas95 | 6:79d422d1ed42 | 91 | gCOM_MNG_TMTC_THREAD->signal_set(COM_MNG_TMTC_SIGNAL_UART_INT); |
shreeshas95 | 6:79d422d1ed42 | 92 | } |
shreeshas95 | 0:f016e9e8d48b | 93 | } |
shreeshas95 | 0:f016e9e8d48b | 94 | |
shreeshas95 | 0:f016e9e8d48b | 95 | #define reset_all {\ |
shreeshas95 | 0:f016e9e8d48b | 96 | Base_tc *tcp = gHEAD_NODE_TCL;\ |
aniruddhv | 12:ffdb29353058 | 97 | /*gPC.puts("inside reset\r\n");*/\ |
shreeshas95 | 5:ab276a17ca07 | 98 | gFLAGS = 0x0000;\ |
shreeshas95 | 0:f016e9e8d48b | 99 | while(tcp != NULL){\ |
shreeshas95 | 0:f016e9e8d48b | 100 | Base_tc *temp = tcp->next_TC;\ |
shreeshas95 | 0:f016e9e8d48b | 101 | delete tcp;\ |
shreeshas95 | 0:f016e9e8d48b | 102 | tcp = temp;\ |
shreeshas95 | 0:f016e9e8d48b | 103 | }\ |
shreeshas95 | 5:ab276a17ca07 | 104 | gHEAD_NODE_TCL = NULL;\ |
shreeshas95 | 5:ab276a17ca07 | 105 | gLAST_NODE_TCL = NULL;\ |
shreeshas95 | 5:ab276a17ca07 | 106 | gMASTER_STATE = TCL_STATE_INCOMPLETE;\ |
shreeshas95 | 0:f016e9e8d48b | 107 | gTOTAL_INCORRECT_SIZE_TC = 0;\ |
shreeshas95 | 0:f016e9e8d48b | 108 | gTOTAL_CRC_FAIL_TC = 0;\ |
shreeshas95 | 2:2caf2a9a13aa | 109 | gTOTAL_REPEATED_TC = 0;\ |
shreeshas95 | 5:ab276a17ca07 | 110 | gTOTAL_VALID_TC = 0;\ |
shreeshas95 | 5:ab276a17ca07 | 111 | for(int i = 0 ; i < TM_LONG_SIZE ; ++i){\ |
shreeshas95 | 5:ab276a17ca07 | 112 | gLAST_TM[i] = 0x00;\ |
shreeshas95 | 5:ab276a17ca07 | 113 | }\ |
shreeshas95 | 5:ab276a17ca07 | 114 | gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;\ |
shreeshas95 | 0:f016e9e8d48b | 115 | COM_RX_DATA_NODE *dataptr = gRX_HEAD_DATA_NODE;\ |
shreeshas95 | 0:f016e9e8d48b | 116 | while( dataptr != NULL ){\ |
shreeshas95 | 0:f016e9e8d48b | 117 | COM_RX_DATA_NODE *temp = dataptr->next_node;\ |
shreeshas95 | 0:f016e9e8d48b | 118 | delete dataptr;\ |
shreeshas95 | 0:f016e9e8d48b | 119 | dataptr = temp;\ |
shreeshas95 | 0:f016e9e8d48b | 120 | }\ |
shreeshas95 | 0:f016e9e8d48b | 121 | gRX_HEAD_DATA_NODE = new COM_RX_DATA_NODE;\ |
shreeshas95 | 0:f016e9e8d48b | 122 | gRX_HEAD_DATA_NODE->next_node = NULL;\ |
shreeshas95 | 0:f016e9e8d48b | 123 | gRX_CURRENT_DATA_NODE = gRX_HEAD_DATA_NODE;\ |
shreeshas95 | 0:f016e9e8d48b | 124 | gRX_COUNT = 0;\ |
shreeshas95 | 2:2caf2a9a13aa | 125 | /*PENDING : ALL GLOBAL VAARIABLES AND FLAGS*/\ |
aniruddhv | 12:ffdb29353058 | 126 | /*gPC.puts("finished reset all\r\n");*/\ |
shreeshas95 | 2:2caf2a9a13aa | 127 | } |
shreeshas95 | 2:2caf2a9a13aa | 128 | |
shreeshas95 | 2:2caf2a9a13aa | 129 | #define PUT_RAW_BYTE {\ |
shreeshas95 | 2:2caf2a9a13aa | 130 | if( gRX_COUNT < (RX_BUFFER_LENGTH-1) ){\ |
shreeshas95 | 2:2caf2a9a13aa | 131 | ++gRX_COUNT;\ |
shreeshas95 | 2:2caf2a9a13aa | 132 | }\ |
shreeshas95 | 2:2caf2a9a13aa | 133 | else{\ |
shreeshas95 | 2:2caf2a9a13aa | 134 | gRX_COUNT = 0;\ |
shreeshas95 | 2:2caf2a9a13aa | 135 | gRX_CURRENT_DATA_NODE->next_node = new COM_RX_DATA_NODE;\ |
shreeshas95 | 2:2caf2a9a13aa | 136 | gRX_CURRENT_DATA_NODE = gRX_CURRENT_DATA_NODE->next_node;\ |
shreeshas95 | 2:2caf2a9a13aa | 137 | gRX_CURRENT_DATA_NODE->next_node = NULL;\ |
shreeshas95 | 2:2caf2a9a13aa | 138 | }\ |
shreeshas95 | 2:2caf2a9a13aa | 139 | gRX_TIMEOUT.attach(&after_receive, RX_TIMEOUT_LIMIT);\ |
shreeshas95 | 0:f016e9e8d48b | 140 | } |
shreeshas95 | 0:f016e9e8d48b | 141 | |
shreeshas95 | 0:f016e9e8d48b | 142 | void COM_MNG_TMTC_FUN(void const *args){ |
shreeshas95 | 4:104dd82c99b8 | 143 | if( !(gFLAGS & COM_SESSION_FLAG) ){ |
ee12b079 | 96:4ca92f9775e0 | 144 | //gLEDR = 1; |
ee12b079 | 96:4ca92f9775e0 | 145 | //gLEDG = 1; |
shreeshas95 | 4:104dd82c99b8 | 146 | } |
shreeshas95 | 0:f016e9e8d48b | 147 | while(true){ |
shreeshas95 | 0:f016e9e8d48b | 148 | Thread::signal_wait( COM_MNG_TMTC_SIGNAL_UART_INT ); |
shreeshas95 | 0:f016e9e8d48b | 149 | if( gFLAGS & UART_INT_FLAG ){ |
shreeshas95 | 0:f016e9e8d48b | 150 | gFLAGS = gFLAGS & (~UART_INT_FLAG); |
shreeshas95 | 2:2caf2a9a13aa | 151 | if( !(gFLAGS & COM_SESSION_FLAG) ){ |
shreeshas95 | 2:2caf2a9a13aa | 152 | // PENDING : DISABLE THREADS |
ee12b079 | 186:eb19a02f83d6 | 153 | Base_tm *tm_ptr = new Short_tm; |
ee12b079 | 186:eb19a02f83d6 | 154 | STANDBY_SCIENCE_PL(tm_ptr); |
ee12b079 | 186:eb19a02f83d6 | 155 | /*DELETE THE TM AFTER USE*/\ |
ee12b079 | 186:eb19a02f83d6 | 156 | Base_tm *del_tm = tm_ptr;\ |
ee12b079 | 186:eb19a02f83d6 | 157 | int overCount = 0;\ |
ee12b079 | 186:eb19a02f83d6 | 158 | while( del_tm != NULL ){\ |
ee12b079 | 186:eb19a02f83d6 | 159 | if( (overCount < TM_OVERFLOW_CONSTANT) ){\ |
ee12b079 | 186:eb19a02f83d6 | 160 | Base_tm *temp = del_tm->next_TM;\ |
ee12b079 | 186:eb19a02f83d6 | 161 | delete del_tm;\ |
ee12b079 | 186:eb19a02f83d6 | 162 | del_tm = temp;\ |
ee12b079 | 186:eb19a02f83d6 | 163 | ++overCount;\ |
ee12b079 | 186:eb19a02f83d6 | 164 | }\ |
ee12b079 | 186:eb19a02f83d6 | 165 | else{\ |
ee12b079 | 186:eb19a02f83d6 | 166 | break;\ |
ee12b079 | 186:eb19a02f83d6 | 167 | }\ |
ee12b079 | 186:eb19a02f83d6 | 168 | }\ |
shreeshas95 | 2:2caf2a9a13aa | 169 | gFLAGS = gFLAGS | COM_SESSION_FLAG; |
shreeshas95 | 2:2caf2a9a13aa | 170 | gSESSION_TIMEOUT.attach(&after_session, SESSION_TIME_LIMIT); |
shreeshas95 | 2:2caf2a9a13aa | 171 | gFLAGS = gFLAGS | COM_RX_FLAG; |
shreeshas95 | 2:2caf2a9a13aa | 172 | PUT_RAW_BYTE; |
shreeshas95 | 2:2caf2a9a13aa | 173 | // PENDING : MEASURE RSSI |
shreeshas95 | 4:104dd82c99b8 | 174 | if( gFLAGS & COM_SESSION_FLAG ){ |
ee12b079 | 96:4ca92f9775e0 | 175 | //gLEDR = 0; |
ee12b079 | 96:4ca92f9775e0 | 176 | //gLEDG = 0; |
shreeshas95 | 4:104dd82c99b8 | 177 | } |
shreeshas95 | 2:2caf2a9a13aa | 178 | } |
shreeshas95 | 2:2caf2a9a13aa | 179 | else if( gFLAGS & COM_RX_FLAG ){ |
ee12b079 | 96:4ca92f9775e0 | 180 | //gLEDR = 0; |
ee12b079 | 96:4ca92f9775e0 | 181 | //gLEDG = 1; |
shreeshas95 | 2:2caf2a9a13aa | 182 | PUT_RAW_BYTE; |
shreeshas95 | 0:f016e9e8d48b | 183 | } |
shreeshas95 | 0:f016e9e8d48b | 184 | else{ |
ee12b079 | 96:4ca92f9775e0 | 185 | //gLEDR = 1; |
ee12b079 | 96:4ca92f9775e0 | 186 | //gLEDG = 0; |
shreeshas95 | 2:2caf2a9a13aa | 187 | gFLAGS = gFLAGS | COM_RX_FLAG; |
shreeshas95 | 2:2caf2a9a13aa | 188 | PUT_RAW_BYTE; |
shreeshas95 | 0:f016e9e8d48b | 189 | } |
shreeshas95 | 0:f016e9e8d48b | 190 | } |
shreeshas95 | 4:104dd82c99b8 | 191 | else if( gFLAGS & NEW_TC_RECEIVED ){ |
ee12b079 | 98:fd99ddc0e0a1 | 192 | gPC.puts("NEW TC RECEIVED\r\n"); |
ee12b079 | 164:be3b4b760d0c | 193 | Thread::wait(10000); |
shreeshas95 | 0:f016e9e8d48b | 194 | gFLAGS = gFLAGS & (~NEW_TC_RECEIVED); |
shreeshas95 | 4:104dd82c99b8 | 195 | gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG; |
shreeshas95 | 2:2caf2a9a13aa | 196 | |
shreeshas95 | 0:f016e9e8d48b | 197 | // DISABLE THE RX1M INTERRUPT |
shreeshas95 | 0:f016e9e8d48b | 198 | RX1M.attach(NULL); |
shreeshas95 | 0:f016e9e8d48b | 199 | |
shreeshas95 | 4:104dd82c99b8 | 200 | // VERIFY CRC, REPEATED PSC AND UPDATE TOTAL_VALID_TC, INCORRECT SIZE TC, CRC FAIL TC |
shreeshas95 | 2:2caf2a9a13aa | 201 | while(gRX_COUNT < (RX_BUFFER_LENGTH)){ |
shreeshas95 | 2:2caf2a9a13aa | 202 | gRX_CURRENT_DATA_NODE->values[gRX_COUNT] = 0x00; |
shreeshas95 | 0:f016e9e8d48b | 203 | ++gRX_COUNT; |
shreeshas95 | 0:f016e9e8d48b | 204 | } |
shreeshas95 | 0:f016e9e8d48b | 205 | gRX_COUNT = 0; |
shreeshas95 | 4:104dd82c99b8 | 206 | raw_data_to_tc(); |
shreeshas95 | 6:79d422d1ed42 | 207 | gFLAGS = gFLAGS & (~COM_RX_FLAG); |
aniruddhv | 51:da85d84768e2 | 208 | |
shreeshas95 | 2:2caf2a9a13aa | 209 | if( gTOTAL_VALID_TC > 0 ){ |
aniruddhv | 12:ffdb29353058 | 210 | /*gPC.printf("valid TC rx: %u\r\n", gTOTAL_VALID_TC);*/ |
shreeshas95 | 4:104dd82c99b8 | 211 | if( gTOTAL_VALID_TC < COM_MAX_TC_LIMIT ){ |
shreeshas95 | 4:104dd82c99b8 | 212 | // CHECK WEATHER TC LIST HAS MISSING TC OR WEATHER LAST FRAME BIT IS HIGH IN THE LAST PSC-TC |
aniruddhv | 12:ffdb29353058 | 213 | /*gPC.puts("checking for tc list complete\r\n");*/ |
shreeshas95 | 4:104dd82c99b8 | 214 | uint8_t tempContinue = 0xFF; |
shreeshas95 | 4:104dd82c99b8 | 215 | continueToExecute(tempContinue); |
shreeshas95 | 4:104dd82c99b8 | 216 | if(tempContinue == 0x00){ |
aniruddhv | 12:ffdb29353058 | 217 | /*gPC.puts("tc list is complete\r\n");*/ |
shreeshas95 | 4:104dd82c99b8 | 218 | // CHECK WEATHER GS VERIFICATION CODE MATCHES |
shreeshas95 | 4:104dd82c99b8 | 219 | uint8_t tempGSver = 0x00; |
shreeshas95 | 4:104dd82c99b8 | 220 | GScodeVerification(tempGSver); |
shreeshas95 | 5:ab276a17ca07 | 221 | /*PENDING: INCLUDE GS VERIFICATION CODE*/ |
aniruddhv | 37:c9a739750806 | 222 | if( tempGSver == 0xFF ){ |
aniruddhv | 37:c9a739750806 | 223 | /*gPC.puts("GS code match !!\r\n");*/ |
shreeshas95 | 4:104dd82c99b8 | 224 | gFLAGS = gFLAGS | COM_SESSION_VALIDITY; |
shreeshas95 | 4:104dd82c99b8 | 225 | COM_POWER_ON_TX; |
shreeshas95 | 4:104dd82c99b8 | 226 | // PENDING: PA HOT HANDLED IN EXECUTE_XXX FUNCTIONS |
shreeshas95 | 4:104dd82c99b8 | 227 | uint8_t tempPAHot = 0x00; |
shreeshas95 | 4:104dd82c99b8 | 228 | isPAhot(tempPAHot); |
shreeshas95 | 4:104dd82c99b8 | 229 | if( tempPAHot == 0xFF ){ |
shreeshas95 | 6:79d422d1ed42 | 230 | gFLAGS = gFLAGS & ~(COM_PA_HOT_FLAG); |
shreeshas95 | 6:79d422d1ed42 | 231 | gCOM_PA_COOLING_TIMEOUT.detach(); |
ee12b079 | 98:fd99ddc0e0a1 | 232 | gPC.puts("EXECUTING TELECOMMANDS\r\n"); |
ee12b079 | 98:fd99ddc0e0a1 | 233 | // DEBUF_PRINT("EXECUTING TELECOMMANDS\r\n"); |
shreeshas95 | 4:104dd82c99b8 | 234 | EXECUTE_OBOSC_ONLY; |
shreeshas95 | 4:104dd82c99b8 | 235 | EXECUTE_TC; |
ee12b079 | 164:be3b4b760d0c | 236 | gPC.puts("COMPLETED EXECUTION\r\n"); |
shreeshas95 | 4:104dd82c99b8 | 237 | } |
shreeshas95 | 4:104dd82c99b8 | 238 | else{ |
shreeshas95 | 4:104dd82c99b8 | 239 | gFLAGS = gFLAGS | COM_PA_HOT_FLAG; |
shreeshas95 | 6:79d422d1ed42 | 240 | // PENDING: power off transmitter only |
shreeshas95 | 6:79d422d1ed42 | 241 | gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT); |
shreeshas95 | 6:79d422d1ed42 | 242 | gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); |
shreeshas95 | 4:104dd82c99b8 | 243 | RX1M.attach(&rx_read, Serial::RxIrq); |
shreeshas95 | 4:104dd82c99b8 | 244 | } |
shreeshas95 | 4:104dd82c99b8 | 245 | } |
shreeshas95 | 4:104dd82c99b8 | 246 | else{ |
aniruddhv | 12:ffdb29353058 | 247 | /*gPC.puts("GS code mismatch !!\r\n");*/ |
shreeshas95 | 6:79d422d1ed42 | 248 | RX1M.attach(&rx_read, Serial::RxIrq); |
shreeshas95 | 4:104dd82c99b8 | 249 | reset_all; |
shreeshas95 | 4:104dd82c99b8 | 250 | gFLAGS = gFLAGS & (~COM_SESSION_VALIDITY); |
shreeshas95 | 4:104dd82c99b8 | 251 | // PENDING : ENABLE THREADS |
ee12b079 | 186:eb19a02f83d6 | 252 | Base_tm *tm_ptr = new Short_tm; |
ee12b079 | 186:eb19a02f83d6 | 253 | INIT_SCIENCE_PL(tm_ptr); |
ee12b079 | 186:eb19a02f83d6 | 254 | /*DELETE THE TM AFTER USE*/\ |
ee12b079 | 186:eb19a02f83d6 | 255 | Base_tm *del_tm = tm_ptr;\ |
ee12b079 | 186:eb19a02f83d6 | 256 | int overCount = 0;\ |
ee12b079 | 186:eb19a02f83d6 | 257 | while( del_tm != NULL ){\ |
ee12b079 | 186:eb19a02f83d6 | 258 | if( (overCount < TM_OVERFLOW_CONSTANT) ){\ |
ee12b079 | 186:eb19a02f83d6 | 259 | Base_tm *temp = del_tm->next_TM;\ |
ee12b079 | 186:eb19a02f83d6 | 260 | delete del_tm;\ |
ee12b079 | 186:eb19a02f83d6 | 261 | del_tm = temp;\ |
ee12b079 | 186:eb19a02f83d6 | 262 | ++overCount;\ |
ee12b079 | 186:eb19a02f83d6 | 263 | }\ |
ee12b079 | 186:eb19a02f83d6 | 264 | else{\ |
ee12b079 | 186:eb19a02f83d6 | 265 | break;\ |
ee12b079 | 186:eb19a02f83d6 | 266 | }\ |
ee12b079 | 186:eb19a02f83d6 | 267 | }\ |
shreeshas95 | 4:104dd82c99b8 | 268 | gSESSION_TIMEOUT.detach(); |
shreeshas95 | 4:104dd82c99b8 | 269 | gFLAGS = gFLAGS & (~COM_SESSION_FLAG); |
shreeshas95 | 4:104dd82c99b8 | 270 | // WARNING: clear COM_MNG_TMTC ? |
shreeshas95 | 4:104dd82c99b8 | 271 | } |
shreeshas95 | 0:f016e9e8d48b | 272 | } |
shreeshas95 | 2:2caf2a9a13aa | 273 | else{ |
ee12b079 | 164:be3b4b760d0c | 274 | gPC.puts("tc list is not complete\r\n"); |
shreeshas95 | 5:ab276a17ca07 | 275 | if(tempContinue & 0x01){ |
aniruddhv | 69:20f09a0c3fd2 | 276 | //gPC.puts("last packet bit not found\r\n"); |
shreeshas95 | 5:ab276a17ca07 | 277 | } |
shreeshas95 | 5:ab276a17ca07 | 278 | if( tempContinue & 0x02 ){ |
aniruddhv | 69:20f09a0c3fd2 | 279 | //gPC.puts("missing psc found\r\n"); |
shreeshas95 | 5:ab276a17ca07 | 280 | } |
aniruddhv | 69:20f09a0c3fd2 | 281 | //gPC.printf("crc fail tc = %u\r\n", gTOTAL_CRC_FAIL_TC); |
aniruddhv | 69:20f09a0c3fd2 | 282 | //gPC.printf("incorrect size tc = %u\r\n", gTOTAL_INCORRECT_SIZE_TC); |
aniruddhv | 69:20f09a0c3fd2 | 283 | //gPC.printf("repeated psc = %u\r\n", gTOTAL_REPEATED_TC); |
shreeshas95 | 5:ab276a17ca07 | 284 | Base_tc *test_tc = gHEAD_NODE_TCL; |
shreeshas95 | 5:ab276a17ca07 | 285 | while( test_tc != NULL ){ |
shreeshas95 | 5:ab276a17ca07 | 286 | int length = 0; |
shreeshas95 | 5:ab276a17ca07 | 287 | if( GETshort_or_long_tc(test_tc) == SHORT_TC_CODE ){ |
shreeshas95 | 5:ab276a17ca07 | 288 | length = TC_SHORT_SIZE; |
shreeshas95 | 5:ab276a17ca07 | 289 | } |
shreeshas95 | 5:ab276a17ca07 | 290 | else{ |
shreeshas95 | 5:ab276a17ca07 | 291 | length = TC_LONG_SIZE; |
shreeshas95 | 5:ab276a17ca07 | 292 | } |
rohit3342 | 16:538de1b20b3a | 293 | for(int i = 0 ; i < length ; ++i ){ |
aniruddhv | 69:20f09a0c3fd2 | 294 | //gPC.printf("%x ", test_tc->TC_string[i]); |
shreeshas95 | 5:ab276a17ca07 | 295 | } |
aniruddhv | 69:20f09a0c3fd2 | 296 | //gPC.puts("\r\n"); |
shreeshas95 | 5:ab276a17ca07 | 297 | test_tc = test_tc->next_TC; |
shreeshas95 | 5:ab276a17ca07 | 298 | } |
aniruddhv | 69:20f09a0c3fd2 | 299 | //gPC.puts("\r\n"); |
shreeshas95 | 4:104dd82c99b8 | 300 | COM_POWER_ON_TX; |
shreeshas95 | 4:104dd82c99b8 | 301 | // PENDING : POWER OFF TX |
shreeshas95 | 4:104dd82c99b8 | 302 | RX1M.attach(&rx_read, Serial::RxIrq); |
shreeshas95 | 4:104dd82c99b8 | 303 | gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); |
shreeshas95 | 2:2caf2a9a13aa | 304 | } |
shreeshas95 | 0:f016e9e8d48b | 305 | } |
shreeshas95 | 0:f016e9e8d48b | 306 | else{ |
shreeshas95 | 4:104dd82c99b8 | 307 | COM_POWER_ON_TX; |
shreeshas95 | 6:79d422d1ed42 | 308 | // POWER OFF TX transmitter only |
shreeshas95 | 4:104dd82c99b8 | 309 | // WARNING: reset_all ? clear com_session ? |
shreeshas95 | 2:2caf2a9a13aa | 310 | RX1M.attach(&rx_read, Serial::RxIrq); |
shreeshas95 | 4:104dd82c99b8 | 311 | gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); |
shreeshas95 | 0:f016e9e8d48b | 312 | } |
shreeshas95 | 2:2caf2a9a13aa | 313 | } |
shreeshas95 | 4:104dd82c99b8 | 314 | else{ |
ee12b079 | 164:be3b4b760d0c | 315 | gPC.puts("No valid TC received\r\n"); |
shreeshas95 | 2:2caf2a9a13aa | 316 | RX1M.attach(&rx_read, Serial::RxIrq); |
shreeshas95 | 4:104dd82c99b8 | 317 | gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); |
shreeshas95 | 6:79d422d1ed42 | 318 | reset_all; |
shreeshas95 | 6:79d422d1ed42 | 319 | // PENDING : ENABLE THREADS |
shreeshas95 | 6:79d422d1ed42 | 320 | gSESSION_TIMEOUT.detach(); |
shreeshas95 | 6:79d422d1ed42 | 321 | gFLAGS = gFLAGS & (~COM_SESSION_FLAG); |
shreeshas95 | 2:2caf2a9a13aa | 322 | } |
shreeshas95 | 2:2caf2a9a13aa | 323 | } |
shreeshas95 | 2:2caf2a9a13aa | 324 | else if( gFLAGS & COM_PA_HOT_FLAG ){ |
aniruddhv | 12:ffdb29353058 | 325 | /*gPC.puts("checking for PA hot in main\r\n");*/ |
shreeshas95 | 6:79d422d1ed42 | 326 | if( gFLAGS & COM_RX_FLAG ){ |
shreeshas95 | 6:79d422d1ed42 | 327 | uint8_t tempPA = 0xFF; |
shreeshas95 | 6:79d422d1ed42 | 328 | isPAhot(tempPA); |
shreeshas95 | 6:79d422d1ed42 | 329 | if( tempPA == 0x00 ){ |
shreeshas95 | 6:79d422d1ed42 | 330 | gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT); |
shreeshas95 | 6:79d422d1ed42 | 331 | } |
shreeshas95 | 6:79d422d1ed42 | 332 | else{ |
shreeshas95 | 6:79d422d1ed42 | 333 | gFLAGS = gFLAGS & ~(COM_PA_HOT_FLAG); |
shreeshas95 | 6:79d422d1ed42 | 334 | gCOM_PA_COOLING_TIMEOUT.detach(); |
shreeshas95 | 6:79d422d1ed42 | 335 | } |
shreeshas95 | 0:f016e9e8d48b | 336 | } |
shreeshas95 | 0:f016e9e8d48b | 337 | else{ |
shreeshas95 | 6:79d422d1ed42 | 338 | uint8_t tempPA = 0xFF; |
shreeshas95 | 6:79d422d1ed42 | 339 | isPAhot(tempPA); |
shreeshas95 | 6:79d422d1ed42 | 340 | if( tempPA == 0x00 ){ |
shreeshas95 | 6:79d422d1ed42 | 341 | gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT); |
shreeshas95 | 6:79d422d1ed42 | 342 | } |
shreeshas95 | 6:79d422d1ed42 | 343 | else{ |
aniruddhv | 12:ffdb29353058 | 344 | /*gPC.puts("PA IS COOLED DOWN\r\n");*/ |
shreeshas95 | 6:79d422d1ed42 | 345 | gFLAGS = gFLAGS & (~COM_PA_HOT_FLAG); |
shreeshas95 | 6:79d422d1ed42 | 346 | gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG; |
shreeshas95 | 6:79d422d1ed42 | 347 | RX1M.attach(NULL); |
shreeshas95 | 6:79d422d1ed42 | 348 | gCOM_PA_COOLING_TIMEOUT.detach(); |
shreeshas95 | 6:79d422d1ed42 | 349 | COM_POWER_ON_TX; |
shreeshas95 | 6:79d422d1ed42 | 350 | EXECUTE_OBOSC_ONLY; |
shreeshas95 | 6:79d422d1ed42 | 351 | EXECUTE_TC; |
shreeshas95 | 6:79d422d1ed42 | 352 | } |
shreeshas95 | 0:f016e9e8d48b | 353 | } |
shreeshas95 | 2:2caf2a9a13aa | 354 | } |
shreeshas95 | 6:79d422d1ed42 | 355 | else if( gFLAGS & COM_SESSION_TIMEOUT_FLAG ){ |
aniruddhv | 12:ffdb29353058 | 356 | /*gPC.puts("session timeout: resetting in main\r\n");*/ |
shreeshas95 | 6:79d422d1ed42 | 357 | COM_POWER_OFF_TX; |
shreeshas95 | 6:79d422d1ed42 | 358 | /*PENDING : ENABLE THREADS*/ |
ee12b079 | 173:f81ded27423d | 359 | |
shreeshas95 | 6:79d422d1ed42 | 360 | gSESSION_TIMEOUT.detach(); |
shreeshas95 | 6:79d422d1ed42 | 361 | gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); |
shreeshas95 | 6:79d422d1ed42 | 362 | gFLAGS = gFLAGS & (~COM_SESSION_FLAG); |
shreeshas95 | 6:79d422d1ed42 | 363 | reset_all; |
shreeshas95 | 6:79d422d1ed42 | 364 | } |
shreeshas95 | 2:2caf2a9a13aa | 365 | else{ |
aniruddhv | 12:ffdb29353058 | 366 | /*gPC.puts("INVALID SIGNAL RECEIVED IN MAIN\r\n");*/ |
shreeshas95 | 2:2caf2a9a13aa | 367 | // SOME INVALID SIGNAL RECEIVED |
shreeshas95 | 4:104dd82c99b8 | 368 | COM_POWER_OFF_TX; |
shreeshas95 | 2:2caf2a9a13aa | 369 | reset_all; |
shreeshas95 | 2:2caf2a9a13aa | 370 | // PENDING : ENABLE THREADS |
shreeshas95 | 2:2caf2a9a13aa | 371 | gSESSION_TIMEOUT.detach(); |
shreeshas95 | 2:2caf2a9a13aa | 372 | gFLAGS = gFLAGS & (~COM_SESSION_FLAG); |
shreeshas95 | 0:f016e9e8d48b | 373 | } |
shreeshas95 | 0:f016e9e8d48b | 374 | } |
shreeshas95 | 101:bece931236a2 | 375 | } |