Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Channel Remap Tool #1895

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ examples/ola_latency.exe
examples/ola_patch
examples/ola_patch.exe
examples/ola_ptch.exe
examples/ola_patcher_remap
examples/ola_patcher_remap.exe
examples/ola_ptcher_remap.exe
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we have the file with the a missing?

examples/ola_plugin_info
examples/ola_plugin_info.exe
examples/ola_plugin_state
Expand Down
13 changes: 11 additions & 2 deletions common/dmx/Makefile.mk
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
# LIBRARIES
##################################################
common_libolacommon_la_SOURCES += common/dmx/RunLengthEncoder.cpp
common_libolacommon_la_SOURCES += \
common/dmx/RunLengthEncoder.cpp \
common/dmx/UniverseChannelAddress.cpp


# TESTS
##################################################
test_programs += common/dmx/RunLengthEncoderTester
test_programs += \
common/dmx/RunLengthEncoderTester \
common/dmx/UniverseChannelAddressTester

common_dmx_RunLengthEncoderTester_SOURCES = common/dmx/RunLengthEncoderTest.cpp
common_dmx_RunLengthEncoderTester_CXXFLAGS = $(COMMON_TESTING_FLAGS)
common_dmx_RunLengthEncoderTester_LDADD = $(COMMON_TESTING_LIBS)

common_dmx_UniverseChannelAddressTester_SOURCES = common/dmx/UniverseChannelAddressTest.cpp
common_dmx_UniverseChannelAddressTester_CXXFLAGS = $(COMMON_TESTING_FLAGS)
common_dmx_UniverseChannelAddressTester_LDADD = $(COMMON_TESTING_LIBS)
105 changes: 105 additions & 0 deletions common/dmx/UniverseChannelAddress.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* UniverseChannelAddress.cpp
* Represents a universe-channel address pair.
* Copyright (C) 2023 Peter Newman
*/

#include <assert.h>
#include <ola/Logging.h>
#include <ola/StringUtils.h>
#include <ola/dmx/UniverseChannelAddress.h>
#include <string.h>
#include <string>

namespace ola {
namespace dmx {

using std::string;


string UniverseChannelAddress::ToString() const {
std::ostringstream str;
str << Universe() << ":" << Channel();
return str.str();
}


/**
* Extract a UniverseChannelAddress from a string.
*/
bool UniverseChannelAddress::FromString(
const string &input,
UniverseChannelAddress *universe_channel_address) {
size_t pos = input.find_first_of(":");
if (pos == string::npos) {
return false;
}

unsigned int universe;
if (!StringToInt(input.substr(0, pos), &universe)) {
return false;
}
uint16_t channel;
if (!StringToInt(input.substr(pos + 1), &channel)) {
return false;
}
*universe_channel_address = UniverseChannelAddress(universe, channel);
return true;
}


UniverseChannelAddress UniverseChannelAddress::FromStringOrDie(
const string &address) {
UniverseChannelAddress universe_channel_address;
assert(FromString(address, &universe_channel_address));
return universe_channel_address;
}


string UniverseChannelAddressOneBased::ToStringZeroBased() const {
std::ostringstream str;
str << Universe() << ":" << ChannelZeroBased();
return str.str();
}


/**
* Extract a UniverseChannelAddressOneBased from a string.
*/
bool UniverseChannelAddressOneBased::FromString(
const string &input,
UniverseChannelAddressOneBased *universe_channel_address_one_based) {
size_t pos = input.find_first_of(":");
if (pos == string::npos) {
return false;
}

unsigned int universe;
if (!StringToInt(input.substr(0, pos), &universe)) {
return false;
}
uint16_t channel;
if (!StringToInt(input.substr(pos + 1), &channel)) {
return false;
}
*universe_channel_address_one_based = UniverseChannelAddressOneBased(
universe,
channel);
return true;
}
} // namespace dmx
} // namespace ola
159 changes: 159 additions & 0 deletions common/dmx/UniverseChannelAddressTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* UniverseChannelAddressTest.cpp
* Test fixture for the UniverseChannelAddress class
* Copyright (C) 2023 Peter Newman
*/

