![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
vr1.1
Dependencies: FreescaleIAP mbed-rtos mbed
Fork of CDMS_RTOS_v1_1 by
Diff: TC.cpp
- Revision:
- 0:d6e3d1e21484
- Child:
- 1:f926f14a52d8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TC.cpp Mon Jun 15 12:16:59 2015 +0000 @@ -0,0 +1,653 @@ +#include "mbed.h" +#include "TC.h" +#include "SDCard.h" +#include "func_head.h" + +Serial sc(USBTX,USBRX); + +void FUNC_CDMS_RLY_TC() +{ + sc.printf("in FUNC_CDMS_RLY_TC\n"); + uint8_t read; + sc.scanf("%d",&read); //Packet sequence count + pac_seq_cnt = read; + sc.scanf("%d",&read); //Data[0] contains APID,LFB,long_or_short,AoN,Spr and Ack + apid_size = read; + apid=(apid_size&0xC0)>>6; //apid is decoded + long_or_short=(apid_size&0x10)>>4; //size of tc is known + switch(apid) + { + case 1: //apid=01 implies it corresponds to bae + { + sc.printf("BAE\r\r\n"); + uint8_t p_i2c_bae[long_or_short*124+11]; + p_i2c_bae[0]=pac_seq_cnt; + p_i2c_bae[1]=apid_size; + sc.scanf("%d",&read); //services contains service_type and sub_service_type + p_i2c_bae[2] = read; + for(int i=3;i<(long_or_short*124+11);i++){ + sc.scanf("%d",&read); + p_i2c_bae[i] = read; + } + sc.printf("inform BAE about TC using I2C\r\n"); //interrupt to be sent to the bae + sc.printf("send the packet + CRC to the BAE after receving i2c signal from BAE\r\n"); //packet along with crc will be sent when bae is ready + break; + } + case 3: + { + sc.printf("SPEED\r\n"); //speed corresponds to apid = 11 + uint8_t p_i2c_speed[long_or_short*124+11]; + p_i2c_speed[0]=pac_seq_cnt; + p_i2c_speed[1]=apid_size; + sc.scanf("%d",&read); + p_i2c_speed[2] = read; //services contains service_type and sub_service_type + for(int i=3;i<(long_or_short*124+11);i++){ + sc.scanf("%d",&read); + p_i2c_speed[i] = read; + } + sc.printf("inform PL about TC using I2C\r\n"); + sc.printf("send the packet + CRC to the PL after receving i2c signal from PL\r\n"); + break; + } + case 2: + { + sc.printf("CDMS\r\n"); //apid = 10 corresponds to cdms + uint8_t services,appdata[long_or_short*124+6],crc[2]; + sc.scanf("%d",&read); + services = read; //services contains service_type and sub_service_type + for(int i=3;i<(long_or_short*124+6);i++){ + sc.scanf("%d",&read); + appdata[i-3] = read; + } + sc.scanf("%d",&read); + crc[0] = read; + sc.scanf("%d",&read); + crc[1] = read; + service_type=(services&0xF0)>>4; + sub_service_type=(services&0x0F); + switch(service_type){ + case 6: + { + sc.printf("memory management syservice_typeem\r\n"); + switch(sub_service_type){ + case 1: + { + sc.printf("READ FROM MEMORY\r\n"); + if(appdata[0]==2){ //appdata[0] is pid + sc.printf("RD_L_FLASH1\r\n"); //tm is lmb + //P_CDMS_RD_FLASH + + for(int i=0;i<128;i++){ + telemetry_type1[i]=long_memory_block_tm[i-1]; + } + for(int i=128;i<130;i++){ + telemetry_type1[i]=crc_tm[i-128]; + } + } + else if ((appdata[0]&0xF0)==0x10){ + sc.printf("RD_L_FLASH2\r\n"); //tm is lmb + //P_CDMS_RD_FLASH + + for(int i=0;i<128;i++){ + telemetry_type1[i]=long_memory_block_tm[i-1]; + } + for(int i=128;i<130;i++){ + telemetry_type1[i]=crc_tm[i-128]; + } + } + else if (appdata[0]==0x22){ + sc.printf("RD_S_FLASH1\r\n"); //tm is smb + //P_CDMS_RD_FLASH + + telemetry_type2[0]=tmid3_spr_tm; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + for(int i=4;i<11;i++){ + telemetry_type2[i]=small_memory_block_tm[i-4]; + } + for(int i=11;i<13;i++){ + telemetry_type2[i]=crc_tm[i-11]; + } + } + else if ((appdata[0]&0xF0)==0x30){ + sc.printf("RD_S_FLASH2\r\n"); //tm is smb + //P_CDMS_RD_FLASH + + telemetry_type2[0]=tmid3_spr_tm; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + for(int i=3;i<11;i++){ + telemetry_type2[i]=small_memory_block_tm[i-3]; + } + for(int i=11;i<13;i++){ + telemetry_type2[i]=crc_tm[i-11]; + } + } + else if (appdata[0]==0x42){ + sc.printf("RD_L_RAM1\r\n"); //tm is lmb + //P_CDMS_RD_RAM + + for(int i=0;i<128;i++){ + telemetry_type1[i]=long_memory_block_tm[i-1]; + } + for(int i=128;i<130;i++){ + telemetry_type1[i]=crc_tm[i-128]; + } + } + else if ((appdata[0]&0xF0)==0x50){ + sc.printf("RD_L_RAM2\r\n"); //tm is lmb + //P_CDMS_RD_RAM + + for(int i=0;i<128;i++){ + telemetry_type1[i]=long_memory_block_tm[i-1]; + } + for(int i=128;i<130;i++){ + telemetry_type1[i]=crc_tm[i-128]; + } + } + else if (appdata[0]==0x62){ + sc.printf("RD_S_RAM\r\n"); //tm is smb + //P_CDMS_RD_RAM + + telemetry_type2[0]=tmid3_spr_tm; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + for(int i=3;i<11;i++){ + telemetry_type2[i]=small_memory_block_tm[i-3]; + } + for(int i=11;i<13;i++){ + telemetry_type2[i]=crc_tm[i-11]; + } + } + else if ((appdata[0]&0xF0)==0x70){ + sc.printf("RD_S_RAM2\r\n"); //tm is smb + //P_CDMS_RD_RAM + + telemetry_type2[0]=tmid3_spr_tm; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + for(int i=3;i<11;i++){ + telemetry_type2[i]=small_memory_block_tm[i-3]; + } + for(int i=11;i<13;i++){ + telemetry_type2[i]=crc_tm[i-11]; + } + } + else { + sc.printf("INVALID TC"); + //Send Invalid TC Telemetry + } + break; + } + case 5: + { + sc.printf("WRITE ON MEMORY\r\n"); + switch(appdata[0]){ + case 0:sc.printf("WR_S_FLASH\r\n"); + //P_CDMS_WR_FLASH + telemetry_type2[0]=0XB0; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + telemetry_type2[3]=ackcode_tm; + for(int i=4;i<11;i++){ + telemetry_type2[i]=0X00; + } + + break; + case 1:sc.printf("WR_S_RAM\r\n"); + //P_CDMS_WR_RAM + telemetry_type2[0]=0XB0; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + telemetry_type2[3]=ackcode_tm; + for(int i=4;i<11;i++){ + telemetry_type2[i]=0X00; + } + + break; + case 16:sc.printf("WR_L_FLASH\r\n"); + telemetry_type2[0]=0XB0; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + telemetry_type2[3]=ackcode_tm; + for(int i=4;i<11;i++){ + telemetry_type2[i]=0X00; + } + //P_CDMS_WR_FLASH + + break; + case 17:sc.printf("WR_L_RAM\r\n"); + //P_CDMS_WR_RAM + telemetry_type2[0]=0XB0; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + telemetry_type2[3]=ackcode_tm; + for(int i=4;i<11;i++){ + telemetry_type2[i]=0X00; + } + + break; + default:{sc.printf("INVALID TC"); + //send invalid TC TM + break;} + } + break; + } + case 6: + { + sc.printf("WRITE FROM ONE MEMORY TO ANOTHER\r\n"); + switch(appdata[0]){ + case 0:sc.printf("WR_S_FLASH\r\n"); + //P_CDMS_WR_FLASH + telemetry_type2[0]=0XB0; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + telemetry_type2[3]=ackcode_tm; + for(int i=4;i<11;i++){ + telemetry_type2[i]=0X00; + } + break; + case 1:sc.printf("WR_S_RAM\r\n"); + //P_CDMS_WR_RAM + telemetry_type2[0]=0XB0; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + telemetry_type2[3]=ackcode_tm; + for(int i=4;i<11;i++){ + telemetry_type2[i]=0X00; + } + break; + case 16:sc.printf("WR_L_FLASH\r\n"); + //P_CDMS_WR_FLASH + telemetry_type2[0]=0XB0; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + telemetry_type2[3]=ackcode_tm; + for(int i=4;i<11;i++){ + telemetry_type2[i]=0X00; + } + break; + case 17:sc.printf("WR_L_RAM\r\n"); + //P_CDMS_WR_RAM + telemetry_type2[0]=0XB0; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + telemetry_type2[3]=ackcode_tm; + for(int i=4;i<11;i++){ + telemetry_type2[i]=0X00; + } + break; + default:{sc.printf("INVALID TC"); + //send invalid TC TM + break;} + } + break; + } + case 9: + { + sc.printf("SEND CRC OF FLASH MEMORY\r\n"); + if(appdata[0]==2){ + sc.printf("GET_FLASH_CRC\r\n"); //tm is crc_flash + //P_CDMS_GET_FLASH_CRC + + for(int i=0;i<2;i++){ + telemetry_type1[i]=crc1_tm[i]; + } + for(int i=2;i<4;i++){ + telemetry_type1[i]=crc2_tm[i-2]; + } + for(int i=128;i<130;i++){ + telemetry_type1[i]=crc_tm[i-128]; + } + } + else { + sc.printf("INVALID TC"); + //Send Invalid TC Telemetry + } + break; + } + default:{sc.printf("INVALID TC"); + //send invalid TC TM + break;} + } + break; + } + case 8: + { + sc.printf("FUNCTION MANAGEMENT SERVICE\r\n"); + if(sub_service_type==1){ + if((appdata[0]&0xF0)==0x00){ + sc.printf("RUN_PRCS\r\n"); + switch(appdata[0]){ + case 1:sc.printf("P_PL_INIT\r\n");//tm is ack_l234 + //P_PL_INIT + telemetry_type2[0]=tmid2_spr_tm; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + telemetry_type2[3]=ackcode_tm; + for(int i=3;i<11;i++){ + telemetry_type2[i]=0x00; + } + for(int i=11;i<13;i++){ + telemetry_type2[i]=crc_tm[i-11]; + } + break; + case 2:sc.printf("P_PL_MNGR\r\n");//tm is ack_l234 + //P_PL_MNGR + telemetry_type2[0]=tmid2_spr_tm; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + telemetry_type2[3]=ackcode_tm; + for(int i=3;i<11;i++){ + telemetry_type2[i]=0x00; + } + for(int i=11;i<13;i++){ + telemetry_type2[i]=crc_tm[i-11]; + } + break; + case 3:sc.printf("P_COM_INIT\r\n");//tm is ack_l234 + //P_COM_INIT + telemetry_type2[0]=tmid2_spr_tm; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + telemetry_type2[3]=ackcode_tm; + for(int i=3;i<11;i++){ + telemetry_type2[i]=0x00; + } + for(int i=11;i<13;i++){ + telemetry_type2[i]=crc_tm[i-11]; + } + break; + case 4:sc.printf("P_CDMS_HK_MNGR\r\n");//tm is ack_l234 + //P_CDMS_HK_MNGR + telemetry_type2[0]=tmid2_spr_tm; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + telemetry_type2[3]=ackcode_tm; + for(int i=3;i<11;i++){ + telemetry_type2[i]=0x00; + } + for(int i=11;i<13;i++){ + telemetry_type2[i]=crc_tm[i-11]; + } + break; + default:{sc.printf("INVALID TC"); + //send invalid TC TM + break;} + } + } + else if((appdata[0]&0xF0)==0x10){ + sc.printf("PWR_SWCH\r\n"); + //P_CDMS_SWCH_PWR + + } + else if((appdata[0]&0xF0)==0x20){ + sc.printf("PWR_Rservice_type\r\n"); + //P_CDMS_RST_PWR + + } + else if((appdata[0]&0xF0)==0xE0){ + sc.printf("RD_RTC\n"); //tm is func_mngmt_service_tm + uint8_t *data; + data = FUNC_CDMS_RD_RTC(); + telemetry_type2[0]=tmid4_spr_tm; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + for(int i=3;i<11;i++) + { + telemetry_type2[i]=data[i-3]; + } + for(int i=0;i<11;i++) + { + sc.printf("%d\r\n",telemetry_type2[i]); + } + for(int i=11;i<13;i++){ + telemetry_type2[i]=crc_tm[i-11]; + } + for(int i=0;i<13;i++) + { sd_data[i]=telemetry_type2[i];} + for(int i=13;i<512;i++) + { sd_data[i]=' ';} + disk_write(sd_data, TM_SD_BLOCK_NUMBER); + disk_read(sd_read_data,TM_SD_BLOCK_NUMBER); + sc.printf("data read from sd card\r\n"); + sc.printf("%s\r\n",sd_read_data); + TM_SD_BLOCK_NUMBER++; + + } + else if((appdata[0]&0xF0)==0xF0){ + sc.printf("SD_MNGR\r\n"); //tm is func_mngmt_service_tm + //P_CDMS_MNG_SD + + telemetry_type2[0]=tmid4_spr_tm; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + for(int i=3;i<11;i++){ + telemetry_type2[i]=func_mngmt_service_tm[i-3]; + } + for(int i=11;i<13;i++){ + telemetry_type2[i]=crc_tm[i-11]; + } + } + else { + sc.printf("INVALID TC"); + //Send Invalid TC Telemetry + } + } + else { + sc.printf("INVALID TC"); + //Send Invalid TC Telemetry + } + break; + } + case 7: + { + sc.printf("PAYLOAD MANAGEMENT SERVICE\r\n"); //TM is ACKL234 + switch(sub_service_type){ + case 1:sc.printf("INSERT PL SCHEDULE\r\n"); + telemetry_type2[0]=tmid2_spr_tm; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + telemetry_type2[3]=ackcode_tm; + for(int i=3;i<11;i++){ + telemetry_type2[i]=0x00; + } + for(int i=11;i<13;i++){ + telemetry_type2[i]=crc_tm[i-11]; + } + break; + case 2:sc.printf("DELETE PL SCHEDULE\r\n"); + telemetry_type2[0]=tmid2_spr_tm; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + telemetry_type2[3]=ackcode_tm; + for(int i=3;i<11;i++){ + telemetry_type2[i]=0x00; + } + for(int i=11;i<13;i++){ + telemetry_type2[i]=crc_tm[i-11]; + } + break; + default:{sc.printf("INVALID TC"); + //send invalid TC TM + break;} + } + break; + } + case 11: + { + sc.printf("ONBOARD OPERATIONS SCHEDULING SERVICE\r\n"); + switch(sub_service_type){ + case 1: + { + sc.printf("DISABLE RELEASE OF TCs\r\n"); //tm is ack_l1 + telemetry_type2[0]=tmid1_spr_tm; + telemetry_type2[1]=tc_exec_tm; + telemetry_type2[2]=tc_service_typeatus_tm; + for(int i=3;i<11;i++){ + telemetry_type2[i]=pac_seq_cnt_of_tc_tm[i-3]; + } + for(int i=11;i<13;i++){ + telemetry_type2[i]=crc_tm[i-11]; + } + break; + } + case 2: + { + sc.printf("ENABLE RELEASE OF TCs\r\n"); + break; + } + case 5: + { + sc.printf("DELETE TELECOMMANDS\r\n"); + break; + } + case 6: + { + sc.printf("REPORT TC LIST IN DETAILED FORM\r\n"); //tm is tc_liservice_type + for(int i=0;i<9;i++){ + telemetry_type1[i]=tc_liservice_type_packet1_tm[i]; + } + for(int i=9;i<18;i++){ + telemetry_type1[i]=tc_liservice_type_packet2_tm[i-9]; + } + for(int i=128;i<130;i++){ + telemetry_type1[i]=crc_tm[i-128]; + } + break; + } + case 8: + { + sc.printf("REPORT STATUS OF TC LIST\r\n"); //tm is ack_l1 + telemetry_type2[0]=tmid1_spr_tm; + telemetry_type2[1]=tc_exec_tm; + telemetry_type2[2]=tc_service_typeatus_tm; + for(int i=3;i<11;i++){ + telemetry_type2[i]=pac_seq_cnt_of_tc_tm[i-3]; + } + for(int i=11;i<13;i++){ + telemetry_type2[i]=crc_tm[i-11]; + } + break; + } + case 15: + { + sc.printf("REPORT STATUS OF LAST UNEXECUTED TC\r\n"); //tm is ack_l234 + telemetry_type2[0]=tmid2_spr_tm; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + telemetry_type2[3]=ackcode_tm; + for(int i=3;i<11;i++){ + telemetry_type2[i]=0x00; + } + for(int i=11;i<13;i++){ + telemetry_type2[i]=crc_tm[i-11]; + } + break; + } + default:{sc.printf("INVALID TC"); + //send invalid TC TM + break;} + } + break; + } + case 13: + { + sc.printf("LARGE DATA TRANSFER\r\n"); //tm is ack_l234 + telemetry_type2[0]=tmid2_spr_tm; + telemetry_type2[1]=tc_pac_seq_cnt_tm; + telemetry_type2[2]=tm_pac_seq_cnt_tm; + telemetry_type2[3]=ackcode_tm; + for(int i=3;i<11;i++){ + telemetry_type2[i]=0x00; + } + for(int i=11;i<13;i++){ + telemetry_type2[i]=crc_tm[i-11]; + } + break; + } + case 15: + { + sc.printf("ONBOARD STORAGE AND RETRIEVAL SERVICE\r\n"); + switch(sub_service_type){ + case 0: + { + sc.printf("SCF\r\n"); //tm is obsrs + telemetry_type1[0]=frmseqcnt_fileheadpointer_tm; + for(int i=1;i<128;i++){ + telemetry_type1[i]=multi_obsrs_tm_packets[i-1]; + } + for(int i=128;i<130;i++){ + telemetry_type1[i]=crc_tm[i-128]; + } + break; + } + case 1: + { + sc.printf("SFF-AT\r\n"); + telemetry_type1[0]=frmseqcnt_fileheadpointer_tm; //tm is obsrs + for(int i=1;i<128;i++){ + telemetry_type1[i]=multi_obsrs_tm_packets[i-1]; + } + for(int i=128;i<130;i++){ + telemetry_type1[i]=crc_tm[i-128]; + } + break; + } + case 2: + { + sc.printf("SFF-BT\r\n"); //tm is obsrs + telemetry_type1[0]=frmseqcnt_fileheadpointer_tm; + for(int i=1;i<128;i++){ + telemetry_type1[i]=multi_obsrs_tm_packets[i-1]; + } + for(int i=128;i<130;i++){ + telemetry_type1[i]=crc_tm[i-128]; + } + break; + } + case 3: + { + sc.printf("LOG\r\n"); //tm is obsrs + telemetry_type1[0]=frmseqcnt_fileheadpointer_tm; + for(int i=1;i<128;i++){ + telemetry_type1[i]=multi_obsrs_tm_packets[i-1]; + } + for(int i=128;i<130;i++){ + telemetry_type1[i]=crc_tm[i-128]; + } + break; + } + case 4: + { + sc.printf("HK_ARCHIVE\r\n"); //tm is obsrs + telemetry_type1[0]=frmseqcnt_fileheadpointer_tm; + for(int i=1;i<128;i++){ + telemetry_type1[i]=multi_obsrs_tm_packets[i-1]; + } + for(int i=128;i<130;i++){ + telemetry_type1[i]=crc_tm[i-128]; + } + break; + } + default:{sc.printf("INVALID TC"); + //send invalid TC TM + break; + } + } + break; + } + default:{sc.printf("INVALID TC"); + //send invalid TC TM + break; + } + } + break; + } + default:{sc.printf("INVALID TC"); + //send invalid TC TM + break; + } + } + +}