Lab3-05_create_satcode_step4_lite
Dependencies: mbed HEPTA_CDH_lite HEPTA_EPS_lite
main.cpp
00001 #include "mbed.h" 00002 #include "HEPTA_EPS.h" 00003 #include "HEPTA_CDH.h" 00004 HEPTA_CDH cdh(PB_5, PB_4, PB_3, PA_8, "sd"); 00005 HEPTA_EPS eps(PA_0,PA_4); 00006 DigitalOut condition(PB_1); 00007 Serial gs(USBTX,USBRX,9600); 00008 Timer sattime; 00009 int rcmd = 0, cmdflag = 0; //command variable 00010 00011 //getting command and command flag 00012 void commandget() 00013 { 00014 rcmd = gs.getc(); 00015 cmdflag = 1; 00016 } 00017 //interrupting process by command receive 00018 void receive(int rcmd, int cmdflag) 00019 { 00020 gs.attach(commandget,Serial::RxIrq); 00021 } 00022 //initializing 00023 void initialize() 00024 { 00025 rcmd = 0; 00026 cmdflag = 0; 00027 condition = 0; 00028 } 00029 00030 int main() 00031 { 00032 gs.printf("From Sat : Nominal Operation\r\n"); 00033 int flag = 0; //condition flag 00034 float batvol, temp; //voltage, temperature 00035 sattime.start(); 00036 receive(rcmd,cmdflag); //interrupting 00037 eps.turn_on_regulator();//turn on 3.3V conveter 00038 for(int i=0;i<50;i++){ 00039 //satellite condition led 00040 condition = !condition; 00041 00042 //senssing HK data(dummy data) 00043 eps.vol(&batvol); 00044 temp = 28.5; 00045 00046 //Transmitting HK data to Ground Station(GS) 00047 gs.printf("HEPTASAT::Condition = %d, Time = %f [s], batvol = %2f [V], temp = %2f [deg C]\r\n",flag,sattime.read(),batvol,temp); 00048 wait_ms(1000); 00049 00050 //Power Saving Mode 00051 if(batvol <= 3.5){ 00052 eps.shut_down_regulator(); 00053 gs.printf("Power saving mode ON\r\n"); 00054 flag = 1; 00055 } else if((flag == 1) & (batvol > 3.7)) { 00056 eps.turn_on_regulator(); 00057 gs.printf("Power saving mode OFF\r\n"); 00058 flag = 0; 00059 } 00060 00061 if(cmdflag == 1){ 00062 if(rcmd == 'a'){ 00063 for(int j=0;j<5;j++){ 00064 gs.printf("Hello World!\r\n"); 00065 condition = 1; 00066 wait_ms(1000); 00067 } 00068 }else if(rcmd == 'b') { 00069 char str[100]; 00070 mkdir("/sd/mydir", 0777); 00071 FILE *fp = fopen("/sd/mydir/satdata.txt","w"); 00072 if(fp == NULL) { 00073 error("Could not open file for write\r\n"); 00074 } 00075 for(int i = 0; i < 10; i++) { 00076 eps.vol(&batvol); 00077 fprintf(fp,"%f\r\n",batvol); 00078 condition = 1; 00079 wait_ms(1000); 00080 } 00081 fclose(fp); 00082 fp = fopen("/sd/mydir/satdata.txt","r"); 00083 for(int i = 0; i < 10; i++) { 00084 fgets(str,100,fp); 00085 gs.puts(str); 00086 } 00087 fclose(fp); 00088 } 00089 initialize(); //initializing 00090 } 00091 } 00092 sattime.stop(); 00093 gs.printf("From Sat : End of operation\r\n"); 00094 }
Generated on Sun Aug 7 2022 16:41:45 by
1.7.2