Example #1
0
bool ArtNetDevice::StartHook() {
  unsigned int subnet = 0;
  StringToInt(m_preferences->GetValue(K_SUBNET_KEY), &subnet);

  unsigned int net;
  StringToInt(m_preferences->GetValue(K_NET_KEY), &net);

  ola::network::Interface interface;
  auto_ptr<ola::network::InterfacePicker> picker(
      ola::network::InterfacePicker::NewPicker());
  ola::network::InterfacePicker::Options options;
  options.include_loopback = m_preferences->GetValueAsBool(K_LOOPBACK_KEY);
  if (!picker->ChooseInterface(
          &interface,
          m_preferences->GetValue(K_IP_KEY),
          options)) {
    OLA_INFO << "Failed to find an interface";
    return false;
  }

  ArtNetNodeOptions node_options;
  node_options.always_broadcast = m_preferences->GetValueAsBool(
      K_ALWAYS_BROADCAST_KEY);
  node_options.use_limited_broadcast_address = m_preferences->GetValueAsBool(
      K_LIMITED_BROADCAST_KEY);
  // OLA Output ports are ArtNet input ports
  StringToInt(m_preferences->GetValue(K_OUTPUT_PORT_KEY),
              &node_options.input_port_count);

  m_node = new ArtNetNode(interface, m_plugin_adaptor, node_options);
  m_node->SetNetAddress(net);
  m_node->SetSubnetAddress(subnet);
  m_node->SetShortName(m_preferences->GetValue(K_SHORT_NAME_KEY));
  m_node->SetLongName(m_preferences->GetValue(K_LONG_NAME_KEY));

  for (unsigned int i = 0; i < node_options.input_port_count; i++) {
    AddPort(new ArtNetOutputPort(this, i, m_node));
  }

  for (unsigned int i = 0; i < ARTNET_MAX_PORTS; i++) {
    AddPort(new ArtNetInputPort(this, i, m_plugin_adaptor, m_node));
  }

  if (!m_node->Start()) {
    DeleteAllPorts();
    delete m_node;
    m_node = NULL;
    return false;
  }

  ostringstream str;
  str << K_DEVICE_NAME << " [" << interface.ip_address << "]";
  SetName(str.str());

  m_timeout_id = m_plugin_adaptor->RegisterRepeatingTimeout(
      POLL_INTERVAL,
      NewCallback(m_node, &ArtNetNode::SendPoll));
  return true;
}
Example #2
0
void StringUtilsTest::testStringToUInt8() {
  uint8_t value;

  OLA_ASSERT_FALSE(StringToInt("", &value));
  OLA_ASSERT_FALSE(StringToInt("-1", &value));
  OLA_ASSERT_FALSE(StringToInt("256", &value));

  OLA_ASSERT_TRUE(StringToInt("0", &value));
  OLA_ASSERT_EQ((uint8_t) 0, value);
  OLA_ASSERT_TRUE(StringToInt("1", &value));
  OLA_ASSERT_EQ((uint8_t) 1, value);
  OLA_ASSERT_TRUE(StringToInt("143", &value));
  OLA_ASSERT_EQ((uint8_t) 143, value);
  OLA_ASSERT_TRUE(StringToInt("255", &value));
  OLA_ASSERT_EQ((uint8_t) 255, value);
}
Example #3
0
void StringUtilsTest::testStringToUInt16() {
  uint16_t value;

  OLA_ASSERT_FALSE(StringToInt("", &value));
  OLA_ASSERT_FALSE(StringToInt("-1", &value));
  OLA_ASSERT_FALSE(StringToInt("65536", &value));

  OLA_ASSERT_TRUE(StringToInt("0", &value));
  OLA_ASSERT_EQ((uint16_t) 0, value);
  OLA_ASSERT_TRUE(StringToInt("1", &value));
  OLA_ASSERT_EQ((uint16_t) 1, value);
  OLA_ASSERT_TRUE(StringToInt("143", &value));
  OLA_ASSERT_EQ((uint16_t) 143, value);
  OLA_ASSERT_TRUE(StringToInt("65535", &value));
  OLA_ASSERT_EQ((uint16_t) 65535, value);
}
Example #4
0
/*
 * Main
 */
