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