/*
 * Check the UpdateDmxData method works
 */
void OlaServerServiceImplTest::testUpdateDmxData() {
  UniverseStore store(NULL, NULL);
  ola::TimeStamp time1;
  ola::Client client(NULL);
  ola::Client client2(NULL);
  OlaServerServiceImpl impl(&store,
                            NULL,
                            NULL,
                            NULL,
                            NULL,
                            NULL,
                            &time1,
                            m_uid);
  OlaClientService service1(&client, &impl);
  OlaClientService service2(&client2, &impl);

  GenericMissingUniverseCheck<UpdateDmxDataCheck, ola::proto::Ack>
    missing_universe_check;
  GenericAckCheck<UpdateDmxDataCheck> ack_check;
  unsigned int universe_id = 0;
  DmxBuffer dmx_data("this is a test");
  DmxBuffer dmx_data2("different data hmm");

  // Update a universe that doesn't exist
  m_clock.CurrentTime(&time1);
  CallUpdateDmxData(&service1, universe_id, dmx_data, missing_universe_check);
  Universe *universe = store.GetUniverse(universe_id);
  OLA_ASSERT_FALSE(universe);

  // Update a universe that exists
  m_clock.CurrentTime(&time1);
  universe = store.GetUniverseOrCreate(universe_id);
  CallUpdateDmxData(&service1, universe_id, dmx_data, ack_check);
  OLA_ASSERT(dmx_data == universe->GetDMX());

  // Update a second client with an older timestamp
  // make sure we're in ltp mode
  OLA_ASSERT_EQ(universe->MergeMode(), Universe::MERGE_LTP);
  time1 = time1 - ola::TimeInterval(1000000);
  CallUpdateDmxData(&service2, universe_id, dmx_data2, ack_check);
  OLA_ASSERT_EQ(dmx_data.Size(), universe->GetDMX().Size());
  // Should continue to hold the old data
  OLA_ASSERT(dmx_data == universe->GetDMX());

  // Now send a new update
  m_clock.CurrentTime(&time1);
  CallUpdateDmxData(&service2, universe_id, dmx_data2, ack_check);
  OLA_ASSERT(dmx_data2 == universe->GetDMX());
}
예제 #2
0
void UniverseTracker::PrintStats() {
  UniverseStatsMap::iterator iter = m_stats.begin();
  TimeStamp now;
  m_clock.CurrentTime(&now);

  TimeInterval interval = now - m_start_time;
  OLA_INFO << "Time delta was " << interval;

  for (; iter != m_stats.end(); ++iter) {
    const UniverseStats stats = iter->second;

    float fps = 0.0;
    if (interval.Seconds() > 0)
      fps = static_cast<float>(stats.frame_count) / interval.Seconds();

    cout << "Universe " << iter->first << endl;
    cout << "  Frames Received: " << stats.frame_count <<
      ", Frames/sec: " << fps << endl;
    cout << "  Frame changes: " << stats.frame_changes << endl;
    cout << "  Smallest Frame: ";
    if (stats.shortest_frame == DMX_UNIVERSE_SIZE + 1)
      cout << "N/A";
    else
      cout << stats.shortest_frame;
    cout << ", Largest Frame: ";
    if (stats.longest_frame == 0)
      cout << "N/A";
    else
      cout << stats.longest_frame;
    cout << endl;
    cout << "------------------------------" << endl;
  }
}
예제 #3
0
/*
 * Check that we update when ports have new data
 */
void UniverseTest::testReceiveDmx() {
  ola::PortBroker broker;
  ola::PortManager port_manager(m_store, &broker);
  TimeStamp time_stamp;
  MockSelectServer ss(&time_stamp);
  ola::PluginAdaptor plugin_adaptor(NULL, &ss, NULL, NULL, NULL, NULL);

  MockDevice device(NULL, "foo");
  TestMockInputPort port(&device, 1, &plugin_adaptor);  // input port
  port_manager.PatchPort(&port, TEST_UNIVERSE);

  Universe *universe = m_store->GetUniverseOrCreate(TEST_UNIVERSE);
  OLA_ASSERT(universe);

  OLA_ASSERT_EQ((unsigned int) 1, universe->InputPortCount());
  OLA_ASSERT_EQ((unsigned int) 0, universe->OutputPortCount());
  OLA_ASSERT(universe->IsActive());

  // Setup the port with some data, and check that signalling the universe
  // works.
  m_clock.CurrentTime(&time_stamp);
  port.WriteDMX(m_buffer);
  port.DmxChanged();
  OLA_ASSERT_EQ(ola::dmx::SOURCE_PRIORITY_DEFAULT, universe->ActivePriority());
  OLA_ASSERT_EQ(m_buffer.Size(), universe->GetDMX().Size());
  OLA_ASSERT(m_buffer == universe->GetDMX());

  // Remove the port from the universe
  universe->RemovePort(&port);
  OLA_ASSERT_FALSE(universe->IsActive());
  OLA_ASSERT_EQ((unsigned int) 0, universe->InputPortCount());
  OLA_ASSERT_EQ((unsigned int) 0, universe->OutputPortCount());
}
예제 #4
0
void UniverseTracker::ResetStats() {
  m_clock.CurrentTime(&m_start_time);

  UniverseStatsMap::iterator iter = m_stats.begin();
  for (; iter != m_stats.end(); ++iter) {
    iter->second.Reset();
  }
  cout << "Reset counters" << endl;
}
예제 #5
0
void Tracker::SendRequest() {
  m_clock.CurrentTime(&m_send_time);
  if (FLAGS_send_dmx) {
    m_wrapper.GetClient()->SendDmx(
        FLAGS_universe,
        m_buffer,
        NewSingleCallback(this, &Tracker::SendComplete));

  } else {
    m_wrapper.GetClient()->FetchDmx(
        FLAGS_universe,
        NewSingleCallback(this, &Tracker::GotDmx));
  }
}
예제 #6
0
/*
 * Check that the base device class works correctly.
 */
