Lab5-03_create_satcode_step6_lite_Q

Dependencies:   mbed HEPTA_CDH_lite HEPTA_COM_lite HEPTA_SENSOR_lite HEPTA_EPS_lite

Committer:
heptasat2021
Date:
Tue Aug 24 02:55:33 2021 +0000
Revision:
4:52de4bb3146f
Parent:
3:e5ae22e02335
Child:
5:1f73ab69f023
For Hepta-Sat Lite

Who changed what in which revision?

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