Group B Mission
Dependencies: mbed HeptaBattery SDFileSystem Hepta9axis HeptaTemp
Diff: main.cpp
- Revision:
- 23:3dad6c03c214
- Parent:
- 22:228f5d9aed7b
--- a/main.cpp Sun Aug 25 03:19:04 2019 +0000 +++ b/main.cpp Mon Aug 26 01:13:38 2019 +0000 @@ -20,6 +20,24 @@ HeptaTemp temp(p17); HeptaBattery battery(p16,p26); +int rcmd = 0,cmdflag = 0; + +void commandget() +{ + rcmd=pc.getc(); + cmdflag = 1; +} +void initialize() +{ + rcmd = 0; + cmdflag = 0; +} +void receive(int *xrcmd, int *xcmdflag) +{ + pc.attach(commandget,Serial::RxIrq); + *xrcmd = rcmd; + *xcmdflag = cmdflag; +} // Interrupt Handler void AirQualityInterrupt() { @@ -47,17 +65,12 @@ while(1) { battery.power_saving_mode(&flag,&bt); temp.temp_sense(&temper); + wait(0.5); - mkdir("/sd/mydir", 0777); - FILE *fp = fopen("/sd/mydir/data.txt","w"); - if(fp == NULL) { - error("Could not open file for write\r\n"); - } - pc.printf("flag = %d, bt = %.2f [V], temp = %.1f [C]\r\n",flag,bt,temper); - xbee.printf("flag = %d, bt = %.2f [V], temp = %.1f [C]\r\n",flag,bt,temper); - fprintf(fp,"flag = %d, bt = %.2f [V], temp = %.1f [C]\r\n",flag,bt,temper); xbee.xbee_receive(&rcmd,&cmdflag); - + //receive(&rcmd,&cmdflag); + xbee.printf("Type q to see commands available.\r\n"); + pc.printf("Type q to see commands available.\r\n"); if(flag == 1) { pc.printf("Low Battery\r\n"); xbee.printf("Low Battery\r\n"); @@ -69,16 +82,30 @@ xbee.printf("Low Battery and High Temperature\n\r"); } if (cmdflag == 1) { + pc.printf("Command Get = %d\r\n",rcmd); - xbee.printf("Command Get = %d\r\n",rcmd); + xbee.printf("HEPTA is ready to command\r\n",rcmd); switch (rcmd) { + case 'h': + for(int i = 0; i < 50; i++){ + pc.printf("flag = %d, bt = %.2f [V], temp = %.1f [C]\r\n",flag,bt,temper); + xbee.printf("flag = %d, bt = %.2f [V], temp = %.1f [C]\r\n",flag,bt,temper); + } + break; + case 'q': + xbee.printf("HEPTA Uplink OK\r\n"); + xbee.printf("a for Air Quality. \r\n"); + xbee.printf("b for UV Reading. \r\n"); + xbee.printf("c for Take a snaphot. \r\n"); + xbee.printf("d for Air Temperature.\r\n"); + xbee.printf("e for Satellite Attitude. \r\n"); + xbee.printf("f for GPS Data. \r\n"); + xbee.printf("h for Housekeeping Data. \r\n"); + wait(3.0); + break; case 'a': - pc.printf("Command Get %d\r\n",rcmd); - xbee.printf("HEPTA Uplink OK\r\n"); - break; - case 'b': airqualitysensor.init(analogPin, AirQualityInterrupt); - for(int i = 0; i < 10; i++){ + for(int i = 0; i < 50; i++){ current_quality=airqualitysensor.slope(); if (current_quality >= 0) { // if a valid data returned. if (current_quality == 0){ @@ -101,16 +128,16 @@ wait(1.0); } break; - case 'c': + case 'b': float value; - for(int i = 0; i < 10; i++){ + for(int i = 0; i < 50; i++){ value = sensorUV; pc.printf("\rUV Value = %3.2f%%\r\n",value*100); xbee.printf("\rUV Value = %3.2f%%\r\n",value*100); wait(1.0); } break; - case 'd': + case 'c': pc.printf("Camera Snapshot Mode\r\n"); pc.printf("Hit Any Key To Take Picture\r\n"); @@ -121,20 +148,17 @@ cam_gps.initialize(HeptaCamera_GPS::Baud115200, HeptaCamera_GPS::JpegResolution320x240); cam_gps.test_jpeg_snapshot_picture("/sd/test.jpg"); break; - case 'e': + case 'd': float temper; - for (int i=0;i<10;i++) { + for (int i=0;i<50;i++) { temp.temp_sense(&temper); pc.printf("Air Temperature: %f\n\r", temper); xbee.printf("Air Temperature: %f\n\r", temper); wait(1.0); } break; - case 'f': - //int quality=0,stnum=0,gps_check=0; - // char ns='A',ew='B',aunit='m'; - //float time=0.0,latitude=0.0,longitude=0.0,hacu=0.0,altitude=0.0; - for (int i=0;i<10;i++) { + case 'e': + for (int i=0;i<50;i++) { n_axis.sen_acc(&ax,&ay,&az); n_axis.sen_mag(&mx,&my,&mz); n_axis.sen_gyro(&gx,&gy,&gz); @@ -148,13 +172,13 @@ } break; - case 'g': + case 'f': cam_gps.gps_setting(); int quality=0,stnum=0,gps_check=0; char ns='A',ew='B',aunit='m'; float time=0.0,latitude=0.0,longitude=0.0,hacu=0.0,altitude=0.0; - for(int i=1; i<10; i++) { + for(int i=1; i<50; i++) { cam_gps.gga_sensing(&time, &latitude, &ns, &longitude, &ew, &quality, &stnum, &hacu, &altitude, &aunit, &gps_check); if((gps_check==0)|(gps_check==1)) { 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);