Abstraction for the glider class
Diff: Glider.cpp
- Revision:
- 2:cc07e65227ff
- Parent:
- 1:7039ae86fe70
- Child:
- 3:d8932a3036a8
--- a/Glider.cpp Mon Apr 10 17:33:41 2017 +0000 +++ b/Glider.cpp Wed Apr 12 22:22:38 2017 +0000 @@ -1,17 +1,20 @@ #include "Glider.h" -Glider::Glider(Serial* device, PinName sda, PinName scl, PinName tx, PinName rx) { - startTime = time(NULL); +Glider::Glider(Serial* device, PinName sda, PinName scl, PinName tx, PinName rx) : xbeeRxInt(rx) { + dev = device; + //readTime(); xbee = new Serial(tx, rx); dev->printf("constructing glider..."); heading = 0.0; pressure = 0.0; temp = 0.0; alt = 0.0; + comm = false; hmc = new HMC5883L(sda, scl); bmp = new BMP180(sda, scl); bmp->Initialize(1013.25, BMP180_OSS_ULTRA_LOW_POWER); + xbeeRxInt.rise(this, &Glider::setCommand); } void Glider::setHeading() { @@ -32,8 +35,43 @@ fclose(fp); } +void Glider::readTime() { + this->dev->printf("getting the time...\r\n"); + FILE *fp = fopen("/telem/data.txt", "r"); + + if (fp == NULL) { + this->startTime = time(NULL); + FILE *fp1 = fopen("/telem/data.txt", "w"); + fclose(fp1); + return; + } + this->dev->printf("getting the time...\r\n"); + fscanf(fp, "%d", this->startTime); + this->dev->printf("start time: %d\r\n", this->startTime); + rewind(fp); + fclose(fp); +} + +void Glider::saveData() { + FILE *fp = fopen("/telem/data.txt", "w"); + fprintf(fp, "%d", this->missionTime); + fclose(fp); +} + void Glider::transmitPacket() { //TODO: transmit mission time, packet count, alt, pressure, speed //temp, voltage, state xbee->printf("3387, GLIDER, %f, %d\r\n", this->heading, this->missionTime); } + +void Glider::setCommand() { + 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); + this->comm = false; + } +}