Abstraction for the glider class
Diff: Glider.cpp
- Revision:
- 3:d8932a3036a8
- Parent:
- 2:cc07e65227ff
- Child:
- 4:ff59603d9fb6
--- a/Glider.cpp Wed Apr 12 22:22:38 2017 +0000 +++ b/Glider.cpp Thu Apr 13 01:58:17 2017 +0000 @@ -1,11 +1,10 @@ #include "Glider.h" Glider::Glider(Serial* device, PinName sda, PinName scl, PinName tx, PinName rx) : xbeeRxInt(rx) { - dev = device; - //readTime(); + dev->printf("constructing glider..."); + readTime(); xbee = new Serial(tx, rx); - dev->printf("constructing glider..."); heading = 0.0; pressure = 0.0; temp = 0.0; @@ -14,7 +13,7 @@ hmc = new HMC5883L(sda, scl); bmp = new BMP180(sda, scl); bmp->Initialize(1013.25, BMP180_OSS_ULTRA_LOW_POWER); - xbeeRxInt.rise(this, &Glider::setCommand); + xbeeRxInt.rise(this, &Glider::setCommandFlag); } void Glider::setHeading() { @@ -26,6 +25,7 @@ } void Glider::setMissionTime() { + this->dev->printf("current time: %d\r\n", this->missionTime); this->missionTime = time(NULL) - this->startTime; } @@ -37,23 +37,26 @@ void Glider::readTime() { this->dev->printf("getting the time...\r\n"); - FILE *fp = fopen("/telem/data.txt", "r"); + FILE *fp = fopen("/telem/data.txt", "r"); //attempt to read the saved data - if (fp == NULL) { - this->startTime = time(NULL); - FILE *fp1 = fopen("/telem/data.txt", "w"); + 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 + FILE *fp1 = fopen("/telem/data.txt", "w"); //create the data file + fprintf(fp1, "%d", this->startTime); //save the start time fclose(fp1); return; } - this->dev->printf("getting the time...\r\n"); - fscanf(fp, "%d", this->startTime); + + fscanf(fp, "%d", &this->startTime); this->dev->printf("start time: %d\r\n", this->startTime); rewind(fp); fclose(fp); } -void Glider::saveData() { +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); fclose(fp); } @@ -64,14 +67,21 @@ xbee->printf("3387, GLIDER, %f, %d\r\n", this->heading, this->missionTime); } -void Glider::setCommand() { +void Glider::setCommandFlag() { this->comm = true; } void Glider::processCommand() { if (this->comm) { //command recieved char command = this->xbee->getc(); - this->xbee->printf("you sent: %c\r\n", command); + + switch (command) { + case BUZZER: + this->dev->printf("buzzing...\r\n"); + while(1); + break; + } + this->comm = false; } }