Lab4-03_create_satcode_step5_lite

Dependencies:   mbed HEPTA_CDH_lite HEPTA_SENSOR_lite HEPTA_EPS_lite

Committer:
heptasat2021
Date:
Fri Aug 20 12:34:39 2021 +0000
Revision:
2:197079c5867f
Parent:
1:ddac5ec89167
Child:
3:41cb41ed1fa3
For Hepta-Sat Lite

Who changed what in which revision?

UserRevisionLine numberNew contents of line
heptasat2021 0:da0f6aca15b8 1 #include "mbed.h"
heptasat2021 2:197079c5867f 2 #include "HEPTA_EPS.h"
heptasat2021 1:ddac5ec89167 3 #include "HEPTA_CDH.h"
heptasat2021 2:197079c5867f 4 #include "HEPTA_SENSOR.h"
heptasat2021 1:ddac5ec89167 5 HEPTA_CDH cdh(PB_5, PB_4, PB_3, PA_8, "sd");
heptasat2021 2:197079c5867f 6 HEPTA_EPS eps(PA_0,PA_4);
heptasat2021 2:197079c5867f 7 HEPTA_SENSOR sensor(PA_7,PB_7,PB_6,0xD0);
heptasat2021 2:197079c5867f 8 DigitalOut condition(PB_1);
heptasat2021 2:197079c5867f 9 Serial gs(USBTX,USBRX,9600);
heptasat2021 2:197079c5867f 10 Timer sattime;
heptasat2021 2:197079c5867f 11 int rcmd = 0, cmdflag = 0; //command variable
heptasat2021 2:197079c5867f 12
heptasat2021 2:197079c5867f 13 //getting command and command flag
heptasat2021 2:197079c5867f 14 void commandget()
heptasat2021 2:197079c5867f 15 {
heptasat2021 2:197079c5867f 16 rcmd = gs.getc();
heptasat2021 2:197079c5867f 17 cmdflag = 1;
heptasat2021 2:197079c5867f 18 }
heptasat2021 2:197079c5867f 19 //interrupting process by command receive
heptasat2021 2:197079c5867f 20 void receive(int rcmd, int cmdflag)
heptasat2021 2:197079c5867f 21 {
heptasat2021 2:197079c5867f 22 gs.attach(commandget,Serial::RxIrq);
heptasat2021 2:197079c5867f 23 }
heptasat2021 2:197079c5867f 24 //initializing
heptasat2021 2:197079c5867f 25 void initialize()
heptasat2021 2:197079c5867f 26 {
heptasat2021 2:197079c5867f 27 rcmd = 0;
heptasat2021 2:197079c5867f 28 cmdflag = 0;
heptasat2021 2:197079c5867f 29 condition = 0;
heptasat2021 2:197079c5867f 30 }
heptasat2021 2:197079c5867f 31
heptasat2021 0:da0f6aca15b8 32 int main()
heptasat2021 0:da0f6aca15b8 33 {
heptasat2021 2:197079c5867f 34 gs.printf("From Sat : Nominal Operation\r\n");
heptasat2021 2:197079c5867f 35 int flag = 0; //condition flag
heptasat2021 2:197079c5867f 36 float batvol, temp; //voltage, temperature
heptasat2021 2:197079c5867f 37 sattime.start();
heptasat2021 2:197079c5867f 38 receive(rcmd,cmdflag); //interrupting
heptasat2021 2:197079c5867f 39 eps.turn_on_regulator();//turn on 3.3V conveter
heptasat2021 2:197079c5867f 40 for(int i=0;i<50;i++){
heptasat2021 2:197079c5867f 41 //satellite condition led
heptasat2021 2:197079c5867f 42 condition = !condition;
heptasat2021 2:197079c5867f 43
heptasat2021 2:197079c5867f 44 //senssing HK data
heptasat2021 2:197079c5867f 45 eps.vol(&batvol);
heptasat2021 2:197079c5867f 46 sensor.temp_sense(&temp);
heptasat2021 2:197079c5867f 47
heptasat2021 2:197079c5867f 48 //Transmitting HK data to Ground Station(GS)
heptasat2021 2:197079c5867f 49 gs.printf("HEPTASAT::Condition = %d, Time = %f [s], batvol = %2f [V], temp = %2f [deg C]\r\n",flag,sattime.read(),batvol,temp);
heptasat2021 2:197079c5867f 50 wait_ms(1000);
heptasat2021 2:197079c5867f 51
heptasat2021 2:197079c5867f 52 //Power Saving Mode
heptasat2021 2:197079c5867f 53 if((batvol <= 3.5) | (temp > 35.0)){
heptasat2021 2:197079c5867f 54 eps.shut_down_regulator();
heptasat2021 2:197079c5867f 55 gs.printf("Power saving mode ON\r\n");
heptasat2021 2:197079c5867f 56 flag = 1;
heptasat2021 2:197079c5867f 57 } else if((flag == 1) & (batvol > 3.7) & (temp <= 25.0)) {
heptasat2021 2:197079c5867f 58 eps.turn_on_regulator();
heptasat2021 2:197079c5867f 59 gs.printf("Power saving mode OFF\r\n");
heptasat2021 2:197079c5867f 60 flag = 0;
heptasat2021 2:197079c5867f 61 }
heptasat2021 2:197079c5867f 62
heptasat2021 2:197079c5867f 63 if(cmdflag == 1){
heptasat2021 2:197079c5867f 64 if(rcmd == 'a'){
heptasat2021 2:197079c5867f 65 for(int j=0;j<5;j++){
heptasat2021 2:197079c5867f 66 gs.printf("Hello World!\r\n");
heptasat2021 2:197079c5867f 67 condition = 1;
heptasat2021 2:197079c5867f 68 wait_ms(1000);
heptasat2021 2:197079c5867f 69 }
heptasat2021 2:197079c5867f 70 }else if(rcmd == 'b') {
heptasat2021 2:197079c5867f 71 char str[100];
heptasat2021 2:197079c5867f 72 mkdir("/sd/mydir", 0777);
heptasat2021 2:197079c5867f 73 FILE *fp = fopen("/sd/mydir/satdata.txt","w");
heptasat2021 2:197079c5867f 74 if(fp == NULL) {
heptasat2021 2:197079c5867f 75 error("Could not open file for write\r\n");
heptasat2021 2:197079c5867f 76 }
heptasat2021 2:197079c5867f 77 for(int i = 0; i < 10; i++) {
heptasat2021 2:197079c5867f 78 eps.vol(&batvol);
heptasat2021 2:197079c5867f 79 fprintf(fp,"%f\r\n",batvol);
heptasat2021 2:197079c5867f 80 condition = 1;
heptasat2021 2:197079c5867f 81 wait_ms(1000);
heptasat2021 2:197079c5867f 82 }
heptasat2021 2:197079c5867f 83 fclose(fp);
heptasat2021 2:197079c5867f 84 fp = fopen("/sd/mydir/satdata.txt","r");
heptasat2021 2:197079c5867f 85 for(int i = 0; i < 10; i++) {
heptasat2021 2:197079c5867f 86 fgets(str,100,fp);
heptasat2021 2:197079c5867f 87 gs.puts(str);
heptasat2021 2:197079c5867f 88 }
heptasat2021 2:197079c5867f 89 fclose(fp);
heptasat2021 2:197079c5867f 90 }else if(rcmd == 'c'){
heptasat2021 2:197079c5867f 91 float ax,ay,az;
heptasat2021 2:197079c5867f 92 for(int i = 0; i < 10; i++) {
heptasat2021 2:197079c5867f 93 sensor.sen_acc(&ax,&ay,&az);
heptasat2021 2:197079c5867f 94 gs.printf("%f,%f,%f\r\n",ax,ay,az);
heptasat2021 2:197079c5867f 95 wait_ms(1000);
heptasat2021 2:197079c5867f 96 }
heptasat2021 2:197079c5867f 97 }else if(rcmd == 'd'){
heptasat2021 2:197079c5867f 98 float gx,gy,gz;
heptasat2021 2:197079c5867f 99 for(int i = 0; i < 10; i++) {
heptasat2021 2:197079c5867f 100 sensor.sen_gyro(&gx,&gy,&gz);
heptasat2021 2:197079c5867f 101 gs.printf("%f,%f,%f\r\n",gx,gy,gz);
heptasat2021 2:197079c5867f 102 wait_ms(1000);
heptasat2021 2:197079c5867f 103 }
heptasat2021 2:197079c5867f 104 }
heptasat2021 2:197079c5867f 105 initialize(); //initializing
heptasat2021 2:197079c5867f 106 }
heptasat2021 0:da0f6aca15b8 107 }
heptasat2021 2:197079c5867f 108 sattime.stop();
heptasat2021 2:197079c5867f 109 gs.printf("From Sat : End of operation\r\n");
heptasat2021 0:da0f6aca15b8 110 }