gs testing

Dependencies:   HEPTA_CDH HEPTA_COM HEPTA_EPS HEPTA_SENSOR mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "HEPTA_CDH.h"
00003 #include "HEPTA_EPS.h"
00004 #include "HEPTA_SENSOR.h"
00005 #include "HEPTA_COM.h"
00006 HEPTA_CDH cdh(p5, p6, p7, p8, "sd");
00007 HEPTA_EPS eps(p16,p26);
00008 HEPTA_SENSOR sensor(p17,
00009                     p28,p27,0xD0,0x18,
00010                     p13,p14,p25,p24);
00011 HEPTA_COM com(p9,p10);
00012 DigitalOut condition(LED1);
00013 Serial sat(USBTX,USBRX,9600);
00014 Timer sattime;
00015 int rcmd = 0,cmdflag = 0; //command variable
00016 
00017 int main()
00018 {
00019     sat.printf("From Sat : Nominal Operation\r\n");
00020     com.printf("From Sat : Nominal Operation\r\n");
00021     com.baud(9600);
00022     int flag = 0; //condition flag
00023     float batvol, temp; //voltage, temperature
00024     int rcmd=0,cmdflag=0;  //command variable
00025     sattime.start();
00026     eps.turn_on_regulator();//turn on 3.3V conveter
00027 
00028     while(1) {
00029         com.xbee_receive(&rcmd,&cmdflag);//interupting by ground station command
00030         //senssing HK data(dummy data)
00031         eps.vol(&batvol);
00032         sensor.temp_sense(&temp);
00033         wait_ms(100);
00034         //Transmitting HK data to Ground Station(GS)
00035         sensor.gps_setting();
00036         int quality=0,stnum=0,gps_check=0;
00037         char ns='A',ew='B',aunit='m';
00038         float time=0.0,latitude=0.0,longitude=0.0,hacu=0.0,altitude=0.0;
00039         com.printf("HEPTASAT::Condition=%d,Time=%f[s],batVol=%.2f[V],Temp=%.2f[C],GPGGA,%f,%f,%f\r\n",
00040                    flag,sattime.read(),batvol,temp,latitude,longitude,altitude);
00041         wait_ms(1000);
00042 
00043         //Power Saving Mode
00044         if((batvol <= 3.5)  | (temp > 35.0)) {
00045             eps.shut_down_regulator();
00046             com.printf("Power saving mode ON\r\n");
00047             flag = 1;
00048         } else if((flag == 1) & (batvol > 3.7) & (temp <= 25.0)) {
00049             eps.turn_on_regulator();
00050             com.printf("Power saving mode OFF\r\n");
00051             flag = 0;
00052         }
00053         //Contents of command
00054         //if (cmdflag == 1) {
00055         if (rcmd == '0') {
00056             sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag);
00057             com.printf("Hepta-Sat Uplink Ok\r\n");
00058             for(int j=0; j<5; j++) {
00059                 com.printf("Hello World!\r\n");
00060                 condition = 1;
00061                 wait_ms(1000);
00062             }
00063         } else if (rcmd == '1') {
00064             sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag);
00065             com.printf("Hepta-Sat Uplink Ok\r\n");
00066             char str[100];
00067             mkdir("/sd/mydir", 0777);
00068             FILE *fp = fopen("/sd/mydir/satdata.txt","w");
00069             if(fp == NULL) {
00070                 error("Could not open file for write\r\n");
00071             }
00072             for(int i = 0; i < 10; i++) {
00073                 eps.vol(&batvol);
00074                 fprintf(fp,"%f\r\n",batvol);
00075                 condition = 1;
00076                 wait_ms(1000);
00077             }
00078             fclose(fp);
00079             fp = fopen("/sd/mydir/satdata.txt","r");
00080             for(int i = 0; i < 10; i++) {
00081                 fgets(str,100,fp);
00082                 com.puts(str);
00083             }
00084             fclose(fp);
00085         } else if (rcmd == '2') {
00086             sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag);
00087             com.printf("Hepta-Sat Uplink Ok\r\n");
00088             sensor.gps_setting();
00089             int quality=0,stnum=0,gps_check=0;
00090             char ns='A',ew='B',aunit='m';
00091             float time=0.0,latitude=0.0,longitude=0.0,hacu=0.0,altitude=0.0;
00092             for(int i=1; i<1000; i++) {
00093                 sensor.gga_sensing(&time, &latitude, &ns, &longitude, &ew, &quality, &stnum, &hacu, &altitude, &aunit, &gps_check);
00094                 if((gps_check==0)|(gps_check==1)) {
00095                     com.printf("GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f,%c\r\n",time,latitude,ns,longitude,ew,quality,stnum,hacu,altitude,aunit);
00096                 }
00097             }
00098         } else if (rcmd == '3') {
00099             sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag);
00100             com.printf("Hepta-Sat Uplink Ok\r\n");
00101             float ax,ay,az;
00102             com.printf("Accel Sensor Mode\r\n");
00103             for(int i = 0; i<50; i++) {
00104                 sensor.sen_acc(&ax,&ay,&az);
00105                 com.printf("%f,%f,%f\r\n",ax,ay,az);
00106                 wait(0.5);
00107             }
00108         } else if (rcmd == '4') {
00109             sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag);
00110             com.printf("Hepta-Sat Uplink Ok\r\n");
00111             float gx,gy,gz;
00112             com.printf("Gyro Sensor Mode\r\n");
00113             for(int i = 0; i<50; i++) {
00114                 sensor.sen_gyro(&gx,&gy,&gz);
00115                 com.printf("%f,%f,%f\r\n",gx,gy,gz);
00116                 wait(0.5);
00117             }
00118         } else if (rcmd == '5') {
00119             sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag);
00120             com.printf("Hepta-Sat Uplink Ok\r\n");
00121             float mx,my,mz;
00122             com.printf("Magnetometer Mode\r\n");
00123             for(int i = 0; i<50; i++) {
00124                 sensor.sen_mag(&mx,&my,&mz);
00125                 com.printf("%f,%f,%f\r\n",mx,my,mz);
00126                 wait(0.5);
00127             }
00128         } else if (rcmd == '6') {
00129             sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag);
00130             com.printf("Hepta-Sat Uplink Ok\r\n");
00131             float ax,ay,az;
00132             float gx,gy,gz;
00133             float mx,my,mz;
00134             com.printf("9-axis sensor Mode\r\n");
00135             for(int i = 0; i<50; i++) {
00136                 sensor.sen_acc(&ax,&ay,&az);
00137                 sensor.sen_gyro(&gx,&gy,&gz);
00138                 sensor.sen_mag(&mx,&my,&mz);
00139                 com.printf("-,-,-,-,-,-,-,-,-,-,-,-,-,-,-,%f,%f,%f,%f,%f,%f,%f,%f,%f\r\n",ax,ay,az,gx,gy,gz,mx,my,mz);
00140                 wait(0.5);
00141             }
00142         } else if (rcmd == '7') {
00143             sat.printf("rcmd=%c,cmdflag=%d\r\n",rcmd,cmdflag);
00144             com.printf("Hepta-Sat Uplink Ok\r\n");
00145             com.printf("CAMERA\r\n");
00146             sensor.Sync();
00147             sensor.initialize(HeptaCamera_GPS::Baud115200, HeptaCamera_GPS::JpegResolution320x240);
00148             sensor.test_jpeg_snapshot_data("/sd/test.txt");
00149             FILE *fp = fopen("/sd/test.txt", "r");
00150             if(fp == NULL) {
00151                 sat.printf("Could not open file for write\r\n");
00152             } else {
00153                 char str[1024];
00154                 com.printf("INICIO\r\n");
00155                 while((fgets(str,256,fp))!=NULL) {
00156                     com.printf("%s",str);
00157                     wait(0.001);
00158                 }
00159                 com.printf("FIN\r\n");
00160                 //com.printf("Data transmitting finished:)\r\n");
00161                 fclose(fp);
00162             }
00163         } else if (rcmd == '8') {
00164             com.initialize();
00165             sattime.stop();
00166             sat.printf("From Sat : End of operation\r\n");
00167             com.printf("From Sat : End of operation\r\n");
00168             break;
00169         }
00170         //}
00171     }
00172 }