Abstraction for the glider class

Dependents:   DropTest

Glider.cpp

Committer:
chasefarmer2808
Date:
2017-04-12
Revision:
2:cc07e65227ff
Parent:
1:7039ae86fe70
Child:
3:d8932a3036a8

File content as of revision 2:cc07e65227ff:

#include "Glider.h"

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() {
    this->heading = this->hmc->getHeadingXYDeg();
}

void Glider::setTempPress() {
    bmp->ReadData(&this->temp, &this->pressure, &this->alt);
}

void Glider::setMissionTime() {
    this->missionTime = time(NULL) - this->startTime;
}

void Glider::saveTelem() {
     FILE *fp = fopen("/telem/telem.txt", "w");
     fprintf(fp, "hello,");
     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;
    }  
}