
Repository for CDMS code
Dependencies: SimpleDMA mbed-rtos mbed eeprom
Fork of COM_MNG_TMTC_SIMPLE by
Revision 212:3d13a06bcd3a, committed 2016-07-03
- Comitter:
- aniruddhv
- Date:
- Sun Jul 03 05:37:25 2016 +0000
- Parent:
- 211:77bee0cbebfe
- Commit message:
- ACK_L1, P_COM_HK, Changed BAE TCs to long, COM_POWER_ON_TX, after_cooling_timeout, Update TC status, Execute OBOSC, Removed OBSRS execution from MNG_TMTC, RCV_TC in ThreadsandFunctions to include byte_limit
Changed in this revision
--- a/COM_MNG_TMTC.h Sat Jun 18 09:07:28 2016 +0000 +++ b/COM_MNG_TMTC.h Sun Jul 03 05:37:25 2016 +0000 @@ -41,7 +41,7 @@ -#define detect_ack(tm_ptr, temp_ack, tc_psc) {\ +#define detect_ack(tm_ptr, temp_ack) {\ if( tm_ptr != NULL ){\ int length = TM_SHORT_SIZE;\ if( GETshort_or_long_tm(tm_ptr) == SHORT_TM_CODE ){\ @@ -58,21 +58,20 @@ if( (temp8 == 0xC0) || (temp8 == 0xA0) )\ temp_ack = 0x01;\ else{\ - temp_ack = 0x00;\ + temp_ack = 0x02;\ /*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 = 0x02; - tm_ptr->TM_string[2] = tc_psc;\ + temp_ack = 0x04;\ }\ }\ }\ else\ - temp_ack = 0x00;\ + temp_ack = 0x03;\ }\ else{\ - temp_ack = 0x00;\ + temp_ack = 0x02;\ }\ } @@ -828,6 +827,7 @@ } } // CDMS TEAM CODE END + // EXECUTE OBOSC #define execute_obosc_core(tc_ptr, tm_ptr, reset_flag) {\ if (DEBUG)\ @@ -927,13 +927,11 @@ 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] = 0xA2;\ + ackl234new->TM_string[2] = 0xAF;\ }\ if (DEBUG)\ gPC.puts("completed obosc\r\n");\ @@ -943,6 +941,7 @@ #define EXECUTE_OBOSC_ONLY {\ + gMASTER_STATE = TCL_STATE_EXECUTING;\ int reset_flag = 0;\ if (DEBUG)\ gPC.puts("iNSIDE EXECUTE_OBOSC_ONLY\r\n");\ @@ -971,8 +970,14 @@ while(obosc_tm_core != NULL){\ obosc_tm_core = obosc_tm_core->next_TM;\ }\ - uint16_t temp16 = TC_STATE_SUCCESSFULLY_EXECUTED;\ - PUTexec_status(current_TC, temp16);\ + 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);\ + }\ while( obosc_tm_current != NULL ){\ int length = TM_SHORT_SIZE;\ if( GETshort_or_long_tm(obosc_tm_current) == SHORT_TM_CODE ){\ @@ -986,9 +991,6 @@ }\ obosc_tm_current = obosc_tm_current->next_TM;\ }\ - if ( reset_flag ==1 ){\ - reset_all;\ - }\ }\ }\ }\ @@ -996,7 +998,7 @@ ++overCount;\ }\ else{\ - /*PENDING: REST CDMS: MEMORY LEAK FOUND*/\ + RESET_CDMS;\ break;\ }\ }\ @@ -1019,8 +1021,8 @@ }\ obosc_tm_current->next_TM = obosc_tm;\ /*Sending OBOSC TM to GS*/\ - /*snd_tm.head_pointer(obosc_tm_head);*/\ - /*transmit_adf;*/\ + snd_tm.head_pointer(obosc_tm_head);\ + transmit_adf;\ /*DELETE THE TM AFTER USE*/\ obosc_tm_current = obosc_tm_head;\ int overCount = 0;\ @@ -1036,7 +1038,13 @@ break;\ }\ }\ - }\ + }\ + if ( reset_flag == 1 ){\ + reset_all;\ + /*PENDING: Enable threads*/\ + /*gCDMS_HK_TIMER.start(5000);*/\ + gSESSION_TIMEOUT.detach();\ + }\ } #define EXECUTE_TC {\ @@ -1086,7 +1094,7 @@ tm_ptr = tm_ptr->next_TM;\ }\ /*Send only call sign, ACK_L1 to GS*/\ - /*snd_tm.head_pointer(tm_ptr_head);*/\ + snd_tm.head_pointer(tm_ptr_head);\ /*transmit_adf;*/\ /*DELETE THE TM AFTER USE*/\ tm_ptr = tm_ptr_head;\ @@ -1128,29 +1136,37 @@ 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;\ - uint8_t temp84 = GETpacket_seq_count(current_TC);\ - detect_ack(put_tm_here, temp83, temp84);\ + detect_ack(put_tm_here, temp83);\ if( temp83 == 0x01){\ uint16_t temp16 = TC_STATE_SUCCESSFULLY_EXECUTED;\ PUTexec_status(current_TC, temp16);\ }\ - else if( temp83 == 0x02){\ + 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) && (GETabort_on_nack(current_TC) == 1) ){\ + if( ((GETexec_status(current_TC) == TC_STATE_EXECUTION_FAILED) || (GETexec_status(current_TC) == TC_STATE_EXECUTION_UNKNOWN)) && (GETabort_on_nack(current_TC) == 1) ){\ gMASTER_STATE = TCL_STATE_ABORTED;\ }\ else if( execute_psc == (gTOTAL_VALID_TC-1) ){\ @@ -1159,20 +1175,23 @@ }\ /*update last executed L1_ack*/\ if( put_tm_here != NULL ){\ - if( GETshort_or_long_tm(put_tm_here) == SHORT_TM_CODE ){\ + 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 ){\ for(int i = 0 ; i < TM_SHORT_SIZE ; ++i){\ - gLAST_TM[i] = put_tm_here->TM_string[i];\ + gLAST_TM[i] = ptr_tm->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[i] = ptr_tm->TM_string[i];\ gLAST_TM_SHORT_OR_LONG = LONG_TM_CODE;\ }\ }\ }\ - /*PENDING: APPEND ACK L1*/\ + P_COM_HK;\ Base_tm *tm_ptr = tm_ptr_head;\ get_ack_l1(tm_ptr->next_TM);\ int overflowCountExecute = 0;\ @@ -1187,11 +1206,6 @@ }\ }\ 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;\ @@ -1232,112 +1246,7 @@ 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;\ @@ -1357,15 +1266,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 ){\ + else if( (gFLAGS & COM_PA_HOT_FLAG) || (gFLAGS & COM_PA_OC_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;\ @@ -1381,6 +1290,7 @@ 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);\
--- a/COM_POWER_OFF_TX.h Sat Jun 18 09:07:28 2016 +0000 +++ b/COM_POWER_OFF_TX.h Sun Jul 03 05:37:25 2016 +0000 @@ -16,8 +16,16 @@ uint16_t crc16 = crc16_gen(RESET_tc->TC_string, 9);\ RESET_tc->TC_string[9] = (crc16 & 0xFF00)>>8;\ RESET_tc->TC_string[10] = (crc16 & 0x00FF);\ - FCTN_CDMS_RLY_TMTC(RESET_tc);\ + Base_tm *tm_ptr = NULL;\ + tm_ptr = FCTN_CDMS_RLY_TMTC(RESET_tc);\ delete RESET_tc;\ + /*DELETE THE TM AFTER USE*/\ + Base_tm *del_tm = tm_ptr;\ + while( del_tm != NULL ){\ + Base_tm *temp = del_tm->next_TM;\ + delete del_tm;\ + del_tm = temp;\ + }\ } #define power_on_bae {\ @@ -38,7 +46,7 @@ uint16_t crc16 = crc16_gen(power_on_BAE->TC_string, 9);\ power_on_BAE->TC_string[9] = (crc16 & 0xFF00)>>8;\ power_on_BAE->TC_string[10] = (crc16 & 0x00FF);\ - Base_tm *tm_ptr = new Short_tm;\ + Base_tm *tm_ptr = NULL;\ tm_ptr = FCTN_CDMS_RLY_TMTC(power_on_BAE);\ delete power_on_BAE;\ /*DELETE THE TM AFTER USE*/\ @@ -59,9 +67,9 @@ } #define resume_bcn {\ - Base_tc *beacon_tc = new Short_tc;\ + Base_tc *beacon_tc = new Long_tc;\ beacon_tc->next_TC = NULL;\ - PUTshort_or_long(beacon_tc,SHORT_TC_CODE);\ + PUTshort_or_long(beacon_tc,LONG_TC_CODE);\ PUTcrc_pass(beacon_tc,0x1);\ PUTexec_status(beacon_tc,0);\ beacon_tc->TC_string[0] = 0x01;\ @@ -76,9 +84,27 @@ uint16_t crc16 = crc16_gen(beacon_tc->TC_string, 9);\ beacon_tc->TC_string[9] = (crc16 & 0xFF00)>>8;\ beacon_tc->TC_string[10] = (crc16 & 0x00FF);\ - Base_tm *tm_ptr = new Short_tm;\ + for(int i = 11; i < 135; i++){\ + beacon_tc->TC_string[i] = 0;\ + }\ + Base_tm *tm_ptr = NULL;\ tm_ptr = FCTN_CDMS_RLY_TMTC(beacon_tc);\ delete beacon_tc;\ + /*DELETE THE TM AFTER USE*/\ + Base_tm *del_tm = tm_ptr;\ + int overCount = 0;\ + while( del_tm != NULL ){\ + if( (overCount < TM_OVERFLOW_CONSTANT) ){\ + Base_tm *temp = del_tm->next_TM;\ + delete del_tm;\ + del_tm = temp;\ + ++overCount;\ + }\ + else{\ + RESET_CDMS;\ + break;\ + }\ + }\ } #define COM_POWER_OFF_TX {\ @@ -102,6 +128,7 @@ }\ }\ gFLAGS = gFLAGS & (~COM_PA_HOT_FLAG);\ + gFLAGS = gFLAGS & (~COM_PA_OC_FLAG);\ gCOM_PA_COOLING_TIMEOUT.detach();\ gFLAGS = gFLAGS & (~COM_TX_FLAG);\ gFLAGS = gFLAGS & (~COM_SESSION_TIMEOUT_FLAG);\
--- a/COM_POWER_ON_TX.h Sat Jun 18 09:07:28 2016 +0000 +++ b/COM_POWER_ON_TX.h Sun Jul 03 05:37:25 2016 +0000 @@ -1,7 +1,32 @@ +#define STANDBY_PRCS(tm_ptr){\ + Base_tc *stdby_tc = new Long_tc;\ + stdby_tc->next_TC = NULL;\ + PUTshort_or_long(stdby_tc,LONG_TC_CODE);\ + PUTcrc_pass(stdby_tc,0x1);\ + PUTexec_status(stdby_tc,0);\ + stdby_tc->TC_string[0] = 0x01;\ + stdby_tc->TC_string[1] = 0x41;\ + stdby_tc->TC_string[2] = 0x81;\ + stdby_tc->TC_string[3] = 0x40;\ + stdby_tc->TC_string[4] = 0x01;\ + stdby_tc->TC_string[5] = 0x01;\ + stdby_tc->TC_string[6] = 0x01;\ + stdby_tc->TC_string[7] = 0;\ + stdby_tc->TC_string[8] = 0;\ + uint16_t crc16 = crc16_gen(stdby_tc->TC_string, 9);\ + stdby_tc->TC_string[9] = (crc16 & 0xFF00)>>8;\ + stdby_tc->TC_string[10] = (crc16 & 0x00FF);\ + for(int i = 11; i < 135; i++){\ + stdby_tc->TC_string[i] = 0;\ + }\ + tm_ptr = FCTN_CDMS_RLY_TMTC(stdby_tc);\ + delete stdby_tc;\ +} + #define SET_BCN_STANDBY(tm_ptr){\ - Base_tc *beacon_tc = new Short_tc;\ + Base_tc *beacon_tc = new Long_tc;\ beacon_tc->next_TC = NULL;\ - PUTshort_or_long(beacon_tc,SHORT_TC_CODE);\ + PUTshort_or_long(beacon_tc,LONG_TC_CODE);\ PUTcrc_pass(beacon_tc,0x1);\ PUTexec_status(beacon_tc,0);\ beacon_tc->TC_string[0] = 0x01;\ @@ -16,6 +41,9 @@ uint16_t crc16 = crc16_gen(beacon_tc->TC_string, 9);\ beacon_tc->TC_string[9] = (crc16 & 0xFF00)>>8;\ beacon_tc->TC_string[10] = (crc16 & 0x00FF);\ + for(int i = 11; i < 135; i++){\ + beacon_tc->TC_string[i] = 0;\ + }\ tm_ptr = FCTN_CDMS_RLY_TMTC(beacon_tc);\ delete beacon_tc;\ } @@ -38,7 +66,7 @@ uint16_t crc16 = crc16_gen(reset_BAE->TC_string, 9);\ reset_BAE->TC_string[9] = (crc16 & 0xFF00)>>8;\ reset_BAE->TC_string[10] = (crc16 & 0x00FF);\ - Base_tm *tm_ptr = new Short_tm;\ + Base_tm *tm_ptr = NULL;\ tm_ptr = FCTN_CDMS_RLY_TMTC(reset_BAE);\ delete reset_BAE;\ /*DELETE THE TM AFTER USE*/\ @@ -76,8 +104,8 @@ uint16_t crc16 = crc16_gen(power_off_BAE->TC_string, 9);\ power_off_BAE->TC_string[9] = (crc16 & 0xFF00)>>8;\ power_off_BAE->TC_string[10] = (crc16 & 0x00FF);\ - Base_tm *tm_ptr = new Short_tm;\ - tm_ptr = FCTN_CDMS_RLY_TMTC(power_off_BAE);\ + Base_tm *tm_ptr = NULL;\ + tm_ptr = FCTN_CDMS_RLY_TMTC(power_off_BAE);\ delete power_off_BAE;\ /*DELETE THE TM AFTER USE*/\ Base_tm *del_tm = tm_ptr;\ @@ -114,8 +142,8 @@ uint16_t crc16 = crc16_gen(hk_main_ptr->TC_string, 9);\ hk_main_ptr->TC_string[9] = (crc16 & 0xFF00)>>8;\ hk_main_ptr->TC_string[10] = (crc16 & 0x00FF);\ - Base_tm *tm_ptr = new Short_tm;\ - tm_ptr = FCTN_CDMS_RLY_TMTC(hk_main_ptr);\ + Base_tm *tm_ptr = NULL;\ + tm_ptr = FCTN_CDMS_RLY_TMTC(hk_main_ptr);\ delete hk_main_ptr;\ /*DELETE THE TM AFTER USE*/\ Base_tm *del_tm = tm_ptr;\ @@ -135,9 +163,9 @@ } #define P_BCN_TX_MAIN(tm_ptr) {\ - Base_tc *bcn_tx_main_ptr = new Short_tc;\ + Base_tc *bcn_tx_main_ptr = new Long_tc;\ bcn_tx_main_ptr->next_TC = NULL;\ - PUTshort_or_long(bcn_tx_main_ptr,SHORT_TC_CODE);\ + PUTshort_or_long(bcn_tx_main_ptr,LONG_TC_CODE);\ PUTcrc_pass(bcn_tx_main_ptr,0x1);\ PUTexec_status(bcn_tx_main_ptr,0);\ bcn_tx_main_ptr->TC_string[0] = 0x01;\ @@ -152,6 +180,9 @@ uint16_t crc16 = crc16_gen(bcn_tx_main_ptr->TC_string, 9);\ bcn_tx_main_ptr->TC_string[9] = (crc16 & 0xFF00)>>8;\ bcn_tx_main_ptr->TC_string[10] = (crc16 & 0x00FF);\ + for(int i = 11; i < 135; i++){\ + bcn_tx_main_ptr->TC_string[i] = 0;\ + }\ tm_ptr = FCTN_CDMS_RLY_TMTC(bcn_tx_main_ptr);\ delete bcn_tx_main_ptr;\ } @@ -165,15 +196,12 @@ /*WARNING: INFINITE WHILE LOOP POSSIBLE: if standby ack received and bcn tx main status = 0*/ bool retryFlag = true; while( retryFlag == true ){ - Base_tm *tm_ptr = new Short_tm; + Base_tm *tm_ptr = NULL; SET_BCN_STANDBY(tm_ptr); - uint8_t standbyAck = 0; uint8_t bcn_main_status = (tm_ptr->TM_string[2] & 0xEF); - if(( bcn_main_status == 0xC0 )||( bcn_main_status ==0xA0 )) - standbyAck = 1; - if( /*standbyAck*/ true ){ + if(( bcn_main_status == 0xC0 )||( bcn_main_status ==0xA0 )){ /*ACK RECCEIVED*/ - if( /*bcn_main_status == 0xA0*/ true ){ + if( bcn_main_status == 0xA0 ){ retryFlag = false; RF_SW_CNTRL_TX = 1; Thread::wait(25); @@ -186,13 +214,11 @@ } else{ reset_bae; - Base_tm *tm_ptr2 = new Short_tm; + Base_tm *tm_ptr2 = NULL; SET_BCN_STANDBY(tm_ptr2); uint8_t standbyAck2 = 0; uint8_t bcn_main_status2 = (tm_ptr2->TM_string[2] & 0xEF); - if( ( bcn_main_status2 == 0xC0 )||( bcn_main_status2 == 0xA0 ) ) - standbyAck2 = 1; - if( standbyAck2 ){ + if( ( bcn_main_status2 == 0xC0 )||( bcn_main_status2 == 0xA0 ) ){ if( bcn_main_status2 == 0xA0 ){ retryFlag = false; RF_SW_CNTRL_TX = 1; @@ -202,7 +228,7 @@ } else{ Thread::wait(5000); - }\ + } } else{ retryFlag = false; @@ -248,18 +274,16 @@ } } else{ - power_off_bae; - gFLAGS = gFLAGS & (~BAE_SW_EN_FLAG); RF_SW_CNTRL_TX = 1; Thread::wait(25); RF_SW_CNTRL_TX = 0; gFLAGS = gFLAGS & (~RF_SW_STATUS_FLAG);/*RF_SW_STATUS_FLAG set to RF_COM_TX*/ } } - //COM_TX_CNTRL = 1; + COM_TX_CNTRL = 1; uint8_t adfConfigPass = 0xFF; for( int i = 0 ; i < COM_TX_CONFIG_LIMIT ; ++i ){ - /*PENDING: CONFIGURE ADF*/ + /*PENDING: CONFIGURE ADF and set adfConfigPass*/ if( adfConfigPass == 0xFF ){ break; } @@ -310,19 +334,76 @@ /*NOT Transmitted succesfully*/ COM_POWER_OFF_TX; P_CDMS_HK_MAIN; + Base_tm *ptr_tm = NULL; + STANDBY_PRCS(ptr_tm); + uint8_t standbyACK = 0x00; + uint8_t bcn_main_status = (ptr_tm->TM_string[2] & 0xEF); + if(( bcn_main_status == 0xC0 )||( bcn_main_status ==0xA0 )){ + standbyACK = 1; + } + if(standbyACK == 1){ + uint8_t ackReceived = 0x00; + Base_tm *tm_ptr = NULL; + P_BCN_TX_MAIN(tm_ptr); + uint8_t ackcode = tm_ptr->TM_string[2] & 0xEF; + if( (ackcode == 0xA0) || (ackcode == 0xC0)) + ackReceived = 0xFF; + /*DELETE THE TM AFTER USE*/ + Base_tm *del_tm = tm_ptr; + int overCount = 0; + while( del_tm != NULL ){ + if( (overCount < TM_OVERFLOW_CONSTANT) ){ + Base_tm *temp = del_tm->next_TM; + delete del_tm; + del_tm = temp; + ++overCount; + } + else{ + RESET_CDMS; + break; + } + } + if( ackReceived == 0xFF ){ + Thread::wait(5000); + } + } + /*DELETE THE TM AFTER USE*/ + Base_tm *del_tm = ptr_tm; + int overCount = 0; + while( del_tm != NULL ){ + if( (overCount < TM_OVERFLOW_CONSTANT) ){ + Base_tm *temp = del_tm->next_TM; + delete del_tm; + del_tm = temp; + ++overCount; + } + else{ + RESET_CDMS; + break; + } + } + RESET_CDMS; + } + } + else{ + /*ADF not configured*/ + gFLAGS = gFLAGS & (~COM_TX_STATUS_FLAG); + COM_POWER_OFF_TX; + P_CDMS_HK_MAIN; + Base_tm *ptr_tm = NULL; + STANDBY_PRCS(ptr_tm); + uint8_t standbyACK = 0x00; + uint8_t bcn_main_status = (ptr_tm->TM_string[2] & 0xEF); + if(( bcn_main_status == 0xC0 )||( bcn_main_status ==0xA0 )){ + standbyACK = 1; + } + if(standbyACK == 1){ uint8_t ackReceived = 0x00; - Base_tm *tm_ptr = new Short_tm; + Base_tm *tm_ptr = NULL; P_BCN_TX_MAIN(tm_ptr); uint8_t ackcode = tm_ptr->TM_string[2] & 0xEF; if( (ackcode == 0xA0) || (ackcode == 0xC0)) ackReceived = 0xFF; - if( ackReceived == 0xFF ){ - Thread::wait(5000); - RESET_CDMS; - } - else{ - RESET_CDMS; - } /*DELETE THE TM AFTER USE*/ Base_tm *del_tm = tm_ptr; int overCount = 0; @@ -338,28 +419,12 @@ break; } } - } - } - else{ - /*ADF not configured*/ - gFLAGS = gFLAGS & (~COM_TX_STATUS_FLAG); - COM_POWER_OFF_TX; - P_CDMS_HK_MAIN; - uint8_t ackReceived = 0x00; - Base_tm *tm_ptr = new Short_tm; - P_BCN_TX_MAIN(tm_ptr); - uint8_t ackcode = tm_ptr->TM_string[2] & 0xEF; - if( (ackcode == 0xA0) || (ackcode == 0xC0)) - ackReceived = 0xFF; - if( ackReceived == 0xFF ){ - Thread::wait(5000); - RESET_CDMS; - } - else{ - RESET_CDMS; + if( ackReceived == 0xFF ){ + Thread::wait(5000); + } } /*DELETE THE TM AFTER USE*/ - Base_tm *del_tm = tm_ptr; + Base_tm *del_tm = ptr_tm; int overCount = 0; while( del_tm != NULL ){ if( (overCount < TM_OVERFLOW_CONSTANT) ){ @@ -373,6 +438,7 @@ break; } } + RESET_CDMS; } /*gPC.puts("COMPLETED COM_POWER_ON_TX\r\n");*/ } \ No newline at end of file
--- a/COM_RCV_TC.h Sat Jun 18 09:07:28 2016 +0000 +++ b/COM_RCV_TC.h Sun Jul 03 05:37:25 2016 +0000 @@ -261,5 +261,4 @@ gRX_COUNT = 0; /*gPC.puts("Completed conversion of raw_data\r\n")*/; - // PENDING: SORT THE LINKED LIST ACCORDING TO PSC VALUE } \ No newline at end of file
--- a/DefinitionsAndGlobals.h Sat Jun 18 09:07:28 2016 +0000 +++ b/DefinitionsAndGlobals.h Sun Jul 03 05:37:25 2016 +0000 @@ -55,13 +55,14 @@ // COM_MNG_TMTC THREAD #define SESSION_TIME_LIMIT 1500 + #define COM_RX_DISABLE_TIMEOUT 10 #define COM_MNG_TMTC_SIGNAL_UART_INT 0x01 #define COM_MNG_TMTC_SIGNAL_ADF_NSD 0x02 #define COM_MNG_TMTC_SIGNAL_ADF_SD 0x03 #define SCIENCE_SIGNAL 0x04 // COM_MNG_TMTC #define COM_PA_COOLING_TIME_LIMIT 20 - #define COM_MAX_TC_LIMIT 200 + #define COM_MAX_TC_LIMIT 256 #define TM_ACK_CODE_INDEX 2 #define CRC_FAIL_NACK_CODE 0x01 @@ -72,6 +73,7 @@ // max value of telecommands in a tcl #define TCL_OVERFLOW_CONSTANT 256 #define TM_OVERFLOW_CONSTANT 256 + #define BYTE_OVERFLOW_CONSTANT 35000 // starting value of packet sequence count at each pass #define PSC_START_VALUE 1 @@ -149,6 +151,7 @@ COM_RX_DATA_NODE *gRX_CURRENT_DATA_NODE = NULL; // uint8_t *gRX_CURRENT_PTR = NULL; uint32_t gRX_COUNT = 0; +uint16_t gTOTAL_RAW_BYTES = 0; uint16_t gTOTAL_INCORRECT_SIZE_TC = 0x00; uint16_t gTOTAL_CRC_FAIL_TC = 0x00; uint16_t gTOTAL_REPEATED_TC = 0x00; @@ -178,6 +181,7 @@ Thread* gCOM_MNG_TMTC_THREAD = NULL; Timeout gRX_TIMEOUT; Timeout gSESSION_TIMEOUT; +Timeout gCOM_RX_DISABLE; // COM_MNG_TMTC
--- a/P_COM_INIT.h Sat Jun 18 09:07:28 2016 +0000 +++ b/P_COM_INIT.h Sun Jul 03 05:37:25 2016 +0000 @@ -4,7 +4,7 @@ Thread::wait(25);\ RF_SW_CNTRL_BCN = 0;\ gFLAGS = gFLAGS | RF_SW_STATUS_FLAG;\ - //COM_RX_CNTRL = 0;\ + COM_RX_CNTRL = 0;\ Thread::wait(200);\ COM_RX_CNTRL = 1;\ gFLAGS = gFLAGS & (~COM_INIT_STATUS_FLAG);\
--- a/ThreadsAndFunctions.h Sat Jun 18 09:07:28 2016 +0000 +++ b/ThreadsAndFunctions.h Sun Jul 03 05:37:25 2016 +0000 @@ -23,6 +23,7 @@ linktest_tc->TC_string[9] = (crc16 & 0xFF00)>>8;\ linktest_tc->TC_string[10] = (crc16 & 0x00FF);\ tm_ptr = FCTN_CDMS_RLY_TMTC(linktest_tc);\ + delete linktest_tc;\ } #define Pause_gPAY_SPI{\ @@ -66,6 +67,12 @@ gCOM_MNG_TMTC_THREAD->signal_set(COM_MNG_TMTC_SIGNAL_UART_INT); } +// COM_RX_DISABLE ISR +void after_com_disable(){ + gCOM_RX_DISABLE.detach(); + RX1M.attach(&rx_read, Serial::RxIrq); +} + // RX_TIMEOUT ISR void after_receive(){ gRX_TIMEOUT.detach(); @@ -101,7 +108,7 @@ for(int i = 0 ; i < TM_LONG_SIZE ; ++i){\ /*gLAST_TM[i] = 0x00;*/\ }\ - gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;\ + /*gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;*/\ COM_RX_DATA_NODE *dataptr = gRX_HEAD_DATA_NODE;\ while( dataptr != NULL ){\ COM_RX_DATA_NODE *temp = dataptr->next_node;\ @@ -112,6 +119,7 @@ gRX_HEAD_DATA_NODE->next_node = NULL;\ gRX_CURRENT_DATA_NODE = gRX_HEAD_DATA_NODE;\ gRX_COUNT = 0;\ + gTOTAL_RAW_BYTES = 0;\ /*PENDING : ALL GLOBAL VAARIABLES AND FLAGS*/\ /*gPC.puts("finished reset all\r\n");*/\ } @@ -126,6 +134,7 @@ gRX_CURRENT_DATA_NODE = gRX_CURRENT_DATA_NODE->next_node;\ gRX_CURRENT_DATA_NODE->next_node = NULL;\ }\ + ++gTOTAL_RAW_BYTES;\ gRX_TIMEOUT.attach(&after_receive, RX_TIMEOUT_LIMIT);\ } @@ -140,6 +149,7 @@ gFLAGS = gFLAGS & (~UART_INT_FLAG); if( !(gFLAGS & COM_SESSION_FLAG) ){ // PENDING : DISABLE THREADS + // gCDMS_HK_TIMER.stop(); Base_tm *tm_ptr = new Short_tm; SPI_LINK_TEST(tm_ptr); /*DELETE THE TM AFTER USE*/\ @@ -161,6 +171,7 @@ gFLAGS = gFLAGS | COM_SESSION_FLAG; gSESSION_TIMEOUT.attach(&after_session, SESSION_TIME_LIMIT); gFLAGS = gFLAGS | COM_RX_FLAG; + gTOTAL_RAW_BYTES = 0; PUT_RAW_BYTE; // PENDING : MEASURE RSSI if( gFLAGS & COM_SESSION_FLAG ){ @@ -179,10 +190,15 @@ gFLAGS = gFLAGS | COM_RX_FLAG; PUT_RAW_BYTE; } + if(gTOTAL_RAW_BYTES > BYTE_OVERFLOW_CONSTANT){ + RX1M.attach(NULL); + gCOM_RX_DISABLE.attach(&after_com_disable, COM_RX_DISABLE_TIMEOUT); + after_receive(); + } } else if( gFLAGS & NEW_TC_RECEIVED ){ gPC.puts("NEW TC RECEIVED\r\n"); - Thread::wait(10000); + Thread::wait(10000);/*For testing with transmitter. To be removed later*/ gFLAGS = gFLAGS & (~NEW_TC_RECEIVED); gFLAGS = gFLAGS | COM_MNG_TMTC_RUNNING_FLAG; @@ -210,30 +226,24 @@ // CHECK WEATHER GS VERIFICATION CODE MATCHES uint8_t tempGSver = 0x00; GScodeVerification(tempGSver); - /*PENDING: INCLUDE GS VERIFICATION CODE*/ if( tempGSver == 0xFF ){ /*gPC.puts("GS code match !!\r\n");*/ gFLAGS = gFLAGS | COM_SESSION_VALIDITY; COM_POWER_ON_TX; - // PENDING: PA HOT HANDLED IN EXECUTE_XXX FUNCTIONS - uint8_t tempPAHot = 0x00; - isPAhot(tempPAHot); - if( tempPAHot == 0xFF ){ - gFLAGS = gFLAGS & ~(COM_PA_HOT_FLAG); + P_COM_HK; + if( (gFLAGS & COM_PA_HOT_FLAG) || ( gFLAGS & COM_PA_OC_FLAG ) ){ + COM_TX_CNTRL = 0; + 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); + } + else{ gCOM_PA_COOLING_TIMEOUT.detach(); gPC.puts("EXECUTING TELECOMMANDS\r\n"); -// DEBUF_PRINT("EXECUTING TELECOMMANDS\r\n"); EXECUTE_OBOSC_ONLY; EXECUTE_TC; gPC.puts("COMPLETED EXECUTION\r\n"); } - else{ - gFLAGS = gFLAGS | COM_PA_HOT_FLAG; - // COM_TX_CNTRL = 0; - 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); - } } else{ /*gPC.puts("GS code mismatch !!\r\n");*/ @@ -241,10 +251,11 @@ reset_all; gFLAGS = gFLAGS & (~COM_SESSION_VALIDITY); // PENDING : ENABLE THREADS + // gCDMS_HK_TIMER.start(5000); Init_gPAY_SPI; gSESSION_TIMEOUT.detach(); gFLAGS = gFLAGS & (~COM_SESSION_FLAG); - // WARNING: clear COM_MNG_TMTC ? + gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); } } else{ @@ -275,7 +286,7 @@ } //gPC.puts("\r\n"); COM_POWER_ON_TX; - // COM_TX_CNTRL = 0; + COM_TX_CNTRL = 0; RX1M.attach(&rx_read, Serial::RxIrq); gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); } @@ -295,6 +306,7 @@ gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); reset_all; // PENDING : ENABLE THREADS + // gCDMS_HK_TIMER.start(5000); Init_gPAY_SPI; gSESSION_TIMEOUT.detach(); gFLAGS = gFLAGS & (~COM_SESSION_FLAG); @@ -302,40 +314,28 @@ } else if( gFLAGS & COM_PA_HOT_FLAG ){ /*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(); - } + P_COM_HK; + if((gFLAGS & COM_PA_HOT_FLAG) || (gFLAGS & COM_PA_OC_FLAG)){ + COM_TX_CNTRL = 0; + gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT); } else{ - uint8_t tempPA = 0xFF; - isPAhot(tempPA); - if( tempPA == 0x00 ){ - gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT); - } - else{ + gCOM_PA_COOLING_TIMEOUT.detach(); + if( !(gFLAGS & COM_RX_FLAG) ){ /*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*/ - + // gCDMS_HK_TIMER.start(5000); gSESSION_TIMEOUT.detach(); gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG); gFLAGS = gFLAGS & (~COM_SESSION_FLAG); @@ -347,6 +347,7 @@ COM_POWER_OFF_TX; reset_all; // PENDING : ENABLE THREADS + // gCDMS_HK_TIMER.start(5000); Init_gPAY_SPI; gSESSION_TIMEOUT.detach(); gFLAGS = gFLAGS & (~COM_SESSION_FLAG);
--- a/common_functions.h Sat Jun 18 09:07:28 2016 +0000 +++ b/common_functions.h Sun Jul 03 05:37:25 2016 +0000 @@ -77,7 +77,7 @@ }\ }\ else{\ - /*PENDING: reset cdms*/\ + RESET_CDMS;\ break;\ }\ }\ @@ -99,18 +99,24 @@ /*Attach this new node at the end*/\ }\ else{\ - /*PENDING: reset CDMS*/\ + RESET_CDMS;\ break;\ }\ }\ } #define put_crc_l1_ack(tm_ptr) {\ - tm_ptr->TM_string[2] = gTOTAL_CRC_FAIL_TC & 0xFF;\ /*TC LIST STATUS*/\ - tm_ptr->TM_string[3] |= (gMASTER_STATE << 5) & 0xE0;\ + tm_ptr->TM_string[3] |= (gMASTER_STATE << 6) & 0xC0;\ /*PA HOT*/\ if( gFLAGS & COM_PA_HOT_FLAG ){\ + tm_ptr->TM_string[3] |= (1 << 5);\ + }\ + else{\ + tm_ptr->TM_string[3] &= ~(1 << 5);\ + }\ + /*PA OC*/\ + if( gFLAGS & COM_PA_OC_FLAG ){\ tm_ptr->TM_string[3] |= (1 << 4);\ }\ else{\ @@ -124,16 +130,39 @@ #define fill_l1_ack(tm_ptr) {\ tm_ptr->next_TM = NULL;\ tm_ptr->TM_string[0] = TMID_ACK_L1 << 4;\ - /*PENDING: PA TEMPERATURE*/\ tm_ptr->TM_string[1] = gTOTAL_INCORRECT_SIZE_TC & 0xFF;\ tm_ptr->TM_string[2] = gTOTAL_CRC_FAIL_TC & 0xFF;\ } +#define P_COM_HK{\ + uint8_t returnHere;\ + isPAhot(returnHere);\ + if (returnHere == 0xFF)\ + gFLAGS = gFLAGS & ~(COM_PA_HOT_FLAG);\ + else\ + gFLAGS = gFLAGS | COM_PA_HOT_FLAG;\ + if (gFLAGS & COM_PA_OC_FLAG){\ + COM_TX_CNTRL = 1;\ + wait_ms(5);\ + }\ + isPAoc(returnHere);\ + if (returnHere == 0xFF)\ + gFLAGS = gFLAGS & ~(COM_PA_OC_FLAG);\ + else\ + gFLAGS = gFLAGS | COM_PA_OC_FLAG;\ + /*P_CDMS_HANDLE_HW_FAULTS*/\ +} + #define isPAhot(returnHere){\ /*PENDING : COMPLETE THIS FUNCTION*/\ returnHere = 0xFF;\ } +#define isPAoc(returnHere){\ + /*PENDING : COMPLETE THIS FUNCTION*/\ + returnHere = 0xFF;\ +} + #define get_call_sign(tm_ptr) {\ Base_tm* call_sign_tm = new Short_tm;\ call_sign_tm->next_TM = NULL;\ @@ -156,7 +185,6 @@ /*IF CRC PASS*/\ if( (GETcrc_pass(current_TC) == 1) ){\ if(TC_count > 4){\ - /*PENDING: FILL TC_EXEC_CODE, APPEND CRC TO THE TM*/\ put_crc_l1_ack( l1_ack );\ /*extend the TM linked list*/\ TC_count = 0;\ @@ -189,7 +217,7 @@ ++overflowCountL1;\ }\ else{\ - /*PENDING: RESET CDMS*/\ + RESET_CDMS;\ break;\ }\ }\
--- a/main.cpp Sat Jun 18 09:07:28 2016 +0000 +++ b/main.cpp Sun Jul 03 05:37:25 2016 +0000 @@ -20,11 +20,11 @@ #include "cdms_sd.h" #include "common_functions.h" //#include "CDMS_HK.h" -#include "OBSRS.h" #include "adf.h" #include "COM_RCV_TC.h" #include "COM_MNG_TMTC.h" #include "COM_POWER_OFF_TX.h" +#include "OBSRS.h" #include "COM_POWER_ON_TX.h" #include "Compression.h" #include "ThreadsAndFunctions.h"