示例#1
0
int main (int argc, char* args[]) {
    po::options_description desc("Allowed options");

    desc.add_options()
        ("help", "Display this message")
        ("registers", po::value<int>()->default_value(50), "Number of registers kept in memory")
    ;

    po::variables_map vm;
    po::store(po::parse_command_line(argc, args, desc), vm);
    po::notify(vm);

    if (vm.count("help")) {
        std::cerr << desc << std::endl;
        return 1;
    }

    poleng::bonsai::IncrementalFSA fsa(vm["registers"].as<int>());

    int c = 1;
    std::string line;
    while (getline(std::cin, line)) {
        poleng::bonsai::Word w = line_to_word(line);
    fsa.add_word(w);
    if (c % 100000 == 0)
        std::cerr << "Added " << c << " words - actual size: " << fsa.size() << std::endl;
    c++;
    }
    fsa.finalize();

    std::cerr << "end" << std::endl;
    return 0;
}
示例#2
0
void init(char *interface)
{
  struct netif *ni;

  // Initialize network interface
  if ((ni = init_ec(interface)) == NULL)
  {
    fprintf(stderr, "Unable to initialize interface: %s", interface);
    exit(-1);
  }

  // Initialize Application Layer (AL)
  EtherCAT_DataLinkLayer::instance()->attach(ni);
  EtherCAT_AL *al;
  if ((al = EtherCAT_AL::instance()) == NULL)
  {
    fprintf(stderr, "Unable to initialize Application Layer (AL): %08x", (int)al);
    exit(-1);
  }

  uint32_t num_slaves = al->get_num_slaves();
  if (num_slaves == 0)
  {
    fprintf(stderr, "Unable to locate any slaves");
    exit(-1);
  }

  // Initialize Master
  EtherCAT_Master *em;
  if ((em = EtherCAT_Master::instance()) == NULL)
  {
    fprintf(stderr, "Unable to initialize EtherCAT_Master: %08x", int(em));
    exit(-1);
  }

  static int startAddress = 0x00010000;

  for (unsigned int slave = 0; slave < num_slaves; ++slave)
  {
    EC_FixedStationAddress fsa(slave + 1);
    EtherCAT_SlaveHandler *sh = em->get_slave_handler(fsa);
    if (sh == NULL)
    {
      fprintf(stderr, "Unable to get slave handler #%d", slave);
      exit(-1);
    }

    if (sh->get_product_code() == WG05::PRODUCT_CODE)
    {
      printf("found a WG05 at #%d\n", slave);
      WG05 *dev = new WG05();
      dev->configure(startAddress, sh);
      devices.push_back(dev);
    }
    else if (sh->get_product_code() == WG06::PRODUCT_CODE)
    {
      printf("found a WG06 at #%d\n", slave);
      WG06 *dev = new WG06();
      dev->configure(startAddress, sh);
      devices.push_back(dev);
    }
    else
    {
      printf("found a %08x at #%d\n", sh->get_product_code(), slave);
      devices.push_back(NULL);
    }
  }

  BOOST_FOREACH(WG0X *device, devices)
  {
    Actuator a;
    if (!device) continue;
    if (!device->sh_->to_state(EC_OP_STATE))
    {
      fprintf(stderr, "Unable set device %d into OP_STATE", device->sh_->get_ring_position());
    }
    device->initialize(&a, true);
  }