Beispiel #1
0
static bool
MacCreadyProcessTimer()
{
  bool modified = false;

  static ExternalSettings last_external_settings;
  static Validity last_auto_mac_cready;

  const NMEAInfo &basic = CommonInterface::Basic();
  const DerivedInfo &calculated = CommonInterface::Calculated();

  if (last_auto_mac_cready.Modified(calculated.auto_mac_cready_available)) {
    /* time warp, reset */
    last_auto_mac_cready.Clear();
    modified = true;
  }

  if (basic.settings.mac_cready_available.Modified(last_external_settings.mac_cready_available)) {
    ActionInterface::SetMacCready(basic.settings.mac_cready, false);
    modified = true;
  } else if (calculated.auto_mac_cready_available.Modified(last_auto_mac_cready)) {
    last_auto_mac_cready = calculated.auto_mac_cready_available;
    ActionInterface::SetMacCready(calculated.auto_mac_cready);
    modified = true;
  }

  last_external_settings = basic.settings;

  return modified;
}
Beispiel #2
0
static Validity
invalid()
{
  Validity v;
  v.Clear();
  return v;
}
Beispiel #3
0
 void Reset() {
   bank_angle_available.Clear();
   bank_angle_computed = false;
   pitch_angle_available.Clear();
   pitch_angle_computed = false;
   heading_available.Clear();
   heading_computed = false;
 }
Beispiel #4
0
int main(int argc, char **argv)
{
  Args args(argc, argv, "DRIVER FILE");
  DebugReplay *replay = CreateDebugReplay(args);
  if (replay == NULL)
    return EXIT_FAILURE;

  args.ExpectEnd();

  printf("# time wind_bearing (deg) wind_speed (m/s)\n");

  GlidePolar glide_polar(fixed(0));

  CirclingSettings circling_settings;

  WindSettings wind_settings;
  wind_settings.SetDefaults();

  CirclingComputer circling_computer;
  circling_computer.Reset();

  WindComputer wind_computer;
  wind_computer.Reset();

  Validity last;
  last.Clear();

  while (replay->Next()) {
    const MoreData &basic = replay->Basic();
    const DerivedInfo &calculated = replay->Calculated();

    circling_computer.TurnRate(replay->SetCalculated(),
                               basic, calculated.flight);
    circling_computer.Turning(replay->SetCalculated(),
                              basic,
                              calculated.flight,
                              circling_settings);

    wind_computer.Compute(wind_settings, glide_polar, basic,
                          replay->SetCalculated());

    if (calculated.estimated_wind_available.Modified(last)) {
      TCHAR time_buffer[32];
      FormatTime(time_buffer, replay->Basic().time);

      _tprintf(_T("%s %d %g\n"),
               time_buffer, (int)calculated.estimated_wind.bearing.Degrees(),
               (double)calculated.estimated_wind.norm);
    }

    last = calculated.estimated_wind_available;
  }

  delete replay;
}
Beispiel #5
0
void CanvasBase::validateSelection()
{
    register Sheet * const sheet = activeSheet();
    if (!sheet)
        return;
#if 0
XXX TODO
    if (selection()->isSingular()) {
        const Cell cell = Cell(sheet, selection()->marker()).masterCell();
        Validity validity = cell.validity();
        if (validity.displayValidationInformation()) {
            const QString title = validity.titleInfo();
            QString message = validity.messageInfo();
            if (title.isEmpty() && message.isEmpty())
                return;

            if (!d->validationInfo) {
                d->validationInfo = new QLabel(this);
                QPalette palette = d->validationInfo->palette();
                palette.setBrush(QPalette::Window, palette.toolTipBase());
                palette.setBrush(QPalette::WindowText, palette.toolTipText());
                d->validationInfo->setPalette(palette);
//                 d->validationInfo->setWindowFlags(Qt::ToolTip);
                d->validationInfo->setFrameShape(QFrame::Box);
                d->validationInfo->setAlignment(Qt::AlignVCenter);
                d->validationInfo->setTextFormat(Qt::RichText);
            }

            QString resultText("<html><body>");
            if (!title.isEmpty()) {
                resultText += "<h2>" + title + "</h2>";
            }
            if (!message.isEmpty()) {
                message.replace(QChar('\n'), QString("<br>"));
                resultText += "<p>" + message + "</p>";
            }
            resultText += "</body></html>";
            d->validationInfo->setText(resultText);

            const double xpos = sheet->columnPosition(cell.column()) + cell.width();
            const double ypos = sheet->rowPosition(cell.row()) + cell.height();
            const QPointF position = QPointF(xpos, ypos) - offset();
            const QPoint viewPosition = viewConverter()->documentToView(position).toPoint();
            d->validationInfo->move(/*mapToGlobal*/(viewPosition)); // Qt::ToolTip!
            d->validationInfo->show();
        } else {
            delete d->validationInfo;
            d->validationInfo = 0;
        }
    } else {
        delete d->validationInfo;
        d->validationInfo = 0;
    }
#endif
}
Beispiel #6
0
 /**
  * Set the true airspeed [m/s] and derive the indicated airspeed
  * from it, using the specified altitude [m].
  */
 void ProvideTrueAirspeedWithAltitude(fixed tas, fixed altitude) {
   true_airspeed = tas;
   indicated_airspeed = true_airspeed /
     AtmosphericPressure::AirDensityRatio(altitude);
   airspeed_available.Update(clock);
   airspeed_real = true;
 }
