Team Fox / Mbed 2 deprecated BAE_QM_MAR9

Dependencies:   FreescaleIAP mbed-rtos mbed

Fork of workinQM_5thJan_azad by Team Fox

Revision:
49:61c9f28332ba
Parent:
47:d59ba66229ce
Child:
52:daa685b0e390
--- a/TCTM.cpp	Fri Jul 08 08:25:39 2016 +0000
+++ b/TCTM.cpp	Thu Jul 14 23:04:26 2016 +0000
@@ -1,3 +1,4 @@
+
 #include "mbed.h"
 #include "rtos.h"
 #include "TCTM.h"
@@ -12,14 +13,18 @@
 #include "cassert"
 #include"math.h"
 
+//Serial pc(USBTX,USBRX);
+
+Serial gpc(USBTX, USBRX);
+
+
 //**********************************STATUS_PARAMETERS*****************************************************
 uint8_t BCN_TX_SW_ENABLE=0x00;
 
 //***********************************FOR STANDBY TIMER****************************************************
 extern void BAE_STANDBY_TIMER_RESET();
 
-uint8_t telemetry[135];
-extern uint8_t BAE_HK_data[134];
+uint8_t telemetry[134];
 
 //*****************PARA******************************
 
@@ -75,6 +80,11 @@
 
 
 //main
+extern Timer BAE_uptime;
+extern Timer I2C_last;
+extern uint8_t BAE_RESET_COUNTER;
+extern void RETURN_UPTIME(float time, uint8_t *day,uint8_t *hour,uint8_t *min);
+
 extern uint8_t ACS_ATS_STATUS;
 extern uint16_t ACS_MAIN_COUNTER;//change\apply
 extern uint8_t HTR_CYCLE_COUNTER;
@@ -84,36 +94,36 @@
 extern uint8_t HTR_ON_DURATION;          //EPS_HTR_OFF timer duration in minutes
 extern uint16_t HTR_CYCLE_PERIOD; 
 
-extern DigitalInOut ACS_TR_XY_ENABLE;
-extern DigitalInOut ACS_TR_Z_ENABLE;
-extern DigitalInOut ACS_TR_XY_OC_FAULT;
-extern DigitalInOut ACS_TR_Z_OC_FAULT;
-extern DigitalInOut ACS_TR_XY_FAULT;
-extern DigitalInOut ACS_TR_Z_FAULT;
-extern DigitalInOut ACS_ATS1_OC_FAULT;
-extern DigitalInOut ACS_ATS2_OC_FAULT;
+extern DigitalOut ACS_TR_XY_ENABLE;
+extern DigitalOut ACS_TR_Z_ENABLE;
+extern DigitalIn ACS_TR_XY_OC_FAULT;
+extern DigitalIn ACS_TR_Z_OC_FAULT;
+extern DigitalIn ACS_TR_XY_FAULT;
+extern DigitalIn ACS_TR_Z_FAULT;
+extern DigitalIn ACS_ATS1_OC_FAULT;
+extern DigitalIn ACS_ATS2_OC_FAULT;
 
-extern DigitalInOut ATS1_SW_ENABLE; // enable of att sens2 switch
-extern DigitalInOut ATS2_SW_ENABLE; // enable of att sens switch
+extern DigitalOut ATS1_SW_ENABLE; // enable of att sens2 switch
+extern DigitalOut ATS2_SW_ENABLE; // enable of att sens switch
 
-extern DigitalInOut DRV_Z_EN;
-extern DigitalInOut DRV_XY_EN;
-extern DigitalInOut TRXY_SW;  //TR XY Switch if any TR_SW error arises then it is same as TR_SW_EN
-extern DigitalInOut TRZ_SW;  //TR Z Switch
+extern DigitalOut DRV_Z_EN;
+extern DigitalOut DRV_XY_EN;
+extern DigitalOut TRXY_SW;  //TR XY Switch if any TR_SW error arises then it is same as TR_SW_EN
+extern DigitalOut TRZ_SW;  //TR Z Switch
 
-extern DigitalInOut phase_TR_x;
-extern DigitalInOut phase_TR_y;
-extern DigitalInOut phase_TR_z;
+extern DigitalOut phase_TR_x;
+extern DigitalOut phase_TR_y;
+extern DigitalOut phase_TR_z;
 
 
 //CDMS
-extern DigitalInOut CDMS_RESET; // CDMS RESET
+extern DigitalOut CDMS_RESET; // CDMS RESET
 extern uint8_t CDMS_SW_STATUS;
-extern DigitalInOut CDMS_OC_FAULT;
+extern DigitalIn CDMS_OC_FAULT;
 
 
 //BCN
-extern DigitalInOut BCN_SW;      //Beacon switch
+extern DigitalOut BCN_SW;      //Beacon switch
 extern uint8_t BCN_TX_STATUS;
 extern uint8_t BCN_FEN;
 extern uint8_t BCN_SPND_TX;
@@ -123,7 +133,7 @@
 extern uint8_t BCN_INIT_STATUS;
 extern uint8_t BCN_FAIL_COUNT;
 extern uint16_t BCN_TX_MAIN_COUNTER;
-extern DigitalInOut BCN_TX_OC_FAULT;
+extern DigitalIn BCN_TX_OC_FAULT;
 extern uint8_t BCN_TMP;
 extern void F_BCN();
 extern void FCTN_BCN_TX_MAIN();
@@ -174,9 +184,9 @@
 extern DigitalOut SelectLineb2;
 extern DigitalOut SelectLineb1;
 extern DigitalOut SelectLineb0;
