コード例 #1
0
ファイル: Protocol.cpp プロジェクト: Adrien81/XCSoar
bool
Volkslogger::SendCommand(Port &port, OperationEnvironment &env,
                         Command cmd, uint8_t param1, uint8_t param2)
{
  static constexpr unsigned delay = 2;

  /* flush buffers */
  if (!port.FullFlush(env, 20, 100))
    return false;

  /* reset command interpreter */
  if (!Reset(port, env, 6))
    return false;

  /* send command packet */

  const uint8_t cmdarray[8] = {
    (uint8_t)cmd, param1, param2,
    0, 0, 0, 0, 0,
  };

  if (!port.Write(ENQ))
    return false;

  env.Sleep(delay);

  if (!SendWithCRC(port, cmdarray, sizeof(cmdarray), env))
    return false;

  /* wait for confirmation */

  return port.WaitRead(env, 4000) == Port::WaitResult::READY &&
    port.GetChar() == 0;
}
コード例 #2
0
ファイル: Protocol.cpp プロジェクト: CnZoom/XcSoarPull
bool
LX::CommandMode(Port &port, OperationEnvironment &env)
{
  /* switch to command mode, first attempt */

  if (!SendSYN(port) || !port.FullFlush(env, 50, 200))
    return false;

  /* the port is clean now; try the SYN/ACK procedure up to three
     times */
  for (unsigned i = 0; i < 100 && !env.IsCancelled(); ++i)
    if (Connect(port, env))
      /* make sure all remaining ACKs are flushed */
      return port.FullFlush(env, 200, 500);

  return false;
}
コード例 #3
0
ファイル: Protocol.cpp プロジェクト: Adrien81/XCSoar
bool
Volkslogger::ConnectAndFlush(Port &port, OperationEnvironment &env,
                             unsigned timeout_ms)
{
  port.Flush();

  return Connect(port, env, timeout_ms) && port.FullFlush(env, 50, 300);
}
コード例 #4
0
ファイル: Protocol.cpp プロジェクト: XCSoar/XCSoar
bool
Volkslogger::ConnectAndFlush(Port &port, OperationEnvironment &env,
                             std::chrono::steady_clock::duration timeout)
{
  port.Flush();

  return Connect(port, env, timeout) &&
    port.FullFlush(env, std::chrono::milliseconds(50),
                   std::chrono::milliseconds(300));
}
コード例 #5
0
ファイル: Protocol.cpp プロジェクト: davidswelt/XCSoar
bool
LX::CommandMode(Port &port, OperationEnvironment &env)
{
  /* switch to command mode, first attempt */
  port.Write(SYN);

  /* now flush all of the remaining input */
  port.SetRxTimeout(10);
  port.FullFlush(20);

  /* the port is clean now; try the SYN/ACK procedure up to three
     times */
  return port.SetRxTimeout(500) &&
    (Connect(port, env) || Connect(port, env) || Connect(port, env)) &&
    /* ... and configure the timeout */
    port.SetRxTimeout(5000);
}
コード例 #6
0
ファイル: NanoLogger.cpp プロジェクト: Advi42/XCSoar
static bool
DownloadFlightInner(Port &port, const char *filename, FILE *file,
                    OperationEnvironment &env)
{
  PortNMEAReader reader(port, env);
  unsigned row_count = 0, i = 1;

  while (true) {
    /* read up to 32 lines at a time */
    unsigned nrequest = row_count == 0 ? 1 : 32;
    if (row_count > 0) {
      assert(i <= row_count);
      const unsigned remaining = row_count - i + 1;
      if (nrequest > remaining)
        nrequest = remaining;
    }

    const unsigned start = i;
    const unsigned end = start + nrequest;
    unsigned request_retry_count = 0;

    /* read the requested lines and save to file */

    while (i != end) {
      if (i == start) {
        /* send request range to Nano */
        reader.Flush();
        if (!RequestFlight(port, filename, start, end, env))
          return false;
        request_retry_count++;
      }

      TimeoutClock timeout(2000);
      const char *line = reader.ExpectLine("PLXVC,FLIGHT,A,", timeout);
      if (line == nullptr || !HandleFlightLine(line, file, i, row_count)) {
        if (request_retry_count > 5)
          return false;

        /* Discard data which might still be in-transit, e.g. buffered
           inside a bluetooth dongle */
        port.FullFlush(env, 200, 2000);

        /* If we already received parts of the request range correctly break
           out of the loop to calculate new request range */
        if (i != start)
          break;

        /* No valid reply received (i==start) - request same range again */
      }
    }

    if (i > row_count)
      /* finished successfully */
      return true;

    if (start == 1)
      /* configure the range in the first iteration, now that we know
         the length of the file */
      env.SetProgressRange(row_count);

    env.SetProgressPosition(i - 1);
  }
}