コード例 #1
0
ファイル: Casts.hpp プロジェクト: HSOFEUP/dune
 inline T
 castLexical(const std::string& str)
 {
   T var = T();
   castLexical(str, var);
   return var;
 }
コード例 #2
0
ファイル: BasicParameterParser.hpp プロジェクト: posilva/dune
      virtual void
      read(const std::string& value)
      {
        m_copy.clear();

        if (!castLexical(value, m_copy))
          throw std::runtime_error("value is not of the correct type");
      }
コード例 #3
0
ファイル: activation.cpp プロジェクト: Aero348/dune
int
main(int argc, char** argv)
{
  if (argc < 4)
  {
    std::fprintf(stderr, "Usage: %s <destination host> <destination port> <entity> <true|false>\n", argv[0]);
    return 1;
  }

  Address dest(argv[1]);

  // Parse port.
  unsigned port = 0;
  if (!castLexical(argv[2], port))
  {
    fprintf(stderr, "ERROR: invalid port '%s'\n", argv[2]);
    return 1;
  }

  if (port > 65535)
  {
    fprintf(stderr, "ERROR: invalid port '%s'\n", argv[2]);
    return 1;
  }

  IMC::EntityParameter p;
  p.name = "Active";
  p.value = argv[4];

  IMC::SetEntityParameters msg;
  msg.name = argv[3];
  msg.params.push_back(p);
  msg.setTimeStamp();

  uint8_t bfr[1024] = {0};
  uint16_t rv = IMC::Packet::serialize(&msg, bfr, sizeof(bfr));

  UDPSocket sock;
  try
  {
    sock.write(bfr, rv, dest, port);

    fprintf(stderr, "Raw:");
    for (int i = 0; i < rv; ++i)
      fprintf(stderr, " %02X", bfr[i]);
    fprintf(stderr, "\n");

    msg.toText(std::cerr);
  }
  catch (std::runtime_error& e)
  {
    std::cerr << "ERROR: " << e.what() << std::endl;
    return 1;
  }

  return 0;
}
コード例 #4
0
ファイル: Casts.hpp プロジェクト: HSOFEUP/dune
  inline bool
  castLexical(const std::string& str, std::vector<T>& var)
  {
    var.clear();
    std::vector<std::string> vec;
    Utils::String::split(str, c_string_list_separator, vec);
    bool no_errors = true;
    for (std::vector<std::string>::iterator itr = vec.begin(); itr != vec.end(); ++itr)
    {
      T elm;
      if (castLexical(*itr, elm))
        var.push_back(elm);
      else
        no_errors = false;
    }

    return no_errors;
  }
