本文整理汇总了C++中DmxBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ DmxBuffer类的具体用法?C++ DmxBuffer怎么用?C++ DmxBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DmxBuffer类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testSetChannel
/*
* 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()));
}
示例2: sizeof
/*
* Check that SetRange works.
*/
void DmxBufferTest::testSetRange() {
unsigned int data_size = sizeof(TEST_DATA);
DmxBuffer buffer;
OLA_ASSERT_FALSE(buffer.SetRange(0, NULL, data_size));
OLA_ASSERT_FALSE(buffer.SetRange(600, TEST_DATA, data_size));
// Setting an uninitialized buffer calls blackout first
OLA_ASSERT_TRUE(buffer.SetRange(0, TEST_DATA, data_size));
OLA_ASSERT_EQ((unsigned int) DMX_UNIVERSE_SIZE, buffer.Size());
OLA_ASSERT_EQ(0, memcmp(TEST_DATA, buffer.GetRaw(), data_size));
// try overrunning the buffer
OLA_ASSERT_TRUE(buffer.SetRange(DMX_UNIVERSE_SIZE - 2, TEST_DATA, data_size));
OLA_ASSERT_EQ((unsigned int) DMX_UNIVERSE_SIZE, buffer.Size());
OLA_ASSERT_EQ(0, memcmp(TEST_DATA, buffer.GetRaw() + DMX_UNIVERSE_SIZE - 2,
2));
// reset the buffer so that the valid data is 0, and try again
buffer.Reset();
OLA_ASSERT_TRUE(buffer.SetRange(0, TEST_DATA, data_size));
OLA_ASSERT_EQ((unsigned int) data_size, buffer.Size());
OLA_ASSERT_EQ(0, memcmp(TEST_DATA, buffer.GetRaw(), data_size));
// setting past the end of the valid data should fail
OLA_ASSERT_FALSE(buffer.SetRange(50, TEST_DATA, data_size));
OLA_ASSERT_EQ((unsigned int) data_size, buffer.Size());
OLA_ASSERT_EQ(0, memcmp(TEST_DATA, buffer.GetRaw(), buffer.Size()));
// overwrite part of the valid data
unsigned int offset = 2;
OLA_ASSERT_TRUE(buffer.SetRange(offset, TEST_DATA, data_size));
OLA_ASSERT_EQ((unsigned int) data_size + offset,
buffer.Size());
OLA_ASSERT_EQ(0, memcmp(TEST_DATA, buffer.GetRaw(), offset));
OLA_ASSERT_EQ(0, memcmp(TEST_DATA, buffer.GetRaw() + offset,
buffer.Size() - offset));
// now try writing 1 channel past the valid data
buffer.Reset();
OLA_ASSERT_TRUE(buffer.SetRange(0, TEST_DATA, data_size));
OLA_ASSERT_TRUE(buffer.SetRange(data_size, TEST_DATA,
data_size));
OLA_ASSERT_EQ((unsigned int) data_size * 2, buffer.Size());
OLA_ASSERT_EQ(0, memcmp(TEST_DATA, buffer.GetRaw(), data_size));
OLA_ASSERT_EQ(0, memcmp(TEST_DATA, buffer.GetRaw() + data_size, data_size));
}
示例3: runStringToDmx
/*
* 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);
}
示例4: Encode
/*
* Take a DMXBuffer and RunLengthEncode the data
* @param src the DmxBuffer with the DMX data
* @param data where to store the RLE data
* @param size the size of the data segment, set to the amount of data encoded
* @return true if we encoded all data, false if we ran out of space
*/
bool RunLengthEncoder::Encode(const DmxBuffer &src,
uint8_t *data,
unsigned int &data_size) {
unsigned int src_size = src.Size();
unsigned int dst_size = data_size;
unsigned int &dst_index = data_size;
dst_index = 0;
unsigned int i;
for (i = 0; i < src_size && dst_index < dst_size;) {
// j points to the first non-repeating value
unsigned int j = i + 1;
while (j < src_size && src.Get(i) == src.Get(j) && j - i < 0x7f) {
j++;
}
// if the number of repeats is more than 2
// don't encode only two repeats,
if (j - i > 2) {
// if room left in dst buffer
if (dst_size - dst_index > 1) {
data[dst_index++] = (REPEAT_FLAG | (j - i));
data[dst_index++] = src.Get(i);
} else {
// else return what we have done so far
return false;
}
i = j;
} else {
// this value doesn't repeat more than twice
// find out where the next repeat starts
// postcondition: j is one more than the last value we want to send
for (j = i + 1; j < src_size - 2 && j - i < 0x7f; j++) {
// at the end of the array
if (j == src_size - 2) {
j = src_size;
break;
}
// if we're found a repeat of 3 or more stop here
if (src.Get(j) == src.Get(j+1) && src.Get(j) == src.Get(j+2))
break;
}
if (j >= src_size - 2)
j = src_size;
// if we have enough room left for all the values
if (dst_index + j - i < dst_size) {
data[dst_index++] = j - i;
memcpy(&data[dst_index], src.GetRaw() + i, j-i);
dst_index += j - i;
i = j;
// see how much data we can get in
} else if (dst_size - dst_index > 1) {
unsigned int l = dst_size - dst_index -1;
data[dst_index++] = l;
memcpy(&data[dst_index], src.GetRaw() + i, l);
dst_index += l;
return false;
} else {
return false;
}
}
}
if (i < src_size)
return false;
else
return true;
}
示例5: setUp
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);
}