Chase Farmer / Glider

Dependents:   DropTest

Files at this revision

API Documentation at this revision

Comitter:
chasefarmer2808
Date:
Sat Apr 29 21:27:57 2017 +0000
Parent:
12:ca3e1c6203f7
Child:
14:a226bedae730
Commit message:
save csv

Changed in this revision

Glider.cpp Show annotated file Show diff for this revision Revisions of this file
Glider.h Show annotated file Show diff for this revision Revisions of this file
--- a/Glider.cpp	Sat Apr 29 18:49:55 2017 +0000
+++ b/Glider.cpp	Sat Apr 29 21:27:57 2017 +0000
@@ -50,8 +50,16 @@
 }
 
 void Glider::saveTelem() {
-     FILE *fp = fopen("/telem/telem.txt", "w");
-     fprintf(fp, "hello,");
+     FILE *fp = fopen("/telem/telem.csv", "a");
+     fprintf(fp, "3387, GLIDER, %d, %u, %f, %f, %f, %f, %f, %u\r\n", 
+                        this->missionTime,  //duration in seconds 
+                        this->packetCount,  
+                        this->alt, //meters
+                        this->pressure, //
+                        this->temp,  //C
+                        this->speed,  //m per s
+                        this->heading, //degrees from North
+                        this->state);;
      fclose(fp);
 }
 
@@ -109,14 +117,20 @@
         switch (command) {
             case CMD_BUZZER:  //'b' was recieved.  sound the buzzer
                   this->state = LAND; //set state to land
-                  this->transmitPacket();  //transmit one last packet
-                  this->soundBuzzer(BUZZER_FREQ, 1, true);  //sound buzzer forever
-                  while (1);
+                  //this->transmitPacket();  //transmit one last packet
+                  //this->soundBuzzer(BUZZER_FREQ, 1, true);  //sound buzzer forever
+                  //while (1);
                   break; 
             case CMD_RESET:  //'z' was recieved
-                  this->dev->printf("resetting save file...\r\n");
-                  remove("/telem/data.txt");
-                  this->initSaveData();
+                  xbee->printf("resetting save file...\r\n");
+                  
+                  state = 0;
+                  packetCount = 0;
+                  startTime = 0;
+                  saveData();
+                  //remove("/telem/data.txt");
+                  //this->initSaveData();
+                  break;
         }
         
         this->cmdFlag = false;  //reset the flag so a new command can be recieved
@@ -126,3 +140,18 @@
 void Glider::soundBuzzer(float freq, float dur, bool infinate) {
     buzzer.beep(freq, dur, infinate);    
 }
+
+void Glider::checkForLand() {
+    xbee->printf("%f\r\n", alt);
+    if (alt <= ALT_THRESH) {
+        state = LAND;   
+    }   
+}
+
+void Glider::endMission() {
+    this->transmitPacket();  //transmit one last packet
+    this->soundBuzzer(BUZZER_FREQ, 1, true);  //sound buzzer forever
+    while (1) {
+         processCommand();   
+    }
+}
--- a/Glider.h	Sat Apr 29 18:49:55 2017 +0000
+++ b/Glider.h	Sat Apr 29 21:27:57 2017 +0000
@@ -11,8 +11,11 @@
 #define SAVE_DATA_FORMAT "%d %d %d"
 #define CMD_BUZZER 'b'
 #define CMD_RESET 'z'
+#define CMD_NEXT_STATE 'n'
+#define CMD_PREV_STATE 'p'
 
 #define FREQ 1.0
+
 #define CRUZE 0
 #define LAND 1
 
@@ -23,6 +26,8 @@
 
 #define BUZZER_FREQ 700.0
 
+#define ALT_THRESH 100.0 //meters
+
 class Glider {
 public:
     Serial* dev;
@@ -57,6 +62,8 @@
     void setCommandFlag();
     void processCommand();
     void soundBuzzer(float freq, float dur, bool infinate);
+    void checkForLand();
+    void endMission();
 };
 
 #endif