![](/media/cache/profiles/2e74f94b232c5a0cc3e75b4eaaf64c90.jpg.50x50_q85.jpg)
simulate satellite program structure
Dependencies: mbed HeptaBattery SDFileSystem HeptaCamera_GPS Hepta9axis HeptaTemp HeptaXbee
Fork of Lab7-01_template by
main.cpp@17:e83f07212ed3, 2018-08-08 (annotated)
- Committer:
- HEPTA
- Date:
- Wed Aug 08 11:02:16 2018 +0000
- Revision:
- 17:e83f07212ed3
- Parent:
- 13:a1fa75a002f6
- Child:
- 20:8bc48b6ac23d
simulate satellite program structure
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" |
umeume | 2:1c5cdb2c3e0f | 3 | #include "HeptaXbee.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 | #include "HeptaBattery.h" |
umeume | 2:1c5cdb2c3e0f | 8 | |
umeume | 2:1c5cdb2c3e0f | 9 | Serial pc(USBTX,USBRX); |
HEPTA | 9:942eb6e8c117 | 10 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
umeume | 2:1c5cdb2c3e0f | 11 | HeptaXbee xbee(p9,p10); |
umeume | 2:1c5cdb2c3e0f | 12 | HeptaCamera_GPS cam_gps(p13, p14,p25,p24); |
HEPTA | 10:4d6870d0caa0 | 13 | Hepta9axis n_axis(p28,p27,0xD0,0x18); |
HEPTA | 7:fab080b8be64 | 14 | HeptaTemp temp(p17); |
HEPTA | 13:a1fa75a002f6 | 15 | HeptaBattery battery(p16,p26); |
umeume | 2:1c5cdb2c3e0f | 16 | |
HEPTA | 17:e83f07212ed3 | 17 | DigitalOut myleds[] = {LED1,LED2,LED3,LED4};; |
umeume | 5:c5ccb1b07e8f | 18 | |
umeume | 2:1c5cdb2c3e0f | 19 | int main() |
umeume | 2:1c5cdb2c3e0f | 20 | { |
HEPTA | 17:e83f07212ed3 | 21 | pc.baud(9600); |
HEPTA | 17:e83f07212ed3 | 22 | float bt; |
HEPTA | 17:e83f07212ed3 | 23 | float temper; |
HEPTA | 17:e83f07212ed3 | 24 | char str[100]; |
HEPTA | 17:e83f07212ed3 | 25 | char gx[4],gy[4],gz[4],ax[4],ay[4],az[4],mx[4],my[4],mz[4],lad[8],log[8],height[4],bat[4],temperature[4]; |
HEPTA | 17:e83f07212ed3 | 26 | int flag = 0; |
HEPTA | 17:e83f07212ed3 | 27 | int rcmd=0,cmdflag=0; |
HEPTA | 17:e83f07212ed3 | 28 | while(1) { |
HEPTA | 17:e83f07212ed3 | 29 | battery.power_saving_mode(&flag,&bt); |
HEPTA | 17:e83f07212ed3 | 30 | temp.temp_sense(&temper); |
HEPTA | 17:e83f07212ed3 | 31 | wait(0.5); |
HEPTA | 17:e83f07212ed3 | 32 | xbee.printf("flag = %d, bt = %.2f [V], temp = %.1f [C]\r\n",flag,bt,temper); |
HEPTA | 17:e83f07212ed3 | 33 | if(flag == 1) { |
HEPTA | 17:e83f07212ed3 | 34 | xbee.printf("Low Battery\r\n"); |
HEPTA | 17:e83f07212ed3 | 35 | } else if(temper > 35.0) { |
HEPTA | 17:e83f07212ed3 | 36 | xbee.printf("High Temperaturer\n"); |
HEPTA | 17:e83f07212ed3 | 37 | } else if((flag == 1) & (temper > 35.0)) { |
HEPTA | 17:e83f07212ed3 | 38 | xbee.printf("Low Battery and High Temperaturer\n"); |
HEPTA | 17:e83f07212ed3 | 39 | } |
HEPTA | 17:e83f07212ed3 | 40 | xbee.xbee_receive(&rcmd,&cmdflag); |
HEPTA | 17:e83f07212ed3 | 41 | if (cmdflag == 1) { |
HEPTA | 17:e83f07212ed3 | 42 | xbee.printf("Command Get = %d\r\n",rcmd); |
HEPTA | 17:e83f07212ed3 | 43 | if (rcmd == 'a') { |
HEPTA | 17:e83f07212ed3 | 44 | for(int i = 0; i < 10; i++) { |
HEPTA | 17:e83f07212ed3 | 45 | xbee.printf("Count = %d\r\n",i); |
HEPTA | 17:e83f07212ed3 | 46 | wait(1.0); |
HEPTA | 17:e83f07212ed3 | 47 | } |
HEPTA | 17:e83f07212ed3 | 48 | } |
HEPTA | 17:e83f07212ed3 | 49 | if (rcmd == 'b') { |
HEPTA | 17:e83f07212ed3 | 50 | mkdir("/sd/mydir", 0777); |
HEPTA | 17:e83f07212ed3 | 51 | FILE *fp = fopen("/sd/mydir/battery.txt","w"); |
HEPTA | 17:e83f07212ed3 | 52 | if(fp == NULL) { |
HEPTA | 17:e83f07212ed3 | 53 | error("Could not open file for write\r\n"); |
HEPTA | 17:e83f07212ed3 | 54 | } else { |
HEPTA | 17:e83f07212ed3 | 55 | for(int i = 0; i < 10; i++) { |
HEPTA | 17:e83f07212ed3 | 56 | battery.vol(&bt); |
HEPTA | 17:e83f07212ed3 | 57 | fprintf(fp,"%f\r\n",bt); |
HEPTA | 17:e83f07212ed3 | 58 | wait(1.0); |
HEPTA | 17:e83f07212ed3 | 59 | } |
HEPTA | 17:e83f07212ed3 | 60 | fclose(fp); |
HEPTA | 17:e83f07212ed3 | 61 | } |
HEPTA | 17:e83f07212ed3 | 62 | FILE *fp1 = fopen("/sd/mydir/battery.txt","r"); |
HEPTA | 17:e83f07212ed3 | 63 | if(fp1 == NULL) { |
HEPTA | 17:e83f07212ed3 | 64 | error("Could not open file for read\r\n"); |
HEPTA | 17:e83f07212ed3 | 65 | } else { |
HEPTA | 17:e83f07212ed3 | 66 | for(int i = 0; i < 10; i++) { |
HEPTA | 17:e83f07212ed3 | 67 | fgets(str,100,fp1); |
HEPTA | 17:e83f07212ed3 | 68 | xbee.printf("%s",str); |
HEPTA | 17:e83f07212ed3 | 69 | wait(1.0); |
HEPTA | 17:e83f07212ed3 | 70 | } |
HEPTA | 17:e83f07212ed3 | 71 | fclose(fp1); |
HEPTA | 17:e83f07212ed3 | 72 | } |
HEPTA | 17:e83f07212ed3 | 73 | }// |
HEPTA | 17:e83f07212ed3 | 74 | if (rcmd == 'c') { |
HEPTA | 17:e83f07212ed3 | 75 | |
HEPTA | 17:e83f07212ed3 | 76 | |
HEPTA | 17:e83f07212ed3 | 77 | |
HEPTA | 17:e83f07212ed3 | 78 | } |
HEPTA | 17:e83f07212ed3 | 79 | if (rcmd == 'd') { |
HEPTA | 17:e83f07212ed3 | 80 | cam_gps.Sync(); |
HEPTA | 17:e83f07212ed3 | 81 | cam_gps.initialize(HeptaCamera_GPS::Baud115200, HeptaCamera_GPS::JpegResolution320x240); |
HEPTA | 17:e83f07212ed3 | 82 | cam_gps.test_jpeg_snapshot_data("/sd/test.jpg"); |
HEPTA | 17:e83f07212ed3 | 83 | } |
HEPTA | 17:e83f07212ed3 | 84 | xbee.initialize(); |
HEPTA | 17:e83f07212ed3 | 85 | } |
HEPTA | 17:e83f07212ed3 | 86 | } |
HEPTA | 17:e83f07212ed3 | 87 | } |