for textbook v4.4

Dependencies:   HEPTA_SENSOR mbed HEPTA_EPS HEPTA_COM HEPTA_CDH

Committer:
MEXT1
Date:
Wed Jul 22 02:30:28 2020 +0000
Revision:
27:e587c17f53fe
Parent:
26:220e5f95168a
202007

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};
MEXT1 27:e587c17f53fe 5 Serial gs(USBTX,USBRX); // 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.baud(9600);
MEXT1 27:e587c17f53fe 31 gs.printf("From Sat : Operation Start...\r\n");
MEXT1 27:e587c17f53fe 32 int flag = 0; // condition
MEXT1 27:e587c17f53fe 33 float sattime=0.0,btvol,temp; //Voltage, Temerature
MEXT1 27:e587c17f53fe 34 receive(rcmd,cmdflag); //interupting by ground station command
MEXT1 27:e587c17f53fe 35
MEXT1 27:e587c17f53fe 36 for(int i = 0; i < 100; i++) {
MEXT1 27:e587c17f53fe 37 //Sensing and Transmitting HK data
MEXT1 27:e587c17f53fe 38 eps.vol(&btvol);
MEXT1 27:e587c17f53fe 39 temp = 28.5;
MEXT1 27:e587c17f53fe 40 gs.printf("HEPTASAT::Condition = %d, Time = %f [s], BatVol = %.2f [V],Temp = %.2f [C]\r\n",flag,sattime,btvol,temp);
MEXT1 27:e587c17f53fe 41 //Condition
MEXT1 27:e587c17f53fe 42 cond[0] = 1;
MEXT1 27:e587c17f53fe 43 //Power Saving Mode
MEXT1 27:e587c17f53fe 44 if(btvol <= 3.5) {
HeptaSatTraining2019 26:220e5f95168a 45 eps.shut_down_regulator();
HeptaSatTraining2019 26:220e5f95168a 46 flag = 1;
HeptaSatTraining2019 26:220e5f95168a 47 } else {
HeptaSatTraining2019 26:220e5f95168a 48 eps.turn_on_regulator();
HeptaSatTraining2019 26:220e5f95168a 49 flag = 0;
HeptaSatTraining2019 26:220e5f95168a 50 }
HeptaSatTraining2019 26:220e5f95168a 51 if(flag == 1) {
MEXT1 27:e587c17f53fe 52 gs.printf("Power saving mode ON\r\n");
HeptaSatTraining2019 26:220e5f95168a 53 }
MEXT1 27:e587c17f53fe 54 //Contents of command
HeptaSatTraining2019 26:220e5f95168a 55 if (cmdflag == 1) {
HeptaSatTraining2019 26:220e5f95168a 56 if (rcmd == 'a') {
MEXT1 27:e587c17f53fe 57 for(int j=0;j<5;j++){
MEXT1 27:e587c17f53fe 58 gs.printf("HEPTASAT::Hello World!\r\n");
MEXT1 27:e587c17f53fe 59 cond[0] = 0;
MEXT1 27:e587c17f53fe 60 wait(1);
MEXT1 27:e587c17f53fe 61 cond[0] = 1;
MEXT1 27:e587c17f53fe 62 }
HeptaSatTraining2019 26:220e5f95168a 63 }
HeptaSatTraining2019 26:220e5f95168a 64 if (rcmd == 'b') {
MEXT1 27:e587c17f53fe 65 //Prease enter your answer in this part
HeptaSatTraining2019 26:220e5f95168a 66
HeptaSatTraining2019 26:220e5f95168a 67
HeptaSatTraining2019 26:220e5f95168a 68 }
HeptaSatTraining2019 26:220e5f95168a 69 initialize();
HeptaSatTraining2019 26:220e5f95168a 70 }
MEXT1 27:e587c17f53fe 71 //Operation Interval
MEXT1 27:e587c17f53fe 72 wait(1.0);
MEXT1 27:e587c17f53fe 73 sattime = sattime+1.0;
HeptaSatTraining2019 24:3659e0c223c8 74 }
MEXT1 27:e587c17f53fe 75 gs.printf("From Sat : Operation Stop...\r\n");
umeume 2:1c5cdb2c3e0f 76 }