当前位置: 首页>>代码示例>>C++>>正文


C++ Port::Write方法代码示例

本文整理汇总了C++中Port::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ Port::Write方法的具体用法?C++ Port::Write怎么用?C++ Port::Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Port的用法示例。


在下文中一共展示了Port::Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sprintf

static void
WriteWithChecksum(Port &port, const char *String)
{
  port.Write(String);

  char sTmp[8];
  sprintf(sTmp, "%02X\r\n", ::NMEAChecksum(String));
  port.Write(sTmp);
}
开发者ID:DRIZO,项目名称:xcsoar,代码行数:9,代码来源:EW.cpp

示例2:

void
LX::CommandModeQuick(Port &port, OperationEnvironment &env)
{
  port.Write(SYN);
  env.Sleep(500);
  port.Write(SYN);
  env.Sleep(500);
  port.Write(SYN);
  env.Sleep(500);
}
开发者ID:davidswelt,项目名称:XCSoar,代码行数:10,代码来源:Protocol.cpp

示例3: EWMicroRecorderPrintf

bool
EWMicroRecorderDevice::Declare(const Declaration *decl)
{
  // Must have at least two, max 12 waypoints
  if (decl->size() < 2 || decl->size() > 12)
    return false;

  port->StopRxThread();

  port->SetRxTimeout(500);                     // set RX timeout to 500[ms]

  if (!TryConnect())
    return false;

  port->Write('\x18');         // start to upload file
  port->Write(user_data);
  EWMicroRecorderPrintf(port, _T("%-15s %s\r\n"),
               _T("Pilot Name:"), decl->PilotName);
  EWMicroRecorderPrintf(port, _T("%-15s %s\r\n"),
               _T("Competition ID:"), decl->AircraftRego);
  EWMicroRecorderPrintf(port, _T("%-15s %s\r\n"),
               _T("Aircraft Type:"), decl->AircraftType);
  port->Write("Description:      Declaration\r\n");

  for (unsigned i = 0; i < 11; i++) {
    if (i+1>= decl->size()) {
      EWMicroRecorderPrintf(port, _T("%-17s %s\r\n"),
               _T("TP LatLon:"), _T("0000000N00000000E TURN POINT\r\n"));
    } else {
      const Waypoint &wp = decl->waypoints[i];
      if (i == 0) {
        EWMicroRecorderWriteWayPoint(port, wp, _T("Take Off LatLong:"));
        EWMicroRecorderWriteWayPoint(port, wp, _T("Start LatLon:"));
      } else if (i + 1 < decl->size()) {
        EWMicroRecorderWriteWayPoint(port, wp, _T("TP LatLon:"));
      }
    }
  }

  const Waypoint &wp = decl->waypoints[decl->size() - 1];
  EWMicroRecorderWriteWayPoint(port, wp, _T("Finish LatLon:"));
  EWMicroRecorderWriteWayPoint(port, wp, _T("Land LatLon:"));

  port->Write('\x03');         // finish sending user file

  bool success = ExpectStringWait(port, "uploaded successfully");

  port->Write("!!\r\n");         // go back to NMEA mode

  port->SetRxTimeout(0);                       // clear timeout
  port->StartRxThread();                       // restart RX thread

  return success;
}
开发者ID:hnpilot,项目名称:XCSoar,代码行数:54,代码来源:EWMicroRecorder.cpp

示例4:

void
DeviceDescriptor::ForwardLine(const char *line)
{
  /* XXX make this method thread-safe; this method can be called from
     any thread, and if the Port gets closed, bad things happen */

  if (IsNMEAOut() && port != nullptr) {
    Port *p = port;
    p->Write(line);
    p->Write("\r\n");
  }
}
开发者ID:kwtskran,项目名称:XCSoar,代码行数:12,代码来源:Descriptor.cpp

示例5:

bool
CaiGpsNavDevice::Open(OperationEnvironment &env)
{
  port->Write(CtrlC);
  env.Sleep(50);
  port->Write("NMEA\r");

  // This is for a slightly different mode, that
  // apparently outputs pressure info too...
  //port->Write("PNP\r\n");
  //port->Write("LOG 0\r\n");

  return true;
}
开发者ID:Mrdini,项目名称:XCSoar,代码行数:14,代码来源:CaiGpsNav.cpp

示例6:

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;
}
开发者ID:Adrien81,项目名称:XCSoar,代码行数:34,代码来源:Protocol.cpp

示例7: while

bool
Volkslogger::WriteBulk(Port &port, OperationEnvironment &env,
                       const void *buffer, unsigned length)
{
  const unsigned delay = 1;

  env.SetProgressRange(length);

  uint16_t crc16 = 0;
  const uint8_t *p = (const uint8_t *)buffer, *end = p + length;
  while (p < end) {
    unsigned n = end - p;
    if (n > 400)
      n = 400;

    n = port.Write(p, n);
    if (n == 0)
      return false;

    crc16 = UpdateCRC16CCITT(p, n, crc16);
    p += n;

    env.SetProgressPosition(p - (const uint8_t *)buffer);

    /* throttle sending a bit, or the Volkslogger's receive buffer
       will overrun */
    env.Sleep(delay * 100);
  }

  return port.Write(crc16 >> 8) && port.Write(crc16 & 0xff);
}
开发者ID:Adrien81,项目名称:XCSoar,代码行数:31,代码来源:Protocol.cpp

示例8: strchr

static void
EWMicroRecorderPrintf(Port &port, const TCHAR *fmt, ...)
{
  TCHAR EWStr[128];
  va_list ap;

  va_start(ap, fmt);
  _vstprintf(EWStr, fmt, ap);
  va_end(ap);

#ifdef _UNICODE
  char buffer[256];
  if (::WideCharToMultiByte(CP_ACP, 0, EWStr, -1, buffer, sizeof(buffer),
                            NULL, NULL) <= 0)
    return;
#else
  char *buffer = EWStr;
#endif

  char *p = strchr(buffer, ':');
  if (p != NULL)
    ++p;
  else
    p = buffer;

  for (; *p != 0; ++p)
    if (!IsValidEWChar(*p))
      *p = ' ';

  port.Write(buffer);
}
开发者ID:joachimwieland,项目名称:xcsoar-jwieland,代码行数:31,代码来源:EWMicroRecorder.cpp

示例9: timeout

static bool
TryConnect(Port &port, char *user_data, size_t max_user_data,
           OperationEnvironment &env)
{
  port.Flush();
  port.Write('\x02');         // send IO Mode command

  unsigned user_size = 0;

  TimeoutClock timeout(8000);

  while (true) {
    int remaining = timeout.GetRemainingSigned();
    if (remaining < 0)
      return false;

    if (port.WaitRead(env, remaining) != Port::WaitResult::READY)
      return false;

    int nbytes = port.Read(user_data + user_size, max_user_data - user_size);
    if (nbytes < 0)
      return false;

    if (user_size == 0) {
      const char *minus = (const char *)memchr(user_data, '-', nbytes);
      if (minus == NULL)
        continue;

      user_size = user_data + nbytes - minus;
      memmove(user_data, minus, user_size);
    } else
      user_size += nbytes;

    char *end = (char *)memchr(user_data, '\x13', user_size);
    if (end != NULL) {
      *end = 0;
      port.Write('\x16');
      return true;
    }

    if (user_size >= max_user_data)
      /* response too large */
      return false;
  }

  return false;
}
开发者ID:XCame,项目名称:XCSoar,代码行数:47,代码来源:EWMicroRecorder.cpp

示例10: sprintf