#include <cppunit/extensions/HelperMacros.h>
#include <string>

#include "ola/dmx/UniverseChannelAddress.h"
#include "ola/testing/TestUtils.h"

using ola::dmx::UniverseChannelAddress;
using ola::dmx::UniverseChannelAddressOneBased;
using std::ostringstream;
using std::string;

class UniverseChannelAddressTest: public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(UniverseChannelAddressTest);
CPPUNIT_TEST(testUniverseChannelAddress);
CPPUNIT_TEST(testUniverseChannelAddressFromString);
CPPUNIT_TEST_SUITE_END();

public:
void testUniverseChannelAddress();
void testUniverseChannelAddressToString();
void testUniverseChannelAddressFromString();
};

CPPUNIT_TEST_SUITE_REGISTRATION(UniverseChannelAddressTest);


/*
* Test the UniverseChannelAddress class works
*/
void UniverseChannelAddressTest::testUniverseChannelAddress() {
UniverseChannelAddress universe_channel_address(10, 500);
OLA_ASSERT_EQ(static_cast<unsigned int>(10),
universe_channel_address.Universe());
OLA_ASSERT_EQ(static_cast<uint16_t>(500),
universe_channel_address.Channel());

UniverseChannelAddressOneBased universe_channel_address_one_based(10, 501);
OLA_ASSERT_EQ(static_cast<unsigned int>(10),
universe_channel_address_one_based.Universe());
OLA_ASSERT_EQ(static_cast<uint16_t>(501),
universe_channel_address_one_based.Channel());
OLA_ASSERT_EQ(static_cast<uint16_t>(500),
universe_channel_address_one_based.ChannelZeroBased());

// TODO(Peter): Test out of range channel values

// test comparison operators
UniverseChannelAddress universe_channel_address2(10, 499);
UniverseChannelAddress universe_channel_address3(10, 501);
UniverseChannelAddress universe_channel_address4(9, 500);
UniverseChannelAddress universe_channel_address5(11, 500);

OLA_ASSERT_EQ(universe_channel_address, universe_channel_address);
OLA_ASSERT_NE(universe_channel_address, universe_channel_address2);
OLA_ASSERT_NE(universe_channel_address, universe_channel_address3);
OLA_ASSERT_NE(universe_channel_address, universe_channel_address4);
OLA_ASSERT_NE(universe_channel_address, universe_channel_address5);

OLA_ASSERT_LT(universe_channel_address2, universe_channel_address);
OLA_ASSERT_LT(universe_channel_address, universe_channel_address3);
OLA_ASSERT_LT(universe_channel_address4, universe_channel_address);
OLA_ASSERT_LT(universe_channel_address4, universe_channel_address3);

OLA_ASSERT_GT(universe_channel_address, universe_channel_address2);
OLA_ASSERT_GT(universe_channel_address3, universe_channel_address);
OLA_ASSERT_GT(universe_channel_address, universe_channel_address4);
OLA_ASSERT_GT(universe_channel_address3, universe_channel_address4);

OLA_ASSERT_EQ(universe_channel_address,
static_cast<UniverseChannelAddress>(
universe_channel_address_one_based));

// test assignment & copy constructor
UniverseChannelAddress copy_address(universe_channel_address);
universe_channel_address4 = universe_channel_address;
OLA_ASSERT_EQ(universe_channel_address, copy_address);
OLA_ASSERT_EQ(universe_channel_address, universe_channel_address4);
}

/**
* Test that ToString() works
*/
void UniverseChannelAddressTest::testUniverseChannelAddressToString() {
UniverseChannelAddress universe_channel_address(10, 500);

OLA_ASSERT_EQ(string("10:500"), universe_channel_address.ToString());

universe_channel_address.Universe(100);
universe_channel_address.Channel(50);
OLA_ASSERT_EQ(string("100:50"), universe_channel_address.ToString());

ostringstream str;
str << universe_channel_address;
OLA_ASSERT_EQ(string("100:50"), str.str());
}

