示例#1
0
void
DeviceDescriptor::OnSysTicker()
{
  assert(InMainThread());

  if (port != nullptr && port->GetState() == PortState::FAILED && !IsOccupied())
    Close();

  if (device == nullptr)
    return;

  const bool now_alive = IsAlive();
  if (!now_alive && was_alive && !IsOccupied()) {
    /* connection was just lost */
    device->LinkTimeout();

    NullOperationEnvironment env;
    EnableNMEA(env);
  }

  was_alive = now_alive;

  if (now_alive || IsBorrowed()) {
    ticker = !ticker;
    if (ticker)
      // write settings to vario every second
      device->OnSysTicker();
  }
}
示例#2
0
bool
LXDevice::PutVolume(unsigned volume, OperationEnvironment &env)
{
  if (!IsLX16xx() || !EnableNMEA(env))
    return false;

  return LX1600::SetVolume(port, env, volume);
}
示例#3
0
bool
DeviceDescriptor::OpenOnPort(DumpPort *_port, OperationEnvironment &env)
{
#if !CLANG_CHECK_VERSION(3,6)
  /* disabled on clang due to -Wtautological-pointer-compare */
  assert(_port != nullptr);
#endif
  assert(port == nullptr);
  assert(device == nullptr);
  assert(second_device == nullptr);
  assert(driver != nullptr);
  assert(!ticker);
  assert(!IsBorrowed());

  reopen_clock.Update();

  device_blackboard->mutex.Lock();
  device_blackboard->SetRealState(index).Reset();
  device_blackboard->ScheduleMerge();
  device_blackboard->mutex.Unlock();

  settings_sent.Clear();
  settings_received.Clear();
  was_alive = false;

  port = _port;

  parser.Reset();
  parser.SetReal(!StringIsEqual(driver->name, _T("Condor")));
  if (config.IsDriver(_T("Condor")))
    parser.DisableGeoid();

  if (driver->CreateOnPort != nullptr) {
    Device *new_device = driver->CreateOnPort(config, *port);

    const ScopeLock protect(mutex);
    device = new_device;

    if (driver->HasPassThrough() && config.use_second_device)
      second_device = second_driver->CreateOnPort(config, *port);
  } else
    port->StartRxThread();

  EnableNMEA(env);

  if (env.IsCancelled()) {
    /* the caller is responsible for freeing the port on error */
    port = nullptr;
    delete device;
    device = nullptr;
    delete second_device;
    second_device = nullptr;
    return false;
  }

  return true;
}
示例#4
0
bool
VaulterDevice::PutBallast(fixed fraction, fixed overload, OperationEnvironment &env)
{
  if (!EnableNMEA(env))
    return false;
  char buffer[30];
  sprintf(buffer,"PITV1,WL=%0.2f", (double)overload);
  return PortWriteNMEA(port, buffer, env);
}
示例#5
0
bool
VaulterDevice::PutMacCready(fixed mc, OperationEnvironment &env)
{
  if (!EnableNMEA(env))
    return false;
  char buffer[30];
  sprintf(buffer,"PITV1,MC=%0.2f", (double)mc);
  return PortWriteNMEA(port, buffer, env);
}
示例#6
0
bool
LXDevice::PutQNH(const AtmosphericPressure &pres, OperationEnvironment &env)
{
  if (!EnableNMEA(env))
    return false;

  if (IsV7())
    return V7::SetQNH(port, env, pres);
  else
    return LX1600::SetQNH(port, env, pres);
}
示例#7
0
bool
LXDevice::PutMacCready(fixed mac_cready, OperationEnvironment &env)
{
  if (!EnableNMEA(env))
    return false;

  if (IsV7())
    return V7::SetMacCready(port, env, mac_cready);
  else
    return LX1600::SetMacCready(port, env, mac_cready);
}
示例#8
0
bool
LXDevice::PutBallast(gcc_unused fixed fraction, fixed overload,
                     OperationEnvironment &env)
{
  if (!EnableNMEA(env))
    return false;

  if (IsV7())
    return V7::SetBallast(port, env, overload);
  else
    return LX1600::SetBallast(port, env, overload);
}
示例#9
0
bool
LXDevice::PutBugs(fixed bugs, OperationEnvironment &env)
{
  if (!EnableNMEA(env))
    return false;

  int transformed_bugs_value = 100 - (int)(bugs*100);

  if (IsV7())
    return V7::SetBugs(port, env, transformed_bugs_value);
  else
    return LX1600::SetBugs(port, env, transformed_bugs_value);
}
示例#10
0
bool
DeviceDescriptor::Open(Port &_port, OperationEnvironment &env)
{
  assert(port == NULL);
  assert(device == NULL);
  assert(driver != NULL);
  assert(!ticker);
  assert(!IsBorrowed());

  reopen_clock.Update();

  device_blackboard->mutex.Lock();
  device_blackboard->SetRealState(index).Reset();
  device_blackboard->ScheduleMerge();
  device_blackboard->mutex.Unlock();

  settings_sent.Clear();
  settings_received.Clear();
  was_alive = false;

  port = &_port;

  assert(driver->CreateOnPort != NULL || driver->IsNMEAOut());
  if (driver->CreateOnPort == NULL) {
    assert(driver->IsNMEAOut());

    /* start the Port thread for NMEA out; this is a kludge for
       TCPPort, because TCPPort calls accept() only in the receive
       thread.  Data received from NMEA out is discarded by our method
       DataReceived().  Once TCPPort gets fixed, this kludge can be
       removed. */
    port->StartRxThread();
    return true;
  }

  parser.Reset();
  parser.SetReal(_tcscmp(driver->name, _T("Condor")) != 0);
  parser.SetIgnoreChecksum(config.ignore_checksum);
  if (config.IsDriver(_T("Condor")))
    parser.DisableGeoid();

  Device *new_device = driver->CreateOnPort(config, *port);

  {
    const ScopeLock protect(mutex);
    device = new_device;
  }

  EnableNMEA(env);
  return true;
}
示例#11
0
bool
LXDevice::RequestV7Setting(const char *name, OperationEnvironment &env)
{
  if (!EnableNMEA(env))
    return false;

  v7_settings.Lock();
  v7_settings.MarkOld(name);
  v7_settings.Unlock();

  char buffer[256];
  sprintf(buffer, "PLXV0,%s,R", name);
  return PortWriteNMEA(port, buffer, env);
}
示例#12
0
bool
LXDevice::PutMacCready(fixed mac_cready, OperationEnvironment &env)
{
  if (!EnableNMEA(env))
    return false;

  char tmp[32];

  if (IsV7())
    sprintf(tmp, "PLXV0,MC,W,%.1f", (double)mac_cready);
  else
    sprintf(tmp, "PFLX2,%1.1f,,,,,,", (double)mac_cready);
  return PortWriteNMEA(port, tmp, env);
}
示例#13
0
bool
LXDevice::SendNanoSetting(const char *name, const char *value,
                        OperationEnvironment &env)
{
  if (!EnableNMEA(env))
    return false;

  nano_settings.Lock();
  nano_settings.MarkOld(name);
  nano_settings.Unlock();

  char buffer[256];
  sprintf(buffer, "PLXVC,SET,W,%s,%s", name, value);
  return PortWriteNMEA(port, buffer, env);
}
示例#14
0
bool
LXDevice::PutQNH(const AtmosphericPressure &pres, OperationEnvironment &env)
{
  if (!EnableNMEA(env))
    return false;

  double altitude_offset =
    (double)pres.StaticPressureToQNHAltitude(AtmosphericPressure::Standard()) / 0.3048;

  char buffer[100];
  if (IsV7())
    sprintf(buffer, "PLXV0,QNH,W,%.2f", altitude_offset);
  else
    sprintf(buffer, "PFLX3,%.2f,,,,,,,,,,,,", altitude_offset);
  return PortWriteNMEA(port, buffer, env);
}
示例#15
0
bool
LXDevice::PutMacCready(fixed mac_cready, OperationEnvironment &env)
{
  if (!EnableNMEA(env))
    return false;

  char tmp[32];
  sprintf(tmp, "PFLX2,%1.1f,,,,,,", (double)mac_cready);
  PortWriteNMEA(port, tmp, env);

  // LXNAV V7 variant:
  sprintf(tmp, "PLXV0,MC,W,%.1f", (double)mac_cready);
  PortWriteNMEA(port, tmp, env);

  return true;
}
示例#16
0
bool
LXDevice::PutBugs(fixed bugs, OperationEnvironment &env)
{
  if (!EnableNMEA(env))
    return false;

  // This is a copy of the routine done in LK8000 for LX MiniMap, realized
  // by Lx developers.

  char tmp[100];
  int transformed_bugs_value = 100 - (int)(bugs*100);

  if (IsV7())
    sprintf(tmp, "PLXV0,BUGS,W,%d", transformed_bugs_value);
  else
    sprintf(tmp, "PFLX2,,,%d,,,", transformed_bugs_value);
  return PortWriteNMEA(port, tmp, env);
}
示例#17
0
bool
LXDevice::PutBallast(gcc_unused fixed fraction, fixed overload,
                     OperationEnvironment &env)
{
  if (!EnableNMEA(env))
    return false;

  // This is a copy of the routine done in LK8000 for LX MiniMap, realized
  // by Lx developers.

  char tmp[100];
  sprintf(tmp, "PFLX2,,%.2f,,,,", (double)overload);
  PortWriteNMEA(port, tmp, env);

  // LXNAV V7 variant:
  sprintf(tmp, "PLXV0,BAL,W,%.2f", (double)overload);
  PortWriteNMEA(port, tmp, env);

  return true;
}