コード例 #5
0
ファイル: dune-lucb.cpp プロジェクト: FreddyFox/dune
int
main(int argc, char** argv)
{
  OptionParser options;
  options.executable("lucb")
  .program(DUNE_SHORT_NAME)
  .copyright(DUNE_COPYRIGHT)
  .email(DUNE_CONTACT)
  .version(getFullVersion())
  .date(getCompileDate())
  .arch(DUNE_SYSTEM_NAME)
  .description("Utility to update firmware of LUCL based devices.")
  .add("-d", "--sys-device",
       "System device", "DEVICE")
  .add("-b", "--baud-rate",
       "Baud rate", "BAUD")
  .add("-i", "--i2c-address",
       "I2C slave address", "I2C_ADDR")
  .add("-f", "--file",
       "iHEX file", "IHEX_FILE");

  // Parse command line arguments.
  if (!options.parse(argc, argv))
  {
    if (options.bad())
      std::cerr << "ERROR: " << options.error() << std::endl;
    options.usage();
    return 1;
  }

  // Get iHEX file.
  std::string ihex = options.value("--file");
  if (ihex.empty())
  {
    std::cerr << "ERROR: you must specify one iHEX file." << std::endl;
    return 1;
  }

  // Get system device.
  std::string sys_dev = options.value("--sys-device");
  if (sys_dev.empty())
  {
    std::cerr << "ERROR: you must specify one system device." << std::endl;
    return 1;
  }

  // Get specified baud rate.
  int baud = 0;
  castLexical(options.value("--baud-rate"), baud);

  // Get I2C address (if any).
  bool is_i2c = false;
  uint8_t i2c_addr = 0;
  if (castLexical(options.value("--i2c-address"), i2c_addr))
  {
    if ((i2c_addr < 0x03) || (i2c_addr > 0x77))
    {
      std::cerr << "ERROR: I2C device address is out of range (0x03 - 0x77)" << std::endl;
      return 1;
    }

    is_i2c = true;
  }

  LUCL::Protocol proto;

  if (is_i2c)
    proto.setI2C(sys_dev, i2c_addr);
  else
    proto.setUART(sys_dev);

  try
  {
    LUCL::BootLoader boot(proto, true, baud);
    boot.flash(ihex);
  }
  catch (std::exception& e)
  {
    std::cerr << "ERROR: " << e.what() << std::endl;
  }

  return 0;
}
コード例 #6
0
ファイル: dune-lucl-talk.cpp プロジェクト: AndreGCGuerra/dune
int
main(int argc, char** argv)
{
  OptionParser options;
  options.executable(argv[0])
  .program(DUNE_SHORT_NAME)
  .copyright(DUNE_COPYRIGHT)
  .email("Renato Caldas <*****@*****.**>")
  .version(getFullVersion())
  .date(getCompileDate())
  .arch(DUNE_SYSTEM_NAME)
  .description("Utility to update firmware of LUCL based devices.")
  .add("-d", "--sys-device",
       "System device", "DEVICE")
  .add("-i", "--i2c-address",
       "I2C slave address", "I2C_ADDR")
  .add("-c", "--command",
       "LUCL command", "CMD")
  .add("-p", "--data-payload",
       "LUCL data", "DATA0[,DATA1 ...]");

  // Parse command line arguments.
  if (!options.parse(argc, argv))
  {
    if (options.bad())
      std::cerr << "ERROR: " << options.error() << std::endl;
    options.usage();
    return 1;
  }

  // Get system device.
  std::string sys_dev = options.value("--sys-device");
  if (sys_dev.empty())
  {
    std::cerr << "ERROR: you must specify one system device." << std::endl;
    return 1;
  }

  // Get I2C address (if any).
  bool is_i2c = false;
  uint8_t i2c_addr = 0;
  if (castLexical(options.value("--i2c-address"), i2c_addr))
  {
    if ((i2c_addr < 0x03) || (i2c_addr > 0x77))
    {
      std::cerr << "ERROR: I2C device address is out of range (0x03 - 0x77)" << std::endl;
      return 1;
    }

    is_i2c = true;
  }

  // Open the device
  LUCL::Protocol proto;

  if (is_i2c)
    proto.setI2C(sys_dev, i2c_addr);
  else
    proto.setUART(sys_dev);

  try
  {
    proto.open();
  }
  catch (std::exception& e)
  {
    std::cerr << "ERROR: " << e.what() << std::endl;
    return 1;
  }

  // Check for the command token
  std::string command = options.value("--command");
  if (command.empty())
  {
    std::cerr << "ERROR: reading from stdio not supported yet." << std::endl;
    return 1;
  }

  // Get the data payload
  std::string data_str = options.value("--data-payload");
  std::vector<uint8_t> data_lst;
  if (!castLexical(data_str, data_lst))
  {
    std::cerr << "ERROR: failed to parse the data payload argument." << std::endl;
    return 1;
  }

  // Build and send the packet
  if (command.compare("Info") == 0)
  {
    std::cerr << "Requesting device information" << std::endl;
    try
    {
      proto.requestVersion();
    }
    catch (std::exception& e)
    {
      std::cerr << "ERROR: " << e.what() << std::endl;
      return 1;
    }
  }
  else if (command.compare("Reset") == 0)
  {
    std::cerr << "Requesting reset" << std::endl;
    try
    {
      proto.requestReset();
    }
    catch (std::exception& e)
    {
      std::cerr << "ERROR: " << e.what() << std::endl;
      return 1;
    }
  }
  else
  {
    // Command string not recognized, attempt to interpret it as an integer
    int cmd;
    if (!castLexical(command, cmd))
    {
      std::cerr << "ERROR: bad command \"" << command << "\"" << std::endl;
      return 1;
    }

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

    try
    {
      proto.sendCommand(cmd, (uint8_t*)(&data_lst[0]), (int)data_lst.size());
    }
    catch (std::exception& e)
    {
      std::cerr << "ERROR: " << e.what() << std::endl;
      return 1;
    }
  }

  // Handle the results
  handleReply(proto);

  return 0;
}
コード例 #7
0
ファイル: BasicParameterParser.hpp プロジェクト: posilva/dune
 void
 minimumValue(const std::string& value)
 {
   castLexical(value, m_min);
   m_min_set = false;
 }
コード例 #8
0
ファイル: BasicParameterParser.hpp プロジェクト: posilva/dune
 void
 values(const std::string& list)
 {
   if (!castLexical(list, m_values))
     throw std::runtime_error("possible values are not of the correct type");
 }
コード例 #9
0
ファイル: BasicParameterParser.hpp プロジェクト: posilva/dune
 void
 maximumValue(const std::string& value)
 {
   castLexical(value, m_max);
   m_max_set = false;
 }
コード例 #10
0
 virtual bool
 read(const std::string& value)
 {
   return castLexical(value, m_var);
 }