-extern DigitalInOut EPS_CHARGER_FAULT;
-extern DigitalInOut EPS_CHARGER_STATUS;
-extern DigitalInOut EPS_BATTERY_GAUGE_ALERT;
+extern DigitalIn EPS_CHARGER_FAULT;
+extern DigitalIn EPS_CHARGER_STATUS;
+extern DigitalIn EPS_BATTERY_GAUGE_ALERT;
 
 extern void F_EPS();
 extern AnalogIn CurrentInput;
@@ -220,7 +230,7 @@
     float div=max-min;
     div=(65535.0/div);
     val=((val-min)*div);
-    printf("\n\r the scale is %x",(uint16_t)val);
+    gpc.printf("\n\r the scale is %x",(uint16_t)val);
     return (uint16_t)val;
 }
 
@@ -250,7 +260,7 @@
     float theta_z = acosf(cos_z);
 
     return theta_z;
-    //printf("/n cos_zz= %f /t theta_z= %f /n",cos_z,theta_z);
+    //gpc.printf("/n cos_zz= %f /t theta_z= %f /n",cos_z,theta_z);
 }
 
 //uint8_t tm1[134];
@@ -268,7 +278,7 @@
     /*chaged*/
     uint8_t* tm; // without it some identifier error
     uint16_t crc16=CRC::crc16_gen(telemetry,9); //implementing crc
