Lab5-03_create_satcode_step6_lite_Q

Dependencies:   mbed HEPTA_CDH_lite HEPTA_COM_lite HEPTA_SENSOR_lite HEPTA_EPS_lite

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

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