/**
* Test that FromString() works
*/
void UniverseChannelAddressTest::testUniverseChannelAddressFromString() {
UniverseChannelAddress universe_channel_address;
OLA_ASSERT_TRUE(
UniverseChannelAddress::FromString("127:80", &universe_channel_address));
OLA_ASSERT_EQ(static_cast<unsigned int>(127),
universe_channel_address.Universe());
OLA_ASSERT_EQ(static_cast<uint16_t>(80), universe_channel_address.Channel());

UniverseChannelAddressOneBased universe_channel_address_one_based;
OLA_ASSERT_TRUE(UniverseChannelAddressOneBased::FromString(
"127:81", &universe_channel_address_one_based));
OLA_ASSERT_EQ(static_cast<unsigned int>(127),
universe_channel_address_one_based.Universe());
OLA_ASSERT_EQ(static_cast<uint16_t>(81),
universe_channel_address_one_based.Channel());
OLA_ASSERT_EQ(static_cast<uint16_t>(80),
universe_channel_address_one_based.ChannelZeroBased());

OLA_ASSERT_FALSE(
UniverseChannelAddress::FromString("127", &universe_channel_address));
OLA_ASSERT_FALSE(
UniverseChannelAddress::FromString("foo", &universe_channel_address));
OLA_ASSERT_FALSE(
UniverseChannelAddress::FromString("127:", &universe_channel_address));
OLA_ASSERT_FALSE(
UniverseChannelAddress::FromString("foo:", &universe_channel_address));
OLA_ASSERT_FALSE(
UniverseChannelAddress::FromString(":80", &universe_channel_address));

OLA_ASSERT_FALSE(UniverseChannelAddressOneBased::FromString(
"127", &universe_channel_address_one_based));
OLA_ASSERT_FALSE(UniverseChannelAddressOneBased::FromString(
"foo", &universe_channel_address_one_based));
OLA_ASSERT_FALSE(UniverseChannelAddressOneBased::FromString(
"127:", &universe_channel_address_one_based));
OLA_ASSERT_FALSE(UniverseChannelAddressOneBased::FromString(
"foo:", &universe_channel_address_one_based));
OLA_ASSERT_FALSE(UniverseChannelAddressOneBased::FromString(
":80", &universe_channel_address_one_based));
}
4 changes: 3 additions & 1 deletion doxygen/examples/receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ int main() {
ola::InitLogging(ola::OLA_LOG_INFO, ola::OLA_LOG_STDERR);

ola::client::OlaClientWrapper wrapper;
if (!wrapper.Setup())
if (!wrapper.Setup()) {
std::cerr << "Setup failed" << std::endl;
exit(1);
}

ola::client::OlaClient *client = wrapper.GetClient();
// Set the callback and register our interest in this universe
Expand Down
5 changes: 5 additions & 0 deletions examples/Makefile.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ examples_libolaconfig_la_CXXFLAGS = $(COMMON_PROTOBUF_CXXFLAGS)
##################################################
bin_PROGRAMS += \
examples/ola_dev_info \
examples/ola_patcher_remap \
examples/ola_rdm_discover \
examples/ola_rdm_get \
examples/ola_recorder \
Expand Down Expand Up @@ -61,6 +62,10 @@ endif
examples_ola_dev_info_SOURCES = examples/ola-client.cpp
examples_ola_dev_info_LDADD = $(EXAMPLE_COMMON_LIBS)

examples_ola_patcher_remap_SOURCES = examples/ola-patcher-remap.cpp
examples_ola_patcher_remap_LDADD = $(EXAMPLE_COMMON_LIBS) \
olad/plugin_api/libolaserverplugininterface.la

examples_ola_streaming_client_SOURCES = examples/ola-streaming-client.cpp
examples_ola_streaming_client_LDADD = $(EXAMPLE_COMMON_LIBS)

Expand Down
Loading
Loading