Abstraction for the glider class

Dependents:   DropTest

Revision:
5:460412fc4a17
Parent:
4:ff59603d9fb6
Child:
6:bb82dd1618c2
--- a/Glider.cpp	Thu Apr 13 05:44:14 2017 +0000
+++ b/Glider.cpp	Thu Apr 13 15:10:29 2017 +0000
@@ -3,13 +3,13 @@
 Glider::Glider(Serial* device, PinName sda, PinName scl, PinName tx, PinName rx) : xbeeRxInt(rx) {
     dev = device;
     dev->printf("constructing glider...");
-    readTime();
+    initSaveData();
     xbee = new Serial(tx, rx);
     heading = 0.0;
     pressure = 0.0;
     temp = 0.0;
     alt = 0.0;
-    packetCount = 0;
+    //packetCount = 0;
     comm = false;
     transmitFlag = false;
     hmc = new HMC5883L(sda, scl);
@@ -41,29 +41,31 @@
      fclose(fp);
 }
 
-void Glider::readTime() {
+void Glider::initSaveData() {
      this->dev->printf("getting the time...\r\n");
      FILE *fp = fopen("/telem/data.txt", "r");   //attempt to read the saved data
      
      if (fp == NULL) {  //file does not exist
         this->dev->printf("starting the time...\r\n");
         this->startTime = time(NULL); //initialize the start time to now
+        this->packetCount = 0;
         FILE *fp1 = fopen("/telem/data.txt", "w");  //create the data file
-        fprintf(fp1, "%d", this->startTime);  //save the start time
+        fprintf(fp1, "%d %d", this->startTime, this->packetCount);  //save the start time
         fclose(fp1);
         return;   
      }
      
-     fscanf(fp, "%d", &this->startTime);
+     fscanf(fp, "%d %d", &this->startTime, &this->packetCount);
      this->dev->printf("start time: %d\r\n", this->startTime);
+     this->dev->printf("start packetCount: %d\r\n", this->packetCount);
      rewind(fp);
      fclose(fp);
 }
 
 void Glider::saveData() { //bad
      FILE *fp = fopen("/telem/data.txt", "w");
-     this->dev->printf("saving time: %d\r\n", this->missionTime);
-     fprintf(fp, "%d", this->missionTime);
+     this->dev->printf("saving packet count: %d\r\n", this->packetCount);
+     fprintf(fp, "%d %d", this->startTime, this->packetCount);
      fclose(fp);   
 }