werwere
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of COM_MNG_TMTC_SIMPLE_pl123 by
COM_MNG_TMTC.h
00001 // 8 Jul 00002 // did flowchart of states 00003 00004 // handle sd card with cdms team 00005 00006 // Jun 6 00007 // WHAT IS TC exec code in L1 ack ? 00008 00009 //Jan 7 00010 //added RLY_TMTC function 00011 //added included related files 00012 00013 //#include "Flash.h" 00014 #include "cdms_rtc.h" 00015 Timer t_pl; 00016 //defined in definations and globals, need to mapped with the final ones. 00017 //DigitalIn tm_status_4m_slv(PIN39); //I2C interrupt to CDMS from BAE 00018 //DigitalIn tm_status_4m_pl(PIN61); //I2C interrupt to CDMS from PL 00019 00020 uint8_t received = 0; 00021 uint16_t mid1; 00022 uint16_t mid2; 00023 uint16_t Nbytes; 00024 uint32_t Data[2]; 00025 uint16_t nbytes; 00026 uint8_t flash_counter = 0; 00027 uint16_t crc16; 00028 uint16_t mid; 00029 uint32_t block; 00030 00031 #define delete_TC(tc_ptr) {\ 00032 if(tc_ptr == gHEAD_NODE_TCL){\ 00033 gHEAD_NODE_TCL = tc_ptr->next_TC;\ 00034 }\ 00035 delete tc_ptr;\ 00036 } 00037 00038 // typeof tm_ptr: Base_tm 00039 // typeof tc_ptr: Base_tc 00040 // typeof temp_xxxx: uint8_t 00041 #define fill_l1_ack(tm_ptr) {\ 00042 tm_ptr->next_TM = NULL;\ 00043 tm_ptr->TM_string[0] = TMID_ACK_L1 << 4;\ 00044 /*PENDING: PA TEMPERATURE*/\ 00045 tm_ptr->TM_string[1] = gTOTAL_INCORRECT_SIZE_TC & 0xFF;\ 00046 tm_ptr->TM_string[2] = gTOTAL_CRC_FAIL_TC & 0xFF;\ 00047 } 00048 00049 #define put_crc_l1_ack(tm_ptr) {\ 00050 tm_ptr->TM_string[2] = gTOTAL_CRC_FAIL_TC & 0xFF;\ 00051 /*TC LIST STATUS*/\ 00052 tm_ptr->TM_string[3] |= (gMASTER_STATE << 5) & 0xE0;\ 00053 /*PA HOT*/\ 00054 if( gFLAGS & COM_PA_HOT_FLAG ){\ 00055 tm_ptr->TM_string[3] |= (1 << 4);\ 00056 }\ 00057 else{\ 00058 tm_ptr->TM_string[3] &= ~(1 << 4);\ 00059 }\ 00060 uint16_t crc_checksum = crc16_gen(tm_ptr->TM_string, TM_SHORT_SIZE-2);\ 00061 tm_ptr->TM_string[TM_SHORT_SIZE-2] = (crc_checksum >> 8) & 0xFF;\ 00062 tm_ptr->TM_string[TM_SHORT_SIZE-1] = crc_checksum & 0xFF;\ 00063 } 00064 00065 #define detect_ack(tm_ptr, temp_ack, tc_psc) {\ 00066 if( tm_ptr != NULL ){\ 00067 int length = TM_SHORT_SIZE;\ 00068 if( GETshort_or_long_tm(tm_ptr) == SHORT_TM_CODE ){\ 00069 length = TM_SHORT_SIZE;\ 00070 }\ 00071 else{\ 00072 length = TM_LONG_SIZE;\ 00073 }\ 00074 uint16_t crc = crc16_gen(tm_ptr->TM_string, length-2);\ 00075 if( (((crc & 0xFF00) >> 8) == tm_ptr->TM_string[length-2]) && ( (crc & 0x00FF) == tm_ptr->TM_string[length-1] ) ){\ 00076 uint8_t temp8;\ 00077 temp8 = tm_ptr->TM_string[TM_ACK_CODE_INDEX];\ 00078 temp8 = temp8 & 0xE0;\ 00079 if( (temp8 == 0xC0) || (temp8 == 0xA0) )\ 00080 temp_ack = 0x01;\ 00081 else{\ 00082 temp_ack = 0x00;\ 00083 /*CHECK FOR NACK CODE: CRC FAIL NACK*/\ 00084 temp8 = tm_ptr->TM_string[TM_ACK_CODE_INDEX];\ 00085 temp8 = temp8 & 0x0F;\ 00086 if( temp8 == CRC_FAIL_NACK_CODE ){\ 00087 tm_ptr->TM_string[2] = tc_psc;\ 00088 }\ 00089 }\ 00090 }\ 00091 else\ 00092 temp_ack = 0x00;\ 00093 }\ 00094 else{\ 00095 temp_ack = 0x00;\ 00096 }\ 00097 } 00098 00099 #define isit_obosc(tc_ptr, temp_obosc) {\ 00100 temp_obosc = 0x00;\ 00101 if( GETapid(tc_ptr) == APID_COM ){\ 00102 if( ((tc_ptr->TC_string[2]) >> 4) == SERVICE_OBOSC ){\ 00103 temp_obosc = 0x01;\ 00104 }\ 00105 }\ 00106 } 00107 00108 #define isit_sdcard(tc_ptr, temp_sdcard) {\ 00109 temp_sdcard = 0x00;\ 00110 if( GETapid(tc_ptr) == APID_COM ){\ 00111 if( ( (tc_ptr->TC_string[2]) >> 4) == SERVICE_OBSRS ){\ 00112 temp_sdcard = 0x01;\ 00113 }\ 00114 }\ 00115 } 00116 00117 #define isPAhot(returnHere){\ 00118 /*PENDING : COMPLETE THIS FUNCTION*/\ 00119 returnHere = 0xFF;\ 00120 } 00121 00122 void after_cooling_pa(){ 00123 gCOM_MNG_TMTC_THREAD->signal_set(COM_MNG_TMTC_SIGNAL_UART_INT); 00124 } 00125 00126 /* 00127 @brief: check for missing tc, also check crc, i.e. 00128 if true execution can be started else have to wait 00129 decide the next state 00130 @param: none 00131 @return: bool indicating whether there are missing tc 00132 */ 00133 // PENDING: LAST FRAME BIT 00134 /* 00135 for loop: check for missing tc 00136 if: check for incorrect sized tc 00137 if: check for last frame bit 00138 */ 00139 #define continueToExecute(returnHere) {\ 00140 uint8_t tempReturn = 0x00;\ 00141 /*search for missing psc*/\ 00142 for(uint8_t p = 0x00 ; p < (gTOTAL_VALID_TC) ; ++p){\ 00143 bool flag = false;\ 00144 Base_tc *node_ptr = gHEAD_NODE_TCL;\ 00145 while(node_ptr != NULL){\ 00146 if( (GETpacket_seq_count(node_ptr) == p) && (GETcrc_pass(node_ptr) == 1) ){\ 00147 flag = true;\ 00148 break;\ 00149 }\ 00150 else{\ 00151 node_ptr = node_ptr->next_TC;\ 00152 }\ 00153 }\ 00154 if(flag == false){\ 00155 tempReturn = 0x02;\ 00156 break;\ 00157 }\ 00158 }\ 00159 /*search for last packet bit*/\ 00160 tempReturn = tempReturn + 0x01;\ 00161 Base_tc *tcp = gHEAD_NODE_TCL;\ 00162 while(tcp != NULL){\ 00163 if(GETpacket_seq_count(tcp) == (gTOTAL_VALID_TC - 1)){\ 00164 if( ( (tcp->TC_string[1]) & 0x20 ) == 0x20 ){\ 00165 tempReturn = tempReturn - 0x01;\ 00166 }\ 00167 break;\ 00168 }\ 00169 tcp = tcp->next_TC;\ 00170 }\ 00171 returnHere = tempReturn;\ 00172 /*UPDATE gMASTER STATE*/\ 00173 if( (returnHere == 0x00) ){\ 00174 if( (gMASTER_STATE == TCL_STATE_INCOMPLETE) || (gMASTER_STATE == TCL_STATE_COMPLETED) || (gMASTER_STATE == TCL_STATE_ABORTED) ){\ 00175 gMASTER_STATE = TCL_STATE_EXECUTING;\ 00176 }\ 00177 }\ 00178 else{\ 00179 if( (gMASTER_STATE == TCL_STATE_INCOMPLETE) || (gMASTER_STATE == TCL_STATE_COMPLETED) ){\ 00180 gMASTER_STATE = TCL_STATE_INCOMPLETE;\ 00181 }\ 00182 }\ 00183 } 00184 00185 /* 00186 return 1 if code match 00187 return 0 if code mismatch 00188 */ 00189 #define GScodeVerification(returnHere){\ 00190 Base_tc *testTC = gHEAD_NODE_TCL;\ 00191 uint16_t overflowCount = 0;\ 00192 returnHere = 0xFF;\ 00193 while( (overflowCount < TCL_OVERFLOW_CONSTANT) && (testTC != NULL) ){\ 00194 if( (GETpacket_seq_count(testTC) == PSC_CALLSIGN) && (GETapid(testTC) == APID_CALLSIGN) ){\ 00195 /*uint8_t temp8 = testTC->TC_string[1];*/\ 00196 if( true ){\ 00197 for( int i = 2 ; i <= 8 ; ++i ){\ 00198 if( testTC->TC_string[i] != gGSCODE[i-2] ){\ 00199 returnHere = 0;\ 00200 break;\ 00201 }\ 00202 }\ 00203 }\ 00204 break;\ 00205 }\ 00206 testTC = testTC->next_TC;\ 00207 ++overflowCount;\ 00208 }\ 00209 } 00210 00211 /* 00212 @brief: DELETE THE CRC FAILED TC FROM THE LIST TO FREE-UP MEMORY AND UPDATE 00213 THE TOTAL VALID TC AND GENERATE L1_ACK_TM 00214 @param: none 00215 @return: none 00216 */ 00217 /*tm_ptr is the next_TM of a linked list, and should have the value NULL, i.e. tm_ptr should be the next_TM pointer of thte last node */ 00218 #define get_ack_l1( tm_ptr ){\ 00219 Base_tc *current_TC = gHEAD_NODE_TCL;\ 00220 Base_tm *l1_ack = new Short_tm;\ 00221 /*APPEND TO THE tm_ptr HERE*/\ 00222 tm_ptr = l1_ack;\ 00223 fill_l1_ack(l1_ack);\ 00224 int TC_count = 0;\ 00225 int overflowCountL1 = 0;\ 00226 while(current_TC != NULL){\ 00227 if( overflowCountL1 < TCL_OVERFLOW_CONSTANT ){\ 00228 /*IF CRC PASS*/\ 00229 if( (GETcrc_pass(current_TC) == 1) ){\ 00230 if(TC_count > 4){\ 00231 /*PENDING: FILL TC_EXEC_CODE, APPEND CRC TO THE TM*/\ 00232 put_crc_l1_ack( l1_ack );\ 00233 /*extend the TM linked list*/\ 00234 TC_count = 0;\ 00235 l1_ack->next_TM = new Short_tm;\ 00236 l1_ack = l1_ack->next_TM;\ 00237 fill_l1_ack(l1_ack);\ 00238 }\ 00239 /*PSC starts from 7th byte*/\ 00240 l1_ack->TM_string[6+TC_count] = GETpacket_seq_count(current_TC);\ 00241 /*TC exec status*/\ 00242 switch(TC_count){\ 00243 case 0:\ 00244 l1_ack->TM_string[3] = (GETexec_status(current_TC)) & 0x0F;\ 00245 break;\ 00246 case 1:\ 00247 l1_ack->TM_string[4] = (GETexec_status(current_TC) << 4) & 0xF0;\ 00248 break;\ 00249 case 2:\ 00250 l1_ack->TM_string[4] |= (GETexec_status(current_TC)) & 0x0F;\ 00251 break;\ 00252 case 3:\ 00253 l1_ack->TM_string[5] = (GETexec_status(current_TC) << 4) & 0xF0;\ 00254 break;\ 00255 case 4:\ 00256 l1_ack->TM_string[5] |= (GETexec_status(current_TC)) & 0x0F;\ 00257 }\ 00258 ++TC_count;\ 00259 }\ 00260 current_TC = current_TC->next_TC;\ 00261 ++overflowCountL1;\ 00262 }\ 00263 else{\ 00264 /*PENDING: RESET CDMS*/\ 00265 break;\ 00266 }\ 00267 }\ 00268 /*FILL UP THE REMAINING FIELDS WITH 0x00 as PSC, AND 0xF as tc exec status*/\ 00269 if( (TC_count < 5) && (TC_count != 0) ){\ 00270 while(TC_count < 5){\ 00271 l1_ack->TM_string[6+TC_count] = 0x00;\ 00272 switch(TC_count){\ 00273 case 1:\ 00274 l1_ack->TM_string[4] = 0xF0;\ 00275 break;\ 00276 case 2:\ 00277 l1_ack->TM_string[4] |= 0x0F;\ 00278 break;\ 00279 case 3:\ 00280 l1_ack->TM_string[5] = 0xF0;\ 00281 break;\ 00282 case 4:\ 00283 l1_ack->TM_string[5] |= 0x0F;\ 00284 }\ 00285 ++TC_count;\ 00286 }\ 00287 }\ 00288 put_crc_l1_ack(l1_ack);\ 00289 } 00290 00291 /*tm_ptr is the next_TM of a linked list, and should have the value NULL, i.e. tm_ptr should be the next_TM pointer of thte last node */ 00292 #define get_tc_list(tm_ptr, thePSC){\ 00293 uint8_t TM_PSC = 0xFF;\ 00294 uint8_t TC_PSC = thePSC;\ 00295 int overflowCount = 0;\ 00296 uint8_t TC_LIST_TAG = 0x00;\ 00297 Base_tc *temp_tc = gHEAD_NODE_TCL;\ 00298 bool first_time = true;\ 00299 Base_tm *current_tm = NULL;\ 00300 while( temp_tc != NULL ){\ 00301 if( overflowCount < TCL_OVERFLOW_CONSTANT ){\ 00302 TM_PSC = TM_PSC + 1;\ 00303 /*Increment TM_PSC for every new TM pointer created*/\ 00304 Base_tm *temp_tm = new Long_tm;\ 00305 temp_tm->next_TM = NULL;\ 00306 temp_tm->TM_string[0] = 0x38;\ 00307 /*Frame type(1) = 0; TMID = 0111; Spare = 000*/\ 00308 temp_tm->TM_string[1] = TC_PSC;\ 00309 temp_tm->TM_string[3] = TM_PSC;\ 00310 int indexCustom = 4, num_of_short_tc = 0;\ 00311 while(temp_tc != NULL){\ 00312 if( overflowCount < TCL_OVERFLOW_CONSTANT ){\ 00313 if( GETshort_or_long_tc(temp_tc) == SHORT_TC_CODE ){\ 00314 for( int i = 0 ; i < TC_SHORT_SIZE ; ++i ){\ 00315 temp_tm->TM_string[indexCustom + i] = temp_tc->TC_string[i];\ 00316 }\ 00317 indexCustom = indexCustom + TC_SHORT_SIZE;\ 00318 ++overflowCount;\ 00319 /*INCREMENT STUFF*/\ 00320 temp_tc = temp_tc->next_TC;\ 00321 num_of_short_tc = num_of_short_tc + 1;\ 00322 if (temp_tc == NULL){\ 00323 for (int i = indexCustom ; i < TM_LONG_SIZE-2 ; ++i){\ 00324 temp_tm->TM_string[i] = 0;\ 00325 /*Fill remaining values with 0*/\ 00326 }\ 00327 TC_LIST_TAG = num_of_short_tc;\ 00328 break;\ 00329 }\ 00330 if( (GETshort_or_long_tc(temp_tc) == LONG_TC_CODE) || (num_of_short_tc == OBOSC_TCL_MAX_SHORT_SIZE) ){\ 00331 /*Next TC is long or memory is filled*/\ 00332 for(int i = indexCustom; i < TM_LONG_SIZE-2 ; ++i){\ 00333 temp_tm->TM_string[i] = 0;\ 00334 /*Fill remaining values with 0*/\ 00335 }\ 00336 TC_LIST_TAG = num_of_short_tc;\ 00337 break;\ 00338 }\ 00339 }\ 00340 else if (TC_LIST_TAG == OBOSC_TCL_TAG_LONG_FIRST_HALF){\ 00341 /*Long TC, 2nd half*/\ 00342 for (int i = 0; i < OBOSC_LONG_TC_SECOND_HALF_SIZE ; ++i){\ 00343 temp_tm->TM_string[indexCustom + i] = temp_tc->TC_string[OBOSC_LONG_TC_FIRST_HALF_SIZE + i];\ 00344 /*Fill the TM with TC_values*/\ 00345 }\ 00346 for (int i = OBOSC_LONG_TC_SECOND_HALF_SIZE + indexCustom ; i < TM_LONG_SIZE-2 ; ++i ){\ 00347 temp_tm->TM_string[i] = 0;\ 00348 /*Fill remaining values with 0*/\ 00349 }\ 00350 temp_tc = temp_tc->next_TC;\ 00351 TC_LIST_TAG = OBOSC_TCL_TAG_LONG_SECOND_HALF;\ 00352 ++overflowCount;\ 00353 break;\ 00354 }\ 00355 else{\ 00356 /*Long TC, 1st half */\ 00357 for (int i = 0; i < OBOSC_LONG_TC_FIRST_HALF_SIZE; ++i){\ 00358 /*gPC.printf("indexCustom = %d\r\n", indexCustom);*/\ 00359 temp_tm->TM_string[indexCustom + i] = temp_tc->TC_string[i];\ 00360 /*Fill the TM with TC_values*/\ 00361 }\ 00362 for (int i = OBOSC_LONG_TC_FIRST_HALF_SIZE + indexCustom ; i < TM_LONG_SIZE-2 ; ++i ){\ 00363 temp_tm->TM_string[i] = 0;\ 00364 /*Fill remaining values with 0*/\ 00365 }\ 00366 TC_LIST_TAG = OBOSC_TCL_TAG_LONG_FIRST_HALF;\ 00367 break;\ 00368 }\ 00369 }\ 00370 else{\ 00371 /*PENDING: reset cdms*/\ 00372 break;\ 00373 }\ 00374 }\ 00375 temp_tm->TM_string[2] = TC_LIST_TAG;\ 00376 /*TC_LIST_TAG as is updated in the inner while loop*/\ 00377 uint16_t crc16 = crc16_gen(temp_tm->TM_string, TM_LONG_SIZE-2);\ 00378 temp_tm->TM_string[TM_LONG_SIZE-2] = (crc16 & 0xFF00) >> 8 ;\ 00379 temp_tm->TM_string[TM_LONG_SIZE-1] = crc16 & 0x00FF;\ 00380 /*Attach this new node to the TM linked list*/\ 00381 if( first_time ){\ 00382 first_time = false;\ 00383 tm_ptr = temp_tm;\ 00384 current_tm = temp_tm;\ 00385 }\ 00386 else{\ 00387 current_tm->next_TM = temp_tm;\ 00388 current_tm = current_tm->next_TM;\ 00389 }\ 00390 /*Attach this new node at the end*/\ 00391 }\ 00392 else{\ 00393 /*PENDING: reset CDMS*/\ 00394 break;\ 00395 }\ 00396 }\ 00397 } 00398 00399 // CDMS TEAM CODE START 00400 inline Base_tm* FCTN_CDMS_RLY_TMTC(Base_tc *tc_ptr){ 00401 uint8_t ACKCODE = 0xB0; 00402 //printf("\rTC execution in progress\r\n"); 00403 Base_tm *tm_pointer = new Long_tm; 00404 Base_tm *tm_ptr = tm_pointer; 00405 received = 0; 00406 switch(GETapid(tc_ptr)) 00407 { 00408 case 1: //apid=01 implies it corresponds to bae 00409 { 00410 //printf("Telecommand is for BAE\r\n"); 00411 //printf("Sending TC to BAE...\r\n"); //interrupt to be sent to the bae 00412 //FCTN_I2C_WRITE((char*)tc_ptr->TC_string); 00413 // while(1) 00414 // { 00415 // wait(1); //TimeOut instead of wait 00416 // if(tm_status_4m_slv == 1) 00417 // { 00418 // //printf("receiving...\r\n"); 00419 // FCTN_I2C_READ((char*)tm_pointer->TM_string,134); 00420 // //printf("%s", tm_pointer->TM_string); 00421 // received+=1; 00422 // tm_pointer = tm_pointer->next_TM; 00423 // break; //only for testing purpose 00424 // } 00425 // else 00426 // { 00427 // break; 00428 // } 00429 // } 00430 // if(received >= 1 ) 00431 // { 00432 // //printf("Telemetry is received from BAE\r\n"); 00433 // Base_tm *tm_print = tm_ptr; 00434 // for(uint8_t i=0;i<received;i++) 00435 // { 00436 // //printf("%s", tm_print->TM_string); 00437 // tm_print = tm_print->next_TM; //for check 00438 // } 00439 // received = 0; 00440 // tm_pointer->next_TM = NULL; return tm_ptr; 00441 // } 00442 // else 00443 // { 00444 // //printf("Telemetry is not received from BAE\r\n"); 00445 // //tm_pointer = new Short_tm; 00446 // tm_pointer->TM_string[0] = 0xB0; 00447 // tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00448 // tm_pointer->TM_string[2] = 0x01; 00449 // tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided 00450 // tm_pointer->TM_string[4] = 0x01; 00451 // for(uint8_t i=0;i<6;i++) 00452 // { 00453 // tm_pointer->TM_string[i+5] = 0; 00454 // } 00455 // crc16 = crc16_gen(tm_ptr->TM_string,11); 00456 // tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00457 // tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00458 tm_pointer->next_TM = NULL; return tm_ptr; 00459 // } 00460 break; 00461 } 00462 case 2: 00463 { 00464 //gPC.printf("Telecommand is for CDMS\r\n"); //apid = 10 corresponds to cdms 00465 switch(GETservice_type(tc_ptr)) 00466 { 00467 case 0x60: 00468 { 00469 //gPC.printf("service:MMS\r\n"); 00470 switch(GETservice_subtype(tc_ptr)) 00471 { 00472 case 0x1: 00473 { 00474 //printf("sub_service:Read from RAM_Memory\r\n"); 00475 mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]); 00476 00477 //Data[0] = FCTN_CDMS_RD_FLASH(0); 00478 //Data[1] = FCTN_CDMS_RD_FLASH(1); 00479 //tm_pointer = new Long_tm; 00480 tm_pointer->TM_string[0] = 0x30; 00481 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00482 tm_pointer->TM_string[2] = (uint8_t)(flash_counter); 00483 for(uint8_t i=0;i<4;i++) 00484 { 00485 tm_pointer->TM_string[3+i] = (uint8_t)((Data[0]>>(8*i))&0x00FF); 00486 } 00487 for(uint8_t i=4;i<8;i++) 00488 { 00489 tm_pointer->TM_string[3+i] = (uint8_t)((Data[1]>>(8*i))&0x00FF); 00490 } 00491 crc16 = crc16_gen(tm_ptr->TM_string,9); 00492 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00493 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00494 tm_pointer->next_TM = NULL; return tm_ptr; 00495 } 00496 case 0x2: 00497 { 00498 printf("sub_service:Read from Flash_Memory\r\n"); 00499 mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]); 00500 00501 //Data[0] = FCTN_CDMS_RD_FLASH(0); 00502 //Data[1] = FCTN_CDMS_RD_FLASH(1); 00503 //tm_pointer = new Long_tm; 00504 tm_pointer->TM_string[0] = 0xB0; 00505 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00506 tm_pointer->TM_string[2] = ACKCODE; 00507 00508 for(uint8_t i=0;i<4;i++) 00509 { 00510 tm_pointer->TM_string[3+i] = (uint8_t)((Data[0]>>(8*i))&0x00FF); 00511 } 00512 for(uint8_t i=4;i<8;i++) 00513 { 00514 tm_pointer->TM_string[3+i] = (uint8_t)((Data[1]>>(8*i))&0x00FF); 00515 } 00516 crc16 = crc16_gen(tm_ptr->TM_string,9); 00517 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00518 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00519 //for(int i = ) 00520 tm_pointer->next_TM = NULL; return tm_ptr; 00521 } 00522 case 0x5: 00523 { 00524 //printf("WRITE ON FLASH_MEMORY\r\n"); 00525 mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]); 00526 block = (((uint32_t)(tc_ptr->TC_string[5])<<24)|((uint32_t)(tc_ptr->TC_string[5])<<16)|((uint32_t)(tc_ptr->TC_string[5])<<8)|((uint32_t)(tc_ptr->TC_string[5]))); 00527 //FCTN_CDMS_WR_FLASH(mid,block); 00528 //tm_pointer = new Short_tm; 00529 tm_pointer->TM_string[0] = 0xB0; 00530 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00531 tm_pointer->TM_string[2] = 0x01; 00532 tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided 00533 tm_pointer->TM_string[4] = 0x01; 00534 for(uint8_t i=0;i<6;i++) 00535 { 00536 tm_pointer->TM_string[i+5] = 0; 00537 } 00538 crc16 = crc16_gen(tm_ptr->TM_string,11); 00539 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00540 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00541 tm_pointer->next_TM = NULL; return tm_ptr; 00542 break; 00543 } 00544 default: 00545 { 00546 //printf("INVALID TC\r\n"); //Send Invalid TC Telemetry 00547 //tm_pointer = new Short_tm; 00548 tm_pointer->TM_string[0] = 0xB0; 00549 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00550 tm_pointer->TM_string[2] = 0x01; 00551 tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided 00552 tm_pointer->TM_string[4] = 0x01; 00553 for(uint8_t i=0;i<6;i++) 00554 { 00555 tm_pointer->TM_string[i+5] = 0; 00556 } 00557 crc16 = crc16_gen(tm_ptr->TM_string,11); 00558 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00559 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00560 tm_pointer->next_TM = NULL; return tm_ptr; 00561 } 00562 break; 00563 } 00564 } 00565 case 0x8: 00566 { 00567 //printf("service:FUNCTION MANAGEMENT SERVICE\r\n"); 00568 if(GETservice_subtype(tc_ptr)==0x1) 00569 { 00570 if(GETpid(tc_ptr)==0x01) 00571 { 00572 //printf("TC_PL_INIT\r\n"); // call PWR_SWCH_ON function 00573 //tm_pointer = new Short_tm; 00574 tm_pointer->TM_string[0] = 0xB0; 00575 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00576 tm_pointer->TM_string[2] = ACKCODE; 00577 for(uint8_t i=3;i<11;i++) 00578 { 00579 tm_pointer->TM_string[i] = 0; 00580 } 00581 crc16 = crc16_gen(tm_ptr->TM_string,11); 00582 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00583 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00584 tm_pointer->next_TM = NULL; return tm_ptr; 00585 break; 00586 } 00587 else if(GETpid(tc_ptr)==0x02) 00588 { 00589 //printf("TC_PL_MAIN\r\n"); // call PWR_SWCH_ON function 00590 //tm_pointer = new Short_tm; 00591 tm_pointer->TM_string[0] = 0xB0; 00592 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00593 tm_pointer->TM_string[2] = ACKCODE; 00594 for(uint8_t i=3;i<11;i++) 00595 { 00596 tm_pointer->TM_string[i] = 0; 00597 } 00598 crc16 = crc16_gen(tm_ptr->TM_string,11); 00599 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00600 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00601 tm_pointer->next_TM = NULL; return tm_ptr; 00602 break; 00603 } 00604 else if(GETpid(tc_ptr)==0x03) 00605 { 00606 //printf("TC_COM_INIT\r\n"); // call PWR_SWCH_ON function 00607 //tm_pointer = new Short_tm; 00608 tm_pointer->TM_string[0] = 0xB0; 00609 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00610 tm_pointer->TM_string[2] = ACKCODE; 00611 for(uint8_t i=3;i<11;i++) 00612 { 00613 tm_pointer->TM_string[i] = 0; 00614 } 00615 crc16 = crc16_gen(tm_ptr->TM_string,11); 00616 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00617 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00618 tm_pointer->next_TM = NULL; return tm_ptr; 00619 break; 00620 } 00621 else if(GETpid(tc_ptr)==0x04) 00622 { 00623 //printf("TC_CDMS_HK_MAIN\r\n"); // call PWR_SWCH_ON function 00624 //tm_pointer = new Short_tm; 00625 tm_pointer->TM_string[0] = 0xB0; 00626 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00627 tm_pointer->TM_string[2] = ACKCODE; 00628 for(uint8_t i=3;i<11;i++) 00629 { 00630 tm_pointer->TM_string[i] = 0; 00631 } 00632 crc16 = crc16_gen(tm_ptr->TM_string,11); 00633 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00634 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00635 tm_pointer->next_TM = NULL; return tm_ptr; 00636 break; 00637 } 00638 else if(GETpid(tc_ptr)==0x11) 00639 { 00640 //printf("TC_SW_ON_SD\r\n"); // call PWR_SWCH_ON function 00641 //tm_pointer = new Short_tm; 00642 tm_pointer->TM_string[0] = 0xB0; 00643 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00644 tm_pointer->TM_string[2] = ACKCODE; 00645 for(uint8_t i=3;i<11;i++) 00646 { 00647 tm_pointer->TM_string[i] = 0; 00648 } 00649 crc16 = crc16_gen(tm_ptr->TM_string,11); 00650 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00651 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00652 tm_pointer->next_TM = NULL; return tm_ptr; 00653 break; 00654 } 00655 else if(GETpid(tc_ptr)==0x12) 00656 { 00657 //printf("TC_SW_ON_RTC\r\n"); // call PWR_SWCH_ON function 00658 //tm_pointer = new Short_tm; 00659 tm_pointer->TM_string[0] = 0xB0; 00660 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00661 tm_pointer->TM_string[2] = ACKCODE; 00662 for(uint8_t i=3;i<11;i++) 00663 { 00664 tm_pointer->TM_string[i] = 0; 00665 } 00666 crc16 = crc16_gen(tm_ptr->TM_string,11); 00667 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00668 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00669 tm_pointer->next_TM = NULL; return tm_ptr; 00670 break; 00671 } 00672 else if(GETpid(tc_ptr)==0x13) 00673 { 00674 //printf("TC_SW_ON_BAE\r\n"); // call PWR_SWCH_ON function 00675 //tm_pointer = new Short_tm; 00676 tm_pointer->TM_string[0] = 0xB0; 00677 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00678 tm_pointer->TM_string[2] = ACKCODE; 00679 for(uint8_t i=3;i<11;i++) 00680 { 00681 tm_pointer->TM_string[i] = 0; 00682 } 00683 crc16 = crc16_gen(tm_ptr->TM_string,11); 00684 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00685 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00686 tm_pointer->next_TM = NULL; return tm_ptr; 00687 break; 00688 } 00689 else if(GETpid(tc_ptr)==0x14) 00690 { 00691 //printf("TC_SW_ON_PL_DL\r\n"); // call PWR_SWCH_ON function 00692 //tm_pointer = new Short_tm; 00693 tm_pointer->TM_string[0] = 0xB0; 00694 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00695 tm_pointer->TM_string[2] = ACKCODE; 00696 for(uint8_t i=3;i<11;i++) 00697 { 00698 tm_pointer->TM_string[i] = 0; 00699 } 00700 crc16 = crc16_gen(tm_ptr->TM_string,11); 00701 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00702 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00703 tm_pointer->next_TM = NULL; return tm_ptr; 00704 break; 00705 } 00706 else if(GETpid(tc_ptr)==0x15) 00707 { 00708 //printf("TC_SW_ON_PL_AG_HV\r\n"); // call PWR_SWCH_ON function 00709 //tm_pointer = new Short_tm; 00710 tm_pointer->TM_string[0] = 0xB0; 00711 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00712 tm_pointer->TM_string[2] = ACKCODE; 00713 for(uint8_t i=3;i<11;i++) 00714 { 00715 tm_pointer->TM_string[i] = 0; 00716 } 00717 crc16 = crc16_gen(tm_ptr->TM_string,11); 00718 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00719 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00720 tm_pointer->next_TM = NULL; return tm_ptr; 00721 break; 00722 } 00723 else if(GETpid(tc_ptr)==0x16) 00724 { 00725 //printf("TC_SW_ON_V_A_EN\r\n"); // call PWR_SWCH_ON function 00726 //tm_pointer = new Short_tm; 00727 tm_pointer->TM_string[0] = 0xB0; 00728 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00729 tm_pointer->TM_string[2] = ACKCODE; 00730 for(uint8_t i=3;i<11;i++) 00731 { 00732 tm_pointer->TM_string[i] = 0; 00733 } 00734 crc16 = crc16_gen(tm_ptr->TM_string,11); 00735 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00736 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00737 tm_pointer->next_TM = NULL; return tm_ptr; 00738 break; 00739 } 00740 else if(GETpid(tc_ptr)==0x21) 00741 { 00742 //printf("TC_SW_OFF_SD\r\n"); // call PWR_SWCH_ON function 00743 //tm_pointer = new Short_tm; 00744 tm_pointer->TM_string[0] = 0xB0; 00745 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00746 tm_pointer->TM_string[2] = ACKCODE; 00747 for(uint8_t i=3;i<11;i++) 00748 { 00749 tm_pointer->TM_string[i] = 0; 00750 } 00751 crc16 = crc16_gen(tm_ptr->TM_string,11); 00752 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00753 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00754 tm_pointer->next_TM = NULL; return tm_ptr; 00755 break; 00756 } 00757 else if(GETpid(tc_ptr)==0x22) 00758 { 00759 //printf("TC_SW_OFF_RTC\r\n"); // call PWR_SWCH_ON function 00760 //tm_pointer = new Short_tm; 00761 tm_pointer->TM_string[0] = 0xB0; 00762 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00763 tm_pointer->TM_string[2] = ACKCODE; 00764 for(uint8_t i=3;i<11;i++) 00765 { 00766 tm_pointer->TM_string[i] = 0; 00767 } 00768 crc16 = crc16_gen(tm_ptr->TM_string,11); 00769 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00770 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00771 tm_pointer->next_TM = NULL; return tm_ptr; 00772 break; 00773 } 00774 else if(GETpid(tc_ptr)==0x23) 00775 { 00776 //printf("TC_SW_OFF_BAE\r\n"); // call PWR_SWCH_ON function 00777 //tm_pointer = new Short_tm; 00778 tm_pointer->TM_string[0] = 0xB0; 00779 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00780 tm_pointer->TM_string[2] = ACKCODE; 00781 for(uint8_t i=3;i<11;i++) 00782 { 00783 tm_pointer->TM_string[i] = 0; 00784 } 00785 crc16 = crc16_gen(tm_ptr->TM_string,11); 00786 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00787 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00788 tm_pointer->next_TM = NULL; return tm_ptr; 00789 break; 00790 } 00791 else if(GETpid(tc_ptr)==0x24) 00792 { 00793 //printf("TC_SW_OFF_PL_DL\r\n"); // call PWR_SWCH_ON function 00794 //tm_pointer = new Short_tm; 00795 tm_pointer->TM_string[0] = 0xB0; 00796 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00797 tm_pointer->TM_string[2] = ACKCODE; 00798 for(uint8_t i=3;i<11;i++) 00799 { 00800 tm_pointer->TM_string[i] = 0; 00801 } 00802 crc16 = crc16_gen(tm_ptr->TM_string,11); 00803 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00804 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00805 tm_pointer->next_TM = NULL; return tm_ptr; 00806 break; 00807 } 00808 else if(GETpid(tc_ptr)==0x25) 00809 { 00810 //printf("TC_SW_OFF_PL_AG_HV\r\n"); // call PWR_SWCH_ON function 00811 //tm_pointer = new Short_tm; 00812 tm_pointer->TM_string[0] = 0xB0; 00813 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00814 tm_pointer->TM_string[2] = ACKCODE; 00815 for(uint8_t i=3;i<11;i++) 00816 { 00817 tm_pointer->TM_string[i] = 0; 00818 } 00819 crc16 = crc16_gen(tm_ptr->TM_string,11); 00820 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00821 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00822 tm_pointer->next_TM = NULL; return tm_ptr; 00823 break; 00824 } 00825 else if(GETpid(tc_ptr)==0x26) 00826 { 00827 //printf("TC_SW_OFF_V_A_EN\r\n"); // call PWR_SWCH_ON function 00828 //tm_pointer = new Short_tm; 00829 tm_pointer->TM_string[0] = 0xB0; 00830 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00831 tm_pointer->TM_string[2] = ACKCODE; 00832 for(uint8_t i=3;i<11;i++) 00833 { 00834 tm_pointer->TM_string[i] = 0; 00835 } 00836 crc16 = crc16_gen(tm_ptr->TM_string,11); 00837 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00838 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00839 tm_pointer->next_TM = NULL; return tm_ptr; 00840 break; 00841 } 00842 else if(GETpid(tc_ptr)==0x31) 00843 { 00844 //printf("TC_RST_SD\r\n"); // call PWR_SWCH_ON function 00845 //tm_pointer = new Short_tm; 00846 tm_pointer->TM_string[0] = 0xB0; 00847 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00848 tm_pointer->TM_string[2] = ACKCODE; 00849 for(uint8_t i=3;i<11;i++) 00850 { 00851 tm_pointer->TM_string[i] = 0; 00852 } 00853 crc16 = crc16_gen(tm_ptr->TM_string,11); 00854 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00855 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00856 tm_pointer->next_TM = NULL; return tm_ptr; 00857 break; 00858 } 00859 else if(GETpid(tc_ptr)==0x32) 00860 { 00861 //printf("TC_RST_RTC\r\n"); // call PWR_SWCH_ON function 00862 //tm_pointer = new Short_tm; 00863 tm_pointer->TM_string[0] = 0xB0; 00864 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00865 tm_pointer->TM_string[2] = ACKCODE; 00866 for(uint8_t i=3;i<11;i++) 00867 { 00868 tm_pointer->TM_string[i] = 0; 00869 } 00870 crc16 = crc16_gen(tm_ptr->TM_string,11); 00871 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00872 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00873 tm_pointer->next_TM = NULL; return tm_ptr; 00874 break; 00875 } 00876 else if(GETpid(tc_ptr)==0x33) 00877 { 00878 //printf("TC_RST_BAE\r\n"); // call PWR_SWCH_ON function 00879 //tm_pointer = new Short_tm; 00880 tm_pointer->TM_string[0] = 0xB0; 00881 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00882 tm_pointer->TM_string[2] = ACKCODE; 00883 for(uint8_t i=3;i<11;i++) 00884 { 00885 tm_pointer->TM_string[i] = 0; 00886 } 00887 crc16 = crc16_gen(tm_ptr->TM_string,11); 00888 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00889 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00890 tm_pointer->next_TM = NULL; return tm_ptr; 00891 break; 00892 } 00893 else if(GETpid(tc_ptr)==0x34) 00894 { 00895 //printf("TC_RST_PL_DL\r\n"); // call PWR_SWCH_ON function 00896 //tm_pointer = new Short_tm; 00897 tm_pointer->TM_string[0] = 0xB0; 00898 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00899 tm_pointer->TM_string[2] = ACKCODE; 00900 for(uint8_t i=3;i<11;i++) 00901 { 00902 tm_pointer->TM_string[i] = 0; 00903 } 00904 crc16 = crc16_gen(tm_ptr->TM_string,11); 00905 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00906 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00907 tm_pointer->next_TM = NULL; return tm_ptr; 00908 break; 00909 break; 00910 } 00911 else if(GETpid(tc_ptr)==0xC1) 00912 { 00913 //printf("RESET_HK_COUNTER\r\n"); // call PWR_SWCH_ON function 00914 //tm_pointer = new Short_tm; 00915 tm_pointer->TM_string[0] = 0xB0; 00916 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00917 tm_pointer->TM_string[2] = ACKCODE; 00918 for(uint8_t i=3;i<11;i++) 00919 { 00920 tm_pointer->TM_string[i] = 0; 00921 } 00922 crc16 = crc16_gen(tm_ptr->TM_string,11); 00923 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00924 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00925 tm_pointer->next_TM = NULL; return tm_ptr; 00926 break; 00927 } 00928 else if(GETpid(tc_ptr)==0xF1) 00929 { 00930 //printf("RD_RTC\r\n"); //call RD_RTC 00931 //tm_pointer = new Short_tm; 00932 tm_pointer->TM_string[0] = 0xD0; 00933 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00934 tm_pointer->TM_string[2] = 0x01; 00935 uint64_t time = FCTN_CDMS_RD_RTC(); 00936 tm_pointer->TM_string[3] = (uint8_t)((time&0xFF00000000000000)>>56); 00937 tm_pointer->TM_string[4] = (uint8_t)((time&0x00FF000000000000)>>48); 00938 tm_pointer->TM_string[5] = (uint8_t)((time&0x0000FF0000000000)>>40); 00939 tm_pointer->TM_string[6] = (uint8_t)((time&0x000000FF00000000)>>32); 00940 tm_pointer->TM_string[7] = (uint8_t)((time&0x00000000FF000000)>>24); 00941 tm_pointer->TM_string[8] = (uint8_t)((time&0x0000000000FF0000)>>16); 00942 tm_pointer->TM_string[9] = (uint8_t)((time&0x000000000000FF00)>>8); 00943 tm_pointer->TM_string[10] = (uint8_t)(time&0x00000000000000FF); 00944 crc16 = crc16_gen(tm_ptr->TM_string,11); 00945 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00946 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00947 tm_pointer->next_TM = NULL; return tm_ptr; 00948 } 00949 else 00950 { 00951 //printf("INVALID TC\r\n"); 00952 //tm_pointer = new Short_tm; 00953 tm_pointer->TM_string[0] = 0xB0; 00954 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00955 tm_pointer->TM_string[2] = 0x01; 00956 tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided 00957 tm_pointer->TM_string[4] = 0x01; 00958 for(uint8_t i=0;i<6;i++) 00959 { 00960 tm_pointer->TM_string[i+5] = 0; 00961 } 00962 crc16 = crc16_gen(tm_ptr->TM_string,11); 00963 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00964 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00965 tm_pointer->next_TM = NULL; return tm_ptr; 00966 } 00967 } 00968 00969 00970 } 00971 default: 00972 { 00973 //printf("INVALID TC"); //send invalid TC TM 00974 //tm_pointer = new Short_tm; 00975 tm_pointer->TM_string[0] = 0xB0; 00976 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00977 tm_pointer->TM_string[2] = 0x01; 00978 tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided 00979 tm_pointer->TM_string[4] = 0x01; 00980 for(uint8_t i=0;i<6;i++) 00981 { 00982 tm_pointer->TM_string[i+5] = 0; 00983 } 00984 crc16 = crc16_gen(tm_ptr->TM_string,11); 00985 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00986 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00987 tm_pointer->next_TM = NULL; return tm_ptr; 00988 break; 00989 } 00990 } 00991 } 00992 case 3: 00993 { 00994 00995 00996 00997 #if DEBUG 00998 printf("Telecommand is for PL\r\n"); 00999 #endif 01000 01001 01002 if(GETservice_subtype(tc_ptr) == 0xD0 || GETservice_subtype(tc_ptr) == 0xD2 || GETservice_subtype(tc_ptr) == 0xD3) 01003 { 01004 PL_TM_SIZE = TM_LONG_SIZE; 01005 } 01006 else 01007 { 01008 PL_TM_SIZE = TM_SHORT_SIZE; 01009 } 01010 01011 if(GETshort_or_long_tc(tc_ptr) == LONG_TC_CODE) 01012 FCTN_I2C_WRITE_PL((char*)tc_ptr->TC_string,TC_LONG_SIZE); 01013 else 01014 { 01015 FCTN_I2C_WRITE_PL((char*)tc_ptr->TC_string,TC_SHORT_SIZE); 01016 } 01017 01018 01019 while(1) 01020 { 01021 gLEDG = !gLEDG; 01022 t_pl.start(); 01023 if(rcv_isr == 1) 01024 { 01025 gPC.printf("read_ack = %d",read_ack); 01026 t_pl.stop(); 01027 //gPC.printf("i2c_t = %d",t_pl.read_ms()); 01028 for(int i = 0;i< PL_TM_SIZE;i++) 01029 tm_pointer->TM_string[i] = PL_I2C_DATA[i]; 01030 rcv_isr = 0; 01031 break; 01032 } 01033 } 01034 tm_pointer->next_TM = NULL; return tm_ptr; 01035 break; 01036 } 01037 default: //invalid TC 01038 { 01039 //printf("INVALID TC\r\n"); 01040 //tm_pointer = new Short_tm; 01041 tm_pointer->TM_string[0] = 0xB0; 01042 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 01043 tm_pointer->TM_string[2] = 0x01; 01044 tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided 01045 tm_pointer->TM_string[4] = 0x01; 01046 for(uint8_t i=0;i<6;i++) 01047 { 01048 tm_pointer->TM_string[i+5] = 0; 01049 } 01050 crc16 = crc16_gen(tm_ptr->TM_string,11); 01051 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 01052 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 01053 tm_pointer->next_TM = NULL; return tm_ptr; 01054 break; 01055 } 01056 } 01057 } 01058 // CDMS TEAM CODE END 01059 // EXECUTE OBOSC 01060 #define execute_obosc_core(tc_ptr, tm_ptr, reset_flag) {\ 01061 uint8_t service_subtype = (tc_ptr->TC_string[2]) & 0x0F;\ 01062 uint8_t temp8 = 0x00;\ 01063 Base_tc *modify_this = gHEAD_NODE_TCL;\ 01064 int modify_overflow = 0x00;\ 01065 switch( service_subtype ){\ 01066 case OBOSC_SUB_DISABLE:\ 01067 /*gPC.puts("target psc are ");*/\ 01068 for(int i = 3 ; i < 9 ; ++i){\ 01069 /*gPC.printf("%u ", tc_ptr->TC_string[i]);*/\ 01070 }\ 01071 /*gPC.puts("\r\n");*/\ 01072 /*gPC.puts("disable type obosc\r\n");*/\ 01073 while( modify_this != NULL ){\ 01074 if( modify_overflow < TCL_OVERFLOW_CONSTANT ){\ 01075 uint8_t modify_psc = GETpacket_seq_count(modify_this);\ 01076 /*gPC.printf("mosify_psc = %u\r\n", modify_psc);*/\ 01077 for( int i = 3 ; i < 9 ; ++i ){\ 01078 uint8_t target_psc = tc_ptr->TC_string[i];\ 01079 if( (target_psc == modify_psc) && (target_psc != 0) ){\ 01080 uint16_t tempExec = TC_STATE_DISABLED;\ 01081 PUTexec_status( modify_this, tempExec );\ 01082 break;\ 01083 }\ 01084 }\ 01085 modify_this = modify_this->next_TC;\ 01086 ++modify_overflow;\ 01087 }\ 01088 else{\ 01089 /*PENDING: RESET CDMS*/\ 01090 break;\ 01091 }\ 01092 }\ 01093 break;\ 01094 case OBOSC_SUB_RETRY:\ 01095 /*gPC.puts("retry type obosc\r\n");*/\ 01096 while( modify_this != NULL ){\ 01097 if( modify_overflow < TCL_OVERFLOW_CONSTANT ){\ 01098 uint8_t modify_psc = GETpacket_seq_count(modify_this);\ 01099 for( int i = 3 ; i < 9 ; ++i ){\ 01100 uint8_t target_psc = tc_ptr->TC_string[i];\ 01101 if( (target_psc == modify_psc) && (target_psc != 0) ){\ 01102 uint16_t tempExec = TC_STATE_MARKED_RETRY;\ 01103 PUTexec_status( modify_this, tempExec );\ 01104 /*gPC.puts("reqquired tc found: disable\r\n");*/\ 01105 break;\ 01106 }\ 01107 }\ 01108 modify_this = modify_this->next_TC;\ 01109 ++modify_overflow;\ 01110 }\ 01111 else{\ 01112 /*PENDING: RESET CDMS*/\ 01113 break;\ 01114 }\ 01115 }\ 01116 break;\ 01117 }\ 01118 Base_tm *ackl234new = new Short_tm;\ 01119 ackl234new->next_TM = NULL;\ 01120 /*return telemetry pointer here*/\ 01121 tm_ptr = ackl234new;\ 01122 ackl234new->TM_string[0] = TMID_ACK_L234 << 4;\ 01123 ackl234new->TM_string[1] = GETpacket_seq_count(tc_ptr);\ 01124 ackl234new->TM_string[2] = 0xA0;\ 01125 for(int i = 3; i < 11; ++i){\ 01126 ackl234new->TM_string[i] = 0x00;\ 01127 }\ 01128 uint16_t crc = crc16_gen(ackl234new->TM_string, TM_SHORT_SIZE-2);\ 01129 ackl234new->TM_string[11] = (crc & 0xFF00) >> 8;\ 01130 ackl234new->TM_string[12] = crc & 0x00FF;\ 01131 /*ack l234 old*/\ 01132 if( service_subtype == OBOSC_SUB_REP_LE ){\ 01133 if( gLAST_TM_SHORT_OR_LONG == SHORT_TM_CODE ){\ 01134 Base_tm *ackl234old = new Short_tm;\ 01135 ackl234old->next_TM = NULL;\ 01136 /*APPEND TO ACK L234 NEW HERE*/\ 01137 ackl234new->next_TM = ackl234old;\ 01138 for( int i = 0 ; i < TM_SHORT_SIZE ; ++i ){\ 01139 ackl234old->TM_string[i] = gLAST_TM[i];\ 01140 }\ 01141 }\ 01142 else{\ 01143 Base_tm *tempLongTM = new Long_tm;\ 01144 tempLongTM->next_TM = NULL;\ 01145 /*APPEND TO ACK L234 NEW HERE*/\ 01146 ackl234new->next_TM = tempLongTM;\ 01147 for( int i = 0 ; i < TM_LONG_SIZE ; ++i ){\ 01148 tempLongTM->TM_string[i] = gLAST_TM[i];\ 01149 }\ 01150 }\ 01151 }\ 01152 else if( service_subtype == OBOSC_SUB_REP_TCLD ){\ 01153 get_tc_list(ackl234new->next_TM, GETpacket_seq_count(tc_ptr));\ 01154 }\ 01155 else if( service_subtype == OBOSC_SUB_RESET ){\ 01156 /*reset_all;*/\ 01157 reset_flag = 1;\ 01158 /*PENDING: VERIFY reset_all, RESET CDMS*/\ 01159 }\ 01160 else if( (service_subtype != OBOSC_SUB_DISABLE) && (service_subtype != OBOSC_SUB_RETRY) ){\ 01161 /*CHANGE THE ACK CODE TO INVALID TC*/\ 01162 ackl234new->TM_string[2] = 0xA2;\ 01163 }\ 01164 /*gPC.puts("completed obosc\r\n");*/\ 01165 } 01166 01167 /*tm_ptr is the next_TM of a linked list, and should have the value NULL, i.e. tm_ptr should be the next_TM pointer of thte last node */ 01168 #define get_call_sign(tm_ptr) {\ 01169 Base_tm* call_sign_tm = new Short_tm;\ 01170 call_sign_tm->next_TM = NULL;\ 01171 tm_ptr = call_sign_tm;\ 01172 for( int i = 0 ; i < TM_SHORT_SIZE ; ++i ){\ 01173 call_sign_tm->TM_string[i] = gCALL_SIGN_STRING[i];\ 01174 }\ 01175 } 01176 01177 #define EXECUTE_OBOSC_ONLY {\ 01178 int reset_flag = 0;\ 01179 for(uint8_t execute_psc = PSC_START_VALUE ; execute_psc < gTOTAL_VALID_TC ; ++execute_psc){\ 01180 Base_tc* current_TC = gHEAD_NODE_TCL;\ 01181 int overCount = 0;\ 01182 while( current_TC != NULL ){\ 01183 if( overCount < TCL_OVERFLOW_CONSTANT ){\ 01184 if( (GETcrc_pass(current_TC) == 1) && (GETpacket_seq_count(current_TC) == execute_psc) ){\ 01185 /*CHECK FOR OBOSC*/\ 01186 uint8_t temp82 = 0x00;\ 01187 isit_obosc(current_TC, temp82);\ 01188 if(temp82 == 0x01){\ 01189 uint16_t current_exec_status = GETexec_status(current_TC);\ 01190 if( (current_exec_status == TC_STATE_SUCCESSFULLY_EXECUTED) || (current_exec_status == TC_STATE_DISABLED) )\ 01191 break;\ 01192 else if( (current_exec_status == TC_STATE_UNEXECUTED) || (current_exec_status == TC_STATE_MARKED_RETRY) ){\ 01193 /*gPC.printf("It is obosc: %u\r\n", execute_psc);*/\ 01194 /*EXECUTION OF OBOSC TC*/\ 01195 /*WARNING: LARGE MEMORY UTILIZATION FOR TC-LIST-REPORT */\ 01196 Base_tm *obosc_tm_head = NULL;\ 01197 get_call_sign(obosc_tm_head);\ 01198 Base_tm *obosc_tm_core = NULL;\ 01199 execute_obosc_core(current_TC, obosc_tm_core, reset_flag);\ 01200 uint16_t temp16 = TC_STATE_SUCCESSFULLY_EXECUTED;\ 01201 PUTexec_status(current_TC, temp16);\ 01202 Base_tm *obosc_tm_current = obosc_tm_head;\ 01203 get_ack_l1(obosc_tm_current->next_TM);\ 01204 int overflowCountOBONLY = 0;\ 01205 while( obosc_tm_current->next_TM != NULL ){\ 01206 if( overflowCountOBONLY < TM_OVERFLOW_CONSTANT ){\ 01207 obosc_tm_current = obosc_tm_current->next_TM;\ 01208 ++overflowCountOBONLY;\ 01209 }\ 01210 else{\ 01211 /*PENDING: RESET CDMS*/\ 01212 break;\ 01213 }\ 01214 }\ 01215 obosc_tm_current->next_TM = obosc_tm_core;\ 01216 obosc_tm_current = obosc_tm_head;\ 01217 while( obosc_tm_current != NULL ){\ 01218 int length = TM_SHORT_SIZE;\ 01219 if( GETshort_or_long_tm(obosc_tm_current) == SHORT_TM_CODE ){\ 01220 length = TM_SHORT_SIZE;\ 01221 }\ 01222 else{\ 01223 length = TM_LONG_SIZE;\ 01224 }\ 01225 for(int i = 0 ; i < length ; ++i){\ 01226 /*gPC.putc(obosc_tm_current->TM_string[i]);*/\ 01227 }\ 01228 obosc_tm_current = obosc_tm_current->next_TM;\ 01229 }\ 01230 /*Sending OBOSC TM to GS*/\ 01231 /*snd_tm.head_pointer(obosc_tm_head);*/\ 01232 /*transmit_adf;*/\ 01233 /*DELETE THE TM AFTER USE*/\ 01234 obosc_tm_current = obosc_tm_head;\ 01235 int overCount = 0;\ 01236 while( obosc_tm_current != NULL ){\ 01237 if( (overCount < TM_OVERFLOW_CONSTANT) ){\ 01238 Base_tm *temp = obosc_tm_current->next_TM;\ 01239 delete obosc_tm_current;\ 01240 obosc_tm_current = temp;\ 01241 ++overCount;\ 01242 }\ 01243 else{\ 01244 /*PENDING: RESET CDMS: MEMORY LEAK FOUND*/\ 01245 break;\ 01246 }\ 01247 }\ 01248 if ( reset_flag ==1 ){\ 01249 reset_all;\ 01250 }\ 01251 }\ 01252 }\ 01253 }\ 01254 current_TC = current_TC->next_TC;\ 01255 ++overCount;\ 01256 }\ 01257 else{\ 01258 /*PENDING: REST CDMS: MEMORY LEAK FOUND*/\ 01259 break;\ 01260 }\ 01261 }\ 01262 }\ 01263 } 01264 01265 #define EXECUTE_TC {\ 01266 gMASTER_STATE = TCL_STATE_EXECUTING;\ 01267 /*gPC.printf("%u\r\n", gTOTAL_VALID_TC);*/\ 01268 for(uint8_t execute_psc = PSC_START_VALUE ; execute_psc < gTOTAL_VALID_TC ; ++execute_psc ){\ 01269 /*gPC.printf("executing normal %u\r\n", execute_psc);*/\ 01270 /*gLEDG = !gLEDG;*/\ 01271 /*gLEDR = !gLEDR;*/\ 01272 Base_tc* current_TC = gHEAD_NODE_TCL;\ 01273 int overflowCount = 0;\ 01274 while(current_TC != NULL){\ 01275 if( overflowCount < TCL_OVERFLOW_CONSTANT ){\ 01276 if( (GETcrc_pass(current_TC) == 1) && (GETpacket_seq_count(current_TC) == execute_psc) ){\ 01277 uint8_t current_exec_status = GETexec_status(current_TC);\ 01278 if( (current_exec_status == TC_STATE_SUCCESSFULLY_EXECUTED) || (current_exec_status == TC_STATE_DISABLED) ){\ 01279 /*gPC.printf("disabled or completed at %u\n", execute_psc);*/\ 01280 break;\ 01281 }\ 01282 else if( (current_exec_status == TC_STATE_EXECUTION_FAILED) && (GETabort_on_nack(current_TC) == 1) ){\ 01283 /*gPC.printf("abort on nack at %u psc\r\n", execute_psc);*/\ 01284 gMASTER_STATE = TCL_STATE_ABORTED;\ 01285 Base_tm *tm_ptr_head = NULL;\ 01286 get_call_sign(tm_ptr_head);\ 01287 Base_tm *tm_ptr = tm_ptr_head;\ 01288 get_ack_l1(tm_ptr->next_TM);\ 01289 tm_ptr = tm_ptr_head;\ 01290 while( tm_ptr != NULL ){\ 01291 int length = TM_SHORT_SIZE;\ 01292 if( GETshort_or_long_tm(tm_ptr) == SHORT_TM_CODE ){\ 01293 length = TM_SHORT_SIZE;\ 01294 }\ 01295 else{\ 01296 length = TM_LONG_SIZE;\ 01297 }\ 01298 /*gPC.puts("Printing Call Sign, ACK_L1, TM list");*/\ 01299 for(int i = 0 ; i < length ; ++i){\ 01300 /*gPC.putc(tm_ptr->TM_string[i]);*/\ 01301 }\ 01302 tm_ptr = tm_ptr->next_TM;\ 01303 }\ 01304 /*Send only call sign, ACK_L1 to GS*/\ 01305 /*snd_tm.head_pointer(tm_ptr_head);*/\ 01306 /*transmit_adf;*/\ 01307 /*DELETE THE TM AFTER USE*/\ 01308 tm_ptr = tm_ptr_head;\ 01309 int overflowCountExecute = 0;\ 01310 while(tm_ptr != NULL){\ 01311 if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\ 01312 Base_tm *temp = tm_ptr->next_TM;\ 01313 delete tm_ptr;\ 01314 tm_ptr = temp;\ 01315 ++overflowCountExecute;\ 01316 }\ 01317 else{\ 01318 /*PENDING: RESET CDMS*/\ 01319 break;\ 01320 }\ 01321 }\ 01322 break;\ 01323 }\ 01324 else if( (current_exec_status == TC_STATE_UNEXECUTED) || (current_exec_status == TC_STATE_MARKED_RETRY) ){\ 01325 /*EXECUTION OF TC START*/\ 01326 uint8_t temp81 = 0x00;\ 01327 isit_sdcard(current_TC, temp81);\ 01328 if( temp81 == 0x00 ){\ 01329 /*gPC.printf("non sd card at %u\r\n", execute_psc);*/\ 01330 /*EXECUTION OF NON SD-CARD (BOTH OBOSC and CDMS functions)*/\ 01331 Base_tm *tm_ptr_head = NULL;\ 01332 get_call_sign(tm_ptr_head);\ 01333 Base_tm *put_tm_here = NULL;\ 01334 uint8_t temp82 = 0x00;\ 01335 uint8_t tempPAhot = 0x00;\ 01336 isit_obosc(current_TC, temp82);\ 01337 if(temp82 == 0x01){\ 01338 /*gPC.printf("obosc tc inside normal tc at %u\r\n", execute_psc);*/\ 01339 /*EXECUTION OF OBOSC TC*/\ 01340 /*SKIP EXECUTION OF OBOSC HERE*/\ 01341 break;\ 01342 }\ 01343 else{\ 01344 /*gPC.printf("cdms relay tmtc at %u\r\n", execute_psc);*/\ 01345 /*call CDMS_RLY_TMTC*/\ 01346 /*CDMS_RLY_TMTC(current_TC, put_tm_here);*/\ 01347 put_tm_here = FCTN_CDMS_RLY_TMTC(current_TC);\ 01348 }\ 01349 /*DETECT ACK OR NACK*/\ 01350 uint8_t temp83 = 0x00;\ 01351 uint8_t temp84 = GETpacket_seq_count(current_TC);\ 01352 detect_ack(put_tm_here, temp83, temp84);\ 01353 if( temp83 == 0x01){\ 01354 uint16_t temp16 = TC_STATE_SUCCESSFULLY_EXECUTED;\ 01355 PUTexec_status(current_TC, temp16);\ 01356 }\ 01357 else{\ 01358 /*gPC.puts("TC_STATE_EXECUTION_FAILED");*/\ 01359 uint16_t temp16 = TC_STATE_EXECUTION_FAILED;\ 01360 PUTexec_status(current_TC, temp16);\ 01361 }\ 01362 /*ABORT ON NACK AND TC LIST COMPLETED: UPDATE IN gMASTERSTATE*/\ 01363 if( (GETexec_status(current_TC) == TC_STATE_EXECUTION_FAILED) && (GETabort_on_nack(current_TC) == 1) ){\ 01364 gMASTER_STATE = TCL_STATE_ABORTED;\ 01365 }\ 01366 else if( execute_psc == (gTOTAL_VALID_TC-1) ){\ 01367 /*LAST TC IS EXECUTED*/\ 01368 gMASTER_STATE = TCL_STATE_COMPLETED;\ 01369 }\ 01370 else{\ 01371 uint8_t check1 = 1;\ 01372 for( uint8_t test_psc = execute_psc+1 ; test_psc < gTOTAL_VALID_TC ; ++test_psc ){\ 01373 Base_tc* test_TC = gHEAD_NODE_TCL;\ 01374 while(test_TC != NULL){\ 01375 if( GETpacket_seq_count(test_TC) == test_psc ){\ 01376 uint8_t checkval;\ 01377 isit_obosc(test_TC, checkval);\ 01378 if( checkval == 0 ){\ 01379 check1 = 0;\ 01380 }\ 01381 }\ 01382 test_TC = test_TC->next_TC;\ 01383 }\ 01384 }\ 01385 if( check1 == 0x01 ){\ 01386 gMASTER_STATE = TCL_STATE_COMPLETED;\ 01387 }\ 01388 }\ 01389 /*update last executed L1_ack*/\ 01390 if( put_tm_here != NULL ){\ 01391 if( GETshort_or_long_tm(put_tm_here) == SHORT_TM_CODE ){\ 01392 for(int i = 0 ; i < TM_SHORT_SIZE ; ++i){\ 01393 gLAST_TM[i] = put_tm_here->TM_string[i];\ 01394 gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;\ 01395 }\ 01396 }\ 01397 else{\ 01398 for( int i = 0 ; i < TM_LONG_SIZE ; ++i ){\ 01399 gLAST_TM[i] = put_tm_here->TM_string[i];\ 01400 gLAST_TM_SHORT_OR_LONG = LONG_TM_CODE;\ 01401 }\ 01402 }\ 01403 }\ 01404 /*PENDING: APPEND ACK L1*/\ 01405 Base_tm *tm_ptr = tm_ptr_head;\ 01406 get_ack_l1(tm_ptr->next_TM);\ 01407 int overflowCountExecute = 0;\ 01408 while( tm_ptr->next_TM != NULL ){\ 01409 if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\ 01410 tm_ptr = tm_ptr->next_TM;\ 01411 ++overflowCountExecute;\ 01412 }\ 01413 else{\ 01414 /*PENDING: RESET CDMS*/\ 01415 break;\ 01416 }\ 01417 }\ 01418 tm_ptr->next_TM = put_tm_here;\ 01419 /*CHECK FOR HOT PA*/\ 01420 isPAhot(tempPAhot);\ 01421 if( tempPAhot == 0x00 ){\ 01422 gFLAGS = gFLAGS | COM_PA_HOT_FLAG;\ 01423 }\ 01424 tm_ptr = tm_ptr_head;\ 01425 while( tm_ptr != NULL ){\ 01426 int length = TM_SHORT_SIZE;\ 01427 if( GETshort_or_long_tm(tm_ptr) == SHORT_TM_CODE ){\ 01428 length = TM_SHORT_SIZE;\ 01429 }\ 01430 else{\ 01431 length = TM_LONG_SIZE;\ 01432 }\ 01433 /*gPC.puts("Printing Call Sign, ACK_L1, TM list");*/\ 01434 for(int i = 0 ; i < length ; ++i){\ 01435 /*gPC.putc(tm_ptr->TM_string[i]);*/\ 01436 }\ 01437 tm_ptr = tm_ptr->next_TM;\ 01438 }\ 01439 /*SEND call sign, ACK_L1, NON OBSRS TM TO GS*/\ 01440 snd_tm.head_pointer(tm_ptr_head);\ 01441 transmit_adf;\ 01442 /*DELETE THE TM AFTER USE*/\ 01443 tm_ptr = tm_ptr_head;\ 01444 overflowCountExecute = 0;\ 01445 while(tm_ptr != NULL){\ 01446 if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\ 01447 Base_tm *temp = tm_ptr->next_TM;\ 01448 delete tm_ptr;\ 01449 tm_ptr = temp;\ 01450 ++overflowCountExecute;\ 01451 }\ 01452 else{\ 01453 /*PENDING: RESET CDMS*/\ 01454 break;\ 01455 }\ 01456 }\ 01457 }\ 01458 else{\ 01459 /*gPC.printf("sd card at %u\r\n", execute_psc);*/\ 01460 /*EXECUTION OF SD-CARD DATA SENDING (OBSRS)*/\ 01461 Base_tm *tm_ptr_head = NULL;\ 01462 get_call_sign(tm_ptr_head);\ 01463 Base_tm *put_tm_here = NULL;\ 01464 /*execute_obsrs(current_TC, put_tm_here)*/\ 01465 /*read_TC(current_TC);*/\ 01466 execute_OBSRS_TC(current_TC);\ 01467 transmit_adf;\ 01468 uint8_t tempExec = TC_STATE_SUCCESSFULLY_EXECUTED;\ 01469 PUTexec_status(current_TC, tempExec);\ 01470 /*PENDING: ABORT ON NACK CHECK, gMASTER_STATE VERIFICATION WITH SD CARD, session timeout, last executed ack l234*/\ 01471 if( (GETexec_status(current_TC) == TC_STATE_EXECUTION_FAILED) && (GETabort_on_nack(current_TC) == 1) ){\ 01472 gMASTER_STATE = TCL_STATE_ABORTED;\ 01473 }\ 01474 else if( execute_psc == (gTOTAL_VALID_TC-1) ){\ 01475 gMASTER_STATE = TCL_STATE_COMPLETED;\ 01476 }\ 01477 else{\ 01478 uint8_t check1 = 1;\ 01479 for( uint8_t test_psc = execute_psc+1 ; test_psc < gTOTAL_VALID_TC ; ++test_psc ){\ 01480 Base_tc* test_TC = gHEAD_NODE_TCL;\ 01481 while(test_TC != NULL){\ 01482 if( GETpacket_seq_count(test_TC) == test_psc ){\ 01483 uint8_t checkval;\ 01484 isit_obosc(test_TC, checkval);\ 01485 if( checkval == 0 ){\ 01486 check1 = 0;\ 01487 }\ 01488 }\ 01489 test_TC = test_TC->next_TC;\ 01490 }\ 01491 }\ 01492 if( check1 == 0x01 ){\ 01493 gMASTER_STATE = TCL_STATE_COMPLETED;\ 01494 }\ 01495 }\ 01496 /*update last executed L1_ack*/\ 01497 if( put_tm_here != NULL ){\ 01498 if( GETshort_or_long_tm(put_tm_here) == SHORT_TM_CODE ){\ 01499 for(int i = 0 ; i < TM_SHORT_SIZE ; ++i){\ 01500 gLAST_TM[i] = put_tm_here->TM_string[i];\ 01501 gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;\ 01502 }\ 01503 }\ 01504 else{\ 01505 for( int i = 0 ; i < TM_LONG_SIZE ; ++i ){\ 01506 gLAST_TM[i] = put_tm_here->TM_string[i];\ 01507 gLAST_TM_SHORT_OR_LONG = LONG_TM_CODE;\ 01508 }\ 01509 }\ 01510 }\ 01511 /*PENDING: APPEND ACK L1*/\ 01512 Base_tm *tm_ptr = tm_ptr_head;\ 01513 get_ack_l1(tm_ptr->next_TM);\ 01514 int overflowCountExecute = 0;\ 01515 while( tm_ptr->next_TM != NULL ){\ 01516 if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\ 01517 tm_ptr = tm_ptr->next_TM;\ 01518 ++overflowCountExecute;\ 01519 }\ 01520 else{\ 01521 /*PENDING: RESET CDMS*/\ 01522 break;\ 01523 }\ 01524 }\ 01525 tm_ptr->next_TM = put_tm_here;\ 01526 /*CHECK FOR HOT PA*/\ 01527 uint8_t tempPAhot = 0x00;\ 01528 isPAhot(tempPAhot);\ 01529 if( tempPAhot == 0x00 ){\ 01530 gFLAGS = gFLAGS | COM_PA_HOT_FLAG;\ 01531 }\ 01532 tm_ptr = tm_ptr_head;\ 01533 while( tm_ptr != NULL ){\ 01534 int length = TM_SHORT_SIZE;\ 01535 if( GETshort_or_long_tm(tm_ptr) == SHORT_TM_CODE ){\ 01536 length = TM_SHORT_SIZE;\ 01537 }\ 01538 else{\ 01539 length = TM_LONG_SIZE;\ 01540 }\ 01541 /*gPC.puts("Printing Call Sign, ACK_L1, TM list");*/\ 01542 for(int i = 0 ; i < length ; ++i){\ 01543 /*gPC.putc(tm_ptr->TM_string[i]);*/\ 01544 }\ 01545 tm_ptr = tm_ptr->next_TM;\ 01546 }\ 01547 /*SEND call sign, ACK_L1, OBSRS TO GS*/\ 01548 /*snd_tm.head_pointer(tm_ptr_head);*/\ 01549 /*adf_SDcard();*/\ 01550 /*DELETE THE TM AFTER USE*/\ 01551 tm_ptr = tm_ptr_head;\ 01552 overflowCountExecute = 0;\ 01553 while(tm_ptr != NULL){\ 01554 if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\ 01555 Base_tm *temp = tm_ptr->next_TM;\ 01556 delete tm_ptr;\ 01557 tm_ptr = temp;\ 01558 ++overflowCountExecute;\ 01559 }\ 01560 else{\ 01561 /*PENDING: RESET CDMS*/\ 01562 break;\ 01563 }\ 01564 }\ 01565 }\ 01566 }\ 01567 break;\ 01568 }\ 01569 current_TC = current_TC->next_TC;\ 01570 ++overflowCount;\ 01571 }\ 01572 else{\ 01573 /*PENDING: RESET CDMS*/\ 01574 break;\ 01575 }\ 01576 }\ 01577 if( gFLAGS & COM_SESSION_TIMEOUT_FLAG ){\ 01578 break;\ 01579 }\ 01580 else if( gMASTER_STATE == TCL_STATE_ABORTED ){\ 01581 /*gPC.puts("ABORTING DUE TO ABORT ON NACK\r\n");*/\ 01582 /*EXITED DUE TO ABORT ON NACK:*/\ 01583 /*PENDING : POWER OFF COM TX*/\ 01584 RX1M.attach(&rx_read, Serial::RxIrq);\ 01585 gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\ 01586 break;\ 01587 }\ 01588 else if( gFLAGS & COM_PA_HOT_FLAG ){\ 01589 /*PA HOT: WAIT FOR TIMEOUT*/\ 01590 gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT);\ 01591 /*PENDING : POWER OFF COMM TX*/\ 01592 RX1M.attach(&rx_read, Serial::RxIrq);\ 01593 gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\ 01594 break;\ 01595 }\ 01596 /*gPC.printf("successflly executed %u tc\r\n", execute_psc);*/\ 01597 }\ 01598 if( (gMASTER_STATE == TCL_STATE_COMPLETED) || (gFLAGS & COM_SESSION_TIMEOUT_FLAG) ){\ 01599 /*gPC.printf("completed or session timed out: %x\r\n", gMASTER_STATE);*/\ 01600 /*COMPLETED EXECUTION OF TC*/\ 01601 gMASTER_STATE = TCL_STATE_COMPLETED;\ 01602 COM_POWER_OFF_TX;\ 01603 reset_all;\ 01604 /*PENDING : ENABLE THREADS*/\ 01605 gSESSION_TIMEOUT.detach();\ 01606 gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\ 01607 gFLAGS = gFLAGS & (~COM_SESSION_FLAG);\ 01608 }\ 01609 }
Generated on Wed Jul 13 2022 23:45:23 by 1.7.2