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