Abstraction for the glider class

Dependents:   DropTest

Committer:
chasefarmer2808
Date:
Wed Apr 12 22:22:38 2017 +0000
Revision:
2:cc07e65227ff
Parent:
1:7039ae86fe70
Child:
3:d8932a3036a8
xbee rx interrupt;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chasefarmer2808 0:4e6b53a7bd38 1 #include "Glider.h"
chasefarmer2808 0:4e6b53a7bd38 2
chasefarmer2808 2:cc07e65227ff 3 Glider::Glider(Serial* device, PinName sda, PinName scl, PinName tx, PinName rx) : xbeeRxInt(rx) {
chasefarmer2808 2:cc07e65227ff 4
chasefarmer2808 0:4e6b53a7bd38 5 dev = device;
chasefarmer2808 2:cc07e65227ff 6 //readTime();
chasefarmer2808 1:7039ae86fe70 7 xbee = new Serial(tx, rx);
chasefarmer2808 1:7039ae86fe70 8 dev->printf("constructing glider...");
chasefarmer2808 1:7039ae86fe70 9 heading = 0.0;
chasefarmer2808 1:7039ae86fe70 10 pressure = 0.0;
chasefarmer2808 1:7039ae86fe70 11 temp = 0.0;
chasefarmer2808 1:7039ae86fe70 12 alt = 0.0;
chasefarmer2808 2:cc07e65227ff 13 comm = false;
chasefarmer2808 0:4e6b53a7bd38 14 hmc = new HMC5883L(sda, scl);
chasefarmer2808 0:4e6b53a7bd38 15 bmp = new BMP180(sda, scl);
chasefarmer2808 0:4e6b53a7bd38 16 bmp->Initialize(1013.25, BMP180_OSS_ULTRA_LOW_POWER);
chasefarmer2808 2:cc07e65227ff 17 xbeeRxInt.rise(this, &Glider::setCommand);
chasefarmer2808 0:4e6b53a7bd38 18 }
chasefarmer2808 0:4e6b53a7bd38 19
chasefarmer2808 0:4e6b53a7bd38 20 void Glider::setHeading() {
chasefarmer2808 0:4e6b53a7bd38 21 this->heading = this->hmc->getHeadingXYDeg();
chasefarmer2808 0:4e6b53a7bd38 22 }
chasefarmer2808 0:4e6b53a7bd38 23
chasefarmer2808 0:4e6b53a7bd38 24 void Glider::setTempPress() {
chasefarmer2808 0:4e6b53a7bd38 25 bmp->ReadData(&this->temp, &this->pressure, &this->alt);
chasefarmer2808 0:4e6b53a7bd38 26 }
chasefarmer2808 0:4e6b53a7bd38 27
chasefarmer2808 1:7039ae86fe70 28 void Glider::setMissionTime() {
chasefarmer2808 1:7039ae86fe70 29 this->missionTime = time(NULL) - this->startTime;
chasefarmer2808 1:7039ae86fe70 30 }
chasefarmer2808 1:7039ae86fe70 31
chasefarmer2808 0:4e6b53a7bd38 32 void Glider::saveTelem() {
chasefarmer2808 0:4e6b53a7bd38 33 FILE *fp = fopen("/telem/telem.txt", "w");
chasefarmer2808 0:4e6b53a7bd38 34 fprintf(fp, "hello,");
chasefarmer2808 1:7039ae86fe70 35 fclose(fp);
chasefarmer2808 1:7039ae86fe70 36 }
chasefarmer2808 1:7039ae86fe70 37
chasefarmer2808 2:cc07e65227ff 38 void Glider::readTime() {
chasefarmer2808 2:cc07e65227ff 39 this->dev->printf("getting the time...\r\n");
chasefarmer2808 2:cc07e65227ff 40 FILE *fp = fopen("/telem/data.txt", "r");
chasefarmer2808 2:cc07e65227ff 41
chasefarmer2808 2:cc07e65227ff 42 if (fp == NULL) {
chasefarmer2808 2:cc07e65227ff 43 this->startTime = time(NULL);
chasefarmer2808 2:cc07e65227ff 44 FILE *fp1 = fopen("/telem/data.txt", "w");
chasefarmer2808 2:cc07e65227ff 45 fclose(fp1);
chasefarmer2808 2:cc07e65227ff 46 return;
chasefarmer2808 2:cc07e65227ff 47 }
chasefarmer2808 2:cc07e65227ff 48 this->dev->printf("getting the time...\r\n");
chasefarmer2808 2:cc07e65227ff 49 fscanf(fp, "%d", this->startTime);
chasefarmer2808 2:cc07e65227ff 50 this->dev->printf("start time: %d\r\n", this->startTime);
chasefarmer2808 2:cc07e65227ff 51 rewind(fp);
chasefarmer2808 2:cc07e65227ff 52 fclose(fp);
chasefarmer2808 2:cc07e65227ff 53 }
chasefarmer2808 2:cc07e65227ff 54
chasefarmer2808 2:cc07e65227ff 55 void Glider::saveData() {
chasefarmer2808 2:cc07e65227ff 56 FILE *fp = fopen("/telem/data.txt", "w");
chasefarmer2808 2:cc07e65227ff 57 fprintf(fp, "%d", this->missionTime);
chasefarmer2808 2:cc07e65227ff 58 fclose(fp);
chasefarmer2808 2:cc07e65227ff 59 }
chasefarmer2808 2:cc07e65227ff 60
chasefarmer2808 1:7039ae86fe70 61 void Glider::transmitPacket() {
chasefarmer2808 1:7039ae86fe70 62 //TODO: transmit mission time, packet count, alt, pressure, speed
chasefarmer2808 1:7039ae86fe70 63 //temp, voltage, state
chasefarmer2808 1:7039ae86fe70 64 xbee->printf("3387, GLIDER, %f, %d\r\n", this->heading, this->missionTime);
chasefarmer2808 1:7039ae86fe70 65 }
chasefarmer2808 2:cc07e65227ff 66
chasefarmer2808 2:cc07e65227ff 67 void Glider::setCommand() {
chasefarmer2808 2:cc07e65227ff 68 this->comm = true;
chasefarmer2808 2:cc07e65227ff 69 }
chasefarmer2808 2:cc07e65227ff 70
chasefarmer2808 2:cc07e65227ff 71 void Glider::processCommand() {
chasefarmer2808 2:cc07e65227ff 72 if (this->comm) { //command recieved
chasefarmer2808 2:cc07e65227ff 73 char command = this->xbee->getc();
chasefarmer2808 2:cc07e65227ff 74 this->xbee->printf("you sent: %c\r\n", command);
chasefarmer2808 2:cc07e65227ff 75 this->comm = false;
chasefarmer2808 2:cc07e65227ff 76 }
chasefarmer2808 2:cc07e65227ff 77 }