Beispiel #7
0
 bool Complement(const Validity &other) {
   if (!IsValid() && other.IsValid()) {
     *this = other;
     return true;
   } else
     return false;
 }
Beispiel #8
0
 /**
  * Set the true airspeed [m/s] and derive the indicated airspeed
  * from it, using the specified altitude [m].
  */
 void ProvideIndicatedAirspeedWithAltitude(fixed ias, fixed altitude) {
   indicated_airspeed = ias;
   true_airspeed = indicated_airspeed *
     AtmosphericPressure::AirDensityRatio(altitude);
   airspeed_available.Update(clock);
   airspeed_real = true;
 }
Beispiel #9
0
  void Expire(fixed clock) {
    new_traffic.Expire(clock, fixed(60));

    for (unsigned i = list.size(); i-- > 0;)
      if (!list[i].Refresh(clock))
        list.quick_remove(i);
  }
Beispiel #10
0
 void Complement(const FlarmVersion &add) {
   if (available.Complement(add.available)) {
     hardware_version = add.hardware_version;
     software_version = add.software_version;
     obstacle_version = add.obstacle_version;
   }
 }
Beispiel #11
0
void
TrafficListWidget::UpdateList()
{
  assert(filter_widget != nullptr);

  items.clear();
  last_update.Clear();

  const TCHAR *callsign = filter_widget->GetValueString(CALLSIGN);
  if (!StringIsEmpty(callsign)) {
    FlarmId ids[30];
    unsigned count = FlarmDetails::FindIdsByCallSign(callsign, ids, 30);

    for (unsigned i = 0; i < count; ++i)
      AddItem(ids[i]);
  } else {
    /* if no filter was set, show a list of current traffic and known
       traffic */

    /* add live FLARM traffic */
    for (const auto &i : CommonInterface::Basic().flarm.traffic.list) {
      AddItem(i.id);
    }

    /* add FLARM peers that have a user-defined color */
    for (const auto &i : traffic_databases->flarm_colors) {
      Item &item = AddItem(i.first);
      item.color = i.second;
    }

    /* add FLARM peers that have a user-defined name */
    for (const auto &i : traffic_databases->flarm_names) {
      AddItem(i.id);
    }

#ifdef HAVE_SKYLINES_TRACKING_HANDLER
    /* show SkyLines traffic unless this is a FLARM traffic picker
       dialog (from dlgTeamCode) */
    if (action_listener == nullptr) {
      const auto &data = tracking->GetSkyLinesData();
      const ScopeLock protect(data.mutex);
      for (const auto &i : data.traffic) {
        items.emplace_back(i.first, i.second.location);
        Item &item = items.back();

        if (i.second.location.IsValid() &&
            CommonInterface::Basic().location_available)
          item.vector = GeoVector(CommonInterface::Basic().location,
                                  i.second.location);
      }
    }
#endif
  }

  GetList().SetLength(items.size());

  UpdateVolatile();
  UpdateButtons();
}
Beispiel #12
0
void
ProcessTimer::AirspaceProcessTimer()
{
  static Validity previous;

  const AirspaceWarningsInfo &warnings =
    CommonInterface::Calculated().airspace_warnings;

  if (previous.Modified(warnings.latest))
    /* time warp, reset */
    previous.Clear();

  if (warnings.latest.Modified(previous)) {
    previous = warnings.latest;
    CommonInterface::main_window.SendAirspaceWarning();
  }
}
Beispiel #13
0
  void ProvideAutoMacCready(fixed clock, fixed mc) {
    if (auto_mac_cready_available &&
        fabs(auto_mac_cready - mc) < fixed(0.05))
      /* change is too small, ignore the new value to limit the rate */
      return;

    auto_mac_cready = mc;
    auto_mac_cready_available.Update(clock);
  }
