LinearVelocity::LinearVelocity(const Distance* const newDistance, const Time* const newTime) { STANDARD_CONSTRUCTOR() distance = 1; time = 1; //Set checks to false bool okDistance = false; bool okTime = false; //Check and convert the distance to meters if (newDistance != nullptr) { LCreal finalDistance = Meters::convertStatic( *newDistance ); okDistance = setMeters(finalDistance); } //Check and convert the time to seconds if (newTime != nullptr) { LCreal finaltime = Seconds::convertStatic( *newTime ); okTime = setSeconds(finaltime); } //Check that both were set correctly - if not give error if ( !okTime || !okDistance ) { //Give error if something was not set correctly: std::cerr << "Distance or Time not set correctly - new LinearVelocity Object bad." << std::endl; } }
void Altitude::setStdAltitude(const Altitude& MSLAltitude, int QNH) { // adapted from Cumulus GpsNmea::calcStdAltitude int qnhDiff = 1013 - QNH; if( qnhDiff != 0 ) { // Calculate altitude correction in meters from pressure difference. // The common approach is to expect a pressure difference of 1 hPa per // 30ft until 18.000ft. 30ft are 9.1437m int delta = (int) rint( qnhDiff * 9.1437 ); setMeters( MSLAltitude.getMeters() + delta ); } else { setMeters(MSLAltitude.getMeters()); } }
//--------------------------------------------------------------------- // setSlotDistance() //--------------------------------------------------------------------- bool LinearVelocity::setSlotDistance(const Distance* const msg) { bool ok = false; //Try to convert Number to a distance if(msg != nullptr) { LCreal finalNumber = Meters::convertStatic(*msg); ok = setMeters(finalNumber); } return ok; }
//--------------------------------------------------------------------- // setMetersPerSecond() //--------------------------------------------------------------------- bool LinearVelocity::setMetersPerSecond(const LCreal newLinearVelocity) { //Set distance and time - units in meters per second -> num = input; den = 1 bool ok1 = setMeters(newLinearVelocity); bool ok2 = setSeconds(1); //Check both values for ok: ok1 = (ok1)&&(ok2); return ok1; }