Pradeep Kotipalli
/
cdms_rly_tmtc
bae_pl_tc_tobeupdated
Embed:
(wiki syntax)
Show/hide line numbers
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 00016 DigitalIn tm_status_4m_slv(PIN39); //I2C interrupt to CDMS from BAE 00017 //DigitalIn tm_status_4m_pl(PIN61); //I2C interrupt to CDMS from PL 00018 00019 uint8_t received = 0; 00020 uint16_t mid1; 00021 uint16_t mid2; 00022 uint16_t Nbytes; 00023 uint32_t Data[2]; 00024 uint16_t nbytes; 00025 uint8_t flash_counter = 0; 00026 uint16_t crc16; 00027 uint16_t mid; 00028 uint32_t block; 00029 00030 #define delete_TC(tc_ptr) {\ 00031 if(tc_ptr == gHEAD_NODE_TCL){\ 00032 gHEAD_NODE_TCL = tc_ptr->next_TC;\ 00033 }\ 00034 delete tc_ptr;\ 00035 } 00036 00037 // typeof tm_ptr: Base_tm 00038 // typeof tc_ptr: Base_tc 00039 // typeof temp_xxxx: uint8_t 00040 00041 00042 00043 00044 #define detect_ack(tm_ptr, temp_ack, tc_psc) {\ 00045 if( tm_ptr != NULL ){\ 00046 int length = TM_SHORT_SIZE;\ 00047 if( GETshort_or_long_tm(tm_ptr) == SHORT_TM_CODE ){\ 00048 length = TM_SHORT_SIZE;\ 00049 }\ 00050 else{\ 00051 length = TM_LONG_SIZE;\ 00052 }\ 00053 uint16_t crc = crc16_gen(tm_ptr->TM_string, length-2);\ 00054 if( (((crc & 0xFF00) >> 8) == tm_ptr->TM_string[length-2]) && ( (crc & 0x00FF) == tm_ptr->TM_string[length-1] ) ){\ 00055 uint8_t temp8;\ 00056 temp8 = tm_ptr->TM_string[TM_ACK_CODE_INDEX];\ 00057 temp8 = temp8 & 0xE0;\ 00058 if( (temp8 == 0xC0) || (temp8 == 0xA0) )\ 00059 temp_ack = 0x01;\ 00060 else{\ 00061 temp_ack = 0x00;\ 00062 /*CHECK FOR NACK CODE: CRC FAIL NACK*/\ 00063 temp8 = tm_ptr->TM_string[TM_ACK_CODE_INDEX];\ 00064 temp8 = temp8 & 0x0F;\ 00065 if( temp8 == CRC_FAIL_NACK_CODE ){\ 00066 tm_ptr->TM_string[2] = tc_psc;\ 00067 }\ 00068 }\ 00069 }\ 00070 else\ 00071 temp_ack = 0x00;\ 00072 }\ 00073 else{\ 00074 temp_ack = 0x00;\ 00075 }\ 00076 } 00077 00078 #define isit_obosc(tc_ptr, temp_obosc) {\ 00079 temp_obosc = 0x00;\ 00080 if( GETapid(tc_ptr) == APID_COM ){\ 00081 if( ((tc_ptr->TC_string[2]) >> 4) == SERVICE_OBOSC ){\ 00082 temp_obosc = 0x01;\ 00083 }\ 00084 }\ 00085 } 00086 00087 #define isit_sdcard(tc_ptr, temp_sdcard) {\ 00088 temp_sdcard = 0x00;\ 00089 if( GETapid(tc_ptr) == APID_COM ){\ 00090 if( ( (tc_ptr->TC_string[2]) >> 4) == SERVICE_OBSRS ){\ 00091 temp_sdcard = 0x01;\ 00092 }\ 00093 }\ 00094 } 00095 00096 00097 00098 void after_cooling_pa(){ 00099 gCOM_MNG_TMTC_THREAD->signal_set(COM_MNG_TMTC_SIGNAL_UART_INT); 00100 } 00101 00102 /* 00103 @brief: check for missing tc, also check crc, i.e. 00104 if true execution can be started else have to wait 00105 decide the next state 00106 @param: none 00107 @return: bool indicating whether there are missing tc 00108 */ 00109 // PENDING: LAST FRAME BIT 00110 /* 00111 for loop: check for missing tc 00112 if: check for incorrect sized tc 00113 if: check for last frame bit 00114 */ 00115 #define continueToExecute(returnHere) {\ 00116 uint8_t tempReturn = 0x00;\ 00117 /*search for missing psc*/\ 00118 for(uint8_t p = 0x00 ; p < (gTOTAL_VALID_TC) ; ++p){\ 00119 bool flag = false;\ 00120 Base_tc *node_ptr = gHEAD_NODE_TCL;\ 00121 while(node_ptr != NULL){\ 00122 if( (GETpacket_seq_count(node_ptr) == p) && (GETcrc_pass(node_ptr) == 1) ){\ 00123 flag = true;\ 00124 break;\ 00125 }\ 00126 else{\ 00127 node_ptr = node_ptr->next_TC;\ 00128 }\ 00129 }\ 00130 if(flag == false){\ 00131 tempReturn = 0x02;\ 00132 break;\ 00133 }\ 00134 }\ 00135 /*search for last packet bit*/\ 00136 tempReturn = tempReturn + 0x01;\ 00137 Base_tc *tcp = gHEAD_NODE_TCL;\ 00138 while(tcp != NULL){\ 00139 if(GETpacket_seq_count(tcp) == (gTOTAL_VALID_TC - 1)){\ 00140 if( ( (tcp->TC_string[1]) & 0x20 ) == 0x20 ){\ 00141 tempReturn = tempReturn - 0x01;\ 00142 }\ 00143 break;\ 00144 }\ 00145 tcp = tcp->next_TC;\ 00146 }\ 00147 returnHere = tempReturn;\ 00148 /*UPDATE gMASTER STATE*/\ 00149 if( (returnHere == 0x00) ){\ 00150 if( (gMASTER_STATE == TCL_STATE_INCOMPLETE) || (gMASTER_STATE == TCL_STATE_COMPLETED) || (gMASTER_STATE == TCL_STATE_ABORTED) ){\ 00151 gMASTER_STATE = TCL_STATE_EXECUTING;\ 00152 }\ 00153 }\ 00154 else{\ 00155 if( (gMASTER_STATE == TCL_STATE_INCOMPLETE) || (gMASTER_STATE == TCL_STATE_COMPLETED) ){\ 00156 gMASTER_STATE = TCL_STATE_INCOMPLETE;\ 00157 }\ 00158 }\ 00159 } 00160 00161 /* 00162 return 1 if code match 00163 return 0 if code mismatch 00164 */ 00165 #define GScodeVerification(returnHere){\ 00166 Base_tc *testTC = gHEAD_NODE_TCL;\ 00167 uint16_t overflowCount = 0;\ 00168 returnHere = 0xFF;\ 00169 while( (overflowCount < TCL_OVERFLOW_CONSTANT) && (testTC != NULL) ){\ 00170 if( (GETpacket_seq_count(testTC) == PSC_CALLSIGN) && (GETapid(testTC) == APID_CALLSIGN) ){\ 00171 /*uint8_t temp8 = testTC->TC_string[1];*/\ 00172 if( true ){\ 00173 for( int i = 2 ; i <= 8 ; ++i ){\ 00174 if( testTC->TC_string[i] != gGSCODE[i-2] ){\ 00175 returnHere = 0;\ 00176 break;\ 00177 }\ 00178 }\ 00179 }\ 00180 break;\ 00181 }\ 00182 testTC = testTC->next_TC;\ 00183 ++overflowCount;\ 00184 }\ 00185 } 00186 00187 /* 00188 @brief: DELETE THE CRC FAILED TC FROM THE LIST TO FREE-UP MEMORY AND UPDATE 00189 THE TOTAL VALID TC AND GENERATE L1_ACK_TM 00190 @param: none 00191 @return: none 00192 */ 00193 /*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 */ 00194 00195 /*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 */ 00196 00197 // CDMS TEAM CODE START 00198 inline Base_tm* FCTN_CDMS_RLY_TMTC(Base_tc *tc_ptr){ 00199 uint8_t ACKCODE = 0x00; 00200 //printf("\rTC execution in progress\r\n"); 00201 Base_tm *tm_pointer = new Long_tm; 00202 Base_tm *tm_ptr = tm_pointer; 00203 received = 0; 00204 switch(GETapid(tc_ptr)) 00205 { 00206 case 1: //apid=01 implies it corresponds to bae 00207 { 00208 //printf("Telecommand is for BAE\r\n"); 00209 //printf("Sending TC to BAE...\r\n"); //interrupt to be sent to the bae 00210 FCTN_I2C_WRITE((char*)tc_ptr->TC_string); 00211 while(1) 00212 { 00213 wait(1); //TimeOut instead of wait 00214 if(tm_status_4m_slv == 1) 00215 { 00216 //printf("receiving...\r\n"); 00217 FCTN_I2C_READ((char*)tm_pointer->TM_string,134); 00218 //printf("%s", tm_pointer->TM_string); 00219 received+=1; 00220 tm_pointer = tm_pointer->next_TM; 00221 break; //only for testing purpose 00222 } 00223 else 00224 { 00225 break; 00226 } 00227 } 00228 if(received >= 1 ) 00229 { 00230 //printf("Telemetry is received from BAE\r\n"); 00231 Base_tm *tm_print = tm_ptr; 00232 for(uint8_t i=0;i<received;i++) 00233 { 00234 //printf("%s", tm_print->TM_string); 00235 tm_print = tm_print->next_TM; //for check 00236 } 00237 received = 0; 00238 tm_pointer->next_TM = NULL; return tm_ptr; 00239 } 00240 else 00241 { 00242 //printf("Telemetry is not received from BAE\r\n"); 00243 //tm_pointer = new Short_tm; 00244 tm_pointer->TM_string[0] = 0xB0; 00245 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00246 tm_pointer->TM_string[2] = 0x01; 00247 tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided 00248 tm_pointer->TM_string[4] = 0x01; 00249 for(uint8_t i=0;i<6;i++) 00250 { 00251 tm_pointer->TM_string[i+5] = 0; 00252 } 00253 crc16 = crc16_gen(tm_ptr->TM_string,11); 00254 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00255 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00256 tm_pointer->next_TM = NULL; return tm_ptr; 00257 } 00258 break; 00259 } 00260 case 2: 00261 { 00262 //gPC.printf("Telecommand is for CDMS\r\n"); //apid = 10 corresponds to cdms 00263 switch(GETservice_type(tc_ptr)) 00264 { 00265 case 0x60: 00266 { 00267 //gPC.printf("service:MMS\r\n"); 00268 switch(GETservice_subtype(tc_ptr)) 00269 { 00270 case 0x1: 00271 { 00272 //printf("sub_service:Read from RAM_Memory\r\n"); 00273 mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]); 00274 00275 //Data[0] = FCTN_CDMS_RD_FLASH(0); 00276 //Data[1] = FCTN_CDMS_RD_FLASH(1); 00277 //tm_pointer = new Long_tm; 00278 tm_pointer->TM_string[0] = 0x30; 00279 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00280 tm_pointer->TM_string[2] = (uint8_t)(flash_counter); 00281 for(uint8_t i=0;i<4;i++) 00282 { 00283 tm_pointer->TM_string[3+i] = (uint8_t)((Data[0]>>(8*i))&0x00FF); 00284 } 00285 for(uint8_t i=4;i<8;i++) 00286 { 00287 tm_pointer->TM_string[3+i] = (uint8_t)((Data[1]>>(8*i))&0x00FF); 00288 } 00289 crc16 = crc16_gen(tm_ptr->TM_string,9); 00290 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00291 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00292 tm_pointer->next_TM = NULL; return tm_ptr; 00293 } 00294 case 0x2: 00295 { 00296 //printf("sub_service:Read from Flash_Memory\r\n"); 00297 mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]); 00298 00299 //Data[0] = FCTN_CDMS_RD_FLASH(0); 00300 //Data[1] = FCTN_CDMS_RD_FLASH(1); 00301 //tm_pointer = new Long_tm; 00302 tm_pointer->TM_string[0] = 0x30; 00303 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00304 tm_pointer->TM_string[2] = (uint8_t)(flash_counter); 00305 for(uint8_t i=0;i<4;i++) 00306 { 00307 tm_pointer->TM_string[3+i] = (uint8_t)((Data[0]>>(8*i))&0x00FF); 00308 } 00309 for(uint8_t i=4;i<8;i++) 00310 { 00311 tm_pointer->TM_string[3+i] = (uint8_t)((Data[1]>>(8*i))&0x00FF); 00312 } 00313 crc16 = crc16_gen(tm_ptr->TM_string,9); 00314 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00315 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00316 tm_pointer->next_TM = NULL; return tm_ptr; 00317 } 00318 case 0x5: 00319 { 00320 //printf("WRITE ON FLASH_MEMORY\r\n"); 00321 mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]); 00322 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]))); 00323 //FCTN_CDMS_WR_FLASH(mid,block); 00324 //tm_pointer = new Short_tm; 00325 tm_pointer->TM_string[0] = 0xB0; 00326 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00327 tm_pointer->TM_string[2] = 0x01; 00328 tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided 00329 tm_pointer->TM_string[4] = 0x01; 00330 for(uint8_t i=0;i<6;i++) 00331 { 00332 tm_pointer->TM_string[i+5] = 0; 00333 } 00334 crc16 = crc16_gen(tm_ptr->TM_string,11); 00335 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00336 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00337 tm_pointer->next_TM = NULL; return tm_ptr; 00338 break; 00339 } 00340 default: 00341 { 00342 //printf("INVALID TC\r\n"); //Send Invalid TC Telemetry 00343 //tm_pointer = new Short_tm; 00344 tm_pointer->TM_string[0] = 0xB0; 00345 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00346 tm_pointer->TM_string[2] = 0x01; 00347 tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided 00348 tm_pointer->TM_string[4] = 0x01; 00349 for(uint8_t i=0;i<6;i++) 00350 { 00351 tm_pointer->TM_string[i+5] = 0; 00352 } 00353 crc16 = crc16_gen(tm_ptr->TM_string,11); 00354 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00355 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00356 tm_pointer->next_TM = NULL; return tm_ptr; 00357 } 00358 break; 00359 } 00360 } 00361 case 0x80: 00362 { 00363 //printf("service:FUNCTION MANAGEMENT SERVICE\r\n"); 00364 if(GETservice_subtype(tc_ptr)==0x1) 00365 { 00366 if(GETpid(tc_ptr)==0x01) 00367 { 00368 //printf("TC_PL_INIT\r\n"); // call PWR_SWCH_ON function 00369 //tm_pointer = new Short_tm; 00370 tm_pointer->TM_string[0] = 0xB0; 00371 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00372 tm_pointer->TM_string[2] = ACKCODE; 00373 for(uint8_t i=3;i<11;i++) 00374 { 00375 tm_pointer->TM_string[i] = 0; 00376 } 00377 crc16 = crc16_gen(tm_ptr->TM_string,11); 00378 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00379 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00380 tm_pointer->next_TM = NULL; return tm_ptr; 00381 break; 00382 } 00383 else if(GETpid(tc_ptr)==0x02) 00384 { 00385 //printf("TC_PL_MAIN\r\n"); // call PWR_SWCH_ON function 00386 //tm_pointer = new Short_tm; 00387 tm_pointer->TM_string[0] = 0xB0; 00388 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00389 tm_pointer->TM_string[2] = ACKCODE; 00390 for(uint8_t i=3;i<11;i++) 00391 { 00392 tm_pointer->TM_string[i] = 0; 00393 } 00394 crc16 = crc16_gen(tm_ptr->TM_string,11); 00395 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00396 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00397 tm_pointer->next_TM = NULL; return tm_ptr; 00398 break; 00399 } 00400 else if(GETpid(tc_ptr)==0x03) 00401 { 00402 //printf("TC_COM_INIT\r\n"); // call PWR_SWCH_ON function 00403 //tm_pointer = new Short_tm; 00404 tm_pointer->TM_string[0] = 0xB0; 00405 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00406 tm_pointer->TM_string[2] = ACKCODE; 00407 for(uint8_t i=3;i<11;i++) 00408 { 00409 tm_pointer->TM_string[i] = 0; 00410 } 00411 crc16 = crc16_gen(tm_ptr->TM_string,11); 00412 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00413 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00414 tm_pointer->next_TM = NULL; return tm_ptr; 00415 break; 00416 } 00417 else if(GETpid(tc_ptr)==0x04) 00418 { 00419 //printf("TC_CDMS_HK_MAIN\r\n"); // call PWR_SWCH_ON function 00420 //tm_pointer = new Short_tm; 00421 tm_pointer->TM_string[0] = 0xB0; 00422 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00423 tm_pointer->TM_string[2] = ACKCODE; 00424 for(uint8_t i=3;i<11;i++) 00425 { 00426 tm_pointer->TM_string[i] = 0; 00427 } 00428 crc16 = crc16_gen(tm_ptr->TM_string,11); 00429 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00430 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00431 tm_pointer->next_TM = NULL; return tm_ptr; 00432 break; 00433 } 00434 else if(GETpid(tc_ptr)==0x11) 00435 { 00436 //printf("TC_SW_ON_SD\r\n"); // call PWR_SWCH_ON function 00437 //tm_pointer = new Short_tm; 00438 tm_pointer->TM_string[0] = 0xB0; 00439 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00440 tm_pointer->TM_string[2] = ACKCODE; 00441 for(uint8_t i=3;i<11;i++) 00442 { 00443 tm_pointer->TM_string[i] = 0; 00444 } 00445 crc16 = crc16_gen(tm_ptr->TM_string,11); 00446 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00447 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00448 tm_pointer->next_TM = NULL; return tm_ptr; 00449 break; 00450 } 00451 else if(GETpid(tc_ptr)==0x12) 00452 { 00453 //printf("TC_SW_ON_RTC\r\n"); // call PWR_SWCH_ON function 00454 //tm_pointer = new Short_tm; 00455 tm_pointer->TM_string[0] = 0xB0; 00456 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00457 tm_pointer->TM_string[2] = ACKCODE; 00458 for(uint8_t i=3;i<11;i++) 00459 { 00460 tm_pointer->TM_string[i] = 0; 00461 } 00462 crc16 = crc16_gen(tm_ptr->TM_string,11); 00463 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00464 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00465 tm_pointer->next_TM = NULL; return tm_ptr; 00466 break; 00467 } 00468 else if(GETpid(tc_ptr)==0x13) 00469 { 00470 //printf("TC_SW_ON_BAE\r\n"); // call PWR_SWCH_ON function 00471 //tm_pointer = new Short_tm; 00472 tm_pointer->TM_string[0] = 0xB0; 00473 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00474 tm_pointer->TM_string[2] = ACKCODE; 00475 for(uint8_t i=3;i<11;i++) 00476 { 00477 tm_pointer->TM_string[i] = 0; 00478 } 00479 crc16 = crc16_gen(tm_ptr->TM_string,11); 00480 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00481 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00482 tm_pointer->next_TM = NULL; return tm_ptr; 00483 break; 00484 } 00485 else if(GETpid(tc_ptr)==0x14) 00486 { 00487 //printf("TC_SW_ON_PL_DL\r\n"); // call PWR_SWCH_ON function 00488 //tm_pointer = new Short_tm; 00489 tm_pointer->TM_string[0] = 0xB0; 00490 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00491 tm_pointer->TM_string[2] = ACKCODE; 00492 for(uint8_t i=3;i<11;i++) 00493 { 00494 tm_pointer->TM_string[i] = 0; 00495 } 00496 crc16 = crc16_gen(tm_ptr->TM_string,11); 00497 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00498 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00499 tm_pointer->next_TM = NULL; return tm_ptr; 00500 break; 00501 } 00502 else if(GETpid(tc_ptr)==0x15) 00503 { 00504 //printf("TC_SW_ON_PL_AG_HV\r\n"); // call PWR_SWCH_ON function 00505 //tm_pointer = new Short_tm; 00506 tm_pointer->TM_string[0] = 0xB0; 00507 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00508 tm_pointer->TM_string[2] = ACKCODE; 00509 for(uint8_t i=3;i<11;i++) 00510 { 00511 tm_pointer->TM_string[i] = 0; 00512 } 00513 crc16 = crc16_gen(tm_ptr->TM_string,11); 00514 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00515 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00516 tm_pointer->next_TM = NULL; return tm_ptr; 00517 break; 00518 } 00519 else if(GETpid(tc_ptr)==0x16) 00520 { 00521 //printf("TC_SW_ON_V_A_EN\r\n"); // call PWR_SWCH_ON function 00522 //tm_pointer = new Short_tm; 00523 tm_pointer->TM_string[0] = 0xB0; 00524 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00525 tm_pointer->TM_string[2] = ACKCODE; 00526 for(uint8_t i=3;i<11;i++) 00527 { 00528 tm_pointer->TM_string[i] = 0; 00529 } 00530 crc16 = crc16_gen(tm_ptr->TM_string,11); 00531 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00532 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00533 tm_pointer->next_TM = NULL; return tm_ptr; 00534 break; 00535 } 00536 else if(GETpid(tc_ptr)==0x21) 00537 { 00538 //printf("TC_SW_OFF_SD\r\n"); // call PWR_SWCH_ON function 00539 //tm_pointer = new Short_tm; 00540 tm_pointer->TM_string[0] = 0xB0; 00541 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00542 tm_pointer->TM_string[2] = ACKCODE; 00543 for(uint8_t i=3;i<11;i++) 00544 { 00545 tm_pointer->TM_string[i] = 0; 00546 } 00547 crc16 = crc16_gen(tm_ptr->TM_string,11); 00548 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00549 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00550 tm_pointer->next_TM = NULL; return tm_ptr; 00551 break; 00552 } 00553 else if(GETpid(tc_ptr)==0x22) 00554 { 00555 //printf("TC_SW_OFF_RTC\r\n"); // call PWR_SWCH_ON function 00556 //tm_pointer = new Short_tm; 00557 tm_pointer->TM_string[0] = 0xB0; 00558 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00559 tm_pointer->TM_string[2] = ACKCODE; 00560 for(uint8_t i=3;i<11;i++) 00561 { 00562 tm_pointer->TM_string[i] = 0; 00563 } 00564 crc16 = crc16_gen(tm_ptr->TM_string,11); 00565 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00566 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00567 tm_pointer->next_TM = NULL; return tm_ptr; 00568 break; 00569 } 00570 else if(GETpid(tc_ptr)==0x23) 00571 { 00572 //printf("TC_SW_OFF_BAE\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)==0x24) 00588 { 00589 //printf("TC_SW_OFF_PL_DL\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)==0x25) 00605 { 00606 //printf("TC_SW_OFF_PL_AG_HV\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)==0x26) 00622 { 00623 //printf("TC_SW_OFF_V_A_EN\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)==0x31) 00639 { 00640 //printf("TC_RST_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)==0x32) 00656 { 00657 //printf("TC_RST_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)==0x33) 00673 { 00674 //printf("TC_RST_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)==0x34) 00690 { 00691 //printf("TC_RST_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 break; 00706 } 00707 else if(GETpid(tc_ptr)==0xC1) 00708 { 00709 //printf("RESET_HK_COUNTER\r\n"); // call PWR_SWCH_ON function 00710 //tm_pointer = new Short_tm; 00711 tm_pointer->TM_string[0] = 0xB0; 00712 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00713 tm_pointer->TM_string[2] = ACKCODE; 00714 for(uint8_t i=3;i<11;i++) 00715 { 00716 tm_pointer->TM_string[i] = 0; 00717 } 00718 crc16 = crc16_gen(tm_ptr->TM_string,11); 00719 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00720 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00721 tm_pointer->next_TM = NULL; return tm_ptr; 00722 break; 00723 } 00724 else if(GETpid(tc_ptr)==0xF1) 00725 { 00726 //printf("RD_RTC\r\n"); //call RD_RTC 00727 //tm_pointer = new Short_tm; 00728 tm_pointer->TM_string[0] = 0xD0; 00729 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00730 tm_pointer->TM_string[2] = 0x01; 00731 uint64_t time = FCTN_CDMS_RD_RTC(); 00732 tm_pointer->TM_string[3] = (uint8_t)((time&0xFF00000000000000)>>56); 00733 tm_pointer->TM_string[4] = (uint8_t)((time&0x00FF000000000000)>>48); 00734 tm_pointer->TM_string[5] = (uint8_t)((time&0x0000FF0000000000)>>40); 00735 tm_pointer->TM_string[6] = (uint8_t)((time&0x000000FF00000000)>>32); 00736 tm_pointer->TM_string[7] = (uint8_t)((time&0x00000000FF000000)>>24); 00737 tm_pointer->TM_string[8] = (uint8_t)((time&0x0000000000FF0000)>>16); 00738 tm_pointer->TM_string[9] = (uint8_t)((time&0x000000000000FF00)>>8); 00739 tm_pointer->TM_string[10] = (uint8_t)(time&0x00000000000000FF); 00740 crc16 = crc16_gen(tm_ptr->TM_string,11); 00741 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00742 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00743 tm_pointer->next_TM = NULL; return tm_ptr; 00744 } 00745 else 00746 { 00747 //printf("INVALID TC\r\n"); 00748 //tm_pointer = new Short_tm; 00749 tm_pointer->TM_string[0] = 0xB0; 00750 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00751 tm_pointer->TM_string[2] = 0x01; 00752 tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided 00753 tm_pointer->TM_string[4] = 0x01; 00754 for(uint8_t i=0;i<6;i++) 00755 { 00756 tm_pointer->TM_string[i+5] = 0; 00757 } 00758 crc16 = crc16_gen(tm_ptr->TM_string,11); 00759 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00760 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00761 tm_pointer->next_TM = NULL; return tm_ptr; 00762 } 00763 } 00764 00765 00766 } 00767 00768 case 0x70: 00769 { 00770 //printf("Payload Management Sercvice"); 00771 if(GETservice_subtype(tc_ptr)==0x1) 00772 { 00773 tm_pointer->TM_string[0] = 0xD0; 00774 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00775 tm_pointer->TM_string[2] = ACKCODE; 00776 tm_pointer->TM_string[3] = GETpacket_seq_count(tc_ptr); 00777 for(uint8_t i=0;i<42;i++) 00778 { 00779 tm_pointer->TM_string[4+3*i]=(pl_schedule_exec_status[i]<<2)+(uint8_t)(pl_schedule_time[i]&0x03)<<6; 00780 tm_pointer->TM_string[5+3*i]=(uint8_t)(pl_schedule_time[i]&0x03FC)>>2; 00781 tm_pointer->TM_string[6+3*i]=(uint8_t)(pl_schedule_time[i]&0xFC00)>>10; 00782 tm_pointer->TM_string[6+3*i]+=(pl_schedule_sid[i]<<6); 00783 } 00784 uint32_t pms_buffer[42]; 00785 for(uint8_t i=0;i<42;i++) 00786 { 00787 pms_buffer[i]=(tc_ptr->TC_string[3*i+2])<<16+(tc_ptr->TC_string[3*i+3])<<8+(tc_ptr->TC_string[3*i+4]); 00788 } 00789 for(uint8_t i=0;i<42;i++) 00790 { 00791 pl_schedule_exec_status[i] = (uint8_t)(pms_buffer[i]&0x0000000C)>>2; 00792 pl_schedule_time[i]=(uint16_t)(pms_buffer[i]&0x003FFFC0)>>6; 00793 pl_schedule_sid[i]= (uint8_t)(pms_buffer[i]&0x00C00000)>>22; 00794 } 00795 00796 } 00797 } 00798 default: 00799 { 00800 //printf("INVALID TC"); //send invalid TC TM 00801 //tm_pointer = new Short_tm; 00802 tm_pointer->TM_string[0] = 0xB0; 00803 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00804 tm_pointer->TM_string[2] = 0x01; 00805 tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided 00806 tm_pointer->TM_string[4] = 0x01; 00807 for(uint8_t i=0;i<6;i++) 00808 { 00809 tm_pointer->TM_string[i+5] = 0; 00810 } 00811 crc16 = crc16_gen(tm_ptr->TM_string,11); 00812 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00813 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00814 tm_pointer->next_TM = NULL; return tm_ptr; 00815 break; 00816 } 00817 } 00818 } 00819 case 3: 00820 { 00821 //printf("Telecommand is for PL\r\n"); 00822 // printf("Informing PL about TC using I2C\r\n"); //interrupt to be sent to the bae 00823 // FCTN_I2C_WRITE((char*)tc_ptr->TC_string); 00824 // printf("sent the Telecommand to BAE\r\n"); //packet along with crc will be sent when bae is ready 00825 // wait(1); //wait time is to be optimised 00826 // if(tm_status_4m_slv == 1) 00827 // { 00828 // FCTN_I2C_READ((char*)tm_ptr->TM_string); 00829 // received = 1; 00830 // } 00831 // if(received == 1 ) 00832 // { 00833 // printf("Telemetry is received from BAE\r\n"); 00834 // printf("%s", tm_ptr->TM_string); 00835 // received = 0; 00836 // } // similar to BAE functions 00837 break; 00838 } 00839 default: //invalid TC 00840 { 00841 //printf("INVALID TC\r\n"); 00842 //tm_pointer = new Short_tm; 00843 tm_pointer->TM_string[0] = 0xB0; 00844 tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); 00845 tm_pointer->TM_string[2] = 0x01; 00846 tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided 00847 tm_pointer->TM_string[4] = 0x01; 00848 for(uint8_t i=0;i<6;i++) 00849 { 00850 tm_pointer->TM_string[i+5] = 0; 00851 } 00852 crc16 = crc16_gen(tm_ptr->TM_string,11); 00853 tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); 00854 tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); 00855 tm_pointer->next_TM = NULL; return tm_ptr; 00856 break; 00857 } 00858 } 00859 } 00860 // CDMS TEAM CODE END 00861 // EXECUTE OBOSC 00862 #define execute_obosc_core(tc_ptr, tm_ptr, reset_flag) {\ 00863 if (DEBUG)\ 00864 gPC.puts("Inside execute_obosc_core\r\n");\ 00865 uint8_t service_subtype = (tc_ptr->TC_string[2]) & 0x0F;\ 00866 uint8_t temp8 = 0x00;\ 00867 Base_tc *modify_this = gHEAD_NODE_TCL;\ 00868 int modify_overflow = 0x00;\ 00869 switch( service_subtype ){\ 00870 case OBOSC_SUB_DISABLE:\ 00871 /*gPC.puts("target psc are ");*/\ 00872 for(int i = 3 ; i < 9 ; ++i){\ 00873 /*gPC.printf("%u ", tc_ptr->TC_string[i]);*/\ 00874 }\ 00875 /*gPC.puts("\r\n");*/\ 00876 /*gPC.puts("disable type obosc\r\n");*/\ 00877 while( modify_this != NULL ){\ 00878 if( modify_overflow < TCL_OVERFLOW_CONSTANT ){\ 00879 uint8_t modify_psc = GETpacket_seq_count(modify_this);\ 00880 /*gPC.printf("mosify_psc = %u\r\n", modify_psc);*/\ 00881 for( int i = 3 ; i < 9 ; ++i ){\ 00882 uint8_t target_psc = tc_ptr->TC_string[i];\ 00883 if( (target_psc == modify_psc) && (target_psc != 0) ){\ 00884 uint16_t tempExec = TC_STATE_DISABLED;\ 00885 PUTexec_status( modify_this, tempExec );\ 00886 break;\ 00887 }\ 00888 }\ 00889 modify_this = modify_this->next_TC;\ 00890 ++modify_overflow;\ 00891 }\ 00892 else{\ 00893 /*PENDING: RESET CDMS*/\ 00894 break;\ 00895 }\ 00896 }\ 00897 break;\ 00898 case OBOSC_SUB_RETRY:\ 00899 /*gPC.puts("retry type obosc\r\n");*/\ 00900 while( modify_this != NULL ){\ 00901 if( modify_overflow < TCL_OVERFLOW_CONSTANT ){\ 00902 uint8_t modify_psc = GETpacket_seq_count(modify_this);\ 00903 for( int i = 3 ; i < 9 ; ++i ){\ 00904 uint8_t target_psc = tc_ptr->TC_string[i];\ 00905 if( (target_psc == modify_psc) && (target_psc != 0) ){\ 00906 uint16_t tempExec = TC_STATE_MARKED_RETRY;\ 00907 PUTexec_status( modify_this, tempExec );\ 00908 /*gPC.puts("reqquired tc found: disable\r\n");*/\ 00909 break;\ 00910 }\ 00911 }\ 00912 modify_this = modify_this->next_TC;\ 00913 ++modify_overflow;\ 00914 }\ 00915 else{\ 00916 /*PENDING: RESET CDMS*/\ 00917 break;\ 00918 }\ 00919 }\ 00920 break;\ 00921 }\ 00922 Base_tm *ackl234new = new Short_tm;\ 00923 ackl234new->next_TM = NULL;\ 00924 /*return telemetry pointer here*/\ 00925 tm_ptr = ackl234new;\ 00926 ackl234new->TM_string[0] = TMID_ACK_L234 << 4;\ 00927 ackl234new->TM_string[1] = GETpacket_seq_count(tc_ptr);\ 00928 ackl234new->TM_string[2] = 0xA0;\ 00929 for(int i = 3; i < 11; ++i){\ 00930 ackl234new->TM_string[i] = 0x00;\ 00931 }\ 00932 uint16_t crc = crc16_gen(ackl234new->TM_string, TM_SHORT_SIZE-2);\ 00933 ackl234new->TM_string[11] = (crc & 0xFF00) >> 8;\ 00934 ackl234new->TM_string[12] = crc & 0x00FF;\ 00935 /*ack l234 old*/\ 00936 if( service_subtype == OBOSC_SUB_REP_LE ){\ 00937 if( gLAST_TM_SHORT_OR_LONG == SHORT_TM_CODE ){\ 00938 Base_tm *ackl234old = new Short_tm;\ 00939 ackl234old->next_TM = NULL;\ 00940 /*APPEND TO ACK L234 NEW HERE*/\ 00941 ackl234new->next_TM = ackl234old;\ 00942 for( int i = 0 ; i < TM_SHORT_SIZE ; ++i ){\ 00943 ackl234old->TM_string[i] = gLAST_TM[i];\ 00944 }\ 00945 }\ 00946 else{\ 00947 Base_tm *tempLongTM = new Long_tm;\ 00948 tempLongTM->next_TM = NULL;\ 00949 /*APPEND TO ACK L234 NEW HERE*/\ 00950 ackl234new->next_TM = tempLongTM;\ 00951 for( int i = 0 ; i < TM_LONG_SIZE ; ++i ){\ 00952 tempLongTM->TM_string[i] = gLAST_TM[i];\ 00953 }\ 00954 }\ 00955 }\ 00956 else if( service_subtype == OBOSC_SUB_REP_TCLD ){\ 00957 get_tc_list(ackl234new->next_TM, GETpacket_seq_count(tc_ptr));\ 00958 }\ 00959 else if( service_subtype == OBOSC_SUB_RESET ){\ 00960 /*reset_all;*/\ 00961 reset_flag = 1;\ 00962 /*PENDING: VERIFY reset_all, RESET CDMS*/\ 00963 }\ 00964 else if( (service_subtype != OBOSC_SUB_DISABLE) && (service_subtype != OBOSC_SUB_RETRY) ){\ 00965 /*CHANGE THE ACK CODE TO INVALID TC*/\ 00966 ackl234new->TM_string[2] = 0xA2;\ 00967 }\ 00968 if (DEBUG)\ 00969 gPC.puts("completed obosc\r\n");\ 00970 } 00971 00972 /*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 */ 00973 00974 00975 #define EXECUTE_OBOSC_ONLY {\ 00976 int reset_flag = 0;\ 00977 if (DEBUG)\ 00978 gPC.puts("iNSIDE EXECUTE_OBOSC_ONLY\r\n");\ 00979 for(uint8_t execute_psc = PSC_START_VALUE ; execute_psc < gTOTAL_VALID_TC ; ++execute_psc){\ 00980 Base_tc* current_TC = gHEAD_NODE_TCL;\ 00981 int overCount = 0;\ 00982 while( current_TC != NULL ){\ 00983 if( overCount < TCL_OVERFLOW_CONSTANT ){\ 00984 if( (GETcrc_pass(current_TC) == 1) && (GETpacket_seq_count(current_TC) == execute_psc) ){\ 00985 /*CHECK FOR OBOSC*/\ 00986 uint8_t temp82 = 0x00;\ 00987 isit_obosc(current_TC, temp82);\ 00988 if(temp82 == 0x01){\ 00989 uint16_t current_exec_status = GETexec_status(current_TC);\ 00990 if( (current_exec_status == TC_STATE_SUCCESSFULLY_EXECUTED) || (current_exec_status == TC_STATE_DISABLED) )\ 00991 break;\ 00992 else if( (current_exec_status == TC_STATE_UNEXECUTED) || (current_exec_status == TC_STATE_MARKED_RETRY) ){\ 00993 if (DEBUG)\ 00994 gPC.printf("It is obosc: %u\r\n", execute_psc);\ 00995 /*EXECUTION OF OBOSC TC*/\ 00996 /*WARNING: LARGE MEMORY UTILIZATION FOR TC-LIST-REPORT */\ 00997 Base_tm *obosc_tm_head = NULL;\ 00998 get_call_sign(obosc_tm_head);\ 00999 Base_tm *obosc_tm_core = NULL;\ 01000 execute_obosc_core(current_TC, obosc_tm_core, reset_flag);\ 01001 uint16_t temp16 = TC_STATE_SUCCESSFULLY_EXECUTED;\ 01002 PUTexec_status(current_TC, temp16);\ 01003 Base_tm *obosc_tm_current = obosc_tm_head;\ 01004 get_ack_l1(obosc_tm_current->next_TM);\ 01005 int overflowCountOBONLY = 0;\ 01006 while( obosc_tm_current->next_TM != NULL ){\ 01007 if( overflowCountOBONLY < TM_OVERFLOW_CONSTANT ){\ 01008 obosc_tm_current = obosc_tm_current->next_TM;\ 01009 ++overflowCountOBONLY;\ 01010 }\ 01011 else{\ 01012 /*PENDING: RESET CDMS*/\ 01013 break;\ 01014 }\ 01015 }\ 01016 obosc_tm_current->next_TM = obosc_tm_core;\ 01017 obosc_tm_current = obosc_tm_head;\ 01018 while( obosc_tm_current != NULL ){\ 01019 int length = TM_SHORT_SIZE;\ 01020 if( GETshort_or_long_tm(obosc_tm_current) == SHORT_TM_CODE ){\ 01021 length = TM_SHORT_SIZE;\ 01022 }\ 01023 else{\ 01024 length = TM_LONG_SIZE;\ 01025 }\ 01026 for(int i = 0 ; i < length ; ++i){\ 01027 /*gPC.putc(obosc_tm_current->TM_string[i]);*/\ 01028 }\ 01029 obosc_tm_current = obosc_tm_current->next_TM;\ 01030 }\ 01031 /*Sending OBOSC TM to GS*/\ 01032 /*snd_tm.head_pointer(obosc_tm_head);*/\ 01033 /*transmit_adf;*/\ 01034 /*DELETE THE TM AFTER USE*/\ 01035 obosc_tm_current = obosc_tm_head;\ 01036 int overCount = 0;\ 01037 while( obosc_tm_current != NULL ){\ 01038 if( (overCount < TM_OVERFLOW_CONSTANT) ){\ 01039 Base_tm *temp = obosc_tm_current->next_TM;\ 01040 delete obosc_tm_current;\ 01041 obosc_tm_current = temp;\ 01042 ++overCount;\ 01043 }\ 01044 else{\ 01045 /*PENDING: RESET CDMS: MEMORY LEAK FOUND*/\ 01046 break;\ 01047 }\ 01048 }\ 01049 if ( reset_flag ==1 ){\ 01050 reset_all;\ 01051 }\ 01052 }\ 01053 }\ 01054 }\ 01055 current_TC = current_TC->next_TC;\ 01056 ++overCount;\ 01057 }\ 01058 else{\ 01059 /*PENDING: REST CDMS: MEMORY LEAK FOUND*/\ 01060 break;\ 01061 }\ 01062 }\ 01063 }\ 01064 } 01065 01066 #define EXECUTE_TC {\ 01067 gMASTER_STATE = TCL_STATE_EXECUTING;\ 01068 if (DEBUG)\ 01069 gPC.puts("iNSIDE EXECUTE_TC\r\n");\ 01070 /*gPC.printf("%u\r\n", gTOTAL_VALID_TC);*/\ 01071 for(uint8_t execute_psc = PSC_START_VALUE ; execute_psc < gTOTAL_VALID_TC ; ++execute_psc ){\ 01072 if (DEBUG)\ 01073 gPC.printf("executing normal %u\r\n", execute_psc);\ 01074 /*gLEDG = !gLEDG;*/\ 01075 /*gLEDR = !gLEDR;*/\ 01076 Base_tc* current_TC = gHEAD_NODE_TCL;\ 01077 int overflowCount = 0;\ 01078 while(current_TC != NULL){\ 01079 if( overflowCount < TCL_OVERFLOW_CONSTANT ){\ 01080 if( (GETcrc_pass(current_TC) == 1) && (GETpacket_seq_count(current_TC) == execute_psc) ){\ 01081 uint8_t current_exec_status = GETexec_status(current_TC);\ 01082 if( (current_exec_status == TC_STATE_SUCCESSFULLY_EXECUTED) || (current_exec_status == TC_STATE_DISABLED) ){\ 01083 /*gPC.printf("disabled or completed at %u\n", execute_psc);*/\ 01084 break;\ 01085 }\ 01086 else if( (current_exec_status == TC_STATE_EXECUTION_FAILED) && (GETabort_on_nack(current_TC) == 1) ){\ 01087 /*gPC.printf("abort on nack at %u psc\r\n", execute_psc);*/\ 01088 gMASTER_STATE = TCL_STATE_ABORTED;\ 01089 Base_tm *tm_ptr_head = NULL;\ 01090 get_call_sign(tm_ptr_head);\ 01091 Base_tm *tm_ptr = tm_ptr_head;\ 01092 get_ack_l1(tm_ptr->next_TM);\ 01093 tm_ptr = tm_ptr_head;\ 01094 while( tm_ptr != NULL ){\ 01095 int length = TM_SHORT_SIZE;\ 01096 if( GETshort_or_long_tm(tm_ptr) == SHORT_TM_CODE ){\ 01097 length = TM_SHORT_SIZE;\ 01098 }\ 01099 else{\ 01100 length = TM_LONG_SIZE;\ 01101 }\ 01102 /*gPC.puts("Printing Call Sign, ACK_L1, TM list");*/\ 01103 for(int i = 0 ; i < length ; ++i){\ 01104 /*gPC.putc(tm_ptr->TM_string[i]);*/\ 01105 }\ 01106 tm_ptr = tm_ptr->next_TM;\ 01107 }\ 01108 /*Send only call sign, ACK_L1 to GS*/\ 01109 /*snd_tm.head_pointer(tm_ptr_head);*/\ 01110 /*transmit_adf;*/\ 01111 /*DELETE THE TM AFTER USE*/\ 01112 tm_ptr = tm_ptr_head;\ 01113 int overflowCountExecute = 0;\ 01114 while(tm_ptr != NULL){\ 01115 if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\ 01116 Base_tm *temp = tm_ptr->next_TM;\ 01117 delete tm_ptr;\ 01118 tm_ptr = temp;\ 01119 ++overflowCountExecute;\ 01120 }\ 01121 else{\ 01122 /*PENDING: RESET CDMS*/\ 01123 break;\ 01124 }\ 01125 }\ 01126 break;\ 01127 }\ 01128 else if( (current_exec_status == TC_STATE_UNEXECUTED) || (current_exec_status == TC_STATE_MARKED_RETRY) ){\ 01129 /*EXECUTION OF TC START*/\ 01130 uint8_t temp81 = 0x00;\ 01131 isit_sdcard(current_TC, temp81);\ 01132 if( temp81 == 0x00 ){\ 01133 if (DEBUG)\ 01134 gPC.printf("non sd card at %u\r\n", execute_psc);\ 01135 /*EXECUTION OF NON SD-CARD (BOTH OBOSC and CDMS functions)*/\ 01136 Base_tm *tm_ptr_head = NULL;\ 01137 get_call_sign(tm_ptr_head);\ 01138 Base_tm *put_tm_here = NULL;\ 01139 uint8_t temp82 = 0x00;\ 01140 uint8_t tempPAhot = 0x00;\ 01141 isit_obosc(current_TC, temp82);\ 01142 if(temp82 == 0x01){\ 01143 /*gPC.printf("obosc tc inside normal tc at %u\r\n", execute_psc);*/\ 01144 /*EXECUTION OF OBOSC TC*/\ 01145 /*SKIP EXECUTION OF OBOSC HERE*/\ 01146 break;\ 01147 }\ 01148 else{\ 01149 /*gPC.printf("cdms relay tmtc at %u\r\n", execute_psc);*/\ 01150 /*call CDMS_RLY_TMTC*/\ 01151 /*CDMS_RLY_TMTC(current_TC, put_tm_here);*/\ 01152 put_tm_here = FCTN_CDMS_RLY_TMTC(current_TC);\ 01153 }\ 01154 /*DETECT ACK OR NACK*/\ 01155 uint8_t temp83 = 0x00;\ 01156 uint8_t temp84 = GETpacket_seq_count(current_TC);\ 01157 detect_ack(put_tm_here, temp83, temp84);\ 01158 if( temp83 == 0x01){\ 01159 uint16_t temp16 = TC_STATE_SUCCESSFULLY_EXECUTED;\ 01160 PUTexec_status(current_TC, temp16);\ 01161 }\ 01162 else{\ 01163 /*gPC.puts("TC_STATE_EXECUTION_FAILED");*/\ 01164 uint16_t temp16 = TC_STATE_EXECUTION_FAILED;\ 01165 PUTexec_status(current_TC, temp16);\ 01166 }\ 01167 /*ABORT ON NACK AND TC LIST COMPLETED: UPDATE IN gMASTERSTATE*/\ 01168 if( (GETexec_status(current_TC) == TC_STATE_EXECUTION_FAILED) && (GETabort_on_nack(current_TC) == 1) ){\ 01169 gMASTER_STATE = TCL_STATE_ABORTED;\ 01170 }\ 01171 else if( execute_psc == (gTOTAL_VALID_TC-1) ){\ 01172 /*LAST TC IS EXECUTED*/\ 01173 gMASTER_STATE = TCL_STATE_COMPLETED;\ 01174 }\ 01175 else{\ 01176 uint8_t check1 = 1;\ 01177 for( uint8_t test_psc = execute_psc+1 ; test_psc < gTOTAL_VALID_TC ; ++test_psc ){\ 01178 Base_tc* test_TC = gHEAD_NODE_TCL;\ 01179 while(test_TC != NULL){\ 01180 if( GETpacket_seq_count(test_TC) == test_psc ){\ 01181 uint8_t checkval;\ 01182 isit_obosc(test_TC, checkval);\ 01183 if( checkval == 0 ){\ 01184 check1 = 0;\ 01185 }\ 01186 }\ 01187 test_TC = test_TC->next_TC;\ 01188 }\ 01189 }\ 01190 if( check1 == 0x01 ){\ 01191 gMASTER_STATE = TCL_STATE_COMPLETED;\ 01192 }\ 01193 }\ 01194 /*update last executed L1_ack*/\ 01195 if( put_tm_here != NULL ){\ 01196 if( GETshort_or_long_tm(put_tm_here) == SHORT_TM_CODE ){\ 01197 for(int i = 0 ; i < TM_SHORT_SIZE ; ++i){\ 01198 gLAST_TM[i] = put_tm_here->TM_string[i];\ 01199 gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;\ 01200 }\ 01201 }\ 01202 else{\ 01203 for( int i = 0 ; i < TM_LONG_SIZE ; ++i ){\ 01204 gLAST_TM[i] = put_tm_here->TM_string[i];\ 01205 gLAST_TM_SHORT_OR_LONG = LONG_TM_CODE;\ 01206 }\ 01207 }\ 01208 }\ 01209 /*PENDING: APPEND ACK L1*/\ 01210 Base_tm *tm_ptr = tm_ptr_head;\ 01211 get_ack_l1(tm_ptr->next_TM);\ 01212 int overflowCountExecute = 0;\ 01213 while( tm_ptr->next_TM != NULL ){\ 01214 if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\ 01215 tm_ptr = tm_ptr->next_TM;\ 01216 ++overflowCountExecute;\ 01217 }\ 01218 else{\ 01219 /*PENDING: RESET CDMS*/\ 01220 break;\ 01221 }\ 01222 }\ 01223 tm_ptr->next_TM = put_tm_here;\ 01224 /*CHECK FOR HOT PA*/\ 01225 isPAhot(tempPAhot);\ 01226 if( tempPAhot == 0x00 ){\ 01227 gFLAGS = gFLAGS | COM_PA_HOT_FLAG;\ 01228 }\ 01229 tm_ptr = tm_ptr_head;\ 01230 while( tm_ptr != NULL ){\ 01231 int length = TM_SHORT_SIZE;\ 01232 if( GETshort_or_long_tm(tm_ptr) == SHORT_TM_CODE ){\ 01233 length = TM_SHORT_SIZE;\ 01234 }\ 01235 else{\ 01236 length = TM_LONG_SIZE;\ 01237 }\ 01238 /*gPC.puts("Printing Call Sign, ACK_L1, TM list");*/\ 01239 for(int i = 0 ; i < length ; ++i){\ 01240 /*gPC.putc(tm_ptr->TM_string[i]);*/\ 01241 }\ 01242 tm_ptr = tm_ptr->next_TM;\ 01243 }\ 01244 /*SEND call sign, ACK_L1, NON OBSRS TM TO GS*/\ 01245 snd_tm.head_pointer(tm_ptr_head);\ 01246 gPC.puts("enter_adf\r\n");\ 01247 transmit_adf;\ 01248 gPC.puts("exit_adf\r\n");\ 01249 /*DELETE THE TM AFTER USE*/\ 01250 tm_ptr = tm_ptr_head;\ 01251 overflowCountExecute = 0;\ 01252 while(tm_ptr != NULL){\ 01253 if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\ 01254 Base_tm *temp = tm_ptr->next_TM;\ 01255 delete tm_ptr;\ 01256 tm_ptr = temp;\ 01257 ++overflowCountExecute;\ 01258 }\ 01259 else{\ 01260 /*PENDING: RESET CDMS*/\ 01261 break;\ 01262 }\ 01263 }\ 01264 }\ 01265 else{\ 01266 if (DEBUG)\ 01267 gPC.printf("sd card at %u\r\n", execute_psc);\ 01268 /*EXECUTION OF SD-CARD DATA SENDING (OBSRS)*/\ 01269 Base_tm *tm_ptr_head = NULL;\ 01270 get_call_sign(tm_ptr_head);\ 01271 Base_tm *put_tm_here = NULL;\ 01272 /*execute_obsrs(current_TC, put_tm_here)*/\ 01273 /*read_TC(current_TC);*/\ 01274 execute_OBSRS_TC(current_TC);\ 01275 gPC.puts("en_adf");\ 01276 transmit_adf;\ 01277 gPC.puts("ex_adf");\ 01278 uint8_t tempExec = TC_STATE_SUCCESSFULLY_EXECUTED;\ 01279 PUTexec_status(current_TC, tempExec);\ 01280 /*PENDING: ABORT ON NACK CHECK, gMASTER_STATE VERIFICATION WITH SD CARD, session timeout, last executed ack l234*/\ 01281 if( (GETexec_status(current_TC) == TC_STATE_EXECUTION_FAILED) && (GETabort_on_nack(current_TC) == 1) ){\ 01282 gMASTER_STATE = TCL_STATE_ABORTED;\ 01283 }\ 01284 else if( execute_psc == (gTOTAL_VALID_TC-1) ){\ 01285 gMASTER_STATE = TCL_STATE_COMPLETED;\ 01286 }\ 01287 else{\ 01288 uint8_t check1 = 1;\ 01289 for( uint8_t test_psc = execute_psc+1 ; test_psc < gTOTAL_VALID_TC ; ++test_psc ){\ 01290 Base_tc* test_TC = gHEAD_NODE_TCL;\ 01291 while(test_TC != NULL){\ 01292 if( GETpacket_seq_count(test_TC) == test_psc ){\ 01293 uint8_t checkval;\ 01294 isit_obosc(test_TC, checkval);\ 01295 if( checkval == 0 ){\ 01296 check1 = 0;\ 01297 }\ 01298 }\ 01299 test_TC = test_TC->next_TC;\ 01300 }\ 01301 }\ 01302 if( check1 == 0x01 ){\ 01303 gMASTER_STATE = TCL_STATE_COMPLETED;\ 01304 }\ 01305 }\ 01306 /*update last executed L1_ack*/\ 01307 if( put_tm_here != NULL ){\ 01308 if( GETshort_or_long_tm(put_tm_here) == SHORT_TM_CODE ){\ 01309 for(int i = 0 ; i < TM_SHORT_SIZE ; ++i){\ 01310 gLAST_TM[i] = put_tm_here->TM_string[i];\ 01311 gLAST_TM_SHORT_OR_LONG = SHORT_TM_CODE;\ 01312 }\ 01313 }\ 01314 else{\ 01315 for( int i = 0 ; i < TM_LONG_SIZE ; ++i ){\ 01316 gLAST_TM[i] = put_tm_here->TM_string[i];\ 01317 gLAST_TM_SHORT_OR_LONG = LONG_TM_CODE;\ 01318 }\ 01319 }\ 01320 }\ 01321 /*PENDING: APPEND ACK L1*/\ 01322 Base_tm *tm_ptr = tm_ptr_head;\ 01323 get_ack_l1(tm_ptr->next_TM);\ 01324 int overflowCountExecute = 0;\ 01325 while( tm_ptr->next_TM != NULL ){\ 01326 if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\ 01327 tm_ptr = tm_ptr->next_TM;\ 01328 ++overflowCountExecute;\ 01329 }\ 01330 else{\ 01331 /*PENDING: RESET CDMS*/\ 01332 break;\ 01333 }\ 01334 }\ 01335 tm_ptr->next_TM = put_tm_here;\ 01336 /*CHECK FOR HOT PA*/\ 01337 uint8_t tempPAhot = 0x00;\ 01338 isPAhot(tempPAhot);\ 01339 if( tempPAhot == 0x00 ){\ 01340 gFLAGS = gFLAGS | COM_PA_HOT_FLAG;\ 01341 }\ 01342 tm_ptr = tm_ptr_head;\ 01343 while( tm_ptr != NULL ){\ 01344 int length = TM_SHORT_SIZE;\ 01345 if( GETshort_or_long_tm(tm_ptr) == SHORT_TM_CODE ){\ 01346 length = TM_SHORT_SIZE;\ 01347 }\ 01348 else{\ 01349 length = TM_LONG_SIZE;\ 01350 }\ 01351 /*gPC.puts("Printing Call Sign, ACK_L1, TM list");*/\ 01352 for(int i = 0 ; i < length ; ++i){\ 01353 /*gPC.putc(tm_ptr->TM_string[i]);*/\ 01354 }\ 01355 tm_ptr = tm_ptr->next_TM;\ 01356 }\ 01357 /*SEND call sign, ACK_L1, OBSRS TO GS*/\ 01358 /*snd_tm.head_pointer(tm_ptr_head);*/\ 01359 /*adf_SDcard();*/\ 01360 /*DELETE THE TM AFTER USE*/\ 01361 tm_ptr = tm_ptr_head;\ 01362 overflowCountExecute = 0;\ 01363 while(tm_ptr != NULL){\ 01364 if( overflowCountExecute < TM_OVERFLOW_CONSTANT ){\ 01365 Base_tm *temp = tm_ptr->next_TM;\ 01366 delete tm_ptr;\ 01367 tm_ptr = temp;\ 01368 ++overflowCountExecute;\ 01369 }\ 01370 else{\ 01371 /*PENDING: RESET CDMS*/\ 01372 break;\ 01373 }\ 01374 }\ 01375 }\ 01376 }\ 01377 break;\ 01378 }\ 01379 current_TC = current_TC->next_TC;\ 01380 ++overflowCount;\ 01381 }\ 01382 else{\ 01383 /*PENDING: RESET CDMS*/\ 01384 break;\ 01385 }\ 01386 }\ 01387 if( gFLAGS & COM_SESSION_TIMEOUT_FLAG ){\ 01388 break;\ 01389 }\ 01390 else if( gMASTER_STATE == TCL_STATE_ABORTED ){\ 01391 if (DEBUG)\ 01392 gPC.puts("ABORTING DUE TO ABORT ON NACK\r\n");\ 01393 /*EXITED DUE TO ABORT ON NACK:*/\ 01394 /*PENDING : POWER OFF COM TX*/\ 01395 RX1M.attach(&rx_read, Serial::RxIrq);\ 01396 gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\ 01397 break;\ 01398 }\ 01399 else if( gFLAGS & COM_PA_HOT_FLAG ){\ 01400 /*PA HOT: WAIT FOR TIMEOUT*/\ 01401 gCOM_PA_COOLING_TIMEOUT.attach(&after_cooling_pa, COM_PA_COOLING_TIME_LIMIT);\ 01402 /*PENDING : POWER OFF COMM TX*/\ 01403 RX1M.attach(&rx_read, Serial::RxIrq);\ 01404 gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\ 01405 break;\ 01406 }\ 01407 if (DEBUG)\ 01408 gPC.printf("successflly executed %u tc\r\n", execute_psc);\ 01409 }\ 01410 if( (gMASTER_STATE == TCL_STATE_COMPLETED) || (gFLAGS & COM_SESSION_TIMEOUT_FLAG) ){\ 01411 if (DEBUG)\ 01412 gPC.printf("completed or session timed out: %x\r\n", gMASTER_STATE);\ 01413 /*COMPLETED EXECUTION OF TC*/\ 01414 gMASTER_STATE = TCL_STATE_COMPLETED;\ 01415 COM_POWER_OFF_TX;\ 01416 reset_all;\ 01417 /*PENDING : ENABLE THREADS*/\ 01418 gPAY_SPI.bulkRead_start();\ 01419 gSESSION_TIMEOUT.detach();\ 01420 gFLAGS = gFLAGS & (~COM_MNG_TMTC_RUNNING_FLAG);\ 01421 gFLAGS = gFLAGS & (~COM_SESSION_FLAG);\ 01422 }\ 01423 }
Generated on Thu Jul 14 2022 06:32:12 by 1.7.2