Beispiel #14
0
  /**
   * Same as ProvideBaroAltitudeTrue(), but don't overwrite a "strong"
   * value.
   */
  void ProvideWeakBaroAltitude(double value) {
    if (baro_altitude_available && !baro_altitude_weak)
      /* don't overwrite "strong" value */
      return;

    baro_altitude = value;
    baro_altitude_weak = true;
    baro_altitude_available.Update(clock);
  }
Beispiel #15
0
  /**
   * Same as ProvidePressureAltitude(), but don't overwrite a "strong"
   * value.
   */
  void ProvideWeakPressureAltitude(double value) {
    if (pressure_altitude_available && !pressure_altitude_weak)
      /* don't overwrite "strong" value */
      return;

    pressure_altitude = value;
    pressure_altitude_weak = true;
    pressure_altitude_available.Update(clock);
  }
Beispiel #16
0
  void Refresh(fixed Time) {
    available.Expire(Time, fixed(10));
    if (!available)
      traffic.clear();

    for (unsigned i = traffic.size(); i-- > 0;)
      if (!traffic[i].Refresh(Time))
        traffic.quick_remove(i);

    NewTraffic = false;
  }
Beispiel #17
0
 void Complement(const FlarmError &add) {
   if (available.Complement(add.available)) {
     severity = add.severity;
     code = add.code;
   }
 }
Beispiel #18
0
 void Clear() {
   available.Clear();
 }
Beispiel #19
0
 /**
  * Set the external wind value.
  */
 void ProvideExternalWind(const SpeedVector &value) {
   external_wind = value;
   external_wind_available.Update(clock);
 }
Beispiel #20
0
 void Clear() {
   new_traffic.Clear();
   list.clear();
 }
Beispiel #21
0
 /**
  * Set the gross, non-compensated, plain-old vertical speed vario value [m/s].
  */
 void ProvideNoncompVario(double value) {
   noncomp_vario = value;
   noncomp_vario_available.Update(clock);
 }
Beispiel #22
0
 /**
  * Set both true airspeed and indicated airspeed to two different
  * values [m/s].
  */
 void ProvideBothAirspeeds(double ias, double tas) {
   indicated_airspeed = ias;
   true_airspeed = tas;
   airspeed_available.Update(clock);
   airspeed_real = true;
 }
Beispiel #23
0
 /**
  * Used only as a config value that should be saved.
  *
  * Currently used for:
  *       battery voltage measurement (multiplier)
  *       offset between the pitot- and the static pressure sensor in hPa (zero).
  *       temperature sensor
  */
 void ProvideSensorCalibration(double value, double offset) {
   sensor_calibration_factor = value;
   sensor_calibration_offset = offset;
   sensor_calibration_available.Update(clock);
 }
Beispiel #24
0
 /**
  * Provide dynamic pressure from a pitot tube.
  * Use only to compute indicated airspeed when static pressure is known.
  * When both pitot- and dynamic pressure are available use dynamic.
  */
 void ProvideDynamicPressure(AtmosphericPressure value) {
   dyn_pressure = value;
   dyn_pressure_available.Update(clock);
 }
Beispiel #25
0
 /**
  * Provide barometric altitude from a static pressure sensor, but
  * only use it if the previous altitude was not present or the
  * same/lower priority.
  */
 void ProvideStaticPressure(AtmosphericPressure value) {
   static_pressure = value;
   static_pressure_available.Update(clock);
 }
