Lab3-05_create_satcode_step3_lite

Dependencies:   mbed HEPTA_CDH_lite HEPTA_EPS_lite

Committer:
heptasat2021
Date:
Fri Aug 20 12:26:17 2021 +0000
Revision:
2:d4178a27e4b2
Parent:
1:ddac5ec89167
For Hepta-Sat Lite

Who changed what in which revision?

UserRevisionLine numberNew contents of line
heptasat2021 0:da0f6aca15b8 1 #include "mbed.h"
heptasat2021 2:d4178a27e4b2 2 #include "HEPTA_EPS.h"
heptasat2021 1:ddac5ec89167 3 #include "HEPTA_CDH.h"
heptasat2021 1:ddac5ec89167 4 HEPTA_CDH cdh(PB_5, PB_4, PB_3, PA_8, "sd");
heptasat2021 2:d4178a27e4b2 5 HEPTA_EPS eps(PA_0,PA_4);
heptasat2021 2:d4178a27e4b2 6 DigitalOut condition(PB_1);
heptasat2021 2:d4178a27e4b2 7 Serial gs(USBTX,USBRX,9600);
heptasat2021 2:d4178a27e4b2 8 Timer sattime;
heptasat2021 2:d4178a27e4b2 9 int rcmd = 0, cmdflag = 0; //command variable
heptasat2021 2:d4178a27e4b2 10
heptasat2021 2:d4178a27e4b2 11 //getting command and command flag
heptasat2021 2:d4178a27e4b2 12 void commandget()
heptasat2021 2:d4178a27e4b2 13 {
heptasat2021 2:d4178a27e4b2 14 rcmd = gs.getc();
heptasat2021 2:d4178a27e4b2 15 cmdflag = 1;
heptasat2021 2:d4178a27e4b2 16 }
heptasat2021 2:d4178a27e4b2 17 //interrupting process by command receive
heptasat2021 2:d4178a27e4b2 18 void receive(int rcmd, int cmdflag)
heptasat2021 2:d4178a27e4b2 19 {
heptasat2021 2:d4178a27e4b2 20 gs.attach(commandget,Serial::RxIrq);
heptasat2021 2:d4178a27e4b2 21 }
heptasat2021 2:d4178a27e4b2 22 //initializing
heptasat2021 2:d4178a27e4b2 23 void initialize()
heptasat2021 2:d4178a27e4b2 24 {
heptasat2021 2:d4178a27e4b2 25 rcmd = 0;
heptasat2021 2:d4178a27e4b2 26 cmdflag = 0;
heptasat2021 2:d4178a27e4b2 27 condition = 0;
heptasat2021 2:d4178a27e4b2 28 }
heptasat2021 2:d4178a27e4b2 29
heptasat2021 0:da0f6aca15b8 30 int main()
heptasat2021 0:da0f6aca15b8 31 {
heptasat2021 2:d4178a27e4b2 32 gs.printf("From Sat : Nominal Operation\r\n");
heptasat2021 2:d4178a27e4b2 33 int flag = 0; //condition flag
heptasat2021 2:d4178a27e4b2 34 float batvol, temp; //voltage, temperature
heptasat2021 2:d4178a27e4b2 35 sattime.start();
heptasat2021 2:d4178a27e4b2 36 receive(rcmd,cmdflag); //interrupting
heptasat2021 2:d4178a27e4b2 37 eps.turn_on_regulator();//turn on 3.3V conveter
heptasat2021 2:d4178a27e4b2 38 for(int i=0;i<50;i++){
heptasat2021 2:d4178a27e4b2 39 //satellite condition led
heptasat2021 2:d4178a27e4b2 40 condition = !condition;
heptasat2021 2:d4178a27e4b2 41
heptasat2021 2:d4178a27e4b2 42 //senssing HK data(dummy data)
heptasat2021 2:d4178a27e4b2 43 eps.vol(&batvol);
heptasat2021 2:d4178a27e4b2 44 temp = 28.5;
heptasat2021 2:d4178a27e4b2 45
heptasat2021 2:d4178a27e4b2 46 //Transmitting HK data to Ground Station(GS)
heptasat2021 2:d4178a27e4b2 47 gs.printf("HEPTASAT::Condition = %d, Time = %f [s], batvol = %2f [V], temp = %2f [deg C]\r\n",flag,sattime.read(),batvol,temp);
heptasat2021 2:d4178a27e4b2 48 wait_ms(1000);
heptasat2021 2:d4178a27e4b2 49
heptasat2021 2:d4178a27e4b2 50 //Power Saving Mode
heptasat2021 2:d4178a27e4b2 51 if(batvol <= 3.5){
heptasat2021 2:d4178a27e4b2 52 eps.shut_down_regulator();
heptasat2021 2:d4178a27e4b2 53 gs.printf("Power saving mode ON\r\n");
heptasat2021 2:d4178a27e4b2 54 flag = 1;
heptasat2021 2:d4178a27e4b2 55 } else if((flag == 1) & (batvol > 3.7)) {
heptasat2021 2:d4178a27e4b2 56 eps.turn_on_regulator();
heptasat2021 2:d4178a27e4b2 57 gs.printf("Power saving mode OFF\r\n");
heptasat2021 2:d4178a27e4b2 58 flag = 0;
heptasat2021 2:d4178a27e4b2 59 }
heptasat2021 2:d4178a27e4b2 60
heptasat2021 2:d4178a27e4b2 61 if(cmdflag == 1){
heptasat2021 2:d4178a27e4b2 62 if(rcmd == 'a'){
heptasat2021 2:d4178a27e4b2 63 for(int j=0;j<5;j++){
heptasat2021 2:d4178a27e4b2 64 gs.printf("Hello World!\r\n");
heptasat2021 2:d4178a27e4b2 65 condition = 1;
heptasat2021 2:d4178a27e4b2 66 wait_ms(1000);
heptasat2021 2:d4178a27e4b2 67 }
heptasat2021 2:d4178a27e4b2 68 }
heptasat2021 2:d4178a27e4b2 69 initialize(); //initializing
heptasat2021 2:d4178a27e4b2 70 }
heptasat2021 0:da0f6aca15b8 71 }
heptasat2021 2:d4178a27e4b2 72 sattime.stop();
heptasat2021 2:d4178a27e4b2 73 gs.printf("From Sat : End of operation\r\n");
heptasat2021 0:da0f6aca15b8 74 }