rev20211120
Dependencies: HEPTA_SENSOR mbed HEPTA_EPS HEPTA_COM HEPTA_CDH
main.cpp@27:06ec1277807c, 2020-07-22 (annotated)
- Committer:
- MEXT1
- Date:
- Wed Jul 22 03:09:47 2020 +0000
- Revision:
- 27:06ec1277807c
- Parent:
- 26:220e5f95168a
- Child:
- 28:5c82ee674ad9
202007
Who changed what in which revision?
User | Revision | Line number | New 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); |
MEXT1 | 27:06ec1277807c | 52 | //Condition |
MEXT1 | 27:06ec1277807c | 53 | cond[0] = 1; |
MEXT1 | 27:06ec1277807c | 54 | //Warning the status of temperature and battery voltage |
MEXT1 | 27:06ec1277807c | 55 | if(flag == 1) { |
MEXT1 | 27:06ec1277807c | 56 | gs.printf("Low Battery\r\n"); |
MEXT1 | 27:06ec1277807c | 57 | } else if(temp > 35.0) { |
MEXT1 | 27:06ec1277807c | 58 | gs.printf("High temperature\r\n"); |
MEXT1 | 27:06ec1277807c | 59 | } else if((flag == 1) & (temp > 35.0)) { |
MEXT1 | 27:06ec1277807c | 60 | gs.printf("Low Battery and High temperature\n"); |
HeptaSatTraining2019 | 26:220e5f95168a | 61 | } |
MEXT1 | 27:06ec1277807c | 62 | //Contents of command |
HeptaSatTraining2019 | 26:220e5f95168a | 63 | if (cmdflag == 1) { |
HeptaSatTraining2019 | 26:220e5f95168a | 64 | if (rcmd == 'a') { |
MEXT1 | 27:06ec1277807c | 65 | for(int j=0;j<5;j++){ |
MEXT1 | 27:06ec1277807c | 66 | gs.printf("HEPTASAT::Hello World!\r\n"); |
MEXT1 | 27:06ec1277807c | 67 | cond[0] = 0; |
MEXT1 | 27:06ec1277807c | 68 | wait(1); |
MEXT1 | 27:06ec1277807c | 69 | cond[0] = 1; |
MEXT1 | 27:06ec1277807c | 70 | } |
HeptaSatTraining2019 | 26:220e5f95168a | 71 | } |
HeptaSatTraining2019 | 26:220e5f95168a | 72 | if (rcmd == 'b') { |
MEXT1 | 27:06ec1277807c | 73 | char str[100]; |
MEXT1 | 27:06ec1277807c | 74 | mkdir("/sd/mydir", 0777); |
MEXT1 | 27:06ec1277807c | 75 | FILE *fp = fopen("/sd/mydir/test.txt","w"); |
MEXT1 | 27:06ec1277807c | 76 | if(fp == NULL) { |
MEXT1 | 27:06ec1277807c | 77 | error("Could not open file for write\r\n"); |
MEXT1 | 27:06ec1277807c | 78 | } |
MEXT1 | 27:06ec1277807c | 79 | else |
MEXT1 | 27:06ec1277807c | 80 | { |
MEXT1 | 27:06ec1277807c | 81 | for(int i = 0; i < 10; i++) { |
MEXT1 | 27:06ec1277807c | 82 | eps.vol(&btvol); |
MEXT1 | 27:06ec1277807c | 83 | fprintf(fp,"%f\r\n",btvol); |
MEXT1 | 27:06ec1277807c | 84 | wait(1.0); |
MEXT1 | 27:06ec1277807c | 85 | } |
MEXT1 | 27:06ec1277807c | 86 | fclose(fp); |
MEXT1 | 27:06ec1277807c | 87 | fp = fopen("/sd/mydir/test.txt","r"); |
MEXT1 | 27:06ec1277807c | 88 | for(int j = 0; j < 10; j++) { |
MEXT1 | 27:06ec1277807c | 89 | fgets(str,100,fp); |
MEXT1 | 27:06ec1277807c | 90 | puts(str); |
MEXT1 | 27:06ec1277807c | 91 | } |
MEXT1 | 27:06ec1277807c | 92 | fclose(fp); |
MEXT1 | 27:06ec1277807c | 93 | } |
MEXT1 | 27:06ec1277807c | 94 | cond[0] = 0; |
MEXT1 | 27:06ec1277807c | 95 | wait(1); |
MEXT1 | 27:06ec1277807c | 96 | cond[0] = 1; |
MEXT1 | 27:06ec1277807c | 97 | } |
MEXT1 | 27:06ec1277807c | 98 | if (rcmd == 'c') { |
HeptaSatTraining2019 | 26:220e5f95168a | 99 | |
HeptaSatTraining2019 | 26:220e5f95168a | 100 | |
HeptaSatTraining2019 | 26:220e5f95168a | 101 | |
HeptaSatTraining2019 | 26:220e5f95168a | 102 | |
MEXT1 | 27:06ec1277807c | 103 | } |
MEXT1 | 27:06ec1277807c | 104 | if (rcmd == 'd') { |
MEXT1 | 27:06ec1277807c | 105 | |
MEXT1 | 27:06ec1277807c | 106 | |
HeptaSatTraining2019 | 26:220e5f95168a | 107 | |
HeptaSatTraining2019 | 26:220e5f95168a | 108 | |
HeptaSatTraining2019 | 26:220e5f95168a | 109 | } |
HeptaSatTraining2019 | 26:220e5f95168a | 110 | initialize(); |
HeptaSatTraining2019 | 26:220e5f95168a | 111 | } |
MEXT1 | 27:06ec1277807c | 112 | |
MEXT1 | 27:06ec1277807c | 113 | //Operation Interval |
MEXT1 | 27:06ec1277807c | 114 | wait(1.0); |
MEXT1 | 27:06ec1277807c | 115 | sattime = sattime+1.0; |
HeptaSatTraining2019 | 24:3659e0c223c8 | 116 | } |
MEXT1 | 27:06ec1277807c | 117 | gs.printf("From Sat : Operation Stop...\r\n"); |
umeume | 2:1c5cdb2c3e0f | 118 | } |