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