rev20211120

Dependencies:   HEPTA_SENSOR mbed HEPTA_EPS HEPTA_COM HEPTA_CDH

Committer:
HeptaSatTraining2019
Date:
Thu Oct 22 07:14:50 2020 +0000
Revision:
28:5c82ee674ad9
Parent:
27:06ec1277807c
Child:
29:3d5175dfeb10
fix if condition

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:06ec1277807c 4 #include "HEPTA_SENSOR.h"
MEXT1 27:06ec1277807c 5 DigitalOut cond[]={LED1,LED2,LED3,LED4};
MEXT1 27:06ec1277807c 6 Serial gs(USBTX,USBRX); // for ground station
HeptaSatTraining2019 26:220e5f95168a 7 HEPTA_CDH cdh(p5, p6, p7, p8, "sd");
HeptaSatTraining2019 26:220e5f95168a 8 HEPTA_EPS eps(p16,p26);
MEXT1 27:06ec1277807c 9 HEPTA_SENSOR sensor(p17,
MEXT1 27:06ec1277807c 10 p28,p27,0xD0,0x18,
MEXT1 27:06ec1277807c 11 p13,p14,p25,p24);
MEXT1 27:06ec1277807c 12 int rcmd = 0,cmdflag = 0; //command variable
HeptaSatTraining2019 24:3659e0c223c8 13
MEXT1 27:06ec1277807c 14 //getting command and flag
HeptaSatTraining2019 26:220e5f95168a 15 void commandget()
HeptaSatTraining2019 26:220e5f95168a 16 {
MEXT1 27:06ec1277807c 17 rcmd=gs.getc();
HeptaSatTraining2019 26:220e5f95168a 18 cmdflag = 1;
HeptaSatTraining2019 26:220e5f95168a 19 }
MEXT1 27:06ec1277807c 20 //interrupting
MEXT1 27:06ec1277807c 21 void receive(int rcmd, int cmdflag)
HeptaSatTraining2019 26:220e5f95168a 22 {
MEXT1 27:06ec1277807c 23 gs.attach(commandget,Serial::RxIrq);
HeptaSatTraining2019 26:220e5f95168a 24 }
MEXT1 27:06ec1277807c 25 //initialzing
HeptaSatTraining2019 26:220e5f95168a 26 void initialize()
HeptaSatTraining2019 26:220e5f95168a 27 {
HeptaSatTraining2019 26:220e5f95168a 28 rcmd = 0;
HeptaSatTraining2019 26:220e5f95168a 29 cmdflag = 0;
MEXT1 27:06ec1277807c 30 cond[0] = 0;
HeptaSatTraining2019 26:220e5f95168a 31 }
MEXT1 27:06ec1277807c 32
MEXT1 27:06ec1277807c 33 int main() {
MEXT1 27:06ec1277807c 34 gs.baud(9600);
MEXT1 27:06ec1277807c 35 float sattime=0.0,btvol,temp;
HeptaSatTraining2019 25:ccc5ff675e0c 36 char str[100];
MEXT1 27:06ec1277807c 37 float ax,ay,az;
MEXT1 27:06ec1277807c 38 float gx,gy,gz;
MEXT1 27:06ec1277807c 39 float mx,my,mz;
MEXT1 27:06ec1277807c 40 int quality=0,stnum=0,gps_check=0;
MEXT1 27:06ec1277807c 41 char ns='A',ew='B',aunit='m';
MEXT1 27:06ec1277807c 42 float latitude=0.0,longitude=0.0,hacu=0.0,altitude=0.0;
MEXT1 27:06ec1277807c 43 int flag = 0; // condition
MEXT1 27:06ec1277807c 44 receive(rcmd,cmdflag); //interupting by ground station command
MEXT1 27:06ec1277807c 45
MEXT1 27:06ec1277807c 46 gs.printf("From Sat : Operation Start...\r\n");
MEXT1 27:06ec1277807c 47 for(int i = 0; i < 100; i++) {
MEXT1 27:06ec1277807c 48 //Sensing and Transmitting HK data , Power Saving Mode
MEXT1 27:06ec1277807c 49 eps.power_saving_mode(&flag,&btvol);
MEXT1 27:06ec1277807c 50 sensor.temp_sense(&temp);
MEXT1 27:06ec1277807c 51 gs.printf("HEPTASAT::Condition = %d, Time = %f [s], BatVol = %.2f [V],Temp = %.2f [C]\r\n",flag,sattime,btvol,temp);
HeptaSatTraining2019 28:5c82ee674ad9 52
MEXT1 27:06ec1277807c 53 //Condition
MEXT1 27:06ec1277807c 54 cond[0] = 1;
HeptaSatTraining2019 28:5c82ee674ad9 55
MEXT1 27:06ec1277807c 56 //Warning the status of temperature and battery voltage
HeptaSatTraining2019 28:5c82ee674ad9 57 if((flag == 1) & (temp > 35.0)) {
HeptaSatTraining2019 28:5c82ee674ad9 58 gs.printf("Low Battery and High temperature\n");
MEXT1 27:06ec1277807c 59 } else if(temp > 35.0) {
MEXT1 27:06ec1277807c 60 gs.printf("High temperature\r\n");
HeptaSatTraining2019 28:5c82ee674ad9 61 } else if(flag == 1) {
HeptaSatTraining2019 28:5c82ee674ad9 62 gs.printf("Low Battery\r\n");
HeptaSatTraining2019 26:220e5f95168a 63 }
HeptaSatTraining2019 28:5c82ee674ad9 64
MEXT1 27:06ec1277807c 65 //Contents of command
HeptaSatTraining2019 26:220e5f95168a 66 if (cmdflag == 1) {
HeptaSatTraining2019 26:220e5f95168a 67 if (rcmd == 'a') {
MEXT1 27:06ec1277807c 68 for(int j=0;j<5;j++){
MEXT1 27:06ec1277807c 69 gs.printf("HEPTASAT::Hello World!\r\n");
MEXT1 27:06ec1277807c 70 cond[0] = 0;
MEXT1 27:06ec1277807c 71 wait(1);
MEXT1 27:06ec1277807c 72 cond[0] = 1;
MEXT1 27:06ec1277807c 73 }
HeptaSatTraining2019 26:220e5f95168a 74 }
HeptaSatTraining2019 26:220e5f95168a 75 if (rcmd == 'b') {
MEXT1 27:06ec1277807c 76 char str[100];
MEXT1 27:06ec1277807c 77 mkdir("/sd/mydir", 0777);
MEXT1 27:06ec1277807c 78 FILE *fp = fopen("/sd/mydir/test.txt","w");
MEXT1 27:06ec1277807c 79 if(fp == NULL) {
MEXT1 27:06ec1277807c 80 error("Could not open file for write\r\n");
MEXT1 27:06ec1277807c 81 }
MEXT1 27:06ec1277807c 82 else
MEXT1 27:06ec1277807c 83 {
MEXT1 27:06ec1277807c 84 for(int i = 0; i < 10; i++) {
MEXT1 27:06ec1277807c 85 eps.vol(&btvol);
MEXT1 27:06ec1277807c 86 fprintf(fp,"%f\r\n",btvol);
MEXT1 27:06ec1277807c 87 wait(1.0);
MEXT1 27:06ec1277807c 88 }
MEXT1 27:06ec1277807c 89 fclose(fp);
MEXT1 27:06ec1277807c 90 fp = fopen("/sd/mydir/test.txt","r");
MEXT1 27:06ec1277807c 91 for(int j = 0; j < 10; j++) {
MEXT1 27:06ec1277807c 92 fgets(str,100,fp);
MEXT1 27:06ec1277807c 93 puts(str);
MEXT1 27:06ec1277807c 94 }
MEXT1 27:06ec1277807c 95 fclose(fp);
MEXT1 27:06ec1277807c 96 }
MEXT1 27:06ec1277807c 97 cond[0] = 0;
MEXT1 27:06ec1277807c 98 wait(1);
MEXT1 27:06ec1277807c 99 cond[0] = 1;
MEXT1 27:06ec1277807c 100 }
MEXT1 27:06ec1277807c 101 if (rcmd == 'c') {
HeptaSatTraining2019 26:220e5f95168a 102
HeptaSatTraining2019 26:220e5f95168a 103
HeptaSatTraining2019 26:220e5f95168a 104
HeptaSatTraining2019 26:220e5f95168a 105
MEXT1 27:06ec1277807c 106 }
MEXT1 27:06ec1277807c 107 if (rcmd == 'd') {
MEXT1 27:06ec1277807c 108
MEXT1 27:06ec1277807c 109
HeptaSatTraining2019 26:220e5f95168a 110
HeptaSatTraining2019 26:220e5f95168a 111
HeptaSatTraining2019 26:220e5f95168a 112 }
HeptaSatTraining2019 26:220e5f95168a 113 initialize();
HeptaSatTraining2019 26:220e5f95168a 114 }
MEXT1 27:06ec1277807c 115
MEXT1 27:06ec1277807c 116 //Operation Interval
MEXT1 27:06ec1277807c 117 wait(1.0);
MEXT1 27:06ec1277807c 118 sattime = sattime+1.0;
HeptaSatTraining2019 24:3659e0c223c8 119 }
MEXT1 27:06ec1277807c 120 gs.printf("From Sat : Operation Stop...\r\n");
umeume 2:1c5cdb2c3e0f 121 }