sakthi priya amirtharaj
/
BAE_vr2_1_3
i2c working with old hk
Fork of BAE_vr2_1_1 by
Diff: main.cpp
- Revision:
- 13:1b37d98840d3
- Parent:
- 12:ba2556c6b990
- Child:
- 14:ef6be8ac6569
--- a/main.cpp Tue Dec 16 11:07:33 2014 +0000 +++ b/main.cpp Wed Dec 17 05:25:04 2014 +0000 @@ -19,10 +19,10 @@ Thread *ptr_t_hk_acq; Thread *ptr_t_acs; -Thread *ptr_t_acs_write2flash; +//Thread *ptr_t_acs_write2flash; Thread *ptr_t_bea; -Thread *ptr_t_bea_telecommand; -Thread *ptr_t_fault; +//Thread *ptr_t_bea_telecommand; +//Thread *ptr_t_fault; Thread *ptr_t_i2c; @@ -40,7 +40,7 @@ typedef struct { - char data[35]; // To avoid dynamic memory allocation + char data[21]; // To avoid dynamic memory allocation int length; }i2c_data; @@ -56,22 +56,23 @@ //TASK 2 : HK //-------------------------------------------------------------------------------------------------------------------------------------------------- -char hk_data[35]; -extern SensorData Sensor; +char hk_data[21]; +extern SensorDataQuantised SensorQuantised; void t_hk_acq(void const *args) { while(1) { Thread::signal_wait(0x2); - + SensorQuantised.power_mode='0'; printf("\nTHIS IS HK %f\n",t1.read()); t.start(); - + FAULTS(); + POWER(SensorQuantised.power_mode); //The power mode algorithm is yet to be obtained FUNC_HK_MAIN(); //Collecting HK data //thread_2.signal_set(0x4); //FUNC_I2C_SLAVE_MAIN(24); - + ir2master(); t.stop(); printf("The time to execute hk_acq is %f seconds\n",t.read()); t.reset(); @@ -81,56 +82,33 @@ //--------------------------------------------------------------------------------------------------------------------------------------- //TASK 1 : ACS //--------------------------------------------------------------------------------------------------------------------------------------- -typedef struct { - float mag_field; - float omega; - } sensor_data; - -Mail <sensor_data, 16> q_acs; - -void func_acs_readdata(sensor_data *ptr) -{ - printf("Reading the data\n"); - ptr -> mag_field = 10; - ptr -> omega = 3; -} - -void func_acs_ctrlalgo() -{ - printf("Executing control algo\n"); -} - - - -void func_acs_write2flash(sensor_data *ptr2) -{ - printf("The magnetic field is %.2f T\n\r",ptr2->mag_field); - printf("The angular velocity is %.2f rad/s\n\r",ptr2->omega); -} int acs_pflag = 1; void t_acs(void const *args) { + float *mag_field; + float *omega; + float *moment; while(1) { Thread::signal_wait(0x1); printf("\nTHIS IS ACS %f\n",t1.read()); t.start(); - sensor_data *ptr = q_acs.alloc(); + mag_field= FUNC_ACS_MAG_EXEC(); //actual execution + omega = FUNC_ACS_EXEC_GYR(); - func_acs_readdata(ptr); - //printf("\ngdhd\n"); - q_acs.put(ptr); + + if(acs_pflag == 1) { - func_acs_ctrlalgo(); - FUNC_ACS_GENPWM(); //Generating PWM signal. + moment = FUNC_ACS_CNTRLALGO(mag_field,omega); + FUNC_ACS_GENPWM(moment); } t.reset(); } } - +/* void t_acs_write2flash(void const *args) { while(1) @@ -147,13 +125,13 @@ } } - +*/ //---------------------------------------------------BEACON-------------------------------------------------------------------------------------------- int beac_flag=0; //To receive telecommand from ground. -void t_bea_telecommand(void const *args) +/*void t_bea_telecommand(void const *args) { char c = pc.getc(); if(c=='a') @@ -162,6 +140,7 @@ beac_flag=1; } } +*/ void t_bea(void const *args) { @@ -225,10 +204,10 @@ } }*/ -extern SensorData Sensor; +extern SensorDataQuantised SensorQuantised; -void T_FAULT(void const *args) +/*void T_FAULT(void const *args) { Sensor.power_mode='0'; while(1) @@ -239,7 +218,7 @@ //Sensor.power_mode++; //testing ... should be removed } } - +*/ //--------------------------------------------------------------------------------------------------------------------------------------------------- //TASK 5 : i2c data //--------------------------------------------------------------------------------------------------------------------------------------------------- @@ -324,7 +303,7 @@ printf("\ndone\n\r"); } -char data_send[35],data_receive[35]; +char data_send[21],data_receive[21]; void T_I2C_BAE() { //char data_send,data_receive; @@ -337,10 +316,10 @@ if(i2c_status == 0 && reset !=1) { - FUNC_I2C_WRITE2CDMS(data_receive,35); + FUNC_I2C_WRITE2CDMS(data_receive,21); i2c_data * i2c_data_r = i2c_data_receive.alloc(); strcpy(i2c_data_r->data,data_receive); - i2c_data_r->length = 35; + i2c_data_r->length = 21; i2c_data_receive.put(i2c_data_r); printf("\n Data received from CDMS is %s \n\r",data_receive); i2c_data_receive.free(i2c_data_r); // This has to be done from a differen thread @@ -353,7 +332,7 @@ { i2c_data *i2c_data_s = (i2c_data*)evt.value.p; strcpy(data_send,i2c_data_s -> data); - FUNC_I2C_WRITE2CDMS(data_send,35); + FUNC_I2C_WRITE2CDMS(data_send,21); printf("\nData sent to CDMS is %s\n\r",data_send); i2c_data_send.free(i2c_data_s); i2c_status = 0; @@ -381,28 +360,32 @@ -char ffp[4] = {Sensor.faultpoll,Sensor.faultir, Sensor.power_mode}; +char fdata[8] = {SensorQuantised.Vcell_soc,SensorQuantised.alerts,SensorQuantised.crate,SensorQuantised.BatteryTemperature,SensorQuantised.faultpoll,SensorQuantised.faultir, SensorQuantised.power_mode}; + void ir2master() { - //char data[35]; + //char data[21]; //strcpy(data,"sakthi "); //strcat(data,"priya"); - - strcpy(hk_data,Sensor.Temperature); //Sending to CDMS via I2C - strcat(hk_data,Sensor.Current); - strcat(hk_data,Sensor.Voltage); + strcpy(hk_data,SensorQuantised.Voltage); + strcat(hk_data,SensorQuantised.Temperature); //Sending to CDMS via I2C + strcat(hk_data,SensorQuantised.Current); + strcat(hk_data,SensorQuantised.PanelTemperature); + strcat(hk_data,SensorQuantised.AngularSpeed); + strcat(hk_data,SensorQuantised.Bnewvalue); /*strcat(hk_data,sfaultpoll); strcat(hk_data,sfaultir); strcat(hk_data,spower_mode);*/ - strcat(hk_data,ffp); + strcat(hk_data,fdata); + printf("\nhk data : %s\n",hk_data); data_ready=0; //data = pcslave.getc(); reset =0; i2c_status=1; i2c_data * i2c_data_s = i2c_data_send.alloc(); strcpy(i2c_data_s->data,hk_data); - i2c_data_s->length = 35; + i2c_data_s->length = 21; i2c_data_send.put(i2c_data_s); data_ready=1; //temp = i2c_status; @@ -439,7 +422,7 @@ } if(schedcount%2==0) { - ptr_t_fault -> signal_set(0x2); + //ptr_t_fault -> signal_set(0x2); ptr_t_hk_acq -> signal_set(0x2); } @@ -462,30 +445,30 @@ ptr_t_hk_acq = new Thread(t_hk_acq); ptr_t_acs = new Thread(t_acs); - ptr_t_acs_write2flash = new Thread(t_acs_write2flash); + //ptr_t_acs_write2flash = new Thread(t_acs_write2flash); ptr_t_bea = new Thread(t_bea); - ptr_t_bea_telecommand = new Thread(t_bea_telecommand); - ptr_t_fault = new Thread(T_FAULT); + //ptr_t_bea_telecommand = new Thread(t_bea_telecommand); + //ptr_t_fault = new Thread(T_FAULT); ptr_t_i2c = new Thread(C_T_I2C_BAE); //ptr_t_sc = new Thread(t_sc); interrupt_fault(); - ptr_t_fault -> set_priority(osPriorityRealtime); + //ptr_t_fault -> set_priority(osPriorityRealtime); ptr_t_acs->set_priority(osPriorityHigh); ptr_t_i2c->set_priority(osPriorityAboveNormal); ptr_t_hk_acq->set_priority(osPriorityNormal); - ptr_t_acs_write2flash->set_priority(osPriorityBelowNormal); + //ptr_t_acs_write2flash->set_priority(osPriorityBelowNormal); ptr_t_bea->set_priority(osPriorityAboveNormal); - ptr_t_bea_telecommand->set_priority(osPriorityIdle); + //ptr_t_bea_telecommand->set_priority(osPriorityIdle); //ptr_t_sc->set_priority(osPriorityAboveNormal); // ---------------------------------------------------------------------------------------------- - printf("\n T_FAULT priority is %d",ptr_t_fault->get_priority()); + //printf("\n T_FAULT priority is %d",ptr_t_fault->get_priority()); printf("\n T_ACS priority is %d",ptr_t_acs->get_priority()); printf("\n T_HK_ACQ priority is %d",ptr_t_hk_acq->get_priority()); - printf("\n T_ACS_WRITE2FLASH priority is %d",ptr_t_acs_write2flash->get_priority()); + //printf("\n T_ACS_WRITE2FLASH priority is %d",ptr_t_acs_write2flash->get_priority()); printf("\n T_BEA priority is %d",ptr_t_bea->get_priority()); RtosTimer t_sc_timer(t_sc,osTimerPeriodic); t_sc_timer.start(10000); @@ -499,7 +482,7 @@ while(1) { //Thread::wait(10000); - ir2master(); + //ir2master(); Thread::wait(5000); }