PWM and ALGO updated.. PWM getting generated

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of TFR_BAE_vr1_1working_finally_PWM_update by Team Fox

Revision:
0:7b4c00e3912f
Child:
3:07e15677a75c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TCTM.cpp	Thu Dec 24 19:15:43 2015 +0000
@@ -0,0 +1,432 @@
+#include "mbed.h"
+#include "TCTM.h"
+
+uint8_t telemetry_type2[13];
+uint8_t telemetry_type1[130];      //two types of telemetry possible
+uint8_t long_memory_block_tm[128],crc_tm[2];   //  tmlmb
+uint8_t frmseqcnt_fileheadpointer_tm,multi_obsrs_tm_packets[127]; // tm obsrs
+uint8_t tc_liservice_type_packet1_tm[9],tc_liservice_type_packet2_tm[9]; // tm tc_liservice_type 
+uint8_t crc1_tm[2],crc2_tm[2];  // tm flash_crc
+uint8_t tmid1_spr_tm=0xA0,tc_exec_tm,tc_service_typeatus_tm,pac_seq_cnt_of_tc_tm[8]; // tm ack_l1
+uint8_t tmid2_spr_tm=0xB0,tc_pac_seq_cnt_tm,tm_pac_seq_cnt_tm,ackcode_tm; // tm ack_l234
+uint8_t tmid3_spr_tm=0xC0,small_memory_block_tm[7]; // tm smb
+uint8_t tmid4_spr_tm=0xD0,func_mngmt_service_tm[8]; // tm func_mngmt_service_tm
+uint8_t apid_size,pac_seq_cnt,apid,long_or_short=1,service_type,sub_service_type; //All variable used TC 
+uint8_t sd_data[512],sd_read_data[512];
+int TM_SD_BLOCK_NUMBER = 1;uint8_t rtc_tc_data[8];
+
+
+void FCTN_TC_DECODE(uint8_t* TC_Packet)
+
+{                   
+                  // uint8_t long_or_short;
+                   // uint8_t TC_Packet[long_or_short*124+11]; 
+                   uint8_t service_type,sub_service_type,ackcode_tm,func_mngmt_service_tm[8],crc_tm[2];;
+                   service_type=(TC_Packet[2]&0xF0)>>4;
+                   sub_service_type=(TC_Packet[2]&0x0F);
+                   switch(service_type){
+                        case 6:printf("memory management service\n");
+                               switch(sub_service_type){
+                                    case 1:printf("READ FROM MEMORY\n");
+                                           if(TC_Packet[3]==2){             //TC_Packet[3] is pid                     
+                                            printf("RD_L_FyoyouyLASH1\n");
+                                            //P_BAE_RD_FLASH
+
+                                            uint8_t long_memory_block_tm[128];
+                                            uint8_t TM_packet[130];
+                                              for(int i=0;i<128;i++){
+                                                TM_packet[i]=long_memory_block_tm[i-1];
+                                              }
+                                              for(int i=128;i<130;i++){
+                                                //FCTN_CRC(long_memory_block_tm)
+                                                TM_packet[i]=crc_tm[i-128];
+                                              }
+                                           }
+                                           else if ((TC_Packet[3]&0xF0)==0x10){
+                                            printf("RD_L_FLASH2\n");
+                                            //P_BAE_RD_FLASH
+
+                                            uint8_t long_memory_block_tm[128];
+                                            uint8_t TM_packet[130];
+                                              for(int i=0;i<128;i++){
+                                                TM_packet[i]=long_memory_block_tm[i-1];
+                                              }
+                                              for(int i=128;i<130;i++){
+                                                TM_packet[i]=crc_tm[i-128];
+                                              }
+                                           }
+                                           else if (TC_Packet[3]==0x22){
+                                            printf("RD_S_FLASH1\n");
+                                            //P_BAE_RD_FLASH
+
+                                            uint8_t tmid_spr_tm=0xC0,tc_psc_tm,tm_psc_tm,small_memory_block_tm[8];
+                                            uint8_t TM_packet[13];
+                                            TM_packet[0]=tmid_spr_tm;
+                                            TM_packet[1]=tc_psc_tm;
+                                            TM_packet[2]=tm_psc_tm;
+                                            TM_packet[3]=ackcode_tm;
+                                            for(int i=3;i<11;i++){
+                                                  TM_packet[i]=small_memory_block_tm[i-3];
+                                                }
+                                              for(int i=11;i<13;i++){
+                                                  TM_packet[i]=crc_tm[i-11];
+                                                }
+                                           }
+                                           else if ((TC_Packet[3]&0xF0)==0x30){
+                                            printf("RD_S_FLASH2\n");
+                                            //P_BAE_RD_FLASH
+
+                                            uint8_t tmid_spr_tm=0xC0,tc_psc_tm,tm_psc_tm,small_memory_block_tm[8];
+                                            uint8_t TM_packet[13];
+                                            TM_packet[0]=tmid_spr_tm;
+                                            TM_packet[1]=tc_psc_tm;
+                                            TM_packet[2]=tm_psc_tm;
+                                            TM_packet[3]=ackcode_tm;
+                                            for(int i=3;i<11;i++){
+                                                  TM_packet[i]=small_memory_block_tm[i-3];
+                                                }
+                                              for(int i=11;i<13;i++){
+                                                  TM_packet[i]=crc_tm[i-11];
+                                                }
+                                           }
+                                           else if (TC_Packet[3]==0x42){
+                                            printf("RD_L_RAM1\n");
+                                            //P_BAE_RD_RAM
+
+                                            uint8_t long_memory_block_tm[128];
+                                            uint8_t TM_packet[130];
+                                              for(int i=0;i<128;i++){
+                                                TM_packet[i]=long_memory_block_tm[i-1];
+                                              }
+                                              for(int i=128;i<130;i++){
+                                                TM_packet[i]=crc_tm[i-128];
+                                              }
+                                           }
+                                           else if ((TC_Packet[3]&0xF0)==0x50){
+                                            printf("RD_L_RAM2\n");
+                                            ////P_BAE_RD_RAM
+                                            uint8_t long_memory_block_tm[128];
+                                            uint8_t TM_packet[130];
+                                              for(int i=0;i<128;i++){
+                                                TM_packet[i]=long_memory_block_tm[i-1];
+                                              }
+                                              for(int i=128;i<130;i++){
+                                                TM_packet[i]=crc_tm[i-128];
+                                              }
+                                           }
+                                           else if (TC_Packet[3]==0x62){
+                                            printf("RD_S_RAM\n");
+                                            //P_BAE_RD_RAM
+
+                                            uint8_t tmid_spr_tm=0xC0,tc_psc_tm,tm_psc_tm,small_memory_block_tm[8];
+                                            uint8_t TM_packet[13];
+                                            TM_packet[0]=tmid_spr_tm;
+                                            TM_packet[1]=tc_psc_tm;
+                                            TM_packet[2]=tm_psc_tm;
+                                            TM_packet[3]=ackcode_tm;
+                                            for(int i=3;i<11;i++){
+                                                  TM_packet[i]=small_memory_block_tm[i-3];
+                                                }
+                                              for(int i=11;i<13;i++){
+                                                  TM_packet[i]=crc_tm[i-11];
+                                                }
+                                           }
+                                           else if ((TC_Packet[3]&0xF0)==0x70){
+                                            printf("RD_S_RAM2\n");
+                                            //P_BAE_RD_RAM
+
+                                            uint8_t tmid_spr_tm=0xC0,tc_psc_tm,tm_psc_tm,small_memory_block_tm[8];
+                                            uint8_t TM_packet[13];
+                                            TM_packet[0]=tmid_spr_tm;
+                                            TM_packet[1]=tc_psc_tm;
+                                            TM_packet[2]=tm_psc_tm;
+                                            TM_packet[3]=ackcode_tm;
+                                            for(int i=3;i<11;i++){
+                                                  TM_packet[i]=small_memory_block_tm[i-3];
+                                                }
+                                              for(int i=11;i<13;i++){
+                                                  TM_packet[i]=crc_tm[i-11];
+                                                }
+                                           }
+                    else {
+                        printf("INVALID TC");
+                        //Send Invalid TC Telemetry
+                    }
+                                    break;
+                                    case 5:printf("WRITE ON MEMORY\n");
+                                           switch(TC_Packet[3]){
+                                                case 0:printf("WR_S_FLASH\n");
+                                                     //P_BAE_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:printf("WR_S_RAM\n");
+                                                     //P_BAE_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:printf("WR_L_FLASH\n");
+                                                    //P_BAE_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:printf("WR_L_RAM\n");
+                                                      //P_BAE_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;
+                                           }
+                                    break;
+                                    case 6:printf("WRITE FROM ONE MEMORY TO ANOTHER\n");
+                                           switch(TC_Packet[3]){
+                                                case 0:printf("WR_S_FLASH\n");
+                                                    //P_BAE_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:printf("WR_S_RAM\n");
+                                                      //P_BAE_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:printf("WR_L_FLASH\n");
+                                                    //P_BAE_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:printf("WR_L_RAM\n");
+                                                     //P_BAE_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;
+                                           }
+                                    break;
+                                    case 9:printf("SEND CRC OF FLASH MEMORY\n");
+                                           if(TC_Packet[3]==2){
+                                            printf("GET_FLASH_CRC\n");
+                                            //P_BAE_GET_FLASH_CRC
+
+                                            uint8_t crc1_tm[2],crc2_tm[2];
+                                            uint8_t TM_packet[130];
+                                          for(int i=0;i<2;i++){
+                                                TM_packet[i]=crc1_tm[i];
+                                              }
+                                            for(int i=2;i<4;i++){
+                                                TM_packet[i]=crc2_tm[i-2];
+                                              }
+                                            for(int i=128;i<130;i++){
+                                                TM_packet[i]=crc_tm[i-128];
+                                              }
+                                           }
+                    else {
+                        printf("INVALID TC");
+                        //Send Invalid TC Telemetry
+                    }
+                                    break;
+                    default:{printf("INVALID TC");
+                            //send invalid TC TM
+                             break;}
+                                }
+                        break;
+                        case 8:printf("FUNCTION MANAGEMENT SERVICE\n");
+                               if(sub_service_type==1){
+                                if((TC_Packet[3]&0xF0)==0x00){
+                                    printf("RUN_PRCS\n");
+                                    switch(TC_Packet[3]){
+                                        case 1:printf("P_EPS_INIT\n");
+                                        //FCTN_EPS_INIT
+                                          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 2:printf("P_EPS_MAIN\n");
+                                        //FCTN_EPS_MAIN
+                                          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 3:printf("P_ACS_INIT\n");
+                                        //FCTN_ACS_INIT
+                                         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 4:printf("P_ACS_ACQ_DATA\n");
+                                        //P_ACS_ACQ_DATA
+                                            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 5:printf("P_ACS_MAIN\n");
+                                        //P_ACS_MAIN
+                                          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 6:printf("P_BCN_INIT\n");
+                                        //FCTN_BCN_INIT
+                                          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 7:printf("P_BCN_MAIN\n");
+                                        //FCTN_BCN_MAIN
+                                          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:{printf("INVALID TC");
+                            //send invalid TC TM
+                             break;}
+                                    }
+                                }
+                                else if((TC_Packet[3]&0xF0)==0x10){
+                                    printf("PWR_SWCH\n");
+                                    //P_BAE_SWCH_PWR
+
+                                }
+                                else if((TC_Packet[3]&0xF0)==0x20){
+                                    printf("PWR_Rservice_type\n");
+                                    //P_BAE_RST_PWR
+
+                                }
+                                else if((TC_Packet[3]&0xF0)==0xE0){
+                                    printf("COMSN_ACS_ALGO\n");
+                                    //P_BAE_COMSN_ACS_ALGO
+
+                                    uint8_t tmid_spr_tm=0xD0,tc_psc_tm,tm_psc_tm,ackcode_tm;
+                                    uint8_t TM_packet[13];
+                                    TM_packet[0]=tmid_spr_tm;
+                                    TM_packet[1]=tc_psc_tm;
+                                    TM_packet[2]=tm_psc_tm;
+                                    TM_packet[3]=ackcode_tm;
+                                    for(int i=3;i<11;i++){
+                                          TM_packet[i]=func_mngmt_service_tm[i-3];
+                                        }
+                                      for(int i=11;i<13;i++){
+                                          TM_packet[i]=crc_tm[i-11];
+                                        }
+                                }
+                                else if((TC_Packet[3]&0xF0)==0xF0){
+                                    printf("COMSN_ACS_HW\n");
+                                    //P_BAE_COMSN_ACS_HW
+
+                                    uint8_t tmid_spr_tm=0xD0,tc_psc_tm,tm_psc_tm,ackcode_tm;
+                                    uint8_t TM_packet[13];
+                                    TM_packet[0]=tmid_spr_tm;
+                                    TM_packet[1]=tc_psc_tm;
+                                    TM_packet[2]=tm_psc_tm;
+                                    TM_packet[3]=ackcode_tm;
+                                    for(int i=3;i<11;i++){
+                                          TM_packet[i]=func_mngmt_service_tm[i-3];
+                                        }
+                                      for(int i=11;i<13;i++){
+                                          TM_packet[i]=crc_tm[i-11];
+                                        }
+                                }
+                else {
+                        printf("INVALID TC");
+                        //Send Invalid TC Telemetry
+                    }
+                               }
+                else {
+                        printf("INVALID TC");
+                        //Send Invalid TC Telemetry
+                    }
+                        break;
+                         default:{printf("INVALID TC");
+                            //send invalid TC TM
+                             break;}
+                    }
+            
+        }
+        
+/************************************************************************************************************************************/        
+//FUNCTIONS EXECUTED BY TELECOMMAND
+//MEMORY MANAGEMENT SERVICE
+//PID 0X02
+
+