-    printf("\n\r the crc is %x",crc16);
+    gpc.printf("\n\r the crc is %x",crc16);
     if( ( ((uint8_t)((crc16 & 0xFF00)>>8)==tc[9]) && ((uint8_t)(crc16 & 0x00FF)==tc[10]) )== 0 )
         {
             telemetry[0]=0xB0;
@@ -282,7 +292,7 @@
             crc16 = CRC::crc16_gen(telemetry,11);
             telemetry[11] = (uint8_t)((crc16&0xFF00)>>8);
             telemetry[12] = (uint8_t)(crc16&0x00FF);
-            printf("\n\rincorrect crc");
+            gpc.printf("\n\rincorrect crc");
             for(int i=13;i<134;i++)
                 {
                     telemetry[i]=0x00;
@@ -304,7 +314,7 @@
                     crc16 = CRC::crc16_gen(telemetry,11);
                     telemetry[11] = (uint8_t)((crc16&0xFF00)>>8);
                     telemetry[12] = (uint8_t)(crc16&0x00FF);
-                    printf("\n\rillegal TC packet APID don't match");
+                    gpc.printf("\n\rillegal TC packet APID don't match");
                     for(int i=13;i<134;i++)
                         {
                             telemetry[i]=0x00;
@@ -318,20 +328,20 @@
                     {
                     case 0x60:
                             {
-                                printf("Memory Management Service\r\n");
+                                gpc.printf("Memory Management Service\r\n");
                                 uint8_t service_subtype=(tc[2]&0x0F);
                                 switch(service_subtype)
                                 {
                                     case 0x02:
                                             {
-                                                printf("\n\rRead from RAM");
+                                                gpc.printf("\n\rRead from RAM");
                                                 uint16_t MID = ((uint16_t)tc[3] << 8) | tc[4];
                                                 switch(MID)
                                                 {
                                                     case 0x0000://changed from 0001
                                                             {
-                                                                printf("\n\rRead from MID 0000 \n");
-                                                                printf("\n\rReading flash parameters");
+                                                                gpc.printf("\n\rRead from MID 0000 \n");
+                                                                gpc.printf("\n\rReading flash parameters");
 
                                                                 /*taking some varible till we find some thing more useful*/
                                                                 //uint8_t ref_val=0x01;
@@ -425,63 +435,71 @@
                                                                 telemetry[46] = BCN_TX_MAIN_COUNTER>>8;
                                                                 telemetry[47] = EPS_MAIN_COUNTER;
                                                                 telemetry[48] = EPS_MAIN_COUNTER>>8;
+                                                                
+                                                                uint8_t days,hours,mins;
+                                                                RETURN_UPTIME(BAE_uptime.read(),&days,&hours,&mins);
+                                                                telemetry[49] = days;
+                                                                RETURN_UPTIME(I2C_last.read(),&days,&hours,&mins);
+                                                                telemetry[49] = (telemetry[49]<<3) | (hours>>2);
+                                                                telemetry[50] = hours;
+                                                                telemetry[50] = (telemetry[50]<<6) | mins;
+                                                                
                                                                 //sending in uint can be converted back to int by direct conversion for +values
                                                                 //make sure to convert baack to int for getting negative values
                                                                 //algo for that done 
-                                                                telemetry[49] = actual_data.bit_data_acs_mm[0];
-                                                                telemetry[50] = actual_data.bit_data_acs_mm[0]>>8;
-                                                                telemetry[51] = actual_data.bit_data_acs_mm[1];
-                                                                telemetry[52] = actual_data.bit_data_acs_mm[1]>>8;
-                                                                telemetry[53] = actual_data.bit_data_acs_mm[2];
-                                                                telemetry[54] = actual_data.bit_data_acs_mm[2]>>8;
+                                                                telemetry[51] = actual_data.bit_data_acs_mm[0];
+                                                                telemetry[52] = actual_data.bit_data_acs_mm[0]>>8;
+                                                                telemetry[53] = actual_data.bit_data_acs_mm[1];
+                                                                telemetry[54] = actual_data.bit_data_acs_mm[1]>>8;
+                                                                telemetry[55] = actual_data.bit_data_acs_mm[2];
+                                                                telemetry[56] = actual_data.bit_data_acs_mm[2]>>8;
                                                                 
-                                                                telemetry[55] = actual_data.bit_data_acs_mg[0];
-                                                                telemetry[56] = actual_data.bit_data_acs_mg[0]>>8;
-                                                                telemetry[57] = actual_data.bit_data_acs_mg[1];
-                                                                telemetry[58] = actual_data.bit_data_acs_mg[1]>>8;
-                                                                telemetry[59] = actual_data.bit_data_acs_mg[2];
-                                                                telemetry[60] = actual_data.bit_data_acs_mg[2]>>8;
+                                                                telemetry[57] = actual_data.bit_data_acs_mg[0];
+                                                                telemetry[58] = actual_data.bit_data_acs_mg[0]>>8;
+                                                                telemetry[59] = actual_data.bit_data_acs_mg[1];
+                                                                telemetry[60] = actual_data.bit_data_acs_mg[1]>>8;
+                                                                telemetry[61] = actual_data.bit_data_acs_mg[2];
+                                                                telemetry[62] = actual_data.bit_data_acs_mg[2]>>8;
                                                                 
-                                                                telemetry[61] = BCN_TX_OC_FAULT;
-                                                                telemetry[61] = (telemetry[61]<<1) | ACS_TR_XY_ENABLE;
-                                                                telemetry[61] = (telemetry[61]<<1) | ACS_TR_Z_ENABLE;
-                                                                telemetry[61] = (telemetry[61]<<1) | ACS_TR_XY_OC_FAULT;
-                                                                telemetry[61] = (telemetry[61]<<1) | ACS_TR_Z_OC_FAULT;
-                                                                telemetry[61] = (telemetry[61]<<1) | ACS_TR_XY_FAULT;
-                                                                telemetry[61] = (telemetry[61]<<1) | EPS_CHARGER_FAULT;
-                                                                telemetry[61] = (telemetry[61]<<1) | EPS_CHARGER_STATUS;
+                                                                telemetry[63] = BCN_TX_OC_FAULT;
+                                                                telemetry[63] = (telemetry[63]<<1) | ACS_TR_XY_ENABLE;
+                                                                telemetry[63] = (telemetry[63]<<1) | ACS_TR_Z_ENABLE;
+                                                                telemetry[63] = (telemetry[63]<<1) | ACS_TR_XY_OC_FAULT;
+                                                                telemetry[63] = (telemetry[63]<<1) | ACS_TR_Z_OC_FAULT;
+                                                                telemetry[63] = (telemetry[63]<<1) | ACS_TR_XY_FAULT;
+                                                                telemetry[63] = (telemetry[63]<<1) | EPS_CHARGER_FAULT;
+                                                                telemetry[63] = (telemetry[63]<<1) | EPS_CHARGER_STATUS;
                                                                 
-                                                                telemetry[62] = EPS_BATTERY_GAUGE_ALERT;
-                                                                telemetry[62] = (telemetry[62]<<1) | CDMS_OC_FAULT;
-                                                                telemetry[62] = (telemetry[62]<<1) | ACS_ATS1_OC_FAULT;
-                                                                telemetry[62] = (telemetry[62]<<1) | ACS_ATS2_OC_FAULT;
-                                                                telemetry[62] = (telemetry[62]<<1) | ACS_TR_Z_FAULT;
-                                                                telemetry[62] = (telemetry[62]<<3);
+                                                                telemetry[64] = EPS_BATTERY_GAUGE_ALERT;
+                                                                telemetry[64] = (telemetry[64]<<1) | CDMS_OC_FAULT;
+                                                                telemetry[64] = (telemetry[64]<<1) | ACS_ATS1_OC_FAULT;
+                                                                telemetry[64] = (telemetry[64]<<1) | ACS_ATS2_OC_FAULT;
+                                                                telemetry[64] = (telemetry[64]<<1) | ACS_TR_Z_FAULT;
+                                                                telemetry[64] = (telemetry[64]<<3);
                                                                 //3 spare
                                                                 
-                                                                telemetry[63] = ACS_TR_X_PWM;
-                                                                telemetry[64] = ACS_TR_Y_PWM;
-                                                                telemetry[65] = ACS_TR_Z_PWM;
+                                                                telemetry[65] = ACS_TR_X_PWM;
+                                                                telemetry[66] = ACS_TR_Y_PWM;
+                                                                telemetry[67] = ACS_TR_Z_PWM;
                                                                 //spare byte
                                                                 //assigned it to counter HTR_CYCLE_COUNTER
                                                                 
                                                                 //assign it b_scz_angle
-                                                                telemetry[66] = B_SCZ_ANGLE>>4; 
-                                                                telemetry[66] = (telemetry[66]<<1) | alarmmode;
-                                                                telemetry[66] = (telemetry[66]<<1) | controlmode_mms;
-                                                                telemetry[66] = (telemetry[66]<<2);
-                                                                //2 bit spare
+                                                                telemetry[68] = B_SCZ_ANGLE>>4; 
+                                                                telemetry[68] = (telemetry[68]<<1) | alarmmode;
+                                                                telemetry[68] = (telemetry[68]<<1) | controlmode_mms;
+                                                                telemetry[68] = (telemetry[68]<<1) | singularity_flag_mms;
+                                                                telemetry[68] = (telemetry[68]<<1);
+                                                                //1 bit spare
                                                                 
                                                                 for(int i=0;i<9;i++)
                                                                 {
-                                                                    telemetry[67+i] =  invjm_mms[i];
+                                                                    telemetry[69+i] =  invjm_mms[i];
                                                                     telemetry[80+i] =  jm_mms[i];
                                                                 }
                                                                 
-                                                                for(int i=0;i<3;i++)
-                                                                telemetry[76+i] = bb_mms[i];
-                                                                
-                                                                telemetry[79] = singularity_flag_mms;                      
+                                                                for(int i=0;i<2;i++)
+                                                                telemetry[78+i] = bb_mms[i];
                                                                 
                                                                 for(int i=0;i<16;i++)
                                                                 {
@@ -520,7 +538,7 @@
                                                             }
                                                     case 0x0001:
                                                             {
-                                                                printf("\r\nhk data tm");
+                                                                gpc.printf("\r\nhk data tm");
                                                                 telemetry[0] = 0x60;
                                                                 telemetry[1] = tc[0];
                                                                 telemetry[2] = ACK_CODE;
@@ -623,9 +641,9 @@
                                             }
                                     case 0x05:
                                             {
-                                                printf("\n\rdata for mms 0x05 flash");
+                                                gpc.printf("\n\rdata for mms 0x05 flash");
                                                 /*changed*/
-                                                printf("\n\rwrite on flash\n");
+                                                gpc.printf("\n\rwrite on flash\n");
                                                 uint32_t FLASH_DATA;//256 bits
                                                 
                                                 uint8_t VALID_MID;//to determine wether mid is valid or not otherwise to much repetition of code 1 meaning valid
@@ -648,7 +666,10 @@
                                                             {
                                                                 //FLASH_DATA[1] = (((uint32_t)tc[5] << 24) | ((uint32_t)tc[6] << 16) | ((uint32_t)tc[7] << 8) | (uint32_t)tc[6]);
                                                                 ACS_DETUMBLING_ALGO_TYPE = (tc[8] & 0x01);
-                                                                ACS_STATE = (tc[8]>>1) & 0x0F;
+                                                                //===============================================
+                                                                ACS_STATE = 4;
+                                                                //tc[8] = 1001_
+                                                               //ACS_STATE = (tc[8]>>1) & 0x0F;
                                                                 FLASH_DATA = FCTN_BAE_RD_FLASH_ENTITY(0);
                                                                 FLASH_DATA = (FLASH_DATA & 0xFFF07FFF) | (15<<(uint32_t)tc[8]);
                                                                 FCTN_BAE_WR_FLASH(0,FLASH_DATA);
@@ -733,7 +754,7 @@
                             
                                                     default:
                                                             {
-                                                                printf("Invalid MMS case 0x05 invalid MID\r\n");
+                                                                gpc.printf("Invalid MMS case 0x05 invalid MID\r\n");
                                                                 VALID_MID=0;
                                                                 //ACK_L234_telemetry
                                                                 break;
@@ -766,12 +787,12 @@
                                                         telemetry[i]=0x00;
                                                     }
                                                 
-                                                printf("\n\rWritten on Flash");
+                                                gpc.printf("\n\rWritten on Flash");
                                                 break;
                                             }
                                     default://when invalid service subtype
                                             {
-                                                printf("\n\r MMS invalid Service Subtype");
+                                                gpc.printf("\n\r MMS invalid Service Subtype");
                                                 //ACK_L234_telemetry
                                                 telemetry[0]=0xB0;
                                                 telemetry[1]=tc[0];
@@ -794,13 +815,13 @@
                             }
                     case 0x80:
                             {
-                                //printf("Function Management Service\r\n");
+                                //gpc.printf("Function Management Service\r\n");
                                 uint8_t service_subtype=(tc[2]&0x0F);
                                 switch(service_subtype)
                                 {
                                     case 0x01:
                                             {
-                                                printf("\n\rFMS Activated");
+                                                gpc.printf("\n\rFMS Activated");
                                                 uint8_t fid=tc[3];//changed from pid to fid
                                                 switch(fid)
                                                 {
@@ -809,37 +830,37 @@
                                                                 float mag_data_comm[3]={uint16_to_float(-1000,1000,ACS_MM_X_COMSN),uint16_to_float(-1000,1000,ACS_MM_Y_COMSN),uint16_to_float(-1000,1000,ACS_MM_Z_COMSN)};
                                                                 float gyro_data_comm[3]={uint16_to_float(-5000,5000,ACS_MG_X_COMSN),uint16_to_float(-5000,5000,ACS_MG_Y_COMSN),uint16_to_float(-5000,5000,ACS_MG_Z_COMSN)};
                                                                 float moment_comm[3];
-                                                                printf("ACS_COMSN SOFTWARE\r\n");
+                                                                gpc.printf("ACS_COMSN SOFTWARE\r\n");
                                                                 //ACK_L234_telemetry
                                                                 ACS_STATE = tc[4];
-                                                                if(ACS_STATE == 7)                     // Nominal mode
+                                                                if(ACS_STATE == 2)                     // Nominal mode
                                                                     {
-                                                                        printf("\n\r Nominal mode \n");
+                                                                        gpc.printf("\n\r Nominal mode \n");
                                                                         FCTN_ACS_CNTRLALGO(moment_comm,mag_data_comm,gyro_data_comm,0x01,0x00,ACS_DETUMBLING_ALGO_TYPE);
-                                                                        printf("\n\r Moment values returned by control algo \n");
+                                                                        gpc.printf("\n\r Moment values returned by control algo \n");
                                                                         for(int i=0; i<3; i++) 
                                                                             {
-                                                                                printf("%f\t",moment_comm[i]);
+                                                                                gpc.printf("%f\t",moment_comm[i]);
                                                                             }
                                                                                 
                                                                     }
-                                                                else if(ACS_STATE == 8)                     // Auto Control
+                                                                else if(ACS_STATE == 3)                     // Auto Control
                                                                     {
-                                                                        printf("\n\r Auto control mode \n");            
+                                                                        gpc.printf("\n\r Auto control mode \n");            
                                                                         FCTN_ACS_CNTRLALGO(moment_comm,mag_data_comm,gyro_data_comm,0x00,0x00,ACS_DETUMBLING_ALGO_TYPE);
-                                                                        printf("\n\r Moment values returned by control algo \n");
+                                                                        gpc.printf("\n\r Moment values returned by control algo \n");
                                                                         for(int i=0; i<3; i++) 
                                                                             {
-                                                                                printf("%f\t",moment_comm[i]);
+                                                                                gpc.printf("%f\t",moment_comm[i]);
                                                                             }
                                                                     }
-                                                                else if(ACS_STATE == 9)                     // Detumbling
+                                                                else if(ACS_STATE == 4)                     // Detumbling
                                                                     {
                                                                         FCTN_ACS_CNTRLALGO(moment_comm,mag_data_comm,gyro_data_comm,0x00,0x01,ACS_DETUMBLING_ALGO_TYPE);
-                                                                        printf("\n\r Moment values returned by control algo \n");
+                                                                        gpc.printf("\n\r Moment values returned by control algo \n");
                                                                         for(int i=0; i<3; i++) 
                                                                             {
-                                                                                printf("%f\t",moment_comm[i]);
+                                                                                gpc.printf("%f\t",moment_comm[i]);
                                                                             }
                                                                     }
                                                                 else
@@ -849,6 +870,9 @@
                                         
                                                                 // Control algo commissioning
                                                                 uint16_t moment_ret;
+                                                                telemetry[0] = 0x78;
+                                                                telemetry[1] = tc[0];
+                                                                telemetry[2] = ACK_CODE;
                                                                 telemetry[3] = 0x00;
                                                                 telemetry[4] = ACS_STATUS;
                                                                 moment_ret = float_to_uint16(-2.2,2.2,moment_comm[0]);
@@ -870,13 +894,13 @@
                                                                         telemetry[i]=0x00;
                                                                     }
                                                                 crc16 = CRC::crc16_gen(telemetry,132);
-                                                                telemetry[133] = (uint8_t)((crc16&0xFF00)>>8);
-                                                                telemetry[134] = (uint8_t)(crc16&0x00FF);
+                                                                telemetry[132] = (uint8_t)((crc16&0xFF00)>>8);
+                                                                telemetry[133] = (uint8_t)(crc16&0x00FF);
                                                                 break;
                                                             }
                                                     case 0xE1:
                                                             {
-                                                                printf("HARDWARE_COMSN\r\n");
+                                                                gpc.printf("HARDWARE_COMSN\r\n");
                                                                 //ACK_L234_telemetry
                                                                 uint8_t SENSOR_NO;
                                                                 
@@ -894,7 +918,7 @@
                                                                 
                                                                 DRV_Z_EN = 1;
                                                                 DRV_XY_EN = 1;  
-                                                                telemetry[0]=0xB0;
+                                                                telemetry[0]=0x78;
                                                                 telemetry[1]=tc[0];
                                                                 telemetry[2]=ACK_CODE;
                                                                 telemetry[3] = 0x00;
@@ -1239,7 +1263,7 @@
                                     
                                                                 // to include commission TR as well
                                                                 
-                                                                telemetry[58] = SENSOR_NO;
+                                                                telemetry[59] = SENSOR_NO;
                                                                 
                                                                 for(uint8_t i=60;i<132;i++)
                                                                     {
@@ -1247,8 +1271,8 @@
                                                                     }
                                     
                                                                 crc16 = CRC::crc16_gen(telemetry,132);
-                                                                telemetry[133] = (uint8_t)((crc16&0xFF00)>>8);
-                                                                telemetry[134] = (uint8_t)(crc16&0x00FF);
+                                                                telemetry[132] = (uint8_t)((crc16&0xFF00)>>8);
+                                                                telemetry[133] = (uint8_t)(crc16&0x00FF);
                                                                 break;
                                                             }
                                                     case 0xE2:
@@ -1347,13 +1371,13 @@
                                                     case 0x01:
                                                             {   if(BAE_STANDBY==0x07)
                                                                     {
-                                                                        printf("\n\rRun P_EPS_INIT");
+                                                                        gpc.printf("\n\rRun P_EPS_INIT");
                                                                         FCTN_EPS_INIT();
                                                                         telemetry[2]=ACK_CODE;
                                                                     }
                                                                 else
                                                                     {
-                                                                        printf("\n\runable to Run P_EPS_INIT as BAE_STATUS not 111 ");;
+                                                                        gpc.printf("\n\runable to Run P_EPS_INIT as BAE_STATUS not 111 ");;
                                                                         telemetry[2]=0x87;
                                                                     }
                                                                     
@@ -1379,13 +1403,13 @@
                                                             {
                                                                 if(BAE_STANDBY==0x07)
                                                                     {
-                                                                        printf("\n\rRun P_EPS_MAIN");
+                                                                        gpc.printf("\n\rRun P_EPS_MAIN");
                                                                         F_EPS();
                                                                         telemetry[2]=ACK_CODE;
                                                                     }
                                                                 else
                                                                     {
-                                                                        printf("\n\runable to Run P_EPS_MAIN as BAE_STATUS not 111 ");;
+                                                                        gpc.printf("\n\runable to Run P_EPS_MAIN as BAE_STATUS not 111 ");;
                                                                         telemetry[2]=0x87;
                                                                     }
                                                                     
@@ -1410,13 +1434,13 @@
                                                             {
                                                                 if(BAE_STANDBY==0x07)
                                                                     {
-                                                                        printf("\n\rRun P_ACS_INIT");
+                                                                        gpc.printf("\n\rRun P_ACS_INIT");
                                                                         FCTN_ACS_INIT();
                                                                         telemetry[2]=ACK_CODE;
                                                                     }
                                                                 else
                                                                     {
-                                                                        printf("\n\runable to Run P_ACS_INIT as BAE_STATUS not 111 ");;
+                                                                        gpc.printf("\n\runable to Run P_ACS_INIT as BAE_STATUS not 111 ");;
                                                                         telemetry[2]=0x87;
                                                                     }
                                                                     
@@ -1441,13 +1465,13 @@
                                                             {
                                                                 if(BAE_STANDBY==0x07)
                                                                     {
-                                                                        printf("\n\rRun P_ACS_MAIN");
+                                                                        gpc.printf("\n\rRun P_ACS_MAIN");
                                                                         F_ACS();
                                                                         telemetry[2]=ACK_CODE;
                                                                     }
                                                                 else
                                                                     {
-                                                                        printf("\n\runable to Run P_ACS_MAIN as BAE_STATUS not 111 ");;
+                                                                        gpc.printf("\n\runable to Run P_ACS_MAIN as BAE_STATUS not 111 ");;
                                                                         telemetry[2]=0x87;
                                                                     }
                                                                            
@@ -1473,13 +1497,13 @@
                                                             {
                                                                 if(BAE_STANDBY==0x07)
                                                                     {
-                                                                        printf("\n\rRun P_BCN_INIT");
+                                                                        gpc.printf("\n\rRun P_BCN_INIT");
                                                                         F_BCN();
                                                                         telemetry[2]=ACK_CODE;
                                                                     }
                                                                 else
                                                                     {
-                                                                        printf("\n\runable to Run P_BCN_INIT as BAE_STATUS not 111 ");;
+                                                                        gpc.printf("\n\runable to Run P_BCN_INIT as BAE_STATUS not 111 ");;
                                                                         telemetry[2]=0x87;
                                                                     }
                                                                     
@@ -1504,13 +1528,13 @@
                                                             {
                                                                 if(BAE_STANDBY==0x07)
                                                                     {
-                                                                        printf("\n\rRun P_BCN_TX_MAIN");
+                                                                        gpc.printf("\n\rRun P_BCN_TX_MAIN");
                                                                         FCTN_BCN_TX_MAIN();//correct function check once
                                                                         telemetry[2]=ACK_CODE;
                                                                     }
                                                                 else
                                                                     {
-                                                                        printf("\n\runable to Run P_BCN_TX_MAIN as BAE_STATUS not 111 ");;
+                                                                        gpc.printf("\n\runable to Run P_BCN_TX_MAIN as BAE_STATUS not 111 ");;
                                                                         telemetry[2]=0x87;
                                                                     }
                                                                 
@@ -1533,7 +1557,7 @@
                                                             }
                                                     case 0x11:
                                                             {
-                                                                printf("\n\rSW_ON_ACS_ATS1_SW_ENABLE");
+                                                                gpc.printf("\n\rSW_ON_ACS_ATS1_SW_ENABLE");
                                                                 //ACK_L234_TM
                                                                 telemetry[0]=0xB0;
                                                                 telemetry[1]=tc[0];
@@ -1563,7 +1587,7 @@
                                                             }
                                                     case 0x12:
                                                             {
-                                                                printf("\n\rSW_ON_ACS_ATS2_SW_ENABLE");
+                                                                gpc.printf("\n\rSW_ON_ACS_ATS2_SW_ENABLE");
                                                                 //ACK_L234_TM
                                                                 telemetry[0]=0xB0;
                                                                 telemetry[1]=tc[0];
@@ -1587,11 +1611,11 @@
                                                             }
                                                     case 0x13:
                                                             {
-                                                                printf("\n\rSW_ON_ACS_TR_XY_ENABLE");
+                                                                gpc.printf("\n\rSW_ON_ACS_TR_XY_ENABLE");
                                                                 //ACK_L234_TM
                                                                 telemetry[0]=0xB0;
                                                                 telemetry[1]=tc[0];
-                                                                TRXY_SW = 1;//1 SWITCH enable here
+                                                                DRV_XY_EN = 1;//1 SWITCH enable here
                                                                 ACS_TR_XY_SW_STATUS=0x01;
                                                                 telemetry[2]=ACK_CODE;
                                                                 for(uint8_t i=3;i<11;i++)
@@ -1609,11 +1633,11 @@
                                                             }
                                                     case 0x14:
                                                             {
-                                                                printf("\n\rSW_ON_ACS_TR_Z_ENABLE");
+                                                                gpc.printf("\n\rSW_ON_ACS_TR_Z_ENABLE");
                                                                 //ACK_L234_TM
                                                                 telemetry[0]=0xB0;
                                                                 telemetry[1]=tc[0];
-                                                                TRZ_SW = 1;
+                                                                DRV_Z_EN = 1;
                                                                 ACS_TR_Z_SW_STATUS=0x01;
                                                                 telemetry[2]=ACK_CODE;
                                                                 for(uint8_t i=3;i<11;i++)
@@ -1631,7 +1655,7 @@
                                                             }
                                                     case 0x15:
                                                             {
-                                                                printf("\n\rSW_ON_BCN_TX_SW_ENABLE");
+                                                                gpc.printf("\n\rSW_ON_BCN_TX_SW_ENABLE");
                                                                 //ACK_L234_TM
                                                                 telemetry[0]=0xB0;
                                                                 telemetry[1]=tc[0];
@@ -1653,13 +1677,19 @@
                                                             }
                                                     case 0x21:
                                                             {
-                                                                printf("\n\rSW_OFF_ACS_ATS1_SW_ENABLE");
+                                                                gpc.printf("\n\rSW_OFF_ACS_ATS1_SW_ENABLE");
                                                                 //ACK_L234_TM
                                                                 telemetry[0]=0xB0;
                                                                 telemetry[1]=tc[0];
                                                                 ATS1_SW_ENABLE = 1;
                                                                 ACS_ATS_STATUS = (ACS_ATS_STATUS & 0x3F) | 0xC0 ;
                                                                 telemetry[2]=ACK_CODE;
+                                                                
+                                                                uint32_t FLASH_DATA;
+                                                                FLASH_DATA = FCTN_BAE_RD_FLASH_ENTITY(0);
+                                                                FLASH_DATA = (FLASH_DATA | 0xC0000000);
+                                                                FCTN_BAE_WR_FLASH(0,FLASH_DATA);
+                                                                
                                                                 for(uint8_t i=3;i<11;i++)
                                                                     {
                                                                         telemetry[i]=0x00;
@@ -1675,11 +1705,17 @@
                                                             }
                                                     case 0x22:
                                                             {
-                                                                printf("\n\rSW_OFF_ACS_ATS2_SW_ENABLE");
+                                                                gpc.printf("\n\rSW_OFF_ACS_ATS2_SW_ENABLE");
                                                                 //ACK_L234_TM
                                                                 telemetry[0]=0xB0;
                                                                 telemetry[1]=tc[0];
                                                                 ATS2_SW_ENABLE = 1;
+                                                                
+                                                                uint32_t FLASH_DATA;
+                                                                FLASH_DATA = FCTN_BAE_RD_FLASH_ENTITY(0);
+                                                                FLASH_DATA = (FLASH_DATA | 0x0C000000);
+                                                                FCTN_BAE_WR_FLASH(0,FLASH_DATA);
+                                                                
                                                                 ACS_ATS_STATUS = (ACS_ATS_STATUS & 0xF3) | 0x0C ;
                                                                 telemetry[2]=ACK_CODE;
                                                                 for(uint8_t i=3;i<11;i++)
@@ -1697,7 +1733,7 @@
                                                             }
                                                     case 0x23:
                                                             {
-                                                                printf("\n\rSW_OFF_ACS_TR_XY_ENABLE");
+                                                                gpc.printf("\n\rSW_OFF_ACS_TR_XY_ENABLE");
                                                                 //ACK_L234_TM
                                                                 telemetry[0]=0xB0;
                                                                 telemetry[1]=tc[0];
@@ -1719,7 +1755,7 @@
                                                             }
                                                     case 0x24:
                                                             {
-                                                                printf("\n\rSW_OFF_ACS_TR_Z_ENABLE");
+                                                                gpc.printf("\n\rSW_OFF_ACS_TR_Z_ENABLE");
                                                                 //ACK_L234_TM
                                                                 telemetry[0]=0xB0;
                                                                 telemetry[1]=tc[0];
@@ -1741,7 +1777,7 @@
                                                             }
                                                     case 0x25:
                                                             {
-                                                                printf("\n\rSW_OFF_BCN_TX_SW_ENABLE");
+                                                                gpc.printf("\n\rSW_OFF_BCN_TX_SW_ENABLE");
                                                                 //ACK_L234_TM
                                                                 telemetry[0]=0xB0;
                                                                 telemetry[1]=tc[0];
@@ -1763,7 +1799,7 @@
                                                             }
                                                     case 0x31:
                                                             {
-                                                                printf("\n\rACS_ATS1_SW_RESET");
+                                                                gpc.printf("\n\rACS_ATS1_SW_RESET");
                                                                 //ACK_L234_TM
                                                                 telemetry[0]=0xB0;
                                                                 telemetry[1]=tc[0];
@@ -1787,7 +1823,7 @@
                                                             }
                                                     case 0x32:
                                                             {
-                                                                printf("\n\rACS_ATS2_SW_RESET");
+                                                                gpc.printf("\n\rACS_ATS2_SW_RESET");
                                                                 //ACK_L234_TM
                                                                 telemetry[0]=0xB0;
                                                                 telemetry[1]=tc[0];
@@ -1811,7 +1847,7 @@
                                                             }
                                                     case 0x33:
                                                             {
-                                                                printf("\n\rACS_TR_XY_SW_RESET");
+                                                                gpc.printf("\n\rACS_TR_XY_SW_RESET");
                                                                 //ACK_L234_TM
                                                                 telemetry[0]=0xB0;
                                                                 telemetry[1]=tc[0];
@@ -1834,7 +1870,7 @@
                                                             }
                                                     case 0x34:
                                                             {
-                                                                printf("\n\rACS_TR_Z_SW_RESET");
+                                                                gpc.printf("\n\rACS_TR_Z_SW_RESET");
                                                                 //ACK_L234_TM
                                                                 telemetry[0]=0xB0;
                                                                 telemetry[1]=tc[0];
@@ -1857,7 +1893,7 @@
                                                             }
                                                     case 0x35:
                                                             {
-                                                                printf("\n\rBCN_TX_SW_RESET");
+                                                                gpc.printf("\n\rBCN_TX_SW_RESET");
                                                                 //ACK_L234_TM
                                                                 telemetry[0]=0xB0;
                                                                 telemetry[1]=tc[0];
@@ -1880,13 +1916,13 @@
                                                             }
                                                     case 0x36:
                                                             {
-                                                                printf("\n\rBAE_INTERNAL_RESET TO be done ??");
+                                                                gpc.printf("\n\rBAE_INTERNAL_RESET TO be done ");
                                                                 NVIC_SystemReset();
                                                                 break;
                                                             }
                                                     case 0x37:
                                                             {
-                                                                printf("\n\rCDMS_RESET");
+                                                                gpc.printf("\n\rCDMS_RESET");
                                                                 //ACK_L234_TM
                                                                 telemetry[0]=0xB0;
                                                                 telemetry[1]=tc[0];
@@ -1907,9 +1943,9 @@
                                                                     }
                                                                 break;
                                                             }
-                                                    case 0x38:
+                                                    case 0x38://not in IF present in SBC
                                                             {
-                                                                printf("\n\rCDMS_SW_RESET pin yet to be decided");
+                                                                gpc.printf("\n\rCDMS_SW_RESET pin yet to be decided");
                                                                 //ACK_L234_TM
                                                                 telemetry[0]=0xB0;
                                                                 telemetry[1]=tc[0];
@@ -1930,26 +1966,26 @@
                                                                     }
                                                                 break;
                                                             }
-                                                    case 0x40:
+                                                    case 0x40://condition changed by AK47 now 00 means off in TC
                                                             {
                                                                 uint8_t STANDBY_DATA_TC;
                                                                 BAE_STANDBY=0x00;
                                                                 STANDBY_DATA_TC=tc[4];
-                                                                if(STANDBY_DATA_TC==0x01)
+                                                                if(STANDBY_DATA_TC==0x00)
                                                                     {
                                                                         BAE_STANDBY |=0x04;
                                                                         BAE_STANDBY_TIMER_RESET();
                                                                         //BAE_STANDBY_TIMER();//to be created to make all sensor on after 20 minutes
                                                                     }
                                                                 STANDBY_DATA_TC=tc[5];
-                                                                if(STANDBY_DATA_TC==0x01)
+                                                                if(STANDBY_DATA_TC==0x00)
                                                                     {
                                                                         BAE_STANDBY |=0x02;
                                                                         BAE_STANDBY_TIMER_RESET();
                                                                         //BAE_STANDBY_TIMER();//to be created to make all sensor on after 20 minutes
                                                                     }
                                                                 STANDBY_DATA_TC=tc[6];
-                                                                if(STANDBY_DATA_TC==0x01)
+                                                                if(STANDBY_DATA_TC==0x00)
                                                                     {
                                                                         BAE_STANDBY |=0x01;
                                                                         BAE_STANDBY_TIMER_RESET();
@@ -1973,13 +2009,10 @@
                                                             }
                                                 case 0x41:
                                                         {
-                                                            printf("\n\rexecutng BAE reset HK counter");
+                                                            gpc.printf("\n\rexecutng BAE reset HK counter");
                                                             firstCount=true;
                                                             void minMaxHkData();
-                                                            
-                                                            //what to do here??*************************************************
-                                                            //TO BE DONE
-                                                            
+                    
                                                             //ACK_L234_TM
                                                             telemetry[0]=0xB0;
                                                             telemetry[1]=tc[0];
@@ -1999,7 +2032,7 @@
                                                         }
                                                     default:
                                                             {
-                                                                printf("\n\rInvalid TC for FMS no matching FID");
+                                                                gpc.printf("\n\rInvalid TC for FMS no matching FID");
                                                                 //ACK_L234_TM
                                                                 telemetry[0]=0xB0;
                                                                 telemetry[1]=tc[0];
@@ -2022,7 +2055,7 @@
                                             }
                                     default:
                                             {
-                                                printf("\n\rInvalid TC, FMS service subtype mismacth");
+                                                gpc.printf("\n\rInvalid TC, FMS service subtype mismacth");
                                                 //ACK_L234_TM
                                                 telemetry[0]=0xB0;
                                                 telemetry[1]=tc[0];
@@ -2045,7 +2078,7 @@
                             }
                     default:
                             {
-                                printf("\n\rInvalid TC neither FMS nor MMS");
+                                gpc.printf("\n\rInvalid TC neither FMS nor MMS");
                                 //ACK_L234_TM
                                 telemetry[0]=0xB0;
                                 telemetry[1]=tc[0];
@@ -2120,7 +2153,7 @@
 
     //float* output1 = reinterpret_cast<float*>(temp);
 
-    //printf("\n\r %f  ", input);
+    //gpc.printf("\n\r %f  ", input);
     //std::cout << "\n\r uint32"<<*temp << std::endl;
 
     output[0] =(uint8_t )(((*temp)>>24)&0xFF);
@@ -2128,13 +2161,13 @@
     output[2] =(uint8_t ) (((*temp)>>8)&0xFF); 
     output[3] =(uint8_t ) ((*temp) & 0xFF);           // verify the logic 
     
- //   printf("\n\rthe values generated are\n");
-     /*printf("\n\r%x\n",output[0]);
-     printf("\n\r%x\n",output[1]);
-     printf("\n\r%x\n",output[2]);
-     printf("\n\r%x\n",output[3]);
+ //   gpc.printf("\n\rthe values generated are\n");
+     /*gpc.printf("\n\r%x\n",output[0]);
+     gpc.printf("\n\r%x\n",output[1]);
+     gpc.printf("\n\r%x\n",output[2]);
+     gpc.printf("\n\r%x\n",output[3]);
      to check the values generated
      */
-    //printf("\n\r inside %d %d %d %d", output[3],output[2],output[1],output[0]);
+    //gpc.printf("\n\r inside %d %d %d %d", output[3],output[2],output[1],output[0]);
     //std:: cout << "\n\r uint8  inside " << output[3] << '\t' << output[2] << '\t' << output[1] << '\t' << output[0] <<std::endl;
 }
\ No newline at end of file