/*
 * Check that the string set/get methods work
 */
void DmxBufferTest::testStringGetSet() {
  const string data = "abcdefg";
  DmxBuffer buffer;
  uint8_t *result = new uint8_t[data.length()];
  unsigned int size = data.length();

  // Check that setting works
  OLA_ASSERT_TRUE(buffer.Set(data));
  OLA_ASSERT_EQ(data.length(), (size_t) buffer.Size());
  OLA_ASSERT_EQ(data, buffer.Get());
  buffer.Get(result, &size);
  OLA_ASSERT_EQ(data.length(), (size_t) size);
  OLA_ASSERT_EQ(0, memcmp(data.data(), result, size));

  // Check the string constructor
  DmxBuffer string_buffer(data);
  OLA_ASSERT_TRUE(buffer == string_buffer);

  // Set with an empty string
  string data2;
  size = data.length();
  OLA_ASSERT_TRUE(buffer.Set(data2));
  OLA_ASSERT_EQ(data2.length(), (size_t) buffer.Size());
  OLA_ASSERT_EQ(data2, buffer.Get());
  buffer.Get(result, &size);
  OLA_ASSERT_EQ(data2.length(), (size_t) size);
  OLA_ASSERT_EQ(0, memcmp(data2.data(), result, size));
  delete[] result;
}
/*
 * Run this thread
 */
void *VellemanOutputPort::Run() {
  DmxBuffer buffer;
  if (!m_usb_handle)
    return NULL;

  while (1) {
    {
      ola::thread::MutexLocker locker(&m_term_mutex);
      if (m_term)
        break;
    }

    {
      ola::thread::MutexLocker locker(&m_data_mutex);
      buffer.Set(m_buffer);
    }

    if (buffer.Size()) {
      if (!SendDMX(buffer)) {
        OLA_WARN << "Send failed, stopping thread...";
        break;
      }
    } else {
      // sleep for a bit
      usleep(40000);
    }
  }
  libusb_release_interface(m_usb_handle, 0);
  libusb_close(m_usb_handle);
  return NULL;
}
/*
 * Check that SetChannel works
 */
void DmxBufferTest::testSetChannel() {
  DmxBuffer buffer;
  buffer.SetChannel(1, 10);
  buffer.SetChannel(10, 50);

  uint8_t expected[DMX_UNIVERSE_SIZE];
  memset(expected, 0, DMX_UNIVERSE_SIZE);
  expected[1] = 10;
  expected[10] = 50;
  OLA_ASSERT_EQ((unsigned int) DMX_UNIVERSE_SIZE, buffer.Size());
  OLA_ASSERT_EQ(0, memcmp(expected, buffer.GetRaw(), buffer.Size()));

  // Check we can't set values greater than the buffer size
  buffer.SetChannel(999, 50);
  OLA_ASSERT_EQ((unsigned int) DMX_UNIVERSE_SIZE, buffer.Size());
  OLA_ASSERT_EQ(0, memcmp(expected, buffer.GetRaw(), buffer.Size()));

  // Check we can't set values outside the current valida data range
  unsigned int slice_size = 20;
  buffer.Set(expected, slice_size);
  buffer.SetChannel(30, 90);
  buffer.SetChannel(200, 10);

  OLA_ASSERT_EQ(slice_size, buffer.Size());
  OLA_ASSERT_EQ(0, memcmp(expected, buffer.GetRaw(), buffer.Size()));
}
Exemple #4
0
/*
 * Called when there is new DMX data
 */
