Lab4-03_create_satcode_step5_lite_Q

Dependencies:   mbed HEPTA_CDH_lite HEPTA_SENSOR_lite HEPTA_EPS_lite

Committer:
heptasat2021
Date:
Fri Aug 20 12:57:14 2021 +0000
Revision:
2:115700794fa6
Parent:
1:ddac5ec89167
Child:
3:98c45e812ac6
For Hepta-Sat Lite

Who changed what in which revision?

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