Entire Solution

Dependencies:   Hepta9axis HeptaBattery HeptaCamera_GPS HeptaTemp HeptaXbee SDFileSystem mbed

Fork of 3daf572bcae1 by Ivan Stoev

Committer:
tuba
Date:
Thu Oct 26 11:35:16 2017 +0000
Revision:
0:ea40bd156a1a
Child:
1:20db10adb732
Second

Who changed what in which revision?

UserRevisionLine numberNew 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 0:ea40bd156a1a 19 int main() {
tuba 0:ea40bd156a1a 20 xbee.baud(9600);
tuba 0:ea40bd156a1a 21 xbee.printf("Xbee comunication begin!\n\r");
tuba 0:ea40bd156a1a 22 char * dir_name = "/sd/Pictures";
tuba 0:ea40bd156a1a 23 mkdir(dir_name, 0777);
tuba 0:ea40bd156a1a 24
tuba 0:ea40bd156a1a 25 HeptaCamera_GPS::ErrorNumber err1 = HeptaCamera_GPS::NoError;
tuba 0:ea40bd156a1a 26 //
tuba 0:ea40bd156a1a 27 mkdir("/sd/Data", 0777);
tuba 0:ea40bd156a1a 28 pc.printf("Created!\n\r");
tuba 0:ea40bd156a1a 29 // while (true) {
tuba 0:ea40bd156a1a 30 // pc.putc(cam_gps.getc());
tuba 0:ea40bd156a1a 31 //}
tuba 0:ea40bd156a1a 32 while (true) {
tuba 0:ea40bd156a1a 33 pc.printf("Begin messurment\n\r");
tuba 0:ea40bd156a1a 34 float batLev;
tuba 0:ea40bd156a1a 35 float tempMes;
tuba 0:ea40bd156a1a 36
tuba 0:ea40bd156a1a 37 FILE *fp = fopen("/sd/Data/Data.txt", "w");
tuba 0:ea40bd156a1a 38 if(fp == NULL) {
tuba 0:ea40bd156a1a 39 error("Could not open file for write\n\r");
tuba 0:ea40bd156a1a 40 }
tuba 0:ea40bd156a1a 41
tuba 0:ea40bd156a1a 42 for (int i =0; i < 5; ++i)
tuba 0:ea40bd156a1a 43 {
tuba 0:ea40bd156a1a 44 char fname[64];
tuba 0:ea40bd156a1a 45 snprintf(fname, sizeof(fname), "%s/Picture%d.jpg", dir_name, i);
tuba 0:ea40bd156a1a 46 //snprintf(fname, sizeof(fname), "/sd/test.jpg");
tuba 0:ea40bd156a1a 47 FILE *fp_jpeg = fopen(fname, "w");
tuba 0:ea40bd156a1a 48 //cam_gps.set_image_file(fp_jpeg);
tuba 0:ea40bd156a1a 49 cam_gps.Sync();
tuba 0:ea40bd156a1a 50 cam_gps.initialize(HeptaCamera_GPS::Baud115200, HeptaCamera_GPS::JpegResolution320x240);
tuba 0:ea40bd156a1a 51
tuba 0:ea40bd156a1a 52 err1 = cam_gps.getJpegSnapshotPicture(fp_jpeg);
tuba 0:ea40bd156a1a 53 //cam_gps.test_jpeg_snapshot_picture(1);
tuba 0:ea40bd156a1a 54
tuba 0:ea40bd156a1a 55 if (HeptaCamera_GPS::NoError == err1) {
tuba 0:ea40bd156a1a 56 printf("[ OK ] : Picture taken\r\n");
tuba 0:ea40bd156a1a 57 } else {
tuba 0:ea40bd156a1a 58 printf("[FAIL] : Picture failed (Error=%02X)\r\n", (int)err1);
tuba 0:ea40bd156a1a 59 }
tuba 0:ea40bd156a1a 60 fclose(fp_jpeg);
tuba 0:ea40bd156a1a 61
tuba 0:ea40bd156a1a 62 fprintf(fp, "Picture data - Name [%s]\n\r--------------------------------\n\r", fname);
tuba 0:ea40bd156a1a 63 temp.temp_sense(&tempMes);
tuba 0:ea40bd156a1a 64 fprintf(fp, "Temperature [%f]\n\r", tempMes);
tuba 0:ea40bd156a1a 65 bat.vol(&batLev);
tuba 0:ea40bd156a1a 66 fprintf(fp, "Battery Level is [%f] Temperature [%f] ", batLev, tempMes);
tuba 0:ea40bd156a1a 67 float mx,my,mz;
tuba 0:ea40bd156a1a 68 n_axis.sen_mag(&mx,&my,&mz);
tuba 0:ea40bd156a1a 69 fprintf(fp, "Magnetometer[%f,%f,%f] ",mx,my,mz);
tuba 0:ea40bd156a1a 70 //pc.printf("Magnet %f,%f,%f\r\n",mx,my,mz);
tuba 0:ea40bd156a1a 71 float gx,gy,gz;
tuba 0:ea40bd156a1a 72 n_axis.sen_gyro(&gx,&gy,&gz);
tuba 0:ea40bd156a1a 73 fprintf(fp, "Gyroscope[%f,%f,%f] ",gx,gy,gz);
tuba 0:ea40bd156a1a 74 // pc.printf("Gyroscope %f,%f,%f\r\n",gx,gy,gz);
tuba 0:ea40bd156a1a 75 float ax,ay,az;
tuba 0:ea40bd156a1a 76 n_axis.sen_acc(&ax,&ay,&az);
tuba 0:ea40bd156a1a 77 fprintf(fp, "Acceletarion[%f,%f,%f]\r\n",ax,ay,az);
tuba 0:ea40bd156a1a 78 // pc.printf("Acceletarion %f,%f,%f\r\n",ax,ay,az);
tuba 0:ea40bd156a1a 79 int quality=0,stnum=0,gps_check=0;
tuba 0:ea40bd156a1a 80 char ns='A',ew='B',aunit='m';
tuba 0:ea40bd156a1a 81 float time=0.0,latitude=0.0,longitude=0.0,hacu=0.0,altitude=0.0;
tuba 0:ea40bd156a1a 82 cam_gps.gps_setting();
tuba 0:ea40bd156a1a 83 wait(1.0);
tuba 0:ea40bd156a1a 84 cam_gps.gga_sensing(&time, &latitude, &ns, &longitude, &ew, &quality, &stnum, &hacu, &altitude, &aunit, &gps_check);
tuba 0:ea40bd156a1a 85 if((gps_check==0)|(gps_check==1)) {
tuba 0:ea40bd156a1a 86 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 0:ea40bd156a1a 87 }
tuba 0:ea40bd156a1a 88 fprintf(fp, "Picture data - End\n\r--------------------------------\n\r");
tuba 0:ea40bd156a1a 89 wait(1.0);
tuba 0:ea40bd156a1a 90 xbee.printf("num = %d\r\n",i);
tuba 0:ea40bd156a1a 91 }
tuba 0:ea40bd156a1a 92 fclose(fp);
tuba 0:ea40bd156a1a 93
tuba 0:ea40bd156a1a 94 FILE *fp1 = fopen("/sd/Data/Data.txt", "r");
tuba 0:ea40bd156a1a 95 char buf[100];
tuba 0:ea40bd156a1a 96 int nread = 0;
tuba 0:ea40bd156a1a 97 if (fp1) {
tuba 0:ea40bd156a1a 98 while ((nread = fread(buf, 1, sizeof buf, fp1)) > 0){
tuba 0:ea40bd156a1a 99 for (int i =0; i<nread; i++)
tuba 0:ea40bd156a1a 100 {
tuba 0:ea40bd156a1a 101 xbee.printf("%c", buf[i]);
tuba 0:ea40bd156a1a 102 }
tuba 0:ea40bd156a1a 103 }
tuba 0:ea40bd156a1a 104 } else error("Could not open file for write\n\r");
tuba 0:ea40bd156a1a 105 fclose(fp1);
tuba 0:ea40bd156a1a 106 }
tuba 0:ea40bd156a1a 107 }