Beispiel #1
0
/**
 * Update the measurements if new level reached
 * @param basic NMEA_INFO for temperature and humidity
 */
void
CuSonde::updateMeasurements(const NMEAInfo &basic,
                            const DerivedInfo &calculated)
{
  // if (not flying) nothing to update...
  if (!calculated.flight.flying)
    return;

  // if (no temperature or humidity available) nothing to update...
  if (!basic.temperature_available || !basic.humidity_available)
    return;

  // find appropriate level
  unsigned short level = (unsigned short)((int)max(basic.GetAltitudeBaroPreferred(),
                                                   fixed(0.0))
                                          / HEIGHT_STEP);

  // if (level out of range) cancel update
  if (level >= NUM_LEVELS)
    return;

  // if (level skipped) cancel update
  if (abs(level - last_level) > 1) {
    last_level = level;
    return;
  }

  // if (no level transition yet) wait for transition
  if (abs(level - last_level) == 0)
    return;

  // calculate ground height
  hGround = calculated.altitude_agl;

  // if (going up)
  if (level > last_level) {
    // we round down (level) because of potential lag of temp sensor
    cslevels[level].updateTemps(basic.humidity,
        Units::ToUserUnit(basic.temperature, unGradCelcius));

    fixed h_agl = fixed(level * HEIGHT_STEP) - hGround;
    cslevels[level].updateThermalIndex(h_agl, maxGroundTemperature);

    if (level > 0) {
      findThermalHeight((unsigned short)(level - 1));
      findCloudBase((unsigned short)(level - 1));
    }

  // if (going down)
  } else {
    // we round up (level+1) because of potential lag of temp sensor
    cslevels[level + 1].updateTemps(basic.humidity,
        Units::ToUserUnit(basic.temperature, unGradCelcius));

    fixed h_agl = fixed((level + 1) * HEIGHT_STEP) - hGround;
    cslevels[level + 1].updateThermalIndex(h_agl, maxGroundTemperature);

    if (level < NUM_LEVELS - 1) {
      findThermalHeight(level);
      findCloudBase(level);
    }
  }

  last_level = level;
}