- 
                Notifications
    You must be signed in to change notification settings 
- Fork 217
Add a Channel Remap Tool #1895
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
          
     Open
      
      
            peternewman
  wants to merge
  7
  commits into
  OpenLightingProject:master
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
peternewman:remap
  
      
      
   
  
    
  
  
  
 
  
      
    base: master
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
  
     Open
                    Add a Channel Remap Tool #1895
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            7 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      c64f668
              
                Improve one of our example's error handling logging
              
              
                peternewman 8790bdf
              
                Fix a comment typo
              
              
                peternewman ddf953d
              
                First version of UniverseChannelAddress class
              
              
                peternewman 7066c00
              
                Add a one based universe channel class
              
              
                peternewman 937dccc
              
                First version of the universe-channel remapper
              
              
                peternewman d36610c
              
                Fix a lint error
              
              
                peternewman d0aeef7
              
                Merge branch 'OpenLightingProject:master' into remap
              
              
                peternewman File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | 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)); | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
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
amissing?