Abstraction for the glider class
Glider.cpp
- Committer:
- chasefarmer2808
- Date:
- 2017-04-13
- Revision:
- 5:460412fc4a17
- Parent:
- 4:ff59603d9fb6
- Child:
- 6:bb82dd1618c2
File content as of revision 5:460412fc4a17:
#include "Glider.h" Glider::Glider(Serial* device, PinName sda, PinName scl, PinName tx, PinName rx) : xbeeRxInt(rx) { dev = device; dev->printf("constructing glider..."); initSaveData(); xbee = new Serial(tx, rx); heading = 0.0; pressure = 0.0; temp = 0.0; alt = 0.0; //packetCount = 0; comm = false; transmitFlag = false; hmc = new HMC5883L(sda, scl); bmp = new BMP180(sda, scl); bmp->Initialize(1013.25, BMP180_OSS_ULTRA_LOW_POWER); xbeeRxInt.rise(this, &Glider::setCommandFlag); } void Glider::setHeading() { this->heading = this->hmc->getHeadingXYDeg(); } void Glider::setTempPress() { bmp->ReadData(&this->temp, &this->pressure, &this->alt); } void Glider::setMissionTime() { this->dev->printf("current time: %d\r\n", this->missionTime); this->missionTime = time(NULL) - this->startTime; } void Glider::setTransmitFlag() { this->transmitFlag = true; } void Glider::saveTelem() { FILE *fp = fopen("/telem/telem.txt", "w"); fprintf(fp, "hello,"); fclose(fp); } 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 %d", this->startTime, this->packetCount); //save the start time fclose(fp1); return; } 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 packet count: %d\r\n", this->packetCount); fprintf(fp, "%d %d", this->startTime, this->packetCount); fclose(fp); } void Glider::transmitPacket() { //TODO: transmit mission time, packet count, alt, pressure, speed //temp, voltage, state this->packetCount++; this->xbee->printf("3387, GLIDER, %f, %d, %d\r\n", this->heading, this->missionTime, this->packetCount); } void Glider::setCommandFlag() { this->comm = true; } void Glider::processCommand() { if (this->comm) { //command recieved char command = this->xbee->getc(); switch (command) { case BUZZER: this->dev->printf("buzzing...\r\n"); while(1); break; } this->comm = false; } }