Skip to content

Commit 7195b7e

Browse files
authored
Added M17 Link Setup Frame CRC (#24)
Added support for M17 LSF CRC from the [Ham Radio M17 Project](https://m17project.org/) Cleaned up Catch2 test project, removing unneeded code after moving to v3.
1 parent 6c05460 commit 7195b7e

4 files changed

Lines changed: 14 additions & 18 deletions

File tree

include/crc_cpp.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ namespace impl
149149
{
150150
using traits = crc_traits<TAccumulator, TABLE_SIZE>;
151151

152-
153152
[[nodiscard]] static constexpr TAccumulator update_impl_tiny(
154153
TAccumulator crc, uint8_t value, typename traits::table_type const &table)
155154
{
@@ -304,7 +303,7 @@ namespace impl
304303
//
305304
// A generic CRC lookup table sized for computing a nibble (4 bits) at a time.
306305
//
307-
// This is can be a large reduction of table space storage for embedded devices.
306+
// This is a large reduction of table space storage for embedded devices.
308307
//
309308
template <typename TAccumulator,
310309
TAccumulator const POLYNOMIAL,
@@ -379,8 +378,6 @@ namespace impl
379378
#endif
380379
};
381380

382-
383-
384381
//
385382
// Define the CRC algorithm parameters
386383
//
@@ -479,8 +476,7 @@ namespace alg
479476
using crc16_modbus = impl::crc_algorithm<uint16_t, 0x8005, 0xFFFF, 0x0000, true>;
480477
using crc16_x25 = impl::crc_algorithm<uint16_t, 0x1021, 0xFFFF, 0xFFFF, true>;
481478
using crc16_xmodem = impl::crc_algorithm<uint16_t, 0x1021, 0x0000, 0x0000, false>;
482-
483-
479+
using crc16_m17lsf = impl::crc_algorithm<uint16_t, 0x5935, 0xFFFF, 0x0000, false>;
484480

485481
// size, poly, init, xor, reverse
486482
using crc32 = impl::crc_algorithm<uint32_t, 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, true>;
@@ -548,6 +544,7 @@ namespace family
548544
template<const table_size TS> class crc16_modbus : public impl::crc<alg::crc16_modbus, TS>{};
549545
template<const table_size TS> class crc16_x25 : public impl::crc<alg::crc16_x25, TS>{};
550546
template<const table_size TS> class crc16_xmodem : public impl::crc<alg::crc16_xmodem, TS>{};
547+
template<const table_size TS> class crc16_m17lsf : public impl::crc<alg::crc16_m17lsf, TS>{};
551548

552549
template<const table_size TS> class crc32 : public impl::crc<alg::crc32, TS>{};
553550
template<const table_size TS> class crc32_bzip2 : public impl::crc<alg::crc32_bzip2, TS>{};
@@ -563,7 +560,9 @@ namespace family
563560

564561
} // namespace family
565562

566-
namespace small {
563+
564+
// Default implementation "size" selected using inline namespace
565+
inline namespace small {
567566
//------------------------------------------------------------------------
568567
//
569568
// Define the set of default CRC implementations using small table size
@@ -606,6 +605,7 @@ namespace small {
606605
using crc16_modbus = family::crc16_modbus <table_size::small>;
607606
using crc16_x25 = family::crc16_x25 <table_size::small>;
608607
using crc16_xmodem = family::crc16_xmodem <table_size::small>;
608+
using crc16_m17lsf = family::crc16_m17lsf <table_size::small>;
609609

610610
using crc32 = family::crc32 <table_size::small>;
611611
using crc32_bzip2 = family::crc32_bzip2 <table_size::small>;
@@ -661,6 +661,7 @@ namespace large
661661
using crc16_modbus = family::crc16_modbus <table_size::large>;
662662
using crc16_x25 = family::crc16_x25 <table_size::large>;
663663
using crc16_xmodem = family::crc16_xmodem <table_size::large>;
664+
using crc16_m17lsf = family::crc16_m17lsf <table_size::large>;
664665

665666
using crc32 = family::crc32 <table_size::large>;
666667
using crc32_bzip2 = family::crc32_bzip2 <table_size::large>;
@@ -713,6 +714,7 @@ namespace tiny
713714
using crc16_modbus = family::crc16_modbus <table_size::tiny>;
714715
using crc16_x25 = family::crc16_x25 <table_size::tiny>;
715716
using crc16_xmodem = family::crc16_xmodem <table_size::tiny>;
717+
using crc16_m17lsf = family::crc16_m17lsf <table_size::tiny>;
716718

717719
using crc32 = family::crc32 <table_size::tiny>;
718720
using crc32_bzip2 = family::crc32_bzip2 <table_size::tiny>;
@@ -728,9 +730,6 @@ namespace tiny
728730

729731
} // namespace tiny
730732

731-
// select the default size
732-
using namespace small;
733-
734733
} // namespace crc_cpp
735734

736735
#undef CRC_CPP_STD20_MODE

test/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ ELSE()
55
INCLUDE(${CONAN_CATCH2_ROOT}/lib/cmake/Catch2/Catch.cmake)
66
ENDIF()
77

8-
ADD_LIBRARY(catch_main STATIC catch_main.cpp)
9-
TARGET_LINK_LIBRARIES(catch_main PUBLIC CONAN_PKG::catch2)
10-
TARGET_LINK_LIBRARIES(catch_main PRIVATE project_options)
11-
128
ADD_EXECUTABLE(tests test.cpp)
13-
TARGET_LINK_LIBRARIES(tests PRIVATE project_warnings project_options catch_main)
9+
TARGET_LINK_LIBRARIES(tests PRIVATE project_warnings project_options CONAN_PKG::catch2)
1410
TARGET_INCLUDE_DIRECTORIES(tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include)
1511

1612
# automatically discover tests that are defined in catch based test files you can modify the unittests. Set TEST_PREFIX

test/catch_main.cpp

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ TEST_CASE("Algorithm", "TestCRC")
105105
REQUIRE(test_crc<family::crc8_maxim>(message, 0xA1));
106106
REQUIRE(test_crc<family::crc8_rohc>(message, 0xD0));
107107
REQUIRE(test_crc<family::crc8_wcdma>(message, 0x25));
108+
108109
REQUIRE(test_crc<family::crc16_ccit>(message, 0x29B1));
109110
REQUIRE(test_crc<family::crc16_arc>(message, 0xBB3D));
110111
REQUIRE(test_crc<family::crc16_augccit>(message, 0xE5CC));
@@ -128,6 +129,8 @@ TEST_CASE("Algorithm", "TestCRC")
128129
REQUIRE(test_crc<family::crc16_modbus>(message, 0x4B37));
129130
REQUIRE(test_crc<family::crc16_x25>( message, 0x906E));
130131
REQUIRE(test_crc<family::crc16_xmodem>( message, 0x31C3));
132+
REQUIRE(test_crc<family::crc16_m17lsf>( message, 0x772B));
133+
131134
REQUIRE(test_crc<family::crc32>(message, 0xCBF43926));
132135
REQUIRE(test_crc<family::crc32_bzip2>( message, 0xFC891918));
133136
REQUIRE(test_crc<family::crc32_c>(message, 0xE3069283));
@@ -137,5 +140,6 @@ TEST_CASE("Algorithm", "TestCRC")
137140
REQUIRE(test_crc<family::crc32_q>(message, 0x3010BF7F));
138141
REQUIRE(test_crc<family::crc32_jamcrc>(message, 0x340BC6D9));
139142
REQUIRE(test_crc<family::crc32_xfer>(message, 0xBD0BE338));
143+
140144
REQUIRE(test_crc<family::crc64_ecma>( message, 0x6C40DF5F0B497347U));
141145
}

0 commit comments

Comments
 (0)