Lab4-03_create_satcode_step5_lite
Dependencies: mbed HEPTA_CDH_lite HEPTA_SENSOR_lite HEPTA_EPS_lite
main.cpp@3:41cb41ed1fa3, 2021-08-24 (annotated)
- Committer:
- heptasat2021
- Date:
- Tue Aug 24 02:40:40 2021 +0000
- Revision:
- 3:41cb41ed1fa3
- Parent:
- 2:197079c5867f
For Hepta-Sat Lite
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
heptasat2021 | 0:da0f6aca15b8 | 1 | #include "mbed.h" |
heptasat2021 | 2:197079c5867f | 2 | #include "HEPTA_EPS.h" |
heptasat2021 | 1:ddac5ec89167 | 3 | #include "HEPTA_CDH.h" |
heptasat2021 | 2:197079c5867f | 4 | #include "HEPTA_SENSOR.h" |
heptasat2021 | 1:ddac5ec89167 | 5 | HEPTA_CDH cdh(PB_5, PB_4, PB_3, PA_8, "sd"); |
heptasat2021 | 2:197079c5867f | 6 | HEPTA_EPS eps(PA_0,PA_4); |
heptasat2021 | 2:197079c5867f | 7 | HEPTA_SENSOR sensor(PA_7,PB_7,PB_6,0xD0); |
heptasat2021 | 2:197079c5867f | 8 | DigitalOut condition(PB_1); |
heptasat2021 | 2:197079c5867f | 9 | Serial gs(USBTX,USBRX,9600); |
heptasat2021 | 2:197079c5867f | 10 | Timer sattime; |
heptasat2021 | 2:197079c5867f | 11 | int rcmd = 0, cmdflag = 0; //command variable |
heptasat2021 | 2:197079c5867f | 12 | |
heptasat2021 | 2:197079c5867f | 13 | //getting command and command flag |
heptasat2021 | 2:197079c5867f | 14 | void commandget() |
heptasat2021 | 2:197079c5867f | 15 | { |
heptasat2021 | 2:197079c5867f | 16 | rcmd = gs.getc(); |
heptasat2021 | 2:197079c5867f | 17 | cmdflag = 1; |
heptasat2021 | 2:197079c5867f | 18 | } |
heptasat2021 | 2:197079c5867f | 19 | //interrupting process by command receive |
heptasat2021 | 2:197079c5867f | 20 | void receive(int rcmd, int cmdflag) |
heptasat2021 | 2:197079c5867f | 21 | { |
heptasat2021 | 2:197079c5867f | 22 | gs.attach(commandget,Serial::RxIrq); |
heptasat2021 | 2:197079c5867f | 23 | } |
heptasat2021 | 2:197079c5867f | 24 | //initializing |
heptasat2021 | 2:197079c5867f | 25 | void initialize() |
heptasat2021 | 2:197079c5867f | 26 | { |
heptasat2021 | 2:197079c5867f | 27 | rcmd = 0; |
heptasat2021 | 2:197079c5867f | 28 | cmdflag = 0; |
heptasat2021 | 2:197079c5867f | 29 | condition = 0; |
heptasat2021 | 2:197079c5867f | 30 | } |
heptasat2021 | 2:197079c5867f | 31 | |
heptasat2021 | 0:da0f6aca15b8 | 32 | int main() |
heptasat2021 | 0:da0f6aca15b8 | 33 | { |
heptasat2021 | 2:197079c5867f | 34 | gs.printf("From Sat : Nominal Operation\r\n"); |
heptasat2021 | 2:197079c5867f | 35 | int flag = 0; //condition flag |
heptasat2021 | 2:197079c5867f | 36 | float batvol, temp; //voltage, temperature |
heptasat2021 | 2:197079c5867f | 37 | sattime.start(); |
heptasat2021 | 2:197079c5867f | 38 | receive(rcmd,cmdflag); //interrupting |
heptasat2021 | 2:197079c5867f | 39 | eps.turn_on_regulator();//turn on 3.3V conveter |
heptasat2021 | 3:41cb41ed1fa3 | 40 | sensor.setup(); |
heptasat2021 | 2:197079c5867f | 41 | for(int i=0;i<50;i++){ |
heptasat2021 | 2:197079c5867f | 42 | //satellite condition led |
heptasat2021 | 2:197079c5867f | 43 | condition = !condition; |
heptasat2021 | 2:197079c5867f | 44 | |
heptasat2021 | 2:197079c5867f | 45 | //senssing HK data |
heptasat2021 | 2:197079c5867f | 46 | eps.vol(&batvol); |
heptasat2021 | 2:197079c5867f | 47 | sensor.temp_sense(&temp); |
heptasat2021 | 2:197079c5867f | 48 | |
heptasat2021 | 2:197079c5867f | 49 | //Transmitting HK data to Ground Station(GS) |
heptasat2021 | 2:197079c5867f | 50 | gs.printf("HEPTASAT::Condition = %d, Time = %f [s], batvol = %2f [V], temp = %2f [deg C]\r\n",flag,sattime.read(),batvol,temp); |
heptasat2021 | 2:197079c5867f | 51 | wait_ms(1000); |
heptasat2021 | 2:197079c5867f | 52 | |
heptasat2021 | 2:197079c5867f | 53 | //Power Saving Mode |
heptasat2021 | 2:197079c5867f | 54 | if((batvol <= 3.5) | (temp > 35.0)){ |
heptasat2021 | 2:197079c5867f | 55 | eps.shut_down_regulator(); |
heptasat2021 | 2:197079c5867f | 56 | gs.printf("Power saving mode ON\r\n"); |
heptasat2021 | 2:197079c5867f | 57 | flag = 1; |
heptasat2021 | 2:197079c5867f | 58 | } else if((flag == 1) & (batvol > 3.7) & (temp <= 25.0)) { |
heptasat2021 | 2:197079c5867f | 59 | eps.turn_on_regulator(); |
heptasat2021 | 2:197079c5867f | 60 | gs.printf("Power saving mode OFF\r\n"); |
heptasat2021 | 2:197079c5867f | 61 | flag = 0; |
heptasat2021 | 2:197079c5867f | 62 | } |
heptasat2021 | 2:197079c5867f | 63 | |
heptasat2021 | 2:197079c5867f | 64 | if(cmdflag == 1){ |
heptasat2021 | 2:197079c5867f | 65 | if(rcmd == 'a'){ |
heptasat2021 | 2:197079c5867f | 66 | for(int j=0;j<5;j++){ |
heptasat2021 | 2:197079c5867f | 67 | gs.printf("Hello World!\r\n"); |
heptasat2021 | 2:197079c5867f | 68 | condition = 1; |
heptasat2021 | 2:197079c5867f | 69 | wait_ms(1000); |
heptasat2021 | 2:197079c5867f | 70 | } |
heptasat2021 | 2:197079c5867f | 71 | }else if(rcmd == 'b') { |
heptasat2021 | 2:197079c5867f | 72 | char str[100]; |
heptasat2021 | 2:197079c5867f | 73 | mkdir("/sd/mydir", 0777); |
heptasat2021 | 2:197079c5867f | 74 | FILE *fp = fopen("/sd/mydir/satdata.txt","w"); |
heptasat2021 | 2:197079c5867f | 75 | if(fp == NULL) { |
heptasat2021 | 2:197079c5867f | 76 | error("Could not open file for write\r\n"); |
heptasat2021 | 2:197079c5867f | 77 | } |
heptasat2021 | 2:197079c5867f | 78 | for(int i = 0; i < 10; i++) { |
heptasat2021 | 2:197079c5867f | 79 | eps.vol(&batvol); |
heptasat2021 | 2:197079c5867f | 80 | fprintf(fp,"%f\r\n",batvol); |
heptasat2021 | 2:197079c5867f | 81 | condition = 1; |
heptasat2021 | 2:197079c5867f | 82 | wait_ms(1000); |
heptasat2021 | 2:197079c5867f | 83 | } |
heptasat2021 | 2:197079c5867f | 84 | fclose(fp); |
heptasat2021 | 2:197079c5867f | 85 | fp = fopen("/sd/mydir/satdata.txt","r"); |
heptasat2021 | 2:197079c5867f | 86 | for(int i = 0; i < 10; i++) { |
heptasat2021 | 2:197079c5867f | 87 | fgets(str,100,fp); |
heptasat2021 | 2:197079c5867f | 88 | gs.puts(str); |
heptasat2021 | 2:197079c5867f | 89 | } |
heptasat2021 | 2:197079c5867f | 90 | fclose(fp); |
heptasat2021 | 2:197079c5867f | 91 | }else if(rcmd == 'c'){ |
heptasat2021 | 2:197079c5867f | 92 | float ax,ay,az; |
heptasat2021 | 2:197079c5867f | 93 | for(int i = 0; i < 10; i++) { |
heptasat2021 | 2:197079c5867f | 94 | sensor.sen_acc(&ax,&ay,&az); |
heptasat2021 | 2:197079c5867f | 95 | gs.printf("%f,%f,%f\r\n",ax,ay,az); |
heptasat2021 | 2:197079c5867f | 96 | wait_ms(1000); |
heptasat2021 | 2:197079c5867f | 97 | } |
heptasat2021 | 2:197079c5867f | 98 | }else if(rcmd == 'd'){ |
heptasat2021 | 2:197079c5867f | 99 | float gx,gy,gz; |
heptasat2021 | 2:197079c5867f | 100 | for(int i = 0; i < 10; i++) { |
heptasat2021 | 2:197079c5867f | 101 | sensor.sen_gyro(&gx,&gy,&gz); |
heptasat2021 | 2:197079c5867f | 102 | gs.printf("%f,%f,%f\r\n",gx,gy,gz); |
heptasat2021 | 2:197079c5867f | 103 | wait_ms(1000); |
heptasat2021 | 2:197079c5867f | 104 | } |
heptasat2021 | 2:197079c5867f | 105 | } |
heptasat2021 | 2:197079c5867f | 106 | initialize(); //initializing |
heptasat2021 | 2:197079c5867f | 107 | } |
heptasat2021 | 0:da0f6aca15b8 | 108 | } |
heptasat2021 | 2:197079c5867f | 109 | sattime.stop(); |
heptasat2021 | 2:197079c5867f | 110 | gs.printf("From Sat : End of operation\r\n"); |
heptasat2021 | 0:da0f6aca15b8 | 111 | } |