Example #1
0
/**
 * Write a name/value pair to the EW microRecorder.
 */
static bool
WritePair(Port &port, const char *name, const TCHAR *value)
{
    return WriteLabel(port, name) &&
           WriteCleanString(port, value, 1000) &&
           port.FullWrite("\r\n", 2, 500);
}
Example #2
0
/**
 * Write a name/value pair to the EW microRecorder.
 */
static bool
WritePair(Port &port, const char *name, const TCHAR *value,
          OperationEnvironment &env)
{
  return WriteLabel(port, name, env) &&
    WriteCleanString(port, value, env, 1000) &&
    port.FullWrite("\r\n", 2, env, 500);
}
Example #3
0
bool
PortWriteNMEA(Port &port, const char *line, OperationEnvironment &env)
{
  assert(line != nullptr);

  /* reasonable hard-coded timeout; do we need to make this a
     parameter? */
  const unsigned timeout_ms = 1000;

  if (!port.Write('$') ||
      !port.FullWrite(line, strlen(line), env, timeout_ms))
    return false;

  char checksum[16];
  sprintf(checksum, "*%02X\r\n", NMEAChecksum(line));
  return port.FullWrite(checksum, strlen(checksum), env, timeout_ms);
}
Example #4
0
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));
}
Example #5
0
static void
PortWriteNMEANoChecksum(Port &port, const char *line,
                        OperationEnvironment &env)
{
  // reasonable hard-coded timeout; Copied from ::PortWriteNMEA()
  const unsigned timeout_ms = 1000;

  port.FullWrite(line, strlen(line), env, timeout_ms);
}
Example #6
0
static void
PortWriteNMEANoChecksum(Port &port, const char *line,
                        OperationEnvironment &env)
{
  // reasonable hard-coded timeout; Copied from ::PortWriteNMEA()
  constexpr auto timeout = std::chrono::seconds(1);

  port.FullWrite(line, strlen(line), env, timeout);
}
Example #7
0
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);
}
Example #8
0
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));
}
Example #9
0
static bool
SendWithCRC(Port &port, const void *data, size_t length,
            OperationEnvironment &env)
{
  if (!port.FullWrite(data, length, env, 2000))
    return false;

  uint16_t crc16 = UpdateCRC16CCITT(data, length, 0);
  return port.Write(crc16 >> 8) && port.Write(crc16 & 0xff);
}
Example #10
0
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;
}
Example #11
0
static bool
WriteLabel(Port &port, const char *name)
{
    return port.FullWriteString(name, 1000) &&
           port.FullWrite(": ", 2, 500);
}
Example #12
0
int
main(int argc, char **argv)
{
  Args args(argc, argv, "PORT BAUD");
  const DeviceConfig config = ParsePortArgs(args);
  args.ExpectEnd();

  InitialiseIOThread();

  MyHandler handler;
  Port *port = OpenPort(config, handler);
  if (port == NULL) {
    fprintf(stderr, "Failed to open COM port\n");
    return EXIT_FAILURE;
  }

  ConsoleOperationEnvironment env;

  if (!port->WaitConnected(env)) {
    delete port;
    DeinitialiseIOThread();
    fprintf(stderr, "Failed to connect the port\n");
    return EXIT_FAILURE;
  }

  if (!port->StartRxThread()) {
    delete port;
    DeinitialiseIOThread();
    fprintf(stderr, "Failed to start the port thread\n");
    return EXIT_FAILURE;
  }

  unsigned long last_stamp = -1;
  char line[1024];
  while (fgets(line, sizeof(line), stdin) != NULL) {
    char *endptr;
    unsigned long current_stamp = strtoul(line, &endptr, 10);
    if (endptr == line || *endptr != ' ' || endptr[1] != '<')
      continue;

    char *start = endptr + 2;
    char *end = strchr(start, '>');
    if (end == NULL)
      continue;

    *end++ = '\n';
    *end = 0;

    if (current_stamp > last_stamp) {
      unsigned long delta_t = std::min(current_stamp - last_stamp, 1000ul);
      Sleep(delta_t);
    }

    last_stamp = current_stamp;

    if (!port->FullWrite(start, end - start, env, 1000)) {
      fprintf(stderr, "Failed to write to port\n");
      delete port;
      return EXIT_FAILURE;

    }
  }

  delete port;
  DeinitialiseIOThread();
  return EXIT_SUCCESS;
}
Example #13
0
static bool
WriteLabel(Port &port, const char *name, OperationEnvironment &env)
{
  return port.FullWriteString(name, env, 1000) &&
    port.FullWrite(": ", 2, env, 500);
}
Example #14
0
bool
CAI302::WriteString(Port &port, const char *p, OperationEnvironment &env)
{
  size_t length = strlen(p);
  return port.FullWrite(p, length, env, 2000);
}
bool
IMI::Send(Port &port, const TMsg &msg)
{
  return port.FullWrite(&msg, IMICOMM_MSG_HEADER_SIZE + msg.payloadSize + 2, 2000);
}
Example #16
0
 bool Send(Port &port, OperationEnvironment &env) {
   data[fill++] = checksum;
   return port.FullWrite(data, fill, env, 2000);
 }
Example #17
0
bool
IMI::Send(Port &port, const TMsg &msg, OperationEnvironment &env)
{
  return port.FullWrite(&msg, IMICOMM_MSG_HEADER_SIZE + msg.payloadSize + 2,
                        env, 2000);
}