Abstraction for the glider class
Glider.cpp@1:7039ae86fe70, 2017-04-10 (annotated)
- Committer:
- chasefarmer2808
- Date:
- Mon Apr 10 17:33:41 2017 +0000
- Revision:
- 1:7039ae86fe70
- Parent:
- 0:4e6b53a7bd38
- Child:
- 2:cc07e65227ff
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chasefarmer2808 | 0:4e6b53a7bd38 | 1 | #include "Glider.h" |
chasefarmer2808 | 0:4e6b53a7bd38 | 2 | |
chasefarmer2808 | 1:7039ae86fe70 | 3 | Glider::Glider(Serial* device, PinName sda, PinName scl, PinName tx, PinName rx) { |
chasefarmer2808 | 1:7039ae86fe70 | 4 | startTime = time(NULL); |
chasefarmer2808 | 0:4e6b53a7bd38 | 5 | dev = device; |
chasefarmer2808 | 1:7039ae86fe70 | 6 | xbee = new Serial(tx, rx); |
chasefarmer2808 | 1:7039ae86fe70 | 7 | dev->printf("constructing glider..."); |
chasefarmer2808 | 1:7039ae86fe70 | 8 | heading = 0.0; |
chasefarmer2808 | 1:7039ae86fe70 | 9 | pressure = 0.0; |
chasefarmer2808 | 1:7039ae86fe70 | 10 | temp = 0.0; |
chasefarmer2808 | 1:7039ae86fe70 | 11 | alt = 0.0; |
chasefarmer2808 | 0:4e6b53a7bd38 | 12 | hmc = new HMC5883L(sda, scl); |
chasefarmer2808 | 0:4e6b53a7bd38 | 13 | bmp = new BMP180(sda, scl); |
chasefarmer2808 | 0:4e6b53a7bd38 | 14 | bmp->Initialize(1013.25, BMP180_OSS_ULTRA_LOW_POWER); |
chasefarmer2808 | 0:4e6b53a7bd38 | 15 | } |
chasefarmer2808 | 0:4e6b53a7bd38 | 16 | |
chasefarmer2808 | 0:4e6b53a7bd38 | 17 | void Glider::setHeading() { |
chasefarmer2808 | 0:4e6b53a7bd38 | 18 | this->heading = this->hmc->getHeadingXYDeg(); |
chasefarmer2808 | 0:4e6b53a7bd38 | 19 | } |
chasefarmer2808 | 0:4e6b53a7bd38 | 20 | |
chasefarmer2808 | 0:4e6b53a7bd38 | 21 | void Glider::setTempPress() { |
chasefarmer2808 | 0:4e6b53a7bd38 | 22 | bmp->ReadData(&this->temp, &this->pressure, &this->alt); |
chasefarmer2808 | 0:4e6b53a7bd38 | 23 | } |
chasefarmer2808 | 0:4e6b53a7bd38 | 24 | |
chasefarmer2808 | 1:7039ae86fe70 | 25 | void Glider::setMissionTime() { |
chasefarmer2808 | 1:7039ae86fe70 | 26 | this->missionTime = time(NULL) - this->startTime; |
chasefarmer2808 | 1:7039ae86fe70 | 27 | } |
chasefarmer2808 | 1:7039ae86fe70 | 28 | |
chasefarmer2808 | 0:4e6b53a7bd38 | 29 | void Glider::saveTelem() { |
chasefarmer2808 | 0:4e6b53a7bd38 | 30 | FILE *fp = fopen("/telem/telem.txt", "w"); |
chasefarmer2808 | 0:4e6b53a7bd38 | 31 | fprintf(fp, "hello,"); |
chasefarmer2808 | 1:7039ae86fe70 | 32 | fclose(fp); |
chasefarmer2808 | 1:7039ae86fe70 | 33 | } |
chasefarmer2808 | 1:7039ae86fe70 | 34 | |
chasefarmer2808 | 1:7039ae86fe70 | 35 | void Glider::transmitPacket() { |
chasefarmer2808 | 1:7039ae86fe70 | 36 | //TODO: transmit mission time, packet count, alt, pressure, speed |
chasefarmer2808 | 1:7039ae86fe70 | 37 | //temp, voltage, state |
chasefarmer2808 | 1:7039ae86fe70 | 38 | xbee->printf("3387, GLIDER, %f, %d\r\n", this->heading, this->missionTime); |
chasefarmer2808 | 1:7039ae86fe70 | 39 | } |