Entire Solution
Dependencies: Hepta9axis HeptaBattery HeptaCamera_GPS HeptaTemp HeptaXbee SDFileSystem mbed
Fork of 3daf572bcae1 by
3daf572bcae1/main.cpp@1:20db10adb732, 2017-10-28 (annotated)
- Committer:
- tuba
- Date:
- Sat Oct 28 09:25:50 2017 +0000
- Revision:
- 1:20db10adb732
- Parent:
- 0:ea40bd156a1a
- Child:
- 2:25c54b82c4e8
final commit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tuba | 0:ea40bd156a1a | 1 | #include "mbed.h" |
tuba | 0:ea40bd156a1a | 2 | #include "SDFileSystem.h" |
tuba | 0:ea40bd156a1a | 3 | #include "HeptaXbee.h" |
tuba | 0:ea40bd156a1a | 4 | #include "HeptaCamera_GPS.h" |
tuba | 0:ea40bd156a1a | 5 | #include "Hepta9axis.h" |
tuba | 0:ea40bd156a1a | 6 | #include "HeptaTemp.h" |
tuba | 0:ea40bd156a1a | 7 | #include "HeptaBattery.h" |
tuba | 0:ea40bd156a1a | 8 | |
tuba | 0:ea40bd156a1a | 9 | |
tuba | 0:ea40bd156a1a | 10 | |
tuba | 0:ea40bd156a1a | 11 | Serial pc(USBTX,USBRX, 9600); |
tuba | 0:ea40bd156a1a | 12 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
tuba | 0:ea40bd156a1a | 13 | HeptaBattery bat(p16, p25); |
tuba | 0:ea40bd156a1a | 14 | HeptaTemp temp(p17); |
tuba | 0:ea40bd156a1a | 15 | Hepta9axis n_axis(p28, p27, 0xD0, 0x18); |
tuba | 0:ea40bd156a1a | 16 | HeptaCamera_GPS cam_gps(p13, p14,p25, p24); |
tuba | 0:ea40bd156a1a | 17 | HeptaXbee xbee(p9,p10); |
tuba | 0:ea40bd156a1a | 18 | |
tuba | 1:20db10adb732 | 19 | bool picture_here (float latitude, char ns, float longitude, char ew) |
tuba | 1:20db10adb732 | 20 | { |
tuba | 1:20db10adb732 | 21 | return true; |
tuba | 1:20db10adb732 | 22 | if ((latitude >=35.722) &(latitude<=35.728) && (longitude >=140.055) && (longitude<=140.060) && (ns == 'N')&&(ew=='E')) |
tuba | 1:20db10adb732 | 23 | return true; |
tuba | 1:20db10adb732 | 24 | return false; |
tuba | 1:20db10adb732 | 25 | } |
tuba | 1:20db10adb732 | 26 | |
tuba | 1:20db10adb732 | 27 | bool send_here (float latitude, char ns, float longitude, char ew) |
tuba | 1:20db10adb732 | 28 | { |
tuba | 1:20db10adb732 | 29 | return true; |
tuba | 1:20db10adb732 | 30 | if ((latitude >=42.664) &(latitude<=42.699) && (longitude >=23.330) && (longitude<=23.350) && (ns == 'N')&&(ew=='E')) |
tuba | 1:20db10adb732 | 31 | return true; |
tuba | 1:20db10adb732 | 32 | return false; |
tuba | 1:20db10adb732 | 33 | } |
tuba | 1:20db10adb732 | 34 | |
tuba | 0:ea40bd156a1a | 35 | int main() { |
tuba | 0:ea40bd156a1a | 36 | xbee.baud(9600); |
tuba | 1:20db10adb732 | 37 | //xbee.printf("Xbee comunication begin!\n\r"); |
tuba | 0:ea40bd156a1a | 38 | char * dir_name = "/sd/Pictures"; |
tuba | 0:ea40bd156a1a | 39 | mkdir(dir_name, 0777); |
tuba | 0:ea40bd156a1a | 40 | |
tuba | 0:ea40bd156a1a | 41 | HeptaCamera_GPS::ErrorNumber err1 = HeptaCamera_GPS::NoError; |
tuba | 0:ea40bd156a1a | 42 | // |
tuba | 0:ea40bd156a1a | 43 | mkdir("/sd/Data", 0777); |
tuba | 0:ea40bd156a1a | 44 | pc.printf("Created!\n\r"); |
tuba | 1:20db10adb732 | 45 | //cam_gps.gps_setting(); |
tuba | 0:ea40bd156a1a | 46 | // while (true) { |
tuba | 1:20db10adb732 | 47 | // xbee.putc(cam_gps.getc()); |
tuba | 0:ea40bd156a1a | 48 | //} |
tuba | 1:20db10adb732 | 49 | |
tuba | 0:ea40bd156a1a | 50 | while (true) { |
tuba | 0:ea40bd156a1a | 51 | pc.printf("Begin messurment\n\r"); |
tuba | 0:ea40bd156a1a | 52 | float batLev; |
tuba | 0:ea40bd156a1a | 53 | float tempMes; |
tuba | 0:ea40bd156a1a | 54 | |
tuba | 0:ea40bd156a1a | 55 | FILE *fp = fopen("/sd/Data/Data.txt", "w"); |
tuba | 0:ea40bd156a1a | 56 | if(fp == NULL) { |
tuba | 0:ea40bd156a1a | 57 | error("Could not open file for write\n\r"); |
tuba | 0:ea40bd156a1a | 58 | } |
tuba | 1:20db10adb732 | 59 | float time=0.0,latitude=0.0,longitude=0.0,hacu=0.0,altitude=0.0; |
tuba | 1:20db10adb732 | 60 | char ns='A',ew='B'; |
tuba | 1:20db10adb732 | 61 | |
tuba | 1:20db10adb732 | 62 | for (int i =0; i < 1; ++i) |
tuba | 1:20db10adb732 | 63 | { |
tuba | 1:20db10adb732 | 64 | pc.printf("Mesurement attemt %d\r\n", i); |
tuba | 1:20db10adb732 | 65 | fprintf(fp, "Picture data - Name\n\r--------------------------------\n\r"); |
tuba | 0:ea40bd156a1a | 66 | temp.temp_sense(&tempMes); |
tuba | 0:ea40bd156a1a | 67 | fprintf(fp, "Temperature [%f]\n\r", tempMes); |
tuba | 1:20db10adb732 | 68 | pc.printf( "Temperature [%f]\n\r", tempMes); |
tuba | 0:ea40bd156a1a | 69 | bat.vol(&batLev); |
tuba | 0:ea40bd156a1a | 70 | fprintf(fp, "Battery Level is [%f] Temperature [%f] ", batLev, tempMes); |
tuba | 1:20db10adb732 | 71 | pc.printf("Battery Level is [%f] Temperature [%f] \n\r", batLev, tempMes); |
tuba | 0:ea40bd156a1a | 72 | float mx,my,mz; |
tuba | 0:ea40bd156a1a | 73 | n_axis.sen_mag(&mx,&my,&mz); |
tuba | 0:ea40bd156a1a | 74 | fprintf(fp, "Magnetometer[%f,%f,%f] ",mx,my,mz); |
tuba | 1:20db10adb732 | 75 | pc.printf("Magnet %f,%f,%f\r\n",mx,my,mz); |
tuba | 0:ea40bd156a1a | 76 | float gx,gy,gz; |
tuba | 0:ea40bd156a1a | 77 | n_axis.sen_gyro(&gx,&gy,&gz); |
tuba | 0:ea40bd156a1a | 78 | fprintf(fp, "Gyroscope[%f,%f,%f] ",gx,gy,gz); |
tuba | 1:20db10adb732 | 79 | pc.printf("Gyroscope %f,%f,%f\r\n",gx,gy,gz); |
tuba | 0:ea40bd156a1a | 80 | float ax,ay,az; |
tuba | 0:ea40bd156a1a | 81 | n_axis.sen_acc(&ax,&ay,&az); |
tuba | 0:ea40bd156a1a | 82 | fprintf(fp, "Acceletarion[%f,%f,%f]\r\n",ax,ay,az); |
tuba | 1:20db10adb732 | 83 | pc.printf("Acceletarion %f,%f,%f\r\n",ax,ay,az); |
tuba | 0:ea40bd156a1a | 84 | int quality=0,stnum=0,gps_check=0; |
tuba | 1:20db10adb732 | 85 | char aunit='m'; |
tuba | 1:20db10adb732 | 86 | pc.printf("GPS\r\n"); |
tuba | 1:20db10adb732 | 87 | wait(1.0); |
tuba | 0:ea40bd156a1a | 88 | cam_gps.gps_setting(); |
tuba | 0:ea40bd156a1a | 89 | wait(1.0); |
tuba | 0:ea40bd156a1a | 90 | cam_gps.gga_sensing(&time, &latitude, &ns, &longitude, &ew, &quality, &stnum, &hacu, &altitude, &aunit, &gps_check); |
tuba | 0:ea40bd156a1a | 91 | if((gps_check==0)|(gps_check==1)) { |
tuba | 0:ea40bd156a1a | 92 | fprintf(fp, "GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f,%c\r\n",time,latitude,ns,longitude,ew,quality,stnum,hacu,altitude,aunit); |
tuba | 1:20db10adb732 | 93 | pc.printf("$GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f,%c\r\n",time,latitude,ns,longitude,ew,quality,stnum,hacu,altitude,aunit); |
tuba | 0:ea40bd156a1a | 94 | } |
tuba | 0:ea40bd156a1a | 95 | fprintf(fp, "Picture data - End\n\r--------------------------------\n\r"); |
tuba | 1:20db10adb732 | 96 | pc.printf("Takeing picture \r\n"); |
tuba | 1:20db10adb732 | 97 | if (picture_here(latitude,ns,longitude,ew)){ |
tuba | 1:20db10adb732 | 98 | pc.printf("Takeing picture attemt %d\r\n", i); |
tuba | 1:20db10adb732 | 99 | char fname[64]; |
tuba | 1:20db10adb732 | 100 | snprintf(fname, sizeof(fname), "%s/Picture%d.jpg", dir_name, i); |
tuba | 1:20db10adb732 | 101 | //snprintf(fname, sizeof(fname), "/sd/test.jpg"); |
tuba | 1:20db10adb732 | 102 | FILE *fp_jpeg = fopen(fname, "w"); |
tuba | 1:20db10adb732 | 103 | //cam_gps.set_image_file(fp_jpeg); |
tuba | 1:20db10adb732 | 104 | //pc.printf("Setting baud\n\r"); |
tuba | 1:20db10adb732 | 105 | cam_gps.Sync(); |
tuba | 1:20db10adb732 | 106 | cam_gps.initialize(HeptaCamera_GPS::Baud115200, HeptaCamera_GPS::JpegResolution640x480); |
tuba | 1:20db10adb732 | 107 | //pc.printf("Takeing picture\n\r"); |
tuba | 1:20db10adb732 | 108 | err1 = cam_gps.getJpegSnapshotPicture(fp_jpeg); |
tuba | 1:20db10adb732 | 109 | //cam_gps.test_jpeg_snapshot_picture(1); |
tuba | 1:20db10adb732 | 110 | if (HeptaCamera_GPS::NoError == err1) { |
tuba | 1:20db10adb732 | 111 | printf("[ OK ] : Picture taken\r\n"); |
tuba | 1:20db10adb732 | 112 | } else { |
tuba | 1:20db10adb732 | 113 | printf("[FAIL] : Picture failed (Error=%02X)\r\n", (int)err1); |
tuba | 1:20db10adb732 | 114 | } |
tuba | 1:20db10adb732 | 115 | fclose(fp_jpeg); |
tuba | 1:20db10adb732 | 116 | } |
tuba | 0:ea40bd156a1a | 117 | wait(1.0); |
tuba | 1:20db10adb732 | 118 | //xbee.printf("num = %d\r\n",i); |
tuba | 0:ea40bd156a1a | 119 | } |
tuba | 0:ea40bd156a1a | 120 | fclose(fp); |
tuba | 1:20db10adb732 | 121 | pc.printf("Sending phase\r\n"); |
tuba | 1:20db10adb732 | 122 | if (send_here(latitude,ns,longitude,ew)) |
tuba | 1:20db10adb732 | 123 | { |
tuba | 1:20db10adb732 | 124 | wait(5.0); |
tuba | 1:20db10adb732 | 125 | FILE *fp1 = fopen("/sd/Data/Data.txt", "r"); |
tuba | 1:20db10adb732 | 126 | char buf[100]; |
tuba | 1:20db10adb732 | 127 | int nread = 0; |
tuba | 1:20db10adb732 | 128 | if (fp1) { |
tuba | 1:20db10adb732 | 129 | pc.printf("Sending data file %s\r\n", "/sd/Data/Data.txt"); |
tuba | 1:20db10adb732 | 130 | //xbee.printf("#SAT6");//%d%s",strlen("/sd/Data/Data.txt"),"/sd/Data/Data.txt"); |
tuba | 1:20db10adb732 | 131 | while ((nread = fread(buf, 1, sizeof buf, fp1)) > 0){ |
tuba | 1:20db10adb732 | 132 | for (int i =0; i<nread; i++) |
tuba | 1:20db10adb732 | 133 | { |
tuba | 1:20db10adb732 | 134 | xbee.putc(buf[i]); |
tuba | 1:20db10adb732 | 135 | } |
tuba | 0:ea40bd156a1a | 136 | } |
tuba | 1:20db10adb732 | 137 | // xbee.printf("#SAT7"); |
tuba | 1:20db10adb732 | 138 | } else error("Could not open file for write\n\r"); |
tuba | 1:20db10adb732 | 139 | fclose(fp1); |
tuba | 1:20db10adb732 | 140 | wait(15.0); |
tuba | 1:20db10adb732 | 141 | for (int i =0; i < 1; ++i) |
tuba | 1:20db10adb732 | 142 | { |
tuba | 1:20db10adb732 | 143 | char fname[64]; |
tuba | 1:20db10adb732 | 144 | snprintf(fname, sizeof(fname), "%s/Picture%d.jpg", dir_name, i); |
tuba | 1:20db10adb732 | 145 | //snprintf(fname, sizeof(fname), "/sd/test.jpg"); |
tuba | 1:20db10adb732 | 146 | FILE *fp_jpeg = fopen(fname, "r"); |
tuba | 1:20db10adb732 | 147 | char buf[100]; |
tuba | 1:20db10adb732 | 148 | int nread = 0; |
tuba | 1:20db10adb732 | 149 | if (fp_jpeg) { |
tuba | 1:20db10adb732 | 150 | pc.printf("Sending image file %s\r\n", fname); |
tuba | 1:20db10adb732 | 151 | // xbee.printf("#SAT8");//%d%s",strlen(fname),fname); |
tuba | 1:20db10adb732 | 152 | while ((nread = fread(buf, 1, sizeof buf, fp_jpeg)) > 0){ |
tuba | 1:20db10adb732 | 153 | for (int i =0; i<nread; i++) |
tuba | 1:20db10adb732 | 154 | { |
tuba | 1:20db10adb732 | 155 | xbee.putc(buf[i]); |
tuba | 1:20db10adb732 | 156 | } |
tuba | 1:20db10adb732 | 157 | } |
tuba | 1:20db10adb732 | 158 | // xbee.printf("#SAT9"); |
tuba | 1:20db10adb732 | 159 | } else error("Could not open file for write\n\r"); |
tuba | 1:20db10adb732 | 160 | fclose(fp_jpeg); |
tuba | 0:ea40bd156a1a | 161 | } |
tuba | 1:20db10adb732 | 162 | } |
tuba | 0:ea40bd156a1a | 163 | } |
tuba | 0:ea40bd156a1a | 164 | } |