void DmxSourceTest::testDmxSource() {
  DmxBuffer buffer("123456789");
  TimeStamp timestamp;
  m_clock.CurrentTime(&timestamp);

  DmxSource source(buffer, timestamp, 100);
  OLA_ASSERT(source.IsSet());
  OLA_ASSERT(buffer == source.Data());
  OLA_ASSERT_EQ(timestamp, source.Timestamp());
  OLA_ASSERT_EQ((uint8_t) 100, source.Priority());

  DmxBuffer buffer2("987654321");
  TimeStamp timestamp2;
  m_clock.CurrentTime(&timestamp2);
  OLA_ASSERT_TRUE(timestamp <= timestamp2);

  source.UpdateData(buffer2, timestamp2, 120);
  OLA_ASSERT(buffer2 == source.Data());
  OLA_ASSERT_EQ(timestamp2, source.Timestamp());
  OLA_ASSERT_EQ((uint8_t) 120, source.Priority());

  DmxSource empty_source;
  OLA_ASSERT_FALSE(empty_source.IsSet());
}
예제 #7
0
void Tracker::LogTime() {
  TimeStamp now;
  m_clock.CurrentTime(&now);
  TimeInterval delta = now - m_send_time;
  if (delta > m_max) {
    m_max = delta;
  }
  m_sum += delta.MicroSeconds();

  OLA_INFO << "RPC took " << delta;
  if (FLAGS_count == ++m_count) {
    m_wrapper.GetSelectServer()->Terminate();
  } else {
    SendRequest();
  }
}
예제 #8
0
/*
 * Test the time based checks
 */
void DmxSourceTest::testIsActive() {
  DmxBuffer buffer("123456789");
  TimeStamp timestamp;
  m_clock.CurrentTime(&timestamp);

  DmxSource source(buffer, timestamp, 100);
  OLA_ASSERT(source.IsSet());

  OLA_ASSERT(source.IsActive(timestamp));
  TimeInterval interval(1000000);
  TimeStamp later = timestamp + interval;
  OLA_ASSERT(source.IsActive(later));

  later = timestamp + TimeInterval(2500000);
  OLA_ASSERT_FALSE(source.IsActive(later));
}
예제 #9
0
/*
 * Check that the DMX get/set works correctly.
 */
void ClientTest::testGetSetDMX() {
  DmxBuffer buffer(TEST_DATA);
  const DmxBuffer empty;
  Client client(NULL);

  ola::TimeStamp timestamp;
  m_clock.CurrentTime(&timestamp);
  ola::DmxSource source(buffer, timestamp, 100);

  // check get/set works
  client.DMXRecieved(TEST_UNIVERSE, source);
  const ola::DmxSource &source2 = client.SourceData(TEST_UNIVERSE);
  OLA_ASSERT(source2.IsSet());
  OLA_ASSERT(source2.Data() == buffer);
  OLA_ASSERT_EQ(timestamp, source2.Timestamp());
  OLA_ASSERT_EQ((uint8_t) 100, source2.Priority());

  // check update works
  ola::DmxBuffer old_data(buffer);
  buffer.Set(TEST_DATA2);
  OLA_ASSERT(source2.Data() == old_data);
  OLA_ASSERT_EQ(timestamp, source2.Timestamp());
  OLA_ASSERT_EQ((uint8_t) 100, source2.Priority());

  source.UpdateData(buffer, timestamp, 120);
  client.DMXRecieved(TEST_UNIVERSE, source);
  const ola::DmxSource source3 = client.SourceData(TEST_UNIVERSE);
  OLA_ASSERT(source3.IsSet());
  OLA_ASSERT(buffer == source3.Data());
  OLA_ASSERT_EQ(timestamp, source3.Timestamp());
  OLA_ASSERT_EQ((uint8_t) 120, source3.Priority());

  // check fetching an unknown universe results in an empty buffer
  const ola::DmxSource source4 = client.SourceData(TEST_UNIVERSE2);
  OLA_ASSERT_FALSE(source4.IsSet());
  OLA_ASSERT(empty == source4.Data());
}
예제 #10
0
bool UniverseTracker::Run() {
  m_clock.CurrentTime(&m_start_time);
  m_wrapper->GetSelectServer()->Run();
  return true;
}
예제 #11
0
/*
 * Check that HTP merging works correctly
 */
