qqqq

Dependencies:   HEPTA_SENSOR mbed HEPTA_EPS HEPTA_COM HEPTA_CDH

Committer:
heptasat2021
Date:
Sun Nov 21 02:23:58 2021 +0000
Revision:
29:eb84063fe5c9
Parent:
28:60f73cc07244
Child:
30:f300d1e88f4c
rev_20211121

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:bdbd3d6fc5d5 1 #include "mbed.h"
HeptaSatTraining2019 25:ccc5ff675e0c 2 #include "HEPTA_CDH.h"
HeptaSatTraining2019 25:ccc5ff675e0c 3 #include "HEPTA_EPS.h"
MEXT1 27:b4689aa48bf5 4 #include "HEPTA_SENSOR.h"
MEXT1 27:b4689aa48bf5 5 #include "HEPTA_COM.h"
HeptaSatTraining2019 26:220e5f95168a 6 HEPTA_CDH cdh(p5, p6, p7, p8, "sd");
HeptaSatTraining2019 26:220e5f95168a 7 HEPTA_EPS eps(p16,p26);
MEXT1 27:b4689aa48bf5 8 HEPTA_SENSOR sensor(p17,
MEXT1 27:b4689aa48bf5 9 p28,p27,0xD0,0x18,
MEXT1 27:b4689aa48bf5 10 p13,p14,p25,p24);
heptasat2021 29:eb84063fe5c9 11 HEPTA_COM com(p9,p10);
heptasat2021 29:eb84063fe5c9 12 DigitalOut condition(LED1);
heptasat2021 29:eb84063fe5c9 13 Serial sat(USBTX,USBRX,9600);
heptasat2021 29:eb84063fe5c9 14 Timer sattime;
MEXT1 27:b4689aa48bf5 15 int rcmd = 0,cmdflag = 0; //command variable
HeptaSatTraining2019 24:3659e0c223c8 16
MEXT1 27:b4689aa48bf5 17 //getting command and flag
HeptaSatTraining2019 26:220e5f95168a 18 void commandget()
HeptaSatTraining2019 26:220e5f95168a 19 {
heptasat2021 29:eb84063fe5c9 20 rcmd=com.getc();
HeptaSatTraining2019 26:220e5f95168a 21 cmdflag = 1;
HeptaSatTraining2019 26:220e5f95168a 22 }
MEXT1 27:b4689aa48bf5 23 //interrupting
MEXT1 27:b4689aa48bf5 24 void receive(int rcmd, int cmdflag)
HeptaSatTraining2019 26:220e5f95168a 25 {
heptasat2021 29:eb84063fe5c9 26 com.xbee.attach(commandget,Serial::RxIrq);
HeptaSatTraining2019 26:220e5f95168a 27 }
MEXT1 27:b4689aa48bf5 28 //initialzing
HeptaSatTraining2019 26:220e5f95168a 29 void initialize()
HeptaSatTraining2019 26:220e5f95168a 30 {
HeptaSatTraining2019 26:220e5f95168a 31 rcmd = 0;
HeptaSatTraining2019 26:220e5f95168a 32 cmdflag = 0;
heptasat2021 29:eb84063fe5c9 33 condition = 0;
HeptaSatTraining2019 26:220e5f95168a 34 }
heptasat2021 29:eb84063fe5c9 35
MEXT1 27:b4689aa48bf5 36 int main() {
heptasat2021 29:eb84063fe5c9 37 sat.printf("From Sat : Nominal Operation\r\n");
heptasat2021 29:eb84063fe5c9 38 com.printf("From Sat : Nominal Operation\r\n");
heptasat2021 29:eb84063fe5c9 39 com.baud(9600);
heptasat2021 29:eb84063fe5c9 40 int flag = 0; //condition flag
heptasat2021 29:eb84063fe5c9 41 float batvol, temp; //voltage, temperature
heptasat2021 29:eb84063fe5c9 42 int rcmd=0,cmdflag=0; //command variable
heptasat2021 29:eb84063fe5c9 43 sattime.start();
MEXT1 27:b4689aa48bf5 44 receive(rcmd,cmdflag); //interupting by ground station command
heptasat2021 29:eb84063fe5c9 45 eps.turn_on_regulator();//turn on 3.3V conveter
MEXT1 27:b4689aa48bf5 46 for(int i = 0; i < 100; i++) {
heptasat2021 29:eb84063fe5c9 47 //satellite condition led
heptasat2021 29:eb84063fe5c9 48 condition = !condition;
heptasat2021 29:eb84063fe5c9 49
heptasat2021 29:eb84063fe5c9 50 //senssing HK data(dummy data)
heptasat2021 29:eb84063fe5c9 51 eps.vol(&batvol);
MEXT1 27:b4689aa48bf5 52 sensor.temp_sense(&temp);
heptasat2021 29:eb84063fe5c9 53
heptasat2021 29:eb84063fe5c9 54 //Transmitting HK data to Ground Station(GS)
heptasat2021 29:eb84063fe5c9 55 com.printf("HEPTASAT::Condition = %d, Time = %f [s], batVol = %.2f [V],Temp = %.2f [C]\r\n",flag,sattime.read(),batvol,temp);
heptasat2021 29:eb84063fe5c9 56 wait_ms(1000);
heptasat2021 29:eb84063fe5c9 57
heptasat2021 29:eb84063fe5c9 58 //Power Saving Mode
heptasat2021 29:eb84063fe5c9 59 if((batvol <= 3.5) | (temp > 35.0)){
heptasat2021 29:eb84063fe5c9 60 eps.shut_down_regulator();
heptasat2021 29:eb84063fe5c9 61 com.printf("Power saving mode ON\r\n");
heptasat2021 29:eb84063fe5c9 62 flag = 1;
heptasat2021 29:eb84063fe5c9 63 } else if((flag == 1) & (batvol > 3.7) & (temp <= 25.0)) {
heptasat2021 29:eb84063fe5c9 64 eps.turn_on_regulator();
heptasat2021 29:eb84063fe5c9 65 com.printf("Power saving mode OFF\r\n");
heptasat2021 29:eb84063fe5c9 66 flag = 0;
HeptaSatTraining2019 26:220e5f95168a 67 }
MEXT1 27:b4689aa48bf5 68 //Contents of command
HeptaSatTraining2019 26:220e5f95168a 69 if (cmdflag == 1) {
HeptaSatTraining2019 26:220e5f95168a 70 if (rcmd == 'a') {
heptasat2021 29:eb84063fe5c9 71 sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag);
heptasat2021 29:eb84063fe5c9 72 com.printf("Hepta-Sat Lite Uplink Ok\r\n");
heptasat2021 29:eb84063fe5c9 73 for(int j=0;j<5;j++){
heptasat2021 29:eb84063fe5c9 74 com.printf("Hello World!\r\n");
heptasat2021 29:eb84063fe5c9 75 condition = 1;
heptasat2021 29:eb84063fe5c9 76 wait_ms(1000);
heptasat2021 29:eb84063fe5c9 77 }
heptasat2021 29:eb84063fe5c9 78 }else if (rcmd == 'b') {
heptasat2021 29:eb84063fe5c9 79 sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag);
heptasat2021 29:eb84063fe5c9 80 com.printf("Hepta-Sat Lite Uplink Ok\r\n");
MEXT1 27:b4689aa48bf5 81 char str[100];
MEXT1 27:b4689aa48bf5 82 mkdir("/sd/mydir", 0777);
heptasat2021 29:eb84063fe5c9 83 FILE *fp = fopen("/sd/mydir/satdata.txt","w");
MEXT1 27:b4689aa48bf5 84 if(fp == NULL) {
MEXT1 27:b4689aa48bf5 85 error("Could not open file for write\r\n");
MEXT1 27:b4689aa48bf5 86 }
heptasat2021 29:eb84063fe5c9 87 for(int i = 0; i < 10; i++) {
heptasat2021 29:eb84063fe5c9 88 eps.vol(&batvol);
heptasat2021 29:eb84063fe5c9 89 fprintf(fp,"%f\r\n",batvol);
heptasat2021 29:eb84063fe5c9 90 condition = 1;
heptasat2021 29:eb84063fe5c9 91 wait_ms(1000);
MEXT1 27:b4689aa48bf5 92 }
heptasat2021 29:eb84063fe5c9 93 fclose(fp);
heptasat2021 29:eb84063fe5c9 94 fp = fopen("/sd/mydir/satdata.txt","r");
heptasat2021 29:eb84063fe5c9 95 for(int i = 0; i < 10; i++) {
heptasat2021 29:eb84063fe5c9 96 fgets(str,100,fp);
heptasat2021 29:eb84063fe5c9 97 com.puts(str);
heptasat2021 29:eb84063fe5c9 98 }
heptasat2021 29:eb84063fe5c9 99 fclose(fp);
heptasat2021 29:eb84063fe5c9 100 }else if (rcmd == 'c') {
heptasat2021 29:eb84063fe5c9 101 //Please insert your answer
heptasat2021 29:eb84063fe5c9 102
heptasat2021 29:eb84063fe5c9 103 }else if (rcmd == 'd') {
heptasat2021 29:eb84063fe5c9 104 //Please insert your answer
heptasat2021 29:eb84063fe5c9 105
heptasat2021 29:eb84063fe5c9 106 }else if (rcmd == 'e') {
heptasat2021 29:eb84063fe5c9 107 //Please insert your answer
heptasat2021 29:eb84063fe5c9 108
HeptaSatTraining2019 26:220e5f95168a 109 }
HeptaSatTraining2019 26:220e5f95168a 110 initialize();
HeptaSatTraining2019 26:220e5f95168a 111 }
HeptaSatTraining2019 24:3659e0c223c8 112 }
heptasat2021 29:eb84063fe5c9 113 sattime.stop();
heptasat2021 29:eb84063fe5c9 114 sat.printf("From Sat : End of operation\r\n");
heptasat2021 29:eb84063fe5c9 115 com.printf("From Sat : End of operation\r\n");
MEXT1 27:b4689aa48bf5 116 }