Example #1
0
void OPCServerTest::testReceiveDmx() {
  DmxBuffer buffer;
  buffer.SetFromString("1,2,3,4");
  SendDataAndCheck(CHANNEL, buffer);
  buffer.SetFromString("5,6");
  SendDataAndCheck(CHANNEL, buffer);
  buffer.SetFromString("5,6,7,8,89,9,5,6,7,8,3");
  SendDataAndCheck(CHANNEL, buffer);
}
Example #2
0
/**
 * Test DMX writes in the individual P9813 mode.
 */
void SPIOutputTest::testIndividualP9813Control() {
  FakeSPIBackend backend(2);
  SPIOutput::Options options(0, "Test SPI Device");
  options.pixel_count = 2;
  SPIOutput output(m_uid, &backend, options);
  output.SetPersonality(5);

  DmxBuffer buffer;
  unsigned int length = 0;
  const uint8_t *data = NULL;

  buffer.SetFromString("1, 10, 100");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED0[] = { 0, 0, 0, 0, 0xEF, 0x64, 0x0A, 0x01,
                                0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  OLA_ASSERT_DATA_EQUALS(EXPECTED0, arraysize(EXPECTED0), data, length);
  OLA_ASSERT_EQ(1u, backend.Writes(0));

  buffer.SetFromString("255,128,0,10,20,30");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED1[] = { 0, 0, 0, 0, 0xF4, 0, 0x80, 0xFF,
                                0xFF, 0x1E, 0x14, 0x0A, 0, 0, 0, 0, 0, 0, 0, 0};
  OLA_ASSERT_DATA_EQUALS(EXPECTED1, arraysize(EXPECTED1), data, length);
  OLA_ASSERT_EQ(2u, backend.Writes(0));

  buffer.SetFromString("34,56,78");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED2[] = { 0, 0, 0, 0, 0xEF, 0x4E, 0x38, 0x22,
                                0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  OLA_ASSERT_DATA_EQUALS(EXPECTED2, arraysize(EXPECTED2), data, length);
  OLA_ASSERT_EQ(3u, backend.Writes(0));

  buffer.SetFromString("7, 9");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  OLA_ASSERT_DATA_EQUALS(EXPECTED2, arraysize(EXPECTED2), data, length);
  OLA_ASSERT_EQ(3u, backend.Writes(0));

  output.SetStartAddress(3);
  buffer.SetFromString("1,2,3,4,5,6,7,8");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED4[] = { 0, 0, 0, 0, 0xFF, 0x05, 0x04, 0x03,
                                0xFF, 0x08, 0x07, 0x06, 0, 0, 0, 0, 0, 0, 0, 0};
  OLA_ASSERT_DATA_EQUALS(EXPECTED4, arraysize(EXPECTED4), data, length);
  OLA_ASSERT_EQ(4u, backend.Writes(0));

  // Check nothing changed on the other output.
  OLA_ASSERT_EQ(reinterpret_cast<const uint8_t*>(NULL),
                backend.GetData(1, &length));
  OLA_ASSERT_EQ(0u, backend.Writes(1));
}
Example #3
0
/**
 * Test DMX writes in the individual LPD8806 mode.
 */
void SPIOutputTest::testIndividualLPD8806Control() {
  FakeSPIBackend backend(2);
  SPIOutput::Options options(0);
  options.pixel_count = 2;
  SPIOutput output(m_uid, &backend, options);
  output.SetPersonality(3);

  DmxBuffer buffer;
  unsigned int length = 0;
  const uint8_t *data = NULL;

  buffer.SetFromString("1, 10, 100");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED0[] = { 0x85, 0x80, 0xb2, 0, 0, 0, 0};
  ASSERT_DATA_EQUALS(__LINE__, EXPECTED0, arraysize(EXPECTED0), data, length);
  OLA_ASSERT_EQ(1u, backend.Writes(0));

  buffer.SetFromString("255,128,0,10,20,30");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED1[] = { 0xc0, 0xff, 0x80, 0x8a, 0x85, 0x8f, 0 };
  ASSERT_DATA_EQUALS(__LINE__, EXPECTED1, arraysize(EXPECTED1), data, length);
  OLA_ASSERT_EQ(2u, backend.Writes(0));

  buffer.SetFromString("34,56,78");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED2[] = { 0x9c, 0x91, 0xa7, 0x8a, 0x85, 0x8f, 0 };
  ASSERT_DATA_EQUALS(__LINE__, EXPECTED2, arraysize(EXPECTED2), data, length);
  OLA_ASSERT_EQ(3u, backend.Writes(0));

  buffer.SetFromString("7, 9");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  ASSERT_DATA_EQUALS(__LINE__, EXPECTED2, arraysize(EXPECTED2), data, length);
  OLA_ASSERT_EQ(3u, backend.Writes(0));

  output.SetStartAddress(3);
  buffer.SetFromString("1,2,3,4,5,6,7,8");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED4[] = { 0x82, 0x81, 0x82, 0x83, 0x83, 0x84, 0 };
  ASSERT_DATA_EQUALS(__LINE__, EXPECTED4, arraysize(EXPECTED4), data, length);
  OLA_ASSERT_EQ(4u, backend.Writes(0));

  // Check nothing changed on the other output.
  OLA_ASSERT_EQ(reinterpret_cast<const uint8_t*>(NULL),
                backend.GetData(1, &length));
  OLA_ASSERT_EQ(0u, backend.Writes(1));
}
Example #4
0
/*
 * Check that we can send DMX
 */
void RobeWidgetTest::testSendDMX() {
  // dmx data
  DmxBuffer buffer;
  buffer.SetFromString("0,1,2,3,4");

  // expected message
  uint8_t dmx_frame_data[] = {0, 1, 2, 3, 4, 0, 0, 0, 0};
  // add the expected data, run and verify.
  m_endpoint->AddExpectedRobeMessage(
      DMX_FRAME_LABEL,
      dmx_frame_data,
      sizeof(dmx_frame_data),
      ola::NewSingleCallback(this, &RobeWidgetTest::Terminate));
  m_widget->SendDMX(buffer);
  m_ss.Run();
  m_endpoint->Verify();

  // now test an empty frame
  DmxBuffer buffer2;
  uint8_t empty_frame_data[] = {0, 0, 0, 0};  // null frames still have 4 bytes

  // add the expected data, run and verify.
  m_endpoint->AddExpectedRobeMessage(
      DMX_FRAME_LABEL,
      empty_frame_data,
      sizeof(empty_frame_data),
      ola::NewSingleCallback(this, &RobeWidgetTest::Terminate));
  m_widget->SendDMX(buffer2);
  m_ss.Run();
  m_endpoint->Verify();
}
/**
 * Check that we can send DMX
 */
void BaseUsbProWidgetTest::testSendDMX() {
  // dmx data
  DmxBuffer buffer;
  buffer.SetFromString("0,1,2,3,4");

  // expected message
  uint8_t dmx_frame_data[] = {DMX512_START_CODE, 0, 1, 2, 3, 4};
  m_endpoint->AddExpectedUsbProMessage(
      DMX_FRAME_LABEL,
      dmx_frame_data,
      sizeof(dmx_frame_data),
      ola::NewSingleCallback(this, &BaseUsbProWidgetTest::Terminate));

  m_widget->SendDMX(buffer);
  m_ss.Run();
  m_endpoint->Verify();

  // now test an empty frame
  DmxBuffer buffer2;
  uint8_t empty_frame_data[] = {DMX512_START_CODE};  // just the start code
  m_endpoint->AddExpectedUsbProMessage(
      DMX_FRAME_LABEL,
      empty_frame_data,
      sizeof(empty_frame_data),
      ola::NewSingleCallback(this, &BaseUsbProWidgetTest::Terminate));
  m_widget->SendDMX(buffer2);
  m_ss.Run();
  m_endpoint->Verify();
}
Example #6
0
/*
 * Test receiving works.
 */
void RobeWidgetTest::testReceive() {
  DmxBuffer buffer;
  buffer.SetFromString("0,1,2,3,4");

  // change to recv mode & setup the callback
  m_endpoint->AddExpectedRobeMessage(
      DMX_IN_REQUEST_LABEL,
      NULL,
      0,
      ola::NewSingleCallback(this, &RobeWidgetTest::Terminate));
  m_widget->ChangeToReceiveMode();
  m_ss.Run();
  m_endpoint->Verify();
  m_widget->SetDmxCallback(
      ola::NewCallback(this, &RobeWidgetTest::NewDMXData));
  CPPUNIT_ASSERT(!m_new_dmx_data);

  // now send some data
  m_endpoint->SendUnsolicitedRobeData(DMX_IN_RESPONSE_LABEL,
                                      buffer.GetRaw(),
                                      buffer.Size());
  m_ss.Run();
  CPPUNIT_ASSERT(m_new_dmx_data);
  const DmxBuffer &new_data = m_widget->FetchDMX();
  CPPUNIT_ASSERT(buffer == new_data);
}
Example #7
0
/**
 * Test DMX writes in the combined WS2801 mode.
 */
void SPIOutputTest::testCombinedWS2801Control() {
  FakeSPIBackend backend(2);
  SPIOutput::Options options(0);
  options.pixel_count = 2;
  SPIOutput output(m_uid, &backend, options);
  output.SetPersonality(2);

  DmxBuffer buffer;
  buffer.SetFromString("255,128,0,10,20,30");
  output.WriteDMX(buffer);

  unsigned int length = 0;
  const uint8_t *data = backend.GetData(0, &length);

  const uint8_t EXPECTED1[] = { 255, 128, 0, 255, 128, 0 };
  ASSERT_DATA_EQUALS(__LINE__, EXPECTED1, arraysize(EXPECTED1), data, length);
  OLA_ASSERT_EQ(1u, backend.Writes(0));

  buffer.SetFromString("34,56,78");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED2[] = { 34, 56, 78, 34, 56, 78 };
  ASSERT_DATA_EQUALS(__LINE__, EXPECTED2, arraysize(EXPECTED2), data, length);
  OLA_ASSERT_EQ(2u, backend.Writes(0));

  // Frames with insufficient data don't trigger writes.
  buffer.SetFromString("7, 9");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  ASSERT_DATA_EQUALS(__LINE__, EXPECTED2, arraysize(EXPECTED2), data, length);
  OLA_ASSERT_EQ(2u, backend.Writes(0));

  output.SetStartAddress(3);
  buffer.SetFromString("1,2,3,4,5,6,7,8");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED4[] = { 3, 4, 5, 3, 4, 5};
  ASSERT_DATA_EQUALS(__LINE__, EXPECTED4, arraysize(EXPECTED4), data, length);
  OLA_ASSERT_EQ(3u, backend.Writes(0));

  // Check nothing changed on the other output.
  OLA_ASSERT_EQ(reinterpret_cast<const uint8_t*>(NULL),
                backend.GetData(1, &length));
  OLA_ASSERT_EQ(0u, backend.Writes(1));
}
/**
 * Check that triggering on a rising edge works correctly.
 */
void DMXTriggerTest::testRisingEdgeTrigger() {
  // setup the actions
  vector<Slot*> slots;
  Slot slot(2);
  MockAction *action = new MockAction();
  BadAction *bad_action = new BadAction();
  ValueInterval interval(10, 20);
  slot.AddAction(interval, action, bad_action);
  slots.push_back(&slot);

  Context context;
  DMXTrigger trigger(&context, slots);
  DmxBuffer buffer;

  // this shouldn't trigger
  buffer.SetFromString("0,0,0");
  trigger.NewDMX(buffer);
  OLA_ASSERT(action->NoCalls());

  // trigger rising edge
  buffer.SetFromString("0,0,10");
  trigger.NewDMX(buffer);
  action->CheckForValue(__LINE__, 10);

  // now send the same again
  OLA_ASSERT(action->NoCalls());
  trigger.NewDMX(buffer);
  OLA_ASSERT(action->NoCalls());

  // shorten the frame
  buffer.SetFromString("0,0");
  trigger.NewDMX(buffer);
  OLA_ASSERT(action->NoCalls());

  // lengthen again
  buffer.SetFromString("0,0,10,0");
  trigger.NewDMX(buffer);
  OLA_ASSERT(action->NoCalls());

  // change everything else
  buffer.SetFromString("10,100,10,20");
  trigger.NewDMX(buffer);
  OLA_ASSERT(action->NoCalls());
}
/*
 * Test ToString()
 */
void DmxBufferTest::testToString() {
  DmxBuffer buffer;
  OLA_ASSERT_EQ(string(""), buffer.ToString());

  buffer.SetFromString("1,2,3,4");
  OLA_ASSERT_EQ(string("1,2,3,4"), buffer.ToString());

  buffer.SetRangeToValue(0, 255, 5);
  OLA_ASSERT_EQ(string("255,255,255,255,255"), buffer.ToString());
}
Example #10
0
void OPCServerTest::testUnknownCommand() {
  uint8_t data[] = {1, 1, 0, 2, 3, 4};
  m_client_socket->Send(data, arraysize(data));
  m_ss.Run();

  DmxBuffer buffer;
  buffer.SetFromString("3,4");
  OLA_ASSERT_EQ(static_cast<uint8_t>(1), m_command);
  OLA_ASSERT_EQ(m_received_data, buffer);
}
Example #11
0
/**
 * Test DMX writes in the combined LPD8806 mode.
 */
void SPIOutputTest::testCombinedLPD8806Control() {
  FakeSPIBackend backend(2);
  SPIOutput::Options options(0, "Test SPI Device");
  options.pixel_count = 2;
  SPIOutput output(m_uid, &backend, options);
  output.SetPersonality(4);

  DmxBuffer buffer;
  buffer.SetFromString("255,128,0,10,20,30");
  output.WriteDMX(buffer);

  unsigned int length = 0;
  const uint8_t *data = backend.GetData(0, &length);

  const uint8_t EXPECTED1[] = { 0xC0, 0xFF, 0x80, 0xC0, 0xFF, 0x80, 0};
  OLA_ASSERT_DATA_EQUALS(EXPECTED1, arraysize(EXPECTED1), data, length);
  OLA_ASSERT_EQ(1u, backend.Writes(0));

  buffer.SetFromString("34,56,78");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED2[] = { 0x9C, 0x91, 0xA7, 0x9C, 0x91, 0xA7, 0 };
  OLA_ASSERT_DATA_EQUALS(EXPECTED2, arraysize(EXPECTED2), data, length);
  OLA_ASSERT_EQ(2u, backend.Writes(0));

  buffer.SetFromString("7, 9");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  OLA_ASSERT_DATA_EQUALS(EXPECTED2, arraysize(EXPECTED2), data, length);
  OLA_ASSERT_EQ(2u, backend.Writes(0));

  output.SetStartAddress(3);
  buffer.SetFromString("1,2,3,4,5,6,7,8");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED4[] = { 0x82, 0x81, 0x82, 0x82, 0x81, 0x82, 0 };
  OLA_ASSERT_DATA_EQUALS(EXPECTED4, arraysize(EXPECTED4), data, length);

  // Check nothing changed on the other output.
  OLA_ASSERT_EQ(reinterpret_cast<const uint8_t*>(NULL),
                backend.GetData(1, &length));
  OLA_ASSERT_EQ(0u, backend.Writes(1));
}
/**
 * Test that falling edges trigger
 */
void DMXTriggerTest::testFallingEdgeTrigger() {
  // setup the actions
  vector<Slot*> slots;
  Slot slot(2);
  MockAction *rising_action = new MockAction();
  MockAction *falling_action = new MockAction();
  ValueInterval interval(10, 20);
  slot.AddAction(interval, rising_action, falling_action);
  slots.push_back(&slot);

  Context context;
  DMXTrigger trigger(&context, slots);
  DmxBuffer buffer;

  // trigger
  buffer.SetFromString("0,0,20");
  trigger.NewDMX(buffer);
  rising_action->CheckForValue(__LINE__, 20);
  OLA_ASSERT(falling_action->NoCalls());

  // trigger a falling edge
  buffer.SetFromString("0,0,19");
  trigger.NewDMX(buffer);
  OLA_ASSERT(rising_action->NoCalls());
  falling_action->CheckForValue(__LINE__, 19);

  // now send the same again
  trigger.NewDMX(buffer);
  OLA_ASSERT(rising_action->NoCalls());
  OLA_ASSERT(falling_action->NoCalls());

  // shorten the frame
  buffer.SetFromString("0,0");
  trigger.NewDMX(buffer);
  OLA_ASSERT(rising_action->NoCalls());
  OLA_ASSERT(falling_action->NoCalls());

  // lengthen again
  buffer.SetFromString("0,0,19,0");
  trigger.NewDMX(buffer);
  OLA_ASSERT(rising_action->NoCalls());
  OLA_ASSERT(falling_action->NoCalls());

  // change everything else
  buffer.SetFromString("10,100,19,20");
  trigger.NewDMX(buffer);
  OLA_ASSERT(rising_action->NoCalls());
  OLA_ASSERT(falling_action->NoCalls());

  // change once more
  buffer.SetFromString("10,100,20,20");
  trigger.NewDMX(buffer);
  rising_action->CheckForValue(__LINE__, 20);
  OLA_ASSERT(falling_action->NoCalls());
}
Example #13
0
void OSCNodeTest::setUp() {
  // Init logging
  ola::InitLogging(ola::OLA_LOG_INFO, ola::OLA_LOG_STDERR);

  // Setup and register the Timeout.
  m_timeout_id = m_ss.RegisterSingleTimeout(
        ABORT_TIMEOUT_IN_MS,
        ola::NewSingleCallback(this, &OSCNodeTest::Timeout));
  OLA_ASSERT_TRUE(m_timeout_id);

  // Init our UDP socket.
  OLA_ASSERT_TRUE(m_udp_socket.Init());
  // Put some data into the DMXBuffer
  m_dmx_data.SetFromString("0,1,2,3,4,5,6,7,8,9,10");

  // Initialize the OSCNode
  OLA_ASSERT_TRUE(m_osc_node->Init());
}
Example #14
0
/*
 * Handle the set dmx command
 * @param request the HTTPRequest
 * @param response the HTTPResponse
 * @returns MHD_NO or MHD_YES
 */
int OladHTTPServer::HandleSetDmx(const HTTPRequest *request,
                                HTTPResponse *response) {
  if (request->CheckParameterExists(HELP_PARAMETER))
    return ServeUsage(response,
        "POST u=[universe], d=[DMX data (a comma separated list of values)]");
  string dmx_data_str = request->GetPostParameter("d");
  string uni_id = request->GetPostParameter("u");
  unsigned int universe_id;
  if (!StringToInt(uni_id, &universe_id))
    return ServeHelpRedirect(response);

  DmxBuffer buffer;
  buffer.SetFromString(dmx_data_str);
  if (!buffer.Size())
    return m_server.ServeError(response, "Invalid DMX string");

  ola::client::SendDMXArgs args(
      NewSingleCallback(this, &OladHTTPServer::HandleBoolResponse, response));
  m_client.SendDMX(universe_id, buffer, args);
  return MHD_YES;
}
Example #15
0
/*
 * Handle the set dmx command
 * @param request the HttpRequest
 * @param response the HttpResponse
 * @returns MHD_NO or MHD_YES
 */
int OlaHttpServer::HandleSetDmx(const HttpRequest *request,
                                HttpResponse *response) {
    string dmx_data_str = request->GetPostParameter("d");
    string uni_id = request->GetPostParameter("u");
    unsigned int universe_id;
    if (!StringToInt(uni_id, &universe_id))
        return m_server.ServeNotFound(response);

    DmxBuffer buffer;
    buffer.SetFromString(dmx_data_str);
    if (!buffer.Size())
        return m_server.ServeError(response, "Invalid DMX string");

    bool ok = m_client.SendDmx(
                  universe_id,
                  buffer,
                  NewSingleCallback(this, &OlaHttpServer::HandleBoolResponse, response));

    if (!ok)
        return m_server.ServeError(response, K_BACKEND_DISCONNECTED_ERROR);
    return MHD_YES;
}
Example #16
0
/**
 * @brief Handle the set DMX command
 * @param request the HTTPRequest
 * @param response the HTTPResponse
 * @returns MHD_NO or MHD_YES
 */
int OladHTTPServer::SetSpacelight(const HTTPRequest *request,
                                 HTTPResponse *response) {
  if (request->CheckParameterExists(HELP_PARAMETER)) {
    return ServeUsage(response,
        "POST u=[universe], d=[DMX data (a comma separated list of values)]");
  }
  string dmx_data_str = request->GetPostParameter("d");
  string uni_id = request->GetPostParameter("u");
  DebugSumo(dmx_data_str);


  curr_Intensity = dmx2sumo(dmx_data_str, 0);
  curr_ColorTemperature = dmx2sumo(dmx_data_str, 1);
  curr_DMX = dmx2sumo(dmx_data_str, 2);

  cout << curr_Intensity << endl;
  cout << curr_ColorTemperature << endl;
  cout << curr_DMX << endl;


  unsigned int universe_id;
  if (!StringToInt(uni_id, &universe_id)) {
    return ServeHelpRedirect(response);
  }

  DmxBuffer buffer;
  buffer.SetFromString(dmx_data_str);
  if (!buffer.Size()) {
    return m_server.ServeError(response, "Invalid DMX string");
  }

  ola::client::SendDMXArgs args(
      NewSingleCallback(this, &OladHTTPServer::HandleBoolResponse, response));
  m_client.SendDMX(universe_id, buffer, args);
  return MHD_YES;
}
/*
 * Handle the set dmx command
 * @param request the HTTPRequest
 * @param response the HTTPResponse
 * @returns MHD_NO or MHD_YES
 */
int OladHTTPServer::HandleSetDmx(const HTTPRequest *request,
                                HTTPResponse *response) {
  if (request->CheckParameterExists(HELP_PARAMETER))
    return ServeUsage(response, "POST u=[universe], d=[DMX data]");
  string dmx_data_str = request->GetPostParameter("d");
  string uni_id = request->GetPostParameter("u");
  unsigned int universe_id;
  if (!StringToInt(uni_id, &universe_id))
    return ServeHelpRedirect(response);

  DmxBuffer buffer;
  buffer.SetFromString(dmx_data_str);
  if (!buffer.Size())
    return m_server.ServeError(response, "Invalid DMX string");

  bool ok = m_client.SendDmx(
      universe_id,
      buffer,
      NewSingleCallback(this, &OladHTTPServer::HandleBoolResponse, response));

  if (!ok)
    return m_server.ServeError(response, K_BACKEND_DISCONNECTED_ERROR);
  return MHD_YES;
}
Example #18
0
DmxBuffer BufferFromString(const string &data) {
    DmxBuffer buffer;
    buffer.SetFromString(data);
    return buffer;
}
Example #19
0
/**
 * Test DMX writes in the individual APA102 mode.
 */
void SPIOutputTest::testIndividualAPA102Control() {
  // personality 7= Individual APA102
  const uint16_t this_test_personality = 7;
  // setup Backend
  FakeSPIBackend backend(2);
  SPIOutput::Options options(0, "Test SPI Device");
  // setup pixel_count to 2 (enough to test all cases)
  options.pixel_count = 2;
  // setup SPIOutput
  SPIOutput output(m_uid, &backend, options);
  // set personality
  output.SetPersonality(this_test_personality);

  // simulate incoming DMX data with this buffer
  DmxBuffer buffer;
  // setup a pointer to the returned data (the fake SPI data stream)
  unsigned int length = 0;
  const uint8_t *data = NULL;

  // test1
  // setup some 'DMX' data
  buffer.SetFromString("1, 10, 100");
  // simulate incoming data
  output.WriteDMX(buffer);
  // get fake SPI data stream
  data = backend.GetData(0, &length);
  // this is the expected spi data stream:
  const uint8_t EXPECTED1[] = { 0, 0, 0, 0,               // StartFrame
                                0xFF, 0x64, 0x0A, 0x01,   // first Pixel
                                0xFF, 0x00, 0x00, 0x00,   // second Pixel
                                0};                       // EndFrame
  // check for Equality
  OLA_ASSERT_DATA_EQUALS(EXPECTED1, arraysize(EXPECTED1), data, length);
  // check if the output writes are 1
  OLA_ASSERT_EQ(1u, backend.Writes(0));

  // test2
  buffer.SetFromString("255,128,0,10,20,30");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED2[] = { 0, 0, 0, 0,
                                0xFF, 0x00, 0x80, 0xFF,
                                0xFF, 0x1E, 0x14, 0x0A,
                                0};
  OLA_ASSERT_DATA_EQUALS(EXPECTED2, arraysize(EXPECTED2), data, length);
  OLA_ASSERT_EQ(2u, backend.Writes(0));

  // test3
  // test what happens when only new data for the first leds is available.
  // later data should be not modified so for pixel2 data set in test2 is valid
  buffer.SetFromString("34,56,78");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED3[] = { 0, 0, 0, 0,
                                0xFF, 0x4E, 0x38, 0x22,
                                0xFF, 0x1E, 0x14, 0x0A,
                                0};
  OLA_ASSERT_DATA_EQUALS(EXPECTED3, arraysize(EXPECTED3), data, length);
  OLA_ASSERT_EQ(3u, backend.Writes(0));

  // test4
  // tests what happens if fewer then needed color information are received
  buffer.SetFromString("7, 9");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  // check that the returns are the same as test3 (nothing changed)
  OLA_ASSERT_DATA_EQUALS(EXPECTED3, arraysize(EXPECTED3), data, length);
  OLA_ASSERT_EQ(3u, backend.Writes(0));

  // test5
  // test with changed StartAddress
  // set StartAddress
  output.SetStartAddress(3);
  // values 1 & 2 should not be visible in SPI data stream
  buffer.SetFromString("1,2,3,4,5,6,7,8");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED5[] = { 0, 0, 0, 0,
                                0xFF, 0x05, 0x04, 0x03,
                                0xFF, 0x08, 0x07, 0x06,
                                0};
  OLA_ASSERT_DATA_EQUALS(EXPECTED5, arraysize(EXPECTED5), data, length);
  OLA_ASSERT_EQ(4u, backend.Writes(0));
  // change StartAddress back to default
  output.SetStartAddress(1);

  // test6
  // Check nothing changed on the other output.
  OLA_ASSERT_EQ(reinterpret_cast<const uint8_t*>(NULL),
                backend.GetData(1, &length));
  OLA_ASSERT_EQ(0u, backend.Writes(1));

  // test7
  // test for multiple ports
  // StartFrame is only allowed on first port.
  SPIOutput::Options options1(1, "second SPI Device");
  // setup pixel_count to 2 (enough to test all cases)
  options1.pixel_count = 2;
  // setup SPIOutput
  SPIOutput output1(m_uid, &backend, options1);
  // set personality
  output1.SetPersonality(this_test_personality);
  // setup some 'DMX' data
  buffer.SetFromString("1, 10, 100, 100, 10, 1");
  // simulate incoming data
  output1.WriteDMX(buffer);
  // get fake SPI data stream
  data = backend.GetData(1, &length);
  // this is the expected spi data stream:
  // StartFrame is missing --> port is >0 !
  const uint8_t EXPECTED7[] = { // 0, 0, 0, 0,            // StartFrame
                                0xFF, 0x64, 0x0A, 0x01,   // first Pixel
                                0xFF, 0x01, 0x0A, 0x64,   // second Pixel
                                0};                       // EndFrame
  // check for Equality
  OLA_ASSERT_DATA_EQUALS(EXPECTED7, arraysize(EXPECTED7), data, length);
  // check if the output writes are 1
  OLA_ASSERT_EQ(1u, backend.Writes(1));

  // test8
  // create new output with pixel_count=16 and check data length
  // setup pixel_count to 16
  options.pixel_count = 16;
  // setup SPIOutput
  SPIOutput output2(m_uid, &backend, options);
  // set personality
  output2.SetPersonality(this_test_personality);
  buffer.SetFromString(
        std::string("0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0,") +
                    "0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0,");
  output2.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED8[] = { 0, 0, 0, 0,
                                0xFF, 0, 0, 0,  // Pixel 1
                                0xFF, 0, 0, 0,  // Pixel 2
                                0xFF, 0, 0, 0,  // Pixel 3
                                0xFF, 0, 0, 0,  // Pixel 4
                                0xFF, 0, 0, 0,  // Pixel 5
                                0xFF, 0, 0, 0,  // Pixel 6
                                0xFF, 0, 0, 0,  // Pixel 7
                                0xFF, 0, 0, 0,  // Pixel 8
                                0xFF, 0, 0, 0,  // Pixel 9
                                0xFF, 0, 0, 0,  // Pixel 10
                                0xFF, 0, 0, 0,  // Pixel 11
                                0xFF, 0, 0, 0,  // Pixel 12
                                0xFF, 0, 0, 0,  // Pixel 13
                                0xFF, 0, 0, 0,  // Pixel 14
                                0xFF, 0, 0, 0,  // Pixel 15
                                0xFF, 0, 0, 0,  // Pixel 16
                                0};
  OLA_ASSERT_DATA_EQUALS(EXPECTED8, arraysize(EXPECTED8), data, length);
  OLA_ASSERT_EQ(5u, backend.Writes(0));

  // test9
  // create new output with pixel_count=17 and check data length
  // setup pixel_count to 17
  options.pixel_count = 17;
  // setup SPIOutput
  SPIOutput output3(m_uid, &backend, options);
  // set personality
  output3.SetPersonality(this_test_personality);
  // generate dmx data
  buffer.SetFromString(
        std::string("0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0,") +
                    "0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0, 0,0,0," +
                    "0,0,0");
  output3.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED9[] = { 0, 0, 0, 0,
                                0xFF, 0, 0, 0,  // Pixel 1
                                0xFF, 0, 0, 0,  // Pixel 2
                                0xFF, 0, 0, 0,  // Pixel 3
                                0xFF, 0, 0, 0,  // Pixel 4
                                0xFF, 0, 0, 0,  // Pixel 5
                                0xFF, 0, 0, 0,  // Pixel 6
                                0xFF, 0, 0, 0,  // Pixel 7
                                0xFF, 0, 0, 0,  // Pixel 8
                                0xFF, 0, 0, 0,  // Pixel 9
                                0xFF, 0, 0, 0,  // Pixel 10
                                0xFF, 0, 0, 0,  // Pixel 11
                                0xFF, 0, 0, 0,  // Pixel 12
                                0xFF, 0, 0, 0,  // Pixel 13
                                0xFF, 0, 0, 0,  // Pixel 14
                                0xFF, 0, 0, 0,  // Pixel 15
                                0xFF, 0, 0, 0,  // Pixel 16
                                0xFF, 0, 0, 0,  // Pixel 17
                                0, 0};  // now we have two latch bytes...
  OLA_ASSERT_DATA_EQUALS(EXPECTED9, arraysize(EXPECTED9), data, length);
  OLA_ASSERT_EQ(6u, backend.Writes(0));
}
Example #20
0
/**
 * Test DMX writes in the combined APA102 mode.
 */
void SPIOutputTest::testCombinedAPA102Control() {
  // personality 8= Combined APA102
  const uint16_t this_test_personality = 8;
  // setup Backend
  FakeSPIBackend backend(2);
  SPIOutput::Options options(0, "Test SPI Device");
  // setup pixel_count to 2 (enough to test all cases)
  options.pixel_count = 2;
  // setup SPIOutput
  SPIOutput output(m_uid, &backend, options);
  // set personality to 8= Combined APA102
  output.SetPersonality(this_test_personality);

  // simulate incoming dmx data with this buffer
  DmxBuffer buffer;
  // setup an pointer to the returned data (the fake SPI data stream)
  unsigned int length = 0;
  const uint8_t *data = NULL;

  // test1
  // setup some 'DMX' data
  buffer.SetFromString("1, 10, 100");
  // simulate incoming data
  output.WriteDMX(buffer);
  // get fake SPI data stream
  data = backend.GetData(0, &length);
  // this is the expected spi data stream:
  const uint8_t EXPECTED1[] = { 0, 0, 0, 0,               // StartFrame
                                0xFF, 0x64, 0x0A, 0x01,   // first Pixel
                                0xFF, 0x64, 0x0A, 0x01,   // second Pixel
                                0};                       // EndFrame
  // check for Equality
  OLA_ASSERT_DATA_EQUALS(EXPECTED1, arraysize(EXPECTED1), data, length);
  // check if the output writes are 1
  OLA_ASSERT_EQ(1u, backend.Writes(0));

  // test2
  buffer.SetFromString("255,128,0,10,20,30");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED2[] = { 0, 0, 0, 0,
                                0xFF, 0x00, 0x80, 0xFF,
                                0xFF, 0x00, 0x80, 0xFF,
                                0};
  OLA_ASSERT_DATA_EQUALS(EXPECTED2, arraysize(EXPECTED2), data, length);
  OLA_ASSERT_EQ(2u, backend.Writes(0));

  // test3
  buffer.SetFromString("34,56,78");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED3[] = { 0, 0, 0, 0,
                                0xFF, 0x4E, 0x38, 0x22,
                                0xFF, 0x4E, 0x38, 0x22,
                                0};
  OLA_ASSERT_DATA_EQUALS(EXPECTED3, arraysize(EXPECTED3), data, length);
  OLA_ASSERT_EQ(3u, backend.Writes(0));

  // test4
  // tests what happens if fewer then needed color information are received
  buffer.SetFromString("7, 9");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  // check that the returns are the same as test2 (nothing changed)
  OLA_ASSERT_DATA_EQUALS(EXPECTED3, arraysize(EXPECTED3), data, length);
  OLA_ASSERT_EQ(3u, backend.Writes(0));

  // test5
  // test with other StartAddress
  // set StartAddress
  output.SetStartAddress(3);
  // values 1 & 2 should not be visible in SPI data stream
  buffer.SetFromString("1,2,3,4,5,6,7,8");
  output.WriteDMX(buffer);
  data = backend.GetData(0, &length);
  const uint8_t EXPECTED5[] = { 0, 0, 0, 0,
                                0xFF, 0x05, 0x04, 0x03,
                                0xFF, 0x05, 0x04, 0x03,
                                0};
  OLA_ASSERT_DATA_EQUALS(EXPECTED5, arraysize(EXPECTED5), data, length);
  OLA_ASSERT_EQ(4u, backend.Writes(0));

  // test6
  // Check nothing changed on the other output.
  OLA_ASSERT_EQ(reinterpret_cast<const uint8_t*>(NULL),
                backend.GetData(1, &length));
  OLA_ASSERT_EQ(0u, backend.Writes(1));

  // test7
  // test for multiple ports
  // StartFrame is only allowed on first port.
  SPIOutput::Options option1(1, "second SPI Device");
  // setup pixel_count to 2 (enough to test all cases)
  option1.pixel_count = 2;
  // setup SPIOutput
  SPIOutput output1(m_uid, &backend, option1);
  // set personality
  output1.SetPersonality(this_test_personality);
  // setup some 'DMX' data
  buffer.SetFromString("1, 10, 100");
  // simulate incoming data
  output1.WriteDMX(buffer);
  // get fake SPI data stream
  data = backend.GetData(1, &length);
  // this is the expected spi data stream:
  // StartFrame is missing --> port is >0 !
  const uint8_t EXPECTED7[] = { // 0, 0, 0, 0,            // StartFrame
                                0xFF, 0x64, 0x0A, 0x01,   // first Pixel
                                0xFF, 0x64, 0x0A, 0x01,   // second Pixel
                                0};                       // EndFrame
  // check for Equality
  OLA_ASSERT_DATA_EQUALS(EXPECTED7, arraysize(EXPECTED7), data, length);
  // check if the output writes are 1
  OLA_ASSERT_EQ(1u, backend.Writes(1));
}
Example #21
0
/*
 * Run the StringToDmxTest
 * @param input the string to parse
 * @param expected the expected result
 */
void DmxBufferTest::runStringToDmx(const string &input,
                                   const DmxBuffer &expected) {
  DmxBuffer buffer;
  OLA_ASSERT_TRUE(buffer.SetFromString(input));
  OLA_ASSERT_TRUE(expected == buffer);
}