for_20211114
Dependencies: HEPTA_SENSOR mbed HEPTA_EPS HEPTA_COM HEPTA_CDH
main.cpp@30:c95e6e3f302a, 2021-11-14 (annotated)
- Committer:
- heptasat2021
- Date:
- Sun Nov 14 10:40:07 2021 +0000
- Revision:
- 30:c95e6e3f302a
- Parent:
- 29:3d7a0b3a1b8a
20211114
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" |
HeptaSatTraining2019 | 26:220e5f95168a | 4 | HEPTA_CDH cdh(p5, p6, p7, p8, "sd"); |
HeptaSatTraining2019 | 26:220e5f95168a | 5 | HEPTA_EPS eps(p16,p26); |
heptasat2021 | 29:3d7a0b3a1b8a | 6 | DigitalOut condition(LED1); |
heptasat2021 | 29:3d7a0b3a1b8a | 7 | Serial gs(USBTX,USBRX,9600); |
heptasat2021 | 28:80d6576011e1 | 8 | Timer sattime; |
heptasat2021 | 29:3d7a0b3a1b8a | 9 | int rcmd = 0, cmdflag = 0; //command variable |
HeptaSatTraining2019 | 24:3659e0c223c8 | 10 | |
MEXT1 | 27:ecdf196153cd | 11 | //getting command and flag |
HeptaSatTraining2019 | 26:220e5f95168a | 12 | void commandget() |
HeptaSatTraining2019 | 26:220e5f95168a | 13 | { |
heptasat2021 | 29:3d7a0b3a1b8a | 14 | rcmd = gs.getc(); |
HeptaSatTraining2019 | 26:220e5f95168a | 15 | cmdflag = 1; |
HeptaSatTraining2019 | 26:220e5f95168a | 16 | } |
MEXT1 | 27:ecdf196153cd | 17 | //interrupting |
MEXT1 | 27:ecdf196153cd | 18 | void receive(int rcmd, int cmdflag) |
HeptaSatTraining2019 | 26:220e5f95168a | 19 | { |
MEXT1 | 27:ecdf196153cd | 20 | gs.attach(commandget,Serial::RxIrq); |
HeptaSatTraining2019 | 26:220e5f95168a | 21 | } |
MEXT1 | 27:ecdf196153cd | 22 | //initialzing |
HeptaSatTraining2019 | 26:220e5f95168a | 23 | void initialize() |
HeptaSatTraining2019 | 26:220e5f95168a | 24 | { |
HeptaSatTraining2019 | 26:220e5f95168a | 25 | rcmd = 0; |
HeptaSatTraining2019 | 26:220e5f95168a | 26 | cmdflag = 0; |
heptasat2021 | 29:3d7a0b3a1b8a | 27 | condition = 0; |
HeptaSatTraining2019 | 26:220e5f95168a | 28 | } |
MEXT1 | 27:ecdf196153cd | 29 | |
heptasat2021 | 29:3d7a0b3a1b8a | 30 | int main() |
heptasat2021 | 29:3d7a0b3a1b8a | 31 | { |
MEXT1 | 27:ecdf196153cd | 32 | gs.printf("From Sat : Operation Start...\r\n"); |
heptasat2021 | 29:3d7a0b3a1b8a | 33 | int flag = 0; // condition |
heptasat2021 | 29:3d7a0b3a1b8a | 34 | float batvol,temp; //Voltage, Temerature |
heptasat2021 | 28:80d6576011e1 | 35 | sattime.start(); |
MEXT1 | 27:ecdf196153cd | 36 | receive(rcmd,cmdflag); //interupting by ground station command |
heptasat2021 | 29:3d7a0b3a1b8a | 37 | eps.turn_on_regulator();//turn on 3.3V conveter |
MEXT1 | 27:ecdf196153cd | 38 | for(int i = 0; i < 100; i++) { |
heptasat2021 | 29:3d7a0b3a1b8a | 39 | //satellite condition led |
heptasat2021 | 29:3d7a0b3a1b8a | 40 | condition = !condition; |
heptasat2021 | 29:3d7a0b3a1b8a | 41 | |
heptasat2021 | 29:3d7a0b3a1b8a | 42 | //senssing HK data(dummy data) |
heptasat2021 | 29:3d7a0b3a1b8a | 43 | eps.vol(&batvol); |
heptasat2021 | 29:3d7a0b3a1b8a | 44 | temp = 28.5; |
heptasat2021 | 29:3d7a0b3a1b8a | 45 | |
heptasat2021 | 29:3d7a0b3a1b8a | 46 | //Transmitting HK data to Ground Station(GS) |
heptasat2021 | 29:3d7a0b3a1b8a | 47 | gs.printf("HEPTASAT::Condition = %d, Time = %f [s], batVol = %.2f [V],Temp = %.2f [C]\r\n",flag,sattime.read(),batvol,temp); |
heptasat2021 | 29:3d7a0b3a1b8a | 48 | wait_ms(1000); |
heptasat2021 | 29:3d7a0b3a1b8a | 49 | |
heptasat2021 | 29:3d7a0b3a1b8a | 50 | //Power Saving Mode |
heptasat2021 | 29:3d7a0b3a1b8a | 51 | if(batvol <= 3.5){ |
HeptaSatTraining2019 | 26:220e5f95168a | 52 | eps.shut_down_regulator(); |
heptasat2021 | 29:3d7a0b3a1b8a | 53 | gs.printf("Power saving mode ON\r\n"); |
HeptaSatTraining2019 | 26:220e5f95168a | 54 | flag = 1; |
heptasat2021 | 29:3d7a0b3a1b8a | 55 | } else if((flag == 1) & (batvol > 3.7)) { |
HeptaSatTraining2019 | 26:220e5f95168a | 56 | eps.turn_on_regulator(); |
heptasat2021 | 29:3d7a0b3a1b8a | 57 | gs.printf("Power saving mode OFF\r\n"); |
HeptaSatTraining2019 | 26:220e5f95168a | 58 | flag = 0; |
HeptaSatTraining2019 | 26:220e5f95168a | 59 | } |
heptasat2021 | 29:3d7a0b3a1b8a | 60 | |
HeptaSatTraining2019 | 26:220e5f95168a | 61 | if (cmdflag == 1) { |
HeptaSatTraining2019 | 26:220e5f95168a | 62 | if (rcmd == 'a') { |
MEXT1 | 27:ecdf196153cd | 63 | for(int j=0;j<5;j++){ |
MEXT1 | 27:ecdf196153cd | 64 | gs.printf("HEPTASAT::Hello World!\r\n"); |
heptasat2021 | 29:3d7a0b3a1b8a | 65 | condition = 1; |
heptasat2021 | 29:3d7a0b3a1b8a | 66 | wait_ms(1000); |
MEXT1 | 27:ecdf196153cd | 67 | } |
heptasat2021 | 29:3d7a0b3a1b8a | 68 | }else if(rcmd == 'b') { |
heptasat2021 | 29:3d7a0b3a1b8a | 69 | |
heptasat2021 | 29:3d7a0b3a1b8a | 70 | |
heptasat2021 | 29:3d7a0b3a1b8a | 71 | |
heptasat2021 | 29:3d7a0b3a1b8a | 72 | |
HeptaSatTraining2019 | 26:220e5f95168a | 73 | } |
HeptaSatTraining2019 | 26:220e5f95168a | 74 | initialize(); |
HeptaSatTraining2019 | 26:220e5f95168a | 75 | } |
HeptaSatTraining2019 | 24:3659e0c223c8 | 76 | } |
heptasat2021 | 28:80d6576011e1 | 77 | sattime.stop(); |
MEXT1 | 27:ecdf196153cd | 78 | gs.printf("From Sat : Operation Stop...\r\n"); |
umeume | 2:1c5cdb2c3e0f | 79 | } |