FINAL ACS TO BE USED FOR TESTING. COMMISSIONING, ACS MAIN, DATA ACQ ALL DONE.
Dependencies: FreescaleIAP mbed-rtos mbed
Fork of ACS_FULL_Flowchart_BAE by
Diff: main.cpp
- Revision:
- 3:07e15677a75c
- Parent:
- 1:446a959e36ce
- Child:
- 4:39a4ae8c7ecd
--- a/main.cpp Fri Dec 25 15:25:44 2015 +0000 +++ b/main.cpp Tue Dec 29 05:14:39 2015 +0000 @@ -59,7 +59,7 @@ bool write_ack = 1; bool read_ack = 1; char telecommand[tc_len]; -char telemetry[tm_len]; +char* telemetry; char data_send_flag = 'h'; //*****************************************************Assigning pins******************************************************// @@ -77,19 +77,20 @@ /*****************************************************************Threads USed***********************************************************************************/ -Thread *ptr_t_acs; -Thread *ptr_t_eps; -Thread *ptr_t_bcn; + Thread *ptr_t_i2c; /*********************************************************FCTN HEADERS***********************************************************************************/ void FCTN_ISR_I2C(); void FCTN_TM(); +void F_ACS(); +void F_EPS(); +void F_BCN(); //*******************************************ACS THREAD**************************************************// -void T_ACS(void const *args) +void F_ACS() { float b1[3]={-23.376,-37.56,14.739}, omega1[3]={-1.52,2.746,0.7629}, moment1[3]= {1.0498,-1.0535,1.3246}; //b1[3] = {22, 22,10}; @@ -97,10 +98,9 @@ // gpo1 = 0; // att sens2 switch is disabled // gpo2 = 0; // att sens switch is disabled - while(1) - { + - Thread::signal_wait(0x1); + //Thread::signal_wait(0x1); ACS_MAIN_STATUS = 's'; //set ACS_MAIN_STATUS flag PWM1 = 0; //clear pwm pins PWM2 = 0; //clear pwm pins @@ -231,21 +231,34 @@ ACS_MAIN_STATUS = 'c'; //clear ACS_MAIN_STATUS flag - }//while ends - - + } //***************************************************EPS THREAD***********************************************// -void T_EPS(void const *args) +void F_EPS() { - while(1) - { - Thread::signal_wait(0x2); + pc.printf("\n\rEntered EPS %f\n",t_start.read()); EPS_MAIN_STATUS = 's'; // Set EPS main status - //FCTN_READ_HK(); - //FCTN_APPEND_HKDATA(); + FCTN_BATT_TEMP_SENSOR_MAIN(actual_data.Batt_temp_actual); + pc.printf("\n\r Battery temperature %f %f" ,actual_data.Batt_temp_actual[0], actual_data.Batt_temp_actual[1]); + EPS_BATTERY_TEMP_STATUS = 's'; //set EPS_BATTERY_TEMP_STATUS + if(EPS_BATTERY_HEAT_ENABLE == 'e') + { + if((actual_data.Batt_temp_actual[0] < batt_heat_low) & (actual_data.Batt_temp_actual[1] < batt_heat_low)) // to confirm + { + batt_heat = 1; //turn on battery heater + } + else + { + batt_heat = 0; //turn off battery heater + } + + } + else if(EPS_BATTERY_HEAT_ENABLE == 'd') + { + EPS_STATUS = 1;//EPS_STATUS = EPS_BATTERY_HEATER_DISABLED + } FCTN_BATTERYGAUGE_MAIN(actual_data.Batt_gauge_actual); if (actual_data.Batt_gauge_actual[1] == 200) //data not received { @@ -258,52 +271,33 @@ FCTN_EPS_POWERMODE(actual_data.Batt_gauge_actual[1]); //updating power level EPS_BATTERY_GAUGE_STATUS = 's'; //set EPS_BATTERY_GAUGE_STATUS } - /* if( Temperature data received) - { - FCTN_BATT_TEMP_SENSOR_MAIN(); - EPS_BATTERY_TEMP_STATUS = 's'; //set EPS_BATTERY_TEMP_STATUS - if(EPS_BATTERY_HEAT_ENABLE = 'e') - { - if(actual_data.Batt_temp_actual[0] < batt_heat_low) - { - batt_heat = 1; //turn on battery heater - } - else - { - batt_heat = 0; //turn off battery heater - } - - } - else if(EPS_BATTERY_HEAT_ENABLE = 'd) - { - EPS_STATUS = EPS_BATTERY_HEATER_DISABLED; - } + // if( Temperature data received) + //{ + - } - else - { - Set battery temp to XX - EPS_BATTERY_TEMP_STATUS = 'c'; //clear EPS_BATTERY_TEMP_STATUS - EPS_STATUS = EPS_ERR_BATTERY_TEMP; - } + // } +// else +// { +// Set battery temp to XX +// EPS_BATTERY_TEMP_STATUS = 'c'; //clear EPS_BATTERY_TEMP_STATUS +// EPS_STATUS = EPS_ERR_BATTERY_TEMP; +// } + FCTN_HK_MAIN(); + //FCTN_APPEND_HKDATA(); + //minMaxHkData(); - EPS_MAIN_STATUS = 'c'; // clear EPS main status */ - - } - + EPS_MAIN_STATUS = 'c'; // clear EPS main status + } //**************************************************BCN THREAD*******************************************************************// -void T_BCN(void const *args) +void F_BCN() { - while(1) - { - Thread::signal_wait(0x3); + pc.printf("\n\rEntered BCN %f\n",t_start.read()); P_BCN_TX_MAIN(); - } } @@ -319,15 +313,19 @@ slave.stop(); else if( slave.receive() == 1) // slave writes to master { - write_ack=slave.write(telemetry,tm_len); + write_ack=slave.write((char*)telemetry,tm_len); } else if( slave.receive()==3 || slave.receive()==2) // slave read { read_ack=slave.read(telecommand,tc_len); pc.printf("\n\rTELECOMMAND received from CDMS is %s \n",telecommand); pc.printf("\n\r Executing Telecommand \n"); - FCTN_TC_DECODE((uint8_t*) telecommand); + // FCTN_TC_DECODE((uint8_t*) telecommand); + uint8_t* temp = FCTN_BAE_TM_TC((uint8_t*) telecommand); + telemetry = (char*)temp; FCTN_TM(); + // for(int i = 0; i<134; i++) + //pc.printf("%c", telemetry[i]); } } @@ -363,17 +361,16 @@ } if(schedcount%1==0) { - //ptr_t_acs -> signal_set(0x1); + F_ACS(); } if(schedcount%2==0) { - ptr_t_eps -> signal_set(0x2); - + F_EPS(); } if(schedcount%3==0) { - //ptr_t_bcn -> signal_set(0x3); + // F_BCN(); } schedcount++; printf("\n\r exited scheduler"); @@ -446,6 +443,8 @@ BAE_STATUS &= 0xFFFDFFFF; //clear EPS_BATTERY_GAUGE_STATUS else if(EPS_BATTERY_GAUGE_STATUS == 's') BAE_STATUS |= 0x00020000; //set EPS_BATTERY_GAUGE_STATUS + + pc.printf("\n\r BAE status %x BAE ENABLE %x ",BAE_STATUS,BAE_ENABLE); @@ -454,9 +453,17 @@ void FCTN_BAE_INIT() { printf("\n\r Initialising BAE "); - // FCTN_ACS_INIT(); + //..........intial status....// + ACS_STATE = '4'; + ACS_ATS_ENABLE = 'e'; + ACS_DATA_ACQ_ENABLE = 'e'; + EPS_BATTERY_HEAT_ENABLE = 'e'; + //............................// + FCTN_ACS_INIT(); FCTN_EPS_INIT(); //P_BCN_INIT(); + + FLAG(); } @@ -472,28 +479,21 @@ while(t_rfsilence.read() < RF_SILENCE_TIME); } */ - ACS_STATE = '4'; + //ACS_INIT_STATUS = 'c'; //ACS_DATA_ACQ_STATUS = 'c'; gpo1 = 0; FLAG(); FCTN_BAE_INIT(); - ACS_ATS_ENABLE = 'e'; - ACS_DATA_ACQ_ENABLE = 'e'; + //...i2c.. - strcpy(telemetry,"This is telemetry THis is sample telemetry. ffffffffffffffffffffffffffffff end"); + //strcpy(telemetry,"This is telemetry THis is sample telemetry. ffffffffffffffffffffffffffffff end"); slave.address(addr); irpt_2_mstr = 0; ptr_t_i2c = new Thread(T_TC); ptr_t_i2c->set_priority(osPriorityHigh); - ptr_t_acs = new Thread(T_ACS); - ptr_t_acs->set_priority(osPriorityAboveNormal); - ptr_t_eps = new Thread(T_EPS); - ptr_t_eps->set_priority(osPriorityAboveNormal); - ptr_t_bcn = new Thread(T_BCN); - ptr_t_bcn->set_priority(osPriorityAboveNormal); irpt_4m_mstr.enable_irq(); irpt_4m_mstr.rise(&FCTN_I2C_ISR); @@ -505,4 +505,5 @@ gpo1 = 0; // att sens2 switch is enabled //FCTN_BAE_INIT(); while(1); //required to prevent main from terminating -} \ No newline at end of file +} +