hepta
Dependencies: HEPTA_CDH HEPTA_COM HEPTA_EPS HEPTA_SENSOR mbed
main.cpp@33:000a098179f4, 18 months ago (annotated)
- Committer:
- RyusukeIwata
- Date:
- Mon Nov 14 13:02:02 2022 +0000
- Revision:
- 33:000a098179f4
- Parent:
- 32:c22cbcfb4635
changed to rawserial
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:b4689aa48bf5 | 4 | #include "HEPTA_SENSOR.h" |
MEXT1 | 27:b4689aa48bf5 | 5 | #include "HEPTA_COM.h" |
HeptaSatTraining2019 | 26:220e5f95168a | 6 | HEPTA_CDH cdh(p5, p6, p7, p8, "sd"); |
HeptaSatTraining2019 | 26:220e5f95168a | 7 | HEPTA_EPS eps(p16,p26); |
MEXT1 | 27:b4689aa48bf5 | 8 | HEPTA_SENSOR sensor(p17, |
csmk18112 | 32:c22cbcfb4635 | 9 | p28,p27,0x19,0x69,0x13, |
csmk18112 | 32:c22cbcfb4635 | 10 | p13, p14,p25,p24); |
heptasat2021 | 29:eb84063fe5c9 | 11 | HEPTA_COM com(p9,p10); |
heptasat2021 | 29:eb84063fe5c9 | 12 | DigitalOut condition(LED1); |
RyusukeIwata | 33:000a098179f4 | 13 | RawSerial sat(USBTX,USBRX,9600); |
heptasat2021 | 29:eb84063fe5c9 | 14 | Timer sattime; |
MEXT1 | 27:b4689aa48bf5 | 15 | int rcmd = 0,cmdflag = 0; //command variable |
heptasat2021 | 29:eb84063fe5c9 | 16 | |
MEXT1 | 27:b4689aa48bf5 | 17 | int main() { |
heptasat2021 | 29:eb84063fe5c9 | 18 | sat.printf("From Sat : Nominal Operation\r\n"); |
heptasat2021 | 29:eb84063fe5c9 | 19 | com.printf("From Sat : Nominal Operation\r\n"); |
heptasat2021 | 29:eb84063fe5c9 | 20 | int flag = 0; //condition flag |
heptasat2021 | 29:eb84063fe5c9 | 21 | float batvol, temp; //voltage, temperature |
heptasat2021 | 29:eb84063fe5c9 | 22 | int rcmd=0,cmdflag=0; //command variable |
heptasat2021 | 29:eb84063fe5c9 | 23 | sattime.start(); |
heptasat2021 | 29:eb84063fe5c9 | 24 | eps.turn_on_regulator();//turn on 3.3V conveter |
MEXT1 | 27:b4689aa48bf5 | 25 | for(int i = 0; i < 100; i++) { |
heptasat2021 | 30:f300d1e88f4c | 26 | com.xbee_receive(&rcmd,&cmdflag);//interupting by ground station command |
heptasat2021 | 30:f300d1e88f4c | 27 | |
heptasat2021 | 29:eb84063fe5c9 | 28 | //satellite condition led |
heptasat2021 | 29:eb84063fe5c9 | 29 | condition = !condition; |
heptasat2021 | 29:eb84063fe5c9 | 30 | |
heptasat2021 | 29:eb84063fe5c9 | 31 | //senssing HK data(dummy data) |
heptasat2021 | 29:eb84063fe5c9 | 32 | eps.vol(&batvol); |
MEXT1 | 27:b4689aa48bf5 | 33 | sensor.temp_sense(&temp); |
heptasat2021 | 29:eb84063fe5c9 | 34 | |
heptasat2021 | 29:eb84063fe5c9 | 35 | //Transmitting HK data to Ground Station(GS) |
heptasat2021 | 29:eb84063fe5c9 | 36 | com.printf("HEPTASAT::Condition = %d, Time = %f [s], batVol = %.2f [V],Temp = %.2f [C]\r\n",flag,sattime.read(),batvol,temp); |
heptasat2021 | 29:eb84063fe5c9 | 37 | wait_ms(1000); |
heptasat2021 | 29:eb84063fe5c9 | 38 | |
heptasat2021 | 29:eb84063fe5c9 | 39 | //Power Saving Mode |
heptasat2021 | 29:eb84063fe5c9 | 40 | if((batvol <= 3.5) | (temp > 35.0)){ |
heptasat2021 | 29:eb84063fe5c9 | 41 | eps.shut_down_regulator(); |
heptasat2021 | 29:eb84063fe5c9 | 42 | com.printf("Power saving mode ON\r\n"); |
heptasat2021 | 29:eb84063fe5c9 | 43 | flag = 1; |
heptasat2021 | 29:eb84063fe5c9 | 44 | } else if((flag == 1) & (batvol > 3.7) & (temp <= 25.0)) { |
heptasat2021 | 29:eb84063fe5c9 | 45 | eps.turn_on_regulator(); |
heptasat2021 | 29:eb84063fe5c9 | 46 | com.printf("Power saving mode OFF\r\n"); |
heptasat2021 | 29:eb84063fe5c9 | 47 | flag = 0; |
HeptaSatTraining2019 | 26:220e5f95168a | 48 | } |
MEXT1 | 27:b4689aa48bf5 | 49 | //Contents of command |
HeptaSatTraining2019 | 26:220e5f95168a | 50 | if (cmdflag == 1) { |
HeptaSatTraining2019 | 26:220e5f95168a | 51 | if (rcmd == 'a') { |
heptasat2021 | 29:eb84063fe5c9 | 52 | sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag); |
heptasat2021 | 29:eb84063fe5c9 | 53 | com.printf("Hepta-Sat Lite Uplink Ok\r\n"); |
heptasat2021 | 29:eb84063fe5c9 | 54 | for(int j=0;j<5;j++){ |
heptasat2021 | 29:eb84063fe5c9 | 55 | com.printf("Hello World!\r\n"); |
heptasat2021 | 29:eb84063fe5c9 | 56 | condition = 1; |
heptasat2021 | 29:eb84063fe5c9 | 57 | wait_ms(1000); |
heptasat2021 | 29:eb84063fe5c9 | 58 | } |
heptasat2021 | 29:eb84063fe5c9 | 59 | }else if (rcmd == 'b') { |
heptasat2021 | 29:eb84063fe5c9 | 60 | sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag); |
heptasat2021 | 29:eb84063fe5c9 | 61 | com.printf("Hepta-Sat Lite Uplink Ok\r\n"); |
MEXT1 | 27:b4689aa48bf5 | 62 | char str[100]; |
MEXT1 | 27:b4689aa48bf5 | 63 | mkdir("/sd/mydir", 0777); |
heptasat2021 | 29:eb84063fe5c9 | 64 | FILE *fp = fopen("/sd/mydir/satdata.txt","w"); |
MEXT1 | 27:b4689aa48bf5 | 65 | if(fp == NULL) { |
MEXT1 | 27:b4689aa48bf5 | 66 | error("Could not open file for write\r\n"); |
MEXT1 | 27:b4689aa48bf5 | 67 | } |
heptasat2021 | 29:eb84063fe5c9 | 68 | for(int i = 0; i < 10; i++) { |
heptasat2021 | 29:eb84063fe5c9 | 69 | eps.vol(&batvol); |
heptasat2021 | 29:eb84063fe5c9 | 70 | fprintf(fp,"%f\r\n",batvol); |
heptasat2021 | 29:eb84063fe5c9 | 71 | condition = 1; |
heptasat2021 | 29:eb84063fe5c9 | 72 | wait_ms(1000); |
MEXT1 | 27:b4689aa48bf5 | 73 | } |
heptasat2021 | 29:eb84063fe5c9 | 74 | fclose(fp); |
heptasat2021 | 29:eb84063fe5c9 | 75 | fp = fopen("/sd/mydir/satdata.txt","r"); |
heptasat2021 | 29:eb84063fe5c9 | 76 | for(int i = 0; i < 10; i++) { |
heptasat2021 | 29:eb84063fe5c9 | 77 | fgets(str,100,fp); |
heptasat2021 | 29:eb84063fe5c9 | 78 | com.puts(str); |
heptasat2021 | 29:eb84063fe5c9 | 79 | } |
heptasat2021 | 29:eb84063fe5c9 | 80 | fclose(fp); |
heptasat2021 | 29:eb84063fe5c9 | 81 | }else if (rcmd == 'c') { |
heptasat2021 | 29:eb84063fe5c9 | 82 | //Please insert your answer |
heptasat2021 | 29:eb84063fe5c9 | 83 | |
heptasat2021 | 29:eb84063fe5c9 | 84 | }else if (rcmd == 'd') { |
heptasat2021 | 29:eb84063fe5c9 | 85 | //Please insert your answer |
heptasat2021 | 29:eb84063fe5c9 | 86 | |
heptasat2021 | 29:eb84063fe5c9 | 87 | }else if (rcmd == 'e') { |
heptasat2021 | 29:eb84063fe5c9 | 88 | //Please insert your answer |
heptasat2021 | 29:eb84063fe5c9 | 89 | |
HeptaSatTraining2019 | 26:220e5f95168a | 90 | } |
heptasat2021 | 30:f300d1e88f4c | 91 | com.initialize(); |
HeptaSatTraining2019 | 26:220e5f95168a | 92 | } |
HeptaSatTraining2019 | 24:3659e0c223c8 | 93 | } |
heptasat2021 | 29:eb84063fe5c9 | 94 | sattime.stop(); |
heptasat2021 | 29:eb84063fe5c9 | 95 | sat.printf("From Sat : End of operation\r\n"); |
heptasat2021 | 29:eb84063fe5c9 | 96 | com.printf("From Sat : End of operation\r\n"); |
MEXT1 | 27:b4689aa48bf5 | 97 | } |