void DmxMonitor::NewDmx(unsigned int universe,
                        const DmxBuffer &buffer,
                        const string &error) {
  m_buffer.Set(buffer);

  if (m_data_loss_window) {
    // delete the window
    wborder(m_data_loss_window, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
    wrefresh(m_data_loss_window);
    delwin(m_data_loss_window);
    m_data_loss_window = NULL;
    Mask();
  }
  move(0, COLS - 1);
  switch (m_counter % 4) {
    case 0:
      printw("/");
      break;
    case 1:
      printw("-");
      break;
    case 2:
      printw("\\");
      break;
    default:
      printw("|");
      break;
  }
  m_counter++;
  gettimeofday(&m_last_data, NULL);
  Values();
  refresh();
  (void) universe;
  (void) error;
}
/*
 * Handle a streaming DMX update, we don't send responses for this
 */
void OlaServerServiceImpl::StreamDmxData(
    RpcController*,
    const ola::proto::DmxData* request,
    ola::proto::STREAMING_NO_RESPONSE*,
    ola::rpc::RpcService::CompletionCallback*,
    Client *client) {

  Universe *universe = m_universe_store->GetUniverse(request->universe());

  if (!universe)
    return;

  if (client) {
    DmxBuffer buffer;
    buffer.Set(request->data());

    uint8_t priority = ola::dmx::SOURCE_PRIORITY_DEFAULT;
    if (request->has_priority()) {
      priority = request->priority();
      priority = std::max(static_cast<uint8_t>(ola::dmx::SOURCE_PRIORITY_MIN),
                          priority);
      priority = std::min(static_cast<uint8_t>(ola::dmx::SOURCE_PRIORITY_MAX),
                          priority);
    }
    DmxSource source(buffer, *m_wake_up_time, priority);
    client->DMXReceived(request->universe(), source);
    universe->SourceClientDataChanged(client);
  }
}
/*
 * Run this thread
 */
void *SunliteOutputPort::Run() {
  DmxBuffer buffer;
  bool new_data;

  if (!m_usb_handle)
    return NULL;

  while (true) {
    {
      ola::thread::MutexLocker locker(&m_term_mutex);
      if (m_term)
        break;
    }

    {
      ola::thread::MutexLocker locker(&m_data_mutex);
      buffer.Set(m_buffer);
      new_data = m_new_data;
      m_new_data = false;
    }

    if (new_data) {
      if (!SendDMX(buffer)) {
        OLA_WARN << "Send failed, stopping thread...";
        break;
      }
    } else {
      // sleep for a bit
      usleep(40000);
    }
  }
  libusb_release_interface(m_usb_handle, 0);
  libusb_close(m_usb_handle);
  return NULL;
}
/*
 * Handle a streaming DMX update, we don't send responses for this
 */
void OlaServerServiceImpl::StreamDmxData(
    RpcController*,
    const ::ola::proto::DmxData* request,
    ::ola::proto::STREAMING_NO_RESPONSE*,
    ::google::protobuf::Closure*,
    Client *client) {

  Universe *universe = m_universe_store->GetUniverse(request->universe());

  if (!universe)
    return;

  if (client) {
    DmxBuffer buffer;
    buffer.Set(request->data());

    uint8_t priority = DmxSource::PRIORITY_DEFAULT;
    if (request->has_priority()) {
      priority = request->priority();
      priority = std::max(DmxSource::PRIORITY_MIN, priority);
      priority = std::min(DmxSource::PRIORITY_MAX, priority);
    }
    DmxSource source(buffer, *m_wake_up_time, priority);
    client->DMXRecieved(request->universe(), source);
    universe->SourceClientDataChanged(client);
  }
}
/*
 * Update the DMX values for a particular universe
 */
void OlaServerServiceImpl::UpdateDmxData(
    RpcController* controller,
    const DmxData* request,
    Ack*,
    ola::rpc::RpcService::CompletionCallback* done,
    Client *client) {
  ClosureRunner runner(done);
  Universe *universe = m_universe_store->GetUniverse(request->universe());
  if (!universe)
    return MissingUniverseError(controller);

  if (client) {
    DmxBuffer buffer;
    buffer.Set(request->data());

    uint8_t priority = ola::dmx::SOURCE_PRIORITY_DEFAULT;
    if (request->has_priority()) {
      priority = request->priority();
      priority = std::max(static_cast<uint8_t>(ola::dmx::SOURCE_PRIORITY_MIN),
                          priority);
      priority = std::min(static_cast<uint8_t>(ola::dmx::SOURCE_PRIORITY_MAX),
                          priority);
    }
    DmxSource source(buffer, *m_wake_up_time, priority);
    client->DMXReceived(request->universe(), source);
    universe->SourceClientDataChanged(client);
  }
}
/*
 * Update the DMX values for a particular universe
 */
void OlaServerServiceImpl::UpdateDmxData(
    RpcController* controller,
    const DmxData* request,
    Ack*,
    google::protobuf::Closure* done,
    Client *client) {
  ClosureRunner runner(done);
  Universe *universe = m_universe_store->GetUniverse(request->universe());
  if (!universe)
    return MissingUniverseError(controller);

  if (client) {
    DmxBuffer buffer;
    buffer.Set(request->data());

    uint8_t priority = DmxSource::PRIORITY_DEFAULT;
    if (request->has_priority()) {
      priority = request->priority();
      priority = std::max(DmxSource::PRIORITY_MIN, priority);
      priority = std::min(DmxSource::PRIORITY_MAX, priority);
    }
    DmxSource source(buffer, *m_wake_up_time, priority);
    client->DMXRecieved(request->universe(), source);
    universe->SourceClientDataChanged(client);
  }
}
Exemple #10
0
/*
 * Called when there is new DMX data
 */
void DmxMonitor::NewDmx(OLA_UNUSED const ola::client::DMXMetadata &meta,
                        const DmxBuffer &buffer) {
  m_buffer.Set(buffer);

  if (m_data_loss_window) {
    // delete the window
    wborder(m_data_loss_window, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');
    wrefresh(m_data_loss_window);
    delwin(m_data_loss_window);
    m_data_loss_window = NULL;
    Mask();
  }
  move(0, COLS - 1);  // NOLINT(build/include_what_you_use) This is ncurses.h's
  switch (m_counter % 4) {
    case 0:
      printw("/");
      break;
    case 1:
      printw("-");
      break;
    case 2:
      printw("\\");
      break;
    default:
      printw("|");
      break;
  }
  m_counter++;

  Clock clock;
  clock.CurrentTime(&m_last_data);
  Values();
  refresh();
}
/*
 * Check that Get/Set works correctly
 */
void DmxBufferTest::testGetSet() {
  unsigned int fudge_factor = 10;
  unsigned int result_length = sizeof(TEST_DATA2) + fudge_factor;
  uint8_t *result = new uint8_t[result_length];
  unsigned int size = result_length;
  DmxBuffer buffer;
  string str_result;

  OLA_ASSERT_EQ((uint8_t) 0, buffer.Get(0));
  OLA_ASSERT_EQ((uint8_t) 0, buffer.Get(1));

  OLA_ASSERT_FALSE(buffer.Set(NULL, sizeof(TEST_DATA)));

  OLA_ASSERT_TRUE(buffer.Set(TEST_DATA, sizeof(TEST_DATA)));
  OLA_ASSERT_EQ((uint8_t) 1, buffer.Get(0));
  OLA_ASSERT_EQ((uint8_t) 2, buffer.Get(1));
  OLA_ASSERT_EQ((unsigned int) sizeof(TEST_DATA), buffer.Size());
  buffer.Get(result, &size);
  OLA_ASSERT_EQ((unsigned int) sizeof(TEST_DATA), size);
  OLA_ASSERT_EQ(0, memcmp(TEST_DATA, result, size));
  str_result = buffer.Get();
  OLA_ASSERT_EQ((size_t) sizeof(TEST_DATA), str_result.length());
  OLA_ASSERT_EQ(0, memcmp(TEST_DATA, str_result.data(), str_result.length()));

  size = result_length;
  OLA_ASSERT_TRUE(buffer.Set(TEST_DATA2, sizeof(TEST_DATA2)));
  OLA_ASSERT_EQ((unsigned int) sizeof(TEST_DATA2), buffer.Size());
  buffer.Get(result, &size);
  OLA_ASSERT_EQ((unsigned int) sizeof(TEST_DATA2), size);
  OLA_ASSERT_EQ(0, memcmp(TEST_DATA2, result, size));
  str_result = buffer.Get();
  OLA_ASSERT_EQ((size_t) sizeof(TEST_DATA2), str_result.length());
  OLA_ASSERT_EQ(0, memcmp(TEST_DATA2, str_result.data(), str_result.length()));

  // now check that Set() with another buffer works
  DmxBuffer buffer2;
  buffer2.Set(buffer);
  str_result = buffer2.Get();
  OLA_ASSERT_EQ((size_t) sizeof(TEST_DATA2), str_result.length());
  OLA_ASSERT_EQ(0, memcmp(TEST_DATA2, str_result.data(), str_result.length()));

  delete[] result;
}
/**
 * The method called by the thread
 */
void *UartDmxThread::Run() {
  TimeStamp ts1, ts2;
  Clock clock;
  CheckTimeGranularity();
  DmxBuffer buffer;

  // Setup the widget
  if (!m_widget->IsOpen())
    m_widget->SetupOutput();

  while (1) {
    {
      ola::thread::MutexLocker locker(&m_term_mutex);
      if (m_term)
        break;
    }

    {
      ola::thread::MutexLocker locker(&m_buffer_mutex);
      buffer.Set(m_buffer);
    }

    if (!m_widget->SetBreak(true))
      goto framesleep;

    if (m_granularity == GOOD)
      usleep(m_breakt);

    if (!m_widget->SetBreak(false))
      goto framesleep;

    if (m_granularity == GOOD)
      usleep(DMX_MAB);

    if (!m_widget->Write(buffer))
      goto framesleep;

  framesleep:
    // Sleep for the remainder of the DMX frame time
    usleep(m_malft);
  }
  return NULL;
}
 void CaptureData(uint8_t command, const uint8_t *data, unsigned int length) {
   m_received_data.Set(data, length);
   m_command = command;
   m_ss.Terminate();
 }
void UniverseTest::setUp() {
  ola::InitLogging(ola::OLA_LOG_INFO, ola::OLA_LOG_STDERR);
  m_preferences = new ola::MemoryPreferences("foo");
  m_store = new ola::UniverseStore(m_preferences, NULL);
  m_buffer.Set(TEST_DATA);
}