Beispiel #26
0
void ValidityDialog::init()
{
    const Map *const map = m_selection->activeSheet()->map();
    const CalculationSettings *settings = map->calculationSettings();
    const KLocale* locale = settings->locale();
    Validity validity = Cell(m_selection->activeSheet(), m_selection->marker()).validity();
    if (!validity.isEmpty()) {
        message->setPlainText(validity.message());
        title->setText(validity.title());
        QString tmp;
        switch (validity.restriction()) {
        case Validity::None:
            chooseType->setCurrentIndex(0);
            break;
        case Validity::Number:
            chooseType->setCurrentIndex(1);
            if (validity.condition() >= 5)
                val_max->setText(tmp.setNum((double)numToDouble(validity.maximumValue().asFloat())));
            val_min->setText(tmp.setNum((double)numToDouble(validity.minimumValue().asFloat())));
            break;
        case Validity::Integer:
            chooseType->setCurrentIndex(2);
            if (validity.condition() >= 5)
                val_max->setText(tmp.setNum((double)numToDouble(validity.maximumValue().asFloat())));
            val_min->setText(tmp.setNum((double)numToDouble(validity.minimumValue().asFloat())));
            break;
        case Validity::TextLength:
            chooseType->setCurrentIndex(6);
            if (validity.condition() >= 5)
                val_max->setText(tmp.setNum((double)numToDouble(validity.maximumValue().asFloat())));
            val_min->setText(tmp.setNum((double)numToDouble(validity.minimumValue().asFloat())));
            break;
        case Validity::Text:
            chooseType->setCurrentIndex(3);
            break;
        case Validity::Date:
            chooseType->setCurrentIndex(4);
            val_min->setText(locale->formatDate(validity.minimumValue().asDate(settings), KLocale::ShortDate));
            if (validity.condition() >= 5)
                val_max->setText(locale->formatDate(validity.maximumValue().asDate(settings), KLocale::ShortDate));
            break;
        case Validity::Time:
            chooseType->setCurrentIndex(5);
            val_min->setText(locale->formatTime(validity.minimumValue().asTime(settings), true));
            if (validity.condition() >= 5)
                val_max->setText(locale->formatTime(validity.maximumValue().asTime(settings), true));
            break;
        case Validity::List: {
            chooseType->setCurrentIndex(7);
            const QStringList lst = validity.validityList();
            QString tmp;
            for (QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it) {
                tmp += (*it) + '\n';
            }
            validityList->setText(tmp);
        }
        break;
        default :
            chooseType->setCurrentIndex(0);
            break;
        }
        chooseAction->setCurrentIndex(chooseAction->findData(QVariant::fromValue(validity.action())));
        choose->setCurrentIndex(choose->findData(QVariant::fromValue(validity.condition())));
        displayMessage->setChecked(validity.displayMessage());
        allowEmptyCell->setChecked(validity.allowEmptyCell());
        titleHelp->setText(validity.titleInfo());
        messageHelp->setPlainText(validity.messageInfo());
        displayHelp->setChecked(validity.displayValidationInformation());
    }
    changeIndexType(chooseType->currentIndex()) ;
    changeIndexCond(choose->currentIndex()) ;
}
Beispiel #27
0
void ValidityDialog::OkPressed()
{
    const KLocale* locale = m_selection->activeSheet()->map()->calculationSettings()->locale();
    const ValueParser *const parser = m_selection->activeSheet()->map()->parser();
    Validity validity;
    if (chooseType->currentIndex() == 1) {
        bool ok;
        val_min->text().toDouble(&ok);
        if (! ok) {
            KMessageBox::error(this , i18n("This is not a valid value."), i18n("Error"));
            val_min->setText("");
            return;
        }
        val_max->text().toDouble(&ok);
        if (! ok && choose->currentIndex() >= 5 && choose->currentIndex() < 7) {
            KMessageBox::error(this , i18n("This is not a valid value."), i18n("Error"));
            val_max->setText("");
            return;
        }
    } else if (chooseType->currentIndex() == 2 || chooseType->currentIndex() == 6) {
        bool ok;
        val_min->text().toInt(&ok);
        if (! ok) {
            KMessageBox::error(this , i18n("This is not a valid value."), i18n("Error"));
            val_min->setText("");
            return;
        }
        val_max->text().toInt(&ok);
        if (! ok && choose->currentIndex() >= 5 && choose->currentIndex() < 7) {
            KMessageBox::error(this , i18n("This is not a valid value."), i18n("Error"));
            val_max->setText("");
            return;
        }
    } else  if (chooseType->currentIndex() == 5) {
        if (!locale->readTime(val_min->text()).isValid()) {
            KMessageBox::error(this , i18n("This is not a valid time."), i18n("Error"));
            val_min->setText("");
            return;
        }
        if (!locale->readTime(val_max->text()).isValid() && choose->currentIndex()  >= 5) {
            KMessageBox::error(this , i18n("This is not a valid time."), i18n("Error"));
            val_max->setText("");
            return;
        }
    } else  if (chooseType->currentIndex() == 4) {
        if (!locale->readDate(val_min->text()).isValid()) {
            KMessageBox::error(this , i18n("This is not a valid date."), i18n("Error"));
            val_min->setText("");
            return;
        }
        if (!locale->readDate(val_max->text()).isValid() && choose->currentIndex()  >= 5) {
            KMessageBox::error(this , i18n("This is not a valid date."), i18n("Error"));
            val_max->setText("");
            return;
        }
    } else if (chooseType->currentIndex() == 7) {
        //Nothing
    }

    if (chooseType->currentIndex() == 0) {//no validity
        validity.setRestriction(Validity::None);
        validity.setAction(Validity::Stop);
        validity.setCondition(Conditional::Equal);
        validity.setMessage(message->toPlainText());
        validity.setTitle(title->text());
        validity.setMinimumValue(Value());
        validity.setMaximumValue(Value());
    } else {
        validity.setRestriction(chooseType->itemData(chooseType->currentIndex()).value<Validity::Restriction>());
        validity.setAction(chooseAction->itemData(chooseAction->currentIndex()).value<Validity::Action>());
        validity.setCondition(choose->itemData(choose->currentIndex()).value<Conditional::Type>());
        validity.setMessage(message->toPlainText());
        validity.setTitle(title->text());
        validity.setMinimumValue(Value());
        validity.setMaximumValue(Value());

        if (chooseType->currentIndex() == 1) {
            if (choose->currentIndex()  < 5) {
                validity.setMinimumValue(Value(val_min->text().toDouble()));
            } else {
                validity.setMinimumValue(Value(qMin(val_min->text().toDouble(), val_max->text().toDouble())));
                validity.setMaximumValue(Value(qMax(val_max->text().toDouble(), val_min->text().toDouble())));
            }
        } else if (chooseType->currentIndex() == 2 || chooseType->currentIndex() == 6) {
            if (choose->currentIndex()  < 5) {
                validity.setMinimumValue(Value(val_min->text().toInt()));
            } else {
                validity.setMinimumValue(Value(qMin(val_min->text().toInt(), val_max->text().toInt())));
                validity.setMaximumValue(Value(qMax(val_max->text().toInt(), val_min->text().toInt())));
            }
        } else  if (chooseType->currentIndex() == 4) {
            const Value minValue = parser->tryParseDate(val_min->text());
            const Value maxValue = parser->tryParseDate(val_max->text());
            if (choose->currentIndex()  < 5) {
                validity.setMinimumValue(minValue);
            } else {
                if (minValue.less(maxValue)) {
                    validity.setMinimumValue(minValue);
                    validity.setMaximumValue(maxValue);
                } else {
                    validity.setMinimumValue(maxValue);
                    validity.setMaximumValue(minValue);
                }
            }
        } else  if (chooseType->currentIndex() == 5) {
            const Value minValue = parser->tryParseTime(val_min->text());
            const Value maxValue = parser->tryParseTime(val_max->text());
            if (choose->currentIndex()  < 5) {
                validity.setMinimumValue(minValue);
            } else {
                if (minValue.less(maxValue)) {
                    validity.setMaximumValue(maxValue);
                    validity.setMinimumValue(minValue);
                } else {
                    validity.setMaximumValue(minValue);
                    validity.setMinimumValue(maxValue);
                }
            }
        } else if (chooseType->currentIndex() == 7) {
            validity.setValidityList(validityList->toPlainText().split('\n', QString::SkipEmptyParts));
        }
    }
    validity.setDisplayMessage(displayMessage->isChecked());
    validity.setAllowEmptyCell(allowEmptyCell->isChecked());
    validity.setDisplayValidationInformation(displayHelp->isChecked());
    validity.setMessageInfo(messageHelp->toPlainText());
    validity.setTitleInfo(titleHelp->text());

    ValidityCommand* manipulator = new ValidityCommand();
    manipulator->setSheet(m_selection->activeSheet());
    manipulator->setValidity(validity);
    manipulator->add(*m_selection);
    manipulator->execute(m_selection->canvas());

    accept();
}
Beispiel #28
0
 /**
  * Set the barometric TE vario value [m/s].
  */
 void ProvideTotalEnergyVario(double value) {
   total_energy_vario = value;
   total_energy_vario_available.Update(clock);
 }
Beispiel #29
0
 /**
  * Used to compute indicated airspeed
  * when static pressure is known.
  * Value already includes calibration data.
  */
 void ProvidePitotPressure(AtmosphericPressure value) {
   pitot_pressure = value;
   pitot_pressure_available.Update(clock);
 }
Beispiel #30
0
 /**
  * Set the barometric netto vario value [m/s].
  */
 void ProvideNettoVario(double value) {
   netto_vario = value;
   netto_vario_available.Update(clock);
 }