bool
XCOM760Device::PutVolume(int Volume)
{
  char szTmp[32];
  sprintf(szTmp, "$RVOL=%d\r\n", Volume);
  port->Write(szTmp);
  return true;
}
开发者ID:joachimwieland,项目名称:xcsoar-jwieland,代码行数:8,代码来源:XCOM760.cpp

示例11: timeout

bool
FLARM::SendEscaped(Port &port, const void *buffer, size_t length,
                   OperationEnvironment &env, unsigned timeout_ms)
{
  assert(buffer != nullptr);
  assert(length > 0);

  const TimeoutClock timeout(timeout_ms);

  // Send data byte-by-byte including escaping
  const uint8_t *p = (const uint8_t *)buffer, *end = p + length;
  while (true) {
    const uint8_t *special = FindSpecial(p, end);

    if (special > p) {
      /* bulk write of "harmless" characters */

      if (!port.FullWrite(p, special - p, env, timeout.GetRemainingOrZero()))
        return false;

      p = special;
    }

    if (p == end)
      break;

    // Check for bytes that need to be escaped and send
    // the appropriate replacements
    bool result;
    if (*p == START_FRAME)
      result = port.Write(ESCAPE) && port.Write(ESCAPE_START);
    else if (*p == ESCAPE)
      result = port.Write(ESCAPE) && port.Write(ESCAPE_ESCAPE);
    else
      // Otherwise just send the original byte
      result = port.Write(*p);

    if (!result)
      return false;

    p++;
  }

  return true;
}
开发者ID:CnZoom,项目名称:XcSoarPull,代码行数:45,代码来源:BinaryProtocol.cpp

示例12: SendCommand

bool
LX::SendPacket(Port &port, Command command,
               const void *data, size_t length,
               OperationEnvironment &env, unsigned timeout_ms)
{
  return SendCommand(port, command) &&
    port.FullWrite(data, length, env, timeout_ms) &&
    port.Write(calc_crc(data, length, 0xff));
}
开发者ID:CnZoom,项目名称:XcSoarPull,代码行数:9,代码来源:Protocol.cpp

示例13: SendCommand

bool
LX::SendPacket(Port &port, Command command,
               const void *data, size_t length,
               OperationEnvironment &env,
               std::chrono::steady_clock::duration timeout)
{
  return SendCommand(port, command) &&
    port.FullWrite(data, length, env, timeout) &&
    port.Write(calc_crc(data, length, 0xff));
}
开发者ID:XCSoar,项目名称:XCSoar,代码行数:10,代码来源:Protocol.cpp

示例14: WriteLabel

static bool
EWMicroRecorderWriteWaypoint(Port &port, const char *type,
                             const Waypoint &way_point)
{
    return WriteLabel(port, type) &&
           WriteGeoPoint(port, way_point.location) &&
           port.Write(' ') &&
           WriteCleanString(port, way_point.name.c_str(), 1000) &&
           port.FullWrite("\r\n", 2, 500);
}
开发者ID:davidswelt,项目名称:XCSoar,代码行数:10,代码来源:EWMicroRecorder.cpp

示例15: while

static bool
TryConnect(Port &port, char *user_data)
{
  int retries=10;

  while (--retries){

    port.Write('\x02');         // send IO Mode command

    unsigned user_size = 0;
    bool started = false;

    PeriodClock clock;
    clock.update();

    int i;
    while ((i = port.GetChar()) != EOF && !clock.check(8000)) {
      char ch = (char)i;

      if (!started && ch == '-')
        started = true;

      if (started) {
        if (ch == 0x13) {
          port.Write('\x16');
          user_data[user_size] = 0;
          // found end of file
          return true;
        } else {
          if (user_size < sizeof(user_data) - 1) {
            user_data[user_size] = ch;
            user_size++;
          }
        }
      }
    }

  }

  return false;
}
开发者ID:joachimwieland,项目名称:xcsoar-jwieland,代码行数:41,代码来源:EWMicroRecorder.cpp


注:本文中的Port::Write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。