void UniverseTest::testHtpMerging() {
  DmxBuffer buffer1, buffer2, htp_buffer;
  buffer1.SetFromString("1,0,0,10");
  buffer2.SetFromString("0,255,0,5,6,7");
  htp_buffer.SetFromString("1,255,0,10,6,7");

  ola::PortBroker broker;
  ola::PortManager port_manager(m_store, &broker);

  TimeStamp time_stamp;
  MockSelectServer ss(&time_stamp);
  ola::PluginAdaptor plugin_adaptor(NULL, &ss, NULL, NULL, NULL, NULL);
  MockDevice device(NULL, "foo");
  MockDevice device2(NULL, "bar");
  TestMockInputPort port(&device, 1, &plugin_adaptor);  // input port
  TestMockInputPort port2(&device2, 1, &plugin_adaptor);  // input port
  port_manager.PatchPort(&port, TEST_UNIVERSE);
  port_manager.PatchPort(&port2, TEST_UNIVERSE);

  Universe *universe = m_store->GetUniverseOrCreate(TEST_UNIVERSE);
  OLA_ASSERT(universe);
  universe->SetMergeMode(Universe::MERGE_HTP);

  OLA_ASSERT_EQ(universe->OutputPortCount(), (unsigned int) 0);
  OLA_ASSERT_EQ(universe->OutputPortCount(), (unsigned int) 0);
  OLA_ASSERT(universe->IsActive());
  OLA_ASSERT_EQ((unsigned int) 0, universe->GetDMX().Size());

  // Setup the ports with some data, and check that signalling the universe
  // works.
  m_clock.CurrentTime(&time_stamp);
  port.WriteDMX(buffer1);
  port.DmxChanged();
  OLA_ASSERT_EQ(ola::dmx::SOURCE_PRIORITY_DEFAULT, universe->ActivePriority());
  OLA_ASSERT_EQ(buffer1.Size(), universe->GetDMX().Size());
  OLA_ASSERT(buffer1 == universe->GetDMX());

  // Now the second port gets data
  m_clock.CurrentTime(&time_stamp);
  port2.WriteDMX(buffer2);
  port2.DmxChanged();
  OLA_ASSERT_EQ(ola::dmx::SOURCE_PRIORITY_DEFAULT, universe->ActivePriority());
  OLA_ASSERT_EQ(htp_buffer.Size(), universe->GetDMX().Size());
  OLA_ASSERT(htp_buffer == universe->GetDMX());

  // now raise the priority of the second port
  uint8_t new_priority = 120;
  port2.SetPriority(new_priority);
  m_clock.CurrentTime(&time_stamp);
  port2.DmxChanged();
  OLA_ASSERT_EQ(new_priority, universe->ActivePriority());
  OLA_ASSERT_EQ(buffer2.Size(), universe->GetDMX().Size());
  OLA_ASSERT(buffer2 == universe->GetDMX());

  // raise the priority of the first port
  port.SetPriority(new_priority);
  m_clock.CurrentTime(&time_stamp);
  port.DmxChanged();
  OLA_ASSERT_EQ(new_priority, universe->ActivePriority());
  OLA_ASSERT_EQ(htp_buffer.Size(), universe->GetDMX().Size());
  OLA_ASSERT(htp_buffer == universe->GetDMX());

  // now check a client
  DmxBuffer client_buffer;
  client_buffer.SetFromString("255,0,0,255,10");
  m_clock.CurrentTime(&time_stamp);
  ola::DmxSource source(client_buffer, time_stamp, new_priority);
  MockClient input_client;
  input_client.DMXReceived(TEST_UNIVERSE, source);
  universe->SourceClientDataChanged(&input_client);

  DmxBuffer client_htp_merge_result;
  client_htp_merge_result.SetFromString("255,255,0,255,10,7");
  OLA_ASSERT_EQ(new_priority, universe->ActivePriority());
  OLA_ASSERT_EQ(client_htp_merge_result.Size(),
                       universe->GetDMX().Size());
  OLA_ASSERT(client_htp_merge_result == universe->GetDMX());

  // clean up
  universe->RemoveSourceClient(&input_client);
  universe->RemovePort(&port);
  universe->RemovePort(&port2);
  OLA_ASSERT_FALSE(universe->IsActive());
}