working version
Dependencies: mbed mbed-rtos SimpleDMA FreescaleIAP eeprom
Fork of CDMS_CODE_FM_28JAN2017 by
Diff: COM_MNG_TMTC.h
- Revision:
- 206:fba4aeebf004
- Parent:
- 187:2c7263530c57
- Child:
- 207:28a07943dded
--- a/COM_MNG_TMTC.h Wed Jun 29 14:17:34 2016 +0000 +++ b/COM_MNG_TMTC.h Thu Jun 30 14:00:33 2016 +0000 @@ -11,7 +11,6 @@ //added included related files //#include "Flash.h" -#include "cdms_rtc.h" DigitalIn tm_status_4m_slv(PIN39); //I2C interrupt to CDMS from BAE //DigitalIn tm_status_4m_pl(PIN61); //I2C interrupt to CDMS from PL @@ -27,6 +26,11 @@ uint16_t mid; uint32_t block; +uint8_t ACK_CODE; + +void TM_PMS_PL_SCHEDULE(Base_tm* tm_pointer1,uint8_t psc); +void ACK_L234(Base_tm* tm_pointer_short1,uint8_t ackCode,uint8_t psc); + #define delete_TC(tc_ptr) {\ if(tc_ptr == gHEAD_NODE_TCL){\ gHEAD_NODE_TCL = tc_ptr->next_TC;\ @@ -195,636 +199,732 @@ /*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 */ // CDMS TEAM CODE START -inline Base_tm* FCTN_CDMS_RLY_TMTC(Base_tc *tc_ptr){ - uint8_t ACKCODE = 0x00; - //printf("\rTC execution in progress\r\n"); +void ACK_L234(Base_tm* tm_pointer_short1,uint8_t ackCode,uint8_t psc) +{ + tm_pointer_short1->TM_string[0] = 0xB0; + tm_pointer_short1->TM_string[1] = psc; + tm_pointer_short1->TM_string[2] = ackCode; + tm_pointer_short1->TM_string[3] = 0x00; + tm_pointer_short1->TM_string[4] = 0x00; + for(uint8_t i=0;i<6;i++) + tm_pointer_short1->TM_string[i+5] = 0; + crc16 = crc16_gen(tm_pointer_short1->TM_string,11); + tm_pointer_short1->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); + tm_pointer_short1->TM_string[12] = (uint8_t)(crc16&0x00FF); + tm_pointer_short1->next_TM = NULL; +} +void TM_PMS_PL_SCHEDULE(Base_tm *tm_pointer1,uint8_t psc) +{ + Base_tm *tm_pointer2 = NULL; + if(!(tm_pointer2 = new Long_tm)) + { + gPC.printf("\n\rError: out of memory"); + return; + } + Base_tm *tm_pointer3 = NULL; + if(!(tm_pointer3 = new Long_tm)) + { + gPC.printf("\n\rError: out of memory"); + return; + } + Base_tm *tm_pointer4 = NULL; + if(!(tm_pointer4 = new Long_tm)) + { + gPC.printf("\n\rError: out of memory"); + return; + } + Base_tm *tm_pointer5 = NULL; + if(!(tm_pointer5 = new Long_tm)) + { + gPC.printf("\n\rError: out of memory"); + return; + } + Base_tm *tm_pointer6 = NULL; + if(!(tm_pointer6 = new Long_tm)) + { + gPC.printf("\n\rError: out of memory"); + return; + } + tm_pointer1->TM_string[0] = 0x48; + tm_pointer1->TM_string[1] = psc; + tm_pointer1->TM_string[2] = 0xA0; + tm_pointer1->TM_string[3] = 0x01; + for(uint8_t i=0;i<128;i+=4) + { + tm_pointer1->TM_string[i+4] = (uint8_t)((pl_block[i/4] & 0xFF000000)>>24); + tm_pointer1->TM_string[i+5] = (uint8_t)((pl_block[i/4] & 0x00FF0000)>>16); + tm_pointer1->TM_string[i+6] = (uint8_t)((pl_block[i/4] & 0x0000FF00)>>8); + tm_pointer1->TM_string[i+7] = (uint8_t)((pl_block[i/4] & 0x000000FF)); + } + crc16 = crc16_gen(tm_pointer1->TM_string,132); + tm_pointer1->TM_string[132] = (uint8_t)((crc16&0xFF00)>>8); + tm_pointer1->TM_string[133] = (uint8_t)(crc16&0x00FF); + tm_pointer1->next_TM = tm_pointer2; + + tm_pointer2->TM_string[0] = 0x48; + tm_pointer2->TM_string[1] = psc; + tm_pointer2->TM_string[2] = 0xA0; + tm_pointer2->TM_string[3] = 0x02; + for(uint8_t i=0;i<128;i+=4) + { + tm_pointer2->TM_string[i+4] = (uint8_t)((pl_block[(i/4)+32] & 0xFF000000)>>24); + tm_pointer2->TM_string[i+5] = (uint8_t)((pl_block[(i/4)+32] & 0x00FF0000)>>16); + tm_pointer2->TM_string[i+6] = (uint8_t)((pl_block[(i/4)+32] & 0x0000FF00)>>8); + tm_pointer2->TM_string[i+7] = (uint8_t)((pl_block[(i/4)+32] & 0x000000FF)); + } + crc16 = crc16_gen(tm_pointer2->TM_string,132); + tm_pointer2->TM_string[132] = (uint8_t)((crc16&0xFF00)>>8); + tm_pointer2->TM_string[133] = (uint8_t)(crc16&0x00FF); + tm_pointer2->next_TM = tm_pointer3; + + tm_pointer3->TM_string[0] = 0x48; + tm_pointer3->TM_string[1] = psc; + tm_pointer3->TM_string[2] = 0xA0; + tm_pointer3->TM_string[3] = 0x03; + for(uint8_t i=0;i<128;i+=4) + { + tm_pointer3->TM_string[i+4] = (uint8_t)((pl_block[(i/4)+64] & 0xFF000000)>>24); + tm_pointer3->TM_string[i+5] = (uint8_t)((pl_block[(i/4)+64] & 0x00FF0000)>>16); + tm_pointer3->TM_string[i+6] = (uint8_t)((pl_block[(i/4)+64] & 0x0000FF00)>>8); + tm_pointer3->TM_string[i+7] = (uint8_t)((pl_block[(i/4)+64] & 0x000000FF)); + } + crc16 = crc16_gen(tm_pointer3->TM_string,132); + tm_pointer3->TM_string[132] = (uint8_t)((crc16&0xFF00)>>8); + tm_pointer3->TM_string[133] = (uint8_t)(crc16&0x00FF); + tm_pointer3->next_TM = tm_pointer4; + + tm_pointer4->TM_string[0] = 0x48; + tm_pointer4->TM_string[1] = psc; + tm_pointer4->TM_string[2] = 0xA0; + tm_pointer4->TM_string[3] = 0x04; + for(uint8_t i=0;i<128;i+=4) + { + tm_pointer4->TM_string[i+4] = (uint8_t)((pl_block[(i/4)+96] & 0xFF000000)>>24); + tm_pointer4->TM_string[i+5] = (uint8_t)((pl_block[(i/4)+96] & 0x00FF0000)>>16); + tm_pointer4->TM_string[i+6] = (uint8_t)((pl_block[(i/4)+96] & 0x0000FF00)>>8); + tm_pointer4->TM_string[i+7] = (uint8_t)((pl_block[(i/4)+96] & 0x000000FF)); + } + crc16 = crc16_gen(tm_pointer4->TM_string,132); + tm_pointer4->TM_string[132] = (uint8_t)((crc16&0xFF00)>>8); + tm_pointer4->TM_string[133] = (uint8_t)(crc16&0x00FF); + tm_pointer4->next_TM = tm_pointer5; + + tm_pointer5->TM_string[0] = 0x48; + tm_pointer5->TM_string[1] = psc; + tm_pointer5->TM_string[2] = 0xA0; + tm_pointer5->TM_string[3] = 0x05; + for(uint8_t i=0;i<128;i+=4) + { + tm_pointer5->TM_string[i+4] = (uint8_t)((pl_block[(i/4)+128] & 0xFF000000)>>24); + tm_pointer5->TM_string[i+5] = (uint8_t)((pl_block[(i/4)+128] & 0x00FF0000)>>16); + tm_pointer5->TM_string[i+6] = (uint8_t)((pl_block[(i/4)+128] & 0x0000FF00)>>8); + tm_pointer5->TM_string[i+7] = (uint8_t)((pl_block[(i/4)+128] & 0x000000FF)); + } + crc16 = crc16_gen(tm_pointer5->TM_string,132); + tm_pointer5->TM_string[132] = (uint8_t)((crc16&0xFF00)>>8); + tm_pointer5->TM_string[133] = (uint8_t)(crc16&0x00FF); + tm_pointer5->next_TM = tm_pointer6; + + tm_pointer6->TM_string[0] = 0x48; + tm_pointer6->TM_string[1] = psc; + tm_pointer6->TM_string[2] = 0xA0; + tm_pointer6->TM_string[3] = 0x06; + for(uint8_t i=0;i<128;i+=4) + { + tm_pointer6->TM_string[i+4] = (uint8_t)((pl_block[(i/4)+160] & 0xFF000000)>>24); + tm_pointer6->TM_string[i+5] = (uint8_t)((pl_block[(i/4)+160] & 0x00FF0000)>>16); + tm_pointer6->TM_string[i+6] = (uint8_t)((pl_block[(i/4)+160] & 0x0000FF00)>>8); + tm_pointer6->TM_string[i+7] = (uint8_t)((pl_block[(i/4)+160] & 0x000000FF)); + } + crc16 = crc16_gen(tm_pointer6->TM_string,132); + tm_pointer6->TM_string[132] = (uint8_t)((crc16&0xFF00)>>8); + tm_pointer6->TM_string[133] = (uint8_t)(crc16&0x00FF); + tm_pointer6->next_TM = NULL; +} +Base_tm* FCTN_CDMS_RLY_TMTC(Base_tc *tc_ptr) +{ + //uint8_t ACKCODE = 0xB0; + bool y; + //gPC.printf("\rTC execution in progress\r\n"); Base_tm *tm_pointer = new Long_tm; Base_tm *tm_ptr = tm_pointer; + //Base_tm *tm_ptr = new Long_tm; + Base_tm *tm_pointer_short = new Short_tm; + Base_tm *tm_ptr_short = tm_pointer_short; received = 0; - switch(GETapid(tc_ptr)) + switch(GETapid(tc_ptr)) //checking APID's { case 1: //apid=01 implies it corresponds to bae { - //printf("Telecommand is for BAE\r\n"); - //printf("Sending TC to BAE...\r\n"); //interrupt to be sent to the bae - FCTN_I2C_WRITE((char*)tc_ptr->TC_string); - while(1) + gPC.printf("Telecommand is for BAE\r\n"); + gPC.printf("Sending TC to BAE...\r\n"); //interrupt to be sent to the bae + y = FCTN_I2C_WRITE((char*)tc_ptr->TC_string,TC_LONG_SIZE); // Check for SHORT and LONG TC and then send + + if(y==1) + { + ACK_L234(tm_ptr_short,0x03,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(y==0) { - wait(1); //TimeOut instead of wait - if(tm_status_4m_slv == 1) + //wait(0.2); + uint8_t poll=0; + while(poll<60 && BAE_I2C_GPIO==0) + { + wait_ms(50); + poll+=1; + } + if(BAE_I2C_GPIO == 1) //name to be changed later { - //printf("receiving...\r\n"); - FCTN_I2C_READ((char*)tm_pointer->TM_string,134); - //printf("%s", tm_pointer->TM_string); - received+=1; - tm_pointer = tm_pointer->next_TM; - break; //only for testing purpose + gPC.printf("BAE_I2C_GPIO is high\r\n"); + + y=FCTN_I2C_READ((char*)tm_pointer->TM_string,TM_LONG_SIZE); //rify later about the size + if(y==0) + { + tm_pointer->next_TM=NULL; + return tm_ptr; + } + else if(y==1) + { + ACK_L234(tm_ptr_short,0x85,GETpacket_seq_count(tc_ptr)); + //gPC.printf("\n\rPTE->PDIR = 0x%08X",PTE->PDIR); + return tm_ptr_short; + break; + } } - else + else if(BAE_I2C_GPIO == 0) //name to be changed later { - break; + gPC.printf("BAE_I2C_GPIO is not high\r\n"); + ACK_L234(tm_ptr_short,0x84,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; } } - if(received >= 1 ) - { - //printf("Telemetry is received from BAE\r\n"); - Base_tm *tm_print = tm_ptr; - for(uint8_t i=0;i<received;i++) - { - //printf("%s", tm_print->TM_string); - tm_print = tm_print->next_TM; //for check - } - received = 0; - tm_pointer->next_TM = NULL; return tm_ptr; - } - else - { - //printf("Telemetry is not received from BAE\r\n"); - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = 0x01; - tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided - tm_pointer->TM_string[4] = 0x01; - for(uint8_t i=0;i<6;i++) - { - tm_pointer->TM_string[i+5] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - } - break; } - case 2: + + case 2: // APID = 2 corresponds to CDMS { //gPC.printf("Telecommand is for CDMS\r\n"); //apid = 10 corresponds to cdms switch(GETservice_type(tc_ptr)) { - case 0x60: + /*case 0x60: //service type = 0x6 { - //gPC.printf("service:MMS\r\n"); - switch(GETservice_subtype(tc_ptr)) - { - case 0x1: - { - //printf("sub_service:Read from RAM_Memory\r\n"); - mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]); - - //Data[0] = FCTN_CDMS_RD_FLASH(0); - //Data[1] = FCTN_CDMS_RD_FLASH(1); - //tm_pointer = new Long_tm; - tm_pointer->TM_string[0] = 0x30; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = (uint8_t)(flash_counter); - for(uint8_t i=0;i<4;i++) - { - tm_pointer->TM_string[3+i] = (uint8_t)((Data[0]>>(8*i))&0x00FF); - } - for(uint8_t i=4;i<8;i++) - { - tm_pointer->TM_string[3+i] = (uint8_t)((Data[1]>>(8*i))&0x00FF); - } - crc16 = crc16_gen(tm_ptr->TM_string,9); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - } - case 0x2: - { - //printf("sub_service:Read from Flash_Memory\r\n"); - mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]); - - //Data[0] = FCTN_CDMS_RD_FLASH(0); - //Data[1] = FCTN_CDMS_RD_FLASH(1); - //tm_pointer = new Long_tm; - tm_pointer->TM_string[0] = 0x30; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = (uint8_t)(flash_counter); - for(uint8_t i=0;i<4;i++) - { - tm_pointer->TM_string[3+i] = (uint8_t)((Data[0]>>(8*i))&0x00FF); - } - for(uint8_t i=4;i<8;i++) - { - tm_pointer->TM_string[3+i] = (uint8_t)((Data[1]>>(8*i))&0x00FF); - } - crc16 = crc16_gen(tm_ptr->TM_string,9); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - } - case 0x5: - { - //printf("WRITE ON FLASH_MEMORY\r\n"); - mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]); - 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]))); - //FCTN_CDMS_WR_FLASH(mid,block); - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = 0x01; - tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided - tm_pointer->TM_string[4] = 0x01; - for(uint8_t i=0;i<6;i++) - { - tm_pointer->TM_string[i+5] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - default: - { - //printf("INVALID TC\r\n"); //Send Invalid TC Telemetry - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = 0x01; - tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided - tm_pointer->TM_string[4] = 0x01; - for(uint8_t i=0;i<6;i++) - { - tm_pointer->TM_string[i+5] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - } - break; - } - } - case 0x8: + gPC.printf("service:MMS\r\n"); + switch(GETservice_subtype(tc_ptr)) { - //printf("service:FUNCTION MANAGEMENT SERVICE\r\n"); - if(GETservice_subtype(tc_ptr)==0x1) - { - if(GETpid(tc_ptr)==0x01) - { - //printf("TC_PL_INIT\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0x02) - { - //printf("TC_PL_MAIN\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0x03) - { - //printf("TC_COM_INIT\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0x04) - { - //printf("TC_CDMS_HK_MAIN\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0x11) - { - //printf("TC_SW_ON_SD\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0x12) - { - //printf("TC_SW_ON_RTC\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0x13) - { - //printf("TC_SW_ON_BAE\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0x14) - { - //printf("TC_SW_ON_PL_DL\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0x15) - { - //printf("TC_SW_ON_PL_AG_HV\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0x16) - { - //printf("TC_SW_ON_V_A_EN\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0x21) - { - //printf("TC_SW_OFF_SD\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0x22) - { - //printf("TC_SW_OFF_RTC\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0x23) - { - //printf("TC_SW_OFF_BAE\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0x24) - { - //printf("TC_SW_OFF_PL_DL\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0x25) - { - //printf("TC_SW_OFF_PL_AG_HV\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0x26) - { - //printf("TC_SW_OFF_V_A_EN\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0x31) - { - //printf("TC_RST_SD\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0x32) - { - //printf("TC_RST_RTC\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0x33) - { - //printf("TC_RST_BAE\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0x34) - { - //printf("TC_RST_PL_DL\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - break; - } - else if(GETpid(tc_ptr)==0xC1) - { - //printf("RESET_HK_COUNTER\r\n"); // call PWR_SWCH_ON function - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = ACKCODE; - for(uint8_t i=3;i<11;i++) - { - tm_pointer->TM_string[i] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; - } - else if(GETpid(tc_ptr)==0xF1) - { - //printf("RD_RTC\r\n"); //call RD_RTC - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xD0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = 0x01; - uint64_t time = FCTN_CDMS_RD_RTC(); - tm_pointer->TM_string[3] = (uint8_t)((time&0xFF00000000000000)>>56); - tm_pointer->TM_string[4] = (uint8_t)((time&0x00FF000000000000)>>48); - tm_pointer->TM_string[5] = (uint8_t)((time&0x0000FF0000000000)>>40); - tm_pointer->TM_string[6] = (uint8_t)((time&0x000000FF00000000)>>32); - tm_pointer->TM_string[7] = (uint8_t)((time&0x00000000FF000000)>>24); - tm_pointer->TM_string[8] = (uint8_t)((time&0x0000000000FF0000)>>16); - tm_pointer->TM_string[9] = (uint8_t)((time&0x000000000000FF00)>>8); - tm_pointer->TM_string[10] = (uint8_t)(time&0x00000000000000FF); - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - } - else - { - //printf("INVALID TC\r\n"); - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = 0x01; - tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided - tm_pointer->TM_string[4] = 0x01; - for(uint8_t i=0;i<6;i++) - { - tm_pointer->TM_string[i+5] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - } - } - - + case 0x2: //service subtye + { + //gPC.printf("sub_service:Read LONG_RAM_Memory\r\n"); + mid=((uint16_t)(tc_ptr->TC_string[3]<<4))+((uint16_t)(tc_ptr->TC_string[4])); + if(mid!=0x0000 && mid!=0x0001) + { + ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + FCTN_CDMS_RD_L_RAM(tm_pointer); + + tm_pointer->TM_string[0] = 0x30; + tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); + tm_pointer->TM_string[2] = 0xA0; + tm_pointer->TM_string[3] = 0x00; //spare bits + + crc16 = crc16_gen(tm_ptr->TM_string,132); + tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); + tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); + tm_pointer->next_TM = NULL; + return tm_ptr; + } + case 0x5: // change the cases appropriately + { + //gPC.printf("WRITE ON SHORT_FLASH_MEMORY\r\n"); + mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]); + //32 bits at a time + + if(mid!= && mid!=) //allowable MID values? + { + ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + + FCTN_CDMS_WR_S_FLASH(tc_ptr); + + ACK_L234(tm_ptr_short,???,GETpacket_seq_count(tc_ptr)); //ackCode = ? for success + + return tm_ptr_short; + } + case 0x6: + { + //gPC.printf("WRITE ON LONG_FLASH_MEMORY\r\n"); + mid=(uint16_t)(tc_ptr->TC_string[3]<<4)+(uint16_t)(tc_ptr->TC_string[4]); + //1024 bits at a time + + if(mid<0x0002 || mid>0x000A) //allowable MID values? + { + ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr)); //ackCode = ? for invalid mid + return tm_ptr_short; + } + + ///Send TM for success after writing onto flash + FCTN_CDMS_WR_L_FLASH(mid); + + return tm_ptr_short; + } + default: + { + gPC.printf("INVALID SERVICE SUBTYPE\r\n"); + ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + } + } */ + case 0x80: + { + gPC.printf("service:FUNCTION MANAGEMENT SERVICE\r\n"); + if(GETservice_subtype(tc_ptr)==0x1) + { + if(GETpid(tc_ptr)==0x01) + { + if(CDMS_STANDBY==1) + { + //gPC.printf("TC_PL_INIT\r\n"); // call PWR_SWCH_ON function + + P_PL_INIT(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(CDMS_STANDBY==0) + { + ACK_L234(tm_ptr_short,0x87,GETpacket_seq_count(tc_ptr)); //TC cannot be processed now + return tm_ptr_short; + } + } + else if(GETpid(tc_ptr)==0x02) + { + if(CDMS_STANDBY==1) + { + //gPC.printf("TC_PL_MAIN\r\n"); // call PWR_SWCH_ON function + + P_PL_MAIN(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(CDMS_STANDBY==0) + { + ACK_L234(tm_ptr_short,0x87,GETpacket_seq_count(tc_ptr)); //TC cannot be processed now + return tm_ptr_short; + } + } + else if(GETpid(tc_ptr)==0x03) + { + if(CDMS_STANDBY==1) + { + //gPC.printf("PL_COM_INIT\r\n"); // call PWR_SWCH_ON function + + P_COM_INIT(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(CDMS_STANDBY==0) + { + ACK_L234(tm_ptr_short,0x87,GETpacket_seq_count(tc_ptr)); //TC cannot be processed now + return tm_ptr_short; + } + } + else if(GETpid(tc_ptr)==0x04) + { + if(CDMS_STANDBY==1) + { + //gPC.printf("TC_P_CDMS_HK_MAIN\r\n"); // call PWR_SWCH_ON function + + P_CDMS_HK_MAIN(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(CDMS_STANDBY==0) + { + ACK_L234(tm_ptr_short,0x87,GETpacket_seq_count(tc_ptr)); //TC cannot be processed now + return tm_ptr_short; + } + } + else if(GETpid(tc_ptr)==0x05) + { + if(CDMS_STANDBY==1) + { + //gPC.printf("TC_SW_ON_SD\r\n"); // call PWR_SWCH_ON function + + P_PL_RCV_SC_DATA(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(CDMS_STANDBY==0) + { + ACK_L234(tm_ptr_short,0x87,GETpacket_seq_count(tc_ptr)); //TC cannot be processed now + return tm_ptr_short; + } + } + else if(GETpid(tc_ptr)==0x06) + { + if(CDMS_STANDBY==1) + { + //gPC.printf("TC_SW_ON_RTC\r\n"); // call PWR_SWCH_ON function + + P_CDMS_INIT_SD(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(CDMS_STANDBY==0) + { + ACK_L234(tm_ptr_short,0x87,GETpacket_seq_count(tc_ptr)); //TC cannot be processed now + return tm_ptr_short; + } + } + else if(GETpid(tc_ptr)==0x11) + { + //gPC.printf("TC_SW_ON_SD\r\n"); // call PWR_SWCH_ON function + + CDMS_SD_SW_ON(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(GETpid(tc_ptr)==0x21) + { + //gPC.printf("TC_SW_ON_SD\r\n"); // call PWR_SWCH_ON function + + CDMS_SD_SW_OFF(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(GETpid(tc_ptr)==0x13) + { + //gPC.printf("TC_SW_ON_BAE\r\n"); // call PWR_SWCH_ON function + + SW_ON_BAE(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(GETpid(tc_ptr)==0x23) + { + //gPC.printf("TC_SW_OFF_BAE\r\n"); // call PWR_SWCH_ON function + + SW_OFF_BAE(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(GETpid(tc_ptr)==0x14) + { + //gPC.printf("TC_SW_ON_PL_BEE\r\n"); // call PWR_SWCH_ON function + + SW_ON_PL_BEE(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(GETpid(tc_ptr)==0x24) + { + //gPC.printf("TC_SW_OFF_PL_BEE\r\n"); // call PWR_SWCH_ON function + + SW_OFF_PL_BEE(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(GETpid(tc_ptr)==0x15) + { + //gPC.printf("TC_SW_ON_PL_EPS\r\n"); // call PWR_SWCH_ON function + + SW_ON_PL_EPS(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(GETpid(tc_ptr)==0x25) + { + //gPC.printf("TC_SW_OFF_PL_EPS\r\n"); // call PWR_SWCH_ON function + + SW_OFF_PL_EPS(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(GETpid(tc_ptr)==0x16) + { + + //gPC.printf("TC_SW_ON_V_A_EN\r\n"); // call PWR_SWCH_ON function + + SW_ON_V_A_EN(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(GETpid(tc_ptr)==0x26) + { + //gPC.printf("TC_SW_OFF_V_A_EN\r\n"); // call PWR_SWCH_ON function + + SW_OFF_V_A_EN(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(GETpid(tc_ptr)==0x31) + { + //gPC.printf("TC_RST_SD\r\n"); // call PWR_SWCH_ON function + + RST_SD(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(GETpid(tc_ptr)==0x33) + { + //gPC.printf("TC_RST_BAE\r\n"); // call PWR_SWCH_ON function + + RST_BAE(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(GETpid(tc_ptr)==0x34) + { + //gPC.printf("TC_RST_PL_BEE\r\n"); // call PWR_SWCH_ON function + + RST_PL_BEE(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(GETpid(tc_ptr)==0x40) + { + //gPC.printf("RESET_HK_COUNTER\r\n"); // call PWR_SWCH_ON function + + RST_HK_COUNTER(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(GETpid(tc_ptr)==0x41) + { + //gPC.printf("RESET_HK_COUNTER\r\n"); // call PWR_SWCH_ON function + + RST_HK_COUNTER(); + + ACK_L234(tm_ptr_short,0xC0,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + else if(GETpid(tc_ptr)==0xF1) + { + //gPC.printf("TC_CDMS_RD_RTC\r\n"); // call PWR_SWCH_ON function + + /*uint32_t time_temp = FCTN_CDMS_RD_RTC(); //RTC_RD_EROR has to incorporated + tm_pointer->TM_string[0] = 0x78; + tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); + tm_pointer->TM_string[2] = 0xA0; + tm_pointer->TM_string[3] = 0x00; + tm_pointer->TM_string[4] = (uint8_t)((time & 0xFF000000)>>24); + tm_pointer->TM_string[5] = (uint8_t)((time & 0x00FF0000)>>16); + tm_pointer->TM_string[6] = (uint8_t)((time & 0x0000FF00)>>8); + tm_pointer->TM_string[7] = (uint8_t)((time & 0x000000FF)); + for(uint8_t i=0;i<124;i++) + { + tm_pointer->TM_string[i+8] = 0x00; + } + crc16 = crc16_gen(tm_ptr->TM_string,132); + tm_pointer->TM_string[132] = (uint8_t)((crc16&0xFF00)>>8); + tm_pointer->TM_string[133] = (uint8_t)(crc16&0x00FF); + tm_pointer->next_TM = NULL; + return tm_ptr; //incomplete + } + else + { + gPC.printf("INVALID FID\r\n"); + ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + } + else + { + gPC.printf("INVALID SERVICE SUBTYPE\r\n"); + ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + }*/ + case 0x70: + { + gPC.printf("\n\n\rService:PAYLOAD MANAGEMENT SERVICE"); + if(GETservice_subtype(tc_ptr)==0x1) //make sure it is LONG TC before executing else INVALID TC + { + gPC.printf("\n\rTC with subtype = 0x1"); + TM_PMS_PL_SCHEDULE(tm_ptr,GETpacket_seq_count(tc_ptr)); + for(uint8_t i=0,j=0;i<32;i++) + { + pl_block[i] &= 0x00000000; + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[3+j]))<<24); + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[4+j]))<<16); + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[5+j]))<<8); + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[6+j]))); + j+=4; + } + return tm_ptr; + } + else if(GETservice_subtype(tc_ptr)==0x2) + { + gPC.printf("\n\rTC with subtype = 0x2"); + TM_PMS_PL_SCHEDULE(tm_ptr,GETpacket_seq_count(tc_ptr)); + for(uint8_t i=32,j=0;i<64;i++,j+=4) + { + pl_block[i] &= 0x00000000; + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[3+j]))<<24); + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[4+j]))<<16); + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[5+j]))<<8); + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[6+j]))); + } + return tm_ptr; + } + else if(GETservice_subtype(tc_ptr)==0x3) + { + gPC.printf("\n\rTC with subtype = 0x3"); + TM_PMS_PL_SCHEDULE(tm_ptr,GETpacket_seq_count(tc_ptr)); + for(uint8_t i=64,j=0;i<96;i++,j+=4) + { + pl_block[i] &= 0x00000000; + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[3+j]))<<24); + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[4+j]))<<16); + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[5+j]))<<8); + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[6+j]))); + } + return tm_ptr; + } + else if(GETservice_subtype(tc_ptr)==0x4) + { + gPC.printf("\n\rTC with subtype = 0x4"); + TM_PMS_PL_SCHEDULE(tm_ptr,GETpacket_seq_count(tc_ptr)); + for(uint8_t i=96,j=0;i<128;i++,j+=4) + { + pl_block[i] &= 0x00000000; + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[3+j]))<<24); + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[4+j]))<<16); + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[5+j]))<<8); + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[6+j]))); + } + return tm_ptr; + } + else if(GETservice_subtype(tc_ptr)==0x5) + { + gPC.printf("\n\rTC with subtype = 0x5"); + TM_PMS_PL_SCHEDULE(tm_ptr,GETpacket_seq_count(tc_ptr)); + for(uint8_t i=128,j=0;i<160;i++,j+=4) + { + pl_block[i] &= 0x00000000; + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[3+j]))<<24); + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[4+j]))<<16); + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[5+j]))<<8); + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[6+j]))); + } + return tm_ptr; + } + else if(GETservice_subtype(tc_ptr)==0x6) + { + gPC.printf("\n\rTC with subtype = 0x6"); + TM_PMS_PL_SCHEDULE(tm_ptr,GETpacket_seq_count(tc_ptr)); + for(uint8_t i=160,j=0;i<192;i++,j+=4) + { + pl_block[i] &= 0x00000000; + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[3+j]))<<24); + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[4+j]))<<16); + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[5+j]))<<8); + pl_block[i] |= (((uint32_t)(tc_ptr->TC_string[6+j]))); + } + return tm_ptr; + } + else if(GETservice_subtype(tc_ptr)==0xF) + { + gPC.printf("\n\rTC with subtype = 0xF"); + TM_PMS_PL_SCHEDULE(tm_ptr,GETpacket_seq_count(tc_ptr)); + return tm_ptr; + } + else + { + gPC.printf("INVALID SERVICE SUBTYPE\r\n"); + ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } } default: { - //printf("INVALID TC"); //send invalid TC TM - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = 0x01; - tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided - tm_pointer->TM_string[4] = 0x01; - for(uint8_t i=0;i<6;i++) - { - tm_pointer->TM_string[i+5] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; + gPC.printf("ILLEGAL TC"); + ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; } } } case 3: { - //printf("Telecommand is for PL\r\n"); - // printf("Informing PL about TC using I2C\r\n"); //interrupt to be sent to the bae - // FCTN_I2C_WRITE((char*)tc_ptr->TC_string); - // printf("sent the Telecommand to BAE\r\n"); //packet along with crc will be sent when bae is ready - // wait(1); //wait time is to be optimised - // if(tm_status_4m_slv == 1) - // { - // FCTN_I2C_READ((char*)tm_ptr->TM_string); - // received = 1; - // } - // if(received == 1 ) - // { - // printf("Telemetry is received from BAE\r\n"); - // printf("%s", tm_ptr->TM_string); - // received = 0; - // } // similar to BAE functions - break; + //#if DEBUG + gPC.printf("\n\rTelecommand is for PL\r\n"); + //#endif + if(GETshort_or_long_tc(tc_ptr) == LONG_TC_CODE) + y=FCTN_I2C_WRITE_PL((char*)tc_ptr->TC_string,TC_LONG_SIZE); + else if(GETshort_or_long_tc(tc_ptr) == SHORT_TC_CODE) + y=FCTN_I2C_WRITE_PL((char*)tc_ptr->TC_string,TC_SHORT_SIZE); + + if(y==1) + { + ACK_L234(tm_ptr_short,0x03,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + break; + } + else if(y==0) + { + //wait(0.2); + uint8_t poll=0; + while(poll<60 && PL_I2C_Intr==0) + { + wait_ms(50); + poll+=1; + } + if(PL_I2C_Intr == 1) //name to be changed later + { + gPC.printf("PL_I2C_Intr is high\r\n"); + + y=FCTN_I2C_READ_PL((char*)tm_pointer->TM_string,TM_LONG_SIZE); //rify later about the size + if(y==0) + { + tm_pointer->next_TM=NULL; + return tm_ptr; + break; + } + else if(y==1) + { + ACK_L234(tm_ptr_short,0x85,GETpacket_seq_count(tc_ptr)); + //gPC.printf("\n\rPTE->PDIR = 0x%08X",PTE->PDIR); + return tm_ptr_short; + break; + } + } + else if(PL_I2C_Intr == 0) //name to be changed later + { + gPC.printf("PL_I2C_Intr is not high\r\n"); + ACK_L234(tm_ptr_short,0x84,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; + } + } } - default: //invalid TC + default: //invalid TC { - //printf("INVALID TC\r\n"); - //tm_pointer = new Short_tm; - tm_pointer->TM_string[0] = 0xB0; - tm_pointer->TM_string[1] = GETpacket_seq_count(tc_ptr); - tm_pointer->TM_string[2] = 0x01; - tm_pointer->TM_string[3] = ACKCODE; //ackcode to be decided - tm_pointer->TM_string[4] = 0x01; - for(uint8_t i=0;i<6;i++) - { - tm_pointer->TM_string[i+5] = 0; - } - crc16 = crc16_gen(tm_ptr->TM_string,11); - tm_pointer->TM_string[11] = (uint8_t)((crc16&0xFF00)>>8); - tm_pointer->TM_string[12] = (uint8_t)(crc16&0x00FF); - tm_pointer->next_TM = NULL; return tm_ptr; - break; + gPC.printf("INVALID TC\r\n"); + ACK_L234(tm_ptr_short,0x02,GETpacket_seq_count(tc_ptr)); + return tm_ptr_short; } - } + } + return; } // CDMS TEAM CODE END // EXECUTE OBOSC