int main(int argc, char *argv[]) {
  TrackerOptions options;
  options.help = false;
  options.log_level = ola::OLA_LOG_WARN;
  ParseOptions(argc, argv, &options);

  if (options.help)
    DisplayHelpAndExit(argv[0]);

  if (options.args.empty())
    DisplayHelpAndExit(argv[0]);

  vector<unsigned int> universes;
  vector<string>::const_iterator iter = options.args.begin();
  for (; iter != options.args.end(); ++iter) {
    unsigned int universe;
    if (!StringToInt(*iter, &universe, true)) {
      cerr << "Invalid Universe " << *iter << endl;
      exit(ola::EXIT_USAGE);
    }
    universes.push_back(universe);
  }

  ola::InitLogging(options.log_level, ola::OLA_LOG_STDERR);

  ola::OlaCallbackClientWrapper ola_client;
  if (!ola_client.Setup()) {
    OLA_FATAL << "Setup failed";
    exit(ola::EXIT_UNAVAILABLE);
  }
  ss = ola_client.GetSelectServer();

  UniverseTracker tracker(&ola_client, universes);
  ola::InstallSignal(SIGINT, InteruptSignal);
  cout << "Actions:" << endl;
  cout << "  p - Print stats" << endl;
  cout << "  q - Quit" << endl;
  cout << "  r - Reset stats" << endl;
  bool r = tracker.Run();
  if (r)
    tracker.PrintStats();
  return r;
}
Example #5
0
void StringUtilsTest::testStringToInt8() {
  int8_t value;

  OLA_ASSERT_FALSE(StringToInt("", &value));
  OLA_ASSERT_FALSE(StringToInt("a", &value));

  OLA_ASSERT_FALSE(StringToInt("-129", &value));
  OLA_ASSERT_TRUE(StringToInt("-128", &value));
  OLA_ASSERT_EQ((int8_t) -128, value);
  OLA_ASSERT_TRUE(StringToInt("-127", &value));
  OLA_ASSERT_EQ((int8_t) -127, value);
  OLA_ASSERT_TRUE(StringToInt("-127", &value));
  OLA_ASSERT_EQ((int8_t) -127, value);
  OLA_ASSERT_TRUE(StringToInt("-1", &value));
  OLA_ASSERT_EQ((int8_t) -1, value);
  OLA_ASSERT_TRUE(StringToInt("0", &value));
  OLA_ASSERT_EQ((int8_t) 0, value);
  OLA_ASSERT_TRUE(StringToInt("1", &value));
  OLA_ASSERT_EQ((int8_t) 1, value);
  OLA_ASSERT_TRUE(StringToInt("127", &value));
  OLA_ASSERT_EQ((int8_t) 127, value);
  OLA_ASSERT_FALSE(StringToInt("128", &value));
  OLA_ASSERT_FALSE(StringToInt("129", &value));
}
Example #6
0
void StringUtilsTest::testStringToInt16() {
  int16_t value;

  OLA_ASSERT_FALSE(StringToInt("", &value));
  OLA_ASSERT_FALSE(StringToInt("a", &value));

  OLA_ASSERT_FALSE(StringToInt("-32769", &value));
  OLA_ASSERT_TRUE(StringToInt("-32768", &value));
  OLA_ASSERT_EQ((int16_t) -32768, value);
  OLA_ASSERT_TRUE(StringToInt("-32767", &value));
  OLA_ASSERT_EQ((int16_t) -32767, value);
  OLA_ASSERT_TRUE(StringToInt("-1", &value));
  OLA_ASSERT_EQ((int16_t) -1, value);

  OLA_ASSERT_TRUE(StringToInt("0", &value));
  OLA_ASSERT_EQ((int16_t) 0, value);
  OLA_ASSERT_TRUE(StringToInt("1", &value));
  OLA_ASSERT_EQ((int16_t) 1, value);
  OLA_ASSERT_TRUE(StringToInt("143", &value));
  OLA_ASSERT_EQ((int16_t) 143, value);
  OLA_ASSERT_TRUE(StringToInt("32767", &value));
  OLA_ASSERT_EQ((int16_t) 32767, value);
  OLA_ASSERT_FALSE(StringToInt("32768", &value));
}
Example #7
0
void StringUtilsTest::testStringToInt() {
  int value;
  OLA_ASSERT_FALSE(StringToInt("", &value));
  OLA_ASSERT_FALSE(StringToInt("a", &value));

  OLA_ASSERT_FALSE(StringToInt("2147483649", &value));
  OLA_ASSERT_TRUE(StringToInt("-2147483648", &value));
  OLA_ASSERT_EQ(static_cast<int>(-2147483647 - 1), value);
  OLA_ASSERT_TRUE(StringToInt("-2147483647", &value));
  OLA_ASSERT_EQ(-2147483647, value);
  OLA_ASSERT_TRUE(StringToInt("-1", &value));
  OLA_ASSERT_EQ(-1, value);

  OLA_ASSERT_TRUE(StringToInt("0", &value));
  OLA_ASSERT_EQ(0, value);
  OLA_ASSERT_TRUE(StringToInt("1", &value));
  OLA_ASSERT_EQ(1, value);
  OLA_ASSERT_TRUE(StringToInt("143", &value));
  OLA_ASSERT_EQ(143, value);
  OLA_ASSERT_TRUE(StringToInt("2147483647", &value));
  OLA_ASSERT_EQ(2147483647, value);
  OLA_ASSERT_FALSE(StringToInt("2147483648", &value));

  // strict mode on
  OLA_ASSERT_FALSE(StringToInt("2147483649 ", &value, true));
  OLA_ASSERT_FALSE(StringToInt("-2147483648bar", &value, true));
  OLA_ASSERT_FALSE(StringToInt("-2147483647 baz", &value, true));
  OLA_ASSERT_FALSE(StringToInt("-1.", &value, true));
  OLA_ASSERT_FALSE(StringToInt("0!", &value, true));
  OLA_ASSERT_FALSE(StringToInt("1 this is a test", &value, true));
  OLA_ASSERT_FALSE(StringToInt("143car", &value, true));
  OLA_ASSERT_FALSE(StringToInt("2147483647 [email protected]#", &value, true));
  OLA_ASSERT_FALSE(StringToInt("2147483648mm", &value, true));
}
Example #8
0
void StringUtilsTest::testStringToUInt() {
  unsigned int value;
  OLA_ASSERT_FALSE(StringToInt("", &value));
  OLA_ASSERT_FALSE(StringToInt("-1", &value));
  OLA_ASSERT_TRUE(StringToInt("0", &value));
  OLA_ASSERT_EQ(0u, value);
  OLA_ASSERT_TRUE(StringToInt("1", &value));
  OLA_ASSERT_EQ(1u, value);
  OLA_ASSERT_TRUE(StringToInt("65537", &value));
  OLA_ASSERT_EQ(65537u, value);
  OLA_ASSERT_TRUE(StringToInt("4294967295", &value));
  OLA_ASSERT_EQ(4294967295U, value);
  OLA_ASSERT_FALSE(StringToInt("4294967296", &value));
  OLA_ASSERT_FALSE(StringToInt("foo", &value));

  // same tests with strict mode on
  OLA_ASSERT_FALSE(StringToInt("-1 foo", &value, true));
  OLA_ASSERT_FALSE(StringToInt("0 ", &value, true));
  OLA_ASSERT_FALSE(StringToInt("1 bar baz", &value, true));
  OLA_ASSERT_FALSE(StringToInt("65537cat", &value, true));
  OLA_ASSERT_FALSE(StringToInt("4294967295bat bar", &value, true));
}