Beispiel #1
0
void
handleReply(LUCL::Protocol& proto)
{
  unsigned retries = 5;

  // Wait for the result
  while (retries)
  {
    LUCL::Command cmd;
    LUCL::CommandType type = proto.consumeData(cmd);

    switch (type)
    {
      case LUCL::CommandTypeReset:
        std::cout << "received reset confirmation" << std::endl;
        break;

      case LUCL::CommandTypeNormal:
        // Print the command and the data in a parseable format
        std::cout << "Received packet CMD 0x" << std::hex << (int)cmd.command.code;
        std::cout << " DATA";
        for (int i = 0; i < cmd.command.size; i++)
        {
          std::cout << " 0x" << std::hex << (int)cmd.command.data[i];
        }
        std::cout << std::endl;
        break;

      case LUCL::CommandTypeVersion:
        std::cout << "Reported version " << cmd.version.major << "." << cmd.version.minor << "." << cmd.version.patch << std::endl;
        break;

      case LUCL::CommandTypeInvalidVersion:
        std::cerr << "Device reported invalid version" << std::endl;
        break;

      case LUCL::CommandTypeError:
        std::cerr << "Device reported: " << proto.getErrorString(cmd.error.code) << std::endl;
        break;

      case LUCL::CommandTypeInvalidChecksum:
        std::cerr << "Invalid checksum while reading data" << std::endl;
        break;

      case LUCL::CommandTypeNone:
        --retries;
        Delay::wait(0.05);
        break;

      default:
        break;
    }
  }
}