rev_20211121

Dependencies:   HEPTA_SENSOR mbed HEPTA_EPS HEPTA_COM HEPTA_CDH

Committer:
heptasat2021
Date:
Fri Dec 03 11:09:33 2021 +0000
Revision:
30:f300d1e88f4c
Parent:
29:eb84063fe5c9
20211203_changeinterrupt

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
heptasat2021 29:eb84063fe5c9 16
MEXT1 27:b4689aa48bf5 17 int main() {
heptasat2021 29:eb84063fe5c9 18 sat.printf("From Sat : Nominal Operation\r\n");
heptasat2021 29:eb84063fe5c9 19 com.printf("From Sat : Nominal Operation\r\n");
heptasat2021 29:eb84063fe5c9 20 com.baud(9600);
heptasat2021 29:eb84063fe5c9 21 int flag = 0; //condition flag
heptasat2021 29:eb84063fe5c9 22 float batvol, temp; //voltage, temperature
heptasat2021 29:eb84063fe5c9 23 int rcmd=0,cmdflag=0; //command variable
heptasat2021 29:eb84063fe5c9 24 sattime.start();
heptasat2021 29:eb84063fe5c9 25 eps.turn_on_regulator();//turn on 3.3V conveter
MEXT1 27:b4689aa48bf5 26 for(int i = 0; i < 100; i++) {
heptasat2021 30:f300d1e88f4c 27 com.xbee_receive(&rcmd,&cmdflag);//interupting by ground station command
heptasat2021 30:f300d1e88f4c 28
heptasat2021 29:eb84063fe5c9 29 //satellite condition led
heptasat2021 29:eb84063fe5c9 30 condition = !condition;
heptasat2021 29:eb84063fe5c9 31
heptasat2021 29:eb84063fe5c9 32 //senssing HK data(dummy data)
heptasat2021 29:eb84063fe5c9 33 eps.vol(&batvol);
MEXT1 27:b4689aa48bf5 34 sensor.temp_sense(&temp);
heptasat2021 29:eb84063fe5c9 35
heptasat2021 29:eb84063fe5c9 36 //Transmitting HK data to Ground Station(GS)
heptasat2021 29:eb84063fe5c9 37 com.printf("HEPTASAT::Condition = %d, Time = %f [s], batVol = %.2f [V],Temp = %.2f [C]\r\n",flag,sattime.read(),batvol,temp);
heptasat2021 29:eb84063fe5c9 38 wait_ms(1000);
heptasat2021 29:eb84063fe5c9 39
heptasat2021 29:eb84063fe5c9 40 //Power Saving Mode
heptasat2021 29:eb84063fe5c9 41 if((batvol <= 3.5) | (temp > 35.0)){
heptasat2021 29:eb84063fe5c9 42 eps.shut_down_regulator();
heptasat2021 29:eb84063fe5c9 43 com.printf("Power saving mode ON\r\n");
heptasat2021 29:eb84063fe5c9 44 flag = 1;
heptasat2021 29:eb84063fe5c9 45 } else if((flag == 1) & (batvol > 3.7) & (temp <= 25.0)) {
heptasat2021 29:eb84063fe5c9 46 eps.turn_on_regulator();
heptasat2021 29:eb84063fe5c9 47 com.printf("Power saving mode OFF\r\n");
heptasat2021 29:eb84063fe5c9 48 flag = 0;
HeptaSatTraining2019 26:220e5f95168a 49 }
MEXT1 27:b4689aa48bf5 50 //Contents of command
HeptaSatTraining2019 26:220e5f95168a 51 if (cmdflag == 1) {
HeptaSatTraining2019 26:220e5f95168a 52 if (rcmd == 'a') {
heptasat2021 29:eb84063fe5c9 53 sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag);
heptasat2021 29:eb84063fe5c9 54 com.printf("Hepta-Sat Lite Uplink Ok\r\n");
heptasat2021 29:eb84063fe5c9 55 for(int j=0;j<5;j++){
heptasat2021 29:eb84063fe5c9 56 com.printf("Hello World!\r\n");
heptasat2021 29:eb84063fe5c9 57 condition = 1;
heptasat2021 29:eb84063fe5c9 58 wait_ms(1000);
heptasat2021 29:eb84063fe5c9 59 }
heptasat2021 29:eb84063fe5c9 60 }else if (rcmd == 'b') {
heptasat2021 29:eb84063fe5c9 61 sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag);
heptasat2021 29:eb84063fe5c9 62 com.printf("Hepta-Sat Lite Uplink Ok\r\n");
MEXT1 27:b4689aa48bf5 63 char str[100];
MEXT1 27:b4689aa48bf5 64 mkdir("/sd/mydir", 0777);
heptasat2021 29:eb84063fe5c9 65 FILE *fp = fopen("/sd/mydir/satdata.txt","w");
MEXT1 27:b4689aa48bf5 66 if(fp == NULL) {
MEXT1 27:b4689aa48bf5 67 error("Could not open file for write\r\n");
MEXT1 27:b4689aa48bf5 68 }
heptasat2021 29:eb84063fe5c9 69 for(int i = 0; i < 10; i++) {
heptasat2021 29:eb84063fe5c9 70 eps.vol(&batvol);
heptasat2021 29:eb84063fe5c9 71 fprintf(fp,"%f\r\n",batvol);
heptasat2021 29:eb84063fe5c9 72 condition = 1;
heptasat2021 29:eb84063fe5c9 73 wait_ms(1000);
MEXT1 27:b4689aa48bf5 74 }
heptasat2021 29:eb84063fe5c9 75 fclose(fp);
heptasat2021 29:eb84063fe5c9 76 fp = fopen("/sd/mydir/satdata.txt","r");
heptasat2021 29:eb84063fe5c9 77 for(int i = 0; i < 10; i++) {
heptasat2021 29:eb84063fe5c9 78 fgets(str,100,fp);
heptasat2021 29:eb84063fe5c9 79 com.puts(str);
heptasat2021 29:eb84063fe5c9 80 }
heptasat2021 29:eb84063fe5c9 81 fclose(fp);
heptasat2021 29:eb84063fe5c9 82 }else if (rcmd == 'c') {
heptasat2021 29:eb84063fe5c9 83 //Please insert your answer
heptasat2021 29:eb84063fe5c9 84
heptasat2021 29:eb84063fe5c9 85 }else if (rcmd == 'd') {
heptasat2021 29:eb84063fe5c9 86 //Please insert your answer
heptasat2021 29:eb84063fe5c9 87
heptasat2021 29:eb84063fe5c9 88 }else if (rcmd == 'e') {
heptasat2021 29:eb84063fe5c9 89 //Please insert your answer
heptasat2021 29:eb84063fe5c9 90
HeptaSatTraining2019 26:220e5f95168a 91 }
heptasat2021 30:f300d1e88f4c 92 com.initialize();
HeptaSatTraining2019 26:220e5f95168a 93 }
HeptaSatTraining2019 24:3659e0c223c8 94 }
heptasat2021 29:eb84063fe5c9 95 sattime.stop();
heptasat2021 29:eb84063fe5c9 96 sat.printf("From Sat : End of operation\r\n");
heptasat2021 29:eb84063fe5c9 97 com.printf("From Sat : End of operation\r\n");
MEXT1 27:b4689aa48bf5 98 }