![](/media/cache/profiles/2e74f94b232c5a0cc3e75b4eaaf64c90.jpg.50x50_q85.jpg)
simulate satellite program structure
Dependencies: mbed HeptaBattery SDFileSystem HeptaCamera_GPS Hepta9axis HeptaTemp
Fork of Lab7-01_template by
main.cpp@19:7eb79d010c3c, 2019-08-20 (annotated)
- Committer:
- HEPTA
- Date:
- Tue Aug 20 10:07:46 2019 +0000
- Revision:
- 19:7eb79d010c3c
- Parent:
- 17:2b3b88724c68
revision;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:bdbd3d6fc5d5 | 1 | #include "mbed.h" |
mbed_official | 0:bdbd3d6fc5d5 | 2 | #include "SDFileSystem.h" |
HEPTA | 17:2b3b88724c68 | 3 | #include "HeptaBattery.h" |
umeume | 2:1c5cdb2c3e0f | 4 | #include "HeptaCamera_GPS.h" |
umeume | 2:1c5cdb2c3e0f | 5 | #include "Hepta9axis.h" |
umeume | 2:1c5cdb2c3e0f | 6 | #include "HeptaTemp.h" |
umeume | 2:1c5cdb2c3e0f | 7 | |
umeume | 2:1c5cdb2c3e0f | 8 | Serial pc(USBTX,USBRX); |
HEPTA | 9:942eb6e8c117 | 9 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
HEPTA | 17:2b3b88724c68 | 10 | HeptaBattery battery(p16,p26); |
umeume | 2:1c5cdb2c3e0f | 11 | HeptaCamera_GPS cam_gps(p13, p14,p25,p24); |
HEPTA | 10:4d6870d0caa0 | 12 | Hepta9axis n_axis(p28,p27,0xD0,0x18); |
HEPTA | 7:fab080b8be64 | 13 | HeptaTemp temp(p17); |
HEPTA | 17:2b3b88724c68 | 14 | |
HEPTA | 17:2b3b88724c68 | 15 | DigitalOut myleds[] = {LED1,LED2,LED3,LED4};; |
HEPTA | 17:2b3b88724c68 | 16 | |
HEPTA | 17:2b3b88724c68 | 17 | int rcmd = 0,cmdflag = 0; |
umeume | 2:1c5cdb2c3e0f | 18 | |
HEPTA | 17:2b3b88724c68 | 19 | void commandget() |
HEPTA | 17:2b3b88724c68 | 20 | { |
HEPTA | 17:2b3b88724c68 | 21 | rcmd=pc.getc(); |
HEPTA | 17:2b3b88724c68 | 22 | cmdflag = 1; |
HEPTA | 17:2b3b88724c68 | 23 | } |
HEPTA | 17:2b3b88724c68 | 24 | void receive(int *xrcmd, int *xcmdflag) |
HEPTA | 17:2b3b88724c68 | 25 | { |
HEPTA | 17:2b3b88724c68 | 26 | pc.attach(commandget,Serial::RxIrq); |
HEPTA | 17:2b3b88724c68 | 27 | *xrcmd = rcmd; |
HEPTA | 17:2b3b88724c68 | 28 | *xcmdflag = cmdflag; |
HEPTA | 17:2b3b88724c68 | 29 | } |
HEPTA | 17:2b3b88724c68 | 30 | |
HEPTA | 17:2b3b88724c68 | 31 | void initialize() |
HEPTA | 17:2b3b88724c68 | 32 | { |
HEPTA | 17:2b3b88724c68 | 33 | rcmd = 0; |
HEPTA | 17:2b3b88724c68 | 34 | cmdflag = 0; |
HEPTA | 17:2b3b88724c68 | 35 | } |
umeume | 5:c5ccb1b07e8f | 36 | |
umeume | 2:1c5cdb2c3e0f | 37 | int main() |
umeume | 2:1c5cdb2c3e0f | 38 | { |
HEPTA | 17:2b3b88724c68 | 39 | pc.baud(9600); |
HEPTA | 17:2b3b88724c68 | 40 | float bt; |
HEPTA | 17:2b3b88724c68 | 41 | float temper; |
HEPTA | 17:2b3b88724c68 | 42 | char str[100]; |
HEPTA | 17:2b3b88724c68 | 43 | float ax,ay,az; |
HEPTA | 17:2b3b88724c68 | 44 | float gx,gy,gz; |
HEPTA | 17:2b3b88724c68 | 45 | float mx,my,mz; |
HEPTA | 17:2b3b88724c68 | 46 | int quality=0,stnum=0,gps_check=0; |
HEPTA | 17:2b3b88724c68 | 47 | char ns='A',ew='B',aunit='m'; |
HEPTA | 17:2b3b88724c68 | 48 | float time=0.0,latitude=0.0,longitude=0.0,hacu=0.0,altitude=0.0; |
HEPTA | 17:2b3b88724c68 | 49 | int flag = 0; |
HEPTA | 19:7eb79d010c3c | 50 | receive(&rcmd,&cmdflag); |
HEPTA | 17:2b3b88724c68 | 51 | while(1) { |
HEPTA | 17:2b3b88724c68 | 52 | battery.power_saving_mode(&flag,&bt); |
HEPTA | 17:2b3b88724c68 | 53 | temp.temp_sense(&temper); |
HEPTA | 17:2b3b88724c68 | 54 | wait(0.5); |
HEPTA | 17:2b3b88724c68 | 55 | pc.printf("flag = %d, bt = %.2f [V], temp = %.1f [C]\r\n",flag,bt,temper); |
HEPTA | 17:2b3b88724c68 | 56 | if(flag == 1) { |
HEPTA | 17:2b3b88724c68 | 57 | pc.printf("Low Battery\r\n"); |
HEPTA | 17:2b3b88724c68 | 58 | } else if(temper > 35.0) { |
HEPTA | 17:2b3b88724c68 | 59 | pc.printf("High Temperaturer\n"); |
HEPTA | 17:2b3b88724c68 | 60 | } else if((flag == 1) & (temper > 35.0)) { |
HEPTA | 17:2b3b88724c68 | 61 | pc.printf("Low Battery and High Temperaturer\n"); |
HEPTA | 17:2b3b88724c68 | 62 | } |
HEPTA | 17:2b3b88724c68 | 63 | if (cmdflag == 1) { |
HEPTA | 17:2b3b88724c68 | 64 | pc.printf("Command Get = %d\r\n",rcmd); |
HEPTA | 17:2b3b88724c68 | 65 | if (rcmd == 'a') { |
HEPTA | 17:2b3b88724c68 | 66 | for(int i = 0; i < 10; i++) { |
HEPTA | 17:2b3b88724c68 | 67 | pc.printf("Count = %d\r\n",i); |
HEPTA | 17:2b3b88724c68 | 68 | wait(1.0); |
HEPTA | 17:2b3b88724c68 | 69 | } |
HEPTA | 17:2b3b88724c68 | 70 | } |
HEPTA | 17:2b3b88724c68 | 71 | if (rcmd == 'b') { |
HEPTA | 17:2b3b88724c68 | 72 | mkdir("/sd/mydir", 0777); |
HEPTA | 17:2b3b88724c68 | 73 | FILE *fp = fopen("/sd/mydir/battery.txt","w"); |
HEPTA | 17:2b3b88724c68 | 74 | if(fp == NULL) { |
HEPTA | 17:2b3b88724c68 | 75 | error("Could not open file for write\r\n"); |
HEPTA | 17:2b3b88724c68 | 76 | } else { |
HEPTA | 17:2b3b88724c68 | 77 | for(int i = 0; i < 10; i++) { |
HEPTA | 17:2b3b88724c68 | 78 | battery.vol(&bt); |
HEPTA | 17:2b3b88724c68 | 79 | fprintf(fp,"%f\r\n",bt); |
HEPTA | 17:2b3b88724c68 | 80 | wait(1.0); |
HEPTA | 17:2b3b88724c68 | 81 | } |
HEPTA | 17:2b3b88724c68 | 82 | fclose(fp); |
HEPTA | 17:2b3b88724c68 | 83 | } |
HEPTA | 17:2b3b88724c68 | 84 | FILE *fp1 = fopen("/sd/mydir/battery.txt","r"); |
HEPTA | 17:2b3b88724c68 | 85 | if(fp1 == NULL) { |
HEPTA | 17:2b3b88724c68 | 86 | error("Could not open file for read\r\n"); |
HEPTA | 17:2b3b88724c68 | 87 | } else { |
HEPTA | 17:2b3b88724c68 | 88 | for(int i = 0; i < 10; i++) { |
HEPTA | 17:2b3b88724c68 | 89 | fgets(str,100,fp1); |
HEPTA | 17:2b3b88724c68 | 90 | puts(str); |
HEPTA | 17:2b3b88724c68 | 91 | wait(1.0); |
HEPTA | 17:2b3b88724c68 | 92 | } |
HEPTA | 17:2b3b88724c68 | 93 | fclose(fp1); |
HEPTA | 17:2b3b88724c68 | 94 | } |
HEPTA | 17:2b3b88724c68 | 95 | }// |
HEPTA | 17:2b3b88724c68 | 96 | if (rcmd == 'c') { |
HEPTA | 17:2b3b88724c68 | 97 | |
HEPTA | 17:2b3b88724c68 | 98 | |
HEPTA | 17:2b3b88724c68 | 99 | |
HEPTA | 17:2b3b88724c68 | 100 | |
HEPTA | 17:2b3b88724c68 | 101 | } |
HEPTA | 17:2b3b88724c68 | 102 | if (rcmd == 'd') { |
HEPTA | 17:2b3b88724c68 | 103 | |
HEPTA | 17:2b3b88724c68 | 104 | |
HEPTA | 17:2b3b88724c68 | 105 | |
HEPTA | 17:2b3b88724c68 | 106 | |
HEPTA | 17:2b3b88724c68 | 107 | } |
HEPTA | 17:2b3b88724c68 | 108 | initialize(); |
HEPTA | 17:2b3b88724c68 | 109 | } |
HEPTA | 17:2b3b88724c68 | 110 | } |
umeume | 2:1c5cdb2c3e0f | 111 | } |