예제 #1
0
static bool
PDSWC(NMEAInputLine &line, NMEAInfo &info, Vega::VolatileData &volatile_data)
{
  unsigned value;
  if (line.ReadChecked(value) &&
      info.settings.ProvideMacCready(fixed(value) / 10, info.clock))
    volatile_data.mc = value;

  auto &switches = info.switch_state;
  auto &vs = switches.vega;
  vs.inputs = line.ReadHex(0);
  vs.outputs = line.ReadHex(0);

  if (vs.GetFlapLanding())
    switches.flap_position = SwitchState::FlapPosition::LANDING;
  else if (vs.GetFlapZero())
    switches.flap_position = SwitchState::FlapPosition::NEUTRAL;
  else if (vs.GetFlapNegative())
    switches.flap_position = SwitchState::FlapPosition::NEGATIVE;
  else if (vs.GetFlapPositive())
    switches.flap_position = SwitchState::FlapPosition::POSITIVE;
  else
    switches.flap_position = SwitchState::FlapPosition::UNKNOWN;

  if (vs.GetUserSwitchMiddle())
    switches.user_switch = SwitchState::UserSwitch::MIDDLE;
  else if (vs.GetUserSwitchUp())
    switches.user_switch = SwitchState::UserSwitch::UP;
  else if (vs.GetUserSwitchDown())
    switches.user_switch = SwitchState::UserSwitch::DOWN;
  else
    switches.user_switch = SwitchState::UserSwitch::UNKNOWN;

  if (vs.GetAirbrakeLocked())
    switches.airbrake_state = SwitchState::AirbrakeState::LOCKED;
  else if (vs.GetAirbrakeNotLocked())
    switches.airbrake_state = SwitchState::AirbrakeState::NOT_LOCKED;
  else
    switches.airbrake_state = SwitchState::AirbrakeState::UNKNOWN;

  switches.flight_mode = vs.GetCircling()
    ? SwitchState::FlightMode::CIRCLING
    : SwitchState::FlightMode::CRUISE;

  if (line.ReadChecked(value)) {
    info.voltage = fixed(value) / 10;
    info.voltage_available.Update(info.clock);
  }

  return true;
}
예제 #2
0
void
ParsePFLAE(NMEAInputLine &line, FlarmError &error, fixed clock)
{
  char type[2];
  line.Read(type, ARRAY_SIZE(type));
  if (strcmp(type, "A") != 0)
    return;

  error.severity = (FlarmError::Severity)
    line.ReadHex((long)FlarmError::Severity::NO_ERROR);
  error.code = (FlarmError::Code)line.ReadHex(0);

  error.available.Update(clock);
}
예제 #3
0
void
ParsePFLAE(NMEAInputLine &line, FlarmError &error, double clock)
{
    char type[2];
    line.Read(type, ARRAY_SIZE(type));
    if (!StringIsEqual(type, "A"))
        return;

    error.severity = (FlarmError::Severity)
                     line.Read((int)FlarmError::Severity::NO_ERROR);
    error.code = (FlarmError::Code)line.ReadHex(0);

    error.available.Update(clock);
}
예제 #4
0
파일: Parser.cpp 프로젝트: alon/xcsoar
static bool
PDSWC(NMEAInputLine &line, NMEAInfo &info)
{
  static long last_switchinputs;
  static long last_switchoutputs;

  fixed value;
  if (line.ReadChecked(value))
    info.settings.ProvideMacCready(value / 10, info.clock);

  long switchinputs = line.ReadHex(0L);
  long switchoutputs = line.ReadHex(0L);

  if (line.ReadChecked(value)) {
    info.voltage = value / 10;
    info.voltage_available.Update(info.clock);
  }

  info.switch_state_available = true;

  info.switch_state.airbrake_locked =
    (switchinputs & (1<<INPUT_BIT_AIRBRAKELOCKED))>0;
  info.switch_state.flap_positive =
    (switchinputs & (1<<INPUT_BIT_FLAP_POS))>0;
  info.switch_state.flap_neutral =
    (switchinputs & (1<<INPUT_BIT_FLAP_ZERO))>0;
  info.switch_state.flap_negative =
    (switchinputs & (1<<INPUT_BIT_FLAP_NEG))>0;
  info.switch_state.gear_extended =
    (switchinputs & (1<<INPUT_BIT_GEAR_EXTENDED))>0;
  info.switch_state.acknowledge =
    (switchinputs & (1<<INPUT_BIT_ACK))>0;
  info.switch_state.repeat =
    (switchinputs & (1<<INPUT_BIT_REP))>0;
  info.switch_state.speed_command =
    (switchinputs & (1<<INPUT_BIT_SC))>0;
  info.switch_state.user_switch_up =
    (switchinputs & (1<<INPUT_BIT_USERSWUP))>0;
  info.switch_state.user_switch_middle =
    (switchinputs & (1<<INPUT_BIT_USERSWMIDDLE))>0;
  info.switch_state.user_switch_down =
    (switchinputs & (1<<INPUT_BIT_USERSWDOWN))>0;
  /*
  info.switch_state.Stall =
    (switchinputs & (1<<INPUT_BIT_STALL))>0;
  */
  info.switch_state.flight_mode =
    (switchoutputs & (1 << OUTPUT_BIT_CIRCLING)) > 0
    ? SwitchInfo::FlightMode::CIRCLING
    : SwitchInfo::FlightMode::CRUISE;
  info.switch_state.flap_landing =
    (switchoutputs & (1<<OUTPUT_BIT_FLAP_LANDING))>0;

  long up_switchinputs;
  long down_switchinputs;
  long up_switchoutputs;
  long down_switchoutputs;

  // detect changes to ON: on now (x) and not on before (!lastx)
  // detect changes to OFF: off now (!x) and on before (lastx)

  down_switchinputs = (switchinputs & (~last_switchinputs));
  up_switchinputs = ((~switchinputs) & (last_switchinputs));
  down_switchoutputs = (switchoutputs & (~last_switchoutputs));
  up_switchoutputs = ((~switchoutputs) & (last_switchoutputs));

  int i;
  long thebit;
  for (i=0; i<32; i++) {
    thebit = 1<<i;
    if ((down_switchinputs & thebit) == thebit) {
      InputEvents::processNmea(i);
    }
    if ((down_switchoutputs & thebit) == thebit) {
      InputEvents::processNmea(i+32);
    }
    if ((up_switchinputs & thebit) == thebit) {
      InputEvents::processNmea(i+64);
    }
    if ((up_switchoutputs & thebit) == thebit) {
      InputEvents::processNmea(i+96);
    }
  }

  last_switchinputs = switchinputs;
  last_switchoutputs = switchoutputs;

  return true;
}