#ifndef GERMANAIRLINESVA_GACONNECTOR_RUNWAY_H #define GERMANAIRLINESVA_GACONNECTOR_RUNWAY_H #include #include #include #include #include #include "util.hpp" /* * Representation of one X-Plane runway with supplementary information * Heading in degrees (0...360) * Width and length in feet * * Length in bytes: 23 + length of designator * Designator must be null terminated * * UINT8 | CHAR[] | DOUBLE | DOUBLE | UINT8 | UINT16 | UINT16 * ------+------------+--------+--------+-------+--------+------- * LEN | DESIGNATOR | LAT | LON | WIDTH | LENGTH | TRUHDG */ class Runway { private: std::string designator; double latitudeStart; double longitudeStart; std::uint8_t width; std::uint16_t length; std::uint16_t trueHeading; std::vector file; public: Runway(std::string designator, double latitudeStart, double longitudeStart, double latitudeEnd, double longitudeEnd, double width) { this->designator = std::move(designator); this->latitudeStart = latitudeStart; this->longitudeStart = longitudeStart; this->width = (std::uint8_t)std::round(util::to_feet(width)); double dist = util::distanceEarth(latitudeStart, longitudeStart, latitudeEnd, longitudeEnd); this->length = (std::uint16_t)std::round(util::to_feet(dist)); this->trueHeading = (std::uint16_t)std::round(util::bearing(latitudeStart, longitudeStart, latitudeEnd, longitudeEnd)); file = std::vector(23 + this->designator.length(), 0); std::uint8_t *bufPtr = file.data(); memset(bufPtr, static_cast(this->designator.length()), sizeof(std::uint8_t)); bufPtr++; memcpy(bufPtr, this->designator.c_str(), this->designator.length()); bufPtr += this->designator.length() + 1; memcpy(bufPtr, &this->latitudeStart, sizeof(this->latitudeStart)); bufPtr += sizeof(this->latitudeStart); memcpy(bufPtr, &this->longitudeStart, sizeof(this->longitudeStart)); bufPtr += sizeof(this->longitudeStart); memcpy(bufPtr, &this->width, sizeof(this->width)); bufPtr += sizeof(this->width); memcpy(bufPtr, &this->length, sizeof(this->length)); bufPtr += sizeof(this->length); memcpy(bufPtr, &this->trueHeading, sizeof(this->trueHeading)); } Runway(std::string designator, double latitudeStart, double longitudeStart, std::uint8_t width, std::uint16_t length, std::uint16_t trueHeading) { this->designator = std::move(designator); this->latitudeStart = latitudeStart; this->longitudeStart = longitudeStart; this->width = width; this->length = length; this->trueHeading = trueHeading; file = std::vector(23 + this->designator.length(), 0); std::uint8_t *bufPtr = file.data(); memset(bufPtr, static_cast(this->designator.length()), sizeof(std::uint8_t)); bufPtr++; memcpy(bufPtr, this->designator.c_str(), this->designator.length()); bufPtr += this->designator.length() + 1; memcpy(bufPtr, &this->latitudeStart, sizeof(this->latitudeStart)); bufPtr += sizeof(this->latitudeStart); memcpy(bufPtr, &this->longitudeStart, sizeof(this->longitudeStart)); bufPtr += sizeof(this->longitudeStart); memcpy(bufPtr, &this->width, sizeof(this->width)); bufPtr += sizeof(this->width); memcpy(bufPtr, &this->length, sizeof(this->length)); bufPtr += sizeof(this->length); memcpy(bufPtr, &this->trueHeading, sizeof(this->trueHeading)); } std::uint8_t *getBinaryData() { return file.data(); } std::size_t getBinaryLength() { return file.size(); } }; #endif