HeptaSat

Dependencies:   HEPTA_COM HEPTA_CDH HEPTA_EPS HEPTA_SENSOR mbed

Committer:
RyusukeIwata
Date:
Mon Nov 07 15:10:40 2022 +0000
Revision:
28:952078c4ea2d
Parent:
27:e587c17f53fe
rawserial;

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:e587c17f53fe 4 DigitalOut cond[]={LED1,LED2,LED3,LED4};
RyusukeIwata 28:952078c4ea2d 5 RawSerial gs(USBTX,USBRX,9600); // for ground station
HeptaSatTraining2019 26:220e5f95168a 6 HEPTA_CDH cdh(p5, p6, p7, p8, "sd");
HeptaSatTraining2019 26:220e5f95168a 7 HEPTA_EPS eps(p16,p26);
MEXT1 27:e587c17f53fe 8 int rcmd = 0,cmdflag = 0; //command variable
HeptaSatTraining2019 24:3659e0c223c8 9
MEXT1 27:e587c17f53fe 10 //getting command and flag
HeptaSatTraining2019 26:220e5f95168a 11 void commandget()
HeptaSatTraining2019 26:220e5f95168a 12 {
MEXT1 27:e587c17f53fe 13 rcmd=gs.getc();
HeptaSatTraining2019 26:220e5f95168a 14 cmdflag = 1;
HeptaSatTraining2019 26:220e5f95168a 15 }
MEXT1 27:e587c17f53fe 16 //interrupting
MEXT1 27:e587c17f53fe 17 void receive(int rcmd, int cmdflag)
HeptaSatTraining2019 26:220e5f95168a 18 {
MEXT1 27:e587c17f53fe 19 gs.attach(commandget,Serial::RxIrq);
HeptaSatTraining2019 26:220e5f95168a 20 }
MEXT1 27:e587c17f53fe 21 //initialzing
HeptaSatTraining2019 26:220e5f95168a 22 void initialize()
HeptaSatTraining2019 26:220e5f95168a 23 {
HeptaSatTraining2019 26:220e5f95168a 24 rcmd = 0;
HeptaSatTraining2019 26:220e5f95168a 25 cmdflag = 0;
MEXT1 27:e587c17f53fe 26 cond[0] = 0;
HeptaSatTraining2019 26:220e5f95168a 27 }
MEXT1 27:e587c17f53fe 28
MEXT1 27:e587c17f53fe 29 int main() {
MEXT1 27:e587c17f53fe 30 gs.printf("From Sat : Operation Start...\r\n");
MEXT1 27:e587c17f53fe 31 int flag = 0; // condition
MEXT1 27:e587c17f53fe 32 float sattime=0.0,btvol,temp; //Voltage, Temerature
MEXT1 27:e587c17f53fe 33 receive(rcmd,cmdflag); //interupting by ground station command
MEXT1 27:e587c17f53fe 34
MEXT1 27:e587c17f53fe 35 for(int i = 0; i < 100; i++) {
MEXT1 27:e587c17f53fe 36 //Sensing and Transmitting HK data
MEXT1 27:e587c17f53fe 37 eps.vol(&btvol);
MEXT1 27:e587c17f53fe 38 temp = 28.5;
MEXT1 27:e587c17f53fe 39 gs.printf("HEPTASAT::Condition = %d, Time = %f [s], BatVol = %.2f [V],Temp = %.2f [C]\r\n",flag,sattime,btvol,temp);
MEXT1 27:e587c17f53fe 40 //Condition
MEXT1 27:e587c17f53fe 41 cond[0] = 1;
MEXT1 27:e587c17f53fe 42 //Power Saving Mode
MEXT1 27:e587c17f53fe 43 if(btvol <= 3.5) {
HeptaSatTraining2019 26:220e5f95168a 44 eps.shut_down_regulator();
HeptaSatTraining2019 26:220e5f95168a 45 flag = 1;
HeptaSatTraining2019 26:220e5f95168a 46 } else {
HeptaSatTraining2019 26:220e5f95168a 47 eps.turn_on_regulator();
HeptaSatTraining2019 26:220e5f95168a 48 flag = 0;
HeptaSatTraining2019 26:220e5f95168a 49 }
HeptaSatTraining2019 26:220e5f95168a 50 if(flag == 1) {
MEXT1 27:e587c17f53fe 51 gs.printf("Power saving mode ON\r\n");
HeptaSatTraining2019 26:220e5f95168a 52 }
MEXT1 27:e587c17f53fe 53 //Contents of command
HeptaSatTraining2019 26:220e5f95168a 54 if (cmdflag == 1) {
HeptaSatTraining2019 26:220e5f95168a 55 if (rcmd == 'a') {
MEXT1 27:e587c17f53fe 56 for(int j=0;j<5;j++){
MEXT1 27:e587c17f53fe 57 gs.printf("HEPTASAT::Hello World!\r\n");
MEXT1 27:e587c17f53fe 58 cond[0] = 0;
MEXT1 27:e587c17f53fe 59 wait(1);
MEXT1 27:e587c17f53fe 60 cond[0] = 1;
MEXT1 27:e587c17f53fe 61 }
HeptaSatTraining2019 26:220e5f95168a 62 }
HeptaSatTraining2019 26:220e5f95168a 63 if (rcmd == 'b') {
MEXT1 27:e587c17f53fe 64 //Prease enter your answer in this part
HeptaSatTraining2019 26:220e5f95168a 65
HeptaSatTraining2019 26:220e5f95168a 66
HeptaSatTraining2019 26:220e5f95168a 67 }
HeptaSatTraining2019 26:220e5f95168a 68 initialize();
HeptaSatTraining2019 26:220e5f95168a 69 }
MEXT1 27:e587c17f53fe 70 //Operation Interval
MEXT1 27:e587c17f53fe 71 wait(1.0);
MEXT1 27:e587c17f53fe 72 sattime = sattime+1.0;
HeptaSatTraining2019 24:3659e0c223c8 73 }
MEXT1 27:e587c17f53fe 74 gs.printf("From Sat : Operation Stop...\r\n");
umeume 2:1c5cdb2c3e0f 75 }