rev20211120
Dependencies: HEPTA_SENSOR mbed HEPTA_EPS HEPTA_COM HEPTA_CDH
main.cpp@29:3d5175dfeb10, 2021-11-20 (annotated)
- Committer:
- heptasat2021
- Date:
- Sat Nov 20 07:32:30 2021 +0000
- Revision:
- 29:3d5175dfeb10
- Parent:
- 28:5c82ee674ad9
- Child:
- 30:e759c0f5f608
rev20211120
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" |
HeptaSatTraining2019 | 26:220e5f95168a | 5 | HEPTA_CDH cdh(p5, p6, p7, p8, "sd"); |
HeptaSatTraining2019 | 26:220e5f95168a | 6 | HEPTA_EPS eps(p16,p26); |
MEXT1 | 27:06ec1277807c | 7 | HEPTA_SENSOR sensor(p17, |
MEXT1 | 27:06ec1277807c | 8 | p28,p27,0xD0,0x18, |
MEXT1 | 27:06ec1277807c | 9 | p13,p14,p25,p24); |
heptasat2021 | 29:3d5175dfeb10 | 10 | DigitalOut condition(LED1); |
heptasat2021 | 29:3d5175dfeb10 | 11 | Serial gs(USBTX,USBRX,9600); |
heptasat2021 | 29:3d5175dfeb10 | 12 | Timer sattime; |
MEXT1 | 27:06ec1277807c | 13 | int rcmd = 0,cmdflag = 0; //command variable |
HeptaSatTraining2019 | 24:3659e0c223c8 | 14 | |
MEXT1 | 27:06ec1277807c | 15 | //getting command and flag |
HeptaSatTraining2019 | 26:220e5f95168a | 16 | void commandget() |
HeptaSatTraining2019 | 26:220e5f95168a | 17 | { |
MEXT1 | 27:06ec1277807c | 18 | rcmd=gs.getc(); |
HeptaSatTraining2019 | 26:220e5f95168a | 19 | cmdflag = 1; |
HeptaSatTraining2019 | 26:220e5f95168a | 20 | } |
MEXT1 | 27:06ec1277807c | 21 | //interrupting |
MEXT1 | 27:06ec1277807c | 22 | void receive(int rcmd, int cmdflag) |
HeptaSatTraining2019 | 26:220e5f95168a | 23 | { |
MEXT1 | 27:06ec1277807c | 24 | gs.attach(commandget,Serial::RxIrq); |
HeptaSatTraining2019 | 26:220e5f95168a | 25 | } |
MEXT1 | 27:06ec1277807c | 26 | //initialzing |
HeptaSatTraining2019 | 26:220e5f95168a | 27 | void initialize() |
HeptaSatTraining2019 | 26:220e5f95168a | 28 | { |
HeptaSatTraining2019 | 26:220e5f95168a | 29 | rcmd = 0; |
HeptaSatTraining2019 | 26:220e5f95168a | 30 | cmdflag = 0; |
heptasat2021 | 29:3d5175dfeb10 | 31 | condition = 0; |
HeptaSatTraining2019 | 26:220e5f95168a | 32 | } |
MEXT1 | 27:06ec1277807c | 33 | |
MEXT1 | 27:06ec1277807c | 34 | int main() { |
heptasat2021 | 29:3d5175dfeb10 | 35 | gs.printf("From Sat : Operation Start...\r\n"); |
heptasat2021 | 29:3d5175dfeb10 | 36 | int flag = 0; // condition |
heptasat2021 | 29:3d5175dfeb10 | 37 | float batvol,temp; //Voltage, Temerature |
MEXT1 | 27:06ec1277807c | 38 | float ax,ay,az; |
MEXT1 | 27:06ec1277807c | 39 | float gx,gy,gz; |
heptasat2021 | 29:3d5175dfeb10 | 40 | sattime.start(); |
MEXT1 | 27:06ec1277807c | 41 | receive(rcmd,cmdflag); //interupting by ground station command |
heptasat2021 | 29:3d5175dfeb10 | 42 | eps.turn_on_regulator();//turn on 3.3V conveter |
MEXT1 | 27:06ec1277807c | 43 | for(int i = 0; i < 100; i++) { |
heptasat2021 | 29:3d5175dfeb10 | 44 | //satellite condition led |
heptasat2021 | 29:3d5175dfeb10 | 45 | condition = !condition; |
HeptaSatTraining2019 | 28:5c82ee674ad9 | 46 | |
heptasat2021 | 29:3d5175dfeb10 | 47 | //senssing HK data(dummy data) |
heptasat2021 | 29:3d5175dfeb10 | 48 | eps.vol(&batvol); |
heptasat2021 | 29:3d5175dfeb10 | 49 | temp = 28.5; |
HeptaSatTraining2019 | 28:5c82ee674ad9 | 50 | |
heptasat2021 | 29:3d5175dfeb10 | 51 | //Transmitting HK data to Ground Station(GS) |
heptasat2021 | 29:3d5175dfeb10 | 52 | gs.printf("HEPTASAT::Condition = %d, Time = %f [s], batVol = %.2f [V],Temp = %.2f [C]\r\n",flag,sattime.read(),batvol,temp); |
heptasat2021 | 29:3d5175dfeb10 | 53 | wait_ms(1000); |
heptasat2021 | 29:3d5175dfeb10 | 54 | |
heptasat2021 | 29:3d5175dfeb10 | 55 | //Power Saving Mode |
heptasat2021 | 29:3d5175dfeb10 | 56 | if((batvol <= 3.5) | (temp > 35.0)){ |
heptasat2021 | 29:3d5175dfeb10 | 57 | eps.shut_down_regulator(); |
heptasat2021 | 29:3d5175dfeb10 | 58 | gs.printf("Power saving mode ON\r\n"); |
heptasat2021 | 29:3d5175dfeb10 | 59 | flag = 1; |
heptasat2021 | 29:3d5175dfeb10 | 60 | } else if((flag == 1) & (batvol > 3.7) & (temp <= 25.0)) { |
heptasat2021 | 29:3d5175dfeb10 | 61 | eps.turn_on_regulator(); |
heptasat2021 | 29:3d5175dfeb10 | 62 | gs.printf("Power saving mode OFF\r\n"); |
heptasat2021 | 29:3d5175dfeb10 | 63 | flag = 0; |
HeptaSatTraining2019 | 26:220e5f95168a | 64 | } |
HeptaSatTraining2019 | 28:5c82ee674ad9 | 65 | |
MEXT1 | 27:06ec1277807c | 66 | //Contents of command |
HeptaSatTraining2019 | 26:220e5f95168a | 67 | if (cmdflag == 1) { |
heptasat2021 | 29:3d5175dfeb10 | 68 | if(rcmd == 'a'){ |
heptasat2021 | 29:3d5175dfeb10 | 69 | for(int j=0;j<5;j++){ |
heptasat2021 | 29:3d5175dfeb10 | 70 | gs.printf("Hello World!\r\n"); |
heptasat2021 | 29:3d5175dfeb10 | 71 | condition = 1; |
heptasat2021 | 29:3d5175dfeb10 | 72 | wait_ms(1000); |
heptasat2021 | 29:3d5175dfeb10 | 73 | } |
heptasat2021 | 29:3d5175dfeb10 | 74 | }else if(rcmd == 'b') { |
MEXT1 | 27:06ec1277807c | 75 | char str[100]; |
MEXT1 | 27:06ec1277807c | 76 | mkdir("/sd/mydir", 0777); |
heptasat2021 | 29:3d5175dfeb10 | 77 | FILE *fp = fopen("/sd/mydir/satdata.txt","w"); |
MEXT1 | 27:06ec1277807c | 78 | if(fp == NULL) { |
MEXT1 | 27:06ec1277807c | 79 | error("Could not open file for write\r\n"); |
MEXT1 | 27:06ec1277807c | 80 | } |
heptasat2021 | 29:3d5175dfeb10 | 81 | for(int i = 0; i < 10; i++) { |
heptasat2021 | 29:3d5175dfeb10 | 82 | eps.vol(&batvol); |
heptasat2021 | 29:3d5175dfeb10 | 83 | fprintf(fp,"%f\r\n",batvol); |
heptasat2021 | 29:3d5175dfeb10 | 84 | condition = 1; |
heptasat2021 | 29:3d5175dfeb10 | 85 | wait_ms(1000); |
MEXT1 | 27:06ec1277807c | 86 | } |
heptasat2021 | 29:3d5175dfeb10 | 87 | fclose(fp); |
heptasat2021 | 29:3d5175dfeb10 | 88 | fp = fopen("/sd/mydir/satdata.txt","r"); |
heptasat2021 | 29:3d5175dfeb10 | 89 | for(int i = 0; i < 10; i++) { |
heptasat2021 | 29:3d5175dfeb10 | 90 | fgets(str,100,fp); |
heptasat2021 | 29:3d5175dfeb10 | 91 | gs.puts(str); |
heptasat2021 | 29:3d5175dfeb10 | 92 | } |
heptasat2021 | 29:3d5175dfeb10 | 93 | fclose(fp); |
heptasat2021 | 29:3d5175dfeb10 | 94 | }else if(rcmd == 'c'){ |
heptasat2021 | 29:3d5175dfeb10 | 95 | |
heptasat2021 | 29:3d5175dfeb10 | 96 | |
heptasat2021 | 29:3d5175dfeb10 | 97 | |
heptasat2021 | 29:3d5175dfeb10 | 98 | |
heptasat2021 | 29:3d5175dfeb10 | 99 | }else if(rcmd == 'd'){ |
heptasat2021 | 29:3d5175dfeb10 | 100 | |
heptasat2021 | 29:3d5175dfeb10 | 101 | |
heptasat2021 | 29:3d5175dfeb10 | 102 | |
HeptaSatTraining2019 | 26:220e5f95168a | 103 | } |
HeptaSatTraining2019 | 26:220e5f95168a | 104 | initialize(); |
HeptaSatTraining2019 | 26:220e5f95168a | 105 | } |
HeptaSatTraining2019 | 24:3659e0c223c8 | 106 | } |
heptasat2021 | 29:3d5175dfeb10 | 107 | sattime.stop(); |
MEXT1 | 27:06ec1277807c | 108 | gs.printf("From Sat : Operation Stop...\r\n"); |
umeume | 2:1c5cdb2c3e0f | 109 | } |