hepta
Dependencies: HEPTA_CDH HEPTA_COM HEPTA_EPS HEPTA_SENSOR mbed
main.cpp
00001 #include "mbed.h" 00002 #include "HEPTA_CDH.h" 00003 #include "HEPTA_EPS.h" 00004 #include "HEPTA_SENSOR.h" 00005 #include "HEPTA_COM.h" 00006 HEPTA_CDH cdh(p5, p6, p7, p8, "sd"); 00007 HEPTA_EPS eps(p16,p26); 00008 HEPTA_SENSOR sensor(p17, 00009 p28,p27,0x19,0x69,0x13, 00010 p13, p14,p25,p24); 00011 HEPTA_COM com(p9,p10); 00012 DigitalOut condition(LED1); 00013 RawSerial sat(USBTX,USBRX,9600); 00014 Timer sattime; 00015 int rcmd = 0,cmdflag = 0; //command variable 00016 00017 int main() { 00018 sat.printf("From Sat : Nominal Operation\r\n"); 00019 com.printf("From Sat : Nominal Operation\r\n"); 00020 int flag = 0; //condition flag 00021 float batvol, temp; //voltage, temperature 00022 int rcmd=0,cmdflag=0; //command variable 00023 sattime.start(); 00024 eps.turn_on_regulator();//turn on 3.3V conveter 00025 for(int i = 0; i < 100; i++) { 00026 com.xbee_receive(&rcmd,&cmdflag);//interupting by ground station command 00027 00028 //satellite condition led 00029 condition = !condition; 00030 00031 //senssing HK data(dummy data) 00032 eps.vol(&batvol); 00033 sensor.temp_sense(&temp); 00034 00035 //Transmitting HK data to Ground Station(GS) 00036 com.printf("HEPTASAT::Condition = %d, Time = %f [s], batVol = %.2f [V],Temp = %.2f [C]\r\n",flag,sattime.read(),batvol,temp); 00037 wait_ms(1000); 00038 00039 //Power Saving Mode 00040 if((batvol <= 3.5) | (temp > 35.0)){ 00041 eps.shut_down_regulator(); 00042 com.printf("Power saving mode ON\r\n"); 00043 flag = 1; 00044 } else if((flag == 1) & (batvol > 3.7) & (temp <= 25.0)) { 00045 eps.turn_on_regulator(); 00046 com.printf("Power saving mode OFF\r\n"); 00047 flag = 0; 00048 } 00049 //Contents of command 00050 if (cmdflag == 1) { 00051 if (rcmd == 'a') { 00052 sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag); 00053 com.printf("Hepta-Sat Lite Uplink Ok\r\n"); 00054 for(int j=0;j<5;j++){ 00055 com.printf("Hello World!\r\n"); 00056 condition = 1; 00057 wait_ms(1000); 00058 } 00059 }else if (rcmd == 'b') { 00060 sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag); 00061 com.printf("Hepta-Sat Lite Uplink Ok\r\n"); 00062 char str[100]; 00063 mkdir("/sd/mydir", 0777); 00064 FILE *fp = fopen("/sd/mydir/satdata.txt","w"); 00065 if(fp == NULL) { 00066 error("Could not open file for write\r\n"); 00067 } 00068 for(int i = 0; i < 10; i++) { 00069 eps.vol(&batvol); 00070 fprintf(fp,"%f\r\n",batvol); 00071 condition = 1; 00072 wait_ms(1000); 00073 } 00074 fclose(fp); 00075 fp = fopen("/sd/mydir/satdata.txt","r"); 00076 for(int i = 0; i < 10; i++) { 00077 fgets(str,100,fp); 00078 com.puts(str); 00079 } 00080 fclose(fp); 00081 }else if (rcmd == 'c') { 00082 //Please insert your answer 00083 00084 }else if (rcmd == 'd') { 00085 //Please insert your answer 00086 00087 }else if (rcmd == 'e') { 00088 //Please insert your answer 00089 00090 } 00091 com.initialize(); 00092 } 00093 } 00094 sattime.stop(); 00095 sat.printf("From Sat : End of operation\r\n"); 00096 com.printf("From Sat : End of operation\r\n"); 00097 }
Generated on Mon Nov 14 2022 13:02:47 by
1.7.2